home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / util / sys5_regex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.6 KB  |  76 lines

  1. #include <config.h>
  2.  
  3. #ifdef SYS5
  4.  
  5. /* sys5_regex.c: system 5 Regex emulation */
  6.  
  7. # ifndef lint
  8. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/util/RCS/sys5_regex.c,v 6.0 1991/12/18 20:25:18 jpo Rel $";
  9. # endif
  10.  
  11. /*
  12.  * $Header: /xtel/pp/pp-beta/Lib/util/RCS/sys5_regex.c,v 6.0 1991/12/18 20:25:18 jpo Rel $
  13.  *
  14.  * $Log: sys5_regex.c,v $
  15.  * Revision 6.0  1991/12/18  20:25:18  jpo
  16.  * Release 6.0
  17.  *
  18.  */
  19.  
  20. /*
  21.  *    Emulation of UCB regular expressions routines using
  22.  *    the ATT variety.  Note that the regex syntax is not
  23.  *    identical (ATT has extra features) so it may be necessary
  24.  *    to preprocess the string before passing to regcmp().
  25.  *
  26.  *    I am not sure if my mapping of the return from regex() is
  27.  *    adequate. It may also be necessary to count '(...)$n' parts
  28.  *    of the regular expression to be able to provide return value
  29.  *    storage for regex().
  30.  *
  31.  *    You probably need to lib agains libPW for these routines but
  32.  *    it may be necessary to include an explicit "-lc" before the
  33.  *    "-lPW" so as not to pick up other (unwanted) PWB routines.
  34.  */
  35.  
  36. static char * complied_regex;
  37.  
  38. char * re_comp(s)
  39. char *s;
  40. {
  41.     char * res;
  42.     extern char * regcmp();
  43.  
  44.     if (s == (char *)0 || *s == '\0')
  45.     return (char *)0;
  46.  
  47.     res = regcmp(s, 0);
  48.     if (res == (char *)0)
  49.     return "invalid regular expression";
  50.     
  51.     if (complied_regex != (char *)0)
  52.     free(complied_regex);
  53.     
  54.     complied_regex = res;
  55.     return (char *)0;
  56. }
  57.  
  58. re_exec(s)
  59. char *s;
  60. {
  61.     extern char * regex();
  62.  
  63.     if (complied_regex == (char *)0)
  64.     return -1;
  65.  
  66.     if (regex(complied_regex, s) == (char *)0)
  67.     return 0;
  68.     else
  69.     return 1;
  70. }
  71. #else
  72.  
  73. sys5_regex_stub () {}
  74.  
  75. #endif /* SYS5 */
  76.