-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathash.c
12298 lines (10879 loc) · 261 KB
/
ash.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
/* vi: set sw=4 ts=4: */
/*
* ash shell port for busybox
*
* Copyright (c) 1989, 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This version of ash is adapted from the source in Debian's ash 0.3.8-5
* package.
*
* Modified by Erik Andersen <andersee@debian.org> and
* Vladimir Oleynik <dzo@simtreas.ru> to be used in busybox
*
*
* Original copyright notice is retained at the end of this file.
*/
/* This enables alias support in ash. If you want to support things
* like "alias ls='ls -l'" with ash, enable this. This is only useful
* when ash is used as an intractive shell. This adds about 1.5k */
#define CONFIG_ASH_ALIAS
/* If you need ash to act as a full Posix shell, with full math
* support, enable this. This adds a bit over 2k an x86 system. */
#define CONFIG_ASH_MATH_SUPPORT
/* Getopts is used by shell procedures to parse positional parameters.
* You probably want to leave this disabled, and use the busybox getopt
* applet if you want to do this sort of thing. There are some scripts
* out there that use it, so if you need it, enable it. Most people will
* leave this disabled. This adds 1k on an x86 system. */
#undef CONFIG_ASH_GETOPTS
/* This allows you to override shell builtins and use whatever is on
* the filesystem. This is most useful when ash is acting as a
* standalone shell. Adds about 272 bytes. */
#undef CONFIG_ASH_CMDCMD
/* Check for mail */
#undef CONFIG_ASH_MAIL
/* Optimize size vs speed as size */
#define CONFIG_ASH_OPTIMIZE_FOR_SIZE
/* Enable this to compile in extra debugging noise. When debugging is
* on, debugging info will be written to $HOME/trace and a quit signal
* will generate a core dump. */
#undef DEBUG
//#define DEBUG 2
/* These are here to work with glibc -- Don't change these... */
#undef FNMATCH_BROKEN
#undef GLOB_BROKEN
#define IFS_BROKEN
#include <assert.h>
#include <stddef.h>
#include <ctype.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <limits.h>
#include <paths.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <io.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/ttycom.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "busybox.h"
#include "pwd_grp/pwd.h"
#include <process.h>
#include <windef.h>
#include <winbase.h>
#if !defined(FNMATCH_BROKEN)
#include <fnmatch.h>
#endif
#if !defined(GLOB_BROKEN)
#include <glob.h>
#endif
#ifdef BB_FEATURE_ASH_JOB_CONTROL
#include <termios.h>
#endif
#include "cmdedit.h"
#if defined(__uClinux__)
#error "Do not even bother, ash will not run on uClinux"
#endif
/*
* This file was generated by the mksyntax program.
*/
/* Syntax classes */
#define CWORD 0 /* character is nothing special */
#define CNL 1 /* newline character */
#define CBACK 2 /* a backslash character */
#define CSQUOTE 3 /* single quote */
#define CDQUOTE 4 /* double quote */
#define CENDQUOTE 5 /* a terminating quote */
#define CBQUOTE 6 /* backwards single quote */
#define CVAR 7 /* a dollar sign */
#define CENDVAR 8 /* a '}' character */
#define CLP 9 /* a left paren in arithmetic */
#define CRP 10 /* a right paren in arithmetic */
#define CENDFILE 11 /* end of file */
#define CCTL 12 /* like CWORD, except it must be escaped */
#define CSPCL 13 /* these terminate a word */
#define CIGN 14 /* character should be ignored */
#define SYNBASE 130
#define PEOF -130
#define PEOA -129
#define TEOF 0
#define TNL 1
#define TREDIR 2
#define TWORD 3
#define TASSIGN 4
#define TSEMI 5
#define TBACKGND 6
#define TAND 7
#define TOR 8
#define TPIPE 9
#define TLP 10
#define TRP 11
#define TENDCASE 12
#define TENDBQUOTE 13
#define TNOT 14
#define TCASE 15
#define TDO 16
#define TDONE 17
#define TELIF 18
#define TELSE 19
#define TESAC 20
#define TFI 21
#define TFOR 22
#define TIF 23
#define TIN 24
#define TTHEN 25
#define TUNTIL 26
#define TWHILE 27
#define TBEGIN 28
#define TEND 29
/* control characters in argument strings */
#define CTLESC '\201'
#define CTLVAR '\202'
#define CTLENDVAR '\203'
#define CTLBACKQ '\204'
#define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */
/* CTLBACKQ | CTLQUOTE == '\205' */
#define CTLARI '\206'
#define CTLENDARI '\207'
#define CTLQUOTEMARK '\210'
#define is_digit(c) ((c)>='0' && (c)<='9')
#define is_name(c) (((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalpha((unsigned char) (c))))
#define is_in_name(c) (((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalnum((unsigned char) (c))))
/*
* is_special(c) evaluates to 1 for c in "!#$*-0123456789?@"; 0 otherwise
* (assuming ascii char codes, as the original implementation did)
*/
#define is_special(c) \
( (((unsigned int)c) - 33 < 32) \
&& ((0xc1ff920dUL >> (((unsigned int)c) - 33)) & 1))
#define digit_val(c) ((c) - '0')
#define S_DFL 1 /* default signal handling (SIG_DFL) */
#define S_CATCH 2 /* signal is caught */
#define S_IGN 3 /* signal is ignored (SIG_IGN) */
#define S_HARD_IGN 4 /* signal is ignored permenantly */
#define S_RESET 5 /* temporary - to reset a hard ignored sig */
/* variable substitution byte (follows CTLVAR) */
#define VSTYPE 0x0f /* type of variable substitution */
#define VSNUL 0x10 /* colon--treat the empty string as unset */
#define VSQUOTE 0x80 /* inside double quotes--suppress splitting */
/* values of VSTYPE field */
#define VSNORMAL 0x1 /* normal variable: $var or ${var} */
#define VSMINUS 0x2 /* ${var-text} */
#define VSPLUS 0x3 /* ${var+text} */
#define VSQUESTION 0x4 /* ${var?message} */
#define VSASSIGN 0x5 /* ${var=text} */
#define VSTRIMLEFT 0x6 /* ${var#pattern} */
#define VSTRIMLEFTMAX 0x7 /* ${var##pattern} */
#define VSTRIMRIGHT 0x8 /* ${var%pattern} */
#define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */
#define VSLENGTH 0xa /* ${#var} */
/* flags passed to redirect */
#define REDIR_PUSH 01 /* save previous values of file descriptors */
#define REDIR_BACKQ 02 /* save the command output to pipe */
/*
* BSD setjmp saves the signal mask, which violates ANSI C and takes time,
* so we use _setjmp instead.
*/
#if 0
#if defined(BSD)
#define setjmp(jmploc) _setjmp(jmploc)
#define longjmp(jmploc, val) _longjmp(jmploc, val)
#endif
#endif
/*
* Most machines require the value returned from malloc to be aligned
* in some way. The following macro will get this right on many machines.
*/
#ifndef ALIGN
union align {
int i;
char *cp;
};
#define ALIGN(nbytes) (((nbytes) + sizeof(union align) - 1) & ~(sizeof(union align) - 1))
#endif
#ifdef BB_LOCALE_SUPPORT
#include <locale.h>
static void change_lc_all(const char *value);
static void change_lc_ctype(const char *value);
#endif
/*
* These macros allow the user to suspend the handling of interrupt signals
* over a period of time. This is similar to SIGHOLD to or sigblock, but
* much more efficient and portable. (But hacking the kernel is so much
* more fun than worrying about efficiency and portability. :-))
*/
static void onint(void);
static volatile int suppressint;
static volatile int intpending;
#define INTOFF suppressint++
#ifndef CONFIG_ASH_OPTIMIZE_FOR_SIZE
#define INTON { if (--suppressint == 0 && intpending) onint(); }
#define FORCEINTON {suppressint = 0; if (intpending) onint();}
#else
static void __inton(void);
static void forceinton(void);
#define INTON __inton()
#define FORCEINTON forceinton()
#endif
#define CLEAR_PENDING_INT intpending = 0
#define int_pending() intpending
typedef void *pointer;
#ifndef NULL
#define NULL (void *)0
#endif
static pointer stalloc(int);
static void stunalloc(pointer);
static void ungrabstackstr(char *, char *);
static char *growstackstr(void);
static char *makestrspace(size_t newlen);
/*
* Parse trees for commands are allocated in lifo order, so we use a stack
* to make this more efficient, and also to avoid all sorts of exception
* handling code to handle interrupts in the middle of a parse.
*
* The size 504 was chosen because the Ultrix malloc handles that size
* well.
*/
#define MINSIZE 504 /* minimum size of a block */
struct stack_block {
struct stack_block *prev;
char space[MINSIZE];
};
static struct stack_block stackbase;
static struct stack_block *stackp = &stackbase;
static struct stackmark *markp;
static char *stacknxt = stackbase.space;
static int stacknleft = MINSIZE;
#define equal(s1, s2) (strcmp(s1, s2) == 0)
#define stackblock() stacknxt
#define stackblocksize() stacknleft
#define STARTSTACKSTR(p) p = stackblock(), sstrnleft = stackblocksize()
#define STPUTC(c, p) (--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c)))
#define CHECKSTRSPACE(n, p) { if (sstrnleft < n) p = makestrspace(n); }
#define STACKSTRNUL(p) (sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0'))
#define USTPUTC(c, p) (--sstrnleft, *p++ = (c))
#define STUNPUTC(p) (++sstrnleft, --p)
#define STTOPC(p) p[-1]
#define STADJUST(amount, p) (p += (amount), sstrnleft -= (amount))
#define grabstackstr(p) stalloc(stackblocksize() - sstrnleft)
#ifdef DEBUG
#define TRACE(param) trace param
typedef union node unode;
static void trace(const char *, ...);
static void trargs(char **);
static void showtree(unode *);
static void trputc(int);
static void trputs(const char *);
static void opentrace(void);
#else
#define TRACE(param)
#endif
#define NSEMI 0
#define NCMD 1
#define NPIPE 2
#define NREDIR 3
#define NBACKGND 4
#define NSUBSHELL 5
#define NAND 6
#define NOR 7
#define NIF 8
#define NWHILE 9
#define NUNTIL 10
#define NFOR 11
#define NCASE 12
#define NCLIST 13
#define NDEFUN 14
#define NARG 15
#define NTO 16
#define NFROM 17
#define NFROMTO 18
#define NAPPEND 19
#define NTOOV 20
#define NTOFD 21
#define NFROMFD 22
#define NHERE 23
#define NXHERE 24
#define NNOT 25
/*
* expandarg() flags
*/
#define EXP_FULL 0x1 /* perform word splitting & file globbing */
#define EXP_TILDE 0x2 /* do normal tilde expansion */
#define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
#define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */
#define NOPTS 16
static char optet_vals[NOPTS];
static const char *const optlist[NOPTS] = {
"e" "errexit",
"f" "noglob",
"I" "ignoreeof",
"i" "interactive",
"m" "monitor",
"n" "noexec",
"s" "stdin",
"x" "xtrace",
"v" "verbose",
"V" "vi",
"E" "emacs",
"C" "noclobber",
"a" "allexport",
"b" "notify",
"u" "nounset",
"q" "quietprofile"
};
#define optent_name(optent) (optent+1)
#define optent_letter(optent) optent[0]
#define optent_val(optent) optet_vals[optent]
#define eflag optent_val(0)
#define fflag optent_val(1)
#define Iflag optent_val(2)
#define iflag optent_val(3)
#define mflag optent_val(4)
#define nflag optent_val(5)
#define sflag optent_val(6)
#define xflag optent_val(7)
#define vflag optent_val(8)
#define Vflag optent_val(9)
#define Eflag optent_val(10)
#define Cflag optent_val(11)
#define aflag optent_val(12)
#define bflag optent_val(13)
#define uflag optent_val(14)
#define qflag optent_val(15)
/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */
#define FORK_FG 0
#define FORK_BG 1
#define FORK_NOJOB 2
struct nbinary {
int type;
union node *ch1;
union node *ch2;
};
struct ncmd {
int type;
int backgnd;
union node *assign;
union node *args;
union node *redirect;
};
struct npipe {
int type;
int backgnd;
struct nodelist *cmdlist;
};
struct nredir {
int type;
union node *n;
union node *redirect;
};
struct nif {
int type;
union node *test;
union node *ifpart;
union node *elsepart;
};
struct nfor {
int type;
union node *args;
union node *body;
char *var;
};
struct ncase {
int type;
union node *expr;
union node *cases;
};
struct nclist {
int type;
union node *next;
union node *pattern;
union node *body;
};
struct narg {
int type;
union node *next;
char *text;
struct nodelist *backquote;
};
struct nfile {
int type;
union node *next;
int fd;
union node *fname;
char *expfname;
};
struct ndup {
int type;
union node *next;
int fd;
int dupfd;
union node *vname;
};
struct nhere {
int type;
union node *next;
int fd;
union node *doc;
};
struct nnot {
int type;
union node *com;
};
union node {
int type;
struct nbinary nbinary;
struct ncmd ncmd;
struct npipe npipe;
struct nredir nredir;
struct nif nif;
struct nfor nfor;
struct ncase ncase;
struct nclist nclist;
struct narg narg;
struct nfile nfile;
struct ndup ndup;
struct nhere nhere;
struct nnot nnot;
};
struct nodelist {
struct nodelist *next;
union node *n;
};
struct backcmd { /* result of evalbackcmd */
int fd; /* file descriptor to read from */
char *buf; /* buffer */
int nleft; /* number of chars in buffer */
struct job *jp; /* job structure for command */
};
struct cmdentry {
int cmdtype;
union param {
int index;
union node *func;
const struct builtincmd *cmd;
} u;
};
struct strlist {
struct strlist *next;
char *text;
};
struct arglist {
struct strlist *list;
struct strlist **lastp;
};
struct strpush {
struct strpush *prev; /* preceding string on stack */
char *prevstring;
int prevnleft;
#ifdef CONFIG_ASH_ALIAS
struct alias *ap; /* if push was associated with an alias */
#endif
char *string; /* remember the string since it may change */
};
struct parsefile {
struct parsefile *prev; /* preceding file on stack */
int linno; /* current line */
int fd; /* file descriptor (or -1 if string) */
int nleft; /* number of chars left in this line */
int lleft; /* number of chars left in this buffer */
char *nextc; /* next char in buffer */
char *buf; /* input buffer */
struct strpush *strpush; /* for pushing strings at this level */
struct strpush basestrpush; /* so pushing one is fast */
};
struct stackmark {
struct stack_block *stackp;
char *stacknxt;
int stacknleft;
struct stackmark *marknext;
};
struct shparam {
int nparam; /* # of positional parameters (without $0) */
unsigned char malloc; /* if parameter list dynamically allocated */
char **p; /* parameter list */
int optind; /* next parameter to be processed by getopts */
int optoff; /* used by getopts */
};
/*
* When commands are first encountered, they are entered in a hash table.
* This ensures that a full path search will not have to be done for them
* on each invocation.
*
* We should investigate converting to a linear search, even though that
* would make the command name "hash" a misnomer.
*/
#define CMDTABLESIZE 31 /* should be prime */
#define ARB 1 /* actual size determined at run time */
struct tblentry {
struct tblentry *next; /* next entry in hash chain */
union param param; /* definition of builtin function */
short cmdtype; /* index identifying command */
char rehash; /* if set, cd done since entry created */
char cmdname[ARB]; /* name of command */
};
static struct tblentry *cmdtable[CMDTABLESIZE];
static int builtinloc = -1; /* index in path of %builtin, or -1 */
static int exerrno = 0; /* Last exec error */
static void tryexec(char *, char **, char **);
static void printentry(struct tblentry *, int);
static void clearcmdentry(int);
static struct tblentry *cmdlookup(const char *, int);
static void delete_cmd_entry(void);
static int path_change(const char *, int *);
static void flushall(void);
static void out2fmt(const char *, ...)
__attribute__ ((__format__(__printf__, 1, 2)));
static int xwrite(int, const char *, int);
static inline void outstr(const char *p, FILE * file)
{
fputs(p, file);
}
static void out1str(const char *p)
{
outstr(p, stdout);
}
static void out2str(const char *p)
{
outstr(p, stderr);
}
#ifndef CONFIG_ASH_OPTIMIZE_FOR_SIZE
#define out2c(c) putc((c), stderr)
#else
static void out2c(int c)
{
putc(c, stderr);
}
#endif
#ifdef CONFIG_ASH_OPTIMIZE_FOR_SIZE
#define USE_SIT_FUNCTION
#endif
/* number syntax index */
#define BASESYNTAX 0 /* not in quotes */
#define DQSYNTAX 1 /* in double quotes */
#define SQSYNTAX 2 /* in single quotes */
#define ARISYNTAX 3 /* in arithmetic */
static const char S_I_T[][4] = {
{CSPCL, CIGN, CIGN, CIGN}, /* 0, PEOA */
{CSPCL, CWORD, CWORD, CWORD}, /* 1, ' ' */
{CNL, CNL, CNL, CNL}, /* 2, \n */
{CWORD, CCTL, CCTL, CWORD}, /* 3, !*-/:=?[]~ */
{CDQUOTE, CENDQUOTE, CWORD, CDQUOTE}, /* 4, '"' */
{CVAR, CVAR, CWORD, CVAR}, /* 5, $ */
{CSQUOTE, CWORD, CENDQUOTE, CSQUOTE}, /* 6, "'" */
{CSPCL, CWORD, CWORD, CLP}, /* 7, ( */
{CSPCL, CWORD, CWORD, CRP}, /* 8, ) */
{CBACK, CBACK, CCTL, CBACK}, /* 9, \ */
{CBQUOTE, CBQUOTE, CWORD, CBQUOTE}, /* 10, ` */
{CENDVAR, CENDVAR, CWORD, CENDVAR}, /* 11, } */
#ifndef USE_SIT_FUNCTION
{CENDFILE, CENDFILE, CENDFILE, CENDFILE}, /* 12, PEOF */
{CWORD, CWORD, CWORD, CWORD}, /* 13, 0-9A-Za-z */
{CCTL, CCTL, CCTL, CCTL} /* 14, CTLESC ... */
#endif
};
#ifdef USE_SIT_FUNCTION
#define U_C(c) ((unsigned char)(c))
static int SIT(int c, int syntax)
{
static const char spec_symbls[] = "\t\n !\"$&'()*-/:;<=>?[\\]`|}~";
static const char syntax_index_table[] = {
1, 2, 1, 3, 4, 5, 1, 6, /* "\t\n !\"$&'" */
7, 8, 3, 3, 3, 3, 1, 1, /* "()*-/:;<" */
3, 1, 3, 3, 9, 3, 10, 1, /* "=>?[\\]`|" */
11, 3
}; /* "}~" */
const char *s;
int indx;
if (c == PEOF) /* 2^8+2 */
return CENDFILE;
if (c == PEOA) /* 2^8+1 */
indx = 0;
else if (U_C(c) >= U_C(CTLESC) && U_C(c) <= U_C(CTLQUOTEMARK))
return CCTL;
else {
s = strchr(spec_symbls, c);
if (s == 0)
return CWORD;
indx = syntax_index_table[(s - spec_symbls)];
}
return S_I_T[indx][syntax];
}
#else /* USE_SIT_FUNCTION */
#define SIT(c, syntax) S_I_T[(int)syntax_index_table[((int)c)+SYNBASE]][syntax]
#define CSPCL_CIGN_CIGN_CIGN 0
#define CSPCL_CWORD_CWORD_CWORD 1
#define CNL_CNL_CNL_CNL 2
#define CWORD_CCTL_CCTL_CWORD 3
#define CDQUOTE_CENDQUOTE_CWORD_CDQUOTE 4
#define CVAR_CVAR_CWORD_CVAR 5
#define CSQUOTE_CWORD_CENDQUOTE_CSQUOTE 6
#define CSPCL_CWORD_CWORD_CLP 7
#define CSPCL_CWORD_CWORD_CRP 8
#define CBACK_CBACK_CCTL_CBACK 9
#define CBQUOTE_CBQUOTE_CWORD_CBQUOTE 10
#define CENDVAR_CENDVAR_CWORD_CENDVAR 11
#define CENDFILE_CENDFILE_CENDFILE_CENDFILE 12
#define CWORD_CWORD_CWORD_CWORD 13
#define CCTL_CCTL_CCTL_CCTL 14
static const char syntax_index_table[258] = {
/* BASESYNTAX_DQSYNTAX_SQSYNTAX_ARISYNTAX */
/* 0 -130 PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE,
/* 1 -129 PEOA */ CSPCL_CIGN_CIGN_CIGN,
/* 2 -128 0xff */ CWORD_CWORD_CWORD_CWORD,
/* 3 -127 */ CCTL_CCTL_CCTL_CCTL,
/* CTLQUOTEMARK */
/* 4 -126 */ CCTL_CCTL_CCTL_CCTL,
/* 5 -125 */ CCTL_CCTL_CCTL_CCTL,
/* 6 -124 */ CCTL_CCTL_CCTL_CCTL,
/* 7 -123 */ CCTL_CCTL_CCTL_CCTL,
/* 8 -122 */ CCTL_CCTL_CCTL_CCTL,
/* 9 -121 */ CCTL_CCTL_CCTL_CCTL,
/* 10 -120 */ CCTL_CCTL_CCTL_CCTL,
/* CTLESC */
/* 11 -119 */ CWORD_CWORD_CWORD_CWORD,
/* 12 -118 */ CWORD_CWORD_CWORD_CWORD,
/* 13 -117 */ CWORD_CWORD_CWORD_CWORD,
/* 14 -116 */ CWORD_CWORD_CWORD_CWORD,
/* 15 -115 */ CWORD_CWORD_CWORD_CWORD,
/* 16 -114 */ CWORD_CWORD_CWORD_CWORD,
/* 17 -113 */ CWORD_CWORD_CWORD_CWORD,
/* 18 -112 */ CWORD_CWORD_CWORD_CWORD,
/* 19 -111 */ CWORD_CWORD_CWORD_CWORD,
/* 20 -110 */ CWORD_CWORD_CWORD_CWORD,
/* 21 -109 */ CWORD_CWORD_CWORD_CWORD,
/* 22 -108 */ CWORD_CWORD_CWORD_CWORD,
/* 23 -107 */ CWORD_CWORD_CWORD_CWORD,
/* 24 -106 */ CWORD_CWORD_CWORD_CWORD,
/* 25 -105 */ CWORD_CWORD_CWORD_CWORD,
/* 26 -104 */ CWORD_CWORD_CWORD_CWORD,
/* 27 -103 */ CWORD_CWORD_CWORD_CWORD,
/* 28 -102 */ CWORD_CWORD_CWORD_CWORD,
/* 29 -101 */ CWORD_CWORD_CWORD_CWORD,
/* 30 -100 */ CWORD_CWORD_CWORD_CWORD,
/* 31 -99 */ CWORD_CWORD_CWORD_CWORD,
/* 32 -98 */ CWORD_CWORD_CWORD_CWORD,
/* 33 -97 */ CWORD_CWORD_CWORD_CWORD,
/* 34 -96 */ CWORD_CWORD_CWORD_CWORD,
/* 35 -95 */ CWORD_CWORD_CWORD_CWORD,
/* 36 -94 */ CWORD_CWORD_CWORD_CWORD,
/* 37 -93 */ CWORD_CWORD_CWORD_CWORD,
/* 38 -92 */ CWORD_CWORD_CWORD_CWORD,
/* 39 -91 */ CWORD_CWORD_CWORD_CWORD,
/* 40 -90 */ CWORD_CWORD_CWORD_CWORD,
/* 41 -89 */ CWORD_CWORD_CWORD_CWORD,
/* 42 -88 */ CWORD_CWORD_CWORD_CWORD,
/* 43 -87 */ CWORD_CWORD_CWORD_CWORD,
/* 44 -86 */ CWORD_CWORD_CWORD_CWORD,
/* 45 -85 */ CWORD_CWORD_CWORD_CWORD,
/* 46 -84 */ CWORD_CWORD_CWORD_CWORD,
/* 47 -83 */ CWORD_CWORD_CWORD_CWORD,
/* 48 -82 */ CWORD_CWORD_CWORD_CWORD,
/* 49 -81 */ CWORD_CWORD_CWORD_CWORD,
/* 50 -80 */ CWORD_CWORD_CWORD_CWORD,
/* 51 -79 */ CWORD_CWORD_CWORD_CWORD,
/* 52 -78 */ CWORD_CWORD_CWORD_CWORD,
/* 53 -77 */ CWORD_CWORD_CWORD_CWORD,
/* 54 -76 */ CWORD_CWORD_CWORD_CWORD,
/* 55 -75 */ CWORD_CWORD_CWORD_CWORD,
/* 56 -74 */ CWORD_CWORD_CWORD_CWORD,
/* 57 -73 */ CWORD_CWORD_CWORD_CWORD,
/* 58 -72 */ CWORD_CWORD_CWORD_CWORD,
/* 59 -71 */ CWORD_CWORD_CWORD_CWORD,
/* 60 -70 */ CWORD_CWORD_CWORD_CWORD,
/* 61 -69 */ CWORD_CWORD_CWORD_CWORD,
/* 62 -68 */ CWORD_CWORD_CWORD_CWORD,
/* 63 -67 */ CWORD_CWORD_CWORD_CWORD,
/* 64 -66 */ CWORD_CWORD_CWORD_CWORD,
/* 65 -65 */ CWORD_CWORD_CWORD_CWORD,
/* 66 -64 */ CWORD_CWORD_CWORD_CWORD,
/* 67 -63 */ CWORD_CWORD_CWORD_CWORD,
/* 68 -62 */ CWORD_CWORD_CWORD_CWORD,
/* 69 -61 */ CWORD_CWORD_CWORD_CWORD,
/* 70 -60 */ CWORD_CWORD_CWORD_CWORD,
/* 71 -59 */ CWORD_CWORD_CWORD_CWORD,
/* 72 -58 */ CWORD_CWORD_CWORD_CWORD,
/* 73 -57 */ CWORD_CWORD_CWORD_CWORD,
/* 74 -56 */ CWORD_CWORD_CWORD_CWORD,
/* 75 -55 */ CWORD_CWORD_CWORD_CWORD,
/* 76 -54 */ CWORD_CWORD_CWORD_CWORD,
/* 77 -53 */ CWORD_CWORD_CWORD_CWORD,
/* 78 -52 */ CWORD_CWORD_CWORD_CWORD,
/* 79 -51 */ CWORD_CWORD_CWORD_CWORD,
/* 80 -50 */ CWORD_CWORD_CWORD_CWORD,
/* 81 -49 */ CWORD_CWORD_CWORD_CWORD,
/* 82 -48 */ CWORD_CWORD_CWORD_CWORD,
/* 83 -47 */ CWORD_CWORD_CWORD_CWORD,
/* 84 -46 */ CWORD_CWORD_CWORD_CWORD,
/* 85 -45 */ CWORD_CWORD_CWORD_CWORD,
/* 86 -44 */ CWORD_CWORD_CWORD_CWORD,
/* 87 -43 */ CWORD_CWORD_CWORD_CWORD,
/* 88 -42 */ CWORD_CWORD_CWORD_CWORD,
/* 89 -41 */ CWORD_CWORD_CWORD_CWORD,
/* 90 -40 */ CWORD_CWORD_CWORD_CWORD,
/* 91 -39 */ CWORD_CWORD_CWORD_CWORD,
/* 92 -38 */ CWORD_CWORD_CWORD_CWORD,
/* 93 -37 */ CWORD_CWORD_CWORD_CWORD,
/* 94 -36 */ CWORD_CWORD_CWORD_CWORD,
/* 95 -35 */ CWORD_CWORD_CWORD_CWORD,
/* 96 -34 */ CWORD_CWORD_CWORD_CWORD,
/* 97 -33 */ CWORD_CWORD_CWORD_CWORD,
/* 98 -32 */ CWORD_CWORD_CWORD_CWORD,
/* 99 -31 */ CWORD_CWORD_CWORD_CWORD,
/* 100 -30 */ CWORD_CWORD_CWORD_CWORD,
/* 101 -29 */ CWORD_CWORD_CWORD_CWORD,
/* 102 -28 */ CWORD_CWORD_CWORD_CWORD,
/* 103 -27 */ CWORD_CWORD_CWORD_CWORD,
/* 104 -26 */ CWORD_CWORD_CWORD_CWORD,
/* 105 -25 */ CWORD_CWORD_CWORD_CWORD,
/* 106 -24 */ CWORD_CWORD_CWORD_CWORD,
/* 107 -23 */ CWORD_CWORD_CWORD_CWORD,
/* 108 -22 */ CWORD_CWORD_CWORD_CWORD,
/* 109 -21 */ CWORD_CWORD_CWORD_CWORD,
/* 110 -20 */ CWORD_CWORD_CWORD_CWORD,
/* 111 -19 */ CWORD_CWORD_CWORD_CWORD,
/* 112 -18 */ CWORD_CWORD_CWORD_CWORD,
/* 113 -17 */ CWORD_CWORD_CWORD_CWORD,
/* 114 -16 */ CWORD_CWORD_CWORD_CWORD,
/* 115 -15 */ CWORD_CWORD_CWORD_CWORD,
/* 116 -14 */ CWORD_CWORD_CWORD_CWORD,
/* 117 -13 */ CWORD_CWORD_CWORD_CWORD,
/* 118 -12 */ CWORD_CWORD_CWORD_CWORD,
/* 119 -11 */ CWORD_CWORD_CWORD_CWORD,
/* 120 -10 */ CWORD_CWORD_CWORD_CWORD,
/* 121 -9 */ CWORD_CWORD_CWORD_CWORD,
/* 122 -8 */ CWORD_CWORD_CWORD_CWORD,
/* 123 -7 */ CWORD_CWORD_CWORD_CWORD,
/* 124 -6 */ CWORD_CWORD_CWORD_CWORD,
/* 125 -5 */ CWORD_CWORD_CWORD_CWORD,
/* 126 -4 */ CWORD_CWORD_CWORD_CWORD,
/* 127 -3 */ CWORD_CWORD_CWORD_CWORD,
/* 128 -2 */ CWORD_CWORD_CWORD_CWORD,
/* 129 -1 */ CWORD_CWORD_CWORD_CWORD,
/* 130 0 */ CWORD_CWORD_CWORD_CWORD,
/* 131 1 */ CWORD_CWORD_CWORD_CWORD,
/* 132 2 */ CWORD_CWORD_CWORD_CWORD,
/* 133 3 */ CWORD_CWORD_CWORD_CWORD,
/* 134 4 */ CWORD_CWORD_CWORD_CWORD,
/* 135 5 */ CWORD_CWORD_CWORD_CWORD,
/* 136 6 */ CWORD_CWORD_CWORD_CWORD,
/* 137 7 */ CWORD_CWORD_CWORD_CWORD,
/* 138 8 */ CWORD_CWORD_CWORD_CWORD,
/* 139 9 "\t" */ CSPCL_CWORD_CWORD_CWORD,
/* 140 10 "\n" */ CNL_CNL_CNL_CNL,
/* 141 11 */ CWORD_CWORD_CWORD_CWORD,
/* 142 12 */ CWORD_CWORD_CWORD_CWORD,
/* 143 13 */ CWORD_CWORD_CWORD_CWORD,
/* 144 14 */ CWORD_CWORD_CWORD_CWORD,
/* 145 15 */ CWORD_CWORD_CWORD_CWORD,
/* 146 16 */ CWORD_CWORD_CWORD_CWORD,
/* 147 17 */ CWORD_CWORD_CWORD_CWORD,
/* 148 18 */ CWORD_CWORD_CWORD_CWORD,
/* 149 19 */ CWORD_CWORD_CWORD_CWORD,
/* 150 20 */ CWORD_CWORD_CWORD_CWORD,
/* 151 21 */ CWORD_CWORD_CWORD_CWORD,
/* 152 22 */ CWORD_CWORD_CWORD_CWORD,
/* 153 23 */ CWORD_CWORD_CWORD_CWORD,
/* 154 24 */ CWORD_CWORD_CWORD_CWORD,
/* 155 25 */ CWORD_CWORD_CWORD_CWORD,
/* 156 26 */ CWORD_CWORD_CWORD_CWORD,
/* 157 27 */ CWORD_CWORD_CWORD_CWORD,
/* 158 28 */ CWORD_CWORD_CWORD_CWORD,
/* 159 29 */ CWORD_CWORD_CWORD_CWORD,
/* 160 30 */ CWORD_CWORD_CWORD_CWORD,
/* 161 31 */ CWORD_CWORD_CWORD_CWORD,
/* 162 32 " " */ CSPCL_CWORD_CWORD_CWORD,
/* 163 33 "!" */ CWORD_CCTL_CCTL_CWORD,
/* 164 34 """ */ CDQUOTE_CENDQUOTE_CWORD_CDQUOTE,
/* 165 35 "#" */ CWORD_CWORD_CWORD_CWORD,
/* 166 36 "$" */ CVAR_CVAR_CWORD_CVAR,
/* 167 37 "%" */ CWORD_CWORD_CWORD_CWORD,
/* 168 38 "&" */ CSPCL_CWORD_CWORD_CWORD,
/* 169 39 "'" */ CSQUOTE_CWORD_CENDQUOTE_CSQUOTE,
/* 170 40 "(" */ CSPCL_CWORD_CWORD_CLP,
/* 171 41 ")" */ CSPCL_CWORD_CWORD_CRP,
/* 172 42 "*" */ CWORD_CCTL_CCTL_CWORD,
/* 173 43 "+" */ CWORD_CWORD_CWORD_CWORD,
/* 174 44 "," */ CWORD_CWORD_CWORD_CWORD,
/* 175 45 "-" */ CWORD_CCTL_CCTL_CWORD,
/* 176 46 "." */ CWORD_CWORD_CWORD_CWORD,
/* 177 47 "/" */ CWORD_CCTL_CCTL_CWORD,
/* 178 48 "0" */ CWORD_CWORD_CWORD_CWORD,
/* 179 49 "1" */ CWORD_CWORD_CWORD_CWORD,
/* 180 50 "2" */ CWORD_CWORD_CWORD_CWORD,
/* 181 51 "3" */ CWORD_CWORD_CWORD_CWORD,
/* 182 52 "4" */ CWORD_CWORD_CWORD_CWORD,
/* 183 53 "5" */ CWORD_CWORD_CWORD_CWORD,
/* 184 54 "6" */ CWORD_CWORD_CWORD_CWORD,
/* 185 55 "7" */ CWORD_CWORD_CWORD_CWORD,
/* 186 56 "8" */ CWORD_CWORD_CWORD_CWORD,
/* 187 57 "9" */ CWORD_CWORD_CWORD_CWORD,
/* 188 58 ":" */ CWORD_CCTL_CCTL_CWORD,
/* 189 59 ";" */ CSPCL_CWORD_CWORD_CWORD,
/* 190 60 "<" */ CSPCL_CWORD_CWORD_CWORD,
/* 191 61 "=" */ CWORD_CCTL_CCTL_CWORD,
/* 192 62 ">" */ CSPCL_CWORD_CWORD_CWORD,
/* 193 63 "?" */ CWORD_CCTL_CCTL_CWORD,
/* 194 64 "@" */ CWORD_CWORD_CWORD_CWORD,
/* 195 65 "A" */ CWORD_CWORD_CWORD_CWORD,
/* 196 66 "B" */ CWORD_CWORD_CWORD_CWORD,
/* 197 67 "C" */ CWORD_CWORD_CWORD_CWORD,
/* 198 68 "D" */ CWORD_CWORD_CWORD_CWORD,
/* 199 69 "E" */ CWORD_CWORD_CWORD_CWORD,
/* 200 70 "F" */ CWORD_CWORD_CWORD_CWORD,
/* 201 71 "G" */ CWORD_CWORD_CWORD_CWORD,
/* 202 72 "H" */ CWORD_CWORD_CWORD_CWORD,
/* 203 73 "I" */ CWORD_CWORD_CWORD_CWORD,
/* 204 74 "J" */ CWORD_CWORD_CWORD_CWORD,
/* 205 75 "K" */ CWORD_CWORD_CWORD_CWORD,
/* 206 76 "L" */ CWORD_CWORD_CWORD_CWORD,
/* 207 77 "M" */ CWORD_CWORD_CWORD_CWORD,