| 1 | /*
|
|---|
| 2 | * mksyntax.c - construct shell syntax table for fast char attribute lookup.
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | /* Copyright (C) 2000-2002 Free Software Foundation, Inc.
|
|---|
| 6 |
|
|---|
| 7 | This file is part of GNU Bash, the Bourne Again SHell.
|
|---|
| 8 |
|
|---|
| 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
|
|---|
| 12 | version.
|
|---|
| 13 |
|
|---|
| 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
|
|---|
| 17 | for more details.
|
|---|
| 18 |
|
|---|
| 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. */
|
|---|
| 22 |
|
|---|
| 23 | #include "config.h"
|
|---|
| 24 |
|
|---|
| 25 | #include <stdio.h>
|
|---|
| 26 | #include "bashansi.h"
|
|---|
| 27 | #include "chartypes.h"
|
|---|
| 28 | #include <errno.h>
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HAVE_UNISTD_H
|
|---|
| 31 | # include <unistd.h>
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #include "syntax.h"
|
|---|
| 35 |
|
|---|
| 36 | extern int optind;
|
|---|
| 37 | extern char *optarg;
|
|---|
| 38 |
|
|---|
| 39 | #ifndef errno
|
|---|
| 40 | extern int errno;
|
|---|
| 41 | #endif
|
|---|
| 42 |
|
|---|
| 43 | #ifndef HAVE_STRERROR
|
|---|
| 44 | extern char *strerror();
|
|---|
| 45 | #endif
|
|---|
| 46 |
|
|---|
| 47 | struct wordflag {
|
|---|
| 48 | int flag;
|
|---|
| 49 | char *fstr;
|
|---|
| 50 | } wordflags[] = {
|
|---|
| 51 | { CWORD, "CWORD" },
|
|---|
| 52 | { CSHMETA, "CSHMETA" },
|
|---|
| 53 | { CSHBRK, "CSHBRK" },
|
|---|
| 54 | { CBACKQ, "CBACKQ" },
|
|---|
| 55 | { CQUOTE, "CQUOTE" },
|
|---|
| 56 | { CSPECL, "CSPECL" },
|
|---|
| 57 | { CEXP, "CEXP" },
|
|---|
| 58 | { CBSDQUOTE, "CBSDQUOTE" },
|
|---|
| 59 | { CBSHDOC, "CBSHDOC" },
|
|---|
| 60 | { CGLOB, "CGLOB" },
|
|---|
| 61 | { CXGLOB, "CXGLOB" },
|
|---|
| 62 | { CXQUOTE, "CXQUOTE" },
|
|---|
| 63 | { CSPECVAR, "CSPECVAR" },
|
|---|
| 64 | { CSUBSTOP, "CSUBSTOP" },
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | #define N_WFLAGS (sizeof (wordflags) / sizeof (wordflags[0]))
|
|---|
| 68 | #define SYNSIZE 256
|
|---|
| 69 |
|
|---|
| 70 | int lsyntax[SYNSIZE];
|
|---|
| 71 | int debug;
|
|---|
| 72 | char *progname;
|
|---|
| 73 |
|
|---|
| 74 | char preamble[] = "\
|
|---|
| 75 | /*\n\
|
|---|
| 76 | * This file was generated by mksyntax. DO NOT EDIT.\n\
|
|---|
| 77 | */\n\
|
|---|
| 78 | \n";
|
|---|
| 79 |
|
|---|
| 80 | char includes[] = "\
|
|---|
| 81 | #include \"config.h\"\n\
|
|---|
| 82 | #include \"stdc.h\"\n\
|
|---|
| 83 | #include \"syntax.h\"\n\n";
|
|---|
| 84 |
|
|---|
| 85 | static void
|
|---|
| 86 | usage()
|
|---|
| 87 | {
|
|---|
| 88 | fprintf (stderr, "%s: usage: %s [-d] [-o filename]\n", progname, progname);
|
|---|
| 89 | exit (2);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | #ifdef INCLUDE_UNUSED
|
|---|
| 93 | static int
|
|---|
| 94 | getcflag (s)
|
|---|
| 95 | char *s;
|
|---|
| 96 | {
|
|---|
| 97 | int i;
|
|---|
| 98 |
|
|---|
| 99 | for (i = 0; i < N_WFLAGS; i++)
|
|---|
| 100 | if (strcmp (s, wordflags[i].fstr) == 0)
|
|---|
| 101 | return wordflags[i].flag;
|
|---|
| 102 | return -1;
|
|---|
| 103 | }
|
|---|
| 104 | #endif
|
|---|
| 105 |
|
|---|
| 106 | static char *
|
|---|
| 107 | cdesc (i)
|
|---|
| 108 | int i;
|
|---|
| 109 | {
|
|---|
| 110 | static char xbuf[16];
|
|---|
| 111 |
|
|---|
| 112 | if (i == ' ')
|
|---|
| 113 | return "SPC";
|
|---|
| 114 | else if (ISPRINT (i))
|
|---|
| 115 | {
|
|---|
| 116 | xbuf[0] = i;
|
|---|
| 117 | xbuf[1] = '\0';
|
|---|
| 118 | return (xbuf);
|
|---|
| 119 | }
|
|---|
| 120 | else if (i == CTLESC)
|
|---|
| 121 | return "CTLESC";
|
|---|
| 122 | else if (i == CTLNUL)
|
|---|
| 123 | return "CTLNUL";
|
|---|
| 124 | else if (i == '\033') /* ASCII */
|
|---|
| 125 | return "ESC";
|
|---|
| 126 |
|
|---|
| 127 | xbuf[0] = '\\';
|
|---|
| 128 | xbuf[2] = '\0';
|
|---|
| 129 |
|
|---|
| 130 | switch (i)
|
|---|
| 131 | {
|
|---|
| 132 | #ifdef __STDC__
|
|---|
| 133 | case '\a': xbuf[1] = 'a'; break;
|
|---|
| 134 | case '\v': xbuf[1] = 'v'; break;
|
|---|
| 135 | #else
|
|---|
| 136 | case '\007': xbuf[1] = 'a'; break;
|
|---|
| 137 | case 0x0B: xbuf[1] = 'v'; break;
|
|---|
| 138 | #endif
|
|---|
| 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;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | return xbuf;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | static char *
|
|---|
| 151 | getcstr (f)
|
|---|
| 152 | int f;
|
|---|
| 153 | {
|
|---|
| 154 | int i;
|
|---|
| 155 |
|
|---|
| 156 | for (i = 0; i < N_WFLAGS; i++)
|
|---|
| 157 | if (f == wordflags[i].flag)
|
|---|
| 158 | return (wordflags[i].fstr);
|
|---|
| 159 | return ((char *)NULL);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | static void
|
|---|
| 163 | addcstr (str, flag)
|
|---|
| 164 | char *str;
|
|---|
| 165 | int flag;
|
|---|
| 166 | {
|
|---|
|
|---|