home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 278.lha / RegexLibrary_v1.0 / lib1.c < prev    next >
C/C++ Source or Header  |  1989-08-06  |  1KB  |  67 lines

  1. /*
  2.  *  BSD style entry points for the GNU regular expression package.
  3.  *  Edwin Hoogerbeets 18/07/89
  4.  *
  5.  *  This file may be copied and distributed under the GNU Public
  6.  *  Licence. See the comment at the top of regex.c for details.
  7.  *
  8.  *  Adapted from Elib by Jim Mackraz, mklib by Edwin Hoogerbeets, and the
  9.  *  GNU regular expression package by the Free Software Foundation.
  10.  */
  11.  
  12.  
  13. #include "regex.h"
  14.  
  15. /* Entry points compatible with bsd4.2 regex library.
  16.  * These must be in a .lib file since they use a global variable
  17.  * to store the "previous regular expression" that vi is fond of.
  18.  */
  19.  
  20. static struct re_pattern_buffer re_comp_buf;
  21.  
  22. extern char *malloc();
  23.  
  24. char *re_BSD_initialize()
  25. {
  26.   return(re_initialize_buffer(&re_comp_buf,__Upcase));
  27. }
  28.  
  29. void re_BSD_terminate()
  30. {
  31.   re_terminate_buffer(&re_comp_buf);
  32. }
  33.  
  34. char *
  35. re_comp(s)
  36. char *s;
  37. {
  38.   if ( !s ) {
  39.     if ( !(re_comp_buf.buffer) )
  40.       return ("No previous regular expression");
  41.     return((char *)0L);
  42.   }
  43.  
  44.   if ( !re_comp_buf.buffer ) {
  45.     register char *result;
  46.  
  47.     if ( (result = re_BSD_initialize()) ) {
  48.       return( result );
  49.     }
  50.   }
  51.  
  52.   return( (char *) re_compile_pattern(s, (long) strlen(s), &re_comp_buf,
  53.                                       RE_SYNTAX_GREP) );
  54. }
  55.  
  56. LONG
  57. re_exec(s)
  58. char *s;
  59. {
  60.   long len = strlen (s);
  61.   return( (long) 0 <= re_search(&re_comp_buf, s, len, 0L, len, 0L) );
  62. }
  63.  
  64.  
  65.  
  66.  
  67.