]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/regexp.c
r4264@bucket (orig r254): kcr | 2008-01-20 22:11:44 -0500
[1ts-debian.git] / zephyr / zwgc / regexp.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It is one of the source files comprising zwgc, the Zephyr WindowGram
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id$
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14 #include <sysdep.h>
15 #include <regex.h>
16
17 #if (!defined(lint) && !defined(SABER))
18 static const char rcsid_regexp_c[] = "$Id$";
19 #endif
20
21 #include "regexp.h"
22
23 int
24 ed_regexp_match_p(string test_string,
25                   string pattern)
26 {
27     regex_t RE;
28     int retval;
29     char errbuf[512];
30
31     retval = regcomp(&RE, pattern, REG_NOSUB);
32     if (retval != 0) {
33         regerror(retval, &RE, errbuf, sizeof(errbuf));
34         fprintf(stderr,"%s in regcomp %s\n",errbuf,pattern);
35         return(0);
36     }
37     retval = regexec(&RE, test_string, 0, NULL, 0);
38     if (retval != 0 && retval != REG_NOMATCH) {
39         regerror(retval, &RE, errbuf, sizeof(errbuf));
40         fprintf(stderr,"%s in regexec %s\n",errbuf,pattern);
41         regfree(&RE);
42         return(0);
43     }
44     regfree(&RE);
45     return(retval == 0 ? 1 : 0);
46 }