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