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" },
64 { CSUBSTOP, "CSUBSTOP" },
67 #define N_WFLAGS (sizeof (wordflags) / sizeof (wordflags[0]))
76 * This file was generated by mksyntax. DO NOT EDIT.\n\
81 #include \"stdc.h\"\n\
82 #include \"syntax.h\"\n\n";
87 fprintf (stderr, "%s: usage: %s [-d] [-o filename]\n", progname, progname);
98 for (i = 0; i < N_WFLAGS; i++)
99 if (strcmp (s, wordflags[i].fstr) == 0)
100 return wordflags[i].flag;
109 static char xbuf[16];
113 else if (ISPRINT (i))
119 else if (i == CTLESC)
121 else if (i == CTLNUL)
123 else if (i == '\033') /* ASCII */
131 case '\a': xbuf[1] = 'a'; break;
132 case '\v': xbuf[1] = 'v'; break;
133 case '\b': xbuf[1] = 'b'; break;
134 case '\f': xbuf[1] = 'f'; break;
135 case '\n': xbuf[1] = 'n'; break;
136 case '\r': xbuf[1] = 'r'; break;
137 case '\t': xbuf[1] = 't'; break;
138 default: sprintf (xbuf, "%d", i); break;
150 for (i = 0; i < N_WFLAGS; i++)
151 if (f == wordflags[i].flag)
152 return (wordflags[i].fstr);
153 return ((char *)NULL);
164 for (s = str; s && *s; s++)
170 fstr = getcstr (flag);
171 fprintf(stderr, "added %s for character %s\n", fstr, cdesc(uc));
187 fstr = getcstr (flag);
188 fprintf (stderr, "added %s for character %s\n", fstr, cdesc(c));
193 /* load up the correct flag values in lsyntax */
197 /* shell metacharacters */
198 addcstr (shell_meta_chars, CSHMETA);
200 /* shell word break characters */
201 addcstr (shell_break_chars, CSHBRK);
203 addcchar ('`', CBACKQ);
205 addcstr (shell_quote_chars, CQUOTE);
207 addcchar (CTLESC, CSPECL);
208 addcchar (CTLNUL, CSPECL);
210 addcstr (shell_exp_chars, CEXP);
212 addcstr (slashify_in_quotes, CBSDQUOTE);
213 addcstr (slashify_in_here_document, CBSHDOC);
215 addcstr (shell_glob_chars, CGLOB);
217 #if defined (EXTENDED_GLOB)
218 addcstr (ext_glob_chars, CXGLOB);
221 addcstr (shell_quote_chars, CXQUOTE);
222 addcchar ('\\', CXQUOTE);
224 addcstr ("@*#?-$!", CSPECVAR); /* omits $0...$9 and $_ */
226 addcstr ("-=?+", CSUBSTOP); /* OP in ${paramOPword} */
230 dump_lflags (fp, ind)
234 int xflags, first, i;
236 xflags = lsyntax[ind];
240 fputs (wordflags[0].fstr, fp);
243 for (i = 1; i < N_WFLAGS; i++)
244 if (xflags & wordflags[i].flag)
250 fputs (wordflags[i].fstr, fp);
260 fputs ("\t\t/* ", fp);
262 fprintf (fp, "%s", cdesc(i));
273 fprintf (fp, "const int sh_syntaxtab[%d] = {\n", SYNSIZE);
275 for (i = 0; i < SYNSIZE; i++)
284 fprintf (fp, "};\n");
296 if ((progname = strrchr (argv[0], '/')) == 0)
301 filename = (char *)NULL;
304 while ((opt = getopt (argc, argv, "do:")) != EOF)
324 fp = fopen (filename, "w");
327 fprintf (stderr, "%s: %s: cannot open: %s\n", progname, filename, strerror(errno));
338 for (i = 0; i < SYNSIZE; i++)
343 fprintf (fp, "%s\n", preamble);
344 fprintf (fp, "%s\n", includes);
354 #if !defined (HAVE_STRERROR)
356 #include <bashtypes.h>
358 # include <sys/param.h>
361 #if defined (HAVE_UNISTD_H)
365 /* Return a string corresponding to the error number E. From
367 #if defined (strerror)
375 static char emsg[40];
376 #if defined (HAVE_SYS_ERRLIST)
378 extern char *sys_errlist[];
380 if (e > 0 && e < sys_nerr)
381 return (sys_errlist[e]);
383 #endif /* HAVE_SYS_ERRLIST */
385 sprintf (emsg, "Unknown system error %d", e);
389 #endif /* HAVE_STRERROR */