aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/tads/tads2/ltk.cpp
blob: 6961f216aed7583194398894e8c19e8df0d18721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "glk/tads/tads2/ltk.h"
#include "glk/tads/tads2/lib.h"
#include "glk/tads/tads2/error_handling.h"

namespace Glk {
namespace TADS {
namespace TADS2 {


/*--------------------------------- ltkini ---------------------------------*/
/*
 * ltkini - allocate and INItialize toolkit context.
 */
void ltkini(unsigned short heapsiz) {
}


/*--------------------------------- ltkfre ---------------------------------*/
/*
 * ltkfre - FREe toolkit context.
 */
void ltkfre() {
}


/*------------------------------ ltk_suballoc ------------------------------*/
/*
 * ltk_suballoc - SUB ALLOCate memory from heap segment.
 */
void *ltk_suballoc(size_t siz) {
	return ltk_alloc(siz);
}


/*---------------------------- ltk_sigsuballoc -----------------------------*/
/*
 * ltk_sigsuballoc - allocate from heap, signal failure.
 */
void *ltk_sigsuballoc(errcxdef *errcx, size_t siz) {
  void *ptr;                                     /* ptr to allocated memory */

  /* allocate the memory */
  if (!(ptr = ltk_suballoc(siz)))
  {
    /* signal an error */
    errsigf(errcx, "LTK", 0);
  }

  /* return the memory */
  return(ptr);
}


/*------------------------------ ltk_subfree -------------------------------*/
/*
 * ltk_subfree - FREe memory allocated by ltk_suballoc
 */
void ltk_subfree(void *ptr) {
	free(ptr);
}


/*------------------------------- ltk_alloc --------------------------------*/
/*
 * ltk_alloc - Allocate a block of memory
 */
void *ltk_alloc(size_t siz) {
	byte *data = (byte *)malloc(siz);
	Common::fill(data, data + siz, 0);
	return data;
}

/*------------------------------ ltk_realloc ------------------------------*/

void *ltk_realloc(void *ptr, size_t siz) {
	return realloc(ptr, siz);
}

/*------------------------------ ltk_sigalloc ------------------------------*/
/*
 * ltk_sigalloc - allocate permanent global memory, and signal on failure.
 */
void *ltk_sigalloc(errcxdef *errcx, size_t siz) {
  void *ptr;                                 /* pointer to allocated memory */

  if (!(ptr = ltk_alloc(siz))) {
    /* signal error */
    errsigf(errcx, "LTK", 0);
  }

  /* return a ptr to the allocated memory */
  return ptr;
}


/*-------------------------------- ltk_free --------------------------------*/
/*
 * ltk_free - free a block of memory allocated by ltk_alloc.  This
 * takes the memory handle stashed just behind the allocation, and frees
 * the block of memory.  
 */
void ltk_free(void *mem) {
	free(mem);
}

/*------------------------------- ltk_errlog -------------------------------*/
/*
* ltk_errlog - ERRor LOGging function.  Logs an error from the LER
* system.
*/
void ltk_errlog(void *ctx, const char *fac, int errCode, int argc, erradef *argv) {
	char buf[128];                                  /* formatted error buffer */
	char msg[128];                                          /* message buffer */

															/* $$$ filter out error #504 $$$ */
	if (errCode == 504) return;

	/* get the error message into msg */
	errmsg((errcxdef *)ctx, msg, sizeof(msg), errCode);

	/* format the error message */
	errfmt(buf, (int)sizeof(buf), msg, argc, argv);

	/* display a dialog box containing the error message */
	ltk_dlg("Error", buf);
}


/*-------------------------------- ltk_dlg ---------------------------------*/
/*
* ltk_dlg - DiaLog.  Puts the given message in a dialog box.
*/
void ltk_dlg(const char *title, const char *msg, ...) {
	va_list  argp;                                             /* printf args */
	char     inbuf[80];                                       /* input buffer */
	char     outbuf[160];                    /* allow inbuf to double in size */

											 /* clip the input message, if necessary */
	strncpy(inbuf, msg, sizeof(inbuf));
	inbuf[sizeof(inbuf) - 1] = '\0';

	/* get the printf args, build the message, and display it */
	va_start(argp, msg);
	vsprintf(outbuf, inbuf, argp);

	/* display the message */
	error("%s", outbuf);
}


/*-------------------------------- ltk_beep --------------------------------*/
/*
* ltk_beep - BEEP the PC's speaker.
*/
void ltk_beep() {
}

/*------------------------------ ltk_beg_wait ------------------------------*/
/*
* ltk_beg_wait - Put up hourglass prompt.
*/
void ltk_beg_wait() {
}


/*------------------------------ ltk_end_wait ------------------------------*/
/*
* ltk_end_wait - Put up normal prompt.
*/
void ltk_end_wait() {
}

} // End of namespace TADS2
} // End of namespace TADS
} // End of namespace Glk