grep.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #ifndef EXTERN
  13. #define EXTERN extern
  14. #endif
  15. typedef struct Re Re;
  16. typedef struct Re2 Re2;
  17. typedef struct State State;
  18. struct State {
  19. int count;
  20. int match;
  21. Re **re;
  22. State *linkleft;
  23. State *linkright;
  24. State *next[256];
  25. };
  26. struct Re2 {
  27. Re *beg;
  28. Re *end;
  29. };
  30. struct Re {
  31. uint8_t type;
  32. uint16_t gen;
  33. union {
  34. Re *alt; /* Talt */
  35. Re **cases; /* case */
  36. struct { /* class */
  37. Rune lo;
  38. Rune hi;
  39. };
  40. Rune val; /* char */
  41. };
  42. Re *next;
  43. };
  44. enum {
  45. Talt = 1,
  46. Tbegin,
  47. Tcase,
  48. Tclass,
  49. Tend,
  50. Tor,
  51. Caselim = 7,
  52. Nhunk = 1 << 16,
  53. Cbegin = Runemax + 1,
  54. Flshcnt = (1 << 9) - 1,
  55. Cflag = 1 << 0,
  56. Hflag = 1 << 1,
  57. Iflag = 1 << 2,
  58. Llflag = 1 << 3,
  59. LLflag = 1 << 4,
  60. Nflag = 1 << 5,
  61. Sflag = 1 << 6,
  62. Vflag = 1 << 7,
  63. Bflag = 1 << 8
  64. };
  65. EXTERN union {
  66. char string[16 * 1024];
  67. struct {
  68. /*
  69. * if a line requires multiple reads, we keep shifting
  70. * buf down into pre and then do another read into
  71. * buf. so you'll get the last 16-32k of the matching line.
  72. * if pre were smaller than buf you'd get a suffix of the
  73. * line with a hole cut out.
  74. */
  75. uint8_t pre[16 * 1024]; /* to save to previous '\n' */
  76. uint8_t buf[16 * 1024]; /* input buffer */
  77. };
  78. } u;
  79. EXTERN char *filename;
  80. EXTERN char *pattern;
  81. EXTERN Biobuf bout;
  82. EXTERN char flags[256];
  83. EXTERN Re **follow;
  84. EXTERN uint16_t gen;
  85. EXTERN char *input;
  86. EXTERN int32_t lineno;
  87. EXTERN int literal;
  88. EXTERN int matched;
  89. EXTERN int32_t maxfollow;
  90. EXTERN int32_t nfollow;
  91. EXTERN int peekc;
  92. EXTERN Biobuf *rein;
  93. EXTERN State *state0;
  94. EXTERN Re2 topre;
  95. extern Re *addcase(Re *);
  96. extern void appendnext(Re *, Re *);
  97. extern void error(char *);
  98. extern int fcmp(const void *, const void *); /* (Re**, Re**) */
  99. extern void fol1(Re *, int);
  100. extern int getrec(void);
  101. extern void increment(State *, int);
  102. extern State *initstate(Re *);
  103. extern void *mal(int);
  104. extern void patchnext(Re *, Re *);
  105. extern Re *ral(int);
  106. extern Re2 re2cat(Re2, Re2);
  107. extern Re2 re2class(char *);
  108. extern Re2 re2or(Re2, Re2);
  109. extern Re2 re2char(int, int);
  110. extern Re2 re2star(Re2);
  111. extern State *sal(int);
  112. extern int search(char *, int);
  113. extern void str2top(char *);
  114. extern int yyparse(void);
  115. extern void reprint(char *, Re *);
  116. extern void yyerror(char *, ...);