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