]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/tcsh/sh.h
MFC r315948:
[FreeBSD/stable/10.git] / contrib / tcsh / sh.h
1 /* $Header: /p/tcsh/cvsroot/tcsh/sh.h,v 3.178 2016/09/12 16:33:54 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 /* values for noclobber */
197 #define NOCLOBBER_DEFAULT  1
198 #define NOCLOBBER_NOTEMPTY 2
199 #define NOCLOBBER_ASK      4
200
201 /*
202  * The shell moves std in/out/diag and the old std input away from units
203  * 0, 1, and 2 so that it is easy to set up these standards for invoked
204  * commands.
205  */
206 #define FSAFE   5               /* We keep the first 5 descriptors untouched */
207 #define FSHTTY  15              /* /dev/tty when manip pgrps */
208 #define FSHIN   16              /* Preferred desc for shell input */
209 #define FSHOUT  17              /* ... shell output */
210 #define FSHDIAG 18              /* ... shell diagnostics */
211 #define FOLDSTD 19              /* ... old std input */
212
213 #ifdef PROF
214 #define xexit(n)        done(n)
215 #endif 
216
217 #ifdef cray
218 # define word word_t           /* sys/types.h defines word.. bad move! */
219 #endif
220
221 #include <sys/types.h>
222
223 #ifdef cray
224 # undef word
225 #endif 
226
227 /* 
228  * Path separator in environment variables
229  */
230 #ifndef PATHSEP
231 # if defined(__EMX__) || defined(WINNT_NATIVE)
232 #  define PATHSEP ';'
233 # else /* unix */
234 #  define PATHSEP ':'
235 # endif /* __EMX__ || WINNT_NATIVE */
236 #endif /* !PATHSEP */
237
238 #if defined(__HP_CXD_SPP) && !defined(__hpux)
239 # include <sys/cnx_stat.h>
240 # define stat stat64
241 # define fstat fstat64
242 # define lstat lstat64
243 #endif /* __HP_CXD_SPP && !__hpux */
244
245 #ifdef HAVE_LONG_LONG
246 typedef long long tcsh_number_t;
247 #else
248 typedef long tcsh_number_t;
249 #endif
250 /*
251  * This macro compares the st_dev field of struct stat. On aix on ibmESA
252  * st_dev is a structure, so comparison does not work. 
253  */
254 #ifndef DEV_DEV_COMPARE
255 # define DEV_DEV_COMPARE(x,y)   ((x) == (y))
256 #endif /* DEV_DEV_COMPARE */
257
258 #ifdef _SEQUENT_
259 # include <sys/procstats.h>
260 #endif /* _SEQUENT_ */
261 #if (defined(POSIX) || SYSVREL > 0) && !defined(WINNT_NATIVE)
262 # include <sys/times.h>
263 #endif /* (POSIX || SYSVREL > 0) && !WINNT_NATIVE */
264
265 #ifdef NLS
266 # include <locale.h>
267 #endif /* NLS */
268
269 #if !defined(_MINIX) && !defined(_VMS_POSIX) && !defined(WINNT_NATIVE) && !defined(__MVS__)
270 # include <sys/param.h>
271 #endif /* !_MINIX && !_VMS_POSIX && !WINNT_NATIVE && !__MVS__ */
272 #include <sys/stat.h>
273
274 #if defined(BSDTIMES) || defined(BSDLIMIT)
275 # include <sys/time.h>
276 # if SYSVREL>3 && !defined(SCO) && !defined(sgi) && !defined(SNI) && !defined(sun) && !(defined(__alpha) && defined(__osf__)) && !defined(_SX) && !defined(__MVS__)
277 #  include "/usr/ucbinclude/sys/resource.h"
278 # else
279 #  ifdef convex
280 #   define sysrusage cvxrusage
281 #   include <sys/sysinfo.h>
282 #  else
283 #   define sysrusage rusage
284 #   include <sys/resource.h>
285 #  endif /* convex */
286 # endif /* SYSVREL>3 */
287 #endif /* BSDTIMES */
288
289 #ifndef WINNT_NATIVE
290 # ifndef POSIX
291 #  ifdef TERMIO
292 #   include <termio.h>
293 #  else /* SGTTY */
294 #   include <sgtty.h>
295 #  endif /* TERMIO */
296 # else /* POSIX */
297 #  ifndef _UWIN
298 #   include <termios.h>
299 #  else
300 #   include <termio.h>
301 #  endif /* _UWIN */
302 #  if SYSVREL > 3 || defined(__linux__)
303 #   undef TIOCGLTC      /* we don't need those, since POSIX has them */
304 #   undef TIOCSLTC
305 #   undef CSWTCH
306 #   define CSWTCH _POSIX_VDISABLE       /* So job control works */
307 #  endif /* SYSVREL > 3 */
308 # endif /* POSIX */
309 #endif /* WINNT_NATIVE */
310
311 #ifdef sonyrisc
312 # include <sys/ttold.h>
313 #endif /* sonyrisc */
314
315 #if defined(POSIX) && !defined(WINNT_NATIVE)
316 # include <unistd.h>
317
318 /*
319  * the gcc+protoize version of <stdlib.h>
320  * redefines malloc(), so we define the following
321  * to avoid it.
322  */
323 # if defined(SYSMALLOC) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) || defined(sgi) || defined(_OSD_POSIX)
324 #  define NO_FIX_MALLOC
325 #  include <stdlib.h>
326 # else /* glibc */
327 #  define _GNU_STDLIB_H
328 #  define malloc __malloc
329 #  define free __free
330 #  define calloc __calloc
331 #  define realloc __realloc
332 #  include <stdlib.h>
333 #  undef malloc
334 #  undef free
335 #  undef calloc
336 #  undef realloc
337 # endif /* glibc || sgi */
338 #endif /* POSIX && !WINNT_NATIVE */
339 #include <limits.h>
340
341 #if SYSVREL > 0 || defined(_IBMR2) || defined(_MINIX) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
342 # if !defined(pyr) && !defined(stellar)
343 #  include <time.h>
344 #  ifdef _MINIX
345 #   define HZ CLOCKS_PER_SEC
346 #  endif /* _MINIX */
347 # endif /* !pyr && !stellar */
348 #endif /* SYSVREL > 0 ||  _IBMR2 */
349
350 /* In the following ifdef the DECOSF1 has been commented so that later
351  * versions of DECOSF1 will get TIOCGWINSZ. This might break older versions...
352  */
353 #if !((defined(SUNOS4) || defined(_MINIX) /* || defined(DECOSF1) */) && defined(TERMIO))
354 # if !defined(_VMS_POSIX) && !defined(WINNT_NATIVE)
355 #  include <sys/ioctl.h>
356 #  if SYSVREL > 3 || defined(__linux__)
357 #   undef TIOCGLTC      /* we don't need those, since POSIX has them */
358 #   undef TIOCSLTC
359 #   undef CSWTCH
360 #   define CSWTCH _POSIX_VDISABLE       /* So job control works */
361 #  endif /* SYSVREL > 3 */
362 # endif
363 #endif 
364
365 #if (defined(__DGUX__) && defined(POSIX)) || defined(DGUX)
366 #undef CSWTCH
367 #define CSWTCH _POSIX_VDISABLE
368 #endif
369
370 #if (!defined(FIOCLEX) && defined(SUNOS4)) || ((SYSVREL == 4) && !defined(_SEQUENT_) && !defined(SCO) && !defined(_SX)) && !defined(__MVS__)
371 # include <sys/filio.h>
372 #endif /* (!FIOCLEX && SUNOS4) || (SYSVREL == 4 && !_SEQUENT_ && !SCO && !_SX ) */
373
374 #if !defined(_MINIX) && !defined(supermax) && !defined(WINNT_NATIVE) && !defined(IRIS4D)
375 # include <sys/file.h>
376 #endif  /* !_MINIX && !supermax && !WINNT_NATIVE && !defined(IRIS4D) */
377
378 #if !defined(O_RDONLY) || !defined(O_NDELAY)
379 # include <fcntl.h>
380 #endif 
381
382 #include <errno.h>
383
384 #include <setjmp.h>
385
386 #include <stdarg.h>
387
388 #ifdef HAVE_DIRENT_H
389 # include <dirent.h>
390 #else
391 # ifdef HAVE_NDIR_H
392 #  include <ndir.h>
393 # else
394 #  include <sys/dir.h>
395 # endif
396 # define dirent direct
397 #endif /* HAVE_DIRENT_H */
398 #ifndef HAVE_STRUCT_DIRENT_D_INO
399 # define d_ino d_fileno
400 #endif
401 #if defined(hpux) || defined(sgi) || defined(OREO)
402 # include <stdio.h>     /* So the fgetpwent() prototypes work */
403 #endif /* hpux || sgi || OREO */
404 #ifndef WINNT_NATIVE
405 #include <pwd.h>
406 #include <grp.h>
407 #endif /* WINNT_NATIVE */
408 #ifdef HAVE_SHADOW_H
409 # include <shadow.h>
410 #endif /* HAVE_SHADOW_H */
411 #ifdef HAVE_AUTH_H
412 # include <auth.h>
413 #endif /* HAVE_AUTH_H */
414 #if defined(BSD) && !defined(POSIX)
415 # include <strings.h>
416 # define strchr(a, b) index(a, b)
417 # define strrchr(a, b) rindex(a, b)
418 #else
419 # include <string.h>
420 #endif /* BSD */
421
422 /*
423  * IRIX-5.0 has <sys/cdefs.h>, but most system include files do not
424  * include it yet, so we include it here
425  */
426 #if defined(sgi) && SYSVREL > 3
427 # include <sys/cdefs.h>
428 #endif /* sgi && SYSVREL > 3 */
429
430 #ifdef REMOTEHOST
431 # ifdef ISC
432 #  undef MAXHOSTNAMELEN /* Busted headers? */
433 # endif
434
435 # include <netinet/in.h>
436 # include <arpa/inet.h>
437 # include <sys/socket.h>
438 # if (defined(_SS_SIZE) || defined(_SS_MAXSIZE)) && defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY)
439 #  if !defined(__APPLE__) /* Damnit, where is getnameinfo() folks? */
440 #   if !defined(sgi)
441 #    define INET6
442 #   endif /* sgi */
443 #  endif /* __APPLE__ */
444 # endif
445 # include <sys/uio.h>   /* For struct iovec */
446 #endif /* REMOTEHOST */
447
448 #ifdef PURIFY
449 /* exit normally, allowing purify to trace leaks */
450 # define _exit          exit
451 #endif /* !PURIFY */
452
453 /*
454  * ASCII vs. EBCDIC
455  */
456 #if 'Z' - 'A' == 25
457 # ifndef IS_ASCII
458 #  define IS_ASCII
459 # endif
460 #endif
461
462 #include "sh.types.h"
463
464 #if !HAVE_DECL_GETPGRP
465 # ifndef GETPGRP_VOID
466 extern pid_t getpgrp (int);
467 # else
468 extern pid_t getpgrp (void);
469 # endif
470 #endif
471
472 #ifndef lint
473 typedef ptr_t memalign_t;
474 #else
475 typedef union {
476     char    am_char, *am_char_p;
477     short   am_short, *am_short_p;
478     int     am_int, *am_int_p;
479     long    am_long, *am_long_p;
480     float   am_float, *am_float_p;
481     double  am_double, *am_double_p;
482 }      *memalign_t;
483
484 # define malloc         lint_malloc
485 # define free           lint_free
486 # define realloc        lint_realloc
487 # define calloc         lint_calloc
488 #endif 
489
490 #ifdef SYSMALLOC
491 # define xmalloc(i)     smalloc(i)
492 # define xrealloc(p, i) srealloc(p, i)
493 # define xcalloc(n, s)  scalloc(n, s)
494 # define xfree          sfree
495 #else
496 # define xmalloc(i)     malloc(i)
497 # define xrealloc(p, i) realloc(p, i)
498 # define xcalloc(n, s)  calloc(n, s)
499 # define xfree          free
500 #endif /* SYSMALLOC */
501 #include "sh.char.h"
502 #include "sh.err.h"
503 #include "sh.dir.h"
504 #include "sh.proc.h"
505
506 #include "pathnames.h"
507
508
509 /*
510  * C shell
511  *
512  * Bill Joy, UC Berkeley
513  * October, 1978; May 1980
514  *
515  * Jim Kulp, IIASA, Laxenburg Austria
516  * April, 1980
517  */
518
519 #ifdef HESIOD
520 # include <hesiod.h>
521 #endif /* HESIOD */
522
523 #ifdef REMOTEHOST
524 # include <netdb.h>
525 #endif /* REMOTEHOST */
526
527 #ifndef MAXHOSTNAMELEN
528 # ifdef HOST_NAME_MAX
529 #  define MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
530 # elif defined(SCO) && (SYSVREL > 3)
531 #  include <sys/socket.h>
532 # else
533 #  define MAXHOSTNAMELEN 256
534 # endif
535 #endif /* MAXHOSTNAMELEN */
536
537
538
539 #define eq(a, b)        (Strcmp(a, b) == 0)
540
541 /* globone() flags */
542 #define G_ERROR         0       /* default action: error if multiple words */
543 #define G_IGNORE        1       /* ignore the rest of the words            */
544 #define G_APPEND        2       /* make a sentence by cat'ing the words    */
545
546 /*
547  * Global flags
548  */
549 EXTERN int    chkstop IZERO;    /* Warned of stopped jobs... allow exit */
550
551 #if (defined(FIOCLEX) && defined(FIONCLEX)) || defined(F_SETFD)
552 # define CLOSE_ON_EXEC
553 #else
554 EXTERN int    didcch IZERO;     /* Have closed unused fd's for child */
555 #endif /* (FIOCLEX && FIONCLEX) || F_SETFD */
556
557 EXTERN int    didfds IZERO;     /* Have setup i/o fd's for child */
558 EXTERN int    doneinp IZERO;    /* EOF indicator after reset from readc */
559 EXTERN int    exiterr IZERO;    /* Exit if error or non-zero exit status */
560 EXTERN int    child IZERO;      /* Child shell ... errors cause exit */
561 EXTERN int    haderr IZERO;     /* Reset was because of an error */
562 EXTERN int    intty IZERO;      /* Input is a tty */
563 EXTERN int    intact IZERO;     /* We are interactive... therefore prompt */
564 EXTERN int    justpr IZERO;     /* Just print because of :p hist mod */
565 EXTERN int    loginsh IZERO;    /* We are a loginsh -> .login/.logout */
566 EXTERN int    neednote IZERO;   /* Need to pnotify() */
567 EXTERN int    noexec IZERO;     /* Don't execute, just syntax check */
568 EXTERN int    pjobs IZERO;      /* want to print jobs if interrupted */
569 EXTERN int    setintr IZERO;    /* Set interrupts on/off -> Wait intr... */
570 EXTERN int    handle_interrupt IZERO;/* Are we currently handling an interrupt? */
571 EXTERN int    havhash IZERO;    /* path hashing is available */
572 EXTERN int    editing IZERO;    /* doing filename expansion and line editing */
573 EXTERN int    noediting IZERO;  /* initial $term defaulted to noedit */
574 EXTERN int    bslash_quote IZERO;/* PWP: tcsh-style quoting?  (in sh.c) */
575 EXTERN int    anyerror IZERO;   /* propagate errors from pipelines/backq */
576 EXTERN int    compat_expr IZERO;/* csh-style expressions? */
577 EXTERN int    isoutatty IZERO;  /* is SHOUT a tty */
578 EXTERN int    isdiagatty IZERO;/* is SHDIAG a tty */
579 EXTERN int    is1atty IZERO;    /* is file descriptor 1 a tty (didfds mode) */
580 EXTERN int    is2atty IZERO;    /* is file descriptor 2 a tty (didfds mode) */
581 EXTERN int    arun IZERO;       /* Currently running multi-line-aliases */
582 EXTERN int    implicit_cd IZERO;/* implicit cd enabled?(1=enabled,2=verbose) */
583 EXTERN int    cdtohome IZERO;   /* cd without args goes home */
584 EXTERN int    inheredoc IZERO;  /* Currently parsing a heredoc */
585 EXTERN int    no_clobber IZERO; /* no clobber enabled? 1=yes 2=notempty, 4=ask*/
586 /* We received a window change event */
587 EXTERN volatile sig_atomic_t windowchg IZERO;
588 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
589 EXTERN int    dspmbyte_ls;
590 #endif
591
592 /*
593  * Global i/o info
594  */
595 EXTERN Char   *arginp IZERO;    /* Argument input for sh -c and internal `xx` */
596 EXTERN int     onelflg IZERO;   /* 2 -> need line for -t, 1 -> exit on read */
597 extern Char   *ffile;           /* Name of shell file for $0 */
598 extern int    dolzero;          /* if $?0 should return true... */
599
600 extern char *seterr;            /* Error message from scanner/parser */
601 #ifndef errno
602 extern int errno;               /* Error from C library routines */
603 #endif
604 extern int exitset;
605 /* Temp name for << shell files in /tmp, for xfree() */
606 EXTERN Char   *shtemp IZERO;
607
608 #ifdef BSDTIMES
609 EXTERN struct timeval time0;    /* Time at which the shell started */
610 EXTERN struct sysrusage ru0;
611 #else
612 # ifdef _SEQUENT_
613 EXTERN timeval_t time0;         /* time at which shell started */
614 EXTERN struct process_stats ru0;
615 # else /* _SEQUENT_ */
616 #  ifndef POSIX
617 EXTERN time_t  time0;           /* time at which shell started */
618 #  else /* POSIX */
619 EXTERN clock_t time0;           /* time at which shell started */
620 EXTERN clock_t clk_tck;
621 #  endif /* POSIX */
622 EXTERN struct tms shtimes;      /* shell and child times for process timing */
623 # endif /* _SEQUENT_ */
624 EXTERN time_t seconds0;
625 #endif /* BSDTIMES */
626
627 #ifndef HZ
628 # define HZ     100             /* for division into seconds */
629 #endif
630
631 /*
632  * Miscellany
633  */
634 EXTERN pid_t   mainpid;         /* pid of the main shell ($$) */
635 EXTERN Char   *doldol;          /* Character pid for $$ */
636 EXTERN pid_t   backpid;         /* pid of the last background job */
637
638
639 /*
640  * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now
641  * cause pid's could be unsigned and that would break our -1 flag, and 
642  * uid_t and gid_t are not defined in all the systems so I would have to
643  * make special cases for them. In the future...
644  */
645 EXTERN uid_t   uid, euid;       /* Invokers real and effective */
646 EXTERN gid_t   gid, egid;       /* User and group ids */
647 EXTERN pid_t   opgrp,           /* Initial pgrp and tty pgrp */
648                shpgrp,          /* Pgrp of shell */
649                tpgrp;           /* Terminal process group */
650                                 /* If tpgrp is -1, leave tty alone! */
651
652 EXTERN Char   *Prompt;          /* The actual printed prompt or NULL */
653 EXTERN Char   *RPrompt;         /* Right-hand side prompt or NULL */
654
655 /*
656  * To be able to redirect i/o for builtins easily, the shell moves the i/o
657  * descriptors it uses away from 0,1,2.
658  * Ideally these should be in units which are closed across exec's
659  * (this saves work) but for version 6, this is not usually possible.
660  * The desired initial values for these descriptors are defined in
661  * sh.local.h.
662  */
663 EXTERN int   SHIN IZERO;        /* Current shell input (script) */
664 EXTERN int   SHOUT IZERO;       /* Shell output */
665 EXTERN int   SHDIAG IZERO;      /* Diagnostic output... shell errs go here */
666 EXTERN int   OLDSTD IZERO;      /* Old standard input (def for cmds) */
667
668
669 #if (SYSVREL == 4 && defined(_UTS)) || defined(__linux__)
670 /* 
671  * From: fadden@uts.amdahl.com (Andy McFadden)
672  * we need sigsetjmp for UTS4, but not UTS2.1
673  */
674 # define SIGSETJMP
675 #endif
676
677 /*
678  * Error control
679  *
680  * Errors in scanning and parsing set up an error message to be printed
681  * at the end and complete.  Other errors always cause a reset.
682  * Because of source commands and .cshrc we need nested error catches.
683  */
684
685 #ifdef SIGSETJMP
686    typedef struct { sigjmp_buf j; } jmp_buf_t;
687 # define setexit()  sigsetjmp(reslab.j, 1)
688 # define _reset()    siglongjmp(reslab.j, 1)
689 #else
690    typedef struct { jmp_buf j; } jmp_buf_t;
691 # define setexit()  setjmp(reslab.j)
692 # define _reset()    longjmp(reslab.j, 1)
693 #endif
694
695 #define getexit(a) (void) ((a) = reslab)
696 #define resexit(a) (void) (reslab = (a))
697
698 #define cpybin(a, b) (void) ((a) = (b))
699
700 extern jmp_buf_t reslab;
701
702 EXTERN Char   *gointr;          /* Label for an onintr transfer */
703
704 extern struct sigaction parintr;        /* Parents interrupt catch */
705 extern struct sigaction parterm;        /* Parents terminate catch */
706
707 /*
708  * Lexical definitions.
709  *
710  * All lexical space is allocated dynamically.
711  * The eighth/sixteenth bit of characters is used to prevent recognition,
712  * and eventually stripped.
713  */
714 #define         META            0200
715 #define         ASCII           0177
716 #ifdef WIDE_STRINGS             /* Implies SHORT_STRINGS */
717 /* 31st char bit used for 'ing (not 32nd, we want all values nonnegative) */
718 /*
719  * Notice
720  *
721  * By fix for handling unicode name file, 32nd bit is used.
722  * We need use '&' instead of '> or <' when comparing with INVALID_BYTE etc..
723  * Cast to uChar is not recommended,
724  *  becase Char is 4bytes but uChar is 8bytes on I32LP64. */
725 # define        QUOTE           0x80000000
726 # define        TRIM            0x7FFFFFFF /* Mask to strip quote bit */
727 # define        UNDER           0x08000000 /* Underline flag */
728 # define        BOLD            0x04000000 /* Bold flag */
729 # define        STANDOUT        0x02000000 /* Standout flag */
730 # define        LITERAL         0x01000000 /* Literal character flag */
731 # define        ATTRIBUTES      0x0F000000 /* The bits used for attributes */
732 # define        INVALID_BYTE    0xF0000000 /* Invalid character on input */
733 # ifdef SOLARIS2
734 #  define       CHAR            0x30FFFFFF /* Mask to mask out the character */
735 # else
736 #  define       CHAR            0x00FFFFFF /* Mask to mask out the character */
737 # endif
738 #elif defined (SHORT_STRINGS)
739 # define        QUOTE   ((Char) 0100000)/* 16nth char bit used for 'ing */
740 # define        TRIM            0073777 /* Mask to strip quote/lit bit */
741 # define        UNDER           0040000 /* Underline flag */
742 # define        BOLD            0020000 /* Bold flag */
743 # define        STANDOUT        0010000 /* Standout flag */
744 # define        LITERAL         0004000 /* Literal character flag */
745 # define        ATTRIBUTES      0074000 /* The bits used for attributes */
746 # define        INVALID_BYTE    0
747 # define        CHAR            0000377 /* Mask to mask out the character */
748 #else
749 # define        QUOTE   ((Char) 0200)   /* Eighth char bit used for 'ing */
750 # define        TRIM            0177    /* Mask to strip quote bit */
751 # define        UNDER           0000000 /* No extra bits to do both */
752 # define        BOLD            0000000 /* Bold flag */
753 # define        STANDOUT        META    /* Standout flag */
754 # define        LITERAL         0000000 /* Literal character flag */
755 # define        ATTRIBUTES      0200    /* The bits used for attributes */
756 # define        INVALID_BYTE    0
757 # define        CHAR            0000177 /* Mask to mask out the character */
758 #endif
759 #define         CHAR_DBWIDTH    (LITERAL|(LITERAL-1))
760
761 # define        MAX_UTF32       0x7FFFFFFF      /* max UTF32 is U+7FFFFFFF */
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 #ifndef MAXPATHLEN
1031 # ifdef PATH_MAX
1032 #  define MAXPATHLEN PATH_MAX
1033 # else
1034 #  define MAXPATHLEN 2048
1035 # endif
1036 #endif /* MAXPATHLEN */
1037
1038 #ifndef HAVENOLIMIT
1039 /*
1040  * resource limits
1041  */
1042 extern struct limits {
1043     int         limconst;
1044     const char *limname;
1045     int         limdiv;
1046     const char *limscale;
1047 } limits[];
1048 #endif /* !HAVENOLIMIT */
1049
1050 /*
1051  * History list
1052  *
1053  * Each history list entry contains an embedded wordlist
1054  * from the scanner, a number for the event, and a reference count
1055  * to aid in discarding old entries.
1056  *
1057  * Essentially "invisible" entries are put on the history list
1058  * when history substitution includes modifiers, and thrown away
1059  * at the next discarding since their event numbers are very negative.
1060  */
1061 EXTERN struct Hist {
1062     struct wordent Hlex;
1063     int     Hnum;                /* eventno when inserted into history list  */
1064     int     Href;
1065     time_t  Htime;
1066     Char   *histline;
1067     struct Hist *Hnext, *Hprev;         /* doubly linked list */
1068     unsigned Hhash;                     /* hash value of command line */
1069 }       Histlist IZERO_STRUCT;
1070
1071 extern struct wordent paraml;   /* Current lexical word list */
1072 EXTERN int     eventno;         /* Next events number */
1073 EXTERN int     lastev;          /* Last event reference (default) */
1074
1075 EXTERN Char    HIST;            /* history invocation character */
1076 EXTERN Char    HISTSUB;         /* auto-substitute character */
1077 EXTERN Char    PRCH;            /* Prompt symbol for regular users */
1078 EXTERN Char    PRCHROOT;        /* Prompt symbol for root */
1079
1080 /*
1081  * For operating systems with single case filenames (OS/2)
1082  */
1083 #ifdef CASE_INSENSITIVE
1084 # ifdef WIDE_STRINGS
1085 #  define samecase(x) (towlower(x))
1086 # else
1087 #  define samecase(x) (isupper((unsigned char)(x)) ? \
1088                        tolower((unsigned char)(x)) : (x))
1089 # endif
1090 #else
1091 # define samecase(x) (x)
1092 #endif /* CASE_INSENSITIVE */
1093
1094 /*
1095  * strings.h:
1096  */
1097 #ifndef SHORT_STRINGS
1098 #define Strchr(a, b)            strchr(a, b)
1099 #define Strrchr(a, b)           strrchr(a, b)
1100 #define Strcat(a, b)            strcat(a, b)
1101 #define Strncat(a, b, c)        strncat(a, b, c)
1102 #define Strcpy(a, b)            strcpy(a, b)
1103 #define Strncpy(a, b, c)        strncpy(a, b, c)
1104 #define Strlen(a)               strlen(a)
1105 #define Strcmp(a, b)            strcmp(a, b)
1106 #define Strncmp(a, b, c)        strncmp(a, b, c)
1107 #define Strcasecmp(a, b)        strcasecmp(a, b)
1108
1109 #define Strspl(a, b)            strspl(a, b)
1110 #define Strnsave(a, b)          strnsave(a, b)
1111 #define Strsave(a)              strsave(a)
1112 #define Strend(a)               strend(a)
1113 #define Strstr(a, b)            strstr(a, b)
1114
1115 #define str2short(a)            (a)
1116 #define blk2short(a)            saveblk(a)
1117 #define short2blk(a)            saveblk(a)
1118 #define short2str(a)            caching_strip(a)
1119 #else
1120 #if defined(WIDE_STRINGS) && !defined(UTF16_STRINGS)
1121 #define Strchr(a, b)            wcschr(a, b)
1122 #define Strrchr(a, b)           wcsrchr(a, b)
1123 #define Strcat(a, b)            wcscat(a, b)
1124 #define Strncat(a, b, c)        wcsncat(a, b, c)
1125 #define Strcpy(a, b)            wcscpy(a, b)
1126 #define Strncpy(a, b, c)        wcsncpy(a, b, c)
1127 #define Strlen(a)               wcslen(a)
1128 #define Strcmp(a, b)            wcscmp(a, b)
1129 #define Strncmp(a, b, c)        wcsncmp(a, b, c)
1130 #else
1131 #define Strchr(a, b)            s_strchr(a, b)
1132 #define Strrchr(a, b)           s_strrchr(a, b)
1133 #define Strcat(a, b)            s_strcat(a, b)
1134 #define Strncat(a, b, c)        s_strncat(a, b, c)
1135 #define Strcpy(a, b)            s_strcpy(a, b)
1136 #define Strncpy(a, b, c)        s_strncpy(a, b, c)
1137 #define Strlen(a)               s_strlen(a)
1138 #define Strcmp(a, b)            s_strcmp(a, b)
1139 #define Strncmp(a, b, c)        s_strncmp(a, b, c)
1140 #endif
1141 #define Strcasecmp(a, b)        s_strcasecmp(a, b)
1142
1143 #define Strspl(a, b)            s_strspl(a, b)
1144 #define Strnsave(a, b)          s_strnsave(a, b)
1145 #define Strsave(a)              s_strsave(a)
1146 #define Strend(a)               s_strend(a)
1147 #define Strstr(a, b)            s_strstr(a, b)
1148 #endif 
1149
1150 /*
1151  * setname is a macro to save space (see sh.err.c)
1152  */
1153 EXTERN const char   *bname;
1154
1155 #define setname(a)      (bname = (a))
1156
1157 #ifdef VFORK
1158 EXTERN Char   *Vsav;
1159 EXTERN Char   *Vdp;
1160 EXTERN Char   *Vexpath;
1161 EXTERN char  **Vt;
1162 #endif /* VFORK */
1163
1164 EXTERN Char  **evalvec;
1165 EXTERN Char   *evalp;
1166
1167 extern struct mesg {
1168     const char   *iname;        /* name from /usr/include */
1169     const char *pname;          /* print name */
1170 } mesg[];
1171
1172 /* word_chars is set by default to WORD_CHARS (or WORD_CHARS_VI) but can
1173    be overridden by the wordchars variable--if unset, reverts to
1174    WORD_CHARS (or WORD_CHARS_VI) */
1175
1176 EXTERN Char   *word_chars;
1177
1178 #define WORD_CHARS "*?_-.[]~="  /* default chars besides alnums in words */
1179 #define WORD_CHARS_VI "_"       /* default chars besides alnums in words */
1180
1181 EXTERN Char   *STR_SHELLPATH;
1182
1183 #ifdef _PATH_BSHELL
1184 EXTERN Char   *STR_BSHELL;
1185 #endif 
1186 EXTERN Char   *STR_WORD_CHARS;
1187 EXTERN Char   *STR_WORD_CHARS_VI;
1188 EXTERN Char  **STR_environ IZERO;
1189
1190 extern int     dont_free;       /* Tell free that we are in danger if we free */
1191
1192 extern Char    *INVPTR;
1193 extern Char    **INVPPTR;
1194
1195 extern char    *progname;
1196 extern int      tcsh;
1197 extern int      xlate_cr;
1198 extern int      output_raw;
1199 extern int      lbuffed;
1200 extern time_t   Htime;
1201 extern int      numeof;
1202 extern int      insource;
1203 extern char     linbuf[];
1204 extern char     *linp;
1205 extern int      nsig;
1206 #ifdef VFORK
1207 extern int      use_fork;
1208 #endif
1209 extern int      tellwhat;
1210 extern int      NoNLSRebind;
1211 #if !HAVE_DECL_ENVIRON
1212 extern char   **environ;
1213 #endif
1214
1215 #include "tc.h"
1216
1217 #ifndef WINNT_NATIVE
1218 # ifdef NLS_CATALOGS
1219 #  ifdef HAVE_FEATURES_H
1220 #   include <features.h>
1221 #  endif
1222 #  ifdef HAVE_NL_LANGINFO
1223 #   include <langinfo.h>
1224 #  endif
1225 #  ifdef __uxps__
1226 #   define gettxt gettxt_ds
1227 #  endif
1228 #  include <nl_types.h>
1229 #  ifdef __uxps__
1230 #   undef gettxt
1231 #  endif
1232 EXTERN nl_catd catd;
1233 #  if defined(HAVE_ICONV) && defined(HAVE_NL_LANGINFO)
1234 #   define CGETS(b, c, d)       iconv_catgets(catd, b, c, d)
1235 #  else
1236 #   define CGETS(b, c, d)       xcatgets(catd, b, c, d)
1237 #  endif
1238 #  define CSAVS(b, c, d)        strsave(CGETS(b, c, d))
1239 # else
1240 #  define CGETS(b, c, d)        d
1241 #  define CSAVS(b, c, d)        d
1242 # endif 
1243 #else /* WINNT_NATIVE */
1244 # define CGETS(b, c, d) nt_cgets( b, c, d)
1245 # define CSAVS(b, c, d) strsave(CGETS(b, c, d))
1246 #endif /* WINNT_NATIVE */
1247
1248 #if defined(FILEC)
1249 extern int    filec;
1250 #endif /* FILEC */
1251
1252 #include "sh.decls.h"
1253 /*
1254  * Since on some machines characters are unsigned, and the signed
1255  * keyword is not universally implemented, we treat all characters
1256  * as unsigned and sign extend them where we need.
1257  */
1258 #define SIGN_EXTEND_CHAR(a)     (((a) & 0x80) ? ((a) | ~0x7f) : (a))
1259
1260 /*
1261  * explanation for use by the "--help" option
1262  */
1263 #define HELP_STRING "\
1264 -b file         batch mode, read and execute commands from `file' \n\
1265 -c command      run `command' from next argument \n\
1266 -d              load directory stack from `~/.cshdirs' \n\
1267 -Dname[=value]  define environment variable `name' to `value' (DomainOS only) \n\
1268 -e              exit on any error \n\
1269 -f              start faster by ignoring the start-up file \n\
1270 -F              use fork() instead of vfork() when spawning (ConvexOS only) \n\
1271 -i              interactive, even when input is not from a terminal \n\
1272 -l              act as a login shell, must be the only option specified \n\
1273 -m              load the start-up file, whether or not owned by effective user \n\
1274 -n file         no execute mode, just check syntax of the following `file' \n\
1275 -q              accept SIGQUIT for running under a debugger \n\
1276 -s              read commands from standard input \n\
1277 -t              read one line from standard input \n\
1278 -v              echo commands after history substitution \n\
1279 -V              like -v but including commands read from the start-up file \n\
1280 -x              echo commands immediately before execution \n\
1281 -X              like -x but including commands read from the start-up file \n\
1282 --help          print this message and exit \n\
1283 --version       print the version shell variable and exit \n\
1284 \nSee the tcsh(1) manual page for detailed information.\n"
1285
1286 #include "tc.nls.h"
1287
1288 #endif /* _h_sh */