home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / passwd+ / patSYSV.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  2.0 KB  |  97 lines

  1. /*
  2.  * interface for System V pattern matchers
  3.  */
  4. #include "passwd.h"
  5.  
  6. /*
  7.  * set up some things on a per-system basis here
  8.  */
  9. #define INIT        register char *sp = instring;
  10. #define GETC()        (*sp++)
  11. #define PEEKC()        (*sp)
  12. #define UNGETC(c)    (--sp)
  13. #define RETURN(c)    return;
  14. #define ERROR(c)    regerr(c)
  15. #include <regexp.h>
  16.  
  17. /*
  18.  * global variables
  19.  */
  20. static char *pattern;        /* points to typed-in pattern */
  21. static char patcomp[BUFSIZ];    /* buffer for compiled pattern */
  22.  
  23. /*
  24.  * smatch -- set up the pattern to be matched; bomb on error
  25.  */
  26. int smatch(pat)
  27. char *pat;            /* pattern to be matched */
  28. {
  29.     pattern = pat;
  30.     (void) compile(pat, patcomp, &patcomp[BUFSIZ], '\0');
  31.     return(0);
  32. }
  33.  
  34. /*
  35.  * match -- compare a string to the compiled pattern
  36.  */
  37. match(str)
  38. char *str;            /* string to be compared */
  39. {
  40.     /*
  41.      * compare appropriately
  42.      */
  43.     return(step(str, patcomp));
  44. }
  45.  
  46. /*
  47.  * regerr -- pattern matching error handler
  48.  */
  49. regerr(n)
  50. int n;                /* number of error */
  51. {
  52.     char buf[BUFSIZ];    /* buffer for error message */
  53.  
  54.     switch(n){
  55.     case 11:
  56.         SPRINTF(buf, "%s: range endpoint too large", pattern);
  57.         break;
  58.     case 16:
  59.         SPRINTF(buf, "%s: bad number", pattern);
  60.         break;
  61.     case 25:
  62.         SPRINTF(buf, "%s: \"\\digit\" out of range", pattern);
  63.         break;
  64.     case 36:
  65.         SPRINTF(buf, "%s: illegal or missing delimiter", pattern);
  66.         break;
  67.     case 41:
  68.         SPRINTF(buf, "%s: no remembered search string", pattern);
  69.         break;
  70.     case 42:
  71.         SPRINTF(buf, "%s: \\( \\) imbalance", pattern);
  72.         break;
  73.     case 43:
  74.         SPRINTF(buf, "%s: too many \\(", pattern);
  75.         break;
  76.     case 44:
  77.         SPRINTF(buf, "%s: more than 2 numbers given in \\{ \\}", pattern);
  78.         break;
  79.     case 45:
  80.         SPRINTF(buf, "%s: } expected after \\", pattern);
  81.         break;
  82.     case 46:
  83.         SPRINTF(buf, "%s: first number exceeds second in \\{ \\}", pattern);
  84.         break;
  85.     case 49:
  86.         SPRINTF(buf, "%s: { } imbalance", pattern);
  87.         break;
  88.     case 50:
  89.         SPRINTF(buf, "%s: regular expression overflow", pattern);
  90.         break;
  91.     default:
  92.         SPRINTF(buf, "%s: unknown regexp error %d", pattern, n);
  93.         break;
  94.     }
  95.     paterr(buf);
  96. }
  97.