2 * mksyntax.c - construct shell syntax table for fast char attribute lookup.
5 /* Copyright (C) 2000-2009 Free Software Foundation, Inc.
7 This file is part of GNU Bash, the Bourne Again SHell.
9 Bash is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Bash is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Bash. If not, see <http://www.gnu.org/licenses/>.
27 #include "chartypes.h"
44 extern char *strerror();
52 { CSHMETA, "CSHMETA" },
58 { CBSDQUOTE, "CBSDQUOTE" },
59 { CBSHDOC, "CBSHDOC" },
62 { CXQUOTE, "CXQUOTE" },
63 { CSPECVAR, "CSPECVAR" },
64 { CSUBSTOP, "CSUBSTOP" },
68 #define N_WFLAGS (sizeof (wordflags) / sizeof (wordflags[0]))
77 * This file was generated by mksyntax. DO NOT EDIT.\n\
82 #include \"config.h\"\n\
83 #include \"stdc.h\"\n\
84 #include \"syntax.h\"\n\n";
89 fprintf (stderr, "%s: usage: %s [-d] [-o filename]\n", progname, progname);
100 for (i = 0; i < N_WFLAGS; i++)
101 if (strcmp (s, wordflags[i].fstr) == 0)
102 return wordflags[i].flag;
111 static char xbuf[16];
115 else if (ISPRINT (i))
121 else if (i == CTLESC)
123 else if (i == CTLNUL)
125 else if (i == '\033') /* ASCII */
134 case '\a': xbuf[1] = 'a'; break;
135 case '\v': xbuf[1] = 'v'; break;
137 case '\007': xbuf[1] = 'a'; break;
138 case 0x0B: xbuf[1] = 'v'; break;
140 case '\b': xbuf[1] = 'b'; break;
141 case '\f': xbuf[1] = 'f'; break;
142 case '\n': xbuf[1] = 'n'; break;
143 case '\r': xbuf[1] = 'r'; break;
144 case '\t': xbuf[1] = 't'; break;
145 default: sprintf (xbuf, "%d", i); break;
157 for (i = 0; i < N_WFLAGS; i++)
158 if (f == wordflags[i].flag)
159 return (wordflags[i].fstr);
160 return ((char *)NULL);
171 for (s = str; s && *s; s++)
177 fstr = getcstr (flag);
178 fprintf(stderr, "added %s for character %s\n", fstr, cdesc(uc));
194 fstr = getcstr (flag);
195 fprintf (stderr, "added %s for character %s\n", fstr, cdesc(c));
206 for (i = 0; i < SYNSIZE; i++)
209 /* Since we don't call setlocale(), this defaults to the "C" locale, and
210 the default blank characters will be space and tab. */
212 lsyntax[uc] |= CBLANK;
216 /* load up the correct flag values in lsyntax */
220 /* shell metacharacters */
221 addcstr (shell_meta_chars, CSHMETA);
223 /* shell word break characters */
224 addcstr (shell_break_chars, CSHBRK);
226 addcchar ('`', CBACKQ);
228 addcstr (shell_quote_chars, CQUOTE);
230 addcchar (CTLESC, CSPECL);
231 addcchar (CTLNUL, CSPECL);
233 addcstr (shell_exp_chars, CEXP);
235 addcstr (slashify_in_quotes, CBSDQUOTE);
236 addcstr (slashify_in_here_document, CBSHDOC);
238 addcstr (shell_glob_chars, CGLOB);
240 #if defined (EXTENDED_GLOB)
241 addcstr (ext_glob_chars, CXGLOB);
244 addcstr (shell_quote_chars, CXQUOTE);
245 addcchar ('\\', CXQUOTE);
247 addcstr ("@*#?-$!", CSPECVAR); /* omits $0...$9 and $_ */
249 addcstr ("-=?+", CSUBSTOP); /* OP in ${paramOPword} */
255 dump_lflags (fp, ind)
259 int xflags, first, i;
261 xflags = lsyntax[ind];
265 fputs (wordflags[0].fstr, fp);
268 for (i = 1; i < N_WFLAGS; i++)
269 if (xflags & wordflags[i].flag)
275 fputs (wordflags[i].fstr, fp);
285 fputs ("\t\t/* ", fp);
287 fprintf (fp, "%s", cdesc(i));
298 fprintf (fp, "int sh_syntabsiz = %d;\n", SYNSIZE);
299 fprintf (fp, "int sh_syntaxtab[%d] = {\n", SYNSIZE);
301 for (i = 0; i < SYNSIZE; i++)
310 fprintf (fp, "};\n");
322 if ((progname = strrchr (argv[0], '/')) == 0)
327 filename = (char *)NULL;
330 while ((opt = getopt (argc, argv, "do:")) != EOF)
350 fp = fopen (filename, "w");
353 fprintf (stderr, "%s: %s: cannot open: %s\n", progname, filename, strerror(errno));
364 for (i = 0; i < SYNSIZE; i++)
369 fprintf (fp, "%s\n", preamble);
370 fprintf (fp, "%s\n", includes);
380 #if !defined (HAVE_STRERROR)
382 #include <bashtypes.h>
383 #if defined (HAVE_SYS_PARAM_H)
384 # include <sys/param.h>
387 #if defined (HAVE_UNISTD_H)
391 /* Return a string corresponding to the error number E. From
393 #if defined (strerror)
401 static char emsg[40];
402 #if defined (HAVE_SYS_ERRLIST)
404 extern char *sys_errlist[];
406 if (e > 0 && e < sys_nerr)
407 return (sys_errlist[e]);
409 #endif /* HAVE_SYS_ERRLIST */
411 sprintf (emsg, "Unknown system error %d", e);
415 #endif /* HAVE_STRERROR */