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. */
39 extern char *strerror();
47 { CSHMETA
, "CSHMETA" },
53 { CBSDQUOTE
, "CBSDQUOTE" },
54 { CBSHDOC
, "CBSHDOC" },
57 { CXQUOTE
, "CXQUOTE" },
58 { CSPECVAR
, "CSPECVAR" }
61 #define N_WFLAGS (sizeof (wordflags) / sizeof (wordflags[0]))
70 * This file was generated by mksyntax. DO NOT EDIT.\n\
75 #include \"stdc.h\"\n\
76 #include \"syntax.h\"\n\n";
81 fprintf (stderr
, "%s: usage: %s [-d] [-o filename]\n", progname
, progname
);
91 for (i
= 0; i
< N_WFLAGS
; i
++)
92 if (strcmp (s
, wordflags
[i
].fstr
) == 0)
93 return wordflags
[i
].flag
;
101 static char xbuf
[16];
105 else if (isprint (i
))
111 else if (i
== CTLESC
)
113 else if (i
== CTLNUL
)
115 else if (i
== '\033') /* ASCII */
123 case '\a': xbuf
[1] = 'a'; break;
124 case '\v': xbuf
[1] = 'v'; break;
125 case '\b': xbuf
[1] = 'b'; break;
126 case '\f': xbuf
[1] = 'f'; break;
127 case '\n': xbuf
[1] = 'n'; break;
128 case '\r': xbuf
[1] = 'r'; break;
129 case '\t': xbuf
[1] = 't'; break;
130 default: sprintf (xbuf
, "%d", i
); break;
142 for (i
= 0; i
< N_WFLAGS
; i
++)
143 if (f
== wordflags
[i
].flag
)
144 return (wordflags
[i
].fstr
);
145 return ((char *)NULL
);
156 for (s
= (unsigned char *)str
; s
&& *s
; s
++)
160 fstr
= getcstr (flag
);
161 fprintf(stderr
, "added %s for character %s\n", fstr
, cdesc(*s
));
177 fstr
= getcstr (flag
);
178 fprintf (stderr
, "added %s for character %s\n", fstr
, cdesc(c
));
183 /* load up the correct flag values in lsyntax */
187 /* shell metacharacters */
188 addcstr (shell_meta_chars
, CSHMETA
);
190 /* shell word break characters */
191 addcstr (shell_break_chars
, CSHBRK
);
193 addcchar ('`', CBACKQ
);
195 addcstr (shell_quote_chars
, CQUOTE
);
197 addcchar (CTLESC
, CSPECL
);
198 addcchar (CTLNUL
, CSPECL
);
200 addcstr (shell_exp_chars
, CEXP
);
202 addcstr (slashify_in_quotes
, CBSDQUOTE
);
203 addcstr (slashify_in_here_document
, CBSHDOC
);
205 addcstr (shell_glob_chars
, CGLOB
);
207 #if defined (EXTENDED_GLOB)
208 addcstr (ext_glob_chars
, CXGLOB
);
211 addcstr (shell_quote_chars
, CXQUOTE
);
212 addcchar ('\\', CXQUOTE
);
214 addcstr ("@*#?-$!", CSPECVAR
); /* omits $0...$9 and $_ */
218 dump_lflags (fp
, ind
)
222 int xflags
, first
, i
;
224 xflags
= lsyntax
[ind
];
228 fputs (wordflags
[0].fstr
, fp
);
231 for (i
= 1; i
< N_WFLAGS
; i
++)
232 if (xflags
& wordflags
[i
].flag
)
238 fputs (wordflags
[i
].fstr
, fp
);
248 fputs ("\t\t/* ", fp
);
250 fprintf (fp
, "%s", cdesc(i
));
262 fprintf (fp
, "const int sh_syntaxtab[%d] = {\n", SYNSIZE
);
264 for (i
= 0; i
< SYNSIZE
; i
++)
273 fprintf (fp
, "};\n");
284 if ((progname
= strrchr (argv
[0], '/')) == 0)
289 filename
= (char *)NULL
;
292 while ((opt
= getopt (argc
, argv
, "do:")) != EOF
)
312 fp
= fopen (filename
, "w");
315 fprintf (stderr
, "%s: %s: cannot open: %s\n", progname
, filename
, strerror(errno
));
326 for (i
= 0; i
< SYNSIZE
; i
++)
331 fprintf (fp
, "%s\n", preamble
);
332 fprintf (fp
, "%s\n", includes
);
342 #if !defined (HAVE_STRERROR)
344 #include <bashtypes.h>
346 # include <sys/param.h>
349 #if defined (HAVE_UNISTD_H)
353 /* Return a string corresponding to the error number E. From
355 #if defined (strerror)
363 static char emsg
[40];
364 #if defined (HAVE_SYS_ERRLIST)
366 extern char *sys_errlist
[];
368 if (e
> 0 && e
< sys_nerr
)
369 return (sys_errlist
[e
]);
371 #endif /* HAVE_SYS_ERRLIST */
373 sprintf (emsg
, "Unknown system error %d", e
);
377 #endif /* HAVE_STRERROR */