home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* Copyright 1988, 1989 by Chuck Musciano and Harris Corporation */
- /* */
- /* Permission to use, copy, modify, and distribute this software */
- /* and its documentation for any purpose and without fee is */
- /* hereby granted, provided that the above copyright notice */
- /* appear in all copies and that both that copyright notice and */
- /* this permission notice appear in supporting documentation, and */
- /* that the name of Chuck Musciano and Harris Corporation not be */
- /* used in advertising or publicity pertaining to distribution */
- /* of the software without specific, written prior permission. */
- /* Chuck Musciano and Harris Corporation make no representations */
- /* about the suitability of this software for any purpose. It is */
- /* provided "as is" without express or implied warranty. This */
- /* software may not be sold without the prior explicit permission */
- /* of Harris Corporation. */
- /************************************************************************/
-
- #include <stdio.h>
-
- #include "contool.h"
-
- PRIVATE regexp_error();
-
- #define INIT register char *expbuf = ep, *sp = instring;
- #define GETC() (*sp++)
- #define PEEKC() (*sp)
- #define UNGETC(c) (--sp)
- #define RETURN(p) {bcopy(expbuf, sp = (char *) malloc(p - expbuf), p - expbuf); return(sp);}
- #define ERROR(val) {regexp_error(val, instring); return(NULL);}
-
- #include <regexp.h>
-
- PRIVATE char error_message[512];
-
- /************************************************************************/
- EXPORT int match_exp(exp, circ, str)
-
- char *exp;
- int circ;
- char *str;
-
- {
- circf = circ;
- return(step(str, exp));
- }
-
- /************************************************************************/
- PRIVATE regexp_error(val, string)
-
- int val;
- char *string;
-
- { char *msg;
-
- switch (val) {
- case 11 : msg = "range endpoint too large";
- case 16 : msg = "bad number";
- case 25 : msg = "\"\\digit\" out of range";
- case 36 : msg = "illegal or missing delimiter";
- case 41 : msg = "no remembered search string";
- case 42 : msg = "\\(\\) imbalance";
- case 43 : msg = "too many \\(";
- case 44 : msg = "more than 2 numbers given in \\{\\}";
- case 45 : msg = "} expected after \\";
- case 46 : msg = "first number exceeds second in \\{\\}";
- case 49 : msg = "[] imbalance";
- case 50 : msg = "regular expression overflow";
- default : msg = "regular expression error";
- }
- sprintf(error_message, "%s in\n\t%s", msg, string);
- }
-
- /************************************************************************/
- EXPORT char *compile_exp(filter, start, end)
-
- f_ptr filter;
- char *start;
- char *end;
-
- { char rbuf[1024], *sre, *ere;
- int sc, ec;
-
- sre = ere = NULL;
- if ((sre = compile(start, rbuf, rbuf+1024, '\0')) == NULL)
- return(error_message);
- sc = circf;
- if (end) {
- if ((ere = compile(end, rbuf, rbuf+1024, '\0')) == NULL) {
- free(sre);
- return(error_message);
- }
- ec = circf;
- }
- if (filter) {
- filter->start = start;
- filter->end = end;
- filter->start_re = sre;
- filter->end_re = ere;
- filter->scircf = sc;
- filter->ecircf = ec;
- }
- else {
- free(sre);
- if (ere)
- free(ere);
- }
- return(NULL);
- }
-