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