syntax.h revision 1.1 1
2 /*-
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Kenneth Almquist.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 #include <ctype.h>
36
37 /* Syntax classes */
38 #define CWORD 0 /* character is nothing special */
39 #define CNL 1 /* newline character */
40 #define CBACK 2 /* a backslash character */
41 #define CSQUOTE 3 /* single quote */
42 #define CDQUOTE 4 /* double quote */
43 #define CBQUOTE 5 /* backwards single quote */
44 #define CVAR 6 /* a dollar sign */
45 #define CENDVAR 7 /* a '}' character */
46 #define CLP 8 /* a left paren in arithmetic */
47 #define CRP 9 /* a right paren in arithmetic */
48 #define CEOF 10 /* end of file */
49 #define CCTL 11 /* like CWORD, except it must be escaped */
50 #define CSPCL 12 /* these terminate a word */
51
52 /* Syntax classes for is_ functions */
53 #define ISDIGIT 01 /* a digit */
54 #define ISUPPER 02 /* an upper case letter */
55 #define ISLOWER 04 /* a lower case letter */
56 #define ISUNDER 010 /* an underscore */
57 #define ISSPECL 020 /* the name of a special parameter */
58
59 #define PEOF (CHAR_MIN - 1)
60 #define SYNBASE (-PEOF)
61 /* XXX UPEOF is CHAR_MAX, so is a valid 'char' value... */
62 #define UPEOF ((char)PEOF)
63
64
65 #define BASESYNTAX (basesyntax + SYNBASE)
66 #define DQSYNTAX (dqsyntax + SYNBASE)
67 #define SQSYNTAX (sqsyntax + SYNBASE)
68 #define ARISYNTAX (arisyntax + SYNBASE)
69
70 /* These defines assume that the digits are contiguous */
71 #define is_digit(c) ((unsigned)((c) - '0') <= 9)
72 #define is_alpha(c) (((char)(c)) != UPEOF && ((c) < CTL_FIRST || (c) > CTL_LAST) && isalpha((unsigned char)(c)))
73 #define is_name(c) (((char)(c)) != UPEOF && ((c) < CTL_FIRST || (c) > CTL_LAST) && ((c) == '_' || isalpha((unsigned char)(c))))
74 #define is_in_name(c) (((char)(c)) != UPEOF && ((c) < CTL_FIRST || (c) > CTL_LAST) && ((c) == '_' || isalnum((unsigned char)(c))))
75 #define is_special(c) ((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))
76 #define digit_val(c) ((c) - '0')
77
78 extern const char basesyntax[];
79 extern const char dqsyntax[];
80 extern const char sqsyntax[];
81 extern const char arisyntax[];
82 extern const char is_type[];
83