Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 1 | /* syntax.h -- Syntax definitions for the shell */ |
| 2 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 3 | /* Copyright (C) 2000, 2001, 2005, 2008,2009 Free Software Foundation, Inc. |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 4 | |
| 5 | This file is part of GNU Bash, the Bourne Again SHell. |
| 6 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 7 | Bash is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or |
| 10 | (at your option) any later version. |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 11 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 12 | Bash is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 16 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 17 | You should have received a copy of the GNU General Public License |
| 18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 20 | |
| 21 | #ifndef _SYNTAX_H_ |
| 22 | #define _SYNTAX_H_ |
| 23 | |
| 24 | /* Defines for use by mksyntax.c */ |
| 25 | |
| 26 | #define slashify_in_quotes "\\`$\"\n" |
| 27 | #define slashify_in_here_document "\\`$" |
| 28 | |
| 29 | #define shell_meta_chars "()<>;&|" |
| 30 | #define shell_break_chars "()<>;&| \t\n" |
| 31 | |
| 32 | #define shell_quote_chars "\"`'" |
| 33 | |
| 34 | #if defined (PROCESS_SUBSTITUTION) |
| 35 | # define shell_exp_chars "$<>" |
| 36 | #else |
| 37 | # define shell_exp_chars "$" |
| 38 | #endif |
| 39 | |
| 40 | #if defined (EXTENDED_GLOB) |
| 41 | # define ext_glob_chars "@*+?!" |
| 42 | #else |
| 43 | # define ext_glob_chars "" |
| 44 | #endif |
| 45 | #define shell_glob_chars "*?[]^" |
| 46 | |
| 47 | /* Defines shared by mksyntax.c and the rest of the shell code. */ |
| 48 | |
| 49 | /* Values for character flags in syntax tables */ |
| 50 | |
| 51 | #define CWORD 0x0000 /* nothing special; an ordinary character */ |
| 52 | #define CSHMETA 0x0001 /* shell meta character */ |
| 53 | #define CSHBRK 0x0002 /* shell break character */ |
| 54 | #define CBACKQ 0x0004 /* back quote */ |
| 55 | #define CQUOTE 0x0008 /* shell quote character */ |
| 56 | #define CSPECL 0x0010 /* special character that needs quoting */ |
| 57 | #define CEXP 0x0020 /* shell expansion character */ |
| 58 | #define CBSDQUOTE 0x0040 /* characters escaped by backslash in double quotes */ |
| 59 | #define CBSHDOC 0x0080 /* characters escaped by backslash in here doc */ |
| 60 | #define CGLOB 0x0100 /* globbing characters */ |
| 61 | #define CXGLOB 0x0200 /* extended globbing characters */ |
| 62 | #define CXQUOTE 0x0400 /* cquote + backslash */ |
| 63 | #define CSPECVAR 0x0800 /* single-character shell variable name */ |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 64 | #define CSUBSTOP 0x1000 /* values of OP for ${word[:]OPstuff} */ |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 65 | #define CBLANK 0x2000 /* whitespace (blank) character */ |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 66 | |
| 67 | /* Defines for use by the rest of the shell. */ |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 68 | extern int sh_syntaxtab[]; |
| 69 | extern int sh_syntabsiz; |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 70 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 71 | #define shellmeta(c) (sh_syntaxtab[(unsigned char)(c)] & CSHMETA) |
| 72 | #define shellbreak(c) (sh_syntaxtab[(unsigned char)(c)] & CSHBRK) |
| 73 | #define shellquote(c) (sh_syntaxtab[(unsigned char)(c)] & CQUOTE) |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 74 | #define shellxquote(c) (sh_syntaxtab[(unsigned char)(c)] & CXQUOTE) |
| 75 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 76 | #define shellblank(c) (sh_syntaxtab[(unsigned char)(c)] & CBLANK) |
| 77 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 78 | #define issyntype(c, t) ((sh_syntaxtab[(unsigned char)(c)] & (t)) != 0) |
| 79 | #define notsyntype(c,t) ((sh_syntaxtab[(unsigned char)(c)] & (t)) == 0) |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 80 | |
| 81 | #if defined (PROCESS_SUBSTITUTION) |
| 82 | # define shellexp(c) ((c) == '$' || (c) == '<' || (c) == '>') |
| 83 | #else |
| 84 | # define shellexp(c) ((c) == '$') |
| 85 | #endif |
| 86 | |
| 87 | #if defined (EXTENDED_GLOB) |
| 88 | # define PATTERN_CHAR(c) \ |
| 89 | ((c) == '@' || (c) == '*' || (c) == '+' || (c) == '?' || (c) == '!') |
| 90 | #else |
| 91 | # define PATTERN_CHAR(c) 0 |
| 92 | #endif |
| 93 | |
| 94 | #define GLOB_CHAR(c) \ |
| 95 | ((c) == '*' || (c) == '?' || (c) == '[' || (c) == ']' || (c) == '^') |
| 96 | |
| 97 | #define CTLESC '\001' |
| 98 | #define CTLNUL '\177' |
| 99 | |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 100 | #if !defined (HAVE_ISBLANK) && !defined (isblank) |
| 101 | # define isblank(x) ((x) == ' ' || (x) == '\t') |
| 102 | #endif |
| 103 | |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 104 | #endif /* _SYNTAX_H_ */ |