1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * A copy of the CDDL is also available via the Internet at 11 * http://www.opensource.org/licenses/cddl1.txt 12 * See the License for the specific language governing permissions 13 * and limitations under the License. 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 * If applicable, add the following below this CDDL HEADER, with the 18 * fields enclosed by brackets "[]" replaced with your own identifying 19 * information: Portions Copyright [yyyy] [name of copyright owner] 20 * 21 * CDDL HEADER END 22 */ 23 /* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 #if defined(sun) 31 #pragma ident "@(#)mode.h 1.13 06/05/17 SMI" 32 #endif 33 34 #ifndef _MODE_H 35 #define _MODE_H 36 37 /* 38 * Copyright 2008-2021 J. Schilling 39 * 40 * @(#)mode.h 1.30 21/02/27 2008-2021 J. Schilling 41 */ 42 43 /* 44 * UNIX shell 45 */ 46 #ifdef SCHILY_INCLUDES 47 #include <schily/unistd.h> 48 #include <schily/utypes.h> 49 #else 50 #include <unistd.h> 51 #endif 52 53 #include "bosh.h" 54 55 #ifdef pdp11 56 typedef char BOOL; 57 #else 58 typedef short BOOL; 59 #endif 60 61 #define BYTESPERWORD (sizeof (char *)) 62 #define ALIGNSIZ (sizeof (double)) 63 #define NIL ((char *)0) 64 65 66 /* 67 * the following nonsense is required 68 * because casts turn an Lvalue 69 * into an Rvalue so two cheats 70 * are necessary, one for each context. 71 */ 72 #define Rcheat(a) ((Intptr_t)(a)) 73 74 75 /* address puns for storage allocation */ 76 typedef union 77 { 78 struct forknod *_forkptr; 79 struct comnod *_comptr; 80 struct fndnod *_fndptr; 81 struct parnod *_parptr; 82 struct ifnod *_ifptr; 83 struct whnod *_whptr; 84 struct fornod *_forptr; 85 struct lstnod *_lstptr; 86 struct blk *_blkptr; 87 struct namnod *_namptr; 88 char *_bytptr; 89 } address; 90 91 92 /* 93 * largefile converson hack note. 94 * the shell uses the *fnxt and *fend pointers when 95 * parsing a script. However, it was also using the 96 * difference between them when doing lseeks. Because 97 * that doesn't work in the largefile world, I have 98 * added a parallel set of offset counters that need to 99 * be updated whenever the "buffer" offsets the shell 100 * uses get changed. Most of this code is in word.c. 101 * If you change it, have fun... 102 */ 103 104 #ifdef FBUF_BUFFERSIZE 105 #define BUFFERSIZE FBUF_BUFFERSIZE 106 #else 107 #define BUFFERSIZE 128 108 #endif 109 struct fileblk 110 { 111 int fdes; /* file descr. or < 0 for string */ 112 unsigned flin; /* current line */ 113 int peekn; /* saved peekn for aliases */ 114 BOOL feof; /* EOF marker */ 115 #if BUFFERSIZE > 128 116 unsigned int fsiz; /* buffer size to use */ 117 #else 118 unsigned char fsiz; 119 #endif 120 unsigned char *fnxt; /* ptr. to next char in buffer */ 121 unsigned char *fend; /* ptr. past end of buffer */ 122 off_t nxtoff; /* file offset */ 123 off_t endoff; /* file offset */ 124 unsigned char **feval; /* arg vector for eval */ 125 struct fileblk *fstak; /* previous input if stacked */ 126 void *alias; /* active aliases */ 127 wchar_t lastwc; /* last wchar for EILSEQ */ 128 unsigned char mbs[2]; /* "multi byte" string for EILSEQ */ 129 unsigned char fbuf[BUFFERSIZE]; 130 }; 131 132 struct tempblk 133 { 134 int fdes; 135 struct tempblk *fstak; 136 }; 137 138 139 /* 140 * for files not used with file descriptors 141 * 142 * fsiz is 1 in this case 143 */ 144 struct filehdr 145 { 146 int fdes; /* file descr. or < 0 for string */ 147 unsigned flin; /* current line */ 148 int peekn; /* saved peekn for aliases */ 149 BOOL feof; /* EOF marker */ 150 #if BUFFERSIZE > 128 151 unsigned int fsiz; /* buffer size to use */ 152 #else 153 unsigned char fsiz; 154 #endif 155 unsigned char *fnxt; /* ptr. to next char in buffer */ 156 unsigned char *fend; /* ptr. past end of buffer */ 157 off_t nxtoff; /* file offset */ 158 off_t endoff; /* file offset */ 159 unsigned char **feval; /* arg vector for eval */ 160 struct fileblk *fstak; /* previous input if stacked */ 161 void *alias; /* active aliases */ 162 wchar_t lastwc; /* last wchar for EILSEQ */ 163 unsigned char mbs[2]; /* "multi byte" string for EILSEQ */ 164 unsigned char _fbuf[1]; 165 }; 166 167 /* 168 * For the results from waitid() 169 */ 170 struct excode { 171 int ex_code; /* Child status code */ 172 int ex_status; /* Child exit code or signal number */ 173 pid_t ex_pid; /* Child pid */ 174 int ex_signo; /* Causing signal, SIGCLD for wait() */ 175 }; 176 177 struct sysnod 178 { 179 char *sysnam; /* Name of reserved / builtin */ 180 UInt16_t sysval; /* Value to identify above */ 181 UInt16_t sysflg; /* Flag for builtins */ 182 }; 183 184 typedef int (*bftype) __PR((int argc, Uchar *argv[], bosh_t *__bp)); 185 186 struct sysnod2 187 { 188 char *sysnam; /* Name of reserved / builtin */ 189 UInt16_t sysval; /* Value to identify above */ 190 UInt16_t sysflg; /* Flag for builtins */ 191 bftype sysptr; /* Ptr to function */ 192 struct sysnod2 *snext; /* Allow a chain of entries */ 193 }; 194 195 /* 196 * this node is a proforma for those that follow 197 */ 198 struct trenod 199 { 200 int tretyp; 201 struct ionod *treio; 202 }; 203 204 /* 205 * dummy for access only 206 */ 207 struct argnod 208 { 209 struct argnod *argnxt; 210 unsigned char argval[1]; 211 }; 212 213 struct dolnod 214 { 215 struct dolnod *dolnxt; 216 int doluse; 217 unsigned char **dolarg; 218 }; 219 220 /* 221 * Used for TFORK, TNOFORK 222 */ 223 struct forknod 224 { 225 int forktyp; 226 struct ionod *forkio; 227 struct trenod *forktre; 228 }; 229 230 /* 231 * Used for TCOM 232 */ 233 struct comnod 234 { 235 int comtyp; 236 struct ionod *comio; 237 struct argnod *comarg; 238 struct argnod *comset; 239 }; 240 241 /* 242 * Used for TFND (function definition) 243 */ 244 struct fndnod 245 { 246 int fndtyp; 247 unsigned char *fndnam; 248 struct trenod *fndval; 249 int fndref; 250 }; 251 252 /* 253 * Used for TIF 254 */ 255 struct ifnod 256 { 257 int iftyp; 258 struct trenod *iftre; 259 struct trenod *thtre; 260 struct trenod *eltre; 261 }; 262 263 /* 264 * Used for TWH, TUN 265 */ 266 struct whnod 267 { 268 int whtyp; 269 struct trenod *whtre; 270 struct trenod *dotre; 271 }; 272 273 /* 274 * Used fot TFOR, TSELECT 275 */ 276 struct fornod 277 { 278 int fortyp; 279 struct trenod *fortre; 280 unsigned char *fornam; 281 struct comnod *forlst; 282 }; 283 284 /* 285 * Used for TSW 286 */ 287 struct swnod 288 { 289 int swtyp; 290 unsigned char *swarg; 291 struct regnod *swlst; 292 }; 293 294 struct regnod 295 { 296 struct argnod *regptr; 297 struct trenod *regcom; 298 struct regnod *regnxt; 299 char regflag; 300 }; 301 302 /* 303 * Used for TPAR, TNOT, TTIME 304 */ 305 struct parnod 306 { 307 int partyp; 308 struct trenod *partre; 309 }; 310 311 /* 312 * Used for TLST, TAND, TORF, TFIL 313 */ 314 struct lstnod 315 { 316 int lsttyp; 317 struct trenod *lstlef; 318 struct trenod *lstrit; 319 }; 320 321 struct ionod 322 { 323 int iofile; 324 char *ioname; 325 char *iolink; 326 struct ionod *ionxt; 327 struct ionod *iolst; 328 }; 329 330 struct fdsave 331 { 332 int org_fd; 333 int dup_fd; 334 }; 335 336 struct optv 337 { 338 int opterr; /* Whether getopt() prints error messages */ 339 int optind; /* Index in argv */ 340 int optopt; /* Option character */ 341 int opt_sp; /* Index in multi opt arg like -abc */ 342 int optret; /* Return from last getopt() */ 343 int ooptind; /* Index in argv from before getopt() call */ 344 int optflag; /* Flags used by getopt() / optnext() */ 345 char *optarg; /* Option argument string */ 346 }; 347 348 /* 349 * Values for optflag: 350 */ 351 #define OPT_NOFAIL 1 /* Do not print a message for wrong opts */ 352 #define OPT_SPC 2 /* Failed option handling for spec builtins */ 353 354 #define treptr(x) ((struct trenod *)x) 355 #define fndptr(x) ((struct fndnod *)x) 356 #define comptr(x) ((struct comnod *)x) 357 #define forkptr(x) ((struct forknod *)x) 358 #define parptr(x) ((struct parnod *)x) 359 #define lstptr(x) ((struct lstnod *)x) 360 #define forptr(x) ((struct fornod *)x) 361 #define whptr(x) ((struct whnod *)x) 362 #define ifptr(x) ((struct ifnod *)x) 363 #define swptr(x) ((struct swnod *)x) 364 365 #endif /* _MODE_H */ 366