1
0

regexp.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. typedef struct Resub Resub;
  10. typedef struct Reclass Reclass;
  11. typedef struct Reinst Reinst;
  12. typedef struct Reprog Reprog;
  13. /*
  14. * Sub expression matches
  15. */
  16. struct Resub{
  17. union
  18. {
  19. char *sp;
  20. Rune *rsp;
  21. };
  22. union
  23. {
  24. char *ep;
  25. Rune *rep;
  26. };
  27. };
  28. /*
  29. * character class, each pair of rune's defines a range
  30. */
  31. struct Reclass{
  32. Rune *end;
  33. Rune spans[64];
  34. };
  35. /*
  36. * Machine instructions
  37. */
  38. struct Reinst{
  39. int type;
  40. union {
  41. Reclass *cp; /* class pointer */
  42. Rune r; /* character */
  43. int subid; /* sub-expression id for RBRA and LBRA */
  44. Reinst *right; /* right child of OR */
  45. };
  46. union { /* regexp relies on these two being in the same union */
  47. Reinst *left; /* left child of OR */
  48. Reinst *next; /* next instruction for CAT & LBRA */
  49. };
  50. };
  51. /*
  52. * Reprogram definition
  53. */
  54. struct Reprog{
  55. Reinst *startinst; /* start pc */
  56. Reclass class[16]; /* .data */
  57. Reinst firstinst[5]; /* .text */
  58. };
  59. extern Reprog *regcomp(char*);
  60. extern Reprog *regcomplit(char*);
  61. extern Reprog *regcompnl(char*);
  62. extern void regerror(char*);
  63. extern int regexec(Reprog*, char*, Resub*, int);
  64. extern void regsub(char*, char*, int, Resub*, int);
  65. extern int rregexec(Reprog*, Rune*, Resub*, int);
  66. extern void rregsub(Rune*, Rune*, int, Resub*, int);