-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.c
More file actions
413 lines (388 loc) · 10.4 KB
/
help.c
File metadata and controls
413 lines (388 loc) · 10.4 KB
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
401
402
403
404
405
406
407
408
409
410
411
412
413
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_FCNTL_H
# include <fcntl.h>
#endif
#include "deco.h"
#include "scr.h"
#include "env.h"
#define CS 34
#define HELPDIR "/usr/lib/deco/help/"
#define LCLHELPDIR "/usr/local/lib/deco/help/"
struct helptab {
char row;
char col;
char bold;
char *str;
};
struct help {
char *name;
struct helptab *htab;
char **mesg;
};
static void inithelp (struct help *hp);
static void initnewhelp (char **q, char *p);
static char *genmesg [] = {
"The Demos Commander, Copyright (C) 1989-1997 Serge Vakulenko",
" Cursor Arrows ",
"Left ^[ l",
"Right ^[ r",
"Up ^[ u",
"Down ^[ d",
" Cursor Movement ",
"Char left ^S or ^A",
"Char right ^D",
" Panels ",
"Switch panels ^I or <Tab>",
"Panels on/off ^O or ^P",
"Swap panels ^U",
"Toggle status ^L",
"Full screen ^F",
"Double width ^W",
"The \"+\" and \"-\" keys select and unselect groups of files.",
" Delete ",
"Char left ^H or <BS>",
"Under cursor ^G or <Del>",
"Line ^Y",
" Other ",
"History ^B",
"Home directory ^\\",
"Reread directory ^R",
"Select/Unselect ^T or <Ins>",
"Previous command ^E",
"Next command ^X",
"Run file or",
"Enter directory ^M or <Ret>",
"Use file name ^J or <LF>",
"Function keys ^[ + digit",
0,
};
static struct helptab gentab [] = {
{ 1, 0, 0, 0 },
/* 2, */
{ 3, 2, 1, 0 },
{ 4, 6, 0, 0 },
{ 5, 6, 0, 0 },
{ 6, 6, 0, 0 },
{ 7, 6, 0, 0 },
{ 8, 2, 1, 0 },
{ 9, 6, 0, 0 },
{ 10, 6, 0, 0 },
{ 11, 2, 1, 0 },
{ 12, 6, 0, 0 },
{ 13, 6, 0, 0 },
{ 14, 6, 0, 0 },
{ 15, 6, 0, 0 },
{ 16, 6, 0, 0 },
{ 17, 6, 0, 0 },
/* 18, */
{ 19, 0, 0, 0 },
/* 2, */
{ 3, CS+ 2, 1, 0 },
{ 4, CS+ 6, 0, 0 },
{ 5, CS+ 6, 0, 0 },
{ 6, CS+ 6, 0, 0 },
{ 7, CS+ 2, 1, 0 },
{ 8, CS+ 6, 0, 0 },
{ 9, CS+ 6, 0, 0 },
{ 10, CS+ 6, 0, 0 },
{ 11, CS+ 6, 0, 0 },
{ 12, CS+ 6, 0, 0 },
{ 13, CS+ 6, 0, 0 },
{ 14, CS+ 6, 0, 0 },
{ 15, CS+ 6, 0, 0 },
{ 16, CS+ 6, 0, 0 },
{ 17, CS+ 6, 0, 0 },
{ 0, 0, 0, 0 },
};
static char *editmesg [] = {
"The Demos Commander Text Editor, Copyright (C) 1990-1997 Serge Vakulenko",
" Cursor Movement ",
"Char Left ^A",
"Char Right ^D",
"Line Up ^E",
"Line Down ^X",
"Word Left ^W",
"Word Right ^F",
"Prev Page ^R",
"Next Page ^B",
"Begin of line Home",
"End of line End",
"Top of file F5",
"End of file F6",
"Top of screen F8",
" Search ",
"Search string F7",
" Delete ",
"Char left ^H or <BS>",
"Under cursor ^G or <Del>",
"Line ^Y",
"To end of line ^K",
" Other ",
"Redraw screen ^]",
"Quote next char ^V",
"Save file F2",
"Exit ^C",
" Modes ",
"Raw mode F3",
"Visible spaces F9",
0,
};
static struct helptab edittab [] = {
{ 1, 0, 0, 0 },
{ 3, 2, 1, 0 },
{ 4, 6, 0, 0 },
{ 5, 6, 0, 0 },
{ 6, 6, 0, 0 },
{ 7, 6, 0, 0 },
{ 8, 6, 0, 0 },
{ 9, 6, 0, 0 },
{ 10, 6, 0, 0 },
{ 11, 6, 0, 0 },
{ 12, 6, 0, 0 },
{ 13, 6, 0, 0 },
{ 14, 6, 0, 0 },
{ 15, 6, 0, 0 },
{ 16, 6, 0, 0 },
{ 17, 2, 1, 0 },
{ 18, 6, 0, 0 },
{ 3, CS+ 2, 1, 0 },
{ 4, CS+ 6, 0, 0 },
{ 5, CS+ 6, 0, 0 },
{ 6, CS+ 6, 0, 0 },
{ 7, CS+ 6, 0, 0 },
{ 9, CS+ 2, 1, 0 },
{ 10, CS+ 6, 0, 0 },
{ 11, CS+ 6, 0, 0 },
{ 12, CS+ 6, 0, 0 },
{ 13, CS+ 6, 0, 0 },
{ 15, CS+ 2, 1, 0 },
{ 16, CS+ 6, 0, 0 },
{ 17, CS+ 6, 0, 0 },
{ 0, 0, 0, 0 },
};
static char *viewmesg [] = {
"The Demos Commander Viewer, Copyright (C) 1990-1997 Serge Vakulenko",
" Cursor Movement ",
"Page Left ^A",
"Page Right ^D",
"Line Up ^E",
"Line Down ^X",
"Prev Page ^R",
"Next Page ^B",
"Top of file Home or F5",
"End of file End or F6",
" Search ",
"Search string F7",
" Other ",
"Redraw screen ^]",
"Exit ^C",
" Modes ",
"Raw mode F3",
"Visible spaces F9",
"Lines longer than 1024 bytes",
"are broken and marked with \"\\\"",
"Spaces are displayed as \".\"",
"and tabs as \"_\"",
0,
};
static struct helptab viewtab [] = {
{ 1, 0, 0, 0 },
{ 3, 3, 1, 0 },
{ 5, 7, 0, 0 },
{ 6, 7, 0, 0 },
{ 7, 7, 0, 0 },
{ 8, 7, 0, 0 },
{ 9, 7, 0, 0 },
{ 10, 7, 0, 0 },
{ 11, 7, 0, 0 },
{ 12, 7, 0, 0 },
{ 15, 3, 1, 0 },
{ 17, 7, 0, 0 },
{ 3, CS+ 3, 1, 0 },
{ 5, CS+ 7, 0, 0 },
{ 6, CS+ 7, 0, 0 },
{ 9, CS+ 3, 1, 0 },
{ 11, CS+ 7, 0, 0 },
{ 12, CS+ 7, 0, 0 },
{ 15, CS+ 3, 0, 0 },
{ 16, CS+ 3, 0, 0 },
{ 17, CS+ 3, 0, 0 },
{ 18, CS+ 3, 0, 0 },
{ 0, 0, 0, 0 },
};
static char *hviewmesg [] = {
"The Demos Commander Hexadecimal Viewer, Copyright (C) 1990-1997 Serge Vakulenko",
" Cursor Movement ",
"Page Left ^A",
"Page Right ^D",
"Line Up ^E",
"Line Down ^X",
"Prev Page ^R",
"Next Page ^B",
"Top of file Home or F5",
"End of file End or F6",
" Search ",
"Search string F7",
" Other ",
"Redraw screen ^]",
"Exit ^C",
" Modes ",
"Raw mode F3",
"Visible spaces F9",
"Spaces are displayed as \".\"",
"and tabs as \"_\"",
"For hexadecimal search",
"type char codes as \"\\xx\"",
0,
};
static struct helptab hviewtab [] = {
{ 1, 0, 0, 0 },
{ 3, 3, 1, 0 },
{ 5, 7, 0, 0 },
{ 6, 7, 0, 0 },
{ 7, 7, 0, 0 },
{ 8, 7, 0, 0 },
{ 9, 7, 0, 0 },
{ 10, 7, 0, 0 },
{ 11, 7, 0, 0 },
{ 12, 7, 0, 0 },
{ 15, 3, 1, 0 },
{ 17, 7, 0, 0 },
{ 3, CS+ 3, 1, 0 },
{ 5, CS+ 7, 0, 0 },
{ 6, CS+ 7, 0, 0 },
{ 9, CS+ 3, 1, 0 },
{ 11, CS+ 7, 0, 0 },
{ 12, CS+ 7, 0, 0 },
{ 15, CS+ 3, 0, 0 },
{ 16, CS+ 3, 0, 0 },
{ 17, CS+ 3, 0, 0 },
{ 18, CS+ 3, 0, 0 },
{ 0, 0, 0, 0 },
};
static struct help help [] = {
{ "general", gentab, genmesg },
{ "edit", edittab, editmesg },
{ "view", viewtab, viewmesg },
{ "hexview", hviewtab, hviewmesg },
{ 0, 0, 0 },
};
struct help *findhelp (char *name)
{
register struct help *p;
for (p=help; p->name; ++p)
if (! strcmp (p->name, name))
return (p);
return (0);
}
void genhelp ()
{
runhelp ("general");
}
void runhelp (char *name)
{
register r, c, w, h;
BOX *box;
register struct helptab *p;
struct help *hp;
hp = findhelp (name);
if (! hp)
return;
p = hp->htab;
if (! p->str)
inithelp (hp);
w = 72;
h = 21;
r = 2;
c = 4;
box = VGetBox (r, c-1, h, w+2); /* save box */
VStandOut ();
VSetDim ();
VFillBox (r, c-1, h, w+2, ' '); /* clear */
VDrawBox (r, c, h, w); /* draw margins */
VMPutString (r, c + (w-6) / 2, " Help "); /* head */
for (; p->row; ++p) {
if (p->row >= h)
continue;
if (p->bold) {
VSetBold ();
VStandEnd ();
}
if (! p->col)
VMPutString (r+p->row, c + (w-strlen(p->str))/2, p->str);
else
VMPutString (r+p->row, c + p->col, p->str);
if (p->bold) {
VSetDim ();
VStandOut ();
}
}
VStandEnd ();
VSetNormal ();
for (;;) {
hidecursor ();
VSync ();
switch (KeyGet ()) {
default:
break;
case cntrl (']'): /* redraw screen */
VRedraw ();
continue;
}
break;
}
VUngetBox (box);
VFreeBox (box);
}
static int findhelpfile (char *filename, char *name, char *dir)
{
register char *s;
s = filename; /* build dir/name */
strcpy (s, dir);
s += strlen (s);
switch (lang) {
case ENG: *s++ = 'e'; *s++ = '.'; break;
case RUS: *s++ = 'r'; *s++ = '.'; break;
case UKR: *s++ = 'u'; *s++ = '.'; break;
case DEU: *s++ = 'd'; *s++ = '.'; break;
case FRA: *s++ = 'f'; *s++ = '.'; break;
}
strcpy (s, name);
return (! access (filename, 4)); /* can I read it ? */
}
static void inithelp (struct help *hp)
{
register struct helptab *p;
register n, fd;
register char **q;
char filename [60];
char buf [1024];
if (! findhelpfile (filename, hp->name, LCLHELPDIR))
findhelpfile (filename, hp->name, HELPDIR);
fd = open (filename, 0);
if (fd >= 0) {
n = read (fd, buf, sizeof (buf) - 1);
if (n > 0) {
buf [n] = 0;
initnewhelp (hp->mesg, mdup (buf));
}
close (fd);
}
q = hp->mesg;
for (p=hp->htab; p->row && *q; ++p, ++q)
p->str = *q;
}
static void initnewhelp (char **q, char *p)
{
for (; *q; ++q) {
for(*q=p; *p && *p != '\n'; ++p)
if (*p == '@')
*p = ' ';
if (! *p)
break;
*p++ = 0;
}
*q = 0;
}