forked from ogdenpm/aedit-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macrof.c
1538 lines (1185 loc) · 43.9 KB
/
macrof.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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// #SMALL
// #title ('MACROF process MACRO FILE')
/*********************************************************************
* INTEL CORPORATION PROPRIETARY INFORMATION *
* This software is supplied under the terms of a license agreement *
* or nondisclosure agreement with Intel Corporation and may not be *
* copied or disclosed except in accordance with the terms of that *
* agreement. *
*********************************************************************/
#include "oscompat.h"
#include <string.h>
#include "lit.h"
#include "type.h"
#include "data.h"
#include "proc.h"
static void Macro_null();
static void Macro_save();
static void Macro_create();
static void Macro_get();
static void Macro_list();
static void Macro_insert();
/*
* Begin iRMX II.4 Fix, Part 4 of 8, 12/28/88
* Feature addition allowing aedit to capture CLI terminal name and then read
* :config:termcap for initial terminal configurations based on this name.
*/
/*
* End iRMX II.4 Fix, Part 4 of 8
*/
extern byte memory[memory_leng];
logical check_for_run_keys = { _TRUE };
/* Re-Used Strings */
byte bad_command[] = { "\xb" "bad command" };
byte bad_hex_value[] = {"\xd" "bad hex value" };
byte no_such_macro[] = { "\xd" "no such macro" };
/* LOCALS USED DURING MACROFILE PROCESSING */
/* THE MACROS ARRAY COMTAINS ALL CURRENT MACRO DEFINITIONS */
/* EACH MACRO HAS THE FOLLOWING:
BYTE LENGTH OF MACRO NAME.
BYTES MACRO NAME.
WORD LENGTH OF MACRO TEXT.
BYTES MACRO TEXT. */
/* THE FOLLOWING IS A DUMMY MACRO CONTAINING ONLY THE ESCAPE CODE */
/* IT IS USED WHEN MACROS ARE EXECUTING AND A MOVE OFF OF THE END */
/* OF TEXT OR SIMILAR STOPPER IS ENCOUNTERED. ITS USE HAS THE EFFECT OF */
/* ENDING ANY MODE. */
struct {
word len;
byte contents;
} escape = { 1, esc_code };
logical next_char_is_escape = { _FALSE };
pointer macros = memory; /* CONTAINS MACROS - memory is allocated statically */
word macro_buf_size = { 3072 };
pointer macro_at; /* USEFUL POINTER TO MACRO LENGTHS */
#define macro_name_length (*macro_at) /* USED TO GET MACRO TEXT LENGTHS */
#define macro_text_length (*(wpointer)macro_at) /* USED TO GET MACRO NAME LENGTHS */
pointer macro_end = memory; /* NEXT FREE BYTE OF MACROS */
pointer macro_next; /* ADDRESS OF NEXT BYTE TO PLUCK FROM MFILE */
pointer macro_last; /* ADDRESS 1 PAST END OF CURRENT BUFFER */
word macro_line = 0; /* MACRO FILE LINE NUMBER */
boolean macro_fail = _FALSE;
byte found_em; /* !!! CAUTION: 0FFH if found \MM, 1 if found \EM, else 0 */
macrotext_t *new_macro; /* IF IN_MACRO THEN THIS POINTS TO THE
WORD THAT DEFINES THE NEW MACRO'S TEXT LENGTH */
boolean creating = { _FALSE }; /* TRUE when creating interactively. */
/* EIGHT LEVEL STACK ALLOWS 8 LEVELS OF MACRO EXECUTION NESTING */
/* MACRO_EXEC_LEVEL CONTAINS THE NUMBER OF THE CURRENT LEVEL */
macrotext_t *macro_exec_pointer[9]; /* POINT TO MACRO_TEXT_LENGTH BYTES FOR EACH LEVEL */
word macro_exec_length[9]; /* NUMBER OF WORDS USED UP AT EACH LEVEL */
word macro_exec_count[9]; /* NUMBER OF TIMES TO REPEAT MACRO AT A LEVEL*/
byte macro_exec_infinite[9]; /* whether or not count is infinite */
byte macro_end_state[9]; /* STATE TO RETURN TO ON END (I,X,NULL) */
dword cnt_exe[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* execution counter. size is 10 to save a check in macro_add_level.*/
boolean go_flag[9];
word namepair;
dispatch_t m_dispatch[8] = {
esc_code, Macro_null,
CONTROLC, Macro_null,
'C', Macro_create,
'G', Macro_get,
'I', Macro_insert,
'L', Macro_list,
'S', Macro_save,
0, 0 };
byte no_more_room[] = { "\x17" "no more room for macros" };
byte create_while_exec[] = { "\x37" "macro redefinition is forbidden while executing a macro" };
byte state = { 0 };
logical dont_double_backslash = { _FALSE };
boolean null_macro_filename = { _FALSE };
/* if there is an INIT macro, print the banner when it terminates. */
boolean do_print_banner;
/* ADDS 'error in nnn ' TO START OF ERROR MESSAGE AND THEN PRINTS IT.
ALL ERRORS DETECTED DURING MACROFILE PROCESSING ARE PRINTED THIS WAY. */
void Macro_file_error(pointer string) {
pointer prev_char_ptr;
byte ch;
byte macro_error_string[81];
Init_str(macro_error_string, sizeof(macro_error_string));
Add_str("error in line ");
Add_str_num(macro_line, 10); /* Line number */
Add_str(": ");
Add_str_str(string);
error_status.from_macro_file = _TRUE;
Error(macro_error_string);
error_status.from_macro_file = _FALSE;
if (!error_status.key_was_space) {
macro_fail = _TRUE;
return;
}
prev_char_ptr = macro_next - 1;
if (*prev_char_ptr != ';' && *prev_char_ptr != CR) {
while ((ch = Macro_not_blank()) != ';') { /* scan till semicolon */
if (macro_fail) return;
}
}
} /* macro_file_error */
byte bad_msg[] = { "\x0c" "bad __ value" };
static void Bad_value(pointer p) {
bad_msg[5] = p[0];
bad_msg[6] = p[1];
Macro_file_error(bad_msg);
} /* bad_value */
/*
MACRO_BYTE RETURN NEXT RAW BYTE FROM MACRO FILE.
SET MACRO_EOF IF END OF FILE IS DETECTED.
WHEN MACRO_EOF SET THEN RETURN 0FFH AS
CALLERS WILL EVENTUALLY FIGURE OUT THAT
SOMETHING IS NOT RIGHT. NOTICE THAT
ROUTINE IS WRITTEN SO THAT CALLERS
CAN BACK UP ONCE BY DECREMENTING
MACRO_NEXT.
*/
byte Macro_byte() {
byte ch;
if (macro_fail) return 0xff;
/* IF CURRENT BUFFER IS EMPTY, ATTEMPT TO REFILL */
if (macro_next == macro_last) {
if (!null_macro_filename) {
macro_next = oa.low_e;
macro_last = oa.low_e + Macro_file_read(); /*macro_file_read in io.plm*/
}
else {
if (macro_next == oa.low_e) {
macro_next = oa.high_s; /* NEED PORTION ABOVE WINDOW */
macro_last = oa.high_e - 1; /* ASSUME AT EOF */
}
}
if (macro_next == macro_last) {
macro_fail = found_em = _TRUE;
return 0xff;
}
}
/*
* Begin iRMX II.4 Fix, Part 5 of 8, 12/28/88
* Feature addition allowing aedit to capture CLI terminal name and then read
* :config:termcap for initial terminal configurations based on this name.
*/
/*
* End iRMX II.4 Fix, Part 5 of 8
*/
ch = *macro_next;
if (ch == LF)
macro_line++;
macro_next++;
return ch;
} /* macro_byte */
/* PROCESS$MACRO$COMMENT loop until EOF or a *\
If EOF found first, issue error
message and return 0FFH
*/
static void Process_macro_comment() {
byte ch, ch2;
ch = 0;
/* Scan for matching '*\' */
for (;;) {
ch2 = Macro_byte();
if (ch == '*' && ch2 == '\\')
return;
ch = ch2;
if (macro_fail) {
Macro_file_error("\xc" "missing '*\\'");
return;
}
}
} /* process_macro_comment */
/*
MACRO_CHAR THIS ROUTINE RECOGNISES THE FUNNY MACRO
FILE CHARACTERS SUCH AS \0D AND \CU.
IT RETURNS THE NEXT CHARACTER. CR AND
LF ARE IGNORED.
*/
static byte Macro_char() {
byte ch, ival;
wbyte i;
next_macro_char:
ch = Macro_byte();
while (ch == LF || ch == CR) {
ch = Macro_byte();
}
if (ch == '\\') { /* '\' IS LEAD IN FOR STRANGE CHARS */
ch = Macro_byte();
if (ch == '\\') { /* COULD BE DOUBLED '\' */
/* do nothing */
}
else if (ch == '*') { /* Macro Comment */
Process_macro_comment();
if (macro_fail)
return 0xff;
goto next_macro_char;
}
else if (ch == '0') { /* A HEX VALUE */
/* FIRST CHARACTER MUST BE VALID HEX */
if ((ival = Hex_value(Macro_byte())) == not_hex) {
Macro_file_error(bad_hex_value);
macro_fail = _TRUE;
return 0xff;
}
/* SECOND MAY BE HEX OR NOT HEX. BACKUP IF NOT */
if ((ch = Hex_value(Macro_byte())) == not_hex)
macro_next--;
else
ival = (ival << 4) + ch;
return ival;
}
else {
/* OR IS \CU, \CH ETC. */
/* SET NAME_WORD TO THE NEXT TWO CHARACTERS */
namepair = CHAR2(Upper(ch), Upper(Macro_byte()));
/* SEARCH NAMES OF INPUT CODES */
for (i = 0; i <= last(input_code_names); i++) {
if (input_code_names[i] == namepair)
return first_code + i;
}
switch (namepair) {
case CHAR2('T', 'B'): return TAB;
case CHAR2('N', 'L'): return CR;
case CHAR2('E', 'M'): found_em = 1; return 0; // end of macro definition
case CHAR2('M', 'M'): found_em = _TRUE; return 0; // end of modeless macro definition
}
Macro_file_error("\xc" "bad '\\' code");
macro_fail = _TRUE;
ch = 0xff;
}
}
return ch;
} /* macro_char */
/* RETURN THE NEXT NON-BLANK MACRO_BYTE.
CHANGE CR TO ';' AND LOWER TO UPPER CASE. */
static byte Macro_not_blank() {
byte ch;
read_next:
ch = Macro_byte();
if (ch == ' ' || ch == CR || ch == TAB) goto read_next;
if (ch == '\\') { /* comment */
Process_macro_comment();
if (macro_fail)
return 0xff;
goto read_next;
}
if (ch == LF)
ch = ';'; /* CHANGE LF TO ';' */
return Upper(ch);
} /* macro_not_blank */
/*
NOT_EQUAL TRIVIAL ROUTINE TO SEE IF '=' IS THE
NEXT MACRO CHARACTER.
*/
static byte Not_equal() {
byte ch;
ch = Macro_not_blank();
if (ch == '=')
return _FALSE;
Macro_file_error("\xb" "missing '='");
return _TRUE;
} /* not_equal */
/*
NOT_SEMI_COLON TRIVIAL ROUTINE TO SEE IF ';' IS THE
NEXT MACRO CHARACTER.
*/
static byte Not_semi_colon() {
byte ch;
ch = Macro_not_blank();
if (ch == ';')
return _FALSE;
Macro_file_error("xb" "missing ';'");
return _TRUE;
} /* not_semi_colon */
/*
MACRO_NUMBER INPUT A BYTE NUMBER FROM MACROFILE.
*/
static word Macro_number() {
byte ch; dword num;
num = 0;
while ((ch = (Macro_not_blank() - '0')) < 10) {
num = num * 10 + ch;
}
macro_next--;; /* we read one char too far; backup */
if (num > 0xffff)
num = 0;
return num;
} /* macro_number */
/*
BAD_HEX INPUTS A ZERO TO FOUR CHARACTER HEX
VALUE INTO SET_AT. IF ERROR FOUND,
RETURNS TRUE AND PRINTS MESSAGE.
*/
static byte Bad_hex(pointer code_p, // destination of hex string
byte max_num, // max length of the input number (in bytes,not digits)
boolean in_place) { // store the string at *code_p even if it is long
byte str[81];
byte ch;
byte i, j;
if (!Not_equal()) { /* NEED = FIRST */
str[0] = 0; /* ACCUMULATE CHARACTERS IN str */
while (Hex_value(ch = Macro_not_blank()) != not_hex && str[0] < 80) {
str[++str[0]] = Hex_value(ch);
}
if (ch == ';') { /* NEED ; AT END OF HEX */
if (str[0] == 0) { /* NULL MEANS FUNCTION NOT AVAILABLE */
code_p[0] = 0;
return _FALSE;
}
if (str[0] == 1) { /* SINGLE CHAR IS OK */
code_p[0] = 1;
code_p[1] = str[1];
return _FALSE;
}
/* else must be even */
if (str[0] <= max_num * 2 && ((str[0] & 1) == 0)) {
if (str[0] <= 8 || in_place) {
code_p[0] = str[0] / 2; /* get the length */
i = 0;
while (i < str[0]) {
code_p++;
code_p[0] = str[++i] << 4;
code_p[0] += str[++i];
}
return _FALSE;
}
else {
i = 0; j = 0;
while (i < str[0]) {
j++;
str[j] = str[++i] << 4;
str[j] = code_p[0] + str[++i]; // possible buf should code_p[0] be str[j]
}
str[0] = str[0] / 2;
Insert_long_config(str, (entry_t *)code_p);
return _FALSE;
}
}
}
}
Macro_file_error(bad_hex_value);
return _TRUE;
} /* bad_hex */
/*
ADD_MACRO_CHAR ADD ONE CHARACTER TO CURRENT MACRO
DEFINITION. PRINT APPROPRIATE
MESSAGE IF NO ROOM LEFT.
*/
boolean Add_macro_char(byte ch) {
if (new_macro->text + new_macro->text_length >= ¯os[macro_buf_size]) {
if (in_macro_def) {
Error(no_more_room);
ms_sleep(3000);
}
else {
Macro_file_error(no_more_room);
}
in_macro_def = _FALSE;
return _FALSE;
}
new_macro->text[new_macro->text_length++] = ch; /* ADD BYTE TO MACRO TEXT */
return _TRUE;
} /* add_macro_char */
/*
FIND_MACRO SEES IF STRING IN INPUT_BUFFER IS
A MACRO NAME. IF TRUE, SETS MACRO_AT TO
WORD CONTAINING LENGTH OF MACRO NAME.
RETURNS TRUE IF MATCH FOUND. */
static byte Find_macro() {
macro_at = macros; /* POINT TO FIRST ENTRY */
while (macro_at < macro_end) { /* SEARCH BUFFER */
if (macro_name_length == input_buffer[0] &&
/* MUST BE SAME LENGTH */
Cmp_name(input_buffer, macro_at))
return _TRUE;
/* AND BE THE SAME */
macro_at += macro_name_length + sizeof(byte);
macro_at += macro_text_length + sizeof(word);
}
return _FALSE;
} /* find_macro */
/*
CAN_ADD_MACRO DELETE OLD MACRO WITH SAME NAME AND
SEE IF SOME ROOM REMAINS FOR ANOTHER
MACRO. RETURN TRUE IF ALL IS OK.
*/
static byte Can_add_macro() {
pointer old;
if (Find_macro()) { /* MUST DELETE OLD MACRO */
if (macro_exec_level != 0) {
/*
Redefinition of an existing macro while executing a macro is
forbidden. If there is an old macro with the same name, then
all the macros that reside in the macro buffer following that
macro will move, including the active ones, and pointers will
be no longer valid.
*/
if (creating)
Error(create_while_exec);
else
Macro_file_error(create_while_exec);
return _FALSE;
}
old = macro_at;
macro_at += macro_name_length + sizeof(byte);
/* GO TO LENGTH OF MACRO TEXT */
macro_at += macro_text_length + sizeof(word);
/* POINTS TO FIRST AFTER OLD ONE */
memcpy(old, macro_at, macro_end - macro_at);
macro_end += old - macro_at;
}
if (macro_end + input_buffer[0] + 20 > macros + macro_buf_size) {
if (creating)
Error(no_more_room);
else
Macro_file_error(no_more_room);
return _FALSE;
}
Move_name(input_buffer, macro_end);
/* PUT NEW NAME IN MACROS */
/* MACRO_END IS LEFT AT THE WORD
THAT SPECIFIES MACRO TEXT LENGTH */
new_macro = (macrotext_t *)(macro_end + input_buffer[0] + 1);
/* USE THIS TO DO THE ADD OF MACRO BYTES */
new_macro->text_length = 0; /* NO TEXT YET */
return _TRUE;
} /* can_add_macro */
/* Find an index for a case statement from a char and a char list;
will return then length of the list if the char is not found. */
byte Find_index(byte ch, pointer chList) {
byte *s;
return (s = memchr(chList + 1, ch, chList[0])) ? (byte)(s - (chList + 1)) : chList[0];
} /* find_index */
static void Process_t_or_f(pointer flag_p, pointer err_p) {
byte i, ch;
i = Not_equal();
ch = Upper(Macro_not_blank());
if (ch == 'T') {
*flag_p = _TRUE;
}
else if (ch == 'F') {
*flag_p = _FALSE;
}
else {
Bad_value(err_p);
return;
}
i = Not_semi_colon();
} /* process_t_or_f */
/*
* Begin iRMX II.4 Fix, Part 6 of 8, 12/28/88
* Feature addition allowing aedit to capture CLI terminal name and then read
* :config:termcap for initial terminal configurations based on this name.
*/
/*
* End iRMX II.4 Fix, Part 6 of 8
*/
/*
MACRO_FILE_PROCEDURES DO THE MANUAL LABOR OF INPUTTING
A MACRO FILE. CALLED FROM START CODE
AS WELL AS FROM MACRO_GET. NAME IS
ALREADY IN MACRO_NAME.
*/
void Macro_file_process() {
byte blankout_code[5];
byte ch; word num;
wbyte i;
macro_line = 1; /* FIRST LINE IS NUMBER 1 */
current_prompt[0] = 0;
/*
* Begin iRMX II.4 Fix, Part 7 of 8, 12/28/88
* Feature addition allowing aedit to capture CLI terminal name and then read
* :config:termcap for initial terminal configurations based on this name.
*/
/*
* End iRMX II.4 Fix, Part 7 of 8
*/
/* IF NO NAME THEN THE PART OF CURRENT BUFFER THAT IS IN MEMORY IS
START OF 'MACROFILE'. THIS IS
'CHEATING' - SPILLED MACRO FILES ARE NOT HANDLED CORRECTLY. HOWEVER
A SPILLED MACRO FILE IS DEGENERATE AND IS EITHER A MILLION BLANKS
OR WILL OVERFLOW THE MACRO BUFFER ANYWAY. */
if (null_macro_filename) {
macro_next = oa.low_s;
macro_last = oa.low_e;
}
else { /* MUST OPEN THE FILE */
macro_next = macro_last; /* FORCE READ ON NEXT MACRO_CHAR CALL */
}
macro_fail = _FALSE;
next_macro_line:
for (;;) {
ch = Macro_not_blank();
if (macro_fail)
return;
switch (ch) {
case 'A': /* Case A */
ch = Upper(Macro_byte());
switch (ch) {
case 'V': /* FOUND A AV */
i = Not_equal();
num = Macro_number();
if (num < 5 || num > 66) {
Bad_value("AV");
}
else {
i = Not_semi_colon();
if (!window_present) {
window.prompt_line = prompt_line = num - 1;
window.message_line = message_line = num - 2;
window.last_text_line = last_text_line = num - 3;
}
}
break;
case 'B': /* FOUND AN AB */
if (Bad_hex(input_codes[esc_code - first_code].code,
4, _FALSE));
break;
case 'O': /* FOUND AN AO */
if (Bad_hex(output_codes[offset_index].code, 4, _FALSE));
break;
case 'R': /* FOUND AN AR */
if (Bad_hex(input_codes[rubout_code - first_code].code, 4, _FALSE));
break;
case 'W': /* FOUND AN AW */
Process_t_or_f(&wrapper, "AW");
break;
case 'X': /* FOUND AN AX */
{
boolean flag;
Process_t_or_f(&flag, "AX");
if (flag)
first_coordinate = col_first;
else
first_coordinate = row_first;
}
break;
case 'F': /* FOUND A ALTER FUNCTION */
/* SET NAME_WORD TO THE NEXT TWO CHARACTERS */
namepair = Upper(Macro_byte());
namepair = CHAR2(namepair, Upper(Macro_byte()));
/* SEE IF IT IS THE BLANKOUT CHARACTER */
switch (namepair) {
case CHAR2('B', 'K'):
if (!Bad_hex(blankout_code, 4, _FALSE)) {
/* THE BLANKOUT CHARACTER IS STORED IN PRINT_AS */
if (blankout_code[0] == 1)
print_as[' '] = blankout_code[1];
}
break;
case CHAR2('C','C'):
/* the ^C replacement character */
if (Bad_hex(cc_code_buf, 4, _FALSE))
;
break;
case CHAR2('S', 'T'):
if (!Bad_hex(input_buffer, 40, _TRUE)) {
if (!batch_mode) {
Print_unconditionally_p(input_buffer);
Co_flush();
}
}
break;
case CHAR2('E', 'N'):
if (Bad_hex(exit_config_list, 40, _TRUE))
;
break;
default:
/* SEE IF AF IS FOR AN INPUT FUNCTION */
for (i = 0; i <= last(input_code_names); i++) {
if (input_code_names[i] == namepair) {
if (Bad_hex(input_codes[i].code, 4, _FALSE))
;
goto next_macro_line;
}
}
/* SEE IF AF IS FOR AN OUTPUT FUNCTION */
for (i = 0; i <= last(output_code_names); i++) {
if (output_code_names[i] == namepair) {
if (Bad_hex(output_codes[i].code, 20, _FALSE))
;
goto next_macro_line;
}
}
/* MATCHES NOTHING - MUST BE ERROR. PRINT MESSAGE
AND KEEP GOING */
Macro_file_error("\xb" "bad AF type");
break;
}
break;
case 'D':
{ /* FOUND A ALTER DELAY TIME */
/* SET NAME_WORD TO THE NEXT TWO CHARACTERS */
word namepair = Upper(Macro_byte());
namepair = CHAR2(namepair, Upper(Macro_byte()));
if (namepair == CHAR2('C','O')) {
ch = Not_equal();
delay_after_each_char = Macro_number();
goto next_macro_line;
}
/* SEE IF AF IS FOR AN OUTPUT FUNCTION */
for (i = 0; i <= last(output_code_names); i++) {
if (namepair == output_code_names[i]) {
ch = Not_equal();
delay_times[i] = Macro_number();
goto next_macro_line;
}
}
/* MATCHES NOTHING - MUST BE ERROR.
PRINT MESSAGE AND KEEP GOING */
Bad_value("AD");
}
break;
case 'I': // invisible attribute
ch = ~visible_attributes;
Process_t_or_f(&ch, "AI");
visible_attributes = ~ch;
break;
case 'C': // character_attribute
Process_t_or_f(&character_attributes, "AC");
break;
case 'H': { // hardware
byte str[10];
byte i, ch;
i = Not_equal();
Init_str(str, 10);
ch = Macro_not_blank();
while (ch != ';' && !macro_fail) {
Add_str_char(ch);
ch = Macro_not_blank();
}
if (str[0] == 0) {
Reset_config();
}
else if (Cmp_name(str, "\x5" "VT100")) {
VT100_setup();
}
else if (Cmp_name(str, "\x4" "ANSI")) {
ANSI_setup();
}
else {
Bad_value("AH");
}
break;
}
case 'S': // prompt
Process_t_or_f(&input_expected_flag, "AS");
if (input_expected_flag)
Set_input_expected('!');
else
Set_input_expected('-');
break;
case 'T': // type ahead
Process_t_or_f(&do_type_ahead, "AT");
break;
case 'Z':
Process_t_or_f(&strip_parity, "AZ");
break;
case 'G': /* Gong */
Process_t_or_f(&bell_on, "AG");
break;
case 'M': /* Max memory allocated by tmpman */
i = Not_equal();
max_tmpman_mem = Macro_number();
break;
default: // default
Macro_file_error(bad_command);
break;
/* default_a_case */
}
// end case 0
break;
case 'S': /* Case 'S' */
/* SET COMMANDS */
if (!Set_from_macro())
;
break;
case 'M': /* Case 'M' */
/* MACRO DEFINITIONS */
input_buffer[0] = 0; /* ACCUMULATE THE MACRO NAME */
ch = Upper(Macro_char());
while (input_buffer[0] <= last(input_buffer) &&
ch != esc_code && !macro_fail) {
input_buffer[++input_buffer[0]] = ch;
ch = Upper(Macro_char());
}
if (ch != esc_code || input_buffer[0] == 0) {
Macro_file_error("\xd" "no macro name");
break;
}
if (Can_add_macro()) {
found_em = 0; /* NOT \EM OR \AM YET */
ch = Macro_char();
while (found_em == 0 && !macro_fail) {
/* QUIT IF RUN OUT OF SPACE */
if (!Add_macro_char(ch)) {
macro_fail = _TRUE; /* abort macro file */
break;
}
/* GET A RAW CHARACTER BUT SKIP CR AND LF */
ch = Macro_char();
}
if (macro_fail)
break;
if (found_em == 0xff) { /* MM, so add return char */
/* else was an AM, so we abort without
returning to previous state */
if (!Add_macro_char(0xff))
break;
}
macro_end = new_macro->text + new_macro->text_length;
}
break;
case ';': /* Case ';' */
/* IGNORE NULL COMMANDS */
break;
case 'D': // debugging not enabled
;
break;
default: /* Default Case */
Macro_file_error(bad_command);
break;
}
}
} /* macro_file_process */
/*
STOP_MACRO DECREMENT COUNT OF CURRENTLY EXECUTING MACROS
IF ANY ARE EXECUTING. CALLED BY BACKUP_CHAR
ETC. WHENEVER AN ATTEMPT IS MADE TO MOVE OFF
THE WORLD. POINT TO SINGLE
ESCAPE CHARACTER TO STOP ANY MODE.
*/
void Stop_macro() {
macrotext_t *temp;
if (macro_exec_level > 0) {
temp = macro_exec_pointer[macro_exec_level];
if (temp->text[temp->text_length - 1] == 0xff)
macro_exec_length[macro_exec_level] = temp->text_length - 1;
else
macro_exec_length[macro_exec_level] = temp->text_length;
macro_exec_count[macro_exec_level] = 1;
macro_exec_infinite[macro_exec_level] = _FALSE;
}
} /* stop_macro */
/*
MACRO_ADD_LEVEL EXECUTE THE MACRO WHOSE NAME IS
POINTED TO BY MACRO_AT. THIS
MEANS ADDING ANOTHER LEVEL TO THE
EXECUTION STACK.
*/
static void Macro_add_level() {
macrotext_t *temp;
if (count == 0 && !infinite)
return;
if (macro_exec_level == last(macro_exec_pointer)) {
Error("\x16" "macro nesting too deep");
macro_exec_level = 0; /* KILL ALL MACROS */
Rebuild_screen();
return;
}
if (macro_exec_level == 0) {