1 /* $NetBSD: syntax.c,v 1.1 2004/01/17 17:38:12 dsl Exp $ */ 2 3 #include "shell.h" 4 #include "syntax.h" 5 #include "parser.h" 6 #include <limits.h> 7 8 #if CWORD != 0 9 #error initialisation assumes 'CWORD' is zero 10 #endif 11 12 #define ndx(ch) (ch + 1 - CHAR_MIN) 13 #define set(ch, val) [ndx(ch)] = val, 14 #define set_range(s, e, val) [ndx(s) ... ndx(e)] = val, 15 16 /* syntax table used when not in quotes */ 17 const char basesyntax[257] = { CEOF, 18 set_range(CTL_FIRST, CTL_LAST, CCTL) 19 set('\n', CNL) 20 set('\\', CBACK) 21 set('\'', CSQUOTE) 22 set('"', CDQUOTE) 23 set('`', CBQUOTE) 24 set('$', CVAR) 25 set('}', CENDVAR) 26 set('<', CSPCL) 27 set('>', CSPCL) 28 set('(', CSPCL) 29 set(')', CSPCL) 30 set(';', CSPCL) 31 set('&', CSPCL) 32 set('|', CSPCL) 33 set(' ', CSPCL) 34 set('\t', CSPCL) 35 }; 36 37 /* syntax table used when in double quotes */ 38 const char dqsyntax[257] = { CEOF, 39 set_range(CTL_FIRST, CTL_LAST, CCTL) 40 set('\n', CNL) 41 set('\\', CBACK) 42 set('"', CDQUOTE) 43 set('`', CBQUOTE) 44 set('$', CVAR) 45 set('}', CENDVAR) 46 /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ 47 set('!', CCTL) 48 set('*', CCTL) 49 set('?', CCTL) 50 set('[', CCTL) 51 set('=', CCTL) 52 set('~', CCTL) 53 set(':', CCTL) 54 set('/', CCTL) 55 set('-', CCTL) 56 }; 57 58 /* syntax table used when in single quotes */ 59 const char sqsyntax[257] = { CEOF, 60 set_range(CTL_FIRST, CTL_LAST, CCTL) 61 set('\n', CNL) 62 set('\'', CSQUOTE) 63 /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ 64 set('!', CCTL) 65 set('*', CCTL) 66 set('?', CCTL) 67 set('[', CCTL) 68 set('=', CCTL) 69 set('~', CCTL) 70 set(':', CCTL) 71 set('/', CCTL) 72 set('-', CCTL) 73 }; 74 75 /* syntax table used when in arithmetic */ 76 const char arisyntax[257] = { CEOF, 77 set_range(CTL_FIRST, CTL_LAST, CCTL) 78 set('\n', CNL) 79 set('\\', CBACK) 80 set('`', CBQUOTE) 81 set('\'', CSQUOTE) 82 set('"', CDQUOTE) 83 set('$', CVAR) 84 set('}', CENDVAR) 85 set('(', CLP) 86 set(')', CRP) 87 }; 88 89 /* character classification table */ 90 const char is_type[257] = { 0, 91 set_range('0', '9', ISDIGIT) 92 set_range('a', 'z', ISLOWER) 93 set_range('A', 'Z', ISUPPER) 94 set('_', ISUNDER) 95 set('#', ISSPECL) 96 set('?', ISSPECL) 97 set('$', ISSPECL) 98 set('!', ISSPECL) 99 set('-', ISSPECL) 100 set('*', ISSPECL) 101 set('@', ISSPECL) 102 }; 103