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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
|
char *tecstate_c_version = "tecstate.c: $Revision: 1.3 $";
/*
* $Date: 2007/12/26 13:28:31 $
* $Source: /cvsroot/videoteco/videoteco/tecstate.c,v $
* $Revision: 1.3 $
* $Locker: $
*/
/* tecstate.c
* Main SWITCH/CASE statements to implement the parser syntax stage
*
*
* Copyright (C) 1985-2007 BY Paul Cantrell
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "teco.h"
#include "tecparse.h"
extern char immediate_execute_flag;
extern char trace_mode_flag;
extern char suspend_is_okay_flag;
/* PARSE_INPUT_CHARACTER - Continue the parse with the supplied character
*
* Function:
*
* We re-enter the parser with a new character at this point. We jump back
* to the state we left before.
*/
void
parse_input_character( struct cmd_token *ct, struct cmd_token *uct )
{
char tmp_message[LINE_BUFFER_SIZE];
register struct cmd_token *oct = NULL;
PREAMBLE();
switch(ct->ctx.state){
/*
* Here on initial command state. This is the begining of a command, so we are
* looking for arguments that might go with a command. If there are no args,
* we just transfer into the main command loop.
*/
case STATE_C_INITIALSTATE:
ct->ctx.flags &= ~(CTOK_M_COLON_SEEN | CTOK_M_ATSIGN_SEEN);
ct->flags |= TOK_M_WORDBOUNDARY;
case STATE_C_ACCEPT_ARGS:
ct->ctx.carg = NULL;
switch(ct->input_byte){
/*
* If it looks like an argument, then transfer into a subexpression parser to
* get the value of the expression. ARG1 will stuff the result into iarg1 and
* also check for a comma (',') incase he is specifing a twin argument command
*/
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'Q': case 'q': case '%':
#ifdef CLASSIC_B_BEHAVIOR
case 'B': case 'b':
#endif
case 'Z': case 'z':
case '\\':
case '.':
case '-':
case '(':
case '^':
ct->ctx.flags &= ~CTOK_M_STATUS_PASSED;
ct->ctx.iarg1_flag = ct->ctx.iarg2_flag = NO;
ct->ctx.state = STATE_C_EXPRESSION;
ct->flags &= ~TOK_M_EAT_TOKEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_ARG1;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
/*
* H is a special case, since the single argument actually implies two args.
* (H actually is the same as 0,z<cmd>)
*/
case 'H': case 'h':
ct->ctx.flags &= ~CTOK_M_STATUS_PASSED;
ct->ctx.iarg1_flag = ct->ctx.iarg2_flag = YES;
ct->ctx.state = STATE_C_MAINCOMMANDS;
ct->execute_state = EXEC_C_HVALUE;
return;
/*
* Here on the @ command. This says to use user specified delimeters for
* strings, rather than just terminating with escape.
*/
case '@':
ct->ctx.flags |= CTOK_M_ATSIGN_SEEN;
ct->ctx.state = STATE_C_ACCEPT_ARGS;
return;
/*
* Here on the : command. This is just a flag to many commands to tell them
* to work in a slightly different way. The most common usage is to mean that
* the command should return a value which says whether it worked or not.
*/
case ':':
ct->ctx.flags |= CTOK_M_COLON_SEEN;
ct->ctx.state = STATE_C_ACCEPT_ARGS;
return;
/*
* Well, it doesn't look like he is going to be specifying any arguments, so we
* just go and decode the command.
*/
default:
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){
ct->ctx.state = STATE_C_MAINCOMMANDS;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.flags &= ~CTOK_M_STATUS_PASSED;
return;
}/* End IF */
ct->ctx.state = STATE_C_MAINCOMMANDS;
ct->ctx.iarg1_flag = ct->ctx.iarg2_flag = NO;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
/*
* Here to parse the major commands (i.e., ones that have no lead-in)
*/
case STATE_C_MAINCOMMANDS:
switch(ct->input_byte){
/*
* Space is a nop so that it can be used to make macros more readable
*/
case ' ':
ct->ctx.state = STATE_C_INITIALSTATE;
return;
/*
* Carriage Return is a nop so that it can be used in a macro to avoid
* extremely long lines wrapping.
*/
case '\n':
ct->ctx.state = STATE_C_MAINCOMMANDS;
return;
/*
* Here on an escape. First of all, we have to remember that we have seen an
* escape since two in a row will terminate the command. Also, escape has the
* effect of blocking arguments from commands i.e. 2L will move two lines, but
* 2$L will only move one since the escape eats the argument.
*/
case ESCAPE:
ct->ctx.iarg1_flag = ct->ctx.iarg2_flag = NO;
ct->ctx.state = STATE_C_ESCAPESEEN;
return;
/*
* Here on an Asterisk command. This causes the last double-escaped command
* sequence to be saved in the named q-register.
*/
case '*':
if(parse_any_arguments(ct,"*")) return;
ct->ctx.state = STATE_C_SAVECOMMAND;
return;
/*
* Here on the @ command. This says to use user specified delimeters for
* strings, rather than just terminating with escape.
*/
case '@':
ct->ctx.flags |= CTOK_M_ATSIGN_SEEN;
return;
/*
* Here on the : command. This is just a flag to many commands to tell them
* to work in a slightly different way. The most common usage is to mean that
* the command should return a value which says whether it worked or not.
*/
case ':':
ct->ctx.flags |= CTOK_M_COLON_SEEN;
return;
/*
* Here on the [ command. This causes the specified Q register to be pushed
* onto the Q register pushdown stack.
*/
case '[':
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
ct->ctx.state = STATE_C_PUSH_QREGISTER;
return;
/*
* Here on the ] command. This causes a Q register to be popped off of the
* Q register pushdown stack, and replaces the specified Q register.
*/
case ']':
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
ct->ctx.state = STATE_C_POP_QREGISTER;
return;
/*
* The B command moves backwards by lines. It is strictly a Video TECO
* enhancement. In normal TECO, the B command returns the address of the
* begining of the buffer, i.e. 0.
*/
case 'B': case 'b':
if(parse_more_than_one_arg(ct,"B")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_RLINE;
return;
/*
* Here on the C command. The C command is a relative move command, i.e., the
* argument says how many spaces from the current position to move.
*/
case 'C': case 'c':
if(parse_more_than_one_arg(ct,"C")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_CHAR;
return;
/*
* The D command deletes the specified number of characters in the indicated
* direction.
*/
case 'D': case 'd':
if(parse_more_than_one_arg(ct,"D")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_DELETE;
return;
/*
* Here on an E command. This is simply the lead-in to any one of the many
* E commands.
*/
case 'E': case 'e':
ct->ctx.state = STATE_C_ECOMMAND;
return;
/*
* Here on an F command. This is a lead-in to one of the F? commands.
*/
case 'F': case 'f':
ct->ctx.state = STATE_C_FCOMMAND;
return;
/*
* The G command copies the contents of the specified q-register into the
* edit buffer at the current position.
*/
case 'G': case 'g':
if(parse_any_arguments(ct,"G")) return;
ct->ctx.state = STATE_C_GQREGISTER;
return;
/*
* The I command inserts characters until an escape is input. If this is
* entered with the tab command, not only do we enter insert mode, we also
* insert the tab itself.
*/
case '\t':
if(ct->ctx.iarg1_flag == NO) ct->flags &= ~TOK_M_EAT_TOKEN;
case 'I': case 'i':
if(parse_more_than_one_arg(ct,"I")) return;
if(ct->ctx.iarg1_flag == YES){
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_INSERT;
return;
}/* End IF */
if(ct->ctx.flags & CTOK_M_ATSIGN_SEEN){
ct->ctx.state = STATE_C_ATINSERT;
return;
}/* End IF */
ct->ctx.state = STATE_C_INSERT;
return;
/*
* Here on the J command. The J command jumps to an absolute position in the
* buffer.
*/
case 'J': case 'j':
if(parse_more_than_one_arg(ct,"J")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_JUMP;
return;
/*
* The K command acts just like the L command except that it deletes instead
* of moving over. Also, it is legal to specify an a,b range to K
*/
case 'K': case 'k':
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_KILL;
return;
/*
* The L command moves over the specified number of new-line characters. An
* argument of zero means get to the begining of the current line.
*/
case 'L': case 'l':
if(parse_more_than_one_arg(ct,"L")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_LINE;
return;
/*
* The M command executes the contents of the specified Q register as a macro.
*/
case 'M': case 'm':
ct->ctx.state = STATE_C_MQREGISTER;
return;
/*
* The N command will search for the specified string across multiple edit
* buffers.
*/
case 'N': case 'n':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_NSEARCH;
return;
/*
* The O command goes to the specified label
*/
case 'O': case 'o':
if(parse_any_arguments(ct,"O")) return;
ct->ctx.state = STATE_C_GOTO;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_GOTO_BEGIN;
return;
/*
* The P command selects the next window
*/
case 'P': case 'p':
if(parse_more_than_one_arg(ct,"P")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_NEXT_WINDOW;
return;
/*
* The R command is exactly like the C command, except that the direction
* is reversed.
*/
case 'R': case 'r':
if(parse_more_than_one_arg(ct,"R")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_RCHAR;
return;
/*
* The S command will search for the specified string
*/
case 'S': case 's':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_SEARCH;
return;
/*
* The ^L command is temporarily used to redraw the screen
*/
case '\f':
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_REDRAW_SCREEN;
return;
/*
* The U command loads the argument into the specified Q register
*/
case 'U': case 'u':
if(parse_more_than_one_arg(ct,"U")) return;
ct->ctx.state = STATE_C_UQREGISTER;
return;
/*
* The V command deletes words. This is a Vido TECO enhancement. In normal
* TECO, the V command was equivalent to 0TT
*/
case 'V': case 'v':
if(parse_more_than_one_arg(ct,"V")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_DELWORD;
return;
/*
* The W command moves by words
*/
case 'W': case 'w':
if(parse_more_than_one_arg(ct,"W")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_WORD;
return;
/*
* The X command moves a block of characters from the edit buffer into
* the specified q register.
*/
case 'X': case 'x':
ct->ctx.state = STATE_C_XQREGISTER;
return;
/*
* The Y command deletes words in reverse direction. This is a Video TECO
* enhancement. In classic TECO, the Y command 'yanked' input data into the
* edit buffer.
*/
case 'Y': case 'y':
if(parse_more_than_one_arg(ct,"Y")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_RDELWORD;
return;
/*
* The ^A command allows you to print a message to the message line
*/
case CNTRL_A:
if(parse_any_arguments(ct,"^A")) return;
ct->ctx.state = STATE_C_MESSAGE;
ct->execute_state = EXEC_C_RESET_MESSAGE;
return;
/*
* The < command opens an iteration
*/
case '<':
if(parse_more_than_one_arg(ct,"<")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_ITERATION_BEGIN;
ct->ctx.inest += 1;
ct->execute_state = EXEC_C_ITERATION_BEGIN;
return;
/*
* The > command closes an iteration
*/
case '>':
if(parse_more_than_one_arg(ct,">")) return;
if(ct->ctx.inest == 0){
error_message("?No Iteration Present");
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_INITIALSTATE;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_ITERATION_END;
while((oct = oct->prev_token)){
if(oct->opcode != TOK_C_ITERATION_BEGIN) continue;
if(oct->ctx.inest != ct->ctx.inest) continue;
ct->ctx.caller_token = oct;
break;
}/* End While */
/*
* Preserve the arguments so that if the loop gets undone, it will get redone
* the correct number of iterations when the > is typed again.
*/
{
register struct undo_token *ut;
ut = allocate_undo_token(ct);
if(ut == NULL){
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ut->opcode = UNDO_C_PRESERVEARGS;
ut->iarg1 = oct->ctx.iarg1;
ut->iarg2 = oct->ctx.iarg2;
ut->carg1 = (char *)oct;
ct->ctx.inest -= 1;
ct->execute_state = EXEC_C_ITERATION_END;
ct = allocate_cmd_token(ct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_COPYTOKEN;
return;
}
/*
* The ; command terminates an iteration if the argument is >= 0.
* If there is no argument supplied, it uses the state of the last
* search operation performed as a value.
*/
case ';':
if(parse_more_than_one_arg(ct,";")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_SEMICOLON;
return;
/*
* The = command prints out the value of the supplied expression.
* A single = prints out in decimal, == prints in octal and === in hex.
*/
case '=':
if(parse_more_than_one_arg(ct,"=")) return;
ct->ctx.state = STATE_C_ONE_EQUALS;
ct->execute_state = EXEC_C_EQUALS;
return;
/*
* The " command is the conditional 'IF' operator. The following commands only
* get executed if the condition is satisfied.
*/
case '"':
if(parse_more_than_one_arg(ct,"\"")) return;
ct->ctx.state = STATE_C_CONDITIONALS;
ct->ctx.cnest += 1;
return;
/*
* The | command provides an else clause to a conditional expression
*/
case '|':
if(parse_any_arguments(ct,"|")) return;
if(ct->ctx.cnest <= 0){
error_message("?Not in a conditional");
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_SKIP_ELSE;
ct->execute_state = EXEC_C_SKIP_ELSE;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
/*
* The ' command ends a conditional expression.
*/
case '\'':
if(parse_any_arguments(ct,"'")) return;
if(ct->ctx.cnest <= 0){
error_message("?Not in a conditional");
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_INITIALSTATE;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_CONDITIONAL_END;
ct->ctx.cnest -= 1;
return;
/*
* The Label command allows you to set a tag which can be jumped to with
* the 'O' command. It also provides a way to comment macros.
*/
case '!':
if(parse_any_arguments(ct,"!")) return;
ct->ctx.state = STATE_C_LABEL;
ct->execute_state = EXEC_C_SKIPLABEL;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_LABEL_BEGIN;
return;
/*
* The backslash command with an argument inserts the decimal
* representation of the argument into the buffer at the current position.
*/
case '\\':
if(ct->ctx.iarg2_flag == NO){
ct->ctx.iarg2 = 10;
ct->flags |= TOK_M_PARSELOAD_IARG2;
}/* End IF */
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_BACKSLASH;
return;
/*
* The open-brace command copies the current command string into a special
* Q-register and places the user there so he can edit it.
*/
case '{':
if(parse_any_arguments(ct,"{")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_OPENBRACE;
return;
/*
* The close-brace command replaces the command string with the string in
* the special Q-register.
*/
case '}':
if(parse_any_arguments(ct,"}")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_CLOSEBRACE;
return;
/*
* Here on a system which doesn't really do suspend correctly
*/
case CNTRL_Z:
if(suspend_is_okay_flag == YES){
cmd_suspend();
}/* End IF */
ct->ctx.state = STATE_C_INITIALSTATE;
return;
/*
* Here to toggle trace mode. This inserts information into q-register ?
* to help us track execution.
*/
case '?':
trace_mode_flag = !trace_mode_flag;
{
char traceString[ 64 ];
if( trace_mode_flag ) strcpy( traceString, "Trace Mode ON" );
else strcpy( traceString, "Trace Mode OFF" );
screen_message( traceString );
}
ct->ctx.state = STATE_C_INITIALSTATE;
return;
/*
* We only get here on an error, since we should never dispatch a command that
* does not have a corresponding case statement.
*/
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,
"?MAINCOMMANDS: unknown command <%c>",
UPCASE((int)ct->input_byte));
error_message(tmp_message);
return;
}/* End Switch */
/*
* Here when we have seen the begining of a conditional '"'. Now we have to
* look at the next character to determine what the actual condition test is.
*/
case STATE_C_CONDITIONALS:
switch(ct->input_byte){
case 'G': case 'g':
case '>':
ct->execute_state = EXEC_C_COND_GT;
break;
case 'L': case 'l':
case 'T': case 't':
case 'S': case 's':
case '<':
ct->execute_state = EXEC_C_COND_LT;
break;
case 'E': case 'e':
case 'F': case 'f':
case 'U': case 'u':
case '=':
ct->execute_state = EXEC_C_COND_EQ;
break;
case 'N': case 'n':
case '!':
ct->execute_state = EXEC_C_COND_NE;
break;
case 'C': case 'c':
ct->execute_state = EXEC_C_COND_SYMBOL;
break;
case 'D': case 'd':
ct->execute_state = EXEC_C_COND_DIGIT;
break;
case 'A': case 'a':
ct->execute_state = EXEC_C_COND_ALPHA;
break;
case 'V': case 'v':
ct->execute_state = EXEC_C_COND_LOWER;
break;
case 'W': case 'w':
ct->execute_state = EXEC_C_COND_UPPER;
break;
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,
"?Unknown conditional command '%c'",
UPCASE((int)ct->input_byte));
error_message(tmp_message);
return;
}/* End Switch */
ct->ctx.state = STATE_C_INITIALSTATE;
return;
/*
* Here to watch for the end of a label
*/
case STATE_C_LABEL:
switch(ct->input_byte){
case '!':
ct->ctx.state = STATE_C_INITIALSTATE;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_LABEL_END;
return;
default:
ct->ctx.state = STATE_C_LABEL;
return;
}/* End Switch */
/*
* Here to eat the characters in a GOTO command
*/
case STATE_C_GOTO:
switch(ct->input_byte){
case ESCAPE:
ct->ctx.state = STATE_C_INITIALSTATE;
ct->flags &= ~TOK_M_EAT_TOKEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_GOTO_END;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->execute_state = EXEC_C_GOTO;
return;
default:
ct->ctx.state = STATE_C_GOTO;
return;
}/* End Switch */
/*
* Here if we have seen an escape. If we see another, then he wants us to
* complete the parse and execute any remaining commands.
*/
case STATE_C_ESCAPESEEN:
switch(ct->input_byte){
case ESCAPE:
if(ct->ctx.inest){
error_message("?Unterminated Iteration");
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
if(ct->ctx.cnest){
error_message("?Unterminated Conditional");
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_FINALSTATE;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->opcode = TOK_C_FINALTOKEN;
return;
default:
ct->ctx.state = STATE_C_INITIALSTATE;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
/*
* Here if we have seen an E as a lead-in to one of the E commands.
*/
case STATE_C_ECOMMAND:
switch(ct->input_byte){
/*
* The EB command creates a new edit buffer and reads the specified file in.
* If the command is given an argument, then this is a shorthand switch to
* the buffer that has that number.
*/
case 'B': case 'b':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
if(ct->ctx.iarg1_flag == YES){
ct->execute_state = EXEC_C_EDITBUF;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
ct->ctx.state = STATE_C_INITIALSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_EDITBUF;
return;
/*
* The EC command allows you to execute a command, and the output is placed
* into the edit buffer.
*/
case 'C': case 'c':
if(ct->ctx.iarg1_flag == YES){
ct->execute_state = EXEC_C_ECCOMMAND;
ct->ctx.state = STATE_C_INITIALSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_ECCOMMAND;
return;
/*
* The EF command closes the current edit buffer. If the current buffer
* is modified, the command will fail unless the user specifies an argument
* to the command.
*/
case 'F': case 'f':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->execute_state = EXEC_C_CLOSEBUF;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The EI command allows you to alter immediate execution mode. With no
* argument, execute mode is turned off for the remainder of the current
* command. An argument of 0 turns it off until further notice and an
* argument of 1 turns it back on.
*/
case 'I': case 'i':
if(parse_more_than_one_arg(ct,"EI")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->ctx.iarg1_flag == NO){
ct->ctx.go_flag = NO;
return;
}/* End IF */
ct->execute_state = EXEC_C_SET_IMMEDIATE_MODE;
return;
/*
* The EJ command allows you to load runtime options into TECO.
*/
case 'J': case 'j':
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_SETOPTIONS;
return;
/*
* The EP command splits the current window in half. If an argument is
* supplied, the command deletes the current window.
*/
case 'P': case 'p':
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_WINDOW_CONTROL;
return;
/*
* The EV command works exactly like the EB command except that the buffer
* which is created is 'readonly'. Thus this command stands for 'VIEW' file.
*/
case 'V': case 'v':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
if(ct->ctx.iarg1_flag == YES){
ct->execute_state = EXEC_C_VIEWBUF;
ct->ctx.state = STATE_C_INITIALSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_VIEWBUF;
return;
/*
* The EQ command reads a file into the specified Q-register.
*/
case 'Q': case 'q':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
if(parse_any_arguments(ct,"EQ")) return;
ct->ctx.state = STATE_C_EQQREGISTER1;
return;
/*
* The ER command reads the specified file into the current buffer location.
*/
case 'R': case 'r':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_READFILE;
return;
/*
* The ES command causes the screen to scroll
*/
case 'S': case 's':
if(parse_more_than_one_arg(ct,"ES")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_SCROLL;
return;
/*
* The ET command causes the screen to update
*/
case 'T': case 't':
if(parse_any_arguments(ct,"ET")) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_UPDATE_SCREEN;
return;
/*
* The EW command writes out the current buffer
*/
case 'W': case 'w':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_WRITEFILE;
return;
/*
* The EX command causes the editor to exit
*/
case 'X': case 'x':
ct->execute_state = EXEC_C_EXITCOMMAND;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->ctx.go_flag = NO;
return;
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,
"?Unknown command E%c",UPCASE((int)ct->input_byte));
error_message(tmp_message);
return;
}/* End Switch */
/*
* Here if we have seen an F as a lead-in to one of the F commands.
*/
case STATE_C_FCOMMAND:
switch(ct->input_byte){
/*
* The FD command finds the string and deletes it.
*/
case 'D': case 'd':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_FDCOMMAND;
return;
/*
* The FK command clears the text between the current position and the position
* of the searched for text. The searched for text is left unmodified.
*/
case 'K': case 'k':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_FKCOMMAND;
return;
/*
* The FS command finds the first string and replaces it with the second
*/
case 'S': case 's':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_FSPART1;
return;
/*
* The FT command is a Video TECO extension to read & use a unix style
* tags file.
*/
case 'T': case 't':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_FTAGS;
return;
/*
* The FR command acts like the FS command except that if the second argument
* is NULL, the string is replaced with the last replace value.
*/
case 'R': case 'r':
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
ct->ctx.flags |= CTOK_M_STATUS_PASSED;
}/* End IF */
ct->execute_state = EXEC_C_SEARCH;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->execute_state = EXEC_C_FRREPLACE;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){ /* mch */
ct = allocate_cmd_token(ct);
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* Here when we have an 'F' command with an unknown second character. This
* makes it an illegal command, and we don't waste any time letting the user
* know about it.
*/
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,
"?Unknown command F%c",UPCASE((int)ct->input_byte));
error_message(tmp_message);
return;
}/* End Switch */
/*
* The following state is the return-state from STRING when the first part
* of an FS command has been parsed.
*/
case STATE_C_FSPART1:
ct->ctx.state = STATE_C_FSPART2;
ct->execute_state = EXEC_C_SEARCH;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->execute_state = EXEC_C_FSREPLACE1;
return;
case STATE_C_FSPART2:
ct->flags |= TOK_M_WORDBOUNDARY;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_FSPART3;
return;
case STATE_C_FSPART3:
if(ct->ctx.flags & CTOK_M_ATSIGN_SEEN){
if(ct->input_byte == ct->ctx.delimeter){
ct->ctx.state = STATE_C_ESCAPESEEN;
ct->execute_state = EXEC_C_FSREPLACE3;
return;
}
else {
ct->ctx.state = STATE_C_FSPART3;
ct->execute_state = EXEC_C_FSREPLACE2;
return;
}
}
if(ct->input_byte == ESCAPE){
ct->ctx.state = STATE_C_ESCAPESEEN;
ct->execute_state = EXEC_C_FSREPLACE3;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){ /* mch */
ct = allocate_cmd_token(ct);
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
}
else {
ct->ctx.state = STATE_C_FSPART3;
ct->execute_state = EXEC_C_FSREPLACE2;
return;
}
#ifdef WIMPY_CODER_WHO_HAS_NOT_HANDLED_THIS_YET
case CNTRL_V:
ct->ctx.state = STATE_C_QUOTED_INSERT;
return;
#endif /* WIMPY_CODER_WHO_HAS_NOT_HANDLED_THIS_YET */
/*
* This state is the return state from STRING and the TAGS command is
* ready to execute.
*/
case STATE_C_FTAGS:
ct->execute_state = EXEC_C_FTAGS;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is the return-state from STRING when a search string
* has been completely specified.
*/
case STATE_C_SEARCH:
ct->execute_state = EXEC_C_SEARCH;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is the return-state from STRING when a search string
* has been completely specified for the 'N' search command.
*/
case STATE_C_NSEARCH:
ct->execute_state = EXEC_C_NSEARCH;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is the return-state from STRING when the search part
* of an FD command has been parsed.
*/
case STATE_C_FDCOMMAND:
ct->execute_state = EXEC_C_SEARCH;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.carg = NULL;
ct->execute_state = EXEC_C_FDCOMMAND;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){ /* mch */
ct = allocate_cmd_token(ct);
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is the return-state from STRING when the search part
* of an FK command has been parsed.
*/
case STATE_C_FKCOMMAND:
ct->execute_state = EXEC_C_REMEMBER_DOT;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->execute_state = EXEC_C_SEARCH;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.carg = NULL;
ct->execute_state = EXEC_C_FKCOMMAND;
if(ct->ctx.flags & CTOK_M_STATUS_PASSED){ /* mch */
ct = allocate_cmd_token(ct);
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is a return-state from STRING when we have seen an
* escape terminated string which in this case is the name of the file to
* write.
*/
case STATE_C_WRITEFILE:
ct->execute_state = EXEC_C_WRITEFILE;
ct->ctx.go_flag = NO;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is a return-state from STRING when we have seen an
* escape terminated string which in this case is the name of the file to
* read into the current buffer location.
*/
case STATE_C_READFILE:
ct->execute_state = EXEC_C_READFILE;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is a return-state from STRING when we have seen an
* escape terminated string which in this case is the name of the file which
* we want to create a buffer for and load.
*/
case STATE_C_EDITBUF:
ct->execute_state = EXEC_C_EDITBUF;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(ct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is a return-state from STRING when we have seen an
* escape terminated string which in this case is the name of the file which
* we want to create a readonly buffer for and load.
*/
case STATE_C_VIEWBUF:
ct->execute_state = EXEC_C_VIEWBUF;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(ct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state is a return-state from STRING when we have seen an
* escape terminated string which in this case is the command the user wants
* to execute.
*/
case STATE_C_ECCOMMAND:
ct->execute_state = EXEC_C_ECCOMMAND;
ct->ctx.state = STATE_C_INITIALSTATE;
if(ct->input_byte == ESCAPE) ct->ctx.state = STATE_C_ESCAPESEEN;
return;
/*
* The following state gets entered when the user has typed ^A
* to print out a message.
*/
case STATE_C_MESSAGE:
switch(ct->input_byte){
case CNTRL_A:
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_OUTPUT_MESSAGE;
return;
default:
ct->execute_state = EXEC_C_MESSAGE;
ct->ctx.state = STATE_C_MESSAGE;
return;
}/* End Switch */
/*
* The following state is a return-state from EXPRESSION when we have seen
* what appears to be a first argument. It stashes the argument and tests if
* there is a second argument available (indicated by a comma).
*/
case STATE_C_ARG1:
ct->ctx.iarg1_flag = YES;
ct->execute_state = EXEC_C_STORE1;
switch(ct->input_byte){
case ',':
ct->ctx.state = STATE_C_EXPRESSION;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_ARG2;
return;
default:
ct->ctx.state = STATE_C_MAINCOMMANDS;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
/*
* Here if the first argument was followed by a comma. This indicates that a
* second argument is being specified. Only certain commands accept a double
* argument.
*/
case STATE_C_ARG2:
ct->ctx.iarg2_flag = YES;
ct->execute_state = EXEC_C_STORE2;
switch(ct->input_byte){
case ',':
ct->ctx.state = STATE_C_ERRORSTATE;
error_message("?Maximum of two arguments exceeded");
return;
default:
ct->ctx.state = STATE_C_MAINCOMMANDS;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
/*
* The next state is the expression substate. States outside of the expression
* parser call through here so that pnest (the current nesting level of
* parentheses) gets set to zero. Then it calls the expression parser's own
* internal sub-expression state.
*/
case STATE_C_EXPRESSION:
ct->ctx.pnest = 0;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_SUBEXPRESSION;
return;
/*
* This is the sub-expression state. It gets called from within the expression
* parser when we want to recursively parse an expression. This lets us handle
* precedence and parenthesis correctly.
*/
case STATE_C_SUBEXPRESSION:
switch(ct->input_byte){
/*
* When we see an open parenthesis, we want to recursively call the
* subexpression state to parse the contents of the parenthesis. Since the open
* parenthesis always occurs in place of an operand, we set that to be the next
* state to call.
*/
case '(':
ct->ctx.pnest += 1;
ct->ctx.state = STATE_C_OPERAND;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_OPERATOR;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_OPERATOR;
return;
/*
* If we see a minus sign here, it is a unary minus. The difference between
* the unary minus and the normal minus is one of precedence. The unary minus
* is very high precedence.
*/
case '-':
ct->ctx.state = STATE_C_MINUSSEEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_UMINUS;
return;
/*
* Here on a leading % command. This just means he is going to default to
* incrementing the queue register by one.
*/
case '%':
ct->ctx.tmpval = 1;
ct->flags |= TOK_M_PARSELOAD_TMPVAL;
/* ;;; the following line shouldn't be required, but is. A bug. */
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.state = STATE_C_PERCENT_OPERAND;
return;
/*
* Well, not much exciting going on here, so we just call the normal operand
* state to parse the current token.
*/
default:
ct->ctx.state = STATE_C_OPERAND;
ct->flags &= ~TOK_M_EAT_TOKEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_OPERATOR;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
/*
* Here if we saw a unary minus. The reason for calling this state at all is to
* catch constructs like -L which really implies -1L. In a case like this,
* the OPERAND state will not see anything it understands, and will return.
* So as to make the defaulting work correctly, we catch that case here and
* default so that we get our -1.
*/
case STATE_C_MINUSSEEN:
switch(ct->input_byte){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'Q': case 'q': case '%':
case '.':
#ifdef CLASSIC_B_BEHAVIOR
case 'B': case 'b':
#endif
case 'Z': case 'z':
case '(':
case '^':
ct->ctx.state = STATE_C_OPERAND;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
default:
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = 1;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_RETURN;
return;
}/* End Switch */
/*
* Here on the return from the OPERAND state. Whatever it parsed, we want to
* make it minus.
*/
case STATE_C_UMINUS:
ct->execute_state = EXEC_C_UMINUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
/*
* Here when we are expecting an operator like + = * /. Note that ')' also gets
* handled here since it always appears in the place an operator would be
* expected to appear.
*/
case STATE_C_OPERATOR:
switch(ct->input_byte){
/*
* Here on an a-b case. Note that since minus is a low precedence operator,
* we stash the temporary value, and call subexpression to parse the rest
* of the expression. In that way, if the next operator was * or /, it will
* get processed first.
*/
case '-':
ct->execute_state = EXEC_C_STORE2;
ct->ctx.state = STATE_C_OPERAND;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_MINUS;
return;
/*
* Here on an a+b case. This is similar to the case above in that we want to
* just stash the first value, and then recursively call the parser to handle
* the rest of the expression first. Note that this causes a+b+c to actually
* get handled as a+(b+c) which is a little weird, but works out ok.
*/
case '+':
ct->execute_state = EXEC_C_STORE2;
ct->ctx.state = STATE_C_OPERAND;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_PLUS;
return;
/*
* Here on the a*b case. Unlike the above two cases, we want to immediately
* handle this case since it is the highest precedence of the four operators.
*/
case '*':
ct->execute_state = EXEC_C_STORE1;
ct->ctx.state = STATE_C_OPERAND;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_TIMES;
return;
/*
* Here on the a/b case. This is just like the multiply state
*/
case '/':
ct->execute_state = EXEC_C_STORE1;
ct->ctx.state = STATE_C_OPERAND;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_DIVIDE;
return;
/*
* Here on the n%q case. This just collapses to the value of the Q-register
* after it has been incremented by 'n'
*/
case '%':
ct->ctx.state = STATE_C_PERCENT_OPERAND;
return;
/*
* Here on the 'A' command which returns a value
*/
case 'A': case 'a':
ct->execute_state = EXEC_C_ACOMMAND;
ct->ctx.state = STATE_C_OPERATOR;
return;
/*
* Here on a close parenthesis. This will force the end of a subexpression
* parse even though it would not normally have terminated yet. Note the check
* for the guy typing too many of these.
*/
case ')':
if(ct->ctx.pnest == 0){
error_message("?No Matching Open Parenthesis");
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.pnest -= 1;
ct->ctx.state = STATE_C_RETURN;
return;
/*
* If this is not an operator character, it must be the end of the expression.
* In this case, we must be back at the zero level for parenthesis nesting.
*/
default:
if(ct->ctx.pnest > 0){
sprintf(tmp_message,"?Missing %d Close Parenthesis",
ct->ctx.pnest);
error_message(tmp_message);
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_RETURN;
return;
}/* End Switch */
/*
* Here when we have the 'b' part of an a+b expression. This happens either
* when the end of the expression has been completed, or a parenthesis has
* forced a temporary end as in: (a+b)
*/
case STATE_C_PLUS:
switch(ct->input_byte){
case '-':
case '+':
case ')':
ct->execute_state = EXEC_C_PLUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
default:
ct->ctx.state = STATE_C_OPERATOR;
ct->flags &= ~TOK_M_EAT_TOKEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_DELAYED_PLUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
case STATE_C_DELAYED_PLUS:
ct->execute_state = EXEC_C_PLUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
/*
* Here when we have the 'b' part of an a-b expression. This happens either
* when the end of the expression has been completed, or a parenthesis has
* forced a temporary end as in: (a-b)
*/
case STATE_C_MINUS:
switch(ct->input_byte){
case '-':
case '+':
case ')':
ct->execute_state = EXEC_C_MINUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
default:
ct->ctx.state = STATE_C_OPERATOR;
ct->flags &= ~TOK_M_EAT_TOKEN;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_DELAYED_MINUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End Switch */
case STATE_C_DELAYED_MINUS:
ct->execute_state = EXEC_C_MINUS;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
/*
* Here when we have both arguments to a multiply. Because multiply is a higher
* precedence operator than +-, it happens immediately unless parenthesis get
* involved.
*/
case STATE_C_TIMES:
ct->execute_state = EXEC_C_TIMES;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
/*
* Here when we have both arguments to a divide. Because division is a higher
* precedence operator than -+, it generally happens immediately. Note that we
* check to be sure that the divisor is non-zero.
*/
case STATE_C_DIVIDE:
ct->execute_state = EXEC_C_DIVIDE;
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_OPERATOR;
return;
/*
* Here to parse any legal TECO operand. These would include numbers and
* commands that return values. Since open parenthesis occur in the same place
* as operands, we also catch them here.
*/
case STATE_C_OPERAND:
switch(ct->input_byte){
/*
* If we see a numeric digit, call a substate which will continue eating bytes
* until a non-digit is seen.
*/
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
ct->ctx.state = STATE_C_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->input_byte - '0';
return;
/*
* Here if he wants to input in a different radix
*/
case '^':
ct->ctx.state = STATE_C_RADIX;
ct->ctx.tmpval = 0;
return;
/*
* Here if he is specifying the numeric value of a q-register. We have to go
* to another state to determine which q-register he wants to access.
*/
case 'Q': case 'q':
ct->ctx.state = STATE_C_QOPERAND;
return;
/*
* Here when he has specified <dot>. This will return as a value the current
* position in the edit buffer.
*/
case '.':
ct->ctx.state = STATE_C_RETURN;
ct->execute_state = EXEC_C_DOTVALUE;
return;
#ifdef CLASSIC_B_BEHAVIOR
/*
* B is a special operand which returns the address of the first character
* in the buffer. This is currently always 0, but may change if some really
* obscure features get put in one of these days.
*/
case 'B': case 'b':
ct->ctx.state = STATE_C_RETURN;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = 0;
return;
#endif
/*
* Z is a special operand which is the number of characters currently in the
* edit buffer.
*/
case 'Z': case 'z':
ct->ctx.state = STATE_C_RETURN;
ct->execute_state = EXEC_C_ZEEVALUE;
return;
/*
* BACKSLASH with no argument actually looks in the buffer at the current
* position and eats numeric digits until it hits a non-digit. It then
* returns the number as a value.
*/
case '\\':
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_BACKSLASH;
ct->ctx.tmpval = 10;
ct->execute_state = EXEC_C_STOREVAL;
ct = allocate_cmd_token(ct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->execute_state = EXEC_C_STORE1;
return;
/*
* If we see a parenthesis in place of an operand, we want to parse it as
* a complete expression of its own until a matching close parenthesis.
*/
case '(':
ct->ctx.state = STATE_C_SUBEXPRESSION;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
/*
* We really should not get here if the guy is typing good syntax, so we
* tell him it is junk and we don't allow it.
*/
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,
"?Unexpected character <%c> in operand",
ct->input_byte);
error_message(tmp_message);
return;
}/* End Switch */
/*
* The following is a substate to parse a number. It will continue until
* it sees a non-digit, and then return to the calling state.
*/
case STATE_C_NUMBER_SUBSTATE:
switch(ct->input_byte){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
ct->ctx.state = STATE_C_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->ctx.tmpval * 10 + ct->input_byte - '0';
return;
default:
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_RETURN;
return;
}/* End Switch*/
/*
* The following is a substate to parse a hex number. It will continue until
* it sees a non hex digit, and then return to the calling state.
*/
case STATE_C_HEX_NUMBER_SUBSTATE:
switch(ct->input_byte){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
ct->ctx.state = STATE_C_HEX_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval *= 16;
ct->ctx.tmpval += ct->input_byte - '0';
return;
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f':
ct->ctx.state = STATE_C_HEX_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval *= 16;
ct->ctx.tmpval += ct->input_byte - 'a' + 10;
return;
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F':
ct->ctx.state = STATE_C_HEX_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval *= 16;
ct->ctx.tmpval += ct->input_byte - 'A' + 10;
return;
default:
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_RETURN;
return;
}/* End Switch*/
/*
* The following is a substate to parse a octal number. It will continue until
* it sees a non octal digit, and then return to the calling state.
*/
case STATE_C_OCTAL_NUMBER_SUBSTATE:
switch(ct->input_byte){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
ct->ctx.state = STATE_C_OCTAL_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval *= 8;
ct->ctx.tmpval += ct->input_byte - '0';
return;
case '8': case '9':
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,"?Illegal octal digit <%c> in operand",
ct->input_byte);
error_message(tmp_message);
return;
default:
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_RETURN;
return;
}/* End Switch*/
/*
* The following state gets the value of the specified q-register
*/
case STATE_C_QOPERAND:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_RETURN;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_QVALUE;
return;
/*
* This is just like QOPERAND except the execute state is different
*/
case STATE_C_PERCENT_OPERAND:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_OPERATOR;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_PERCENT_VALUE;
return;
/*
* Here on a input radix character
*/
case STATE_C_RADIX:
switch(ct->input_byte){
case 'X': case 'x':
ct->ctx.state = STATE_C_HEX_NUMBER;
ct->execute_state = EXEC_C_STOREVAL;
return;
case 'O': case 'o':
ct->ctx.state = STATE_C_OCTAL_NUMBER;
ct->execute_state = EXEC_C_STOREVAL;
return;
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,"?Unknown radix ^<%c> in operand",
ct->input_byte);
error_message(tmp_message);
return;
}/* End Switch */
case STATE_C_HEX_NUMBER:
switch(ct->input_byte){
case '\\':
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_BACKSLASH;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = 16;
return;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
ct->ctx.state = STATE_C_HEX_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->input_byte - '0';
return;
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f':
ct->ctx.state = STATE_C_HEX_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->input_byte - 'a' + 10;
return;
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F':
ct->ctx.state = STATE_C_HEX_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->input_byte - 'A' + 10;
return;
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,"?Illegal hex digit <%c> in operand",
ct->input_byte);
error_message(tmp_message);
return;
}/* End Switch */
case STATE_C_OCTAL_NUMBER:
switch(ct->input_byte){
case '\\':
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_BACKSLASH;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = 8;
return;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
ct->ctx.state = STATE_C_OCTAL_NUMBER_SUBSTATE;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->input_byte - '0';
return;
default:
ct->ctx.state = STATE_C_ERRORSTATE;
sprintf(tmp_message,"?Illegal octal digit <%c> in operand",
ct->input_byte);
error_message(tmp_message);
return;
}/* End Switch*/
/*
* The next state is the string substate. Outside states call in through here
* which does the initial tec_alloc of the string storage. Strings are limited
* to PARSER_STRING_MAX bytes at this time.
*/
case STATE_C_STRING:
if((ct->ctx.flags & CTOK_M_ATSIGN_SEEN) == 0){
ct->ctx.delimeter = ESCAPE;
ct->flags &= ~TOK_M_EAT_TOKEN;
}
else {
ct->ctx.delimeter = ct->input_byte;
}
ct->ctx.state = STATE_C_STRING1;
return;
case STATE_C_STRING1:
/*
* First, check if this is the termination character. This would normally be
* an escape, but could be another character if the user used the @ form.
*/
if( ( (ct->input_byte == ESCAPE) &&
(!(ct->ctx.flags & CTOK_M_ATSIGN_SEEN))
) ||
( (ct->ctx.flags & CTOK_M_ATSIGN_SEEN) &&
(ct->input_byte == ct->ctx.delimeter) &&
(ct->ctx.carg != NULL)
)
){
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_RETURN;
return;
}/* End IF */
/*
* Here when we see a normal character inside of the string. Note that we
* have to do the undo stuff to manage the string since it gets stored in
* a regular string array rather than being spread through the command
* tokens.
*/
{/* Local Block */
register char *cp;
register struct undo_token *ut;
/*
* Get the address of the string
*/
cp = ct->ctx.carg;
/*
* If there is no string allocated yet, then we have to allocate one.
* Also, if an @ was seen, then record the delimeter character.
*/
if(cp == NULL){
ct->ctx.carg = cp = tec_alloc(TYPE_C_CBUFF,PARSER_STRING_MAX);
if(cp == NULL){
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
*cp = '\0';
ut = allocate_undo_token(uct);
if(ut == NULL){
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ut->opcode = UNDO_C_MEMFREE;
ut->carg1 = cp;
}/* End IF */
/*
* Each time we append a character to the string, we also have to allocate
* an undo token which will shorten the string if the input character gets
* rubbed out.
*/
ut = allocate_undo_token(uct);
if(ut == NULL){
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ut->opcode = UNDO_C_SHORTEN_STRING;
ut->carg1 = cp;
ut->iarg1 = 0;
while(*cp){
ut->iarg1 += 1;
cp++;
}/* End While */
if(ut->iarg1 >= (PARSER_STRING_MAX-1)){
sprintf(tmp_message,"?Exceeded maximum string length of %d",
PARSER_STRING_MAX-1);
error_message(tmp_message);
ct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
/*
* Finally, we append the input byte to the string
*/
*cp++ = ct->input_byte;
*cp++ = '\0';
ct->ctx.state = STATE_C_STRING1;
return;
}/* End Local Block */
/*
* The following state gets the Q register that will be used with the
* G command.
*/
case STATE_C_GQREGISTER:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_GQREGISTER;
return;
/*
* The following state gets the Q register that will be used with the
* M command.
*/
case STATE_C_MQREGISTER:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_MQREGISTER;
return;
/*
* The following two states implement the EQ command which reads a file into
* the specified Q-register.
*/
case STATE_C_EQQREGISTER1:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.tmpval = ct->input_byte;
ct->ctx.state = STATE_C_STRING;
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.caller_token = oct;
ct->ctx.return_state = STATE_C_EQQREGISTER2;
return;
case STATE_C_EQQREGISTER2:
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_EQQREGISTER;
if(ct->ctx.flags & CTOK_M_COLON_SEEN){
oct = ct;
ct = allocate_cmd_token(oct);
if(ct == NULL){
oct->ctx.state = STATE_C_ERRORSTATE;
return;
}/* End IF */
ct->ctx.iarg1_flag = YES; ct->ctx.iarg2_flag = NO;
ct->execute_state = EXEC_C_STORE1;
}/* End IF */
return;
/*
* The following state gets the Q register that will be loaded with the
* U command.
*/
case STATE_C_UQREGISTER:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_UQREGISTER;
return;
/*
* The following state gets the Q register that will be loaded with the
* X command.
*/
case STATE_C_XQREGISTER:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_XQREGISTER;
return;
/*
* The following state gets the Q register that will be loaded with the
* previous command line in response to the '*' command.
*/
case STATE_C_SAVECOMMAND:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_SAVECOMMAND;
return;
/*
* The following state gets the Q register which will be pushed onto the
* Q register stack.
*/
case STATE_C_PUSH_QREGISTER:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_PUSH_QREGISTER;
return;
/*
* The following state gets the Q register which will be popped from the
* Q register stack.
*/
case STATE_C_POP_QREGISTER:
if(!parse_check_qname(ct,ct->input_byte)) return;
ct->ctx.state = STATE_C_INITIALSTATE;
ct->q_register = ct->input_byte;
ct->execute_state = EXEC_C_POP_QREGISTER;
return;
/*
* Here to insert characters. The insert state continues until an escape
* is seen. Escapes can also be quoted if they are to be inserted into the
* buffer. If there are many escapes to be inserted, it may be easier to use
* the @ insert command...
*/
case STATE_C_INSERT:
switch(ct->input_byte){
/*
* Here when we see a non-quoted escape. This terminates the insert.
*/
case ESCAPE:
ct->flags &= ~TOK_M_EAT_TOKEN;
ct->ctx.state = STATE_C_INITIALSTATE;
return;
/*
* Here to enter a quote character. This lets you insert characters that would
* normally be handled otherwise. ESCAPE is a good example of this.
*/
case CNTRL_V:
ct->ctx.state = STATE_C_QUOTED_INSERT;
return;
/*
* Here to handle a normal character. It will simply be inserted into the
* edit buffer.
*/
default:
ct->ctx.state = STATE_C_INSERT;
ct->execute_state = EXEC_C_INSERT;
return;
}/* End Switch */
/*
* Here to insert a character directly following the quote character. If
* this is a special character such as an escape, it will be inserted and
* will not terminate the insert command.
*/
case STATE_C_QUOTED_INSERT:
ct->ctx.state = STATE_C_INSERT;
ct->execute_state = EXEC_C_INSERT;
return;
/*
* Here for the alternate form of insert, @I/text/
*/
case STATE_C_ATINSERT:
ct->ctx.tmpval = ct->input_byte;
ct->execute_state = EXEC_C_STOREVAL;
ct->ctx.state = STATE_C_ATINSERT_PART2;
return;
case STATE_C_ATINSERT_PART2:
if(ct->input_byte == ct->ctx.tmpval){
ct->ctx.state = STATE_C_INITIALSTATE;
return;
}/* End IF */
ct->ctx.state = STATE_C_ATINSERT_PART2;
ct->execute_state = EXEC_C_INSERT;
return;
/*
* Here after seeing an equals command. This lets us test for two or three
* in a row which output in octal and hex respectively.
*/
case STATE_C_ONE_EQUALS:
if(ct->input_byte != '='){
ct->ctx.state = STATE_C_INITIALSTATE;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End IF */
ct->ctx.state = STATE_C_TWO_EQUALS;
ct->execute_state = EXEC_C_TWO_EQUALS;
return;
case STATE_C_TWO_EQUALS:
if(ct->input_byte != '='){
ct->ctx.state = STATE_C_INITIALSTATE;
ct->flags &= ~TOK_M_EAT_TOKEN;
return;
}/* End IF */
ct->ctx.state = STATE_C_INITIALSTATE;
ct->execute_state = EXEC_C_THREE_EQUALS;
return;
/*
* Here when we have seen a vertical bar. We have to put a mark here so
* that if the condition is not met, the else clause can be found.
*/
case STATE_C_SKIP_ELSE:
ct->opcode = TOK_C_CONDITIONAL_ELSE;
ct->ctx.state = STATE_C_INITIALSTATE;
return;
case STATE_C_BACKSLASH:
ct->ctx.state = STATE_C_RETURN;
ct->execute_state = EXEC_C_BACKSLASHARG;
return;
default:
sprintf(tmp_message,"?Dispatched unknown state %d",ct->ctx.state);
error_message(tmp_message);
return;
}/* End Switch */
}/* End Routine */
/* PARSE_CHECK_QNAME - Check that the specified Q-register name is ok
*
* Function:
*
* This routine is called when a parse state wants to verify that the
* specified Q-register name is syntactically correct. It does not
* verify that the Q-register exists, because the execute phase may just
* not have got around to that yet.
*/
int
parse_check_qname( struct cmd_token *ct, char name )
{
char tmp_message[LINE_BUFFER_SIZE];
PREAMBLE();
switch(name){
case '*':
case '_':
case '-':
case '@':
case '?':
return(SUCCESS);
}/* End Switch */
if(isalnum((int)name)) return(SUCCESS);
sprintf(tmp_message,"?Illegal Q-register Name <%c>",name);
error_message(tmp_message);
ct->ctx.state = STATE_C_ERRORSTATE;
return(FAIL);
}/* End Routine */
|