xref: /dragonfly/contrib/tcsh-6/sh.h (revision 0db87cb7)
1 /* $Header: /p/tcsh/cvsroot/tcsh/sh.h,v 3.165 2011/04/14 18:25:25 christos Exp $ */
2 /*
3  * sh.h: Catch it all globals and includes file!
4  */
5 /*-
6  * Copyright (c) 1980, 1991 The Regents of the University of California.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 #ifndef _h_sh
34 #define _h_sh
35 
36 /*
37  * All xprintf with %S emit error because Char* used instead of wchar_t*
38  * WARNS doesn't help, and CFLAGS is added before -Werror, so use a
39  * pragma to turn off the format check.
40  */
41 #pragma GCC diagnostic ignored "-Wformat"
42 
43 #include "config.h"
44 
45 #include <stddef.h>
46 #include <signal.h>
47 
48 #ifdef HAVE_ICONV
49 # include <iconv.h>
50 #endif
51 
52 #ifdef HAVE_STDINT_H
53 # include <stdint.h>
54 #endif
55 
56 #ifdef HAVE_INTTYPES_H
57 # include <inttypes.h>
58 #endif
59 
60 #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && !defined(WINNT_NATIVE)
61 typedef unsigned long intptr_t;
62 #endif
63 
64 #ifndef EXTERN
65 # define EXTERN extern
66 #else /* !EXTERN */
67 # ifdef WINNT_NATIVE
68 #  define IZERO = 0
69 #  define IZERO_STRUCT = {0}
70 # endif /* WINNT_NATIVE */
71 #endif /* EXTERN */
72 
73 #ifndef IZERO
74 # define IZERO
75 #endif /* IZERO */
76 #ifndef IZERO_STRUCT
77 # define IZERO_STRUCT
78 #endif /* IZERO_STRUCT */
79 
80 #ifndef WINNT_NATIVE
81 # define INIT_ZERO
82 # define INIT_ZERO_STRUCT
83 # define force_read xread
84 #endif /*!WINNT_NATIVE */
85 
86 #if defined(KANJI) && defined(WIDE_STRINGS) && defined(HAVE_NL_LANGINFO) && defined(CODESET)
87 #define AUTOSET_KANJI
88 #endif
89 /*
90  * Sanity
91  */
92 #if defined(_POSIX_SOURCE) && !defined(POSIX)
93 # define POSIX
94 #endif
95 
96 #if defined(POSIXJOBS) && !defined(BSDJOBS)
97 # define BSDJOBS
98 #endif
99 
100 #define TMP_TEMPLATE ".XXXXXX"
101 
102 #ifdef SHORT_STRINGS
103 # ifdef WIDE_STRINGS
104 #include <wchar.h>
105 #  ifdef UTF16_STRINGS
106 typedef wint_t Char;
107 #  else
108 typedef wchar_t Char;
109 #endif
110 typedef unsigned long uChar;
111 typedef wint_t eChar; /* Can contain any Char value or CHAR_ERR */
112 #define CHAR_ERR WEOF /* Pretty please, use bit 31... */
113 #define normal_mbtowc(PWC, S, N) rt_mbtowc(PWC, S, N)
114 #define reset_mbtowc() TCSH_IGNORE(mbtowc(NULL, NULL, 0))
115 # else
116 typedef short Char;
117 typedef unsigned short uChar;
118 typedef int eChar;
119 #define CHAR_ERR (-1)
120 #define normal_mbtowc(PWC, S, N) ((void)(N), *(PWC) = (unsigned char)*(S), 1)
121 #define reset_mbtowc() ((void)0)
122 # endif
123 # define SAVE(a) (Strsave(str2short(a)))
124 #else
125 typedef char Char;
126 typedef unsigned char uChar;
127 typedef int eChar;
128 #define CHAR_ERR (-1)
129 #define normal_mbtowc(PWC, S, N) ((void)(N), *(PWC) = (unsigned char)*(S), 1)
130 #define reset_mbtowc() ((void)0)
131 # define SAVE(a) (strsave(a))
132 #endif
133 
134 #if !defined(__inline) && !defined(__GNUC__) && !defined(_MSC_VER)
135 #define __inline
136 #endif
137 /* Elide unused argument warnings */
138 #define USE(a)	(void) (a)
139 #define TCSH_IGNORE(a)	tcsh_ignore((intptr_t)a)
140 static __inline void tcsh_ignore(intptr_t a)
141 {
142     USE(a);
143 }
144 
145 /*
146  * Return true if the path is absolute
147  */
148 #if defined(WINNT_NATIVE)
149 # define ABSOLUTEP(p)	((p)[0] == '/' || \
150     (Isalpha((p)[0]) && (p)[1] == ':'))
151 #elif defined(__CYGWIN__)
152 # define ABSOLUTEP(p)	((p)[0] == '/' || \
153     (Isalpha((p)[0]) && (p)[1] == ':' && \
154      ((p)[2] == '\0' || (p)[2] == '/')))
155 #else /* !WINNT_NATIVE && !__CYGWIN__ */
156 # define ABSOLUTEP(p)	(*(p) == '/')
157 #endif /* WINNT_NATIVE || __CYGWIN__ */
158 
159 /*
160  * Fundamental definitions which may vary from system to system.
161  *
162  *	BUFSIZE		The i/o buffering size; also limits word size
163  *	MAILINTVL	How often to mailcheck; more often is more expensive
164  */
165 #ifdef BUFSIZE
166 # if	   BUFSIZE < 4096
167 #  undef   BUFSIZE
168 #  define  BUFSIZE	4096	/* buffer size should be no less than this */
169 # endif
170 #else
171 # define   BUFSIZE	4096
172 #endif /* BUFSIZE */
173 
174 #define FORKSLEEP	10	/* delay loop on non-interactive fork failure */
175 #define	MAILINTVL	600	/* 10 minutes */
176 
177 #ifndef INBUFSIZE
178 # define INBUFSIZE    2*BUFSIZE /* Num input characters on the command line */
179 #endif /* INBUFSIZE */
180 
181 
182 /*
183  * What our builtin echo looks like
184  */
185 #define NONE_ECHO	0
186 #define BSD_ECHO	1
187 #define SYSV_ECHO	2
188 #define BOTH_ECHO	(BSD_ECHO|SYSV_ECHO)
189 
190 #ifndef ECHO_STYLE
191 # if SYSVREL > 0
192 #  define ECHO_STYLE SYSV_ECHO
193 # else /* SYSVREL == 0 */
194 #  define ECHO_STYLE BSD_ECHO
195 # endif /* SYSVREL */
196 #endif /* ECHO_STYLE */
197 
198 /*
199  * The shell moves std in/out/diag and the old std input away from units
200  * 0, 1, and 2 so that it is easy to set up these standards for invoked
201  * commands.
202  */
203 #define	FSAFE	5		/* We keep the first 5 descriptors untouched */
204 #define	FSHTTY	15		/* /dev/tty when manip pgrps */
205 #define	FSHIN	16		/* Preferred desc for shell input */
206 #define	FSHOUT	17		/* ... shell output */
207 #define	FSHDIAG	18		/* ... shell diagnostics */
208 #define	FOLDSTD	19		/* ... old std input */
209 
210 #ifdef PROF
211 #define	xexit(n)	done(n)
212 #endif
213 
214 #ifdef cray
215 # define word word_t           /* sys/types.h defines word.. bad move! */
216 #endif
217 
218 #include <sys/types.h>
219 
220 #ifdef cray
221 # undef word
222 #endif
223 
224 /*
225  * Path separator in environment variables
226  */
227 #ifndef PATHSEP
228 # if defined(__EMX__) || defined(WINNT_NATIVE)
229 #  define PATHSEP ';'
230 # else /* unix */
231 #  define PATHSEP ':'
232 # endif /* __EMX__ || WINNT_NATIVE */
233 #endif /* !PATHSEP */
234 
235 #if defined(__HP_CXD_SPP) && !defined(__hpux)
236 # include <sys/cnx_stat.h>
237 # define stat stat64
238 # define fstat fstat64
239 # define lstat lstat64
240 #endif /* __HP_CXD_SPP && !__hpux */
241 
242 #ifdef HAVE_LONG_LONG
243 typedef long long tcsh_number_t;
244 #else
245 typedef long tcsh_number_t;
246 #endif
247 /*
248  * This macro compares the st_dev field of struct stat. On aix on ibmESA
249  * st_dev is a structure, so comparison does not work.
250  */
251 #ifndef DEV_DEV_COMPARE
252 # define DEV_DEV_COMPARE(x,y)   ((x) == (y))
253 #endif /* DEV_DEV_COMPARE */
254 
255 #ifdef _SEQUENT_
256 # include <sys/procstats.h>
257 #endif /* _SEQUENT_ */
258 #if (defined(POSIX) || SYSVREL > 0) && !defined(WINNT_NATIVE)
259 # include <sys/times.h>
260 #endif /* (POSIX || SYSVREL > 0) && !WINNT_NATIVE */
261 
262 #ifdef NLS
263 # include <locale.h>
264 #endif /* NLS */
265 
266 #if !defined(_MINIX) && !defined(_VMS_POSIX) && !defined(WINNT_NATIVE) && !defined(__MVS__)
267 # include <sys/param.h>
268 #endif /* !_MINIX && !_VMS_POSIX && !WINNT_NATIVE && !__MVS__ */
269 #include <sys/stat.h>
270 
271 #if defined(BSDTIMES) || defined(BSDLIMIT)
272 # include <sys/time.h>
273 # if SYSVREL>3 && !defined(SCO) && !defined(sgi) && !defined(SNI) && !defined(sun) && !(defined(__alpha) && defined(__osf__)) && !defined(_SX) && !defined(__MVS__)
274 #  include "/usr/ucbinclude/sys/resource.h"
275 # else
276 #  ifdef convex
277 #   define sysrusage cvxrusage
278 #   include <sys/sysinfo.h>
279 #  else
280 #   define sysrusage rusage
281 #   include <sys/resource.h>
282 #  endif /* convex */
283 # endif /* SYSVREL>3 */
284 #endif /* BSDTIMES */
285 
286 #ifndef WINNT_NATIVE
287 # ifndef POSIX
288 #  ifdef TERMIO
289 #   include <termio.h>
290 #  else /* SGTTY */
291 #   include <sgtty.h>
292 #  endif /* TERMIO */
293 # else /* POSIX */
294 #  ifndef _UWIN
295 #   include <termios.h>
296 #  else
297 #   include <termio.h>
298 #  endif /* _UWIN */
299 #  if SYSVREL > 3 || defined(__linux__)
300 #   undef TIOCGLTC	/* we don't need those, since POSIX has them */
301 #   undef TIOCSLTC
302 #   undef CSWTCH
303 #   define CSWTCH _POSIX_VDISABLE	/* So job control works */
304 #  endif /* SYSVREL > 3 */
305 # endif /* POSIX */
306 #endif /* WINNT_NATIVE */
307 
308 #ifdef sonyrisc
309 # include <sys/ttold.h>
310 #endif /* sonyrisc */
311 
312 #if defined(POSIX) && !defined(WINNT_NATIVE)
313 # include <unistd.h>
314 
315 /*
316  * the gcc+protoize version of <stdlib.h>
317  * redefines malloc(), so we define the following
318  * to avoid it.
319  */
320 # if defined(SYSMALLOC) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) || defined(sgi) || defined(_OSD_POSIX)
321 #  define NO_FIX_MALLOC
322 #  include <stdlib.h>
323 # else /* glibc */
324 #  define _GNU_STDLIB_H
325 #  define malloc __malloc
326 #  define free __free
327 #  define calloc __calloc
328 #  define realloc __realloc
329 #  include <stdlib.h>
330 #  undef malloc
331 #  undef free
332 #  undef calloc
333 #  undef realloc
334 # endif /* glibc || sgi */
335 #endif /* POSIX && !WINNT_NATIVE */
336 #include <limits.h>
337 
338 #if SYSVREL > 0 || defined(_IBMR2) || defined(_MINIX) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
339 # if !defined(pyr) && !defined(stellar)
340 #  include <time.h>
341 #  ifdef _MINIX
342 #   define HZ CLOCKS_PER_SEC
343 #  endif /* _MINIX */
344 # endif /* !pyr && !stellar */
345 #endif /* SYSVREL > 0 ||  _IBMR2 */
346 
347 /* In the following ifdef the DECOSF1 has been commented so that later
348  * versions of DECOSF1 will get TIOCGWINSZ. This might break older versions...
349  */
350 #if !((defined(SUNOS4) || defined(_MINIX) /* || defined(DECOSF1) */) && defined(TERMIO))
351 # if !defined(_VMS_POSIX) && !defined(WINNT_NATIVE)
352 #  include <sys/ioctl.h>
353 #  if SYSVREL > 3 || defined(__linux__)
354 #   undef TIOCGLTC	/* we don't need those, since POSIX has them */
355 #   undef TIOCSLTC
356 #   undef CSWTCH
357 #   define CSWTCH _POSIX_VDISABLE	/* So job control works */
358 #  endif /* SYSVREL > 3 */
359 # endif
360 #endif
361 
362 #if (defined(__DGUX__) && defined(POSIX)) || defined(DGUX)
363 #undef CSWTCH
364 #define CSWTCH _POSIX_VDISABLE
365 #endif
366 
367 #if (!defined(FIOCLEX) && defined(SUNOS4)) || ((SYSVREL == 4) && !defined(_SEQUENT_) && !defined(SCO) && !defined(_SX)) && !defined(__MVS__)
368 # include <sys/filio.h>
369 #endif /* (!FIOCLEX && SUNOS4) || (SYSVREL == 4 && !_SEQUENT_ && !SCO && !_SX ) */
370 
371 #if !defined(_MINIX) && !defined(supermax) && !defined(WINNT_NATIVE) && !defined(IRIS4D)
372 # include <sys/file.h>
373 #endif	/* !_MINIX && !supermax && !WINNT_NATIVE && !defined(IRIS4D) */
374 
375 #if !defined(O_RDONLY) || !defined(O_NDELAY)
376 # include <fcntl.h>
377 #endif
378 
379 #include <errno.h>
380 
381 #include <setjmp.h>
382 
383 #include <stdarg.h>
384 
385 #ifdef HAVE_DIRENT_H
386 # include <dirent.h>
387 #else
388 # ifdef HAVE_NDIR_H
389 #  include <ndir.h>
390 # else
391 #  include <sys/dir.h>
392 # endif
393 # define dirent direct
394 #endif /* HAVE_DIRENT_H */
395 #ifndef HAVE_STRUCT_DIRENT_D_INO
396 # define d_ino d_fileno
397 #endif
398 #if defined(hpux) || defined(sgi) || defined(OREO)
399 # include <stdio.h>	/* So the fgetpwent() prototypes work */
400 #endif /* hpux || sgi || OREO */
401 #ifndef WINNT_NATIVE
402 #include <pwd.h>
403 #include <grp.h>
404 #endif /* WINNT_NATIVE */
405 #ifdef HAVE_SHADOW_H
406 # include <shadow.h>
407 #endif /* HAVE_SHADOW_H */
408 #ifdef HAVE_AUTH_H
409 # include <auth.h>
410 #endif /* HAVE_AUTH_H */
411 #if defined(BSD) && !defined(POSIX)
412 # include <strings.h>
413 # define strchr(a, b) index(a, b)
414 # define strrchr(a, b) rindex(a, b)
415 #else
416 # include <string.h>
417 #endif /* BSD */
418 
419 /*
420  * IRIX-5.0 has <sys/cdefs.h>, but most system include files do not
421  * include it yet, so we include it here
422  */
423 #if defined(sgi) && SYSVREL > 3
424 # include <sys/cdefs.h>
425 #endif /* sgi && SYSVREL > 3 */
426 
427 #ifdef REMOTEHOST
428 # ifdef ISC
429 #  undef MAXHOSTNAMELEN	/* Busted headers? */
430 # endif
431 
432 # include <netinet/in.h>
433 # include <arpa/inet.h>
434 # include <sys/socket.h>
435 # if (defined(_SS_SIZE) || defined(_SS_MAXSIZE)) && defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY)
436 #  if !defined(__APPLE__) /* Damnit, where is getnameinfo() folks? */
437 #   if !defined(sgi)
438 #    if !defined(__CYGWIN__)
439 #     define INET6
440 #    endif /* __CYGWIN__ */
441 #   endif /* sgi */
442 #  endif /* __APPLE__ */
443 # endif
444 # include <sys/uio.h>	/* For struct iovec */
445 #endif /* REMOTEHOST */
446 
447 #ifdef PURIFY
448 /* exit normally, allowing purify to trace leaks */
449 # define _exit		exit
450 typedef  int		pret_t;
451 #else /* !PURIFY */
452 /*
453  * If your compiler complains, then you can either
454  * throw it away and get gcc or, use the following define
455  * and get rid of the typedef.
456  * [The 4.2/3BSD vax compiler does not like that]
457  * Both MULTIFLOW and PCC compilers exhbit this bug.  -- sterling@netcom.com
458  */
459 # if (defined(vax) || defined(uts) || defined(MULTIFLOW) || defined(PCC)) && !defined(__GNUC__)
460 #  define pret_t void
461 # else /* !((vax || uts || MULTIFLOW || PCC) && !__GNUC__) */
462 typedef void pret_t;
463 # endif /* (vax || uts || MULTIFLOW || PCC) && !__GNUC__ */
464 #endif /* PURIFY */
465 
466 /*
467  * ASCII vs. EBCDIC
468  */
469 #if 'Z' - 'A' == 25
470 # ifndef IS_ASCII
471 #  define IS_ASCII
472 # endif
473 #endif
474 
475 #include "sh.types.h"
476 
477 #if !HAVE_DECL_GETPGRP
478 # ifndef GETPGRP_VOID
479 extern pid_t getpgrp (int);
480 # else
481 extern pid_t getpgrp (void);
482 # endif
483 #endif
484 
485 #ifndef lint
486 typedef ptr_t memalign_t;
487 #else
488 typedef union {
489     char    am_char, *am_char_p;
490     short   am_short, *am_short_p;
491     int     am_int, *am_int_p;
492     long    am_long, *am_long_p;
493     float   am_float, *am_float_p;
494     double  am_double, *am_double_p;
495 }      *memalign_t;
496 
497 # define malloc		lint_malloc
498 # define free		lint_free
499 # define realloc	lint_realloc
500 # define calloc		lint_calloc
501 #endif
502 
503 #ifdef SYSMALLOC
504 # define xmalloc(i)	smalloc(i)
505 # define xrealloc(p, i)	srealloc(p, i)
506 # define xcalloc(n, s)	scalloc(n, s)
507 # define xfree		sfree
508 #else
509 # define xmalloc(i)  	malloc(i)
510 # define xrealloc(p, i)	realloc(p, i)
511 # define xcalloc(n, s)	calloc(n, s)
512 # define xfree	 	free
513 #endif /* SYSMALLOC */
514 #include "sh.char.h"
515 #include "sh.err.h"
516 #include "sh.dir.h"
517 #include "sh.proc.h"
518 
519 #include "pathnames.h"
520 
521 
522 /*
523  * C shell
524  *
525  * Bill Joy, UC Berkeley
526  * October, 1978; May 1980
527  *
528  * Jim Kulp, IIASA, Laxenburg Austria
529  * April, 1980
530  */
531 
532 #ifdef HESIOD
533 # include <hesiod.h>
534 #endif /* HESIOD */
535 
536 #ifdef REMOTEHOST
537 # include <netdb.h>
538 #endif /* REMOTEHOST */
539 
540 #ifndef MAXHOSTNAMELEN
541 # ifdef HOST_NAME_MAX
542 #  define MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
543 # elif defined(SCO) && (SYSVREL > 3)
544 #  include <sys/socket.h>
545 # else
546 #  define MAXHOSTNAMELEN 256
547 # endif
548 #endif /* MAXHOSTNAMELEN */
549 
550 
551 
552 #define	eq(a, b)	(Strcmp(a, b) == 0)
553 
554 /* globone() flags */
555 #define G_ERROR		0	/* default action: error if multiple words */
556 #define G_IGNORE	1	/* ignore the rest of the words		   */
557 #define G_APPEND	2	/* make a sentence by cat'ing the words    */
558 
559 /*
560  * Global flags
561  */
562 EXTERN int    chkstop IZERO;	/* Warned of stopped jobs... allow exit */
563 
564 #if (defined(FIOCLEX) && defined(FIONCLEX)) || defined(F_SETFD)
565 # define CLOSE_ON_EXEC
566 #else
567 EXTERN int    didcch IZERO;	/* Have closed unused fd's for child */
568 #endif /* (FIOCLEX && FIONCLEX) || F_SETFD */
569 
570 EXTERN int    didfds IZERO;	/* Have setup i/o fd's for child */
571 EXTERN int    doneinp IZERO;	/* EOF indicator after reset from readc */
572 EXTERN int    exiterr IZERO;	/* Exit if error or non-zero exit status */
573 EXTERN int    child IZERO;	/* Child shell ... errors cause exit */
574 EXTERN int    haderr IZERO;	/* Reset was because of an error */
575 EXTERN int    intty IZERO;	/* Input is a tty */
576 EXTERN int    intact IZERO;	/* We are interactive... therefore prompt */
577 EXTERN int    justpr IZERO;	/* Just print because of :p hist mod */
578 EXTERN int    loginsh IZERO;	/* We are a loginsh -> .login/.logout */
579 EXTERN int    neednote IZERO;	/* Need to pnotify() */
580 EXTERN int    noexec IZERO;	/* Don't execute, just syntax check */
581 EXTERN int    pjobs IZERO;	/* want to print jobs if interrupted */
582 EXTERN int    setintr IZERO;	/* Set interrupts on/off -> Wait intr... */
583 EXTERN int    handle_intr IZERO;/* Are we currently handling an interrupt? */
584 EXTERN int    havhash IZERO;	/* path hashing is available */
585 EXTERN int    editing IZERO;	/* doing filename expansion and line editing */
586 EXTERN int    noediting IZERO;	/* initial $term defaulted to noedit */
587 EXTERN int    bslash_quote IZERO;/* PWP: tcsh-style quoting?  (in sh.c) */
588 EXTERN int    anyerror IZERO;	/* propagate errors from pipelines/backq */
589 EXTERN int    compat_expr IZERO;/* csh-style expressions? */
590 EXTERN int    isoutatty IZERO;	/* is SHOUT a tty */
591 EXTERN int    isdiagatty IZERO;/* is SHDIAG a tty */
592 EXTERN int    is1atty IZERO;	/* is file descriptor 1 a tty (didfds mode) */
593 EXTERN int    is2atty IZERO;	/* is file descriptor 2 a tty (didfds mode) */
594 EXTERN int    arun IZERO;	/* Currently running multi-line-aliases */
595 EXTERN int     implicit_cd IZERO;/* implicit cd enabled?(1=enabled,2=verbose) */
596 EXTERN int    inheredoc IZERO;	/* Currently parsing a heredoc */
597 /* We received a window change event */
598 EXTERN volatile sig_atomic_t windowchg IZERO;
599 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
600 EXTERN int    dspmbyte_ls;
601 #endif
602 
603 /*
604  * Global i/o info
605  */
606 EXTERN Char   *arginp IZERO;	/* Argument input for sh -c and internal `xx` */
607 EXTERN int     onelflg IZERO;	/* 2 -> need line for -t, 1 -> exit on read */
608 extern Char   *ffile;		/* Name of shell file for $0 */
609 extern int    dolzero;		/* if $?0 should return true... */
610 
611 extern char *seterr;		/* Error message from scanner/parser */
612 #ifndef errno
613 extern int errno;		/* Error from C library routines */
614 #endif
615 extern int exitset;
616 /* Temp name for << shell files in /tmp, for xfree() */
617 EXTERN Char   *shtemp IZERO;
618 
619 #ifdef BSDTIMES
620 EXTERN struct timeval time0;	/* Time at which the shell started */
621 EXTERN struct sysrusage ru0;
622 #else
623 # ifdef _SEQUENT_
624 EXTERN timeval_t time0;		/* time at which shell started */
625 EXTERN struct process_stats ru0;
626 # else /* _SEQUENT_ */
627 #  ifndef POSIX
628 EXTERN time_t  time0;		/* time at which shell started */
629 #  else	/* POSIX */
630 EXTERN clock_t time0;		/* time at which shell started */
631 EXTERN clock_t clk_tck;
632 #  endif /* POSIX */
633 EXTERN struct tms shtimes;	/* shell and child times for process timing */
634 # endif /* _SEQUENT_ */
635 EXTERN time_t seconds0;
636 #endif /* BSDTIMES */
637 
638 #ifndef HZ
639 # define HZ	100		/* for division into seconds */
640 #endif
641 
642 /*
643  * Miscellany
644  */
645 EXTERN Char   *doldol;		/* Character pid for $$ */
646 EXTERN pid_t   backpid;		/* pid of the last background job */
647 
648 /*
649  * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now
650  * cause pid's could be unsigned and that would break our -1 flag, and
651  * uid_t and gid_t are not defined in all the systems so I would have to
652  * make special cases for them. In the future...
653  */
654 EXTERN uid_t   uid, euid; 	/* Invokers real and effective */
655 EXTERN gid_t   gid, egid;	/* User and group ids */
656 EXTERN pid_t   opgrp,		/* Initial pgrp and tty pgrp */
657                shpgrp,		/* Pgrp of shell */
658                tpgrp;		/* Terminal process group */
659 				/* If tpgrp is -1, leave tty alone! */
660 
661 EXTERN Char   *Prompt;		/* The actual printed prompt or NULL */
662 EXTERN Char   *RPrompt;		/* Right-hand side prompt or NULL */
663 
664 /*
665  * To be able to redirect i/o for builtins easily, the shell moves the i/o
666  * descriptors it uses away from 0,1,2.
667  * Ideally these should be in units which are closed across exec's
668  * (this saves work) but for version 6, this is not usually possible.
669  * The desired initial values for these descriptors are defined in
670  * sh.local.h.
671  */
672 EXTERN int   SHIN IZERO;	/* Current shell input (script) */
673 EXTERN int   SHOUT IZERO;	/* Shell output */
674 EXTERN int   SHDIAG IZERO;	/* Diagnostic output... shell errs go here */
675 EXTERN int   OLDSTD IZERO;	/* Old standard input (def for cmds) */
676 
677 
678 #if (SYSVREL == 4 && defined(_UTS)) || defined(__linux__)
679 /*
680  * From: fadden@uts.amdahl.com (Andy McFadden)
681  * we need sigsetjmp for UTS4, but not UTS2.1
682  */
683 # define SIGSETJMP
684 #endif
685 
686 /*
687  * Error control
688  *
689  * Errors in scanning and parsing set up an error message to be printed
690  * at the end and complete.  Other errors always cause a reset.
691  * Because of source commands and .cshrc we need nested error catches.
692  */
693 
694 #ifdef SIGSETJMP
695    typedef struct { sigjmp_buf j; } jmp_buf_t;
696 # define setexit()  sigsetjmp(reslab.j, 1)
697 # define _reset()    siglongjmp(reslab.j, 1)
698 #else
699    typedef struct { jmp_buf j; } jmp_buf_t;
700 # define setexit()  setjmp(reslab.j)
701 # define _reset()    longjmp(reslab.j, 1)
702 #endif
703 
704 #define getexit(a) (void) ((a) = reslab)
705 #define resexit(a) (void) (reslab = (a))
706 
707 #define cpybin(a, b) (void) ((a) = (b))
708 
709 extern jmp_buf_t reslab;
710 
711 EXTERN Char   *gointr;		/* Label for an onintr transfer */
712 
713 extern struct sigaction parintr;	/* Parents interrupt catch */
714 extern struct sigaction parterm;	/* Parents terminate catch */
715 
716 /*
717  * Lexical definitions.
718  *
719  * All lexical space is allocated dynamically.
720  * The eighth/sixteenth bit of characters is used to prevent recognition,
721  * and eventually stripped.
722  */
723 #define		META		0200
724 #define		ASCII		0177
725 #ifdef WIDE_STRINGS		/* Implies SHORT_STRINGS */
726 /* 31st char bit used for 'ing (not 32nd, we want all values nonnegative) */
727 # define	QUOTE		0x40000000
728 # define	TRIM		0x3FFFFFFF /* Mask to strip quote bit */
729 # define	UNDER		0x08000000 /* Underline flag */
730 # define	BOLD		0x04000000 /* Bold flag */
731 # define	STANDOUT	0x02000000 /* Standout flag */
732 # define	LITERAL		0x01000000 /* Literal character flag */
733 # define	ATTRIBUTES	0x0F000000 /* The bits used for attributes */
734 # define	INVALID_BYTE	0x00800000 /* Invalid character on input */
735 # ifdef SOLARIS2
736 #  define	CHAR		0x30FFFFFF /* Mask to mask out the character */
737 # else
738 #  define	CHAR		0x00FFFFFF /* Mask to mask out the character */
739 # endif
740 #elif defined (SHORT_STRINGS)
741 # define	QUOTE 	((Char)	0100000)/* 16nth char bit used for 'ing */
742 # define	TRIM		0073777	/* Mask to strip quote/lit bit */
743 # define	UNDER		0040000	/* Underline flag */
744 # define	BOLD		0020000	/* Bold flag */
745 # define	STANDOUT	0010000	/* Standout flag */
746 # define	LITERAL		0004000	/* Literal character flag */
747 # define	ATTRIBUTES	0074000	/* The bits used for attributes */
748 # define	INVALID_BYTE	0
749 # define	CHAR		0000377	/* Mask to mask out the character */
750 #else
751 # define	QUOTE 	((Char)	0200)	/* Eighth char bit used for 'ing */
752 # define	TRIM		0177	/* Mask to strip quote bit */
753 # define	UNDER		0000000	/* No extra bits to do both */
754 # define	BOLD		0000000	/* Bold flag */
755 # define	STANDOUT	META	/* Standout flag */
756 # define	LITERAL		0000000	/* Literal character flag */
757 # define	ATTRIBUTES	0200	/* The bits used for attributes */
758 # define	INVALID_BYTE	0
759 # define	CHAR		0000177	/* Mask to mask out the character */
760 #endif
761 #define		CHAR_DBWIDTH	(LITERAL|(LITERAL-1))
762 
763 EXTERN int     AsciiOnly;	/* If set only 7 bits expected in characters */
764 
765 /*
766  * Each level of input has a buffered input structure.
767  * There are one or more blocks of buffered input for each level,
768  * exactly one if the input is seekable and tell is available.
769  * In other cases, the shell buffers enough blocks to keep all loops
770  * in the buffer.
771  *
772  * If (WIDE_STRINGS && cantell), fbobp is always a byte offset, but
773  * (fseekp - fbobp) and (feobp - fbobp) are character offsets (usable for
774  * fbuf indexing).
775  *
776  * If (!cantell), all offsets are character offsets; if (!WIDE_STRINGS), there
777  * is no difference between byte and character offsets.
778  */
779 EXTERN struct Bin {
780     off_t   Bfseekp;		/* Seek pointer, generally != lseek() value */
781     off_t   Bfbobp;		/* Seekp of beginning of buffers */
782     off_t   Bfeobp;		/* Seekp of end of buffers */
783     int     Bfblocks;		/* Number of buffer blocks */
784     Char  **Bfbuf;		/* The array of buffer blocks */
785 #ifdef WIDE_STRINGS
786     /* Number of bytes in each character if (cantell) */
787     unsigned char Bfclens[BUFSIZE + 1];
788 #endif
789 }       B;
790 
791 /*
792  * This structure allows us to seek inside aliases
793  */
794 struct Ain {
795     int type;
796 #define TCSH_I_SEEK 	 0		/* Invalid seek */
797 #define TCSH_A_SEEK	 1		/* Alias seek */
798 #define TCSH_F_SEEK	 2		/* File seek */
799 #define TCSH_E_SEEK	 3		/* Eval seek */
800     union {
801 	off_t _f_seek;		/* A byte offset if (cantell) */
802 	Char* _c_seek;
803     } fc;
804 #define f_seek fc._f_seek
805 #define c_seek fc._c_seek
806     Char **a_seek;
807 } ;
808 
809 extern int aret;		/* Type of last char returned */
810 #define SEEKEQ(a, b) ((a)->type == (b)->type && \
811 		      (a)->f_seek == (b)->f_seek && \
812 		      (a)->a_seek == (b)->a_seek)
813 
814 #define	fseekp	B.Bfseekp
815 #define	fbobp	B.Bfbobp
816 #define	feobp	B.Bfeobp
817 #define	fblocks	B.Bfblocks
818 #define	fbuf	B.Bfbuf
819 #define fclens  B.Bfclens
820 
821 /*
822  * The shell finds commands in loops by reseeking the input
823  * For whiles, in particular, it reseeks to the beginning of the
824  * line the while was on; hence the while placement restrictions.
825  */
826 EXTERN struct Ain lineloc;
827 
828 EXTERN int    cantell;		/* Is current source tellable ? */
829 
830 /*
831  * Input lines are parsed into doubly linked circular
832  * lists of words of the following form.
833  */
834 struct wordent {
835     Char   *word;
836     struct wordent *prev;
837     struct wordent *next;
838 };
839 
840 /*
841  * During word building, both in the initial lexical phase and
842  * when expanding $ variable substitutions, expansion by `!' and `$'
843  * must be inhibited when reading ahead in routines which are themselves
844  * processing `!' and `$' expansion or after characters such as `\' or in
845  * quotations.  The following flags are passed to the getC routines
846  * telling them which of these substitutions are appropriate for the
847  * next character to be returned.
848  */
849 #define	DODOL	1
850 #define	DOEXCL	2
851 #define	DOALL	DODOL|DOEXCL
852 
853 /*
854  * Labuf implements a general buffer for lookahead during lexical operations.
855  * Text which is to be placed in the input stream can be stuck here.
856  * We stick parsed ahead $ constructs during initial input,
857  * process id's from `$$', and modified variable values (from qualifiers
858  * during expansion in sh.dol.c) here.
859  */
860 extern struct Strbuf labuf;
861 EXTERN size_t lap; /* N/A if == labuf.len, index into labuf.s otherwise */
862 
863 /*
864  * Parser structure
865  *
866  * Each command is parsed to a tree of command structures and
867  * flags are set bottom up during this process, to be propagated down
868  * as needed during the semantics/exeuction pass (sh.sem.c).
869  */
870 struct command {
871     unsigned char   t_dtyp;	/* Type of node 		 */
872 #define	NODE_COMMAND	1	/* t_dcom <t_dlef >t_drit	 */
873 #define	NODE_PAREN	2	/* ( t_dspr ) <t_dlef >t_drit	 */
874 #define	NODE_PIPE	3	/* t_dlef | t_drit		 */
875 #define	NODE_LIST	4	/* t_dlef ; t_drit		 */
876 #define	NODE_OR		5	/* t_dlef || t_drit		 */
877 #define	NODE_AND	6	/* t_dlef && t_drit		 */
878     unsigned char   t_nice;	/* Nice value			 */
879 #ifdef apollo
880     unsigned char   t_systype;	/* System environment		 */
881 #endif
882     unsigned long   t_dflg;	/* Flags, e.g. F_AMPERSAND|... 	 */
883 /* save these when re-doing 	 */
884 #ifndef apollo
885 #define	F_SAVE	(F_NICE|F_TIME|F_NOHUP|F_HUP)
886 #else
887 #define	F_SAVE	(F_NICE|F_TIME|F_NOHUP||F_HUP|F_VER)
888 #endif
889 #define	F_AMPERSAND	(1<<0)	/* executes in background	 */
890 #define	F_APPEND	(1<<1)	/* output is redirected >>	 */
891 #define	F_PIPEIN	(1<<2)	/* input is a pipe		 */
892 #define	F_PIPEOUT	(1<<3)	/* output is a pipe		 */
893 #define	F_NOFORK	(1<<4)	/* don't fork, last ()ized cmd	 */
894 #define	F_NOINTERRUPT	(1<<5)	/* should be immune from intr's */
895 /* spare */
896 #define	F_STDERR	(1<<7)	/* redirect unit 2 with unit 1	 */
897 #define	F_OVERWRITE	(1<<8)	/* output was !			 */
898 #define	F_READ		(1<<9)	/* input redirection is <<	 */
899 #define	F_REPEAT	(1<<10)	/* reexec aft if, repeat,...	 */
900 #define	F_NICE		(1<<11)	/* t_nice is meaningful 	 */
901 #define	F_NOHUP		(1<<12)	/* nohup this command 		 */
902 #define	F_TIME		(1<<13)	/* time this command 		 */
903 #define F_BACKQ		(1<<14)	/* command is in ``		 */
904 #define F_HUP		(1<<15)	/* hup this command		 */
905 #ifdef apollo
906 #define F_VER		(1<<16)	/* execute command under SYSTYPE */
907 #endif
908     union {
909 	Char   *T_dlef;		/* Input redirect word 		 */
910 	struct command *T_dcar;	/* Left part of list/pipe 	 */
911     }       L;
912     union {
913 	Char   *T_drit;		/* Output redirect word 	 */
914 	struct command *T_dcdr;	/* Right part of list/pipe 	 */
915     }       R;
916 #define	t_dlef	L.T_dlef
917 #define	t_dcar	L.T_dcar
918 #define	t_drit	R.T_drit
919 #define	t_dcdr	R.T_dcdr
920     Char  **t_dcom;		/* Command/argument vector 	 */
921     struct command *t_dspr;	/* Pointer to ()'d subtree 	 */
922 };
923 
924 
925 /*
926  * The keywords for the parser
927  */
928 #define	TC_BREAK	0
929 #define	TC_BRKSW	1
930 #define	TC_CASE		2
931 #define	TC_DEFAULT 	3
932 #define	TC_ELSE		4
933 #define	TC_END		5
934 #define	TC_ENDIF	6
935 #define	TC_ENDSW	7
936 #define	TC_EXIT		8
937 #define	TC_FOREACH	9
938 #define	TC_GOTO		10
939 #define	TC_IF		11
940 #define	TC_LABEL	12
941 #define	TC_LET		13
942 #define	TC_SET		14
943 #define	TC_SWITCH	15
944 #define	TC_TEST		16
945 #define	TC_THEN		17
946 #define	TC_WHILE	18
947 
948 /*
949  * These are declared here because they want to be
950  * initialized in sh.init.c (to allow them to be made readonly)
951  */
952 
953 #if defined(hpux) && defined(__STDC__) && !defined(__GNUC__)
954     /* Avoid hpux ansi mode spurious warnings */
955 typedef void (*bfunc_t) ();
956 #else
957 typedef void (*bfunc_t) (Char **, struct command *);
958 #endif /* hpux && __STDC__ && !__GNUC__ */
959 
960 extern const struct biltins {
961     const char   *bname;
962     bfunc_t bfunct;
963     int     minargs, maxargs;
964 } bfunc[];
965 extern int nbfunc;
966 #ifdef WINNT_NATIVE
967 extern struct biltins  nt_bfunc[];
968 extern int nt_nbfunc;
969 #endif /* WINNT_NATIVE*/
970 extern int bequiet;
971 
972 extern struct srch {
973     const char *s_name;
974     int  s_value;
975 } srchn[];
976 extern int nsrchn;
977 
978 /*
979  * Structure defining the existing while/foreach loops at this
980  * source level.  Loops are implemented by seeking back in the
981  * input.  For foreach (fe), the word list is attached here.
982  */
983 EXTERN struct whyle {
984     struct Ain   w_start;	/* Point to restart loop */
985     struct Ain   w_end;		/* End of loop (0 if unknown) */
986     Char  **w_fe, **w_fe0;	/* Current/initial wordlist for fe */
987     Char   *w_fename;		/* Name for fe */
988     struct whyle *w_next;	/* Next (more outer) loop */
989 }      *whyles;
990 
991 /*
992  * Variable structure
993  *
994  * Aliases and variables are stored in AVL balanced binary trees.
995  */
996 EXTERN struct varent {
997     Char  **vec;		/* Array of words which is the value */
998     Char   *v_name;		/* Name of variable/alias */
999     int	    v_flags;		/* Flags */
1000 #define VAR_ALL		-1
1001 #define VAR_READONLY	1
1002 #define VAR_READWRITE	2
1003 #define VAR_NOGLOB	4
1004 #define VAR_FIRST       32
1005 #define VAR_LAST        64
1006     struct varent *v_link[3];	/* The links, see below */
1007     int     v_bal;		/* Balance factor */
1008 }       shvhed IZERO_STRUCT, aliases IZERO_STRUCT;
1009 
1010 #define v_left		v_link[0]
1011 #define v_right		v_link[1]
1012 #define v_parent	v_link[2]
1013 
1014 #define adrof(v)	adrof1(v, &shvhed)
1015 #define varval(v)	value1(v, &shvhed)
1016 
1017 /*
1018  * The following are for interfacing redo substitution in
1019  * aliases to the lexical routines.
1020  */
1021 EXTERN struct wordent *alhistp IZERO_STRUCT;/* Argument list (first) */
1022 EXTERN struct wordent *alhistt IZERO_STRUCT;/* Node after last in arg list */
1023 EXTERN Char  **alvec IZERO_STRUCT,
1024 	      *alvecp IZERO_STRUCT;/* The (remnants of) alias vector */
1025 
1026 /*
1027  * Filename/command name expansion variables
1028  */
1029 
1030 #ifdef __CYGWIN__
1031 # undef MAXPATHLEN
1032 #endif /* __CYGWIN__ */
1033 
1034 #ifndef MAXPATHLEN
1035 # ifdef PATH_MAX
1036 #  define MAXPATHLEN PATH_MAX
1037 # else
1038 #  define MAXPATHLEN 2048
1039 # endif
1040 #endif /* MAXPATHLEN */
1041 
1042 #ifndef HAVENOLIMIT
1043 /*
1044  * resource limits
1045  */
1046 extern struct limits {
1047     int         limconst;
1048     const char *limname;
1049     int         limdiv;
1050     const char *limscale;
1051 } limits[];
1052 #endif /* !HAVENOLIMIT */
1053 
1054 /*
1055  * History list
1056  *
1057  * Each history list entry contains an embedded wordlist
1058  * from the scanner, a number for the event, and a reference count
1059  * to aid in discarding old entries.
1060  *
1061  * Essentially "invisible" entries are put on the history list
1062  * when history substitution includes modifiers, and thrown away
1063  * at the next discarding since their event numbers are very negative.
1064  */
1065 EXTERN struct Hist {
1066     struct wordent Hlex;
1067     int     Hnum;		 /* eventno when inserted into history list  */
1068     int     Href;
1069     time_t  Htime;
1070     Char   *histline;
1071     struct Hist *Hnext, *Hprev;         /* doubly linked list */
1072     unsigned Hhash;                     /* hash value of command line */
1073 }       Histlist IZERO_STRUCT;
1074 
1075 EXTERN struct wordent paraml;	/* Current lexical word list */
1076 EXTERN int     eventno;		/* Next events number */
1077 EXTERN int     lastev;		/* Last event reference (default) */
1078 
1079 EXTERN Char    HIST;		/* history invocation character */
1080 EXTERN Char    HISTSUB;		/* auto-substitute character */
1081 EXTERN Char    PRCH;		/* Prompt symbol for regular users */
1082 EXTERN Char    PRCHROOT;	/* Prompt symbol for root */
1083 
1084 /*
1085  * For operating systems with single case filenames (OS/2)
1086  */
1087 #ifdef CASE_INSENSITIVE
1088 # ifdef WIDE_STRINGS
1089 #  define samecase(x) (towlower(x))
1090 # else
1091 #  define samecase(x) (isupper((unsigned char)(x)) ? \
1092 		       tolower((unsigned char)(x)) : (x))
1093 # endif
1094 #else
1095 # define samecase(x) (x)
1096 #endif /* CASE_INSENSITIVE */
1097 
1098 /*
1099  * strings.h:
1100  */
1101 #ifndef SHORT_STRINGS
1102 #define Strchr(a, b)  		strchr(a, b)
1103 #define Strrchr(a, b)  		strrchr(a, b)
1104 #define Strcat(a, b)  		strcat(a, b)
1105 #define Strncat(a, b, c) 	strncat(a, b, c)
1106 #define Strcpy(a, b)  		strcpy(a, b)
1107 #define Strncpy(a, b, c) 	strncpy(a, b, c)
1108 #define Strlen(a)		strlen(a)
1109 #define Strcmp(a, b)		strcmp(a, b)
1110 #define Strncmp(a, b, c)	strncmp(a, b, c)
1111 #define Strcasecmp(a, b)	strcasecmp(a, b)
1112 
1113 #define Strspl(a, b)		strspl(a, b)
1114 #define Strnsave(a, b)		strnsave(a, b)
1115 #define Strsave(a)		strsave(a)
1116 #define Strend(a)		strend(a)
1117 #define Strstr(a, b)		strstr(a, b)
1118 
1119 #define str2short(a) 		(a)
1120 #define blk2short(a) 		saveblk(a)
1121 #define short2blk(a) 		saveblk(a)
1122 #define short2str(a) 		caching_strip(a)
1123 #else
1124 #if defined(WIDE_STRINGS) && !defined(UTF16_STRINGS)
1125 #define Strchr(a, b)		wcschr(a, b)
1126 #define Strrchr(a, b)		wcsrchr(a, b)
1127 #define Strcat(a, b)  		wcscat(a, b)
1128 #define Strncat(a, b, c) 	wcsncat(a, b, c)
1129 #define Strcpy(a, b)  		wcscpy(a, b)
1130 #define Strncpy(a, b, c)	wcsncpy(a, b, c)
1131 #define Strlen(a)		wcslen(a)
1132 #define Strcmp(a, b)		wcscmp(a, b)
1133 #define Strncmp(a, b, c)	wcsncmp(a, b, c)
1134 #else
1135 #define Strchr(a, b)		s_strchr(a, b)
1136 #define Strrchr(a, b) 		s_strrchr(a, b)
1137 #define Strcat(a, b)  		s_strcat(a, b)
1138 #define Strncat(a, b, c) 	s_strncat(a, b, c)
1139 #define Strcpy(a, b)  		s_strcpy(a, b)
1140 #define Strncpy(a, b, c)	s_strncpy(a, b, c)
1141 #define Strlen(a)		s_strlen(a)
1142 #define Strcmp(a, b)		s_strcmp(a, b)
1143 #define Strncmp(a, b, c)	s_strncmp(a, b, c)
1144 #endif
1145 #define Strcasecmp(a, b)	s_strcasecmp(a, b)
1146 
1147 #define Strspl(a, b)		s_strspl(a, b)
1148 #define Strnsave(a, b)		s_strnsave(a, b)
1149 #define Strsave(a)		s_strsave(a)
1150 #define Strend(a)		s_strend(a)
1151 #define Strstr(a, b)		s_strstr(a, b)
1152 #endif
1153 
1154 /*
1155  * setname is a macro to save space (see sh.err.c)
1156  */
1157 EXTERN const char   *bname;
1158 
1159 #define	setname(a)	(bname = (a))
1160 
1161 #ifdef VFORK
1162 EXTERN Char   *Vsav;
1163 EXTERN Char   *Vdp;
1164 EXTERN Char   *Vexpath;
1165 EXTERN char  **Vt;
1166 #endif /* VFORK */
1167 
1168 EXTERN Char  **evalvec;
1169 EXTERN Char   *evalp;
1170 
1171 extern struct mesg {
1172     const char   *iname;	/* name from /usr/include */
1173     const char *pname;		/* print name */
1174 } mesg[];
1175 
1176 /* word_chars is set by default to WORD_CHARS but can be overridden by
1177    the worchars variable--if unset, reverts to WORD_CHARS */
1178 
1179 EXTERN Char   *word_chars;
1180 
1181 #define WORD_CHARS "*?_-.[]~="	/* default chars besides alnums in words */
1182 
1183 EXTERN Char   *STR_SHELLPATH;
1184 
1185 #ifdef _PATH_BSHELL
1186 EXTERN Char   *STR_BSHELL;
1187 #endif
1188 EXTERN Char   *STR_WORD_CHARS;
1189 EXTERN Char  **STR_environ IZERO;
1190 
1191 extern int     dont_free;	/* Tell free that we are in danger if we free */
1192 
1193 extern Char    *INVPTR;
1194 extern Char    **INVPPTR;
1195 
1196 extern char    *progname;
1197 extern int	tcsh;
1198 extern int	xlate_cr;
1199 extern int	output_raw;
1200 extern int	lbuffed;
1201 extern time_t	Htime;
1202 extern int	numeof;
1203 extern int 	insource;
1204 extern char	linbuf[];
1205 extern char 	*linp;
1206 extern int	nsig;
1207 #ifdef VFORK
1208 extern int	use_fork;
1209 #endif
1210 extern int	tellwhat;
1211 extern int	NoNLSRebind;
1212 #if !HAVE_DECL_ENVIRON
1213 extern char   **environ;
1214 #endif
1215 
1216 #include "tc.h"
1217 
1218 #ifndef WINNT_NATIVE
1219 # ifdef NLS_CATALOGS
1220 #  ifdef HAVE_FEATURES_H
1221 #   include <features.h>
1222 #  endif
1223 #  ifdef HAVE_NL_LANGINFO
1224 #   include <langinfo.h>
1225 #  endif
1226 #  ifdef __uxps__
1227 #   define gettxt gettxt_ds
1228 #  endif
1229 #  include <nl_types.h>
1230 #  ifdef __uxps__
1231 #   undef gettxt
1232 #  endif
1233 EXTERN nl_catd catd;
1234 #  if defined(HAVE_ICONV) && defined(HAVE_NL_LANGINFO)
1235 #   define CGETS(b, c, d)	iconv_catgets(catd, b, c, d)
1236 #  else
1237 #   define CGETS(b, c, d)	xcatgets(catd, b, c, d)
1238 #  endif
1239 #  define CSAVS(b, c, d)	strsave(CGETS(b, c, d))
1240 # else
1241 #  define CGETS(b, c, d)	d
1242 #  define CSAVS(b, c, d)	d
1243 # endif
1244 #else /* WINNT_NATIVE */
1245 # define CGETS(b, c, d)	nt_cgets( b, c, d)
1246 # define CSAVS(b, c, d)	strsave(CGETS(b, c, d))
1247 #endif /* WINNT_NATIVE */
1248 
1249 #if defined(FILEC)
1250 extern int    filec;
1251 #endif /* FILEC */
1252 
1253 #include "sh.decls.h"
1254 /*
1255  * Since on some machines characters are unsigned, and the signed
1256  * keyword is not universally implemented, we treat all characters
1257  * as unsigned and sign extend them where we need.
1258  */
1259 #define SIGN_EXTEND_CHAR(a)	(((a) & 0x80) ? ((a) | ~0x7f) : (a))
1260 
1261 /*
1262  * explanation for use by the "--help" option
1263  */
1264 #define HELP_STRING "\
1265 -b file		batch mode, read and execute commands from `file' \n\
1266 -c command	run `command' from next argument \n\
1267 -d		load directory stack from `~/.cshdirs' \n\
1268 -Dname[=value]	define environment variable `name' to `value' (DomainOS only) \n\
1269 -e		exit on any error \n\
1270 -f		start faster by ignoring the start-up file \n\
1271 -F		use fork() instead of vfork() when spawning (ConvexOS only) \n\
1272 -i		interactive, even when input is not from a terminal \n\
1273 -l		act as a login shell, must be the only option specified \n\
1274 -m		load the start-up file, whether or not owned by effective user \n\
1275 -n file		no execute mode, just check syntax of the following `file' \n\
1276 -q		accept SIGQUIT for running under a debugger \n\
1277 -s		read commands from standard input \n\
1278 -t		read one line from standard input \n\
1279 -v		echo commands after history substitution \n\
1280 -V		like -v but including commands read from the start-up file \n\
1281 -x		echo commands immediately before execution \n\
1282 -X		like -x but including commands read from the start-up file \n\
1283 --help		print this message and exit \n\
1284 --version	print the version shell variable and exit \n\
1285 \nSee the tcsh(1) manual page for detailed information.\n"
1286 
1287 #include "tc.nls.h"
1288 
1289 #endif /* _h_sh */
1290