home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / UNIX / Programming / class-dump-2.1.1-MIS / src / my_regex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-08  |  1.8 KB  |  73 lines

  1. //
  2. // $Id: my_regex.c,v 1.1 1997/12/08 07:11:08 nygard Exp $
  3. //
  4.  
  5. //
  6. //  This file is a part of class-dump v2, a utility for examining the
  7. //  Objective-C segment of Mach-O files.
  8. //  Copyright (C) 1997  Steve Nygard
  9. //
  10. //  This program is free software; you can redistribute it and/or modify
  11. //  it under the terms of the GNU General Public License as published by
  12. //  the Free Software Foundation; either version 2 of the License, or
  13. //  (at your option) any later version.
  14. //
  15. //  This program is distributed in the hope that it will be useful,
  16. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. //  GNU General Public License for more details.
  19. //
  20. //  You should have received a copy of the GNU General Public License
  21. //  along with this program; if not, write to the Free Software
  22. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. //
  24. //  You may contact the author by:
  25. //     e-mail:  nygard@telusplanet.net
  26. //
  27.  
  28. #include <stdio.h>
  29. #include <sys/types.h>
  30.  
  31. #import "my_regex.h"
  32.  
  33. #ifdef __APPLE_CPP__
  34.  
  35. //
  36. // This provides functions compatible with the interface of the old style
  37. // regular expression matching functions.  Note, however, that we use the
  38. // extended regular expression syntax.
  39. //
  40.  
  41. static regex_t compiled_regex;
  42. static char regex_error_buffer[256];
  43.  
  44. char *my_re_comp (const char *pattern)
  45. {
  46.     int result;
  47.  
  48.     result = regcomp (&compiled_regex, pattern, REG_EXTENDED);
  49.     if (result != 0)
  50.     {
  51.         regerror (result, &compiled_regex, regex_error_buffer, sizeof (regex_error_buffer));
  52.         return regex_error_buffer;
  53.     }
  54.  
  55.     return NULL;
  56. }
  57.  
  58. int my_re_exec (const char *text)
  59. {
  60.     int result;
  61.  
  62.     result = regexec (&compiled_regex, text, 0, NULL, 0);
  63.  
  64.     return (result == 0) ? 1 : 0;
  65. }
  66.  
  67. void my_re_free (void)
  68. {
  69.     regfree (&compiled_regex);
  70. }
  71.  
  72. #endif
  73.