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