-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathp_about.c
400 lines (357 loc) · 11.2 KB
/
p_about.c
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <gem.h>
#include <cflib.h>
#include "version.h"
#include "global.h"
#include "Loader.h"
#include "parser.h"
#include "fontbase.h"
#include "Containr.h"
#include "Location.h"
#include "Form.h"
#include "inet.h"
#include "ovl_sys.h"
#include "cache.h"
#ifdef LIBPNG
#include "png.h"
#endif
#ifdef LIBGIF
#include "gif_lib.h"
#endif
#ifdef LIBJPG
#define XMD_H /* avoid redefining INT16 and INT32, already done in gemlib */
#undef INLINE
#undef LOCAL
#undef GLOBAL
#include <jpeglib.h>
#undef XMD_H
#endif
/*----------------------------------------------------------------------------*/
static void
about_modules (TEXTBUFF current, ENCODING enc)
{
char buf[100];
MODULINF mod = NULL;
size_t num = module_info (&mod);
if (mod && num) {
size_t count = num;
while (count--) {
#if 01
struct ovl_info_t * info = (*mod->Meth->ovl_version)();
sprintf (buf, "\022\005%s:\020 %s %s \026by\024 %s\005\003",
mod->File, info->name, info->version, info->author);
render_text (current, buf);
current->word->line_brk = BRK_LN;
sprintf (buf, "kill=0x%08lX", (long)mod->Meth);
font_byType (-1, FNT_BOLD, font_step2size (2), current->word);
form_buttn (current, buf, "×", enc, 'S');
font_byType (-1, 0x0000, font_step2size (3), current->word);
#else
sprintf (buf, "\022\005%s\020\r", mod->File);
render_text (current, buf);
#endif
mod++;
}
if (num > 0) {
render_hrule (current, ALN_LEFT, -512, 2, TRUE);
}
free (mod - num);
} else {
render_text (current, "\026(none)\024");
}
}
/*----------------------------------------------------------------------------*/
static BOOL
about_cache (TEXTBUFF current, ENCODING enc, CACHEINF info, size_t num)
{
BOOL unused = FALSE;
char buf[1000];
if (info) {
struct s_line {
WORDITEM word; UWORD len;
} * mem = malloc (sizeof(struct s_line) * num), * line = mem;
UWORD max_ln = 0;
size_t count = num;
while (count--) {
WORDITEM w = current->word;
char source[500] ="\022\025\005";
location_FullName (info->Source, source +3, sizeof(source)-3);
render_text (current, source);
render_text (current, "\024\003\005\005\005\020")->line_brk = BRK_LN;
w = current->word;
if (info->Ident) {
int ic = (int)(info->Ident >>24) & 0x00FF; /* bgnd colour */
int iw = (int)(info->Ident >>12) & 0x0FFF; /* width */
int ih = (int) info->Ident & 0x0FFF; /* height */
sprintf (buf, "Memory:\005\021%i*%i,%02X\020", iw, ih, ic);
render_text (current, buf);
} else if (!info->Cached) {
TA_Color (render_text (current, "\026(busy)\024")->attr) = G_RED;
} else {
sprintf (buf, "Disk:\005\022%s\020", info->Cached);
render_text (current, buf);
}
sprintf (buf, " \005%li\005\003", info->Size);
render_text (current, buf);
if (mem) {
line->len = w->word_width;
do {
line->word = w;
w = w->next_word;
line->len += w->word_width;
} while (w != current->prev_wrd);
if (max_ln < line->len) {
max_ln = line->len;
}
line++;
}
if (info->Used || !info->Object) {
sprintf (buf, "[%li]\003", info->Used);
render_text (current, buf);
} else {
sprintf (buf, "clear=0x%08lX", (long)info->Object);
font_byType (-1, FNT_BOLD, font_step2size (1), current->word);
form_buttn (current, buf, "×", enc, 'S');
current->prev_wrd->word_height -= 2;
font_byType (-1, 0x0000, font_step2size (3), current->word);
unused = TRUE;
}
if (info->Date) {
struct tm * tm = localtime ((time_t*)&info->Date);
sprintf (buf, "\005\005\021%04i-%02i-%02i %02i:%02i:%02i\020",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
render_text (current, buf);
if (info->Expires > 0) {
tm = localtime ((time_t*)&info->Expires);
sprintf (buf, "\005\005expires:\005\021%04i-%02i-%02i %02i:%02i:%02i\020",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
render_text (current, buf);
} else if (info->Expires) { /* < 0 */
render_text (current, "\005\005(no-cache)\003");
}
}
current->prev_wrd->line_brk = BRK_LN;
info++;
}
if (mem) {
while (line-- > mem) {
line->word->word_width += max_ln - line->len;
}
free (mem);
}
if (num > 0) {
render_hrule (current, ALN_LEFT, -512, 2, TRUE);
}
free (info - num);
}
return unused;
}
/*----------------------------------------------------------------------------*/
static void
about_highwire (TEXTBUFF current, WORD link_color)
{
#ifndef USE_OVL
const char * i_net = inet_info();
#endif
char buf[100];
WORDITEM list[10], * w = &list[-1];
WORD tab = 0;
size_t m_num = module_info (NULL);
#ifdef GEM_MENU
*(++w) = render_text (current, "\025GEM\005Menu:\005\024\0220.4\020\r");
tab = (*w)->word_width;
#endif
*(++w) = render_text (current, "\025Core:\005\024\022"
_HIGHWIRE_VERSION_ "\020 \026" _HIGHWIRE_BETATAG_ "\024\n");
tab = max (tab, (*w)->word_width);
font_byType (-1, -1, font_step2size (2), current->word);
#ifdef __GEMLIB_MAJOR__
sprintf (buf, "\025GEMlib:\005\024\022%i.%02i.%i\020 \026" __GEMLIB_BETATAG__ "\024\r",
__GEMLIB_MAJOR__, __GEMLIB_MINOR__, __GEMLIB_REVISION__);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#endif
#ifdef __MINTLIB__
sprintf (buf,
"\025MiNTlib:\005\024\022%i.%02i.%i\020 \026" __MINTLIB_BETATAG__ "\024\r",
__MINTLIB_MAJOR__, __MINTLIB_MINOR__, __MINTLIB_REVISION__);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#endif
#ifdef __CFLIB__
sprintf (buf,
"\025CFlib:\005\024\022%i.%02i.%i\020 \026" __CFLIB_BETATAG__ "\024\r",
__CFLIB_MAJOR__, __CFLIB_MINOR__, __CFLIB_REVISION__);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#endif
#ifdef LIBPNG
# ifdef PNG_LIBPNG_VER_STRING
sprintf (buf,
"\025libpng:\005\024\022%s\020 \026\024\r",
PNG_LIBPNG_VER_STRING);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#endif
#endif
#ifdef LIBGIF
#if defined(GIF_LIB_VERSION)
sprintf (buf,
"\025gif_lib:\005\024\022%s\020 \026\024\r",
GIF_LIB_VERSION);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#elif defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && defined(GIFLIB_RELEASE)
sprintf (buf,
"\025gif_lib:\005\024\022%d.%d.%d\020 \026\024\r",
GIFLIB_MAJOR, GIFLIB_MINOR, GIFLIB_RELEASE);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#endif
#endif
#ifdef LIBJPG
#ifdef JPEG_LIB_VERSION
sprintf (buf,
"\025jpeg_lib:\005\024\022%d\020 \026" "\024\r",
JPEG_LIB_VERSION);
*(++w) = render_text (current, buf);
tab = max (tab, (*w)->word_width);
#endif
#endif
*(++w) = render_text (current, "\025compiled:\005\024");
tab = max (tab, (*w)->word_width);
#if defined (__GNUC__)
#ifdef __VERSION__
sprintf (buf, "Gnu C \022%s\020, ", __VERSION__);
#else
sprintf (buf, "Gnu C \022%i.%02i\020, ", __GNUC__, __GNUC_MINOR__);
#endif
render_text (current, buf);
#elif defined (__PUREC__)
sprintf (buf, "Pure C \022%i.%02x\020, ",
__PUREC__ >>8, __PUREC__ & 0xFF);
render_text (current, buf);
#elif defined (LATTICE)
render_text (current, "Lattice C\n");
#endif
render_text (current, "\021"__DATE__ ", " __TIME__"\020\n");
/* align left column */
do {
(*w)->word_width = tab;
} while (--w >= list);
font_byType (-1, -1, font_step2size (3), current->word);
#ifndef USE_OVL
if (i_net) {
sprintf (buf, "(%s support enabled)", i_net);
render_text (current, buf);
}
#endif
render_hrule (current, ALN_LEFT, -512, 2, TRUE);
sprintf (buf, "Screen Mode: '\022%s\020'\r", image_dispinfo());
render_text (current, buf);
sprintf (buf, "Config File: ");
render_text (current, buf);
sprintf (buf, (!cfg_File ? "\026(none)\024\r" : "\022%.*s\020\r"),
(int)sizeof(buf) -1, cfg_File);
render_text (current, buf);
render_link (current, "modules\003: ", "about:modules", link_color);
if (m_num) {
sprintf (buf, "%li loaded\r", m_num);
render_text (current, buf);
} else {
render_text (current, "\026(none)\024\r");
}
render_link (current, "cached\003: ", "about:cache", link_color);
}
/*==============================================================================
* Create 'about' page
*/
int
parse_about (void * arg, long invalidated)
{
PARSER parser = arg;
FRAME frame = parser->Frame;
TEXTBUFF current = &parser->Current;
char buf[100];
const char * title = frame->Location->File;
WORD mode; /* 0 = normal, 1 = cache */
CACHEINF info = NULL;
size_t c_mem = 0, c_num = 0;
BOOL clrable = TRUE; /* guess there is anything cached to be cleared */
if (invalidated) {
delete_parser (parser);
return FALSE;
}
current->paragraph->Box.TextAlign = ALN_CENTER;
font_byType (header_font, FNT_BOLD, font_step2size (6), current->word);
if (strncmp ("modules", title, 7) == 0) {
if (strncmp (title +7, "?kill=", 6) == 0) {
char * rest;
long ovl = strtol (title +13, &rest, 16);
if (ovl > 0 && *rest == '=') {
kill_ovl ((void*)ovl);
}
}
containr_notify (parser->Target, HW_SetTitle, "About: Modules");
title = "Modules loaded:";
mode = 2;
} else if (strncmp ("cache", title, 5) == 0) {
if (strncmp (title +5, "?clear", 6) == 0) {
if (title[11] == '\0' || strcmp (title +11, "=clear") == 0) {
cache_clear (NULL);
} else if (title[11] == '=') {
char * rest;
long obj = strtol (title +12, &rest, 16);
if (obj > 0 && (!*rest || *rest == '=')) {
cache_clear ((CACHED)obj);
}
}
}
containr_notify (parser->Target, HW_SetTitle, "About: Cache");
title = "Objects in cache:";
mode = 1;
} else {
containr_notify (parser->Target, HW_SetTitle, "About: HighWire");
title = "Version Information";
mode = 0;
}
font_switch (current->word->font, NULL);
render_text (current, title);
render_hrule (current, ALN_CENTER, -1024, 2, TRUE);
current->paragraph->Box.TextAlign = ALN_LEFT;
font_byType (normal_font, 0x0000, font_step2size (3), current->word);
if (mode <= 1) {
current->form = new_form (frame, NULL, strdup ("about:cache"), "GET", NULL);
c_num = cache_info (&c_mem, (mode == 1 ? &info : NULL));
}
switch (mode) {
case 2:
current->form = new_form (frame, NULL, strdup("about:modules"), "GET", NULL);
about_modules (current, frame->Encoding);
break;
case 1:
clrable = about_cache (current, frame->Encoding, info, c_num);
break;
default:
about_highwire (current, frame->link_color);
break;
}
if (c_num) {
sprintf (buf, "%lu object%s, %lu bytes \005\022",
c_num, (c_num > 1 ? "s" : ""), c_mem);
render_text (current, buf);
form_buttn (current, "clear", "clear", frame->Encoding, 'S');
if (!clrable) {
input_disable (current->prev_wrd->input, TRUE);
}
} else if (mode <= 1) {
render_text (current, "\026(empty)\024");
}
delete_parser (parser);
return FALSE;
}