2 * mksyntax.c - construct shell syntax table for fast char attribute lookup.
5 /* Copyright (C) 2000-2002 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 \"config.h\"\n\
82 #include \"stdc.h\"\n\
83 #include \"syntax.h\"\n\n";
88 fprintf (stderr, "%s: usage: %s [-d] [-o filename]\n", progname, progname);
99 for (i = 0; i < N_WFLAGS; i++)
100 if (strcmp (s, wordflags[i].fstr) == 0)
101 return wordflags[i].flag;
110 static char xbuf[16];
114 else if (ISPRINT (i))
120 else if (i == CTLESC)
122 else if (i == CTLNUL)
124 else if (i == '\033') /* ASCII */
133 case '\a': xbuf[1] = 'a'; break;
134 case '\v': xbuf[1] = 'v'; break;
136 case '\007': xbuf[1] = 'a'; break;
137 case 0x0B: xbuf[1] = 'v'; break;
139 case '\b': xbuf[1] = 'b'; break;
140 case '\f': xbuf[1] = 'f'; break;
141 case '\n': xbuf[1] = 'n'; break;
142 case '\r': xbuf[1] = 'r'; break;
143 case '\t': xbuf[1] = 't'; break;
144 default: sprintf (xbuf, "%d", i); break;
156 for (i = 0; i < N_WFLAGS; i++)
157 if (f == wordflags[i].flag)
158 return (wordflags[i].fstr);
159 return ((char *)NULL);
170 for (s = str; s && *s; s++)
176 fstr = getcstr (flag);
177 fprintf(stderr, "added %s for character %s\n", fstr, cdesc(uc));
193 fstr = getcstr (flag);
194 fprintf (stderr, "added %s for character %s\n", fstr, cdesc(c));
199 /* load up the correct flag values in lsyntax */
203 /* shell metacharacters */
204 addcstr (shell_meta_chars, CSHMETA);
206 /* shell word break characters */
207 addcstr (shell_break_chars, CSHBRK);
209 addcchar ('`', CBACKQ);
211 addcstr (shell_quote_chars, CQUOTE);
213 addcchar (CTLESC, CSPECL);
214 addcchar (CTLNUL, CSPECL);
216 addcstr (shell_exp_chars, CEXP);
218 addcstr (slashify_in_quotes, CBSDQUOTE);
219 addcstr (slashify_in_here_document, CBSHDOC);
221 addcstr (shell_glob_chars, CGLOB);
223 #if defined (EXTENDED_GLOB)
224 addcstr (ext_glob_chars, CXGLOB);
227 addcstr (shell_quote_chars, CXQUOTE);
228 addcchar ('\\', CXQUOTE);
230 addcstr ("@*#?-$!", CSPECVAR); /* omits $0...$9 and $_ */
232 addcstr ("-=?+", CSUBSTOP); /* OP in ${paramOPword} */
236 dump_lflags (fp, ind)
240 int xflags, first, i;
242 xflags = lsyntax[ind];
246 fputs (wordflags[0].fstr, fp);
249 for (i = 1; i < N_WFLAGS; i++)
250 if (xflags & wordflags[i].flag)
256 fputs (wordflags[i].fstr, fp);
266 fputs ("\t\t/* ", fp);
268 fprintf (fp, "%s", cdesc(i));
279 fprintf (fp, "int sh_syntabsiz = %d;\n", SYNSIZE);
280 fprintf (fp, "int sh_syntaxtab[%d] = {\n", SYNSIZE);
282 for (i = 0; i < SYNSIZE; i++)
291 fprintf (fp, "};\n");
303 if ((progname = strrchr (argv[0], '/')) == 0)
308 filename = (char *)NULL;
311 while ((opt = getopt (argc, argv, "do:")) != EOF)
331 fp = fopen (filename, "w");
334 fprintf (stderr, "%s: %s: cannot open: %s\n", progname, filename, strerror(errno));
345 for (i = 0; i < SYNSIZE; i++)
350 fprintf (fp, "%s\n", preamble);
351 fprintf (fp, "%s\n", includes);
361 #if !defined (HAVE_STRERROR)
363 #include <bashtypes.h>
365 # include <sys/param.h>
368 #if defined (HAVE_UNISTD_H)
372 /* Return a string corresponding to the error number E. From
374 #if defined (strerror)
382 static char emsg[40];
383 #if defined (HAVE_SYS_ERRLIST)
385 extern char *sys_errlist[];
387 if (e > 0 && e < sys_nerr)
388 return (sys_errlist[e]);
390 #endif /* HAVE_SYS_ERRLIST */
392 sprintf (emsg, "Unknown system error %d", e);
396 #endif /* HAVE_STRERROR */