* Copyright (c) 1991 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
/*static char sccsid[] = "from: @(#)mksyntax.c 5.2 (Berkeley) 3/8/91";*/
static char rcsid
[] = "mksyntax.c,v 1.4 1993/08/01 18:58:06 mycroft Exp";
* This program creates syntax.h and syntax.c.
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",
"CENDVAR", "a '}' character",
"CCTL", "like CWORD, except it must be escaped",
"CSPCL", "these terminate a word",
* Syntax classes for is_ functions. Warning: if you add new classes
* you may have to change the definition of the is_in_name macro.
struct synclass is_entry
[] = {
"ISUPPER", "an upper case letter",
"ISLOWER", "a lower case letter",
"ISUNDER", "an underscore",
"ISSPECL", "the name of a special parameter",
* This file was generated by the mksyntax program.\n\
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 */
static char digit
[] = "0123456789";
/* Create output files */
if ((cfile
= fopen("syntax.c", "w")) == NULL
) {
if ((hfile
= fopen("syntax.h", "w")) == NULL
) {
/* Determine the characteristics of chars. */
for (nbits
= 1 ; ; nbits
++) {
printf("%s %d bit chars\n", sign
? "signed" : "unsigned", nbits
);
fputs("Characters can't have more than 9 bits\n", stderr
);
base
+= 1 << (nbits
- 1);
for (i
= 0 ; i
< 10 ; i
++) {
fputs("#include <sys/cdefs.h>\n", hfile
);
/* Generate the #define statements in the header file */
fputs("/* Syntax classes */\n", hfile
);
for (i
= 0 ; synclass
[i
].name
; i
++) {
sprintf(buf
, "#define %s %d", synclass
[i
].name
, i
);
for (pos
= strlen(buf
) ; pos
< 32 ; pos
= pos
+ 8 &~ 07)
fprintf(hfile
, "/* %s */\n", synclass
[i
].comment
);
fputs("/* Syntax classes for is_ functions */\n", hfile
);
for (i
= 0 ; is_entry
[i
].name
; i
++) {
sprintf(buf
, "#define %s %#o", is_entry
[i
].name
, 1 << i
);
for (pos
= strlen(buf
) ; pos
< 32 ; pos
= pos
+ 8 &~ 07)
fprintf(hfile
, "/* %s */\n", is_entry
[i
].comment
);
fprintf(hfile
, "#define SYNBASE %d\n", base
);
fprintf(hfile
, "#define PEOF %d\n\n", -base
);
fputs("#define BASESYNTAX (basesyntax + SYNBASE)\n", hfile
);
fputs("#define DQSYNTAX (dqsyntax + SYNBASE)\n", hfile
);
fputs("#define SQSYNTAX (sqsyntax + SYNBASE)\n", hfile
);
output_type_macros(); /* is_digit, etc. */
/* Generate the syntax tables. */
fputs("#include \"shell.h\"\n", cfile
);
fputs("#include \"syntax.h\"\n\n", cfile
);
fputs("/* syntax table used when not in quotes */\n", cfile
);
add("<>();&| \t", "CSPCL");
fputs("\n/* syntax table used when in double quotes */\n", cfile
);
fputs("\n/* syntax table used when in single quotes */\n", cfile
);
fputs("\n/* character classification table */\n", cfile
);
add("0123456789", "ISDIGIT");
add("abcdefghijklmnopqrstucvwxyz", "ISLOWER");
add("ABCDEFGHIJKLMNOPQRSTUCVWXYZ", "ISUPPER");
add("#?$!-*@", "ISSPECL");
* Clear the syntax table.
for (i
= 0 ; i
< size
; i
++)
* Initialize the syntax table with default values.
syntax
[base
+ CTLESC
] = "CCTL";
syntax
[base
+ CTLVAR
] = "CCTL";
syntax
[base
+ CTLENDVAR
] = "CCTL";
syntax
[base
+ CTLBACKQ
] = "CCTL";
syntax
[base
+ CTLBACKQ
+ CTLQUOTE
] = "CCTL";
* Add entries to the syntax table.
syntax
[*p
++ + base
] = type
;
* Output the syntax table.
fprintf(hfile
, "extern const char %s[];\n", name
);
fprintf(cfile
, "const char %s[%d] = {\n", name
, size
);
for (i
= 0 ; i
< size
; i
++) {
} else if ((i
& 03) == 0) {
while (++col
< 9 * (i
& 03))
col
+= strlen(syntax
[i
]);
* Output character classification macros (e.g. is_digit). If digits are
* contiguous, we can test for them quickly.
"#define is_digit(c)\t((is_type+SYNBASE)[c] & ISDIGIT)",
"#define is_alpha(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER))",
"#define is_name(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER|ISUNDER))",
"#define is_in_name(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER|ISUNDER|ISDIGIT))",
"#define is_special(c)\t((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))",
macro
[0] = "#define is_digit(c)\t((unsigned)((c) - '0') <= 9)";
for (pp
= macro
; *pp
; pp
++)
fprintf(hfile
, "%s\n", *pp
);
fputs("#define digit_val(c)\t((c) - '0')\n", hfile
);
fputs("#define digit_val(c)\t(digit_value[c])\n", hfile
);
* Output digit conversion table (if digits are not contiguous).
static char digit
[] = "0123456789";
for (p
= digit
; *p
; p
++)
fputs("extern const char digit_value[];\n", hfile
);
fputs("\n\nconst char digit_value[] = {\n", cfile
);
for (i
= 0 ; i
<= maxdigit
; i
++) {
for (p
= digit
; *p
&& *p
!= i
; p
++);
fprintf(cfile
, " %d,\n", p
- digit
);