home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / pdksh-src.lha / src / amiga / pdksh / sh / sh.h < prev    next >
C/C++ Source or Header  |  1993-12-01  |  7KB  |  275 lines

  1. /*
  2.  * Public Domain Bourne/Korn shell
  3.  */
  4.  
  5. /* $Id: sh.h,v 1.3 1992/04/25 08:29:52 sjg Exp $ */
  6.  
  7. #include "config.h"
  8.  
  9. /* allow for non-Unix linkers. main.c has a "#define Extern " */
  10. #ifndef Extern
  11. # define Extern    extern
  12. #endif
  13.  
  14. #ifndef SHELL
  15. #define    SHELL    "/bin/sh"    /* shell to exec scripts */
  16. #endif
  17.  
  18. /* some people object to this use of __STDC__ */
  19. #ifdef __STDC__
  20. #define    ARGS(args)    args    /* prototype declaration */
  21. #else
  22. #define    ARGS(args)    ()    /* K&R declaration */
  23. #ifdef VOID
  24. #define    void    VOID
  25. #endif
  26. #define    const    
  27. #define    volatile 
  28. #endif
  29.  
  30. #ifdef _ULTRIX            /* Ultrix 2.x gets dup2 wrong */
  31. int dup2 ARGS ((int, int));
  32. /* assumes we don't want dup2 return value */
  33. #define    dup2(ofd, nfd) \
  34.         (void) ((dup2)(ofd, nfd), fcntl(nfd, F_SETFD, 0))
  35. #endif
  36.  
  37. #if defined(EMACS) || defined(VI)
  38. #define    EDIT
  39. #endif
  40.  
  41. typedef int bool_t;
  42. #define    FALSE    0
  43. #define    TRUE    1
  44.  
  45. #define    sizeofN(type, n) (sizeof(type) * (n))
  46. #define    BIT(i)    (1<<(i))    /* define bit in flag */
  47.  
  48. #define    NUFILE    10        /* Number of user-accessible files */
  49. #define    FDBASE    10        /* First file usable by Shell */
  50.  
  51. /* you're not going to run setuid shell scripts, are you? */
  52. #define    eaccess(path, mode)    access(path, mode)
  53.  
  54. #define    MAGIC    (char)0x80    /* prefix for ~*?[ during expand */
  55. #define    NOT    '!'    /* might use ^ */
  56.  
  57. #define    LINE    256        /* input line size */
  58. #define    PATH    256        /* pathname size */
  59.  
  60. Extern    int    kshpid;        /* $$, shell pid */
  61. Extern    int    exstat;        /* exit status */
  62. Extern    int    async;        /* $!, last &'d pid */
  63. Extern    volatile int sigchld_caught;    /* count of dead children */
  64.  
  65.  
  66. /*
  67.  * Area-based allocation built on malloc/free
  68.  */
  69.  
  70. typedef struct Area {
  71.     struct Block *free;    /* free list */
  72. } Area;
  73.  
  74. extern    Area    aperm;        /* permanent object space */
  75. #define    APERM    &aperm
  76. #define    ATEMP    &e.area
  77.  
  78. /*
  79.  * parsing & execution environment
  80.  */
  81. Extern    struct    env {
  82.     int    type;            /* enviroment type - see below */
  83.     Area    area;            /* temporary allocation area */
  84.     struct    block *loc;        /* local variables and functions */
  85.     short  *savefd;            /* original redirected fd's */
  86.     struct    env *oenv;        /* link to previous enviroment */
  87.     jmp_buf    jbuf;            /* long jump back to env creator */
  88.     int    interactive;        /* fd's 0,1,2 are tty */
  89.     struct temp *temps;        /* temp files */
  90. } e;
  91.  
  92. #define    E_NONE    0        /* dummy enviroment */
  93. #define    E_PARSE    1        /* parsing command # */
  94. #define    E_EXEC    2        /* executing command tree */
  95. #define    E_LOOP    3        /* executing for/while # */
  96. #define    E_TCOM    5        /* executing simple command */
  97. #define    E_FUNC    6        /* executing function */
  98. #define    E_ERRH    7        /* general error handler # */
  99. /* # indicates env has valid jbuf */
  100.  
  101. /*
  102.  * flags
  103.  */
  104. #define    FEXPORT    FLAG('a')    /* -a: allexport */
  105. #define    FERREXIT FLAG('e')    /* -e: errexit (quit on error) */
  106. #define    FBGNICE    29        /* bgnice */
  107. #define    FEMACS 30        /* emacs command editing */
  108. #define    FIGNEOF    27        /* ignoreeof (eof does not exit) */
  109. #define    FHASHALL FLAG('h')    /* -h: trackall, hashall */
  110. #define    FTALKING FLAG('i')    /* -i: interactive (talking type wireless) */
  111. #define    FKEYWORD FLAG('k')    /* -k: keyword (name=value anywhere) */
  112. #define    FMARKDIRS 28        /* markdirs */
  113. #define    FMONITOR FLAG('m')    /* -m: monitor */
  114. #define    FNOEXEC    FLAG('n')    /* -n: noexec */
  115. #define    FNOGLOB    FLAG('f')    /* -f: noglob */
  116. #define    FPRIVILEGED FLAG('p')    /* -p: privileged */
  117. #define    FSTDIN    FLAG('s')    /* -s (invocation): parse stdin */
  118. #define    FNOUNSET FLAG('u')    /* -u: nounset (unset vars is error) */
  119. #define    FVERBOSE FLAG('v')    /* -v: verbose (echo input) */
  120. #define    FVI 31            /* vi command editing */
  121. #define    FXTRACE    FLAG('x')    /* -x: (execute) xtrace */
  122.  
  123. #define    FLAG(c)    (1 + c - 'a')    /* map char to flags index */
  124. #define    FLAGS    32
  125. Extern    char flag [FLAGS];
  126. int    option ARGS((const char *name));
  127. char   *getoptions ARGS((void));
  128. void    printoptions ARGS((void));
  129.  
  130. extern    char    null [];    /* null value for variable */
  131.  
  132. /*
  133.  * other functions
  134.  */
  135. char * substitute ARGS((char const *, int));
  136. char   *search();
  137. struct tbl *findcom();
  138. char   *strsave ARGS((char *, Area *));
  139. char   *ulton ARGS((unsigned long n, int base));
  140. int    xstrcmp();
  141. void    qsortp ARGS((void **base, size_t n, int (*compare)(void *, void *)));
  142. long    evaluate ARGS((const char *expr));
  143. void    resetopts();
  144. void    histsave();
  145. void    histlist();
  146.  
  147. void    j_init ARGS((void));
  148. void    j_exit ARGS((void));
  149. void    j_notify ARGS((void));
  150. void    j_kill ARGS((int job, int sig));
  151. #ifdef JOBS
  152. void    j_change ARGS((void));
  153. int    j_resume ARGS((int job, int bg));
  154. #endif
  155.  
  156. /*
  157.  * error handling
  158.  */
  159. void    leave();    /* abort shell (or fail in subshell) */
  160.  
  161. /*
  162.  * library functions
  163.  */
  164. typedef    void (*handler_t)();    /* signal handler */
  165.  
  166. /* temp/here files. the file is removed when the struct is freed */
  167. struct    temp {
  168.     struct    temp * next;
  169.     char   *name;
  170. };
  171. struct temp *maketemp ARGS((Area *ap));
  172.  
  173. /*
  174.  * stdio and our IO routines
  175.  */
  176.  
  177. #ifdef    BUFSIZ            /* <stdio.h> included? */
  178. extern    FILE *    shf [NUFILE];    /* map shell fd to FILE */
  179. #endif
  180. void    fopenshf();
  181. void    flushshf();
  182.  
  183. #undef    stdin
  184. #undef    stdout
  185.  
  186. #define    stdin    shf[0]        /* standard input */
  187. #define    stdout    shf[1]        /* standard output */
  188. #define    shlout    shf[2]        /* shell output */
  189.  
  190. int    shellf ARGS((const char *fmt, ...)); /* fprintf(shlout, ); */
  191. int    errorf ARGS((const char *fmt, ...)); /* fprintf(shlout, ); error(); */
  192.  
  193. /*
  194.  * IO control
  195.  */
  196. extern    int ttyfd;        /* tty fd (original fd 0) */
  197.  
  198. int    savefd ARGS((int fd));    /* save user fd */
  199. void    restfd ARGS((int fd, int ofd));
  200. void    openpipe ARGS((int [2]));
  201. void    closepipe ARGS((int [2]));
  202.  
  203. /*
  204.  * trap handlers
  205.  */
  206. typedef struct trap {
  207.     int    signal;        /* signal number */
  208.     char   *name;        /* short name */
  209.     char   *mess;        /* descriptive name */
  210.     char   *trap;        /* trap command */
  211.     int    volatile set;    /* trap pending */
  212.     int    ourtrap;    /* not ignored (?) */
  213.     int    sig_dfl;    /* originally SIG_DFL */
  214. } Trap;
  215.  
  216. #ifndef    SIGKILL
  217. #include <signal.h>
  218. #endif    /* SIGKILL */
  219. #ifdef    NSIG
  220. #define    SIGNALS    NSIG
  221. #else
  222. #ifdef    _MINIX
  223. #define    SIGNALS    (_NSIG+1)    /* _NSIG is # of signals used, excluding 0. */
  224. #else
  225. #define    SIGNALS    32
  226. #endif    /* _MINIX */
  227. #endif    /* NSIG */
  228.  
  229. #ifdef USE_SIGACT            /* always use it? */
  230. #ifndef  SA_NOCLDSTOP
  231. # include "sigact.h"            /* use sjg's fake sigaction() */
  232. #endif
  233. Extern struct sigaction Sigact, Sigact_dfl, Sigact_ign, Sigact_trap;
  234. #endif
  235.  
  236. Extern    int volatile trap;    /* traps pending? */
  237. extern    Trap    sigtraps[SIGNALS];
  238. Trap    *gettrap ARGS((char *)); /* search for struct trap by number or name */
  239. void    trapsig ARGS((int sig)); /* trap signal handler */
  240.  
  241. /*
  242.  * fast character classes
  243.  */
  244. #define    C_ALPHA    0x01        /* a-z_A-Z */
  245. #define    C_DIGIT    0x02        /* 0-9 */
  246. #define    C_LEX1    0x04        /* \0 \t\n|&;<>() */
  247. #define    C_VAR1    0x08        /* *@#!$-? */
  248. #define    C_SUBOP    0x40        /* "=-+?#%" */
  249. #define    C_IFS    0x80        /* $IFS */
  250.  
  251. extern    char ctypes [];
  252. #if 0
  253. void    initctypes ARGS((void));
  254. void    setctypes ARGS((const char*, int type));
  255. #endif
  256. #define    ctype(c, t)    !!(ctypes[(unsigned char)(c)]&(t))
  257. #define    letter(c)    ctype(c, C_ALPHA)
  258. #define    digit(c)    ctype(c, C_DIGIT)
  259. #define    letnum(c)    ctype(c, C_ALPHA|C_DIGIT)
  260.  
  261. #include "table.h"
  262. #include "tree.h"
  263. #include "lex.h"
  264. #include "proto.h"
  265.   
  266. /*
  267.  * 91-07-06 <sjg@sun0>
  268.  * use my simple debug tracing... 
  269.  */
  270. #include "trace.h"
  271.  
  272. #ifndef fileno
  273. #define fileno(p)    ((p)->_file)
  274. #endif
  275.