diff options
Diffstat (limited to 'bin/sh/mksyntax.c')
-rw-r--r-- | bin/sh/mksyntax.c | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/bin/sh/mksyntax.c b/bin/sh/mksyntax.c index a4948c0..5b6a30e 100644 --- a/bin/sh/mksyntax.c +++ b/bin/sh/mksyntax.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: mksyntax.c,v 1.4 1996/08/12 12:31:28 ache Exp $ + * $Id: mksyntax.c,v 1.5 1996/08/12 22:14:47 ache Exp $ */ #ifndef lint @@ -43,7 +43,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)mksyntax.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)mksyntax.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ /* @@ -51,6 +51,7 @@ static char sccsid[] = "@(#)mksyntax.c 8.1 (Berkeley) 5/31/93"; */ #include <stdio.h> +#include <string.h> #include "parser.h" @@ -61,21 +62,21 @@ struct synclass { /* Syntax classes */ struct synclass synclass[] = { - "CWORD", "character is nothing special", - "CNL", "newline character", - "CBACK", "a backslash character", - "CSQUOTE", "single quote", - "CDQUOTE", "double quote", - "CENDQUOTE", "a terminating quote", - "CBQUOTE", "backwards single quote", - "CVAR", "a dollar sign", - "CENDVAR", "a '}' character", - "CLP", "a left paren in arithmetic", - "CRP", "a right paren in arithmetic", - "CEOF", "end of file", - "CCTL", "like CWORD, except it must be escaped", - "CSPCL", "these terminate a word", - NULL, NULL + { "CWORD", "character is nothing special" }, + { "CNL", "newline character" }, + { "CBACK", "a backslash character" }, + { "CSQUOTE", "single quote" }, + { "CDQUOTE", "double quote" }, + { "CENDQUOTE", "a terminating quote" }, + { "CBQUOTE", "backwards single quote" }, + { "CVAR", "a dollar sign" }, + { "CENDVAR", "a '}' character" }, + { "CLP", "a left paren in arithmetic" }, + { "CRP", "a right paren in arithmetic" }, + { "CEOF", "end of file" }, + { "CCTL", "like CWORD, except it must be escaped" }, + { "CSPCL", "these terminate a word" }, + { NULL, NULL } }; @@ -84,31 +85,41 @@ struct synclass synclass[] = { * you may have to change the definition of the is_in_name macro. */ struct synclass is_entry[] = { - "ISDIGIT", "a digit", - "ISUPPER", "an upper case letter", - "ISLOWER", "a lower case letter", - "ISUNDER", "an underscore", - "ISSPECL", "the name of a special parameter", - NULL, NULL, + { "ISDIGIT", "a digit" }, + { "ISUPPER", "an upper case letter" }, + { "ISLOWER", "a lower case letter" }, + { "ISUNDER", "an underscore" }, + { "ISSPECL", "the name of a special parameter" }, + { NULL, NULL } }; -char writer[] = "\ +static char writer[] = "\ /*\n\ * This file was generated by the mksyntax program.\n\ */\n\ \n"; -FILE *cfile; -FILE *hfile; -char *syntax[513]; -int base; -int size; /* number of values which a char variable can have */ -int nbits; /* number of bits in a character */ -int digit_contig; /* true if digits are contiguous */ - - -main() { +static FILE *cfile; +static FILE *hfile; +static char *syntax[513]; +static int base; +static int size; /* number of values which a char variable can have */ +static int nbits; /* number of bits in a character */ +static int digit_contig;/* true if digits are contiguous */ + +static void filltable __P((char *)); +static void init __P((void)); +static void add __P((char *, char *)); +static void print __P((char *)); +static void output_type_macros __P((void)); +static void digit_convert __P((void)); + +int +main(argc, argv) + int argc; + char **argv; +{ char c; char d; int sign; @@ -163,7 +174,7 @@ main() { for (i = 0 ; synclass[i].name ; i++) { sprintf(buf, "#define %s %d", synclass[i].name, i); fputs(buf, hfile); - for (pos = strlen(buf) ; pos < 32 ; pos = pos + 8 &~ 07) + for (pos = strlen(buf) ; pos < 32 ; pos = (pos + 8) & ~07) putc('\t', hfile); fprintf(hfile, "/* %s */\n", synclass[i].comment); } @@ -172,7 +183,7 @@ main() { for (i = 0 ; is_entry[i].name ; i++) { sprintf(buf, "#define %s %#o", is_entry[i].name, 1 << i); fputs(buf, hfile); - for (pos = strlen(buf) ; pos < 32 ; pos = pos + 8 &~ 07) + for (pos = strlen(buf) ; pos < 32 ; pos = (pos + 8) & ~07) putc('\t', hfile); fprintf(hfile, "/* %s */\n", is_entry[i].comment); } @@ -210,13 +221,15 @@ main() { add("`", "CBQUOTE"); add("$", "CVAR"); add("}", "CENDVAR"); - add("!*?[=~:/", "CCTL"); /* ':/' for tilde - yuck */ + /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ + add("!*?[=~:/-", "CCTL"); print("dqsyntax"); init(); fputs("\n/* syntax table used when in single quotes */\n", cfile); add("\n", "CNL"); add("'", "CENDQUOTE"); - add("!*?[=~:/", "CCTL"); /* ':/' for tilde - yuck */ + /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ + add("!*?[=~:/-", "CCTL"); print("sqsyntax"); init(); fputs("\n/* syntax table used when in arithmetic */\n", cfile); @@ -249,9 +262,10 @@ main() { * Clear the syntax table. */ +static void filltable(dftval) char *dftval; - { +{ int i; for (i = 0 ; i < size ; i++) @@ -263,7 +277,9 @@ filltable(dftval) * Initialize the syntax table with default values. */ -init() { +static void +init() +{ filltable("CWORD"); syntax[0] = "CEOF"; syntax[base + CTLESC] = "CCTL"; @@ -280,9 +296,10 @@ init() { * Add entries to the syntax table. */ +static void add(p, type) char *p, *type; - { +{ while (*p) syntax[*p++ + base] = type; } @@ -293,9 +310,10 @@ add(p, type) * Output the syntax table. */ +static void print(name) char *name; - { +{ int i; int col; @@ -326,7 +344,7 @@ print(name) * contiguous, we can test for them quickly. */ -char *macro[] = { +static char *macro[] = { "#define is_digit(c)\t((is_type+SYNBASE)[c] & ISDIGIT)", "#define is_alpha(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLENDARI) && isalpha((unsigned char) (c)))", "#define is_name(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalpha((unsigned char) (c))))", @@ -335,7 +353,9 @@ char *macro[] = { NULL }; -output_type_macros() { +static void +output_type_macros() +{ char **pp; if (digit_contig) @@ -354,7 +374,9 @@ output_type_macros() { * Output digit conversion table (if digits are not contiguous). */ -digit_convert() { +static void +digit_convert() +{ int maxdigit; static char digit[] = "0123456789"; char *p; |