OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [sh/] [sh.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#include <stdlib.h>
2
#include <string.h>
3
#include <unistd.h>
4
#include <fcntl.h>
5
 
6
/* Need a way to have void used for ANSI, nothing for K&R. */
7
#ifndef _ANSI
8
#undef _VOID
9
#define _VOID
10
#endif
11
 
12
/* -------- sh.h -------- */
13
/*
14
 * shell
15
 */
16
 
17
#define LINELIM 2100
18
#define NPUSH   8       /* limit to input nesting */
19
 
20
#define NOFILE  20      /* Number of open files */
21
#define NUFILE  10      /* Number of user-accessible files */
22
#define FDBASE  10      /* First file usable by Shell */
23
 
24
/*
25
 * values returned by wait
26
 */
27
#define WAITSIG(s) ((s)&0177)
28
#define WAITVAL(s) (((s)>>8)&0377)
29
#define WAITCORE(s) (((s)&0200)!=0)
30
 
31
/*
32
 * library and system defintions
33
 */
34
#ifdef __STDC__
35
typedef void xint;      /* base type of jmp_buf, for not broken compilers */
36
#else
37
typedef char * xint;    /* base type of jmp_buf, for broken compilers */
38
#endif
39
 
40
/*
41
 * shell components
42
 */
43
/* #include "area.h" */
44
/* #include "word.h" */
45
/* #include "io.h" */
46
/* #include "var.h" */
47
 
48
#define QUOTE   0200
49
 
50
#define NOBLOCK ((struct op *)NULL)
51
#define NOWORD  ((char *)NULL)
52
#define NOWORDS ((char **)NULL)
53
#define NOPIPE  ((int *)NULL)
54
 
55
/*
56
 * Description of a command or an operation on commands.
57
 * Might eventually use a union.
58
 */
59
struct op {
60
        int     type;   /* operation type, see below */
61
        char    **words;        /* arguments to a command */
62
        struct  ioword  **ioact;        /* IO actions (eg, < > >>) */
63
        struct op *left;
64
        struct op *right;
65
        char    *str;   /* identifier for case and for */
66
};
67
 
68
#define TCOM    1       /* command */
69
#define TPAREN  2       /* (c-list) */
70
#define TPIPE   3       /* a | b */
71
#define TLIST   4       /* a [&;] b */
72
#define TOR     5       /* || */
73
#define TAND    6       /* && */
74
#define TFOR    7
75
#define TDO     8
76
#define TCASE   9
77
#define TIF     10
78
#define TWHILE  11
79
#define TUNTIL  12
80
#define TELIF   13
81
#define TPAT    14      /* pattern in case */
82
#define TBRACE  15      /* {c-list} */
83
#define TASYNC  16      /* c & */
84
 
85
/*
86
 * actions determining the environment of a process
87
 */
88
#define BIT(i)  (1<<(i))
89
#define FEXEC   BIT(0)  /* execute without forking */
90
 
91
/*
92
 * flags to control evaluation of words
93
 */
94
#define DOSUB   1       /* interpret $, `, and quotes */
95
#define DOBLANK 2       /* perform blank interpretation */
96
#define DOGLOB  4       /* interpret [?* */
97
#define DOKEY   8       /* move words with `=' to 2nd arg. list */
98
#define DOTRIM  16      /* trim resulting string */
99
 
100
#define DOALL   (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
101
 
102
extern  char    **dolv;
103
extern  int     dolc;
104
extern  int     exstat;
105
extern  char    gflg;
106
extern  int     talking;        /* interactive (talking-type wireless) */
107
extern  int     execflg;
108
extern  int     multiline;      /* \n changed to ; */
109
extern  struct  op      *outtree;       /* result from parser */
110
 
111
extern  xint    *failpt;
112
extern  xint    *errpt;
113
 
114
struct  brkcon {
115
        jmp_buf brkpt;
116
        struct  brkcon  *nextlev;
117
} ;
118
extern  struct brkcon   *brklist;
119
extern  int     isbreak;
120
 
121
/*
122
 * redirection
123
 */
124
struct ioword {
125
        short   io_unit;        /* unit affected */
126
        short   io_flag;        /* action (below) */
127
        char    *io_name;       /* file name */
128
};
129
#define IOREAD  1       /* < */
130
#define IOHERE  2       /* << (here file) */
131
#define IOWRITE 4       /* > */
132
#define IOCAT   8       /* >> */
133
#define IOXHERE 16      /* ${}, ` in << */
134
#define IODUP   32      /* >&digit */
135
#define IOCLOSE 64      /* >&- */
136
 
137
#define IODEFAULT (-1)  /* token for default IO unit */
138
 
139
extern  struct  wdblock *wdlist;
140
extern  struct  wdblock *iolist;
141
 
142
/*
143
 * parsing & execution environment
144
 */
145
extern struct   env {
146
        char    *linep;
147
        struct  io      *iobase;
148
        struct  io      *iop;
149
        xint    *errpt;
150
        int     iofd;
151
        struct  env     *oenv;
152
} e;
153
 
154
/*
155
 * flags:
156
 * -e: quit on error
157
 * -k: look for name=value everywhere on command line
158
 * -n: no execution
159
 * -t: exit after reading and executing one command
160
 * -v: echo as read
161
 * -x: trace
162
 * -u: unset variables net diagnostic
163
 */
164
extern  char    *flag;
165
 
166
extern  char    *null;  /* null value for variable */
167
extern  int     intr;   /* interrupt pending */
168
 
169
extern  char    *trap[_NSIG+1];
170
extern  char    ourtrap[_NSIG+1];
171
extern  int     trapset;        /* trap pending */
172
 
173
extern  int     heedint;        /* heed interrupt signals */
174
 
175
extern  int     yynerrs;        /* yacc */
176
 
177
extern  char    line[LINELIM];
178
extern  char    *elinep;
179
 
180
/*
181
 * other functions
182
 */
183
#ifdef __STDC__
184
int (*inbuilt(char *s ))(void);
185
#else
186
int (*inbuilt())();
187
#endif
188
 
189
char *rexecve (char *c , char **v, char **envp );
190
char *space (int n );
191
char *strsave (char *s, int a );
192
char *evalstr (char *cp, int f );
193
char *putn (int n );
194
char *itoa (unsigned u, int n );
195
char *unquote (char *as );
196
struct var *lookup (char *n );
197
int rlookup (char *n );
198
struct wdblock *glob (char *cp, struct wdblock *wb );
199
int my_getc( int ec);
200
int subgetc (int ec, int quoted );
201
char **makenv (void);
202
char **eval (char **ap, int f );
203
int setstatus (int s );
204
int waitfor (int lastpid, int canintr );
205
 
206
void onintr (int s ); /* SIGINT handler */
207
 
208
int newenv (int f );
209
void quitenv (void);
210
void err (char *s );
211
int anys (char *s1, char *s2 );
212
int any (int c, char *s );
213
void next (int f );
214
void setdash (void);
215
void onecommand (void);
216
void runtrap (int i );
217
void xfree (char *s );
218
int letter (int c );
219
int digit (int c );
220
int letnum (int c );
221
int gmatch (char *s, char *p );
222
 
223
/*
224
 * error handling
225
 */
226
void leave (void); /* abort shell (or fail in subshell) */
227
void fail (void);        /* fail but return to process next command */
228
void warn (char *s );
229
void sig (int i );       /* default signal handler */
230
 
231
/* -------- var.h -------- */
232
 
233
struct  var {
234
        char    *value;
235
        char    *name;
236
        struct  var     *next;
237
        char    status;
238
};
239
#define COPYV   1       /* flag to setval, suggesting copy */
240
#define RONLY   01      /* variable is read-only */
241
#define EXPORT  02      /* variable is to be exported */
242
#define GETCELL 04      /* name & value space was got with getcell */
243
 
244
extern  struct  var     *vlist;         /* dictionary */
245
 
246
extern  struct  var     *homedir;       /* home directory */
247
extern  struct  var     *prompt;        /* main prompt */
248
extern  struct  var     *cprompt;       /* continuation prompt */
249
extern  struct  var     *path;          /* search path for commands */
250
extern  struct  var     *shell;         /* shell to interpret command files */
251
extern  struct  var     *ifs;           /* field separators */
252
 
253
int yyparse (void);
254
struct var *lookup (char *n );
255
void setval (struct var *vp, char *val );
256
void nameval (struct var *vp, char *val, char *name );
257
void export (struct var *vp );
258
void ronly (struct var *vp );
259
int isassign (char *s );
260
int checkname (char *cp );
261
int assign (char *s, int cf );
262
void putvlist (int f, int out );
263
int eqname (char *n1, char *n2 );
264
 
265
int execute (struct op *t, int *pin, int *pout, int act );
266
 
267
/* -------- io.h -------- */
268
/* io buffer */
269
struct iobuf {
270
  unsigned id;                          /* buffer id */
271
  char buf[512];                        /* buffer */
272
  char *bufp;                           /* pointer into buffer */
273
  char *ebufp;                          /* pointer to end of buffer */
274
};
275
 
276
/* possible arguments to an IO function */
277
struct ioarg {
278
        char    *aword;
279
        char    **awordlist;
280
        int     afile;          /* file descriptor */
281
        unsigned afid;          /* buffer id */
282
        long    afpos;          /* file position */
283
        struct iobuf *afbuf;    /* buffer for this file */
284
};
285
extern struct ioarg ioargstack[NPUSH];
286
#define AFID_NOBUF      (~0)
287
#define AFID_ID         0
288
 
289
/* an input generator's state */
290
struct  io {
291
        int     (*iofn)(_VOID);
292
        struct  ioarg   *argp;
293
        int     peekc;
294
        char    prev;           /* previous character read by readc() */
295
        char    nlcount;        /* for `'s */
296
        char    xchar;          /* for `'s */
297
        char    task;           /* reason for pushed IO */
298
};
299
extern  struct  io      iostack[NPUSH];
300
#define XOTHER  0        /* none of the below */
301
#define XDOLL   1       /* expanding ${} */
302
#define XGRAVE  2       /* expanding `'s */
303
#define XIO     3       /* file IO */
304
 
305
/* in substitution */
306
#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
307
 
308
/*
309
 * input generators for IO structure
310
 */
311
int nlchar (struct ioarg *ap );
312
int strchar (struct ioarg *ap );
313
int qstrchar (struct ioarg *ap );
314
int filechar (struct ioarg *ap );
315
int herechar (struct ioarg *ap );
316
int linechar (struct ioarg *ap );
317
int gravechar (struct ioarg *ap, struct io *iop );
318
int qgravechar (struct ioarg *ap, struct io *iop );
319
int dolchar (struct ioarg *ap );
320
int wdchar (struct ioarg *ap );
321
void scraphere (void);
322
void freehere (int area );
323
void gethere (void);
324
void markhere (char *s, struct ioword *iop );
325
int herein (char *hname, int xdoll );
326
int run (struct ioarg *argp, int (*f)(_VOID));
327
 
328
/*
329
 * IO functions
330
 */
331
int eofc (void);
332
int readc (void);
333
void unget (int c );
334
void ioecho (int c );
335
void prs (char *s );
336
void prn (unsigned u );
337
void closef (int i );
338
void closeall (void);
339
 
340
/*
341
 * IO control
342
 */
343
void pushio (struct ioarg *argp, int (*fn)(_VOID));
344
int remap (int fd );
345
int openpipe (int *pv );
346
void closepipe (int *pv );
347
struct io *setbase (struct io *ip );
348
 
349
extern  struct  ioarg   temparg;        /* temporary for PUSHIO */
350
#define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen)))
351
#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
352
 
353
/* -------- word.h -------- */
354
#ifndef WORD_H
355
#define WORD_H  1
356
struct  wdblock {
357
        short   w_bsize;
358
        short   w_nword;
359
        /* bounds are arbitrary */
360
        char    *w_words[1];
361
};
362
 
363
struct wdblock *addword (char *wd, struct wdblock *wb );
364
struct wdblock *newword (int nw );
365
char **getwords (struct wdblock *wb );
366
#endif
367
 
368
//#if 0
369
/* -------- area.h -------- */
370
 
371
/*
372
 * storage allocation
373
 */
374
char *getcell (unsigned nbytes );
375
void garbage (void);
376
void setarea (char *cp, int a );
377
int getarea (char *cp );
378
void freearea (int a );
379
void freecell (char *cp );
380
 
381
extern  int     areanum;        /* current allocation area */
382
 
383
#define NEW(type) (type *)getcell(sizeof(type))
384
#define DELETE(obj)     freecell((char *)obj)
385
 
386
//#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.