|
1 /* |
|
2 * zsh.h - standard header file |
|
3 * |
|
4 * This file is part of zsh, the Z shell. |
|
5 * |
|
6 * Copyright (c) 1992-1997 Paul Falstad |
|
7 * All rights reserved. |
|
8 * |
|
9 * Permission is hereby granted, without written agreement and without |
|
10 * license or royalty fees, to use, copy, modify, and distribute this |
|
11 * software and to distribute modified versions of this software for any |
|
12 * purpose, provided that the above copyright notice and the following |
|
13 * two paragraphs appear in all copies of this software. |
|
14 * |
|
15 * In no event shall Paul Falstad or the Zsh Development Group be liable |
|
16 * to any party for direct, indirect, special, incidental, or consequential |
|
17 * damages arising out of the use of this software and its documentation, |
|
18 * even if Paul Falstad and the Zsh Development Group have been advised of |
|
19 * the possibility of such damage. |
|
20 * |
|
21 * Paul Falstad and the Zsh Development Group specifically disclaim any |
|
22 * warranties, including, but not limited to, the implied warranties of |
|
23 * merchantability and fitness for a particular purpose. The software |
|
24 * provided hereunder is on an "as is" basis, and Paul Falstad and the |
|
25 * Zsh Development Group have no obligation to provide maintenance, |
|
26 * support, updates, enhancements, or modifications. |
|
27 * |
|
28 */ |
|
29 |
|
30 #define trashzle() trashzleptr() |
|
31 #define zle_resetprompt() zle_resetpromptptr() |
|
32 #define zleread(X,Y,H,C) zlereadptr(X,Y,H,C) |
|
33 #define spaceinline(X) spaceinlineptr(X) |
|
34 #define zrefresh() refreshptr() |
|
35 |
|
36 #define compctlread(N,A,O,R) compctlreadptr(N,A,O,R) |
|
37 |
|
38 /* A few typical macros */ |
|
39 #define minimum(a,b) ((a) < (b) ? (a) : (b)) |
|
40 |
|
41 /* |
|
42 * Our longest integer type: will be a 64 bit either if long already is, |
|
43 * or if we found some alternative such as long long. |
|
44 * Currently we only define this to be longer than a long if --enable-lfs |
|
45 * was given. That enables internal use of 64-bit types even if |
|
46 * no actual large file support is present. |
|
47 */ |
|
48 #ifdef ZSH_64_BIT_TYPE |
|
49 typedef ZSH_64_BIT_TYPE zlong; |
|
50 #ifdef ZSH_64_BIT_UTYPE |
|
51 typedef ZSH_64_BIT_UTYPE zulong; |
|
52 #else |
|
53 typedef unsigned zlong zulong; |
|
54 #endif |
|
55 #else |
|
56 typedef long zlong; |
|
57 typedef unsigned long zulong; |
|
58 #endif |
|
59 |
|
60 /* |
|
61 * Double float support requires 64-bit alignment, so if longs and |
|
62 * pointers are less we need to pad out. |
|
63 */ |
|
64 #ifndef LONG_IS_64_BIT |
|
65 # define PAD_64_BIT 1 |
|
66 #endif |
|
67 |
|
68 /* math.c */ |
|
69 typedef struct { |
|
70 union { |
|
71 zlong l; |
|
72 double d; |
|
73 } u; |
|
74 int type; |
|
75 } mnumber; |
|
76 |
|
77 #define MN_INTEGER 1 /* mnumber is integer */ |
|
78 #define MN_FLOAT 2 /* mnumber is floating point */ |
|
79 #define MN_UNSET 4 /* mnumber not yet retrieved */ |
|
80 |
|
81 typedef struct mathfunc *MathFunc; |
|
82 typedef mnumber (*NumMathFunc)(char *, int, mnumber *, int); |
|
83 typedef mnumber (*StrMathFunc)(char *, char *, int); |
|
84 |
|
85 struct mathfunc { |
|
86 MathFunc next; |
|
87 char *name; |
|
88 int flags; |
|
89 NumMathFunc nfunc; |
|
90 StrMathFunc sfunc; |
|
91 char *module; |
|
92 int minargs; |
|
93 int maxargs; |
|
94 int funcid; |
|
95 }; |
|
96 |
|
97 #define MFF_STR 1 |
|
98 #define MFF_ADDED 2 |
|
99 |
|
100 #define NUMMATHFUNC(name, func, min, max, id) \ |
|
101 { NULL, name, 0, func, NULL, NULL, min, max, id } |
|
102 #define STRMATHFUNC(name, func, id) \ |
|
103 { NULL, name, MFF_STR, NULL, func, NULL, 0, 0, id } |
|
104 |
|
105 /* Character tokens are sometimes casted to (unsigned char)'s. * |
|
106 * Unfortunately, some compilers don't correctly cast signed to * |
|
107 * unsigned promotions; i.e. (int)(unsigned char)((char) -1) evaluates * |
|
108 * to -1, instead of 255 like it should. We circumvent the troubles * |
|
109 * of such shameful delinquency by casting to a larger unsigned type * |
|
110 * then back down to unsigned char. */ |
|
111 |
|
112 #ifdef BROKEN_SIGNED_TO_UNSIGNED_CASTING |
|
113 # define STOUC(X) ((unsigned char)(unsigned short)(X)) |
|
114 #else |
|
115 # define STOUC(X) ((unsigned char)(X)) |
|
116 #endif |
|
117 |
|
118 /* Meta together with the character following Meta denotes the character * |
|
119 * which is the exclusive or of 32 and the character following Meta. * |
|
120 * This is used to represent characters which otherwise has special * |
|
121 * meaning for zsh. These are the characters for which the imeta() test * |
|
122 * is true: the null character, and the characters from Meta to Marker. */ |
|
123 |
|
124 #define Meta ((char) 0x83) |
|
125 |
|
126 /* Note that the fourth character in DEFAULT_IFS is Meta * |
|
127 * followed by a space which denotes the null character. */ |
|
128 |
|
129 #define DEFAULT_IFS " \t\n\203 " |
|
130 |
|
131 /* Character tokens */ |
|
132 #define Pound ((char) 0x84) |
|
133 #define String ((char) 0x85) |
|
134 #define Hat ((char) 0x86) |
|
135 #define Star ((char) 0x87) |
|
136 #define Inpar ((char) 0x88) |
|
137 #define Outpar ((char) 0x89) |
|
138 #define Qstring ((char) 0x8a) |
|
139 #define Equals ((char) 0x8b) |
|
140 #define Bar ((char) 0x8c) |
|
141 #define Inbrace ((char) 0x8d) |
|
142 #define Outbrace ((char) 0x8e) |
|
143 #define Inbrack ((char) 0x8f) |
|
144 #define Outbrack ((char) 0x90) |
|
145 #define Tick ((char) 0x91) |
|
146 #define Inang ((char) 0x92) |
|
147 #define Outang ((char) 0x93) |
|
148 #define Quest ((char) 0x94) |
|
149 #define Tilde ((char) 0x95) |
|
150 #define Qtick ((char) 0x96) |
|
151 #define Comma ((char) 0x97) |
|
152 #define Snull ((char) 0x98) |
|
153 #define Dnull ((char) 0x99) |
|
154 #define Bnull ((char) 0x9a) |
|
155 #define Nularg ((char) 0x9b) |
|
156 |
|
157 #define INULL(x) (((x) & 0xfc) == 0x98) |
|
158 |
|
159 /* Marker used in paramsubst for rc_expand_param */ |
|
160 #define Marker ((char) 0x9c) |
|
161 |
|
162 /* chars that need to be quoted if meant literally */ |
|
163 |
|
164 #define SPECCHARS "#$^*()=|{}[]`<>?~;&\n\t \\\'\"" |
|
165 |
|
166 enum { |
|
167 NULLTOK, /* 0 */ |
|
168 SEPER, |
|
169 NEWLIN, |
|
170 SEMI, |
|
171 DSEMI, |
|
172 AMPER, /* 5 */ |
|
173 INPAR, |
|
174 OUTPAR, |
|
175 DBAR, |
|
176 DAMPER, |
|
177 OUTANG, /* 10 */ |
|
178 OUTANGBANG, |
|
179 DOUTANG, |
|
180 DOUTANGBANG, |
|
181 INANG, |
|
182 INOUTANG, /* 15 */ |
|
183 DINANG, |
|
184 DINANGDASH, |
|
185 INANGAMP, |
|
186 OUTANGAMP, |
|
187 AMPOUTANG, /* 20 */ |
|
188 OUTANGAMPBANG, |
|
189 DOUTANGAMP, |
|
190 DOUTANGAMPBANG, |
|
191 TRINANG, |
|
192 BAR, /* 25 */ |
|
193 BARAMP, |
|
194 INOUTPAR, |
|
195 DINPAR, |
|
196 DOUTPAR, |
|
197 AMPERBANG, /* 30 */ |
|
198 SEMIAMP, |
|
199 DOUTBRACK, |
|
200 STRING, |
|
201 ENVSTRING, |
|
202 ENVARRAY, /* 35 */ |
|
203 ENDINPUT, |
|
204 LEXERR, |
|
205 |
|
206 /* Tokens for reserved words */ |
|
207 BANG, /* ! */ |
|
208 DINBRACK, /* [[ */ |
|
209 INBRACE, /* { */ /* 40 */ |
|
210 OUTBRACE, /* } */ |
|
211 CASE, /* case */ |
|
212 COPROC, /* coproc */ |
|
213 DOLOOP, /* do */ |
|
214 DONE, /* done */ /* 45 */ |
|
215 ELIF, /* elif */ |
|
216 ELSE, /* else */ |
|
217 ZEND, /* end */ |
|
218 ESAC, /* esac */ |
|
219 FI, /* fi */ /* 50 */ |
|
220 FOR, /* for */ |
|
221 FOREACH, /* foreach */ |
|
222 FUNC, /* function */ |
|
223 IF, /* if */ |
|
224 NOCORRECT, /* nocorrect */ /* 55 */ |
|
225 REPEAT, /* repeat */ |
|
226 SELECT, /* select */ |
|
227 THEN, /* then */ |
|
228 TIME, /* time */ |
|
229 UNTIL, /* until */ /* 60 */ |
|
230 WHILE /* while */ |
|
231 }; |
|
232 |
|
233 /* Redirection types. If you modify this, you may also have to modify * |
|
234 * redirtab in parse.c and getredirs() in text.c and the IS_* macros * |
|
235 * below. */ |
|
236 |
|
237 enum { |
|
238 REDIR_WRITE, /* > */ |
|
239 REDIR_WRITENOW, /* >| */ |
|
240 REDIR_APP, /* >> */ |
|
241 REDIR_APPNOW, /* >>| */ |
|
242 REDIR_ERRWRITE, /* &>, >& */ |
|
243 REDIR_ERRWRITENOW, /* >&| */ |
|
244 REDIR_ERRAPP, /* >>& */ |
|
245 REDIR_ERRAPPNOW, /* >>&| */ |
|
246 REDIR_READWRITE, /* <> */ |
|
247 REDIR_READ, /* < */ |
|
248 REDIR_HEREDOC, /* << */ |
|
249 REDIR_HEREDOCDASH, /* <<- */ |
|
250 REDIR_HERESTR, /* <<< */ |
|
251 REDIR_MERGEIN, /* <&n */ |
|
252 REDIR_MERGEOUT, /* >&n */ |
|
253 REDIR_CLOSE, /* >&-, <&- */ |
|
254 REDIR_INPIPE, /* < <(...) */ |
|
255 REDIR_OUTPIPE /* > >(...) */ |
|
256 }; |
|
257 |
|
258 #define IS_WRITE_FILE(X) ((X)>=REDIR_WRITE && (X)<=REDIR_READWRITE) |
|
259 #define IS_APPEND_REDIR(X) (IS_WRITE_FILE(X) && ((X) & 2)) |
|
260 #define IS_CLOBBER_REDIR(X) (IS_WRITE_FILE(X) && ((X) & 1)) |
|
261 #define IS_ERROR_REDIR(X) ((X)>=REDIR_ERRWRITE && (X)<=REDIR_ERRAPPNOW) |
|
262 #define IS_READFD(X) (((X)>=REDIR_READWRITE && (X)<=REDIR_MERGEIN) || (X)==REDIR_INPIPE) |
|
263 #define IS_REDIROP(X) ((X)>=OUTANG && (X)<=TRINANG) |
|
264 |
|
265 /* Flags for input stack */ |
|
266 #define INP_FREE (1<<0) /* current buffer can be free'd */ |
|
267 #define INP_ALIAS (1<<1) /* expanding alias or history */ |
|
268 #define INP_HIST (1<<2) /* expanding history */ |
|
269 #define INP_CONT (1<<3) /* continue onto previously stacked input */ |
|
270 #define INP_ALCONT (1<<4) /* stack is continued from alias expn. */ |
|
271 #define INP_LINENO (1<<5) /* update line number */ |
|
272 |
|
273 /* Flags for metafy */ |
|
274 #define META_REALLOC 0 |
|
275 #define META_USEHEAP 1 |
|
276 #define META_STATIC 2 |
|
277 #define META_DUP 3 |
|
278 #define META_ALLOC 4 |
|
279 #define META_NOALLOC 5 |
|
280 #define META_HEAPDUP 6 |
|
281 #define META_HREALLOC 7 |
|
282 |
|
283 |
|
284 /**************************/ |
|
285 /* Abstract types for zsh */ |
|
286 /**************************/ |
|
287 |
|
288 typedef struct linknode *LinkNode; |
|
289 typedef struct linklist *LinkList; |
|
290 typedef struct hashnode *HashNode; |
|
291 typedef struct hashtable *HashTable; |
|
292 |
|
293 typedef struct optname *Optname; |
|
294 typedef struct reswd *Reswd; |
|
295 typedef struct alias *Alias; |
|
296 typedef struct param *Param; |
|
297 typedef struct paramdef *Paramdef; |
|
298 typedef struct cmdnam *Cmdnam; |
|
299 typedef struct shfunc *Shfunc; |
|
300 typedef struct funcstack *Funcstack; |
|
301 typedef struct funcwrap *FuncWrap; |
|
302 typedef struct options *Options; |
|
303 typedef struct builtin *Builtin; |
|
304 typedef struct nameddir *Nameddir; |
|
305 typedef struct module *Module; |
|
306 typedef struct linkedmod *Linkedmod; |
|
307 |
|
308 typedef struct patprog *Patprog; |
|
309 typedef struct process *Process; |
|
310 typedef struct job *Job; |
|
311 typedef struct value *Value; |
|
312 typedef struct conddef *Conddef; |
|
313 typedef struct redir *Redir; |
|
314 typedef struct complist *Complist; |
|
315 typedef struct heap *Heap; |
|
316 typedef struct heapstack *Heapstack; |
|
317 typedef struct histent *Histent; |
|
318 typedef struct hookdef *Hookdef; |
|
319 |
|
320 typedef struct asgment *Asgment; |
|
321 |
|
322 |
|
323 /********************************/ |
|
324 /* Definitions for linked lists */ |
|
325 /********************************/ |
|
326 |
|
327 /* linked list abstract data type */ |
|
328 |
|
329 struct linknode { |
|
330 LinkNode next; |
|
331 LinkNode last; |
|
332 void *dat; |
|
333 }; |
|
334 |
|
335 struct linklist { |
|
336 LinkNode first; |
|
337 LinkNode last; |
|
338 }; |
|
339 |
|
340 /* Macros for manipulating link lists */ |
|
341 |
|
342 #define addlinknode(X,Y) insertlinknode(X,(X)->last,Y) |
|
343 #define zaddlinknode(X,Y) zinsertlinknode(X,(X)->last,Y) |
|
344 #define uaddlinknode(X,Y) uinsertlinknode(X,(X)->last,Y) |
|
345 #define empty(X) ((X)->first == NULL) |
|
346 #define nonempty(X) ((X)->first != NULL) |
|
347 #define firstnode(X) ((X)->first) |
|
348 #define getaddrdata(X) (&((X)->dat)) |
|
349 #define getdata(X) ((X)->dat) |
|
350 #define setdata(X,Y) ((X)->dat = (Y)) |
|
351 #define lastnode(X) ((X)->last) |
|
352 #define nextnode(X) ((X)->next) |
|
353 #define prevnode(X) ((X)->last) |
|
354 #define peekfirst(X) ((X)->first->dat) |
|
355 #define pushnode(X,Y) insertlinknode(X,(LinkNode) X,Y) |
|
356 #define zpushnode(X,Y) zinsertlinknode(X,(LinkNode) X,Y) |
|
357 #define incnode(X) (X = nextnode(X)) |
|
358 #define firsthist() (hist_ring? hist_ring->down->histnum : curhist) |
|
359 #define setsizednode(X,Y,Z) ((X)->first[(Y)].dat = (void *) (Z)) |
|
360 |
|
361 /* stack allocated linked lists */ |
|
362 |
|
363 #define local_list0(N) struct linklist N |
|
364 #define init_list0(N) \ |
|
365 do { \ |
|
366 (N).first = NULL; \ |
|
367 (N).last = (LinkNode) &(N); \ |
|
368 } while (0) |
|
369 #define local_list1(N) struct linklist N; struct linknode __n0 |
|
370 #define init_list1(N,V0) \ |
|
371 do { \ |
|
372 (N).first = &__n0; \ |
|
373 (N).last = &__n0; \ |
|
374 __n0.next = NULL; \ |
|
375 __n0.last = (LinkNode) &(N); \ |
|
376 __n0.dat = (void *) (V0); \ |
|
377 } while (0) |
|
378 |
|
379 /********************************/ |
|
380 /* Definitions for syntax trees */ |
|
381 /********************************/ |
|
382 |
|
383 /* These are control flags that are passed * |
|
384 * down the execution pipeline. */ |
|
385 #define Z_TIMED (1<<0) /* pipeline is being timed */ |
|
386 #define Z_SYNC (1<<1) /* run this sublist synchronously (;) */ |
|
387 #define Z_ASYNC (1<<2) /* run this sublist asynchronously (&) */ |
|
388 #define Z_DISOWN (1<<3) /* run this sublist without job control (&|) */ |
|
389 /* (1<<4) is used for Z_END, see the wordcode definitions */ |
|
390 /* (1<<5) is used for Z_SIMPLE, see the wordcode definitions */ |
|
391 |
|
392 /* Condition types. */ |
|
393 |
|
394 #define COND_NOT 0 |
|
395 #define COND_AND 1 |
|
396 #define COND_OR 2 |
|
397 #define COND_STREQ 3 |
|
398 #define COND_STRNEQ 4 |
|
399 #define COND_STRLT 5 |
|
400 #define COND_STRGTR 6 |
|
401 #define COND_NT 7 |
|
402 #define COND_OT 8 |
|
403 #define COND_EF 9 |
|
404 #define COND_EQ 10 |
|
405 #define COND_NE 11 |
|
406 #define COND_LT 12 |
|
407 #define COND_GT 13 |
|
408 #define COND_LE 14 |
|
409 #define COND_GE 15 |
|
410 #define COND_MOD 16 |
|
411 #define COND_MODI 17 |
|
412 |
|
413 typedef int (*CondHandler) _((char **, int)); |
|
414 |
|
415 struct conddef { |
|
416 Conddef next; /* next in list */ |
|
417 char *name; /* the condition name */ |
|
418 int flags; /* see CONDF_* below */ |
|
419 CondHandler handler; /* handler function */ |
|
420 int min; /* minimum number of strings */ |
|
421 int max; /* maximum number of strings */ |
|
422 int condid; /* for overloading handler functions */ |
|
423 char *module; /* module to autoload */ |
|
424 }; |
|
425 |
|
426 #define CONDF_INFIX 1 |
|
427 #define CONDF_ADDED 2 |
|
428 |
|
429 #define CONDDEF(name, flags, handler, min, max, condid) \ |
|
430 { NULL, name, flags, handler, min, max, condid, NULL } |
|
431 |
|
432 /* tree element for redirection lists */ |
|
433 |
|
434 struct redir { |
|
435 int type; |
|
436 int fd1, fd2; |
|
437 char *name; |
|
438 }; |
|
439 |
|
440 /* The number of fds space is allocated for * |
|
441 * each time a multio must increase in size. */ |
|
442 #define MULTIOUNIT 8 |
|
443 |
|
444 /* A multio is a list of fds associated with a certain fd. * |
|
445 * Thus if you do "foo >bar >ble", the multio for fd 1 will have * |
|
446 * two fds, the result of open("bar",...), and the result of * |
|
447 * open("ble",....). */ |
|
448 |
|
449 /* structure used for multiple i/o redirection */ |
|
450 /* one for each fd open */ |
|
451 |
|
452 struct multio { |
|
453 int ct; /* # of redirections on this fd */ |
|
454 int rflag; /* 0 if open for reading, 1 if open for writing */ |
|
455 int pipe; /* fd of pipe if ct > 1 */ |
|
456 int fds[MULTIOUNIT]; /* list of src/dests redirected to/from this fd */ |
|
457 }; |
|
458 |
|
459 /* structure for foo=bar assignments */ |
|
460 |
|
461 struct asgment { |
|
462 struct asgment *next; |
|
463 char *name; |
|
464 char *value; |
|
465 }; |
|
466 |
|
467 /* lvalue for variable assignment/expansion */ |
|
468 |
|
469 struct value { |
|
470 int isarr; |
|
471 Param pm; /* parameter node */ |
|
472 int inv; /* should we return the index ? */ |
|
473 int start; /* first element of array slice, or -1 */ |
|
474 int end; /* 1-rel last element of array slice, or -1 */ |
|
475 char **arr; /* cache for hash turned into array */ |
|
476 }; |
|
477 |
|
478 #define MAX_ARRLEN 262144 |
|
479 |
|
480 /********************************************/ |
|
481 /* Definitions for word code */ |
|
482 /********************************************/ |
|
483 |
|
484 typedef unsigned int wordcode; |
|
485 typedef wordcode *Wordcode; |
|
486 |
|
487 typedef struct funcdump *FuncDump; |
|
488 typedef struct eprog *Eprog; |
|
489 |
|
490 struct funcdump { |
|
491 FuncDump next; /* next in list */ |
|
492 dev_t dev; /* device */ |
|
493 ino_t ino; /* indoe number */ |
|
494 int fd; /* file descriptor */ |
|
495 Wordcode map; /* pointer to header */ |
|
496 Wordcode addr; /* mapped region */ |
|
497 int len; /* length */ |
|
498 int count; /* reference count */ |
|
499 char *filename; |
|
500 }; |
|
501 |
|
502 /* |
|
503 * A note on the use of reference counts in Eprogs. |
|
504 * |
|
505 * When an Eprog is created, nref is set to -1 if the Eprog is on the |
|
506 * heap; then no attempt is ever made to free it. (This information is |
|
507 * already present in EF_HEAP; we use the redundancy for debugging |
|
508 * checks.) |
|
509 * |
|
510 * Otherwise, nref is initialised to 1. Calling freeprog() decrements |
|
511 * nref and frees the Eprog if the count is now zero. When the Eprog |
|
512 * is in use, we call useeprog() at the start and freeprog() at the |
|
513 * end to increment and decrement the reference counts. If an attempt |
|
514 * is made to free the Eprog from within, this will then take place |
|
515 * when execution is finished, typically in the call to freeeprog() |
|
516 * in execode(). If the Eprog was on the heap, neither useeprog() |
|
517 * nor freeeprog() has any effect. |
|
518 */ |
|
519 struct eprog { |
|
520 int flags; /* EF_* below */ |
|
521 int len; /* total block length */ |
|
522 int npats; /* Patprog cache size */ |
|
523 int nref; /* number of references: delete when zero */ |
|
524 Patprog *pats; /* the memory block, the patterns */ |
|
525 Wordcode prog; /* memory block ctd, the code */ |
|
526 char *strs; /* memory block ctd, the strings */ |
|
527 Shfunc shf; /* shell function for autoload */ |
|
528 FuncDump dump; /* dump file this is in */ |
|
529 }; |
|
530 |
|
531 #define EF_REAL 1 |
|
532 #define EF_HEAP 2 |
|
533 #define EF_MAP 4 |
|
534 #define EF_RUN 8 |
|
535 |
|
536 typedef struct estate *Estate; |
|
537 |
|
538 struct estate { |
|
539 Eprog prog; /* the eprog executed */ |
|
540 Wordcode pc; /* program counter, current pos */ |
|
541 char *strs; /* strings from prog */ |
|
542 }; |
|
543 |
|
544 typedef struct eccstr *Eccstr; |
|
545 |
|
546 struct eccstr { |
|
547 Eccstr left, right; |
|
548 char *str; |
|
549 wordcode offs, aoffs; |
|
550 int nfunc; |
|
551 }; |
|
552 |
|
553 #define EC_NODUP 0 |
|
554 #define EC_DUP 1 |
|
555 #define EC_DUPTOK 2 |
|
556 |
|
557 #define WC_CODEBITS 5 |
|
558 |
|
559 #define wc_code(C) ((C) & ((wordcode) ((1 << WC_CODEBITS) - 1))) |
|
560 #define wc_data(C) ((C) >> WC_CODEBITS) |
|
561 #define wc_bdata(D) ((D) << WC_CODEBITS) |
|
562 #define wc_bld(C,D) (((wordcode) (C)) | (((wordcode) (D)) << WC_CODEBITS)) |
|
563 |
|
564 #define WC_END 0 |
|
565 #define WC_LIST 1 |
|
566 #define WC_SUBLIST 2 |
|
567 #define WC_PIPE 3 |
|
568 #define WC_REDIR 4 |
|
569 #define WC_ASSIGN 5 |
|
570 #define WC_SIMPLE 6 |
|
571 #define WC_SUBSH 7 |
|
572 #define WC_CURSH 8 |
|
573 #define WC_TIMED 9 |
|
574 #define WC_FUNCDEF 10 |
|
575 #define WC_FOR 11 |
|
576 #define WC_SELECT 12 |
|
577 #define WC_WHILE 13 |
|
578 #define WC_REPEAT 14 |
|
579 #define WC_CASE 15 |
|
580 #define WC_IF 16 |
|
581 #define WC_COND 17 |
|
582 #define WC_ARITH 18 |
|
583 #define WC_AUTOFN 19 |
|
584 #define WC_TRY 20 |
|
585 |
|
586 /* increment as necessary */ |
|
587 #define WC_COUNT 21 |
|
588 |
|
589 #define WCB_END() wc_bld(WC_END, 0) |
|
590 |
|
591 #define WC_LIST_TYPE(C) wc_data(C) |
|
592 #define Z_END (1<<4) |
|
593 #define Z_SIMPLE (1<<5) |
|
594 #define WC_LIST_SKIP(C) (wc_data(C) >> 6) |
|
595 #define WCB_LIST(T,O) wc_bld(WC_LIST, ((T) | ((O) << 6))) |
|
596 |
|
597 #define WC_SUBLIST_TYPE(C) (wc_data(C) & ((wordcode) 3)) |
|
598 #define WC_SUBLIST_END 0 |
|
599 #define WC_SUBLIST_AND 1 |
|
600 #define WC_SUBLIST_OR 2 |
|
601 #define WC_SUBLIST_FLAGS(C) (wc_data(C) & ((wordcode) 0x1c)) |
|
602 #define WC_SUBLIST_COPROC 4 |
|
603 #define WC_SUBLIST_NOT 8 |
|
604 #define WC_SUBLIST_SIMPLE 16 |
|
605 #define WC_SUBLIST_SKIP(C) (wc_data(C) >> 5) |
|
606 #define WCB_SUBLIST(T,F,O) wc_bld(WC_SUBLIST, ((T) | (F) | ((O) << 5))) |
|
607 |
|
608 #define WC_PIPE_TYPE(C) (wc_data(C) & ((wordcode) 1)) |
|
609 #define WC_PIPE_END 0 |
|
610 #define WC_PIPE_MID 1 |
|
611 #define WC_PIPE_LINENO(C) (wc_data(C) >> 1) |
|
612 #define WCB_PIPE(T,L) wc_bld(WC_PIPE, ((T) | ((L) << 1))) |
|
613 |
|
614 #define WC_REDIR_TYPE(C) wc_data(C) |
|
615 #define WCB_REDIR(T) wc_bld(WC_REDIR, (T)) |
|
616 |
|
617 #define WC_ASSIGN_TYPE(C) (wc_data(C) & ((wordcode) 1)) |
|
618 #define WC_ASSIGN_TYPE2(C) ((wc_data(C) & ((wordcode) 2)) >> 1) |
|
619 #define WC_ASSIGN_SCALAR 0 |
|
620 #define WC_ASSIGN_ARRAY 1 |
|
621 #define WC_ASSIGN_NEW 0 |
|
622 #define WC_ASSIGN_INC 1 |
|
623 #define WC_ASSIGN_NUM(C) (wc_data(C) >> 2) |
|
624 #define WCB_ASSIGN(T,A,N) wc_bld(WC_ASSIGN, ((T) | ((A) << 1) | ((N) << 2))) |
|
625 |
|
626 #define WC_SIMPLE_ARGC(C) wc_data(C) |
|
627 #define WCB_SIMPLE(N) wc_bld(WC_SIMPLE, (N)) |
|
628 |
|
629 #define WC_SUBSH_SKIP(C) wc_data(C) |
|
630 #define WCB_SUBSH(O) wc_bld(WC_SUBSH, (O)) |
|
631 |
|
632 #define WC_CURSH_SKIP(C) wc_data(C) |
|
633 #define WCB_CURSH(O) wc_bld(WC_CURSH, (O)) |
|
634 |
|
635 #define WC_TIMED_TYPE(C) wc_data(C) |
|
636 #define WC_TIMED_EMPTY 0 |
|
637 #define WC_TIMED_PIPE 1 |
|
638 #define WCB_TIMED(T) wc_bld(WC_TIMED, (T)) |
|
639 |
|
640 #define WC_FUNCDEF_SKIP(C) wc_data(C) |
|
641 #define WCB_FUNCDEF(O) wc_bld(WC_FUNCDEF, (O)) |
|
642 |
|
643 #define WC_FOR_TYPE(C) (wc_data(C) & 3) |
|
644 #define WC_FOR_PPARAM 0 |
|
645 #define WC_FOR_LIST 1 |
|
646 #define WC_FOR_COND 2 |
|
647 #define WC_FOR_SKIP(C) (wc_data(C) >> 2) |
|
648 #define WCB_FOR(T,O) wc_bld(WC_FOR, ((T) | ((O) << 2))) |
|
649 |
|
650 #define WC_SELECT_TYPE(C) (wc_data(C) & 1) |
|
651 #define WC_SELECT_PPARAM 0 |
|
652 #define WC_SELECT_LIST 1 |
|
653 #define WC_SELECT_SKIP(C) (wc_data(C) >> 1) |
|
654 #define WCB_SELECT(T,O) wc_bld(WC_SELECT, ((T) | ((O) << 1))) |
|
655 |
|
656 #define WC_WHILE_TYPE(C) (wc_data(C) & 1) |
|
657 #define WC_WHILE_WHILE 0 |
|
658 #define WC_WHILE_UNTIL 1 |
|
659 #define WC_WHILE_SKIP(C) (wc_data(C) >> 1) |
|
660 #define WCB_WHILE(T,O) wc_bld(WC_WHILE, ((T) | ((O) << 1))) |
|
661 |
|
662 #define WC_REPEAT_SKIP(C) wc_data(C) |
|
663 #define WCB_REPEAT(O) wc_bld(WC_REPEAT, (O)) |
|
664 |
|
665 #define WC_TRY_SKIP(C) wc_data(C) |
|
666 #define WCB_TRY(O) wc_bld(WC_TRY, (O)) |
|
667 |
|
668 #define WC_CASE_TYPE(C) (wc_data(C) & 3) |
|
669 #define WC_CASE_HEAD 0 |
|
670 #define WC_CASE_OR 1 |
|
671 #define WC_CASE_AND 2 |
|
672 #define WC_CASE_SKIP(C) (wc_data(C) >> 2) |
|
673 #define WCB_CASE(T,O) wc_bld(WC_CASE, ((T) | ((O) << 2))) |
|
674 |
|
675 #define WC_IF_TYPE(C) (wc_data(C) & 3) |
|
676 #define WC_IF_HEAD 0 |
|
677 #define WC_IF_IF 1 |
|
678 #define WC_IF_ELIF 2 |
|
679 #define WC_IF_ELSE 3 |
|
680 #define WC_IF_SKIP(C) (wc_data(C) >> 2) |
|
681 #define WCB_IF(T,O) wc_bld(WC_IF, ((T) | ((O) << 2))) |
|
682 |
|
683 #define WC_COND_TYPE(C) (wc_data(C) & 127) |
|
684 #define WC_COND_SKIP(C) (wc_data(C) >> 7) |
|
685 #define WCB_COND(T,O) wc_bld(WC_COND, ((T) | ((O) << 7))) |
|
686 |
|
687 #define WCB_ARITH() wc_bld(WC_ARITH, 0) |
|
688 |
|
689 #define WCB_AUTOFN() wc_bld(WC_AUTOFN, 0) |
|
690 |
|
691 /********************************************/ |
|
692 /* Definitions for job table and job control */ |
|
693 /********************************************/ |
|
694 |
|
695 /* entry in the job table */ |
|
696 |
|
697 struct job { |
|
698 pid_t gleader; /* process group leader of this job */ |
|
699 pid_t other; /* subjob id or subshell pid */ |
|
700 int stat; /* see STATs below */ |
|
701 char *pwd; /* current working dir of shell when * |
|
702 * this job was spawned */ |
|
703 struct process *procs; /* list of processes */ |
|
704 struct process *auxprocs; /* auxiliary processes e.g multios */ |
|
705 LinkList filelist; /* list of files to delete when done */ |
|
706 int stty_in_env; /* if STTY=... is present */ |
|
707 struct ttyinfo *ty; /* the modes specified by STTY */ |
|
708 }; |
|
709 |
|
710 #define STAT_CHANGED (1<<0) /* status changed and not reported */ |
|
711 #define STAT_STOPPED (1<<1) /* all procs stopped or exited */ |
|
712 #define STAT_TIMED (1<<2) /* job is being timed */ |
|
713 #define STAT_DONE (1<<3) /* job is done */ |
|
714 #define STAT_LOCKED (1<<4) /* shell is finished creating this job, */ |
|
715 /* may be deleted from job table */ |
|
716 #define STAT_NOPRINT (1<<5) /* job was killed internally, */ |
|
717 /* we don't want to show that */ |
|
718 #define STAT_INUSE (1<<6) /* this job entry is in use */ |
|
719 #define STAT_SUPERJOB (1<<7) /* job has a subjob */ |
|
720 #define STAT_SUBJOB (1<<8) /* job is a subjob */ |
|
721 #define STAT_WASSUPER (1<<9) /* was a super-job, sub-job needs to be */ |
|
722 /* deleted */ |
|
723 #define STAT_CURSH (1<<10) /* last command is in current shell */ |
|
724 #define STAT_NOSTTY (1<<11) /* the tty settings are not inherited */ |
|
725 /* from this job when it exits. */ |
|
726 #define STAT_ATTACH (1<<12) /* delay reattaching shell to tty */ |
|
727 #define STAT_SUBLEADER (1<<13) /* is super-job, but leader is sub-shell */ |
|
728 |
|
729 #define SP_RUNNING -1 /* fake status for jobs currently running */ |
|
730 |
|
731 struct timeinfo { |
|
732 long ut; /* user space time */ |
|
733 long st; /* system space time */ |
|
734 }; |
|
735 |
|
736 #define JOBTEXTSIZE 80 |
|
737 |
|
738 /* Size to initialise the job table to, and to increment it by when needed. */ |
|
739 #define MAXJOBS_ALLOC (50) |
|
740 |
|
741 /* node in job process lists */ |
|
742 |
|
743 #ifdef HAVE_GETRUSAGE |
|
744 typedef struct rusage child_times_t; |
|
745 #else |
|
746 typedef struct timeinfo child_times_t; |
|
747 #endif |
|
748 |
|
749 struct process { |
|
750 struct process *next; |
|
751 pid_t pid; /* process id */ |
|
752 char text[JOBTEXTSIZE]; /* text to print when 'jobs' is run */ |
|
753 int status; /* return code from waitpid/wait3() */ |
|
754 child_times_t ti; |
|
755 struct timeval bgtime; /* time job was spawned */ |
|
756 struct timeval endtime; /* time job exited */ |
|
757 }; |
|
758 |
|
759 struct execstack { |
|
760 struct execstack *next; |
|
761 |
|
762 LinkList args; |
|
763 pid_t list_pipe_pid; |
|
764 int nowait; |
|
765 int pline_level; |
|
766 int list_pipe_child; |
|
767 int list_pipe_job; |
|
768 char list_pipe_text[JOBTEXTSIZE]; |
|
769 int lastval; |
|
770 int noeval; |
|
771 int badcshglob; |
|
772 pid_t cmdoutpid; |
|
773 int cmdoutval; |
|
774 int trapreturn; |
|
775 int noerrs; |
|
776 int subsh_close; |
|
777 char *underscore; |
|
778 }; |
|
779 |
|
780 struct heredocs { |
|
781 struct heredocs *next; |
|
782 int type; |
|
783 int pc; |
|
784 char *str; |
|
785 }; |
|
786 |
|
787 struct dirsav { |
|
788 int dirfd, level; |
|
789 char *dirname; |
|
790 dev_t dev; |
|
791 ino_t ino; |
|
792 }; |
|
793 |
|
794 #define MAX_PIPESTATS 256 |
|
795 |
|
796 /*******************************/ |
|
797 /* Definitions for Hash Tables */ |
|
798 /*******************************/ |
|
799 |
|
800 typedef void *(*VFunc) _((void *)); |
|
801 typedef void (*FreeFunc) _((void *)); |
|
802 |
|
803 typedef unsigned (*HashFunc) _((char *)); |
|
804 typedef void (*TableFunc) _((HashTable)); |
|
805 typedef void (*AddNodeFunc) _((HashTable, char *, void *)); |
|
806 typedef HashNode (*GetNodeFunc) _((HashTable, char *)); |
|
807 typedef HashNode (*RemoveNodeFunc) _((HashTable, char *)); |
|
808 typedef void (*FreeNodeFunc) _((HashNode)); |
|
809 typedef int (*CompareFunc) _((const char *, const char *)); |
|
810 |
|
811 /* type of function that is passed to * |
|
812 * scanhashtable or scanmatchtable */ |
|
813 typedef void (*ScanFunc) _((HashNode, int)); |
|
814 typedef void (*ScanTabFunc) _((HashTable, ScanFunc, int)); |
|
815 |
|
816 typedef void (*PrintTableStats) _((HashTable)); |
|
817 |
|
818 /* hash table for standard open hashing */ |
|
819 |
|
820 struct hashtable { |
|
821 /* HASHTABLE DATA */ |
|
822 int hsize; /* size of nodes[] (number of hash values) */ |
|
823 int ct; /* number of elements */ |
|
824 HashNode *nodes; /* array of size hsize */ |
|
825 |
|
826 /* HASHTABLE METHODS */ |
|
827 HashFunc hash; /* pointer to hash function for this table */ |
|
828 TableFunc emptytable; /* pointer to function to empty table */ |
|
829 TableFunc filltable; /* pointer to function to fill table */ |
|
830 CompareFunc cmpnodes; /* pointer to function to compare two nodes */ |
|
831 AddNodeFunc addnode; /* pointer to function to add new node */ |
|
832 GetNodeFunc getnode; /* pointer to function to get an enabled node */ |
|
833 GetNodeFunc getnode2; /* pointer to function to get node */ |
|
834 /* (getnode2 will ignore DISABLED flag) */ |
|
835 RemoveNodeFunc removenode; /* pointer to function to delete a node */ |
|
836 ScanFunc disablenode; /* pointer to function to disable a node */ |
|
837 ScanFunc enablenode; /* pointer to function to enable a node */ |
|
838 FreeNodeFunc freenode; /* pointer to function to free a node */ |
|
839 ScanFunc printnode; /* pointer to function to print a node */ |
|
840 ScanTabFunc scantab; /* pointer to function to scan table */ |
|
841 |
|
842 #ifdef HASHTABLE_INTERNAL_MEMBERS |
|
843 HASHTABLE_INTERNAL_MEMBERS /* internal use in hashtable.c */ |
|
844 #endif |
|
845 }; |
|
846 |
|
847 /* generic hash table node */ |
|
848 |
|
849 struct hashnode { |
|
850 HashNode next; /* next in hash chain */ |
|
851 char *nam; /* hash key */ |
|
852 int flags; /* various flags */ |
|
853 }; |
|
854 |
|
855 /* The flag to disable nodes in a hash table. Currently * |
|
856 * you can disable builtins, shell functions, aliases and * |
|
857 * reserved words. */ |
|
858 #define DISABLED (1<<0) |
|
859 |
|
860 /* node in shell option table */ |
|
861 |
|
862 struct optname { |
|
863 HashNode next; /* next in hash chain */ |
|
864 char *nam; /* hash data */ |
|
865 int flags; |
|
866 int optno; /* option number */ |
|
867 }; |
|
868 |
|
869 /* node in shell reserved word hash table (reswdtab) */ |
|
870 |
|
871 struct reswd { |
|
872 HashNode next; /* next in hash chain */ |
|
873 char *nam; /* name of reserved word */ |
|
874 int flags; /* flags */ |
|
875 int token; /* corresponding lexer token */ |
|
876 }; |
|
877 |
|
878 /* node in alias hash table (aliastab) */ |
|
879 |
|
880 struct alias { |
|
881 HashNode next; /* next in hash chain */ |
|
882 char *nam; /* hash data */ |
|
883 int flags; /* flags for alias types */ |
|
884 char *text; /* expansion of alias */ |
|
885 int inuse; /* alias is being expanded */ |
|
886 }; |
|
887 |
|
888 /* bit 0 of flags is the DISABLED flag */ |
|
889 /* is this alias global? */ |
|
890 #define ALIAS_GLOBAL (1<<1) |
|
891 /* is this an alias for suffix handling? */ |
|
892 #define ALIAS_SUFFIX (1<<2) |
|
893 |
|
894 /* node in command path hash table (cmdnamtab) */ |
|
895 |
|
896 struct cmdnam { |
|
897 HashNode next; /* next in hash chain */ |
|
898 char *nam; /* hash data */ |
|
899 int flags; |
|
900 union { |
|
901 char **name; /* full pathname for external commands */ |
|
902 char *cmd; /* file name for hashed commands */ |
|
903 } |
|
904 u; |
|
905 }; |
|
906 |
|
907 /* flag for nodes explicitly added to * |
|
908 * cmdnamtab with hash builtin */ |
|
909 #define HASHED (1<<1) |
|
910 |
|
911 /* node in shell function hash table (shfunctab) */ |
|
912 |
|
913 struct shfunc { |
|
914 HashNode next; /* next in hash chain */ |
|
915 char *nam; /* name of shell function */ |
|
916 int flags; /* various flags */ |
|
917 Eprog funcdef; /* function definition */ |
|
918 }; |
|
919 |
|
920 /* Shell function context types. */ |
|
921 |
|
922 #define SFC_NONE 0 /* no function running */ |
|
923 #define SFC_DIRECT 1 /* called directly from the user */ |
|
924 #define SFC_SIGNAL 2 /* signal handler */ |
|
925 #define SFC_HOOK 3 /* one of the special functions */ |
|
926 #define SFC_WIDGET 4 /* user defined widget */ |
|
927 #define SFC_COMPLETE 5 /* called from completion code */ |
|
928 #define SFC_CWIDGET 6 /* new style completion widget */ |
|
929 |
|
930 /* node in function stack */ |
|
931 |
|
932 struct funcstack { |
|
933 Funcstack prev; /* previous in stack */ |
|
934 char *name; /* name of function called */ |
|
935 }; |
|
936 |
|
937 /* node in list of function call wrappers */ |
|
938 |
|
939 typedef int (*WrapFunc) _((Eprog, FuncWrap, char *)); |
|
940 |
|
941 struct funcwrap { |
|
942 FuncWrap next; |
|
943 int flags; |
|
944 WrapFunc handler; |
|
945 Module module; |
|
946 }; |
|
947 |
|
948 #define WRAPF_ADDED 1 |
|
949 |
|
950 #define WRAPDEF(func) \ |
|
951 { NULL, 0, func, NULL } |
|
952 |
|
953 /* node in builtin command hash table (builtintab) */ |
|
954 |
|
955 /* |
|
956 * Handling of options. |
|
957 * |
|
958 * Option strings are standard in that a trailing `:' indicates |
|
959 * a mandatory argument. In addition, `::' indicates an optional |
|
960 * argument which must immediately follow the option letter if it is present. |
|
961 * `:%' indicates an optional numeric argument which may follow |
|
962 * the option letter or be in the next word; the only test is |
|
963 * that the next character is a digit, and no actual conversion is done. |
|
964 */ |
|
965 |
|
966 #define MAX_OPS 128 |
|
967 |
|
968 /* Macros taking struct option * and char argument */ |
|
969 /* Option was set as -X */ |
|
970 #define OPT_MINUS(ops,c) ((ops)->ind[c] & 1) |
|
971 /* Option was set as +X */ |
|
972 #define OPT_PLUS(ops,c) ((ops)->ind[c] & 2) |
|
973 /* |
|
974 * Option was set any old how, maybe including an argument |
|
975 * (cheap test when we don't care). Some bits of code |
|
976 * expect this to be 1 or 0. |
|
977 */ |
|
978 #define OPT_ISSET(ops,c) ((ops)->ind[c] != 0) |
|
979 /* Option has an argument */ |
|
980 #define OPT_HASARG(ops,c) ((ops)->ind[c] > 3) |
|
981 /* The argument for the option; not safe if it doesn't have one */ |
|
982 #define OPT_ARG(ops,c) ((ops)->args[((ops)->ind[c] >> 2) - 1]) |
|
983 /* Ditto, but safely returns NULL if there is no argument. */ |
|
984 #define OPT_ARG_SAFE(ops,c) (OPT_HASARG(ops,c) ? OPT_ARG(ops,c) : NULL) |
|
985 |
|
986 struct options { |
|
987 unsigned char ind[MAX_OPS]; |
|
988 char **args; |
|
989 int argscount, argsalloc; |
|
990 }; |
|
991 |
|
992 /* |
|
993 * Handler arguments are: builtin name, null-terminated argument |
|
994 * list excluding command name, option structure, the funcid element from the |
|
995 * builtin structure. |
|
996 */ |
|
997 |
|
998 typedef int (*HandlerFunc) _((char *, char **, Options, int)); |
|
999 #define NULLBINCMD ((HandlerFunc) 0) |
|
1000 |
|
1001 struct builtin { |
|
1002 HashNode next; /* next in hash chain */ |
|
1003 char *nam; /* name of builtin */ |
|
1004 int flags; /* various flags */ |
|
1005 HandlerFunc handlerfunc; /* pointer to function that executes this builtin */ |
|
1006 int minargs; /* minimum number of arguments */ |
|
1007 int maxargs; /* maximum number of arguments, or -1 for no limit */ |
|
1008 int funcid; /* xbins (see above) for overloaded handlerfuncs */ |
|
1009 char *optstr; /* string of legal options */ |
|
1010 char *defopts; /* options set by default for overloaded handlerfuncs */ |
|
1011 }; |
|
1012 |
|
1013 #define BUILTIN(name, flags, handler, min, max, funcid, optstr, defopts) \ |
|
1014 { NULL, name, flags, handler, min, max, funcid, optstr, defopts } |
|
1015 #define BIN_PREFIX(name, flags) \ |
|
1016 BUILTIN(name, flags | BINF_PREFIX, NULLBINCMD, 0, 0, 0, NULL, NULL) |
|
1017 |
|
1018 /* builtin flags */ |
|
1019 /* DISABLE IS DEFINED AS (1<<0) */ |
|
1020 #define BINF_PLUSOPTS (1<<1) /* +xyz legal */ |
|
1021 #define BINF_PRINTOPTS (1<<2) |
|
1022 #define BINF_ADDED (1<<3) /* is in the builtins hash table */ |
|
1023 #define BINF_MAGICEQUALS (1<<4) /* needs automatic MAGIC_EQUAL_SUBST substitution */ |
|
1024 #define BINF_PREFIX (1<<5) |
|
1025 #define BINF_DASH (1<<6) |
|
1026 #define BINF_BUILTIN (1<<7) |
|
1027 #define BINF_COMMAND (1<<8) |
|
1028 #define BINF_EXEC (1<<9) |
|
1029 #define BINF_NOGLOB (1<<10) |
|
1030 #define BINF_PSPECIAL (1<<11) |
|
1031 /* Builtin option handling */ |
|
1032 #define BINF_SKIPINVALID (1<<12) /* Treat invalid option as argument */ |
|
1033 #define BINF_KEEPNUM (1<<13) /* `[-+]NUM' can be an option */ |
|
1034 #define BINF_SKIPDASH (1<<14) /* Treat `-' as argument (maybe `+') */ |
|
1035 #define BINF_DASHDASHVALID (1<<15) /* Handle `--' even if SKIPINVALD */ |
|
1036 |
|
1037 enum { BIN_CHOWN, BIN_CHGRP }; |
|
1038 |
|
1039 struct module { |
|
1040 char *nam; |
|
1041 int flags; |
|
1042 union { |
|
1043 void *handle; |
|
1044 Linkedmod linked; |
|
1045 char *alias; |
|
1046 } u; |
|
1047 LinkList deps; |
|
1048 int wrapper; |
|
1049 }; |
|
1050 |
|
1051 #define MOD_BUSY (1<<0) |
|
1052 #define MOD_UNLOAD (1<<1) |
|
1053 #define MOD_SETUP (1<<2) |
|
1054 #define MOD_LINKED (1<<3) |
|
1055 #define MOD_INIT_S (1<<4) |
|
1056 #define MOD_INIT_B (1<<5) |
|
1057 #define MOD_ALIAS (1<<6) |
|
1058 |
|
1059 typedef int (*Module_func) _((Module)); |
|
1060 |
|
1061 struct linkedmod { |
|
1062 char *name; |
|
1063 Module_func setup; |
|
1064 Module_func boot; |
|
1065 Module_func cleanup; |
|
1066 Module_func finish; |
|
1067 }; |
|
1068 |
|
1069 /* C-function hooks */ |
|
1070 |
|
1071 typedef int (*Hookfn) _((Hookdef, void *)); |
|
1072 |
|
1073 struct hookdef { |
|
1074 Hookdef next; |
|
1075 char *name; |
|
1076 Hookfn def; |
|
1077 int flags; |
|
1078 LinkList funcs; |
|
1079 }; |
|
1080 |
|
1081 #define HOOKF_ALL 1 |
|
1082 |
|
1083 #define HOOKDEF(name, func, flags) { NULL, name, (Hookfn) func, flags, NULL } |
|
1084 |
|
1085 /* |
|
1086 * Types used in pattern matching. Most of these longs could probably |
|
1087 * happily be ints. |
|
1088 */ |
|
1089 |
|
1090 struct patprog { |
|
1091 long startoff; /* length before start of programme */ |
|
1092 long size; /* total size from start of struct */ |
|
1093 long mustoff; /* offset to string that must be present */ |
|
1094 long patmlen; /* length of pure string or longest match */ |
|
1095 int globflags; /* globbing flags to set at start */ |
|
1096 int globend; /* globbing flags set after finish */ |
|
1097 int flags; /* PAT_* flags */ |
|
1098 int patnpar; /* number of active parentheses */ |
|
1099 char patstartch; |
|
1100 }; |
|
1101 |
|
1102 /* Flags used in pattern matchers (Patprog) and passed down to patcompile */ |
|
1103 |
|
1104 #define PAT_FILE 0x0001 /* Pattern is a file name */ |
|
1105 #define PAT_FILET 0x0002 /* Pattern is top level file, affects ~ */ |
|
1106 #define PAT_ANY 0x0004 /* Match anything (cheap "*") */ |
|
1107 #define PAT_NOANCH 0x0008 /* Not anchored at end */ |
|
1108 #define PAT_NOGLD 0x0010 /* Don't glob dots */ |
|
1109 #define PAT_PURES 0x0020 /* Pattern is a pure string: set internally */ |
|
1110 #define PAT_STATIC 0x0040 /* Don't copy pattern to heap as per default */ |
|
1111 #define PAT_SCAN 0x0080 /* Scanning, so don't try must-match test */ |
|
1112 #define PAT_ZDUP 0x0100 /* Copy pattern in real memory */ |
|
1113 #define PAT_NOTSTART 0x0200 /* Start of string is not real start */ |
|
1114 #define PAT_NOTEND 0x0400 /* End of string is not real end */ |
|
1115 #define PAT_HAS_EXCLUDP 0x0800 /* (internal): top-level path1~path2. */ |
|
1116 |
|
1117 /* Globbing flags: lower 8 bits gives approx count */ |
|
1118 #define GF_LCMATCHUC 0x0100 |
|
1119 #define GF_IGNCASE 0x0200 |
|
1120 #define GF_BACKREF 0x0400 |
|
1121 #define GF_MATCHREF 0x0800 |
|
1122 |
|
1123 /* Dummy Patprog pointers. Used mainly in executable code, but the |
|
1124 * pattern code needs to know about it, too. */ |
|
1125 |
|
1126 #define dummy_patprog1 ((Patprog) 1) |
|
1127 #define dummy_patprog2 ((Patprog) 2) |
|
1128 |
|
1129 /* standard node types for get/set/unset union in parameter */ |
|
1130 |
|
1131 /* |
|
1132 * note non-standard const in pointer declaration: structures are |
|
1133 * assumed to be read-only. |
|
1134 */ |
|
1135 typedef const struct gsu_scalar *GsuScalar; |
|
1136 typedef const struct gsu_integer *GsuInteger; |
|
1137 typedef const struct gsu_float *GsuFloat; |
|
1138 typedef const struct gsu_array *GsuArray; |
|
1139 typedef const struct gsu_hash *GsuHash; |
|
1140 |
|
1141 struct gsu_scalar { |
|
1142 char *(*getfn) _((Param)); |
|
1143 void (*setfn) _((Param, char *)); |
|
1144 void (*unsetfn) _((Param, int)); |
|
1145 }; |
|
1146 |
|
1147 struct gsu_integer { |
|
1148 zlong (*getfn) _((Param)); |
|
1149 void (*setfn) _((Param, zlong)); |
|
1150 void (*unsetfn) _((Param, int)); |
|
1151 }; |
|
1152 |
|
1153 struct gsu_float { |
|
1154 double (*getfn) _((Param)); |
|
1155 void (*setfn) _((Param, double)); |
|
1156 void (*unsetfn) _((Param, int)); |
|
1157 }; |
|
1158 |
|
1159 struct gsu_array { |
|
1160 char **(*getfn) _((Param)); |
|
1161 void (*setfn) _((Param, char **)); |
|
1162 void (*unsetfn) _((Param, int)); |
|
1163 }; |
|
1164 |
|
1165 struct gsu_hash { |
|
1166 HashTable (*getfn) _((Param)); |
|
1167 void (*setfn) _((Param, HashTable)); |
|
1168 void (*unsetfn) _((Param, int)); |
|
1169 }; |
|
1170 |
|
1171 |
|
1172 /* node used in parameter hash table (paramtab) */ |
|
1173 |
|
1174 struct param { |
|
1175 HashNode next; /* next in hash chain */ |
|
1176 char *nam; /* hash data */ |
|
1177 int flags; /* PM_* flags */ |
|
1178 |
|
1179 /* the value of this parameter */ |
|
1180 union { |
|
1181 void *data; /* used by special parameter functions */ |
|
1182 char **arr; /* value if declared array (PM_ARRAY) */ |
|
1183 char *str; /* value if declared string (PM_SCALAR) */ |
|
1184 zlong val; /* value if declared integer (PM_INTEGER) */ |
|
1185 zlong *valptr; /* value if special pointer to integer */ |
|
1186 double dval; /* value if declared float |
|
1187 (PM_EFLOAT|PM_FFLOAT) */ |
|
1188 HashTable hash; /* value if declared assoc (PM_HASHED) */ |
|
1189 } u; |
|
1190 |
|
1191 /* |
|
1192 * get/set/unset methods. |
|
1193 * |
|
1194 * Unlike the data union, this points to a single instance |
|
1195 * for every type (although there are special types, e.g. |
|
1196 * tied arrays have a different gsu_scalar struct from the |
|
1197 * normal one). It's really a poor man's vtable. |
|
1198 */ |
|
1199 union { |
|
1200 GsuScalar s; |
|
1201 GsuInteger i; |
|
1202 GsuFloat f; |
|
1203 GsuArray a; |
|
1204 GsuHash h; |
|
1205 } gsu; |
|
1206 |
|
1207 int base; /* output base or floating point prec */ |
|
1208 int width; /* field width */ |
|
1209 char *env; /* location in environment, if exported */ |
|
1210 char *ename; /* name of corresponding environment var */ |
|
1211 Param old; /* old struct for use with local */ |
|
1212 int level; /* if (old != NULL), level of localness */ |
|
1213 }; |
|
1214 |
|
1215 /* structure stored in struct param's u.data by tied arrays */ |
|
1216 struct tieddata { |
|
1217 char ***arrptr; /* pointer to corresponding array */ |
|
1218 int joinchar; /* character used to join arrays */ |
|
1219 }; |
|
1220 |
|
1221 /* flags for parameters */ |
|
1222 |
|
1223 /* parameter types */ |
|
1224 #define PM_SCALAR 0 /* scalar */ |
|
1225 #define PM_ARRAY (1<<0) /* array */ |
|
1226 #define PM_INTEGER (1<<1) /* integer */ |
|
1227 #define PM_EFLOAT (1<<2) /* double with %e output */ |
|
1228 #define PM_FFLOAT (1<<3) /* double with %f output */ |
|
1229 #define PM_HASHED (1<<4) /* association */ |
|
1230 |
|
1231 #define PM_TYPE(X) \ |
|
1232 (X & (PM_SCALAR|PM_INTEGER|PM_EFLOAT|PM_FFLOAT|PM_ARRAY|PM_HASHED)) |
|
1233 |
|
1234 #define PM_LEFT (1<<5) /* left justify, remove leading blanks */ |
|
1235 #define PM_RIGHT_B (1<<6) /* right justify, fill with leading blanks */ |
|
1236 #define PM_RIGHT_Z (1<<7) /* right justify, fill with leading zeros */ |
|
1237 #define PM_LOWER (1<<8) /* all lower case */ |
|
1238 |
|
1239 /* The following are the same since they * |
|
1240 * both represent -u option to typeset */ |
|
1241 #define PM_UPPER (1<<9) /* all upper case */ |
|
1242 #define PM_UNDEFINED (1<<9) /* undefined (autoloaded) shell function */ |
|
1243 |
|
1244 #define PM_READONLY (1<<10) /* readonly */ |
|
1245 #define PM_TAGGED (1<<11) /* tagged */ |
|
1246 #define PM_EXPORTED (1<<12) /* exported */ |
|
1247 |
|
1248 /* The following are the same since they * |
|
1249 * both represent -U option to typeset */ |
|
1250 #define PM_UNIQUE (1<<13) /* remove duplicates */ |
|
1251 #define PM_UNALIASED (1<<13) /* do not expand aliases when autoloading */ |
|
1252 |
|
1253 #define PM_HIDE (1<<14) /* Special behaviour hidden by local */ |
|
1254 #define PM_HIDEVAL (1<<15) /* Value not shown in `typeset' commands */ |
|
1255 #define PM_TIED (1<<16) /* array tied to colon-path or v.v. */ |
|
1256 |
|
1257 #define PM_KSHSTORED (1<<17) /* function stored in ksh form */ |
|
1258 #define PM_ZSHSTORED (1<<18) /* function stored in zsh form */ |
|
1259 |
|
1260 /* Remaining flags do not correspond directly to command line arguments */ |
|
1261 #define PM_LOCAL (1<<21) /* this parameter will be made local */ |
|
1262 #define PM_SPECIAL (1<<22) /* special builtin parameter */ |
|
1263 #define PM_DONTIMPORT (1<<23) /* do not import this variable */ |
|
1264 #define PM_RESTRICTED (1<<24) /* cannot be changed in restricted mode */ |
|
1265 #define PM_UNSET (1<<25) /* has null value */ |
|
1266 #define PM_REMOVABLE (1<<26) /* special can be removed from paramtab */ |
|
1267 #define PM_AUTOLOAD (1<<27) /* autoloaded from module */ |
|
1268 #define PM_NORESTORE (1<<28) /* do not restore value of local special */ |
|
1269 #define PM_HASHELEM (1<<29) /* is a hash-element */ |
|
1270 #define PM_NAMEDDIR (1<<30) /* has a corresponding nameddirtab entry */ |
|
1271 |
|
1272 /* The option string corresponds to the first of the variables above */ |
|
1273 #define TYPESET_OPTSTR "aiEFALRZlurtxUhHTkz" |
|
1274 |
|
1275 /* These typeset options take an optional numeric argument */ |
|
1276 #define TYPESET_OPTNUM "LRZiEF" |
|
1277 |
|
1278 /* Flags for extracting elements of arrays and associative arrays */ |
|
1279 #define SCANPM_WANTVALS (1<<0) |
|
1280 #define SCANPM_WANTKEYS (1<<1) |
|
1281 #define SCANPM_WANTINDEX (1<<2) |
|
1282 #define SCANPM_MATCHKEY (1<<3) |
|
1283 #define SCANPM_MATCHVAL (1<<4) |
|
1284 #define SCANPM_MATCHMANY (1<<5) |
|
1285 #define SCANPM_ASSIGNING (1<<6) |
|
1286 #define SCANPM_KEYMATCH (1<<7) |
|
1287 #define SCANPM_DQUOTED (1<<8) |
|
1288 #define SCANPM_ISVAR_AT ((-1)<<15) /* Only sign bit is significant */ |
|
1289 |
|
1290 /* |
|
1291 * Flags for doing matches inside parameter substitutions, i.e. |
|
1292 * ${...#...} and friends. This could be an enum, but so |
|
1293 * could a lot of other things. |
|
1294 */ |
|
1295 |
|
1296 #define SUB_END 0x0001 /* match end instead of beginning, % or %% */ |
|
1297 #define SUB_LONG 0x0002 /* % or # doubled, get longest match */ |
|
1298 #define SUB_SUBSTR 0x0004 /* match a substring */ |
|
1299 #define SUB_MATCH 0x0008 /* include the matched portion */ |
|
1300 #define SUB_REST 0x0010 /* include the unmatched portion */ |
|
1301 #define SUB_BIND 0x0020 /* index of beginning of string */ |
|
1302 #define SUB_EIND 0x0040 /* index of end of string */ |
|
1303 #define SUB_LEN 0x0080 /* length of match */ |
|
1304 #define SUB_ALL 0x0100 /* match complete string */ |
|
1305 #define SUB_GLOBAL 0x0200 /* global substitution ${..//all/these} */ |
|
1306 #define SUB_DOSUBST 0x0400 /* replacement string needs substituting */ |
|
1307 |
|
1308 /* Flags as the second argument to prefork */ |
|
1309 #define PF_TYPESET 0x01 /* argument handled like typeset foo=bar */ |
|
1310 #define PF_ASSIGN 0x02 /* argument handled like the RHS of foo=bar */ |
|
1311 #define PF_SINGLE 0x04 /* single word substitution */ |
|
1312 |
|
1313 struct paramdef { |
|
1314 char *name; |
|
1315 int flags; |
|
1316 void *var; |
|
1317 void *gsu; /* get/set/unset structure */ |
|
1318 }; |
|
1319 |
|
1320 #define PARAMDEF(name, flags, var, gsu) \ |
|
1321 { name, flags, (void *) var, (void *) gsu, } |
|
1322 /* |
|
1323 * Note that the following definitions are appropriate for defining |
|
1324 * parameters that reference a variable (var). Hence the get/set/unset |
|
1325 * methods used will assume var needs dereferencing to get the value. |
|
1326 */ |
|
1327 #define INTPARAMDEF(name, var) \ |
|
1328 { name, PM_INTEGER, (void *) var, NULL } |
|
1329 #define STRPARAMDEF(name, var) \ |
|
1330 { name, PM_SCALAR, (void *) var, NULL } |
|
1331 #define ARRPARAMDEF(name, var) \ |
|
1332 { name, PM_ARRAY, (void *) var, NULL } |
|
1333 |
|
1334 #define setsparam(S,V) assignsparam(S,V,0) |
|
1335 #define setaparam(S,V) assignaparam(S,V,0) |
|
1336 |
|
1337 /* node for named directory hash table (nameddirtab) */ |
|
1338 |
|
1339 struct nameddir { |
|
1340 HashNode next; /* next in hash chain */ |
|
1341 char *nam; /* directory name */ |
|
1342 int flags; /* see below */ |
|
1343 char *dir; /* the directory in full */ |
|
1344 int diff; /* strlen(.dir) - strlen(.nam) */ |
|
1345 }; |
|
1346 |
|
1347 /* flags for named directories */ |
|
1348 /* DISABLED is defined (1<<0) */ |
|
1349 #define ND_USERNAME (1<<1) /* nam is actually a username */ |
|
1350 #define ND_NOABBREV (1<<2) /* never print as abbrev (PWD or OLDPWD) */ |
|
1351 |
|
1352 |
|
1353 /* flags for controlling printing of hash table nodes */ |
|
1354 #define PRINT_NAMEONLY (1<<0) |
|
1355 #define PRINT_TYPE (1<<1) |
|
1356 #define PRINT_LIST (1<<2) |
|
1357 #define PRINT_KV_PAIR (1<<3) |
|
1358 #define PRINT_INCLUDEVALUE (1<<4) |
|
1359 #define PRINT_TYPESET (1<<5) |
|
1360 |
|
1361 /* flags for printing for the whence builtin */ |
|
1362 #define PRINT_WHENCE_CSH (1<<5) |
|
1363 #define PRINT_WHENCE_VERBOSE (1<<6) |
|
1364 #define PRINT_WHENCE_SIMPLE (1<<7) |
|
1365 #define PRINT_WHENCE_FUNCDEF (1<<9) |
|
1366 #define PRINT_WHENCE_WORD (1<<10) |
|
1367 |
|
1368 /***********************************/ |
|
1369 /* Definitions for history control */ |
|
1370 /***********************************/ |
|
1371 |
|
1372 /* history entry */ |
|
1373 |
|
1374 struct histent { |
|
1375 HashNode hash_next; /* next in hash chain */ |
|
1376 char *text; /* the history line itself */ |
|
1377 int flags; /* Misc flags */ |
|
1378 |
|
1379 Histent up; /* previous line (moving upward) */ |
|
1380 Histent down; /* next line (moving downward) */ |
|
1381 char *zle_text; /* the edited history line */ |
|
1382 time_t stim; /* command started time (datestamp) */ |
|
1383 time_t ftim; /* command finished time */ |
|
1384 short *words; /* Position of words in history */ |
|
1385 /* line: as pairs of start, end */ |
|
1386 int nwords; /* Number of words in history line */ |
|
1387 zlong histnum; /* A sequential history number */ |
|
1388 }; |
|
1389 |
|
1390 #define HIST_MAKEUNIQUE 0x00000001 /* Kill this new entry if not unique */ |
|
1391 #define HIST_OLD 0x00000002 /* Command is already written to disk*/ |
|
1392 #define HIST_READ 0x00000004 /* Command was read back from disk*/ |
|
1393 #define HIST_DUP 0x00000008 /* Command duplicates a later line */ |
|
1394 #define HIST_FOREIGN 0x00000010 /* Command came from another shell */ |
|
1395 #define HIST_TMPSTORE 0x00000020 /* Kill when user enters another cmd */ |
|
1396 |
|
1397 #define GETHIST_UPWARD (-1) |
|
1398 #define GETHIST_DOWNWARD 1 |
|
1399 #define GETHIST_EXACT 0 |
|
1400 |
|
1401 /* Parts of the code where history expansion is disabled * |
|
1402 * should be within a pair of STOPHIST ... ALLOWHIST */ |
|
1403 |
|
1404 #define STOPHIST (stophist += 4); |
|
1405 #define ALLOWHIST (stophist -= 4); |
|
1406 |
|
1407 #define HISTFLAG_DONE 1 |
|
1408 #define HISTFLAG_NOEXEC 2 |
|
1409 #define HISTFLAG_RECALL 4 |
|
1410 #define HISTFLAG_SETTY 8 |
|
1411 |
|
1412 #define HFILE_APPEND 0x0001 |
|
1413 #define HFILE_SKIPOLD 0x0002 |
|
1414 #define HFILE_SKIPDUPS 0x0004 |
|
1415 #define HFILE_SKIPFOREIGN 0x0008 |
|
1416 #define HFILE_FAST 0x0010 |
|
1417 #define HFILE_NO_REWRITE 0x0020 |
|
1418 #define HFILE_USE_OPTIONS 0x8000 |
|
1419 |
|
1420 /******************************************/ |
|
1421 /* Definitions for programable completion */ |
|
1422 /******************************************/ |
|
1423 |
|
1424 /* Nothing special. */ |
|
1425 #define IN_NOTHING 0 |
|
1426 /* In command position. */ |
|
1427 #define IN_CMD 1 |
|
1428 /* In a mathematical environment. */ |
|
1429 #define IN_MATH 2 |
|
1430 /* In a condition. */ |
|
1431 #define IN_COND 3 |
|
1432 /* In a parameter assignment (e.g. `foo=bar'). */ |
|
1433 #define IN_ENV 4 |
|
1434 /* In a parameter name in an assignment. */ |
|
1435 #define IN_PAR 5 |
|
1436 |
|
1437 |
|
1438 /******************************/ |
|
1439 /* Definition for zsh options */ |
|
1440 /******************************/ |
|
1441 |
|
1442 /* Possible values of emulation */ |
|
1443 |
|
1444 #define EMULATE_CSH (1<<1) /* C shell */ |
|
1445 #define EMULATE_KSH (1<<2) /* Korn shell */ |
|
1446 #define EMULATE_SH (1<<3) /* Bourne shell */ |
|
1447 #define EMULATE_ZSH (1<<4) /* `native' mode */ |
|
1448 |
|
1449 /* option indices */ |
|
1450 |
|
1451 enum { |
|
1452 OPT_INVALID, |
|
1453 ALIASESOPT, |
|
1454 ALLEXPORT, |
|
1455 ALWAYSLASTPROMPT, |
|
1456 ALWAYSTOEND, |
|
1457 APPENDHISTORY, |
|
1458 AUTOCD, |
|
1459 AUTOCONTINUE, |
|
1460 AUTOLIST, |
|
1461 AUTOMENU, |
|
1462 AUTONAMEDIRS, |
|
1463 AUTOPARAMKEYS, |
|
1464 AUTOPARAMSLASH, |
|
1465 AUTOPUSHD, |
|
1466 AUTOREMOVESLASH, |
|
1467 AUTORESUME, |
|
1468 BADPATTERN, |
|
1469 BANGHIST, |
|
1470 BAREGLOBQUAL, |
|
1471 BASHAUTOLIST, |
|
1472 BEEP, |
|
1473 BGNICE, |
|
1474 BRACECCL, |
|
1475 BSDECHO, |
|
1476 CASEGLOB, |
|
1477 CBASES, |
|
1478 CDABLEVARS, |
|
1479 CHASEDOTS, |
|
1480 CHASELINKS, |
|
1481 CHECKJOBS, |
|
1482 CLOBBER, |
|
1483 COMPLETEALIASES, |
|
1484 COMPLETEINWORD, |
|
1485 CORRECT, |
|
1486 CORRECTALL, |
|
1487 CSHJUNKIEHISTORY, |
|
1488 CSHJUNKIELOOPS, |
|
1489 CSHJUNKIEQUOTES, |
|
1490 CSHNULLCMD, |
|
1491 CSHNULLGLOB, |
|
1492 EMACSMODE, |
|
1493 EQUALS, |
|
1494 ERREXIT, |
|
1495 ERRRETURN, |
|
1496 EXECOPT, |
|
1497 EXTENDEDGLOB, |
|
1498 EXTENDEDHISTORY, |
|
1499 EVALLINENO, |
|
1500 FLOWCONTROL, |
|
1501 FUNCTIONARGZERO, |
|
1502 GLOBOPT, |
|
1503 GLOBALEXPORT, |
|
1504 GLOBALRCS, |
|
1505 GLOBASSIGN, |
|
1506 GLOBCOMPLETE, |
|
1507 GLOBDOTS, |
|
1508 GLOBSUBST, |
|
1509 HASHCMDS, |
|
1510 HASHDIRS, |
|
1511 HASHLISTALL, |
|
1512 HISTALLOWCLOBBER, |
|
1513 HISTBEEP, |
|
1514 HISTEXPIREDUPSFIRST, |
|
1515 HISTFINDNODUPS, |
|
1516 HISTIGNOREALLDUPS, |
|
1517 HISTIGNOREDUPS, |
|
1518 HISTIGNORESPACE, |
|
1519 HISTNOFUNCTIONS, |
|
1520 HISTNOSTORE, |
|
1521 HISTREDUCEBLANKS, |
|
1522 HISTSAVENODUPS, |
|
1523 HISTVERIFY, |
|
1524 HUP, |
|
1525 IGNOREBRACES, |
|
1526 IGNOREEOF, |
|
1527 INCAPPENDHISTORY, |
|
1528 INTERACTIVE, |
|
1529 INTERACTIVECOMMENTS, |
|
1530 KSHARRAYS, |
|
1531 KSHAUTOLOAD, |
|
1532 KSHGLOB, |
|
1533 KSHOPTIONPRINT, |
|
1534 KSHTYPESET, |
|
1535 LISTAMBIGUOUS, |
|
1536 LISTBEEP, |
|
1537 LISTPACKED, |
|
1538 LISTROWSFIRST, |
|
1539 LISTTYPES, |
|
1540 LOCALOPTIONS, |
|
1541 LOCALTRAPS, |
|
1542 LOGINSHELL, |
|
1543 LONGLISTJOBS, |
|
1544 MAGICEQUALSUBST, |
|
1545 MAILWARNING, |
|
1546 MARKDIRS, |
|
1547 MENUCOMPLETE, |
|
1548 MONITOR, |
|
1549 MULTIOS, |
|
1550 NOMATCH, |
|
1551 NOTIFY, |
|
1552 NULLGLOB, |
|
1553 NUMERICGLOBSORT, |
|
1554 OCTALZEROES, |
|
1555 OVERSTRIKE, |
|
1556 PATHDIRS, |
|
1557 POSIXBUILTINS, |
|
1558 PRINTEIGHTBIT, |
|
1559 PRINTEXITVALUE, |
|
1560 PRIVILEGED, |
|
1561 PROMPTBANG, |
|
1562 PROMPTCR, |
|
1563 PROMPTPERCENT, |
|
1564 PROMPTSUBST, |
|
1565 PUSHDIGNOREDUPS, |
|
1566 PUSHDMINUS, |
|
1567 PUSHDSILENT, |
|
1568 PUSHDTOHOME, |
|
1569 RCEXPANDPARAM, |
|
1570 RCQUOTES, |
|
1571 RCS, |
|
1572 RECEXACT, |
|
1573 RESTRICTED, |
|
1574 RMSTARSILENT, |
|
1575 RMSTARWAIT, |
|
1576 SHAREHISTORY, |
|
1577 SHFILEEXPANSION, |
|
1578 SHGLOB, |
|
1579 SHINSTDIN, |
|
1580 SHNULLCMD, |
|
1581 SHOPTIONLETTERS, |
|
1582 SHORTLOOPS, |
|
1583 SHWORDSPLIT, |
|
1584 SINGLECOMMAND, |
|
1585 SINGLELINEZLE, |
|
1586 SUNKEYBOARDHACK, |
|
1587 TRANSIENTRPROMPT, |
|
1588 TRAPSASYNC, |
|
1589 TYPESETSILENT, |
|
1590 UNSET, |
|
1591 VERBOSE, |
|
1592 VIMODE, |
|
1593 XTRACE, |
|
1594 USEZLE, |
|
1595 DVORAK, |
|
1596 OPT_SIZE |
|
1597 }; |
|
1598 |
|
1599 #undef isset |
|
1600 #define isset(X) (opts[X]) |
|
1601 #define unset(X) (!opts[X]) |
|
1602 |
|
1603 #define interact (isset(INTERACTIVE)) |
|
1604 #define jobbing (isset(MONITOR)) |
|
1605 #define islogin (isset(LOGINSHELL)) |
|
1606 |
|
1607 /***********************************************/ |
|
1608 /* Definitions for terminal and display control */ |
|
1609 /***********************************************/ |
|
1610 |
|
1611 /* tty state structure */ |
|
1612 |
|
1613 struct ttyinfo { |
|
1614 #ifdef HAVE_TERMIOS_H |
|
1615 struct termios tio; |
|
1616 #else |
|
1617 # ifdef HAVE_TERMIO_H |
|
1618 struct termio tio; |
|
1619 # else |
|
1620 struct sgttyb sgttyb; |
|
1621 int lmodes; |
|
1622 struct tchars tchars; |
|
1623 struct ltchars ltchars; |
|
1624 # endif |
|
1625 #endif |
|
1626 #ifdef TIOCGWINSZ |
|
1627 struct winsize winsize; |
|
1628 #endif |
|
1629 }; |
|
1630 |
|
1631 /* defines for whether tabs expand to spaces */ |
|
1632 #if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H) |
|
1633 #define SGTTYFLAG shttyinfo.tio.c_oflag |
|
1634 #else /* we're using sgtty */ |
|
1635 #define SGTTYFLAG shttyinfo.sgttyb.sg_flags |
|
1636 #endif |
|
1637 # ifdef TAB3 |
|
1638 #define SGTABTYPE TAB3 |
|
1639 # else |
|
1640 # ifdef OXTABS |
|
1641 #define SGTABTYPE OXTABS |
|
1642 # else |
|
1643 #define SGTABTYPE XTABS |
|
1644 # endif |
|
1645 # endif |
|
1646 |
|
1647 /* flags for termflags */ |
|
1648 |
|
1649 #define TERM_BAD 0x01 /* terminal has extremely basic capabilities */ |
|
1650 #define TERM_UNKNOWN 0x02 /* unknown terminal type */ |
|
1651 #define TERM_NOUP 0x04 /* terminal has no up capability */ |
|
1652 #define TERM_SHORT 0x08 /* terminal is < 3 lines high */ |
|
1653 #define TERM_NARROW 0x10 /* terminal is < 3 columns wide */ |
|
1654 |
|
1655 /* interesting termcap strings */ |
|
1656 |
|
1657 #define TCCLEARSCREEN 0 |
|
1658 #define TCLEFT 1 |
|
1659 #define TCMULTLEFT 2 |
|
1660 #define TCRIGHT 3 |
|
1661 #define TCMULTRIGHT 4 |
|
1662 #define TCUP 5 |
|
1663 #define TCMULTUP 6 |
|
1664 #define TCDOWN 7 |
|
1665 #define TCMULTDOWN 8 |
|
1666 #define TCDEL 9 |
|
1667 #define TCMULTDEL 10 |
|
1668 #define TCINS 11 |
|
1669 #define TCMULTINS 12 |
|
1670 #define TCCLEAREOD 13 |
|
1671 #define TCCLEAREOL 14 |
|
1672 #define TCINSLINE 15 |
|
1673 #define TCDELLINE 16 |
|
1674 #define TCNEXTTAB 17 |
|
1675 #define TCBOLDFACEBEG 18 |
|
1676 #define TCSTANDOUTBEG 19 |
|
1677 #define TCUNDERLINEBEG 20 |
|
1678 #define TCALLATTRSOFF 21 |
|
1679 #define TCSTANDOUTEND 22 |
|
1680 #define TCUNDERLINEEND 23 |
|
1681 #define TCHORIZPOS 24 |
|
1682 #define TCUPCURSOR 25 |
|
1683 #define TCDOWNCURSOR 26 |
|
1684 #define TCLEFTCURSOR 27 |
|
1685 #define TCRIGHTCURSOR 28 |
|
1686 #define TC_COUNT 29 |
|
1687 |
|
1688 #define tccan(X) (tclen[X]) |
|
1689 |
|
1690 #define TXTBOLDFACE 0x01 |
|
1691 #define TXTSTANDOUT 0x02 |
|
1692 #define TXTUNDERLINE 0x04 |
|
1693 #define TXTDIRTY 0x80 |
|
1694 |
|
1695 #define txtisset(X) (txtattrmask & (X)) |
|
1696 #define txtset(X) (txtattrmask |= (X)) |
|
1697 #define txtunset(X) (txtattrmask &= ~(X)) |
|
1698 |
|
1699 #define TXTNOBOLDFACE 0x10 |
|
1700 #define TXTNOSTANDOUT 0x20 |
|
1701 #define TXTNOUNDERLINE 0x40 |
|
1702 |
|
1703 #define txtchangeisset(X) (txtchange & (X)) |
|
1704 #define txtchangeset(X, Y) (txtchange |= (X), txtchange &= ~(Y)) |
|
1705 |
|
1706 /****************************************/ |
|
1707 /* Definitions for the %_ prompt escape */ |
|
1708 /****************************************/ |
|
1709 |
|
1710 #define CMDSTACKSZ 256 |
|
1711 #define cmdpush(X) do { \ |
|
1712 if (cmdsp >= 0 && cmdsp < CMDSTACKSZ) \ |
|
1713 cmdstack[cmdsp++]=(X); \ |
|
1714 } while (0) |
|
1715 #ifdef DEBUG |
|
1716 # define cmdpop() do { \ |
|
1717 if (cmdsp <= 0) { \ |
|
1718 fputs("BUG: cmdstack empty\n", stderr); \ |
|
1719 fflush(stderr); \ |
|
1720 } else cmdsp--; \ |
|
1721 } while (0) |
|
1722 #else |
|
1723 # define cmdpop() do { if (cmdsp > 0) cmdsp--; } while (0) |
|
1724 #endif |
|
1725 |
|
1726 #define CS_FOR 0 |
|
1727 #define CS_WHILE 1 |
|
1728 #define CS_REPEAT 2 |
|
1729 #define CS_SELECT 3 |
|
1730 #define CS_UNTIL 4 |
|
1731 #define CS_IF 5 |
|
1732 #define CS_IFTHEN 6 |
|
1733 #define CS_ELSE 7 |
|
1734 #define CS_ELIF 8 |
|
1735 #define CS_MATH 9 |
|
1736 #define CS_COND 10 |
|
1737 #define CS_CMDOR 11 |
|
1738 #define CS_CMDAND 12 |
|
1739 #define CS_PIPE 13 |
|
1740 #define CS_ERRPIPE 14 |
|
1741 #define CS_FOREACH 15 |
|
1742 #define CS_CASE 16 |
|
1743 #define CS_FUNCDEF 17 |
|
1744 #define CS_SUBSH 18 |
|
1745 #define CS_CURSH 19 |
|
1746 #define CS_ARRAY 20 |
|
1747 #define CS_QUOTE 21 |
|
1748 #define CS_DQUOTE 22 |
|
1749 #define CS_BQUOTE 23 |
|
1750 #define CS_CMDSUBST 24 |
|
1751 #define CS_MATHSUBST 25 |
|
1752 #define CS_ELIFTHEN 26 |
|
1753 #define CS_HEREDOC 27 |
|
1754 #define CS_HEREDOCD 28 |
|
1755 #define CS_BRACE 29 |
|
1756 #define CS_BRACEPAR 30 |
|
1757 #define CS_ALWAYS 31 |
|
1758 |
|
1759 /* Increment as necessary */ |
|
1760 #define CS_COUNT 32 |
|
1761 |
|
1762 /********************* |
|
1763 * Memory management * |
|
1764 *********************/ |
|
1765 |
|
1766 /* heappush saves the current heap state using this structure */ |
|
1767 |
|
1768 struct heapstack { |
|
1769 struct heapstack *next; /* next one in list for this heap */ |
|
1770 size_t used; |
|
1771 }; |
|
1772 |
|
1773 /* A zsh heap. */ |
|
1774 |
|
1775 struct heap { |
|
1776 struct heap *next; /* next one */ |
|
1777 size_t size; /* size of heap */ |
|
1778 size_t used; /* bytes used from the heap */ |
|
1779 struct heapstack *sp; /* used by pushheap() to save the value used */ |
|
1780 |
|
1781 /* Uncomment the following if the struct needs padding to 64-bit size. */ |
|
1782 /* Make sure sizeof(heap) is a multiple of 8 |
|
1783 #if defined(PAD_64_BIT) && !defined(__GNUC__) |
|
1784 size_t dummy; |
|
1785 #endif |
|
1786 */ |
|
1787 #define arena(X) ((char *) (X) + sizeof(struct heap)) |
|
1788 } |
|
1789 #if defined(PAD_64_BIT) && defined(__GNUC__) |
|
1790 __attribute__ ((aligned (8))) |
|
1791 #endif |
|
1792 ; |
|
1793 |
|
1794 # define NEWHEAPS(h) do { Heap _switch_oldheaps = h = new_heaps(); do |
|
1795 # define OLDHEAPS while (0); old_heaps(_switch_oldheaps); } while (0); |
|
1796 |
|
1797 # define SWITCHHEAPS(o, h) do { o = switch_heaps(h); do |
|
1798 # define SWITCHBACKHEAPS(o) while (0); switch_heaps(o); } while (0); |
|
1799 |
|
1800 /****************/ |
|
1801 /* Debug macros */ |
|
1802 /****************/ |
|
1803 |
|
1804 #ifdef DEBUG |
|
1805 # define DPUTS(X,Y) if (!(X)) {;} else dputs(Y) |
|
1806 #else |
|
1807 # define DPUTS(X,Y) |
|
1808 #endif |
|
1809 |
|
1810 /**************************/ |
|
1811 /* Signal handling macros */ |
|
1812 /**************************/ |
|
1813 |
|
1814 /* These used in the sigtrapped[] array */ |
|
1815 |
|
1816 #define ZSIG_TRAPPED (1<<0) /* Signal is trapped */ |
|
1817 #define ZSIG_IGNORED (1<<1) /* Signal is ignored */ |
|
1818 #define ZSIG_FUNC (1<<2) /* Trap is a function, not an eval list */ |
|
1819 /* Mask to get the above flags */ |
|
1820 #define ZSIG_MASK (ZSIG_TRAPPED|ZSIG_IGNORED|ZSIG_FUNC) |
|
1821 /* No. of bits to shift local level when storing in sigtrapped */ |
|
1822 #define ZSIG_SHIFT 3 |
|
1823 |
|
1824 /**********************************/ |
|
1825 /* Flags to third argument of zle */ |
|
1826 /**********************************/ |
|
1827 |
|
1828 #define ZLRF_HISTORY 0x01 /* OK to access the history list */ |
|
1829 #define ZLRF_NOSETTY 0x02 /* Don't set tty before return */ |
|
1830 #define ZLRF_IGNOREEOF 0x04 /* Ignore an EOF from the keyboard */ |
|
1831 |
|
1832 /***************************/ |
|
1833 /* Context of zleread call */ |
|
1834 /***************************/ |
|
1835 |
|
1836 enum { |
|
1837 ZLCON_LINE_START, /* Command line at PS1 */ |
|
1838 ZLCON_LINE_CONT, /* Command line at PS2 */ |
|
1839 ZLCON_SELECT, /* Select loop */ |
|
1840 ZLCON_VARED /* Vared command */ |
|
1841 }; |
|
1842 |
|
1843 /****************/ |
|
1844 /* Entry points */ |
|
1845 /****************/ |
|
1846 |
|
1847 /* compctl entry point pointers */ |
|
1848 |
|
1849 typedef int (*CompctlReadFn) _((char *, char **, Options, char *)); |
|
1850 |
|
1851 /* ZLE entry point pointers */ |
|
1852 |
|
1853 typedef void (*ZleVoidFn) _((void)); |
|
1854 typedef void (*ZleVoidIntFn) _((int)); |
|
1855 typedef unsigned char * (*ZleReadFn) _((char **, char **, int, int)); |
|
1856 |
|
1857 /***************************************/ |
|
1858 /* Hooks in core. */ |
|
1859 /***************************************/ |
|
1860 |
|
1861 #define EXITHOOK (zshhooks + 0) |
|
1862 #define BEFORETRAPHOOK (zshhooks + 1) |
|
1863 #define AFTERTRAPHOOK (zshhooks + 2) |