2 * mksyntax.c - construct shell syntax table for fast char attribute lookup.
5 /* Copyright (C) 2000 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 it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with Bash; see the file COPYING. If not, write to the Free Software
21 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
27 #include "chartypes.h"
44 extern char *strerror();
52 { CSHMETA, "CSHMETA" },
58 { CBSDQUOTE, "CBSDQUOTE" },
59 { CBSHDOC, "CBSHDOC" },
62 { CXQUOTE, "CXQUOTE" },
63 { CSPECVAR, "CSPECVAR" }
66 #define N_WFLAGS (sizeof (wordflags) / sizeof (wordflags[0]))
75 * This file was generated by mksyntax. DO NOT EDIT.\n\
80 #include \"stdc.h\"\n\
81 #include \"syntax.h\"\n\n";
86 fprintf (stderr, "%s: usage: %s [-d] [-o filename]\n", progname, progname);
97 for (i = 0; i < N_WFLAGS; i++)
98 if (strcmp (s, wordflags[i].fstr) == 0)
99 return wordflags[i].flag;
108 static char xbuf[16];
112 else if (ISPRINT (i))
118 else if (i == CTLESC)
120 else if (i == CTLNUL)
122 else if (i == '\033') /* ASCII */
130 case '\a': xbuf[1] = 'a'; break;
131 case '\v': xbuf[1] = 'v'; break;
132 case '\b': xbuf[1] = 'b'; break;
133 case '\f': xbuf[1] = 'f'; break;
134 case '\n': xbuf[1] = 'n'; break;
135 case '\r': xbuf[1] = 'r'; break;
136 case '\t': xbuf[1] = 't'; break;
137 default: sprintf (xbuf, "%d", i); break;
149 for (i = 0; i < N_WFLAGS; i++)
150 if (f == wordflags[i].flag)
151 return (wordflags[i].fstr);
152 return ((char *)NULL);
163 for (s = str; s && *s; s++)
169 fstr = getcstr (flag);
170 fprintf(stderr, "added %s for character %s\n", fstr, cdesc(uc));
186 fstr = getcstr (flag);
187 fprintf (stderr, "added %s for character %s\n", fstr, cdesc(c));
192 /* load up the correct flag values in lsyntax */
196 /* shell metacharacters */
197 addcstr (shell_meta_chars, CSHMETA);
199 /* shell word break characters */
200 addcstr (shell_break_chars, CSHBRK);
202 addcchar ('`', CBACKQ);
204 addcstr (shell_quote_chars, CQUOTE);
206 addcchar (CTLESC, CSPECL);
207 addcchar (CTLNUL, CSPECL);
209 addcstr (shell_exp_chars, CEXP);
211 addcstr (slashify_in_quotes, CBSDQUOTE);
212 addcstr (slashify_in_here_document, CBSHDOC);
214 addcstr (shell_glob_chars, CGLOB);
216 #if defined (EXTENDED_GLOB)
217 addcstr (ext_glob_chars, CXGLOB);
220 addcstr (shell_quote_chars, CXQUOTE);
221 addcchar ('\\', CXQUOTE);
223 addcstr ("@*#?-$!", CSPECVAR); /* omits $0...$9 and $_ */
227 dump_lflags (fp, ind)
231 int xflags, first, i;
233 xflags = lsyntax[ind];
237 fputs (wordflags[0].fstr, fp);
240 for (i = 1; i < N_WFLAGS; i++)
241 if (xflags & wordflags[i].flag)
247 fputs (wordflags[i].fstr, fp);
257 fputs ("\t\t/* ", fp);
259 fprintf (fp, "%s", cdesc(i));
270 fprintf (fp, "const int sh_syntaxtab[%d] = {\n", SYNSIZE);
272 for (i = 0; i < SYNSIZE; i++)
281 fprintf (fp, "};\n");
293 if ((progname = strrchr (argv[0], '/')) == 0)
298 filename = (char *)NULL;
301 while ((opt = getopt (argc, argv, "do:")) != EOF)
321 fp = fopen (filename, "w");
324 fprintf (stderr, "%s: %s: cannot open: %s\n", progname, filename, strerror(errno));
335 for (i = 0; i < SYNSIZE; i++)
340 fprintf (fp, "%s\n", preamble);
341 fprintf (fp, "%s\n", includes);
351 #if !defined (HAVE_STRERROR)
353 #include <bashtypes.h>
355 # include <sys/param.h>
358 #if defined (HAVE_UNISTD_H)
362 /* Return a string corresponding to the error number E. From
364 #if defined (strerror)
372 static char emsg[40];
373 #if defined (HAVE_SYS_ERRLIST)
375 extern char *sys_errlist[];
377 if (e > 0 && e < sys_nerr)
378 return (sys_errlist[e]);
380 #endif /* HAVE_SYS_ERRLIST */
382 sprintf (emsg, "Unknown system error %d", e);
386 #endif /* HAVE_STRERROR */