rc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Plan9 is defined for plan 9
  3. * V9 is defined for 9th edition
  4. * Sun is defined for sun-os
  5. * Please don't litter the code with ifdefs. The three below (and one in
  6. * getflags) should be enough.
  7. */
  8. #define Plan9
  9. #ifdef Plan9
  10. #include <u.h>
  11. #include <libc.h>
  12. #define NSIG 32
  13. #define SIGINT 2
  14. #define SIGQUIT 3
  15. #endif
  16. #ifdef V9
  17. #include <signal.h>
  18. #include <libc.h>
  19. #endif
  20. #ifdef Sun
  21. #include <signal.h>
  22. #endif
  23. #define YYMAXDEPTH 500
  24. #ifndef PAREN
  25. #include "x.tab.h"
  26. #endif
  27. typedef struct tree tree;
  28. typedef struct word word;
  29. typedef struct io io;
  30. typedef union code code;
  31. typedef struct var var;
  32. typedef struct list list;
  33. typedef struct redir redir;
  34. typedef struct thread thread;
  35. typedef struct builtin builtin;
  36. struct tree{
  37. int type;
  38. int rtype, fd0, fd1; /* details of REDIR PIPE DUP tokens */
  39. char *str;
  40. int quoted;
  41. int iskw;
  42. tree *child[3];
  43. tree *next;
  44. };
  45. tree *newtree(void);
  46. tree *token(char*, int), *klook(char*), *tree1(int, tree*);
  47. tree *tree2(int, tree*, tree*), *tree3(int, tree*, tree*, tree*);
  48. tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
  49. tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
  50. tree *simplemung(tree*), *heredoc(tree*);
  51. void freetree(tree*);
  52. tree *cmdtree;
  53. /*
  54. * The first word of any code vector is a reference count.
  55. * Always create a new reference to a code vector by calling codecopy(.).
  56. * Always call codefree(.) when deleting a reference.
  57. */
  58. union code{
  59. void (*f)(void);
  60. int i;
  61. char *s;
  62. };
  63. char *promptstr;
  64. int doprompt;
  65. #define NTOK 8192
  66. char tok[NTOK];
  67. #define APPEND 1
  68. #define WRITE 2
  69. #define READ 3
  70. #define HERE 4
  71. #define DUPFD 5
  72. #define CLOSE 6
  73. struct var{
  74. char *name; /* ascii name */
  75. word *val; /* value */
  76. int changed;
  77. code *fn; /* pointer to function's code vector */
  78. int fnchanged;
  79. int pc; /* pc of start of function */
  80. var *next; /* next on hash or local list */
  81. };
  82. var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
  83. #define NVAR 521
  84. var *gvar[NVAR]; /* hash for globals */
  85. #define new(type) ((type *)emalloc(sizeof(type)))
  86. char *emalloc(long);
  87. void *Malloc(ulong);
  88. void efree(char*);
  89. #define NOFILE 128 /* should come from <param.h> */
  90. struct here{
  91. tree *tag;
  92. char *name;
  93. struct here *next;
  94. };
  95. int mypid;
  96. /*
  97. * Glob character escape in strings:
  98. * In a string, GLOB must be followed by *?[ or GLOB.
  99. * GLOB* matches any string
  100. * GLOB? matches any single character
  101. * GLOB[...] matches anything in the brackets
  102. * GLOBGLOB matches GLOB
  103. */
  104. #define GLOB ((char)0x01)
  105. /*
  106. * onebyte(c), twobyte(c), threebyte(c)
  107. * Is c the first character of a one- two- or three-byte utf sequence?
  108. */
  109. #define onebyte(c) ((c&0x80)==0x00)
  110. #define twobyte(c) ((c&0xe0)==0xc0)
  111. #define threebyte(c) ((c&0xf0)==0xe0)
  112. char **argp;
  113. char **args;
  114. int nerror; /* number of errors encountered during compilation */
  115. int doprompt; /* is it time for a prompt? */
  116. /*
  117. * Which fds are the reading/writing end of a pipe?
  118. * Unfortunately, this can vary from system to system.
  119. * 9th edition Unix doesn't care, the following defines
  120. * work on plan 9.
  121. */
  122. #define PRD 0
  123. #define PWR 1
  124. char Rcmain[], Fdprefix[];
  125. #define register
  126. /*
  127. * How many dot commands have we executed?
  128. * Used to ensure that -v flag doesn't print rcmain.
  129. */
  130. int ndot;
  131. char *getstatus(void);
  132. int lastc;
  133. int lastword;