VirtualBox

source: kBuild/trunk/src/kash/syntax.c@ 2629

Last change on this file since 2629 was 1233, checked in by bird, 17 years ago

keywords.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/* $NetBSD: syntax.c,v 1.1 2004/01/17 17:38:12 dsl Exp $ */
2
3#include "shell.h"
4#include "syntax.h"
5#include "parser.h"
6#include "shinstance.h"
7
8#ifdef _MSC_VER /* doesn't implement the fancy initializers I think... */
9
10char basesyntax[257] = {CSHEOF};
11char dqsyntax[257] = {CSHEOF};
12char sqsyntax[257] = {CSHEOF};
13char arisyntax[257] = {CSHEOF};
14char is_type[257] = {0};
15
16void init_syntax(void)
17{
18 char *tab;
19 int i;
20
21#define ndx(ch) (ch + 1 - CHAR_MIN)
22#define set(ch, val) tab[ndx(ch)] = val
23#define set_range(s, e, val) for (i = ndx(s); i <= ndx(e); i++) tab[i] = val
24
25 /*basesyntax*/
26 tab = basesyntax;
27 set_range(CTL_FIRST, CTL_LAST, CCTL);
28 set('\n', CNL);
29 set('\\', CBACK);
30 set('\'', CSQUOTE);
31 set('"', CDQUOTE);
32 set('`', CBQUOTE);
33 set('$', CVAR);
34 set('}', CENDVAR);
35 set('<', CSPCL);
36 set('>', CSPCL);
37 set('(', CSPCL);
38 set(')', CSPCL);
39 set(';', CSPCL);
40 set('&', CSPCL);
41 set('|', CSPCL);
42 set(' ', CSPCL);
43 set('\t', CSPCL);
44
45 tab = dqsyntax;
46 set_range(CTL_FIRST, CTL_LAST, CCTL);
47 set('\n', CNL);
48 set('\\', CBACK);
49 set('"', CDQUOTE);
50 set('`', CBQUOTE);
51 set('$', CVAR);
52 set('}', CENDVAR);
53 /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
54 set('!', CCTL);
55 set('*', CCTL);
56 set('?', CCTL);
57 set('[', CCTL);
58 set('=', CCTL);
59 set('~', CCTL);
60 set(':', CCTL);
61 set('/', CCTL);
62 set('-', CCTL);
63
64 tab = sqsyntax;
65 set_range(CTL_FIRST, CTL_LAST, CCTL);
66 set('\n', CNL);
67 set('\'', CSQUOTE);
68 /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
69 set('!', CCTL);
70 set('*', CCTL) ;
71 set('?', CCTL);
72 set('[', CCTL);
73 set('=', CCTL);
74 set('~', CCTL);
75 set(':', CCTL);
76 set('/', CCTL);
77 set('-', CCTL);
78
79 tab = arisyntax;
80 set_range(CTL_FIRST, CTL_LAST, CCTL);
81 set('\n', CNL);
82 set('\\', CBACK);
83 set('`', CBQUOTE);
84 set('\'', CSQUOTE);
85 set('"', CDQUOTE);
86 set('$', CVAR);
87 set('}', CENDVAR);
88 set('(', CLP);
89 set(')', CRP);
90
91 tab = is_type;
92 set_range('0', '9', ISDIGIT);
93 set_range('a', 'z', ISLOWER);
94 set_range('A', 'Z', ISUPPER);
95 set('_', ISUNDER);
96 set('#', ISSPECL);
97 set('?', ISSPECL);
98 set('$', ISSPECL);
99 set('!', ISSPECL);
100 set('-', ISSPECL);
101 set('*', ISSPECL);
102 set('@', ISSPECL);
103}
104
105#else /* !_MSC_VER */
106
107#if CWORD != 0
108#error initialisation assumes 'CWORD' is zero
109#endif
110
111#define ndx(ch) (ch + 1 - CHAR_MIN)
112#define set(ch, val) [ndx(ch)] = val,
113#define set_range(s, e, val) [ndx(s) ... ndx(e)] = val,
114
115/* syntax table used when not in quotes */
116const char basesyntax[257] = { CSHEOF,
117 set_range(CTL_FIRST, CTL_LAST, CCTL)
118 set('\n', CNL)
119 set('\\', CBACK)
120 set('\'', CSQUOTE)
121 set('"', CDQUOTE)
122 set('`', CBQUOTE)
123 set('$', CVAR)
124 set('}', CENDVAR)
125 set('<', CSPCL)
126 set('>', CSPCL)
127 set('(', CSPCL)
128 set(')', CSPCL)
129 set(';', CSPCL)
130 set('&', CSPCL)
131 set('|', CSPCL)
132 set(' ', CSPCL)
133 set('\t', CSPCL)
134};
135
136/* syntax table used when in double quotes */
137const char dqsyntax[257] = { CSHEOF,
138 set_range(CTL_FIRST, CTL_LAST, CCTL)
139 set('\n', CNL)
140 set('\\', CBACK)
141 set('"', CDQUOTE)
142 set('`', CBQUOTE)
143 set('$', CVAR)
144 set('}', CENDVAR)
145 /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
146 set('!', CCTL)
147 set('*', CCTL)
148 set('?', CCTL)
149 set('[', CCTL)
150 set('=', CCTL)
151 set('~', CCTL)
152 set(':', CCTL)
153 set('/', CCTL)
154 set('-', CCTL)
155};
156
157/* syntax table used when in single quotes */
158const char sqsyntax[257] = { CSHEOF,
159 set_range(CTL_FIRST, CTL_LAST, CCTL)
160 set('\n', CNL)
161 set('\'', CSQUOTE)
162 /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
163 set('!', CCTL)
164 set('*', CCTL)
165 set('?', CCTL)
166 set('[', CCTL)
167 set('=', CCTL)
168 set('~', CCTL)
169 set(':', CCTL)
170 set('/', CCTL)
171 set('-', CCTL)
172};
173
174/* syntax table used when in arithmetic */
175const char arisyntax[257] = { CSHEOF,
176 set_range(CTL_FIRST, CTL_LAST, CCTL)
177 set('\n', CNL)
178 set('\\', CBACK)
179 set('`', CBQUOTE)
180 set('\'', CSQUOTE)
181 set('"', CDQUOTE)
182 set('$', CVAR)
183 set('}', CENDVAR)
184 set('(', CLP)
185 set(')', CRP)
186};
187
188/* character classification table */
189const char is_type[257] = { 0,
190 set_range('0', '9', ISDIGIT)
191 set_range('a', 'z', ISLOWER)
192 set_range('A', 'Z', ISUPPER)
193 set('_', ISUNDER)
194 set('#', ISSPECL)
195 set('?', ISSPECL)
196 set('$', ISSPECL)
197 set('!', ISSPECL)
198 set('-', ISSPECL)
199 set('*', ISSPECL)
200 set('@', ISSPECL)
201};
202#endif /* !_MSC_VER */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette