VirtualBox

source: kBuild/trunk/src/ash-messup/syntax.c@ 936

Last change on this file since 936 was 809, checked in by bird, 18 years ago

Solaris + cleanup.

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