Mailing-List: contact cygwin-apps-help AT cygwin DOT com; run by ezmlm Sender: cygwin-apps-owner AT cygwin DOT com List-Subscribe: List-Archive: List-Post: List-Help: , Delivered-To: mailing list cygwin-apps AT cygwin DOT com Date: 26 Dec 2001 10:17:29 -0500 Message-ID: <20011226151729.9206.qmail@lizard.curl.com> From: Jonathan Kamens To: cygwin-apps AT cygwin DOT com Subject: Patch to fortune to support POSIX regular expressions Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart_Wed_Dec_26_10:17:29_2001" Content-Transfer-Encoding: 7bit --Multipart_Wed_Dec_26_10:17:29_2001 Content-Type: text/plain; charset=US-ASCII The patch below makes the "fortune" program included with Cygwin support the "-m" flag using the regular expressions in the pcreposix library. This means that it adds to the fortune package a dependency on the "pcre" package. I have not submitted this patch upstream because (a) I don't know to whom to submit it and (b) I don't know what, if any, changes were made to the source tree by the maintainer of the Cygwin package. jik --Multipart_Wed_Dec_26_10:17:29_2001 Content-Type: text/plain; name=fortune-diff; charset=US-ASCII Content-Transfer-Encoding: 7bit diff -ru fortune-1.8-1/fortune/Makefile fortune-1.8-1.new/fortune/Makefile --- fortune-1.8-1/fortune/Makefile Sun Dec 2 11:03:28 2001 +++ fortune-1.8-1.new/fortune/Makefile Wed Dec 26 10:04:20 2001 @@ -1,4 +1,5 @@ -CFLAGS=$(O) -I../strfile -DNO_REGEX +CFLAGS=$(O) -I../strfile -DPOSIX_REGCOMP +LDLIBS=-lpcreposix all: fortune diff -ru fortune-1.8-1/fortune/fortune.c fortune-1.8-1.new/fortune/fortune.c --- fortune-1.8-1/fortune/fortune.c Sun Dec 2 10:37:39 2001 +++ fortune-1.8-1.new/fortune/fortune.c Wed Dec 26 10:12:42 2001 @@ -166,27 +166,43 @@ void zero_tbl __P((STRFILE *)); #ifndef NO_REGEX +# ifndef POSIX_REGCOMP char *conv_pat __P((char *)); +# endif int find_matches __P((void)); void matches_in_list __P((FILEDESC *)); int maxlen_in_list __P((FILEDESC *)); #endif #ifndef NO_REGEX -#ifdef REGCMP -# define RE_COMP(p) (Re_pat = regcmp(p, NULL)) -# define BAD_COMP(f) ((f) == NULL) -# define RE_EXEC(p) regex(Re_pat, (p)) +# ifdef POSIX_REGCOMP +# include + +# define RE_COMP(p) (Re_error = \ + regcomp(&Re_pat, (p), REG_EXTENDED|REG_NOSUB|\ + (ignore_case ? REG_ICASE : 0))) +# define BAD_COMP(f) ((f) != 0) +# define RE_EXEC(p) (! regexec(&Re_pat, (p), 0, NULL, 0)) + +regex_t Re_pat; +int Re_error; + +# else +# ifdef REGCMP +# define RE_COMP(p) (Re_pat = regcmp(p, NULL)) +# define BAD_COMP(f) ((f) == NULL) +# define RE_EXEC(p) regex(Re_pat, (p)) char *Re_pat; char *regcmp(), *regex(); -#else -# define RE_COMP(p) (p = re_comp(p)) -# define BAD_COMP(f) ((f) != NULL) -# define RE_EXEC(p) re_exec(p) +# else +# define RE_COMP(p) (p = re_comp(p)) +# define BAD_COMP(f) ((f) != NULL) +# define RE_EXEC(p) re_exec(p) -#endif +# endif +# endif #endif int @@ -374,16 +390,26 @@ exit(0); } -# ifndef NO_REGEX +#ifndef NO_REGEX if (pat != NULL) { +#ifndef POSIX_REGCOMP if (ignore_case) pat = conv_pat(pat); +#endif if (BAD_COMP(RE_COMP(pat))) { -#ifndef REGCMP +#ifdef POSIX_REGCOMP + char errbuf[BUFSIZ]; + (void) regerror(Re_error, &Re_pat, errbuf, + sizeof(errbuf)); + errbuf[sizeof(errbuf)-1] = '\0'; + fprintf(stderr, "%s\n", errbuf); +#else /* POSIX_REGCOMP */ +# ifndef REGCMP fprintf(stderr, "%s\n", pat); -#else /* REGCMP */ +# else /* REGCMP */ fprintf(stderr, "bad pattern: %s\n", pat); -#endif /* REGCMP */ +# endif /* REGCMP */ +#endif /* POSIX_REGCOMP */ } } # endif /* NO_REGEX */ @@ -1223,6 +1249,7 @@ } #ifndef NO_REGEX +# ifndef POSIX_REGCOMP /* * conv_pat: * Convert the pattern to an ignore-case equivalent. @@ -1265,6 +1292,7 @@ *sp = '\0'; return new; } +# endif /* POSIX_REGCOMP */ /* * find_matches: --Multipart_Wed_Dec_26_10:17:29_2001--