regexp.h 1.3 KB

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