regexp.h 1.7 KB

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