00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "mit-copyright.h"
00010
00011 #ifdef SOLARIS
00012 #include <libgen.h>
00013 #endif
00014
00015 #include "main.h"
00016 #include "regexp.h"
00017
00018 #ifdef HAVE_REGCOMP
00019 #include <regex.h>
00020
00021 int
00022 ed_regexp_match_p(test_string, pattern)
00023 string test_string;
00024 string pattern;
00025 {
00026 regex_t RE;
00027 int retval;
00028 char errbuf[512];
00029
00030 retval = regcomp(&RE, pattern, REG_NOSUB);
00031 if (retval != 0) {
00032 regerror(retval, &RE, errbuf, sizeof(errbuf));
00033 fprintf(stderr, "%s in regcomp %s\n", errbuf, pattern);
00034 return (0);
00035 }
00036 retval = regexec(&RE, test_string, 0, NULL, 0);
00037 if (retval != 0 && retval != REG_NOMATCH) {
00038 regerror(retval, &RE, errbuf, sizeof(errbuf));
00039 fprintf(stderr, "%s in regexec %s\n", errbuf, pattern);
00040 regfree(&RE);
00041 return (0);
00042 }
00043 regfree(&RE);
00044 return (retval == 0 ? 1 : 0);
00045 }
00046
00047 #else
00048 char *re_comp();
00049 int re_exec();
00050
00051 int
00052 ed_regexp_match_p(test_string, pattern)
00053 string test_string;
00054 string pattern;
00055 {
00056 char *comp_retval;
00057 int exec_retval;
00058
00059 if (comp_retval = re_comp(pattern)) {
00060 fprintf(stderr, "%s in regex %s\n", comp_retval, pattern);
00061 return (0);
00062 }
00063 if ((exec_retval = re_exec(test_string)) == -1) {
00064 fprintf(stderr, "Internal error in re_exec()");
00065 return (0);
00066 }
00067
00068 return (exec_retval);
00069 }
00070 #endif
00071
00072 #if !defined(HAVE_RE_COMP) && !defined(HAVE_REGCOMP)
00073
00074 #ifdef HAVE_LIBGEN_H
00075 #include <libgen.h>
00076 #endif
00077
00078 static char *re;
00079
00080 char *
00081 re_comp(s)
00082 char *s;
00083 {
00084 if (!s)
00085 return 0;
00086 if (re)
00087 free(re);
00088
00089 if (!(re = regcmp(s, (char *) 0)))
00090 return "Bad argument to re_comp";
00091
00092 return 0;
00093 }
00094
00095 int
00096 re_exec(s)
00097 char *s;
00098 {
00099 return regex(re, s) != 0;
00100 }
00101
00102 #endif