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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 #ifndef _DEFS_H 31 #define _DEFS_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /* 38 * UNIX shell 39 */ 40 41 /* execute flags */ 42 #define XEC_EXECED 01 43 #define XEC_LINKED 02 44 #define XEC_NOSTOP 04 45 46 /* endjobs flags */ 47 #define JOB_STOPPED 01 48 #define JOB_RUNNING 02 49 50 /* error exits from various parts of shell */ 51 #define ERROR 1 52 #define SYNBAD 2 53 #define SIGFAIL 2000 54 #define SIGFLG 0200 55 56 /* command tree */ 57 #define FPIN 0x0100 58 #define FPOU 0x0200 59 #define FAMP 0x0400 60 #define COMMSK 0x00F0 61 #define CNTMSK 0x000F /* this bit fields no longer used */ 62 63 #define TCOM 0x0000 64 #define TPAR 0x0010 65 #define TFIL 0x0020 66 #define TLST 0x0030 67 #define TIF 0x0040 68 #define TWH 0x0050 69 #define TUN 0x0060 70 #define TSW 0x0070 71 #define TAND 0x0080 72 #define TORF 0x0090 73 #define TFORK 0x00A0 74 #define TFOR 0x00B0 75 #define TFND 0x00C0 76 77 /* execute table */ 78 #define SYSSET 1 79 #define SYSCD 2 80 #define SYSEXEC 3 81 82 #ifdef RES /* include login code */ 83 #define SYSLOGIN 4 84 #else 85 #define SYSNEWGRP 4 86 #endif 87 88 #define SYSTRAP 5 89 #define SYSEXIT 6 90 #define SYSSHFT 7 91 #define SYSWAIT 8 92 #define SYSCONT 9 93 #define SYSBREAK 10 94 #define SYSEVAL 11 95 #define SYSDOT 12 96 #define SYSRDONLY 13 97 #define SYSTIMES 14 98 #define SYSXPORT 15 99 #define SYSNULL 16 100 #define SYSREAD 17 101 #define SYSTST 18 102 103 #ifndef RES /* exclude umask code */ 104 #define SYSUMASK 20 105 #define SYSULIMIT 21 106 #endif 107 108 #define SYSECHO 22 109 #define SYSHASH 23 110 #define SYSPWD 24 111 #define SYSRETURN 25 112 #define SYSUNS 26 113 #define SYSMEM 27 114 #define SYSTYPE 28 115 #define SYSGETOPT 29 116 #define SYSJOBS 30 117 #define SYSFGBG 31 118 #define SYSKILL 32 119 #define SYSSUSP 33 120 #define SYSSTOP 34 121 122 /* used for input and output of shell */ 123 #define INIO 19 124 125 /* io nodes */ 126 #define USERIO 10 127 #define IOUFD 15 128 #define IODOC 0x0010 129 #define IOPUT 0x0020 130 #define IOAPP 0x0040 131 #define IOMOV 0x0080 132 #define IORDW 0x0100 133 #define IOSTRIP 0x0200 134 #define IODOC_SUBST 0x0400 135 #define INPIPE 0 136 #define OTPIPE 1 137 138 /* arg list terminator */ 139 #define ENDARGS 0 140 141 #include <unistd.h> 142 #include "mac.h" 143 #include "mode.h" 144 #include "name.h" 145 #include <signal.h> 146 #include <sys/types.h> 147 148 /* id's */ 149 extern pid_t mypid; 150 extern pid_t mypgid; 151 extern pid_t mysid; 152 153 /* getopt */ 154 155 extern int optind; 156 extern int opterr; 157 extern int _sp; 158 extern char *optarg; 159 160 161 /* use sh-private versions of memory allocation routines */ 162 163 #define alloc malloc 164 165 /* result type declarations */ 166 167 extern int handle(); 168 extern void chktrap(); 169 extern void done(int) 170 __NORETURN; 171 extern void sh_free(); 172 extern unsigned char *make(); 173 extern unsigned char *movstr(); 174 extern unsigned char *movstrn(); 175 extern unsigned char *cwdget(); 176 extern struct trenod *cmd(); 177 extern struct trenod *makefork(); 178 extern struct namnod *lookup(); 179 extern struct namnod *findnam(); 180 extern struct dolnod *useargs(); 181 extern float expr(); 182 extern unsigned char *catpath(); 183 extern unsigned char *getpath(); 184 extern unsigned char *nextpath(); 185 extern unsigned char **scan(); 186 extern unsigned char *mactrim(); 187 extern unsigned char *macro(); 188 extern void exname(struct namnod *); 189 extern void printnam(struct namnod *); 190 extern void printro(struct namnod *); 191 extern void printexp(struct namnod *); 192 extern unsigned int readwc(); 193 extern unsigned int nextwc(); 194 extern unsigned char skipc(); 195 extern unsigned char **local_setenv(); 196 extern time_t time(); 197 extern void exitsh(int) 198 __NORETURN; 199 extern void failed_real(unsigned char *, const char *, unsigned char *) 200 __NORETURN; 201 extern void error(const char *) __NORETURN; 202 extern void prf(); 203 extern void assign(struct namnod *, unsigned char *); 204 extern void setmode(int); 205 extern void trim(unsigned char *); 206 extern void preacct(unsigned char *); 207 extern void addblok(unsigned int); 208 extern void freetree(struct trenod *); 209 210 211 212 #define attrib(n, f) (n->namflg |= f) 213 #define round(a, b) (((int)(((char *)(a)+b)-1))&~((b)-1)) 214 #define closepipe(x) (close(x[INPIPE]), close(x[OTPIPE])) 215 #define eq(a, b) (cf(a, b) == 0) 216 #define max(a, b) ((a) > (b)?(a):(b)) 217 #define assert(x) 218 #define _gettext(s) (unsigned char *)gettext(s) 219 220 /* 221 * macros using failed_real(). Only s2 is gettext'd with both functions. 222 */ 223 #define failed(s1, s2) failed_real(s1, s2, NULL) 224 #define bfailed(s1, s2, s3) failed_real(s1, s2, s3) 225 226 /* 227 * macros using failure_real(). s1 and s2 is gettext'd with gfailure(), but 228 * only s2 is gettext'd with failure(). 229 */ 230 #define failure(s1, s2) failure_real(s1, s2, 0) 231 #define gfailure(s1, s2) failure_real(s1, s2, 1) 232 233 /* temp files and io */ 234 extern int output; 235 extern int ioset; 236 extern struct ionod *iotemp; /* files to be deleted sometime */ 237 extern struct ionod *fiotemp; /* function files to be deleted sometime */ 238 extern struct ionod *iopend; /* documents waiting to be read at NL */ 239 extern struct fdsave fdmap[]; 240 extern int savpipe; 241 242 /* substitution */ 243 extern int dolc; 244 extern unsigned char **dolv; 245 extern struct dolnod *argfor; 246 extern struct argnod *gchain; 247 248 /* stak stuff */ 249 #include "stak.h" 250 251 /* 252 * If non-ANSI C, make const go away. We bring it back 253 * at the end of the file to avoid side-effects. 254 */ 255 #ifndef __STDC__ 256 #define const 257 #endif 258 259 /* string constants */ 260 extern const char atline[]; 261 extern const char readmsg[]; 262 extern const char colon[]; 263 extern const char minus[]; 264 extern const char nullstr[]; 265 extern const char sptbnl[]; 266 extern const char unexpected[]; 267 extern const char endoffile[]; 268 extern const char synmsg[]; 269 270 /* name tree and words */ 271 extern const struct sysnod reserved[]; 272 extern const int no_reserved; 273 extern const struct sysnod commands[]; 274 extern const int no_commands; 275 276 extern int wdval; 277 extern int wdnum; 278 extern int fndef; 279 extern int nohash; 280 extern struct argnod *wdarg; 281 extern int wdset; 282 extern BOOL reserv; 283 284 /* prompting */ 285 extern const char stdprompt[]; 286 extern const char supprompt[]; 287 extern const char profile[]; 288 extern const char sysprofile[]; 289 290 /* locale testing */ 291 extern const char localedir[]; 292 extern int localedir_exists; 293 294 /* built in names */ 295 extern struct namnod fngnod; 296 extern struct namnod cdpnod; 297 extern struct namnod ifsnod; 298 extern struct namnod homenod; 299 extern struct namnod mailnod; 300 extern struct namnod pathnod; 301 extern struct namnod ps1nod; 302 extern struct namnod ps2nod; 303 extern struct namnod mchknod; 304 extern struct namnod acctnod; 305 extern struct namnod mailpnod; 306 307 /* special names */ 308 extern unsigned char flagadr[]; 309 extern unsigned char *pcsadr; 310 extern unsigned char *pidadr; 311 extern unsigned char *cmdadr; 312 313 /* names always present */ 314 extern const char defpath[]; 315 extern const char mailname[]; 316 extern const char homename[]; 317 extern const char pathname[]; 318 extern const char cdpname[]; 319 extern const char ifsname[]; 320 extern const char ps1name[]; 321 extern const char ps2name[]; 322 extern const char mchkname[]; 323 extern const char acctname[]; 324 extern const char mailpname[]; 325 326 /* transput */ 327 extern unsigned char tmpout[]; 328 extern int tmpout_offset; 329 extern unsigned int serial; 330 331 /* 332 * allow plenty of room for size for temp file name: 333 * "/tmp/sh"(7) + <pid> (<=6) + <unsigned int #> (<=10) + \0 (1) 334 */ 335 #define TMPOUTSZ 32 336 337 extern struct fileblk *standin; 338 339 #define input (standin->fdes) 340 #define eof (standin->feof) 341 342 extern int peekc; 343 extern int peekn; 344 extern unsigned char *comdiv; 345 extern 346 #ifdef __STDC__ 347 const 348 #endif 349 char devnull[]; 350 351 /* flags */ 352 #define noexec 01 353 #define sysflg 01 354 #define intflg 02 355 #define prompt 04 356 #define setflg 010 357 #define errflg 020 358 #define ttyflg 040 359 #define forked 0100 360 #define oneflg 0200 361 #define rshflg 0400 362 #define subsh 01000 363 #define stdflg 02000 364 #define STDFLG 's' 365 #define execpr 04000 366 #define readpr 010000 367 #define keyflg 020000 368 #define hashflg 040000 369 #define nofngflg 0200000 370 #define exportflg 0400000 371 #define monitorflg 01000000 372 #define jcflg 02000000 373 #define privflg 04000000 374 #define forcexit 010000000 375 #define jcoff 020000000 376 #define pfshflg 040000000 377 378 extern long flags; 379 extern int rwait; /* flags read waiting */ 380 381 /* error exits from various parts of shell */ 382 #include <setjmp.h> 383 extern jmp_buf subshell; 384 extern jmp_buf errshell; 385 386 /* fault handling */ 387 #include "brkincr.h" 388 389 extern unsigned brkincr; 390 #define MINTRAP 0 391 #define MAXTRAP NSIG 392 393 #define TRAPSET 2 394 #define SIGSET 4 395 #define SIGMOD 8 396 #define SIGIGN 16 397 398 extern BOOL trapnote; 399 400 /* name tree and words */ 401 extern unsigned char **environ; 402 extern unsigned char numbuf[]; 403 extern const char export[]; 404 extern const char duperr[]; 405 extern const char readonly[]; 406 407 /* execflgs */ 408 extern int exitval; 409 extern int retval; 410 extern BOOL execbrk; 411 extern int loopcnt; 412 extern int breakcnt; 413 extern int funcnt; 414 extern int tried_to_exit; 415 416 /* messages */ 417 extern const char mailmsg[]; 418 extern const char coredump[]; 419 extern const char badopt[]; 420 extern const char badparam[]; 421 extern const char unset[]; 422 extern const char badsub[]; 423 extern const char nospace[]; 424 extern const char nostack[]; 425 extern const char notfound[]; 426 extern const char badtrap[]; 427 extern const char baddir[]; 428 extern const char badshift[]; 429 extern const char restricted[]; 430 extern const char execpmsg[]; 431 extern const char notid[]; 432 extern const char badulimit[]; 433 extern const char ulimit[]; 434 extern const char wtfailed[]; 435 extern const char badcreate[]; 436 extern const char nofork[]; 437 extern const char noswap[]; 438 extern const char piperr[]; 439 extern const char badopen[]; 440 extern const char badnum[]; 441 extern const char badsig[]; 442 extern const char badid[]; 443 extern const char arglist[]; 444 extern const char txtbsy[]; 445 extern const char toobig[]; 446 extern const char badexec[]; 447 extern const char badfile[]; 448 extern const char badreturn[]; 449 extern const char badexport[]; 450 extern const char badunset[]; 451 extern const char nohome[]; 452 extern const char badperm[]; 453 extern const char mssgargn[]; 454 extern const char libacc[]; 455 extern const char libbad[]; 456 extern const char libscn[]; 457 extern const char libmax[]; 458 extern const char emultihop[]; 459 extern const char nulldir[]; 460 extern const char enotdir[]; 461 extern const char enoent[]; 462 extern const char eacces[]; 463 extern const char enolink[]; 464 extern const char exited[]; 465 extern const char running[]; 466 extern const char ambiguous[]; 467 extern const char nosuchjob[]; 468 extern const char nosuchpid[]; 469 extern const char nosuchpgid[]; 470 extern const char usage[]; 471 extern const char nojc[]; 472 extern const char killuse[]; 473 extern const char jobsuse[]; 474 extern const char stopuse[]; 475 extern const char ulimuse[]; 476 extern const char nocurjob[]; 477 extern const char loginsh[]; 478 extern const char jobsstopped[]; 479 extern const char jobsrunning[]; 480 extern const char nlorsemi[]; 481 extern const char signalnum[]; 482 extern const char badpwd[]; 483 extern const char badlocale[]; 484 extern const char nobracket[]; 485 extern const char noparen[]; 486 extern const char noarg[]; 487 488 /* 'builtin' error messages */ 489 490 extern const char btest[]; 491 extern const char badop[]; 492 493 #ifndef __STDC__ 494 #undef const /* bring back const */ 495 #endif 496 497 /* fork constant */ 498 499 #define FORKLIM 32 500 501 extern address end[]; 502 503 #include "ctype.h" 504 #include <ctype.h> 505 #include <locale.h> 506 507 extern int eflag; 508 extern int ucb_builtins; 509 510 /* 511 * Find out if it is time to go away. 512 * `trapnote' is set to SIGSET when fault is seen and 513 * no trap has been set. 514 */ 515 516 #define sigchk() if (trapnote & SIGSET) \ 517 exitsh(exitval ? exitval : SIGFAIL) 518 519 #define exitset() retval = exitval 520 521 /* Multibyte characters */ 522 unsigned char *readw(); 523 #include <stdlib.h> 524 #include <limits.h> 525 #define MULTI_BYTE_MAX MB_LEN_MAX 526 527 528 #ifdef __cplusplus 529 } 530 #endif 531 532 #endif /* _DEFS_H */ 533