home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / wildf113.zip / FILMATCH.H < prev    next >
C/C++ Source or Header  |  1991-03-28  |  4KB  |  110 lines

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