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