home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xwphescr.zip / XWPH0208.ZIP / include / helpers / regexp.h < prev    next >
C/C++ Source or Header  |  2002-04-17  |  4KB  |  120 lines

  1. #ifndef ERE_H
  2. #define ERE_H
  3.  
  4. #ifndef BOOLEAN_DEFINED
  5. #define BOOLEAN_DEFINED
  6. typedef int BOOLEAN;
  7. #define TRUE  1
  8. #define FALSE 0
  9. #endif
  10.  
  11. #ifndef NO_ERROR
  12. #define NO_ERROR 0
  13. #endif
  14.  
  15. #define ERROR_REGEXP_FIRST      44000
  16. // #define EREE_OK                 0
  17. // #define EREE_MEM                (ERROR_REGEXP_FIRST + 0)
  18. #ifndef ERROR_NOT_ENOUGH_MEMORY
  19. #define ERROR_NOT_ENOUGH_MEMORY               8L
  20. #endif
  21. #define EREE_UNF_SUB            (ERROR_REGEXP_FIRST + 1)
  22. #define EREE_UNEX_RANGE         (ERROR_REGEXP_FIRST + 2)
  23. #define EREE_UNF_RANGE          (ERROR_REGEXP_FIRST + 3)
  24. #define EREE_UNF_CCLASS         (ERROR_REGEXP_FIRST + 4)
  25. #define EREE_UNEX_RSQR          (ERROR_REGEXP_FIRST + 5)
  26. #define EREE_UNEX_RPAR          (ERROR_REGEXP_FIRST + 6)
  27. #define EREE_UNEX_QUERY         (ERROR_REGEXP_FIRST + 7)
  28. #define EREE_UNEX_PLUS          (ERROR_REGEXP_FIRST + 8)
  29. #define EREE_UNEX_STAR          (ERROR_REGEXP_FIRST + 9)
  30. #define EREE_UNEX_LCUR          (ERROR_REGEXP_FIRST + 10)
  31. #define EREE_UNEX_RCUR          (ERROR_REGEXP_FIRST + 11)
  32. #define EREE_BAD_CREP_M         (ERROR_REGEXP_FIRST + 12)
  33. #define EREE_BAD_CREP_N         (ERROR_REGEXP_FIRST + 13)
  34. #define EREE_UNF_CREP           (ERROR_REGEXP_FIRST + 14)
  35. #define EREE_BAD_CREP           (ERROR_REGEXP_FIRST + 15)
  36. #define EREE_TOO_MANY_SUB       (ERROR_REGEXP_FIRST + 16)
  37. #define EREE_COMPILE_FSM        (ERROR_REGEXP_FIRST + 17)
  38. #define EREE_POSIX_COLLATING    (ERROR_REGEXP_FIRST + 18)
  39. #define EREE_POSIX_EQUIVALENCE  (ERROR_REGEXP_FIRST + 19)
  40. #define EREE_POSIX_CCLASS_BAD   (ERROR_REGEXP_FIRST + 20)
  41. #define EREE_BAD_BACKSLASH      (ERROR_REGEXP_FIRST + 21)
  42. #define EREE_BAD_BACKREF        (ERROR_REGEXP_FIRST + 22)
  43. #define EREE_SUBS_LEN           (ERROR_REGEXP_FIRST + 23)
  44. #define ERROR_REGEXP_LAST       (ERROR_REGEXP_FIRST + 23)
  45.  
  46. #define ERECF_TOLOWER           0x01
  47.  
  48. #define EREMF_SHORTEST          0x01
  49. #define EREMF_ANY           0x02
  50.  
  51. #define MAX_SPANS 9
  52.  
  53. typedef struct { int pos, len; } ERE_SPAN;
  54.  
  55. typedef struct
  56.     {
  57.         int      n_spans;
  58.         ERE_SPAN spans[MAX_SPANS];
  59.     } ERE_MATCHINFO;
  60.  
  61. #ifndef ERE_C
  62.  
  63. typedef void ERE;
  64.  
  65. extern ERE *rxpCompile(
  66.     const char *str,
  67.     int erecf,
  68.     int *rc
  69.     );
  70.  
  71. extern int rxpMinLen(const ERE *ere);
  72.  
  73. /* Returns the number of characters in the match, starting from pos characters
  74.    into the string to be searched. Details of sub-matches can also be returend.
  75.    Returns -1 if no match. */
  76. extern int rxpMatch(
  77.     const ERE *ere,
  78.     int eremf,
  79.     const char *str, int pos,
  80.     ERE_MATCHINFO *mi       /* can be NULL */
  81.     );
  82.  
  83. /* Returns TRUE if a match can be found starting pos characters into the string
  84.    to be searched. Position and length of match are returned. Details of
  85.    sub-matches can also be returned. */
  86. extern BOOLEAN rxpMatch_fwd(
  87.     const ERE *ere,
  88.     int eremf,
  89.     const char *str, int pos,
  90.     int *pos_match, int *len_match,
  91.     ERE_MATCHINFO *mi       /* can be NULL */
  92.     );
  93.  
  94. /* Returns TRUE if a match can be found starting pos characters into the string
  95.    to be searched and scanning backwards. Position and length of match are
  96.    returned. Details of sub-matches can also be returned. */
  97. extern BOOLEAN rxpMatch_bwd(
  98.     const ERE *ere,
  99.     int eremf,
  100.     const char *str, int pos,
  101.     int *pos_match, int *len_match,
  102.     ERE_MATCHINFO *mi       /* can be NULL */
  103.     );
  104.  
  105. extern void rxpFree(ERE *ere);
  106.  
  107. extern BOOLEAN rxpSubsWith(
  108.     const char *str,        /* Original string searched          */
  109.     int pos, int len,       /* Span of the entire match          */
  110.     ERE_MATCHINFO *mi,      /* Details of sub-spans of match     */
  111.     const char *with,       /* Specification of replacement      */
  112.     char *out,          /* Substituted string buffer         */
  113.     int len_out,            /* How much room in output buffer    */
  114.     int *rc             /* Error, if FALSE returned          */
  115.     );
  116.  
  117. #endif
  118.  
  119. #endif
  120.