-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvx_cfg.c
700 lines (612 loc) · 16.4 KB
/
tvx_cfg.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/* -------------------------- tvx_cfg.c --------------------------- */
#include "tvx_defs.ic"
#define BL remark("")
char synofr[20] = /* from table */
{' ',13,']',000,000,000,000,000,000,000,00,00,00,00,00,00,00,00,00,00};
char synoto[20] = /* translate to table */
{'r','d','{',00,000,0,000,00,00,000,00,00,00,00,00,00,00,00,00,00};
char funkey = 0; /* leading char for function key */
char funchar[50] = /* code sent by function key */
{
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
};
char funcmd[50] = /* equivalent command */
{
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
};
/* define standard command set */
char lexsym[LEXVALUES+1] = { E0, 'r', 'l', 'd', 'u',
4, 21, 8, 'k', 'i', 11, '"', '\'', ',', '.', 'f', 6, 'p',
'b', 'e', 2, 'v', 'o', '/', 's', 'g', 23, 25, 24, ';', '&',
'm', ':', '=', 7, 9, '{', 'a', 16, '?', 'h', 20, 'c', 'j', 't',
'n', 14, 15, 5, 18, '#', '*', '(', ')','~' };
char autoin, dsplin, scroll, xcases, warplm, wildch, funesc, cut_mode;
char rp[80];
FILE *f, *fopen();
char cupper(), clower();
main()
{
SLOW int i, val, retcode;
cls();
remark("Standard TVX define a configuration file -- Version 2/27/86");
BL;
for (;;)
{
prompt("Enter name of file to save configuration in: ");
reply(rp,79);
if ((f = fopen(rp,FILEWRITE)) == 0)
continue;
else
break;
}
cls();
shoset();
BL;
for (;;)
{
BL;
prompt("Use standard command definitions? (y/n) ");
lreply(rp,10);
if (*rp == 'y')
{
goto LEXDONE;
}
else if (*rp == 'n')
break;
}
CMDAGAIN:
retcode = 1; /* start with things ok */
for (;;)
{
short_cls();
shoset();
if (retcode < 0)
remark("Invalid value supplied for new command. Try again!");
if ((retcode = set()) == 0)
break;
}
short_cls();
shoset();
remark("");
prompt("Are you finished setting commands? (y/n) ");
ureply(rp,2);
if (*rp != 'Y')
goto CMDAGAIN;
LEXDONE:
for (i=0 ; i <= LEXVALUES ; ++i) /* write out lex symbols */
{
fputc(lexsym[i],f); /* write to file */
}
syno();
funkeys();
cls();
prompt("Use autoindent (n default) (y/n): ");
lreply(rp,10);
if (*rp == 'y')
fputc(1,f);
else
fputc(0,f);
BL;
prompt("Home display line: (1-66, 16 default): ");
rdint(&val);
if (val > 66 || val <= 0)
fputc(16,f);
else
fputc(val,f);
BL;
prompt("Scroll window (0 default): ");
rdint(&val);
if (val > 24)
val = 0;
fputc(val,f);
BL;
prompt("Find case (e=exact,a=any, any default): ");
lreply(rp,10);
if (*rp == 'e')
fputc(1,f);
else
fputc(0,f);
BL;
prompt("Auto line wrap width (0 default): ");
rdint(&val);
if (val > 79)
val = 0;
fputc(val,f);
BL;
prompt("Use wild cards (y default) (y/n)? ");
lreply(rp,10);
if (*rp == 'n')
fputc(0,f);
else
fputc(1,f);
BL;
prompt("Use BACKUP.LOG file (n default) (y/n)? ");
lreply(rp,10);
if (*rp == 'y')
fputc(1,f);
else
fputc(0,f);
BL;
prompt("Use 'cut mode' (killed lines to save buffer too)? (n default) (y/n)? ");
lreply(rp,10);
if (*rp == 'y')
fputc(1,f);
else
fputc(0,f);
#ifdef MSDOS
BL;
remark("The editor can recognize Ctrl-z as EOF, or it can ignore ^Z and");
remark("just use the standard MS-DOS end of file mark.");
prompt("Should the editor recognize Ctrl-Z as EOF? (n default) (y/n) ");
lreply(rp,10);
if (*rp == 'y')
fputc(1,f);
else
fputc(0,f);
#endif
#ifdef GEMDOS
fputc(1,f); /* use ^Z on gemdos by default */
#endif
cls();
remark("Configuration file created.");
fclose(f);
}
/* =============================>>> SHOSET <<<============================= */
shoset()
{ /* show repeat buffer, help if available */
static char rp[2];
FAST int i;
SLOW char *cp, *msg;
SLOW int fields, oldtty, hnum;
SLOW unsigned tmp;
struct help_msg
{
char *hmsg;
char Vmsg;
};
static struct help_msg cmddes[] = /* messages for help */
{
{"nApnd to sv buff", VSAPPEND}, {" Buffer beg ", VTOP},
{" File beg", VFBEGIN}, {"nChange chars ", VCHANGE},
{"nDown line ", VDOWNLINE},{"nDown column", VDOWNCOL},
{" Buffer end ", VBOTTOM}, {"nEdit rpt buffer", VEDITRPT},
{"nFind", VSEARCH}, {" Find cross-buff", VNEXT},
{" Get save buffer", VGET}, {" Unkill lastline", VUNKILL},
{"nHalf page ", VHALFP}, {"nInsert (to ESC)", VINSERT},
{" Jump back", VJUMP}, {"nKill character ", VDELNEXT},
{"nKill line ", VKILLALL}, {"nLeft", VLEFT},
{" Memory status ", VMEMORY}, {"nNote location ", VNOTELOC},
{"nReset loc", VRETNOTE}, {"nOpen line ", VOPENLINE},
{" Call Opr system", VSYSTEM}, {"nPage", VFLIP},
{" Print screen ", VPRINTS}, {"nRight ", VRIGHT},
{" Restore rpt buf", VSTORERPT},{"nSave lines ", VSAVE},
{"nTidy, fill text", VTIDY}, {" Abort", VABORT},
{"nUp ", VUPLINE}, {"nUp column ", VUPCOL},
{" Verify screen", VVERIFY}, {"nWrite buffer ", VWPAGE},
{" Exit, end edit ", VQUIT}, {"nYank file", VYANK},
{"nDel prev char ", VDELLAST}, {"nFind again ", VSAGAIN},
{" Del last", VREMOVE}, {" Change last ", VRMVINS},
{" Del to line beg", VKILLPREV},{" Del to line end", VKILLREST},
{" Line begining ", VBEGLINE}, {" Line end ", VENDLINE},
{"nWord right", VMVWORD}, {"nWord left ", VMVBWORD},
{"nRepeat again ", VXREPEAT}, {"nk Exec rpt k n times",VEXECRPT},
{"n p Set param p ", VSETPARS}, {" Help ", VHELP},
{" Insert find pat", VINSPAT},{"nChange case ",VFOLDCASE},
{"/",0} /* last variable entry */
};
remark("Commands settable by this program: (n => count allowed):");
for (hnum = fields = 0 ; ; ++hnum )
{
prompt(" ");
cp = cmddes[hnum].hmsg;
if (*cp == '/') /* end of variable list */
break;
else
shocout(*cp); /* show n or blank */
msg = ++cp; /* where message is, skipping 'n' field */
while (*cp) /* ship to lex value */
++cp;
i = cmddes[hnum].Vmsg; /* get the lexical index */
shocout(cupper(lexsym[i])); /* show the command */
if (lexsym[i] >= ' ')
shocout(' '); /* skip space for no '^' */
shocout(' '); /* space to separate */
prompt(msg); /* and show the message */
if (++fields == 3) /* bump fields, see if need newline */
{
fields = 0;
remark("");
}
}
remark("");
remark("Note: <> repeat, @ command file, and ESCAPE cannot be changed.");
}
/* =============================>>> SHOCOUT <<<============================= */
shocout(c)
char c;
{
if (c < ' ')
{
printf("^%c",c + '@');
}
else
printf("%c",c);
}
/* ===============================>>> FUNKEYS <<<========================*/
funkeys()
{
SLOW int j,i,val;
SLOW int fun;
FAGAIN:
cls();
remark("You may now define up to 49 function keys to be translated to");
remark("commands OR letters. This translation will take place before");
remark("the editor gets the character at any level -- thus the translation");
remark("will apply equally to command mode and insert mode. The translation");
remark("assumes each function key generates a 2 character sequence. The");
remark("first character is an 'escape' character that must be the same for");
remark("each key. If the 'escape' character is really ESC, then you must");
remark("also define one function key to have ESC as its translation value.");
remark("When asked for the function key, simply press the key, followed by");
remark("RETURN. Enter either the character or decimal value of the translation.");
for (i = 0 ; i < 50 ; ++i)
{
funchar[i] = funcmd[i] = 0;
}
BL;
prompt("Do you want to define any function keys? (y/n) ");
lreply(rp,10);
if (*rp == 'n')
goto WTFUN;
BL;
remark("Now, please press ANY function key so the program can identify");
prompt("the 'function key escape' code (followed by a RETURN): ");
reply(rp,10);
funesc = *rp; /* this should be the escape char */
if (funesc == 27)
{
BL;
remark("IMPORTANT: You MUST define a function key to send an ESCAPE (decimal 27).");
remark("If you don't, then you won't be able to end insert mode or repeat loops.");
remark("The program doesn't have logic to make sure you do this, so don't forget!");
BL;
}
for (i = 0 ; i < 50 ; ++i)
{
FUNAGAIN:
prompt("Press function key to define (RETURN only to exit): ");
rp[1] = 0;
reply(rp,10);
fun = rp[1];
if (rp[1] == 0)
break;
for (j = 0 ; j < 50 ; ++j)
{
if (fun == funchar[j])
{
remark("That's been used already, try again.");
goto FUNAGAIN;
}
}
funchar[i] = fun;
prompt("Now enter the character/command it gets translated to: ");
reply(rp,10);
val = getval(rp);
funcmd[i] = val;
}
cls();
remark("Functions have been defined. You can start over if you made any mistakes.");
remark("");
prompt("Are they ok? (y/n) ");
lreply(rp,10);
if (*rp == 'n')
goto FAGAIN;
WTFUN:
for (i = 0 ; i < 50 ; ++i)
{
fputc(funchar[i],f);
}
for (i = 0 ; i < 50 ; ++i)
{
fputc(funcmd[i],f);
}
fputc(funesc,f);
}
/* ===============================>>> GETVAL <<<========================*/
getval(str)
char *str;
{
/* return one byte value */
if (*str >= '0' && *str <= '9')
return (atoi(str));
else
return (*str & 0377);
}
/* ===============================>>> SET <<<========================*/
set()
{
/* set newlex[indx] to a new value */
SLOW int val,i, oldi;
SAGAIN:
prompt("Enter current command to change (key or decimal value, RETURN to exit) ");
reply(rp,10);
val = clower(getval(rp));
if (val == 0)
{
return 0;
}
for (oldi = 1 ; oldi <= LEXVALUES ; ++oldi)
{
if (val == lexsym[oldi])
{
goto HAVEIT;
}
}
return -1;
HAVEIT:
prompt("Enter NEW command (key or decimal value, RETURN to exit) ");
reply(rp,10);
val = clower(getval(rp));
if (val == 0 || val == '@' || val == 27 || val == '<' || val == '>')
return -1;
for (i = 1 ; i <= LEXVALUES ; ++i)
{
if (val == lexsym[i])
{
return -1; /* duplicate */
}
}
lexsym[oldi] = val;
return 1;
}
/* ===============================>>> SYNO <<<========================*/
syno()
{
SLOW int j, i, valfrom, valto, found;
SAGAIN:
cls();
remark("You may now define up to 19 synonyms. For example, you might");
remark("want to define a space to be a synonym for right, or RETURN");
remark("the same as down. You must use unused values, however. You");
remark("can't use a existing command as a synonym. You may enter the");
remark("character followed by a RETURN, or the decimal value of the key.");
for (i = 0 ; i < 20 ; ++i)
{
synofr[i] = synoto[i] = 0;
}
for (i = 0 ; i < 19 ; ++i)
{
SYNAGAIN:
BL;
prompt("Enter the new synonym (RETURN when done): ");
reply(rp,10);
valfrom = getval(rp);
if (valfrom == 0)
break;
for (j = 1 ; j <= LEXVALUES ; ++j)
{
if (lexsym[j] == valfrom)
{
remark("That is already a command! Try again.");
goto SYNAGAIN;
}
}
prompt("Enter the equivalent command: ");
reply(rp,10);
valto = getval(rp);
for (j = 1, found = FALSE ; j <= LEXVALUES ; ++j)
{
if (lexsym[j] == valto)
found = TRUE;
}
if (!found)
{
remark("That is not a defined command. Try again.");
goto SYNAGAIN;
}
synofr[i] = valfrom;
synoto[i] = valto;
}
cls();
remark("Synonyms have been defined. You can start over if you made any mistakes.");
remark("");
prompt("Are they ok? (y/n) ");
lreply(rp,10);
if (*rp == 'n')
goto SAGAIN;
for (i = 0 ; i < 20 ; ++i)
fputc(synofr[i],f);
for (i = 0 ; i < 20 ; ++i)
fputc(synoto[i],f);
}
/* ===============================>>> CLS <<<========================*/
cls()
{
int i;
for (i = 0 ; i < 25 ; ++i)
remark("");
}
/* ===============================>>> short_CLS <<<========================*/
short_cls()
{
int i;
for (i = 0 ; i < 10 ; ++i)
remark("");
}
#define EXTENDED /* my own extended lib functions */
/* #define STANDARD /* the set of standard functions i use */
#define LOCAL static /* make all local globals, i think */
#ifdef EXTENDED
/*=============================>>> CLOWER <<<================================*/
char clower(ch)
char ch;
{
return ((ch >='A' && ch<='Z') ? ch + ' ' : ch);
}
/*=============================>>> CUPPER <<<================================*/
char cupper(ch)
char ch;
{
return ((ch >= 'a' && ch <= 'z') ? ch - ' ' : ch);
}
/* =========================>>> LOWER <<<==============================*/
lower(str)
char str[];
{
SLOW int i;
for (i=0 ; str[i] ; ++i)
str[i]=clower(str[i]);
}
/*=============================>>> PROMPT <<<================================*/
prompt(msg)
char msg[];
{
printf("%s",msg);
}
/*=============================>>> REMARK <<<================================*/
remark(msg)
char msg[];
{
printf("%s\n",msg);
}
/*=============================>>> UPPER <<<================================*/
upper(str)
char str[];
{
static int i;
for (i=0 ; str[i] ; ++i)
str[i]=cupper(str[i]);
}
/*=============================>>> LREPLY <<<================================*/
lreply(msg,maxc)
char msg[];
int maxc;
{
reply(msg,maxc);
lower(msg);
}
/*=============================>>> UREPLY <<<================================*/
ureply(msg,maxc)
char msg[];
int maxc;
{
reply(msg,maxc);
upper(msg);
}
/*=============================>>> REPLY <<<================================*/
reply(msg,maxc)
char msg[];
int maxc;
{
#ifdef UNIX
gets(msg);
#else
mreply(msg,maxc);
#endif
}
/*=============================>>> RDINT <<<================================*/
rdint(val)
int *val;
{
char chrrep[12];
reply(chrrep,11);
*val = atoi(chrrep);
}
#endif
#ifndef UNIX
/*=============================>>> MREPLY <<<================================*/
mreply(msg,maxc)
char msg[];
int maxc;
{
#define CBS 8 /* Backspace */
#define CDL1 21 /* ^U */
#define CDL2 24 /* ^X */
#define CABORT 3 /* ^C */
#define CRET 13 /* cr */
#define BACKSPACE 8
static char ch, rp;
static int i;
for (i = 0 ; i < maxc ; ) /* i -> next char */
{
ch = ttrd_(); /* read the character */
if (ch == CBS) /* back space */
{
if (i > 0) /* must be something to delete */
{
--i; /* wipe out char */
ttwt_(BACKSPACE); ttwt_(' '); ttwt_(BACKSPACE);
if (msg[i] < ' ') /* double echo ^ chrs */
{
ttwt_(BACKSPACE); ttwt_(' '); ttwt_(BACKSPACE);
}
}
}
#ifdef USE_WIPE
else if (ch == CDL1 || ch == CDL2) /* wipe whole line */
{
i = 0; /* set for loop ++ */
remark("#");
prompt("Re-enter? ");
}
#endif
else if (ch == CABORT)
{
remark("^C");
prompt("Exit to operating system - are you sure? (y/n) ");
rp = ttrd_();
if (rp == 'y' || rp =='Y')
{
remark("y");
exit(0);
}
remark("n");
msg[i] = 0;
prompt("Re-enter? "); prompt(msg); /* re-echo */
}
else if (ch == CRET) /* ret, so done */
{
remark("");
msg[i] = 0;
return;
}
else
{
msg[i++] = ch;
msg[i] = 0; /* always 0 terminate */
if (ch < ' ')
{
ch += '@';
ttwt_('^');
}
ttwt_(ch); /* echo char */
}
} /* end for */
remark("");
}
/*=============================>>> ttrd_ <<<================================*/
ttrd_()
{
#ifdef MSDOS
return (bdos(7,-1) & 0377);
#endif
#ifdef GEMDOS
return (gemdos(7) & 0377);
#endif
}
/*=============================>>> ttwt_ <<<================================*/
ttwt_(c)
char c;
{
fprintf(stderr,"%c",c);
}
#endif
/* -------------------------- tvx_cfg.c --------------------------- */