3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 /* $NetBSD: alias.h,v 1.4 1995/05/11 21:28:42 christos Exp $ */
49 struct alias *lookupalias __P((const char *, int));
50 static int aliascmd __P((int, char **));
51 static int unaliascmd __P((int, char **));
52 static void rmaliases __P((void));
53 static int unalias __P((char *));
54 static void printalias __P((const struct alias *));
56 #define ARITH_LPAREN 258
57 #define ARITH_RPAREN 259
61 #define ARITH_BXOR 263
62 #define ARITH_BAND 264
69 #define ARITH_LSHIFT 271
70 #define ARITH_RSHIFT 272
76 #define ARITH_UNARYMINUS 278
77 #define ARITH_UNARYPLUS 279
79 #define ARITH_BNOT 281
82 * This file was generated by the mkbuiltins program.
86 #define BUILTIN_SPECIAL 0x1
87 #define BUILTIN_REGULAR 0x2
88 #define BUILTIN_ASSIGN 0x4
92 int (*const builtinfunc) __P((int, char **));
96 extern const struct builtincmd builtincmds[];
100 /* $NetBSD: cd.h,v 1.2 1997/07/04 21:01:52 christos Exp $ */
101 static int cdcmd __P((int, char **));
102 static int pwdcmd __P((int, char **));
103 static void setpwd __P((const char *, int));
106 /* $NetBSD: error.h,v 1.14 2001/02/04 19:52:06 christos Exp $ */
109 * Types of operations (passed to the errmsg routine).
112 #define E_OPEN 01 /* opening a file */
113 #define E_CREAT 02 /* creating a file */
114 #define E_EXEC 04 /* executing a program */
118 * We enclose jmp_buf in a structure so that we can declare pointers to
119 * jump locations. The global variable handler contains the location to
120 * jump to when an exception occurs, and the global variable exception
121 * contains a code identifying the exeception. To implement nested
122 * exception handlers, the user should save the value of handler on entry
123 * to an inner scope, set handler to point to a jmploc structure for the
124 * inner scope, and restore handler on exit from the scope.
131 extern struct jmploc *handler;
132 extern int exception;
135 #define EXINT 0 /* SIGINT received */
136 #define EXERROR 1 /* a generic error */
137 #define EXSHELLPROC 2 /* execute a shell procedure */
138 #define EXEXEC 3 /* command execution failed */
142 * These macros allow the user to suspend the handling of interrupt signals
143 * over a period of time. This is similar to SIGHOLD to or sigblock, but
144 * much more efficient and portable. (But hacking the kernel is so much
145 * more fun than worrying about efficiency and portability. :-))
148 extern int suppressint;
149 extern volatile int intpending;
151 #define INTOFF suppressint++
153 static void __inton __P((void));
154 #define INTON __inton()
156 #define INTON { if (--suppressint == 0 && intpending) onint(); }
158 #define FORCEINTON {suppressint = 0; if (intpending) onint();}
159 #define CLEAR_PENDING_INT intpending = 0
160 #define int_pending() intpending
162 static void exraise __P((int)) __attribute__((__noreturn__));
163 static void onint __P((void));
164 static void error __P((const char *, ...)) __attribute__((__noreturn__));
165 static void exerror __P((int, const char *, ...)) __attribute__((__noreturn__));
166 static const char *errmsg __P((int, int));
170 * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
171 * so we use _setjmp instead.
174 #if defined(BSD) && !defined(__SVR4) && !defined(__GLIBC__)
175 #define setjmp(jmploc) _setjmp(jmploc)
176 #define longjmp(jmploc, val) _longjmp(jmploc, val)
181 /* $NetBSD: shell.h,v 1.13 2000/05/22 10:18:47 elric Exp $ */
184 * The follow should be set to reflect the type of system you have:
185 * JOBS -> 1 if you have Berkeley job control, 0 otherwise.
186 * SHORTNAMES -> 1 if your linker cannot handle long names.
187 * define BSD if you are running 4.2 BSD or later.
188 * define SYSV if you are running under System V.
189 * define DEBUG=1 to compile in debugging (set global "debug" to turn on)
190 * define DEBUG=2 to compile in and turn on debugging.
192 * When debugging is on, debugging info will be written to $HOME/trace and
193 * a quit signal will generate a core dump.
203 typedef void *pointer;
205 #define NULL (void *)0
207 #else /* not __STDC__ */
208 typedef char *pointer;
212 #endif /* not __STDC__ */
214 extern char nullstr[1]; /* null string */
218 #define TRACE(param) trace param
227 * This file was generated by the mknodes program.
271 union node *redirect;
278 struct nodelist *cmdlist;
285 union node *redirect;
293 union node *elsepart;
324 struct nodelist *backquote;
362 struct nbinary nbinary;
365 struct nredir nredir;
369 struct nclist nclist;
379 struct nodelist *next;
385 union node *copyfunc(union node *);
386 static void freefunc(union node *);
388 union node *copyfunc();
389 static void freefunc();
394 /* $NetBSD: eval.h,v 1.10 2000/01/27 23:39:40 christos Exp $ */
395 extern char *commandname; /* currently executing command */
396 extern int exitstatus; /* exit status of last command */
397 extern struct strlist *cmdenviron; /* environment for builtin command */
400 struct backcmd { /* result of evalbackcmd */
401 int fd; /* file descriptor to read from */
402 char *buf; /* buffer */
403 int nleft; /* number of chars in buffer */
404 struct job *jp; /* job structure for command */
407 static int evalcmd __P((int, char **));
408 static void evalstring __P((char *, int));
409 static void evaltree __P((union node *, int));
410 static void evalbackcmd __P((union node *, struct backcmd *));
411 static int bltincmd __P((int, char **));
412 static int breakcmd __P((int, char **));
413 static int returncmd __P((int, char **));
414 static int execcmd __P((int, char **));
416 /* in_function returns nonzero if we are currently evaluating a function */
417 #define in_function() funcnest
421 /* reasons for skipping commands (see comment on breakcmd routine) */
430 /* $NetBSD: exec.h,v 1.17 2000/05/22 10:18:47 elric Exp $ */
432 /* values of cmdtype */
433 #define CMDUNKNOWN -1 /* no entry in table for command */
434 #define CMDNORMAL 0 /* command is an executable program */
435 #define CMDBUILTIN 1 /* command is a shell builtin */
436 #define CMDFUNCTION 2 /* command is a shell function */
444 const struct builtincmd *cmd;
449 #define DO_ERR 1 /* find_command prints errors */
450 #define DO_ABS 2 /* find_command checks absolute paths */
451 #define DO_NOFUN 4 /* find_command ignores functions */
452 #define DO_BRUTE 8 /* find_command ignores hash table */
454 extern const char *pathopt; /* set by padvance */
455 extern int exerrno; /* last exec error */
457 static void shellexec __P((char **, char **, const char *, int))
458 __attribute__((noreturn));
459 static char *padvance __P((const char **, const char *));
460 static int hashcmd __P((int, char **));
461 static void find_command __P((char *, struct cmdentry *, int, const char *));
462 struct builtincmd *find_builtin __P((char *));
463 static void hashcd __P((void));
464 static void changepath __P((const char *));
465 static void deletefuncs __P((void));
467 static void getcmdentry __P((char *, struct cmdentry *));
469 static void addcmdentry __P((char *, struct cmdentry *));
470 static void defun __P((char *, union node *));
471 static void unsetfunc __P((char *));
473 static int typecmd __P((int, char **));
475 static int commandcmd __P((int, char **));
479 /* $NetBSD: expand.h,v 1.12 1999/07/09 03:05:50 christos Exp $ */
481 struct strlist *next;
487 struct strlist *list;
488 struct strlist **lastp;
494 #define EXP_FULL 0x1 /* perform word splitting & file globbing */
495 #define EXP_TILDE 0x2 /* do normal tilde expansion */
496 #define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
497 #define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
498 #define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
499 #define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */
502 static void expandhere __P((union node *, int));
503 static void expandarg __P((union node *, struct arglist *, int));
504 #ifdef ASH_MATH_SUPPORT
505 static void expari __P((int));
507 #if !(defined(__GLIBC__) && !defined(FNMATCH_BROKEN) && !defined(GLOB_BROKEN))
508 static int patmatch __P((char *, char *, int));
510 #if defined(__GLIBC__) && !defined(FNMATCH_BROKEN)
511 #define rmescapes(p) _rmescapes((p), 0)
512 static char *_rmescapes __P((char *, int));
514 static void rmescapes __P((char *));
516 static int casematch __P((union node *, char *));
519 #ifdef ASH_MATH_SUPPORT
521 static int arith __P((const char *));
522 static int expcmd __P((int , char **));
523 static void arith_lex_reset __P((void));
524 static int yylex __P((void));
530 /* $NetBSD: init.h,v 1.8 1995/05/11 21:29:14 christos Exp $ */
531 static void init __P((void));
532 static void reset __P((void));
533 static void initshellproc __P((void));
537 /* $NetBSD: input.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */
539 /* PEOF (the end of file marker) is defined in syntax.h */
541 * The input line number. Input.c just defines this variable, and saves
542 * and restores it when files are pushed and popped. The user of this
543 * package must set its value.
546 extern int parsenleft; /* number of characters left in input buffer */
547 extern char *parsenextc; /* next character in input buffer */
549 static char *pfgets __P((char *, int));
550 static int pgetc __P((void));
551 static int pgetc2 __P((void));
552 static int preadbuffer __P((void));
553 static void pungetc __P((void));
554 static void pushstring __P((char *, int, void *));
555 static void popstring __P((void));
556 static void setinputfile __P((const char *, int));
557 static void setinputfd __P((int, int));
558 static void setinputstring __P((char *));
559 static void popfile __P((void));
560 static void popallfiles __P((void));
561 static void closescript __P((void));
563 #define pgetc_macro() (--parsenleft >= 0? *parsenextc++ : preadbuffer())
567 /* $NetBSD: jobs.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */
569 /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */
576 * A job structure contains information about a job. A job is either a
577 * single process or a set of processes contained in a pipeline. In the
578 * latter case, pidlist will be non-NULL, and will point to a -1 terminated
583 pid_t pid; /* process id */
584 int status; /* status flags (defined above) */
585 char *cmd; /* text of command being run */
590 #define JOBSTOPPED 1 /* all procs are stopped */
591 #define JOBDONE 2 /* all procs are completed */
595 struct procstat ps0; /* status of process */
596 struct procstat *ps; /* status or processes when more than one */
597 short nprocs; /* number of processes */
598 short pgrp; /* process group of this job */
599 char state; /* true if job is finished */
600 char used; /* true if this entry is in used */
601 char changed; /* true if status has changed */
603 char jobctl; /* job running under job control */
607 extern short backgndpid; /* pid of last background process */
608 extern int job_warning; /* user was warned about stopped jobs */
610 static void setjobctl __P((int));
611 static int killcmd __P((int, char **));
612 static int fgcmd __P((int, char **));
613 static int bgcmd __P((int, char **));
614 static int jobscmd __P((int, char **));
615 static void showjobs __P((int));
616 static int waitcmd __P((int, char **));
617 struct job *makejob __P((union node *, int));
618 static int forkshell __P((struct job *, union node *, int));
619 static int waitforjob __P((struct job *));
620 static int stoppedjobs __P((void));
621 static char *commandtext __P((union node *));
624 #define setjobctl(on) /* do nothing */
629 /* $NetBSD: machdep.h,v 1.8 1995/05/11 21:29:21 christos Exp $ */
632 * Most machines require the value returned from malloc to be aligned
633 * in some way. The following macro will get this right on many machines.
642 #define ALIGN(nbytes) (((nbytes) + sizeof(union align) - 1) & ~(sizeof(union align) - 1))
647 /* $NetBSD: mail.h,v 1.8 1995/05/11 21:29:23 christos Exp $ */
649 static void chkmail __P((int));
653 /* $NetBSD: main.h,v 1.8 1995/05/11 21:29:27 christos Exp $ */
654 extern int rootpid; /* pid of main shell */
655 extern int rootshell; /* true if we aren't a child of the main shell */
657 static void readcmdfile __P((char *));
658 static void cmdloop __P((int));
659 static int dotcmd __P((int, char **));
660 static int exitcmd __P((int, char **));
664 /* $NetBSD: memalloc.h,v 1.11 2000/11/01 19:56:01 christos Exp $ */
666 struct stack_block *stackp;
669 struct stackmark *marknext;
673 extern char *stacknxt;
674 extern int stacknleft;
675 extern int sstrnleft;
678 static inline pointer ckmalloc (int sz) { return xmalloc(sz); }
679 static inline pointer ckrealloc(void *p, int sz) { return xrealloc(p, sz); }
680 static inline char * savestr (const char *s) { return xstrdup(s); }
682 pointer stalloc __P((int));
683 static void stunalloc __P((pointer));
684 static void setstackmark __P((struct stackmark *));
685 static void popstackmark __P((struct stackmark *));
686 static void growstackblock __P((void));
687 static void grabstackblock __P((int));
688 static char *growstackstr __P((void));
689 static char *makestrspace __P((size_t));
690 static void ungrabstackstr __P((char *, char *));
694 #define stackblock() stacknxt
695 #define stackblocksize() stacknleft
696 #define STARTSTACKSTR(p) p = stackblock(), sstrnleft = stackblocksize()
697 #define STPUTC(c, p) (--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c)))
698 #define CHECKSTRSPACE(n, p) { if (sstrnleft < n) p = makestrspace(n); }
699 #define USTPUTC(c, p) (--sstrnleft, *p++ = (c))
700 #define STACKSTRNUL(p) (sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0'))
701 #define STUNPUTC(p) (++sstrnleft, --p)
702 #define STTOPC(p) p[-1]
703 #define STADJUST(amount, p) (p += (amount), sstrnleft -= (amount))
704 #define grabstackstr(p) stalloc(stackblocksize() - sstrnleft)
706 #define ckfree(p) free((pointer)(p))
710 /* $NetBSD: miscbltin.h,v 1.1 1997/07/04 21:02:10 christos Exp $ */
711 static int readcmd __P((int, char **));
712 static int umaskcmd __P((int, char **));
713 static int ulimitcmd __P((int, char **));
717 /* $NetBSD: mystring.h,v 1.9 1995/05/11 21:29:42 christos Exp $ */
719 extern const char snlfmt[];
720 extern const char spcstr[];
723 static void scopyn __P((const char *, char *, int));
725 static int prefix __P((const char *, const char *));
726 static int number __P((const char *));
727 static int is_number __P((const char *));
728 static char *single_quote __P((const char *));
729 static char *sstrdup __P((const char *));
730 static int pstrcmp __P((const void *, const void *));
731 static const char *const *findstring __P((const char *, const char *const *, size_t));
733 #define equal(s1, s2) (strcmp(s1, s2) == 0)
734 #define scopy(s1, s2) ((void)strcpy(s2, s1))
737 /* $NetBSD: options.h,v 1.14 2001/02/04 19:52:06 christos Exp $ */
740 int nparam; /* # of positional parameters (without $0) */
741 unsigned char malloc; /* if parameter list dynamically allocated */
742 char **p; /* parameter list */
743 int optind; /* next parameter to be processed by getopts */
744 int optoff; /* used by getopts */
749 #define eflag optlist[0].val
750 #define fflag optlist[1].val
751 #define Iflag optlist[2].val
752 #define iflag optlist[3].val
753 #define mflag optlist[4].val
754 #define nflag optlist[5].val
755 #define sflag optlist[6].val
756 #define xflag optlist[7].val
757 #define vflag optlist[8].val
758 #define Vflag optlist[9].val
759 #define Eflag optlist[10].val
760 #define Cflag optlist[11].val
761 #define aflag optlist[12].val
762 #define bflag optlist[13].val
763 #define uflag optlist[14].val
764 #define qflag optlist[15].val
774 extern struct optent optlist[NOPTS];
777 extern char *minusc; /* argument to -c option */
778 extern char *arg0; /* $0 */
779 extern struct shparam shellparam; /* $@ */
780 extern char **argptr; /* argument list for builtin commands */
781 extern char *optionarg; /* set by nextopt */
782 extern char *optptr; /* used by nextopt */
784 static void procargs __P((int, char **));
785 static void optschanged __P((void));
786 static void setparam __P((char **));
787 static void freeparam __P((volatile struct shparam *));
788 static int shiftcmd __P((int, char **));
789 static int setcmd __P((int, char **));
791 static int getoptscmd __P((int, char **));
792 static int setvarsafe __P((const char *, const char *, int));
794 static int nextopt __P((const char *));
795 static void getoptsreset __P((const char *));
799 /* $NetBSD: output.h,v 1.14 1998/01/31 12:37:55 christos Exp $ */
801 #ifdef USE_GLIBC_STDIO
812 extern struct output output;
813 extern struct output errout;
814 extern struct output memout;
815 extern struct output *out1;
816 extern struct output *out2;
818 static void outstr __P((const char *, struct output *));
819 #ifndef USE_GLIBC_STDIO
820 static void outcslow __P((char, struct output *));
822 static void flushall __P((void));
823 static void flushout __P((struct output *));
824 static void freestdout __P((void));
825 static void outfmt __P((struct output *, const char *, ...))
826 __attribute__((__format__(__printf__,2,3)));
827 static void out1fmt __P((const char *, ...))
828 __attribute__((__format__(__printf__,1,2)));
829 static void fmtstr __P((char *, size_t, const char *, ...))
830 __attribute__((__format__(__printf__,3,4)));
831 #ifndef USE_GLIBC_STDIO
832 static void doformat __P((struct output *, const char *, va_list));
834 static int xwrite __P((int, const char *, int));
835 #ifdef USE_GLIBC_STDIO
836 static void initstreams __P((void));
837 static void openmemout __P((void));
838 static int __closememout __P((void));
841 #define OUTPUT_ERR 01 /* error occurred on output */
843 #ifdef USE_GLIBC_STDIO
844 #define outc(c, o) putc((c), (o)->stream)
845 #define doformat(d, f, a) vfprintf((d)->stream, (f), (a))
847 #define outc(c, file) (--(file)->nleft < 0? outcslow((c), (file)) : (*(file)->nextc = (c), (file)->nextc++))
849 #define out1c(c) outc((c), out1)
850 #define out2c(c) outc((c), out2)
851 #define out1str(s) outstr((s), out1)
852 #define out2str(s) outstr((s), out2)
853 #define outerr(f) ((f)->flags & OUTPUT_ERR)
857 /* $NetBSD: parser.h,v 1.14 2000/07/27 04:09:28 cgd Exp $ */
858 /* control characters in argument strings */
859 #define CTLESC '\201'
860 #define CTLVAR '\202'
861 #define CTLENDVAR '\203'
862 #define CTLBACKQ '\204'
863 #define CTLQUOTE 01 /* ored with CTLBACKQ code if in quotes */
864 /* CTLBACKQ | CTLQUOTE == '\205' */
865 #define CTLARI '\206'
866 #define CTLENDARI '\207'
867 #define CTLQUOTEMARK '\210'
869 /* variable substitution byte (follows CTLVAR) */
870 #define VSTYPE 0x0f /* type of variable substitution */
871 #define VSNUL 0x10 /* colon--treat the empty string as unset */
872 #define VSQUOTE 0x80 /* inside double quotes--suppress splitting */
874 /* values of VSTYPE field */
875 #define VSNORMAL 0x1 /* normal variable: $var or ${var} */
876 #define VSMINUS 0x2 /* ${var-text} */
877 #define VSPLUS 0x3 /* ${var+text} */
878 #define VSQUESTION 0x4 /* ${var?message} */
879 #define VSASSIGN 0x5 /* ${var=text} */
880 #define VSTRIMLEFT 0x6 /* ${var#pattern} */
881 #define VSTRIMLEFTMAX 0x7 /* ${var##pattern} */
882 #define VSTRIMRIGHT 0x8 /* ${var%pattern} */
883 #define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */
884 #define VSLENGTH 0xa /* ${#var} */
888 * NEOF is returned by parsecmd when it encounters an end of file. It
889 * must be distinct from NULL, so we use the address of a variable that
890 * happens to be handy.
892 extern int tokpushback;
893 #define NEOF ((union node *)&tokpushback)
894 extern int whichprompt; /* 1 == PS1, 2 == PS2 */
895 extern int checkalias;
898 union node *parsecmd(int);
899 static void fixredir(union node *, const char *, int);
900 static int goodname(char *);
901 static const char *getprompt(void *);
902 static int isassignment __P((const char *));
903 static const char *const *findkwd __P((const char *));
906 /* $NetBSD: redir.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */
907 /* flags passed to redirect */
908 #define REDIR_PUSH 01 /* save previous values of file descriptors */
909 #define REDIR_BACKQ 02 /* save the command output in memory */
913 static void redirect __P((union node *, int));
914 static void popredir __P((void));
915 static int fd0_redirected_p __P((void));
916 static void clearredir __P((void));
917 static int dup_as_newfd __P((int, int));
922 /* $NetBSD: show.h,v 1.4 1999/10/08 21:10:44 pk Exp $ */
924 static void trace __P((const char *, ...));
925 static void trargs __P((char **));
926 static void showtree __P((union node *));
927 static void trputc __P((int));
928 static void trputs __P((const char *));
929 static void opentrace __P((void));
932 * This file was generated by the mksyntax program.
940 #define CWORD 0 /* character is nothing special */
941 #define CNL 1 /* newline character */
942 #define CBACK 2 /* a backslash character */
943 #define CSQUOTE 3 /* single quote */
944 #define CDQUOTE 4 /* double quote */
945 #define CENDQUOTE 5 /* a terminating quote */
946 #define CBQUOTE 6 /* backwards single quote */
947 #define CVAR 7 /* a dollar sign */
948 #define CENDVAR 8 /* a '}' character */
949 #define CLP 9 /* a left paren in arithmetic */
950 #define CRP 10 /* a right paren in arithmetic */
951 #define CEOF 11 /* end of file */
952 #define CCTL 12 /* like CWORD, except it must be escaped */
953 #define CSPCL 13 /* these terminate a word */
954 #define CIGN 14 /* character should be ignored */
956 /* Syntax classes for is_ functions */
957 #define ISDIGIT 01 /* a digit */
958 #define ISUPPER 02 /* an upper case letter */
959 #define ISLOWER 04 /* a lower case letter */
960 #define ISUNDER 010 /* an underscore */
961 #define ISSPECL 020 /* the name of a special parameter */
969 #define BASESYNTAX (basesyntax + SYNBASE)
970 #define DQSYNTAX (dqsyntax + SYNBASE)
971 #define SQSYNTAX (sqsyntax + SYNBASE)
972 #define ARISYNTAX (arisyntax + SYNBASE)
974 #define is_digit(c) ((unsigned)((c) - '0') <= 9)
975 #define is_alpha(c) (((c) < CTLESC || (c) > CTLENDARI) && isalpha((unsigned char) (c)))
976 #define is_name(c) (((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalpha((unsigned char) (c))))
977 #define is_in_name(c) (((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalnum((unsigned char) (c))))
978 #define is_special(c) ((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))
979 #define digit_val(c) ((c) - '0')
981 extern const char basesyntax[];
982 extern const char dqsyntax[];
983 extern const char sqsyntax[];
984 extern const char arisyntax[];
985 extern const char is_type[];
996 #define TENDBQUOTE 10
1017 /* Array indicating which tokens mark the end of a list */
1018 static const char tokendlist[] = {
1051 static const char *const tokname[] = {
1084 #define KWDOFFSET 14
1086 static const char *const parsekwd[] = {
1108 /* $NetBSD: trap.h,v 1.14 2000/05/22 10:18:47 elric Exp $ */
1109 extern int pendingsigs;
1111 static int trapcmd __P((int, char **));
1112 static void clear_traps __P((void));
1113 static void setsignal __P((int));
1114 static void ignoresig __P((int));
1115 static void onsig __P((int));
1116 static void dotrap __P((void));
1117 static void setinteractive __P((int));
1118 static void exitshell __P((int)) __attribute__((noreturn));
1119 static int decode_signal __P((const char *, int));
1123 /* $NetBSD: var.h,v 1.18 2000/05/22 10:18:47 elric Exp $ */
1130 #define VEXPORT 0x01 /* variable is exported */
1131 #define VREADONLY 0x02 /* variable cannot be modified */
1132 #define VSTRFIXED 0x04 /* variable struct is staticly allocated */
1133 #define VTEXTFIXED 0x08 /* text is staticly allocated */
1134 #define VSTACK 0x10 /* text is allocated on the stack */
1135 #define VUNSET 0x20 /* the variable is not set */
1136 #define VNOFUNC 0x40 /* don't call the callback function */
1140 struct var *next; /* next entry in hash list */
1141 int flags; /* flags are defined above */
1142 char *text; /* name=value */
1143 void (*func) __P((const char *));
1144 /* function to be called when */
1145 /* the variable gets set/unset */
1150 struct localvar *next; /* next local variable in list */
1151 struct var *vp; /* the variable that was made local */
1152 int flags; /* saved flags */
1153 char *text; /* saved text */
1157 extern struct localvar *localvars;
1160 extern struct var vatty;
1162 extern struct var vifs;
1163 extern struct var vmail;
1164 extern struct var vmpath;
1165 extern struct var vpath;
1166 extern struct var vps1;
1167 extern struct var vps2;
1169 extern struct var vterm;
1170 extern struct var vtermcap;
1171 extern struct var vhistsize;
1175 extern const char defifsvar[];
1176 #define defifs (defifsvar + 4)
1178 extern const char defifs[];
1180 extern const char defpathvar[];
1181 #define defpath (defpathvar + 5)
1184 * The following macros access the values of the above variables.
1185 * They have to skip over the name. They return the null string
1186 * for unset variables.
1189 #define ifsval() (vifs.text + 4)
1190 #define ifsset() ((vifs.flags & VUNSET) == 0)
1191 #define mailval() (vmail.text + 5)
1192 #define mpathval() (vmpath.text + 9)
1193 #define pathval() (vpath.text + 5)
1194 #define ps1val() (vps1.text + 4)
1195 #define ps2val() (vps2.text + 4)
1196 #define optindval() (voptind.text + 7)
1198 #define histsizeval() (vhistsize.text + 9)
1199 #define termval() (vterm.text + 5)
1203 #define attyset() ((vatty.flags & VUNSET) == 0)
1205 #define mpathset() ((vmpath.flags & VUNSET) == 0)
1207 static void initvar __P((void));
1208 static void setvar __P((const char *, const char *, int));
1209 static void setvareq __P((char *, int));
1211 static void listsetvar __P((struct strlist *));
1212 static char *lookupvar __P((const char *));
1213 static char *bltinlookup __P((const char *));
1214 static char **environment __P((void));
1215 static void shprocvar __P((void));
1216 static int showvarscmd __P((int, char **));
1217 static int exportcmd __P((int, char **));
1218 static int localcmd __P((int, char **));
1219 static void mklocal __P((char *));
1220 static void poplocalvars __P((void));
1221 static int setvarcmd __P((int, char **));
1222 static int unsetcmd __P((int, char **));
1223 static int unsetvar __P((const char *));
1224 static int varequal __P((const char *, const char *));