4 * This file contains functions that depend on the shell's syntax. Most
5 * of the routines extract strings observing the shell's escape conventions.
10 * skip a token in quotes.
13 squote(char *cp, int c)
19 n = chartorune(&r, cp);
23 n += chartorune(&r, cp+n);
26 SYNERR(-1); /* should never occur */
27 fprint(2, "missing closing '\n");
31 * search a string for unescaped characters in a pattern set
34 shcharin(char *cp, char *pat)
41 n = chartorune(&r, cp);
43 case '\\': /* skip escaped char */
45 n = chartorune(&r, cp);
47 case '\'': /* skip quoted string */
49 cp = squote(cp+1, r); /* n must = 1 */
60 else if(utfrune(pat, r))
64 if(vargen == 0 && utfrune(pat, r))
72 fprint(2, "missing closing } in pattern generator\n");
78 * extract an escaped token. Possible escape chars are single-quote,
79 * double-quote,and backslash.
82 shexpandquote(char *s, Rune esc, Bufblock *b)
87 s += chartorune(&r, s);
93 s += chartorune(&r, s);
98 s += chartorune(&r, s);
106 * Input an escaped token. Possible escape chars are single-quote,
107 * double-quote and backslash.
110 shescapetoken(Biobuf *bp, Bufblock *buf, int preserve, int esc)
125 while((c = nextrune(bp, 0)) >= 0){
143 SYNERR(line); fprint(2, "missing closing %c\n", esc);
148 * copy a quoted string; s points to char after opening quote
151 copysingle(char *s, Rune q, Bufblock *buf)
156 s += chartorune(&r, s);
164 * check for quoted strings. backquotes are handled here; single quotes above.
165 * s points to char after opening quote, q.
168 shcopyq(char *s, Rune q, Bufblock *buf)
170 if(q == '\'' || q == '"') /* copy quoted string */
171 return copysingle(s, q, buf);
173 if(q != '`') /* not quoted */
176 while(*s){ /* copy backquoted string */
177 s += chartorune(&q, s);
181 if(q == '\'' || q == '"')
182 s = copysingle(s, q, buf); /* copy quoted string */
188 shmatchname(char *name)
198 "\"'= \t", /*used in parse.c to isolate assignment attribute*/
199 ' ', /* inter-word separator in env */