11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Kenneth Almquist. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 4. Neither the name of the University nor the names of its contributors 171556Srgrimes * may be used to endorse or promote products derived from this software 181556Srgrimes * without specific prior written permission. 191556Srgrimes * 201556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301556Srgrimes * SUCH DAMAGE. 311556Srgrimes * 3217987Speter * @(#)parser.h 8.3 (Berkeley) 5/4/95 3350471Speter * $FreeBSD$ 341556Srgrimes */ 351556Srgrimes 361556Srgrimes/* control characters in argument strings */ 37221551Sjilles#define CTLESC '\300' 38221551Sjilles#define CTLVAR '\301' 39221551Sjilles#define CTLENDVAR '\371' 40221551Sjilles#define CTLBACKQ '\372' 411556Srgrimes#define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */ 42246507Sjilles/* CTLBACKQ | CTLQUOTE == '\373' */ 43221551Sjilles#define CTLARI '\374' 44221551Sjilles#define CTLENDARI '\375' 45221551Sjilles#define CTLQUOTEMARK '\376' 46221551Sjilles#define CTLQUOTEEND '\377' /* only for ${v+-...} */ 471556Srgrimes 481556Srgrimes/* variable substitution byte (follows CTLVAR) */ 49179022Sstefanf#define VSTYPE 0x0f /* type of variable substitution */ 50179022Sstefanf#define VSNUL 0x10 /* colon--treat the empty string as unset */ 51179022Sstefanf#define VSLINENO 0x20 /* expansion of $LINENO, the line number \ 52179022Sstefanf follows immediately */ 53179022Sstefanf#define VSQUOTE 0x80 /* inside double quotes--suppress splitting */ 541556Srgrimes 551556Srgrimes/* values of VSTYPE field */ 5617987Speter#define VSNORMAL 0x1 /* normal variable: $var or ${var} */ 5717987Speter#define VSMINUS 0x2 /* ${var-text} */ 5817987Speter#define VSPLUS 0x3 /* ${var+text} */ 5917987Speter#define VSQUESTION 0x4 /* ${var?message} */ 6017987Speter#define VSASSIGN 0x5 /* ${var=text} */ 6117987Speter#define VSTRIMLEFT 0x6 /* ${var#pattern} */ 6217987Speter#define VSTRIMLEFTMAX 0x7 /* ${var##pattern} */ 6317987Speter#define VSTRIMRIGHT 0x8 /* ${var%pattern} */ 6417987Speter#define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */ 6517987Speter#define VSLENGTH 0xa /* ${#var} */ 66164003Sstefanf#define VSERROR 0xb /* Syntax error, issue when expanded */ 671556Srgrimes 681556Srgrimes 691556Srgrimes/* 701556Srgrimes * NEOF is returned by parsecmd when it encounters an end of file. It 71255068Sjilles * must be distinct from NULL. 721556Srgrimes */ 73255068Sjilles#define NEOF ((union node *)-1) 741556Srgrimesextern int whichprompt; /* 1 == PS1, 2 == PS2 */ 75201053Sjillesextern const char *const parsekwd[]; 761556Srgrimes 771556Srgrimes 7890111Simpunion node *parsecmd(int); 7990111Simpvoid fixredir(union node *, const char *, int); 80200956Sjillesint goodname(const char *); 81222165Sjillesint isassignment(const char *); 8290111Simpchar *getprompt(void *); 83248980Sjillesconst char *expandstr(const char *); 84