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