1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1982-2013 AT&T Intellectual Property          *
5  *                      and is licensed under the                       *
6  *                 Eclipse Public License, Version 1.0                  *
7  *                    by AT&T Intellectual Property                     *
8  *                                                                      *
9  *                A copy of the License is available at                 *
10  *          http://www.eclipse.org/org/documents/epl-v10.html           *
11  *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12  *                                                                      *
13  *              Information and Software Systems Research               *
14  *                            AT&T Research                             *
15  *                           Florham Park NJ                            *
16  *                                                                      *
17  *                    David Korn <dgkorn@gmail.com>                     *
18  *                                                                      *
19  ***********************************************************************/
20 //
21 // Struct to hold a word argument.
22 // Written by David Korn
23 //
24 #ifndef _ARGNOD_H
25 #define _ARGNOD_H 1
26 
27 #include "sfio.h"
28 #include "stk.h"
29 
30 struct ionod {
31     unsigned iofile;
32     char *ioname;
33     struct ionod *ionxt;
34     struct ionod *iolst;
35     char *iodelim;
36     off_t iooffset;
37     long iosize;
38     char *iovname;
39 };
40 
41 struct comnod {
42     int comtyp;
43     struct ionod *comio;
44     struct argnod *comarg;
45     struct argnod *comset;
46     void *comnamp;
47     void *comnamq;
48     void *comstate;
49     int64_t comline;
50 };
51 
52 #define COMBITS 4
53 #define COMMSK ((1 << COMBITS) - 1)
54 #define COMSCAN (01 << COMBITS)
55 #define COMFIXED (04000 << COMBITS)
56 
57 struct slnod {  // struct for link list of stacks
58     struct slnod *slnext;
59     struct slnod *slchild;
60     Sfio_t *slptr;
61     // slpad aligns struct functnod = struct slnod + 1 on some architectures.
62     struct slnod *slpad;
63 };
64 
65 //
66 // This struct is use to hold $* lists and arrays.
67 //
68 struct dolnod {
69     int dolrefcnt;          // reference count
70     int dolmax;             // size of dolval array
71     int dolnum;             // number of elements
72     int dolbot;             // current first element
73     struct dolnod *dolnxt;  // used when list are chained
74     char *dolval[1];        // array of value pointers
75 };
76 
77 //
78 // This struct is used to hold word arguments of variable size during parsing and during expansion.
79 // The flags indicate what processing is required on the argument.
80 //
81 struct argnod {
82     union {
83         struct argnod *ap;
84         char *cp;
85     } argnxt;
86     union {
87         struct argnod *ap;
88         char *cp;
89         int len;
90     } argchn;
91     // This has to be 8 bits because the code expects that assigning to it will mask off any high
92     // bits; e.g., ARG_ARITH and friends.
93     unsigned char argflag;
94     char argval[4];
95 };
96 
97 // The following should evaluate to the offset of argval in argnod.
98 #define ARGVAL offsetof(struct argnod, argval[0])
99 #define sh_argstr(ap) ((ap)->argflag & ARG_RAW ? sh_fmtq((ap)->argval) : (ap)->argval)
100 #define ARG_SPARE 1
101 
102 // Legal argnod flags.
103 #define ARG_RAW (1 << 0)      // string needs no processing
104 #define ARG_MAKE (1 << 1)     // bit set during argument expansion
105 #define ARG_MAC (1 << 2)      // string needs macro expansion
106 #define ARG_EXP (1 << 3)      // string needs file expansion
107 #define ARG_ASSIGN (1 << 4)   // argument is an assignment
108 #define ARG_QUOTED (1 << 5)   // word contained quote characters
109 #define ARG_MESSAGE (1 << 6)  // contains international string
110 #define ARG_APPEND (1 << 7)   // for += assignment
111 #define ARG_ARRAY (ARG_MAKE)  // for typeset -a
112 
113 // The following can be passed as options to sh_macexpand().
114 #define ARG_ARITH (1 << 8)     // arithmetic expansion
115 #define ARG_OPTIMIZE (1 << 9)  // try to optimize
116 #define ARG_NOGLOB (1 << 10)   // no file name expansion
117 #define ARG_LET (1 << 11)      // processing let command arguments
118 #define ARG_ARRAYOK (1 << 12)  // $x[sub] ==> ${x[sub]}
119 #define ARG_CASE (1 << 13)     // expanding case patterns
120 
121 extern struct dolnod *sh_argcreate(char *[]);
122 extern char *sh_argdolminus(Shell_t *);
123 extern int sh_argopts(int, char *[], void *);
124 
125 extern const char e_heading[];
126 extern const char e_off[];
127 extern const char e_on[];
128 extern const char e_sptbnl[];
129 extern const char e_subst[];
130 extern const char e_option[];
131 extern const char e_exec[];
132 extern const char e_devfdNN[];
133 extern const char e_devfdstd[];
134 
135 #endif  // _ARGNOD_H
136