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