home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / MATCH.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  4KB  |  115 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4.  EPSHeader
  5.  
  6.    File: match.h
  7.    Author: J. Kercheval
  8.    Created: Sat, 01/05/1991  22:27:18
  9. */
  10. /*
  11.  EPSRevision History
  12.  
  13.    J. Kercheval  Wed, 02/20/1991  22:28:37  Released to Public Domain
  14.    J. Kercheval  Sun, 03/10/1991  18:02:56  add is_valid_pattern
  15.    J. Kercheval  Sun, 03/10/1991  18:25:48  add error_type in is_valid_pattern
  16.    J. Kercheval  Sun, 03/10/1991  18:47:47  error return from matche()
  17.    J. Kercheval  Tue, 03/12/1991  22:24:49  Released as V1.1 to Public Domain
  18. */
  19.  
  20. #ifndef MATCH__H
  21. #define MATCH__H
  22.  
  23. /*
  24.    Wildcard Pattern Matching
  25. */
  26.  
  27. #ifndef BOOLEAN
  28. # define BOOLEAN int
  29. # define TRUE 1
  30. # define FALSE 0
  31. #endif
  32.  
  33. /* match defines */
  34. #define MATCH_PATTERN  6    /* bad pattern */
  35. #define MATCH_LITERAL  5    /* match failure on literal match */
  36. #define MATCH_RANGE    4    /* match failure on [..] construct */
  37. #define MATCH_ABORT    3    /* premature end of text string */
  38. #define MATCH_END      2    /* premature end of pattern string */
  39. #define MATCH_VALID    1    /* valid match */
  40.  
  41. /* pattern defines */
  42. #define PATTERN_VALID  0    /* valid pattern */
  43. #define PATTERN_ESC   -1    /* literal escape at end of pattern */
  44. #define PATTERN_RANGE -2    /* malformed range in [..] construct */
  45. #define PATTERN_CLOSE -3    /* no end bracket in [..] construct */
  46. #define PATTERN_EMPTY -4    /* [..] construct is empty */
  47.  
  48. /*----------------------------------------------------------------------------
  49. *
  50. *  Match the pattern PATTERN against the string TEXT;
  51. *
  52. *       match() returns TRUE if pattern matches, FALSE otherwise.
  53. *       matche() returns MATCH_VALID if pattern matches, or an errorcode
  54. *           as follows otherwise:
  55. *
  56. *            MATCH_PATTERN  - bad pattern
  57. *            MATCH_LITERAL  - match failure on literal mismatch
  58. *            MATCH_RANGE    - match failure on [..] construct
  59. *            MATCH_ABORT    - premature end of text string
  60. *            MATCH_END      - premature end of pattern string
  61. *            MATCH_VALID    - valid match
  62. *
  63. *
  64. *  A match means the entire string TEXT is used up in matching.
  65. *
  66. *  In the pattern string:
  67. *       `*' matches any sequence of characters (zero or more)
  68. *       `?' matches any character
  69. *       [SET] matches any character in the specified set,
  70. *       [!SET] or [^SET] matches any character not in the specified set.
  71. *
  72. *  A set is composed of characters or ranges; a range looks like
  73. *  character hyphen character (as in 0-9 or A-Z).  [0-9a-zA-Z_] is the
  74. *  minimal set of characters allowed in the [..] pattern construct.
  75. *  Other characters are allowed (ie. 8 bit characters) if your system
  76. *  will support them.
  77. *
  78. *  To suppress the special syntactic significance of any of `[]*?!^-\',
  79. *  and match the character exactly, precede it with a `\'.
  80. *
  81. ----------------------------------------------------------------------------*/
  82.  
  83. BOOLEAN match (char *pattern, char *text);
  84.  
  85. int     matche(register char *pattern, register char *text);
  86.  
  87. /*----------------------------------------------------------------------------
  88. *
  89. * Return TRUE if PATTERN has any special wildcard characters
  90. *
  91. ----------------------------------------------------------------------------*/
  92.  
  93. BOOLEAN is_pattern (char *pattern);
  94.  
  95. /*----------------------------------------------------------------------------
  96. *
  97. * Return TRUE if PATTERN has is a well formed regular expression according
  98. * to the above syntax
  99. *
  100. * error_type is a return code based on the type of pattern error.  Zero is
  101. * returned in error_type if the pattern is a valid one.  error_type return
  102. * values are as follows:
  103. *
  104. *   PATTERN_VALID - pattern is well formed
  105. *   PATTERN_ESC   - pattern has invalid escape ('\' at end of pattern)
  106. *   PATTERN_RANGE - [..] construct has a no end range in a '-' pair (ie [a-])
  107. *   PATTERN_CLOSE - [..] construct has no end bracket (ie [abc-g )
  108. *   PATTERN_EMPTY - [..] construct is empty (ie [])
  109. *
  110. ----------------------------------------------------------------------------*/
  111.  
  112. BOOLEAN is_valid_pattern (char *pattern, int *error_type);
  113.  
  114. #endif /* MATCH__H */
  115.