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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
47 #define JOB_STOPPED 01
48 #define JOB_RUNNING 02
50 /* error exits from various parts of shell */
61 #define CNTMSK 0x000F /* this bit fields no longer used */
82 #ifdef RES /* include login code */
103 #ifndef RES /* exclude umask code */
122 /* used for input and output of shell */
133 #define IOSTRIP 0x0200
134 #define IODOC_SUBST 0x0400
138 /* arg list terminator */
146 #include <sys/types.h>
161 /* use sh-private versions of memory allocation routines */
165 /* result type declarations */
168 extern void chktrap();
169 extern void done(int)
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();
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)
199 extern void failed_real(unsigned char *, const char *, unsigned char *)
201 extern void error(const char *) __NORETURN
;
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
*);
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))
218 #define _gettext(s) (unsigned char *)gettext(s)
221 * macros using failed_real(). Only s2 is gettext'd with both functions.
223 #define failed(s1, s2) failed_real(s1, s2, NULL)
224 #define bfailed(s1, s2, s3) failed_real(s1, s2, s3)
227 * macros using failure_real(). s1 and s2 is gettext'd with gfailure(), but
228 * only s2 is gettext'd with failure().
230 #define failure(s1, s2) failure_real(s1, s2, 0)
231 #define gfailure(s1, s2) failure_real(s1, s2, 1)
233 /* temp files and io */
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
[];
244 extern unsigned char **dolv
;
245 extern struct dolnod
*argfor
;
246 extern struct argnod
*gchain
;
252 * If non-ANSI C, make const go away. We bring it back
253 * at the end of the file to avoid side-effects.
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
[];
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
;
280 extern struct argnod
*wdarg
;
285 extern const char stdprompt
[];
286 extern const char supprompt
[];
287 extern const char profile
[];
288 extern const char sysprofile
[];
291 extern const char localedir
[];
292 extern int localedir_exists
;
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
;
308 extern unsigned char flagadr
[];
309 extern unsigned char *pcsadr
;
310 extern unsigned char *pidadr
;
311 extern unsigned char *cmdadr
;
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
[];
327 extern unsigned char tmpout
[];
328 extern int tmpout_offset
;
329 extern unsigned int serial
;
332 * allow plenty of room for size for temp file name:
333 * "/tmp/sh"(7) + <pid> (<=6) + <unsigned int #> (<=10) + \0 (1)
337 extern struct fileblk
*standin
;
339 #define input (standin->fdes)
340 #define eof (standin->feof)
344 extern unsigned char *comdiv
;
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
379 extern int rwait
; /* flags read waiting */
381 /* error exits from various parts of shell */
383 extern jmp_buf subshell
;
384 extern jmp_buf errshell
;
389 extern unsigned brkincr
;
398 extern BOOL trapnote
;
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
[];
414 extern int tried_to_exit
;
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
[];
488 /* 'builtin' error messages */
490 extern const char btest
[];
491 extern const char badop
[];
494 #undef const /* bring back const */
501 extern address end
[];
508 extern int ucb_builtins
;
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.
516 #define sigchk() if (trapnote & SIGSET) \
517 exitsh(exitval ? exitval : SIGFAIL)
519 #define exitset() retval = exitval
521 /* Multibyte characters */
522 unsigned char *readw();
525 #define MULTI_BYTE_MAX MB_LEN_MAX