00001 #include <stdlib.h>
00002 #include <string.h>
00003 #include <unistd.h>
00004 #include <fcntl.h>
00005
00006
00007 #ifndef _ANSI
00008 #undef _VOID
00009 #define _VOID
00010 #endif
00011
00012
00013
00014
00015
00016
00017 #define LINELIM 4096
00018 #define NPUSH 8
00019
00020 #define NOFILE 20
00021 #define NUFILE 10
00022 #define FDBASE 10
00023
00024
00025
00026
00027 #define WAITSIG(s) ((s)&0177)
00028 #define WAITVAL(s) (((s)>>8)&0377)
00029 #define WAITCORE(s) (((s)&0200)!=0)
00030
00031
00032
00033
00034 #ifdef __STDC__
00035 typedef void xint;
00036 #else
00037 typedef char * xint;
00038 #endif
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #define QUOTE 0200
00049
00050 #define NOBLOCK ((struct op *)NULL)
00051 #define NOWORD ((char *)NULL)
00052 #define NOWORDS ((char **)NULL)
00053 #define NOPIPE ((int *)NULL)
00054
00055
00056
00057
00058
00059 struct op {
00060 int type;
00061 char **words;
00062 struct ioword **ioact;
00063 struct op *left;
00064 struct op *right;
00065 char *str;
00066 };
00067
00068 #define TCOM 1
00069 #define TPAREN 2
00070 #define TPIPE 3
00071 #define TLIST 4
00072 #define TOR 5
00073 #define TAND 6
00074 #define TFOR 7
00075 #define TDO 8
00076 #define TCASE 9
00077 #define TIF 10
00078 #define TWHILE 11
00079 #define TUNTIL 12
00080 #define TELIF 13
00081 #define TPAT 14
00082 #define TBRACE 15
00083 #define TASYNC 16
00084
00085
00086
00087
00088 #define BIT(i) (1<<(i))
00089 #define FEXEC BIT(0)
00090
00091
00092
00093
00094 #define DOSUB 1
00095 #define DOBLANK 2
00096 #define DOGLOB 4
00097 #define DOKEY 8
00098 #define DOTRIM 16
00099
00100 #define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
00101
00102 Extern char **dolv;
00103 Extern int dolc;
00104 Extern int exstat;
00105 Extern char gflg;
00106 Extern int talking;
00107 Extern int execflg;
00108 Extern int multiline;
00109 Extern struct op *outtree;
00110
00111 Extern xint *failpt;
00112 Extern xint *errpt;
00113
00114 struct brkcon {
00115 jmp_buf brkpt;
00116 struct brkcon *nextlev;
00117 } ;
00118 Extern struct brkcon *brklist;
00119 Extern int isbreak;
00120
00121
00122
00123
00124 struct ioword {
00125 short io_unit;
00126 short io_flag;
00127 char *io_name;
00128 };
00129 #define IOREAD 1
00130 #define IOHERE 2
00131 #define IOWRITE 4
00132 #define IOCAT 8
00133 #define IOXHERE 16
00134 #define IODUP 32
00135 #define IOCLOSE 64
00136
00137 #define IODEFAULT (-1)
00138
00139 Extern struct wdblock *wdlist;
00140 Extern struct wdblock *iolist;
00141
00142
00143
00144
00145 extern struct env {
00146 char *linep;
00147 struct io *iobase;
00148 struct io *iop;
00149 xint *errpt;
00150 int iofd;
00151 struct env *oenv;
00152 } e;
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 extern char *flag;
00165
00166 extern char *null;
00167 extern int intr;
00168
00169 Extern char *trap[_NSIG+1];
00170 Extern char ourtrap[_NSIG+1];
00171 Extern int trapset;
00172
00173 extern int heedint;
00174
00175 Extern int yynerrs;
00176
00177 Extern char line[LINELIM];
00178 extern char *elinep;
00179
00180
00181
00182
00183 #ifdef __STDC__
00184 int (*inbuilt(char *s ))(void);
00185 #else
00186 int (*inbuilt())();
00187 #endif
00188 _PROTOTYPE(char *rexecve , (char *c , char **v , char **envp ));
00189 _PROTOTYPE(char *space , (int n ));
00190 _PROTOTYPE(char *strsave , (char *s , int a ));
00191 _PROTOTYPE(char *evalstr , (char *cp , int f ));
00192 _PROTOTYPE(char *putn , (int n ));
00193 _PROTOTYPE(char *itoa , (unsigned u , int n ));
00194 _PROTOTYPE(char *unquote , (char *as ));
00195 _PROTOTYPE(struct var *lookup , (char *n ));
00196 _PROTOTYPE(int rlookup , (char *n ));
00197 _PROTOTYPE(struct wdblock *glob , (char *cp , struct wdblock *wb ));
00198 _PROTOTYPE(int subgetc , (int ec , int quoted ));
00199 _PROTOTYPE(char **makenv , (void));
00200 _PROTOTYPE(char **eval , (char **ap , int f ));
00201 _PROTOTYPE(int setstatus , (int s ));
00202 _PROTOTYPE(int waitfor , (int lastpid , int canintr ));
00203
00204 _PROTOTYPE(void onintr , (int s ));
00205
00206 _PROTOTYPE(int newenv , (int f ));
00207 _PROTOTYPE(void quitenv , (void));
00208 _PROTOTYPE(void err , (char *s ));
00209 _PROTOTYPE(int anys , (char *s1 , char *s2 ));
00210 _PROTOTYPE(int any , (int c , char *s ));
00211 _PROTOTYPE(void next , (int f ));
00212 _PROTOTYPE(void setdash , (void));
00213 _PROTOTYPE(void onecommand , (void));
00214 _PROTOTYPE(void runtrap , (int i ));
00215 _PROTOTYPE(void xfree , (char *s ));
00216 _PROTOTYPE(int letter , (int c ));
00217 _PROTOTYPE(int digit , (int c ));
00218 _PROTOTYPE(int letnum , (int c ));
00219 _PROTOTYPE(int gmatch , (char *s , char *p ));
00220
00221
00222
00223
00224 _PROTOTYPE(void leave , (void));
00225 _PROTOTYPE(void fail , (void));
00226 _PROTOTYPE(void warn , (char *s ));
00227 _PROTOTYPE(void sig , (int i ));
00228
00229
00230
00231 struct var {
00232 char *value;
00233 char *name;
00234 struct var *next;
00235 char status;
00236 };
00237 #define COPYV 1
00238 #define RONLY 01
00239 #define EXPORT 02
00240 #define GETCELL 04
00241
00242 Extern struct var *vlist;
00243
00244 Extern struct var *homedir;
00245 Extern struct var *prompt;
00246 Extern struct var *cprompt;
00247 Extern struct var *path;
00248 Extern struct var *shell;
00249 Extern struct var *ifs;
00250
00251 _PROTOTYPE(int yyparse , (void));
00252 _PROTOTYPE(struct var *lookup , (char *n ));
00253 _PROTOTYPE(void setval , (struct var *vp , char *val ));
00254 _PROTOTYPE(void nameval , (struct var *vp , char *val , char *name ));
00255 _PROTOTYPE(void export , (struct var *vp ));
00256 _PROTOTYPE(void ronly , (struct var *vp ));
00257 _PROTOTYPE(int isassign , (char *s ));
00258 _PROTOTYPE(int checkname , (char *cp ));
00259 _PROTOTYPE(int assign , (char *s , int cf ));
00260 _PROTOTYPE(void putvlist , (int f , int out ));
00261 _PROTOTYPE(int eqname , (char *n1 , char *n2 ));
00262
00263 _PROTOTYPE(int execute , (struct op *t , int *pin , int *pout , int act ));
00264
00265
00266
00267 struct iobuf {
00268 unsigned id;
00269 char buf[512];
00270 char *bufp;
00271 char *ebufp;
00272 };
00273
00274
00275 struct ioarg {
00276 char *aword;
00277 char **awordlist;
00278 int afile;
00279 unsigned afid;
00280 long afpos;
00281 struct iobuf *afbuf;
00282 };
00283 Extern struct ioarg ioargstack[NPUSH];
00284 #define AFID_NOBUF (~0)
00285 #define AFID_ID 0
00286
00287
00288 struct io {
00289 int (*iofn)(_VOID);
00290 struct ioarg *argp;
00291 int peekc;
00292 char prev;
00293 char nlcount;
00294 char xchar;
00295 char task;
00296 };
00297 Extern struct io iostack[NPUSH];
00298 #define XOTHER 0
00299 #define XDOLL 1
00300 #define XGRAVE 2
00301 #define XIO 3
00302
00303
00304 #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
00305
00306
00307
00308
00309 _PROTOTYPE(int nlchar , (struct ioarg *ap ));
00310 _PROTOTYPE(int strchar , (struct ioarg *ap ));
00311 _PROTOTYPE(int qstrchar , (struct ioarg *ap ));
00312 _PROTOTYPE(int filechar , (struct ioarg *ap ));
00313 _PROTOTYPE(int herechar , (struct ioarg *ap ));
00314 _PROTOTYPE(int linechar , (struct ioarg *ap ));
00315 _PROTOTYPE(int gravechar , (struct ioarg *ap , struct io *iop ));
00316 _PROTOTYPE(int qgravechar , (struct ioarg *ap , struct io *iop ));
00317 _PROTOTYPE(int dolchar , (struct ioarg *ap ));
00318 _PROTOTYPE(int wdchar , (struct ioarg *ap ));
00319 _PROTOTYPE(void scraphere , (void));
00320 _PROTOTYPE(void freehere , (int area ));
00321 _PROTOTYPE(void gethere , (void));
00322 _PROTOTYPE(void markhere , (char *s , struct ioword *iop ));
00323 _PROTOTYPE(int herein , (char *hname , int xdoll ));
00324 _PROTOTYPE(int run , (struct ioarg *argp , int (*f)(_VOID)));
00325
00326
00327
00328
00329 _PROTOTYPE(int eofc , (void));
00330 _PROTOTYPE(int getc , (int ec ));
00331 _PROTOTYPE(int readc , (void));
00332 _PROTOTYPE(void unget , (int c ));
00333 _PROTOTYPE(void ioecho , (int c ));
00334 _PROTOTYPE(void prs , (char *s ));
00335 _PROTOTYPE(void putc , (int c ));
00336 _PROTOTYPE(void prn , (unsigned u ));
00337 _PROTOTYPE(void closef , (int i ));
00338 _PROTOTYPE(void closeall , (void));
00339
00340
00341
00342
00343 _PROTOTYPE(void pushio , (struct ioarg *argp , int (*fn)(_VOID)));
00344 _PROTOTYPE(int remap , (int fd ));
00345 _PROTOTYPE(int openpipe , (int *pv ));
00346 _PROTOTYPE(void closepipe , (int *pv ));
00347 _PROTOTYPE(struct io *setbase , (struct io *ip ));
00348
00349 extern struct ioarg temparg;
00350 #define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen)))
00351 #define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
00352
00353
00354 #ifndef WORD_H
00355 #define WORD_H 1
00356 struct wdblock {
00357 short w_bsize;
00358 short w_nword;
00359
00360 char *w_words[1];
00361 };
00362
00363 _PROTOTYPE(struct wdblock *addword , (char *wd , struct wdblock *wb ));
00364 _PROTOTYPE(struct wdblock *newword , (int nw ));
00365 _PROTOTYPE(char **getwords , (struct wdblock *wb ));
00366 #endif
00367
00368
00369
00370
00371
00372
00373 _PROTOTYPE(char *getcell , (unsigned nbytes ));
00374 _PROTOTYPE(void garbage , (void));
00375 _PROTOTYPE(void setarea , (char *cp , int a ));
00376 _PROTOTYPE(int getarea , (char *cp ));
00377 _PROTOTYPE(void freearea , (int a ));
00378 _PROTOTYPE(void freecell , (char *cp ));
00379
00380 Extern int areanum;
00381
00382 #define NEW(type) (type *)getcell(sizeof(type))
00383 #define DELETE(obj) freecell((char *)obj)