regexp.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef __REGEXP_H
  10. #define __REGEXP_H
  11. #ifndef _REGEXP_EXTENSION
  12. This header file is an extension to ANSI/POSIX
  13. #endif
  14. #pragma lib "/$M/lib/ape/libregexp.a"
  15. #ifdef UTF
  16. #define Runeself 0xA0
  17. #else
  18. #define Runeself 0
  19. #endif
  20. typedef struct Resub Resub;
  21. typedef struct Reclass Reclass;
  22. typedef struct Reinst Reinst;
  23. typedef struct Reprog Reprog;
  24. /*
  25. * Sub expression matches
  26. */
  27. struct Resub{
  28. union
  29. {
  30. char *sp;
  31. wchar_t *rsp;
  32. } s;
  33. union
  34. {
  35. char *ep;
  36. wchar_t *rep;
  37. } e;
  38. };
  39. /*
  40. * character class, each pair of rune's defines a range
  41. */
  42. struct Reclass{
  43. wchar_t *end;
  44. wchar_t spans[64];
  45. };
  46. /*
  47. * Machine instructions
  48. */
  49. struct Reinst{
  50. int type; /* < 0200 ==> literal, otherwise action */
  51. union {
  52. Reclass *cp; /* class pointer */
  53. wchar_t r; /* character */
  54. int subid; /* sub-expression id for RBRA and LBRA */
  55. Reinst *right; /* right child of OR */
  56. } r;
  57. union { /* regexp relies on these two being in the same union */
  58. Reinst *left; /* left child of OR */
  59. Reinst *next; /* next instruction for CAT & LBRA */
  60. } l;
  61. };
  62. /*
  63. * Reprogram definition
  64. */
  65. struct Reprog{
  66. Reinst *startinst; /* start pc */
  67. Reclass class[16]; /* .data */
  68. Reinst firstinst[5]; /* .text */
  69. };
  70. extern Reprog *regcomp(char*);
  71. extern Reprog *regcomplit(char*);
  72. extern Reprog *regcompnl(char*);
  73. extern void regerror(char*);
  74. extern int regexec(Reprog*, char*, Resub*, int);
  75. extern void regsub(char*, char*, int, Resub*, int);
  76. extern int rregexec(Reprog*, wchar_t*, Resub*, int);
  77. extern void rregsub(wchar_t*, wchar_t*, int, Resub*, int);
  78. #endif