rc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * Assume plan 9 by default; if Unix is defined, assume unix.
  11. * Please don't litter the code with ifdefs. The five below should be enough.
  12. */
  13. #ifndef Unix
  14. /* plan 9 */
  15. #include <u.h>
  16. #include <libc.h>
  17. #define NSIG 32
  18. #define SIGINT 2
  19. #define SIGQUIT 3
  20. #define fcntl(fd, op, arg) /* unix compatibility */
  21. #define F_SETFD
  22. #define FD_CLOEXEC
  23. #define YYSIZE_T size_t /* GNU Bison/yacc has hundred of types :( */
  24. #else
  25. #include "unix.h"
  26. #endif
  27. #ifndef ERRMAX
  28. #define ERRMAX 128
  29. #endif
  30. #define YYMAXDEPTH 500
  31. #ifndef YYPREFIX
  32. #ifndef PAREN
  33. #include "x.tab.h"
  34. #endif
  35. #endif
  36. typedef struct tree tree;
  37. typedef struct word word;
  38. typedef struct io io;
  39. typedef union code code;
  40. typedef struct var var;
  41. typedef struct list list;
  42. typedef struct redir redir;
  43. typedef struct thread thread;
  44. typedef struct builtin builtin;
  45. #ifndef Unix
  46. //#pragma incomplete word
  47. //#pragma incomplete io
  48. #endif
  49. struct tree{
  50. int type;
  51. int rtype, fd0, fd1; /* details of REDIR PIPE DUP tokens */
  52. char *str;
  53. int quoted;
  54. int iskw;
  55. tree *child[3];
  56. tree *next;
  57. };
  58. tree *newtree(void);
  59. tree *token(char*, int), *klook(char*), *tree1(int, tree*);
  60. tree *tree2(int, tree*, tree*), *tree3(int, tree*, tree*, tree*);
  61. tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
  62. tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
  63. tree *simplemung(tree*), *heredoc(tree*);
  64. void freetree(tree*);
  65. tree *cmdtree;
  66. /*
  67. * The first word of any code vector is a reference count.
  68. * Always create a new reference to a code vector by calling codecopy(.).
  69. * Always call codefree(.) when deleting a reference.
  70. */
  71. union code{
  72. void (*f)(void);
  73. int i;
  74. char *s;
  75. };
  76. char *promptstr;
  77. int doprompt;
  78. #define NTOK 8192 /* maximum bytes in a word (token) */
  79. char tok[NTOK + UTFmax];
  80. #define APPEND 1
  81. #define WRITE 2
  82. #define READ 3
  83. #define HERE 4
  84. #define DUPFD 5
  85. #define CLOSE 6
  86. #define RDWR 7
  87. struct var{
  88. char *name; /* ascii name */
  89. word *val; /* value */
  90. int changed;
  91. code *fn; /* pointer to function's code vector */
  92. int fnchanged;
  93. int pc; /* pc of start of function */
  94. var *next; /* next on hash or local list */
  95. };
  96. var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
  97. #define NVAR 521
  98. var *gvar[NVAR]; /* hash for globals */
  99. #define new(type) ((type *)emalloc(sizeof(type)))
  100. void *emalloc(int32_t);
  101. void *Malloc(uint32_t);
  102. void efree(void *);
  103. struct here{
  104. tree *tag;
  105. char *name;
  106. struct here *next;
  107. };
  108. int mypid;
  109. /*
  110. * Glob character escape in strings:
  111. * In a string, GLOB must be followed by *?[ or GLOB.
  112. * GLOB* matches any string
  113. * GLOB? matches any single character
  114. * GLOB[...] matches anything in the brackets
  115. * GLOBGLOB matches GLOB
  116. */
  117. #define GLOB '\001'
  118. char **argp;
  119. char **args;
  120. int nerror; /* number of errors encountered during compilation */
  121. int doprompt; /* is it time for a prompt? */
  122. /*
  123. * Which fds are the reading/writing end of a pipe?
  124. * Unfortunately, this can vary from system to system.
  125. * 9th edition Unix doesn't care, the following defines
  126. * work on plan 9.
  127. */
  128. #define PRD 0
  129. #define PWR 1
  130. char *Rcmain, *Fdprefix;
  131. /*
  132. * How many dot commands have we executed?
  133. * Used to ensure that -v flag doesn't print rcmain.
  134. */
  135. int ndot;
  136. char *getstatus(void);
  137. int lastc;
  138. int lastword;