1 /******************************************************************** 2 * $Author: jgoerzen $ 3 * $Revision: 1.17 $ 4 * $Date: 2002/03/19 20:57:55 $ 5 * $Source: /home/jgoerzen/tmp/gopher-umn/gopher/head/object/Regex.h,v $ 6 * $State: Exp $ 7 * 8 * Paul Lindner, University of Minnesota CIS. 9 * 10 * Copyright 1991, 1992 by the Regents of the University of Minnesota 11 * see the file "Copyright" in the distribution for conditions of use. 12 ********************************************************************* 13 * MODULE: Regex.h 14 * Portable method of doing regular expressions 15 ********************************************************************* 16 * Revision History: 17 * $Log: Regex.h,v $ 18 * Revision 1.17 2002/03/19 20:57:55 jgoerzen 19 * Modified #warn -> #warning to use correct syntax. 20 * 21 * Revision 1.16 2002/03/19 20:37:28 jgoerzen 22 * Updated configure stuff with regcomp and regfree checks. 23 * Made Regex.h more robust with regcomp stuff. 24 * 25 * Revision 1.15 2002/03/19 20:07:16 jgoerzen 26 * GSgopherobj.c: Moved Regex.h include up. 27 * 28 * Regex.c, Regex.h: continuing full rewrites. 29 * 30 * Revision 1.14 2002/03/19 19:58:12 jgoerzen 31 * More updates. This is part of a major rewrite. 32 * 33 * Revision 1.13 2002/03/19 19:53:31 jgoerzen 34 * *** empty log message *** 35 * 36 * Revision 1.12 2002/03/19 18:07:42 jgoerzen 37 * Fixed regex stuff for Solaris -- I hope! 38 * 39 * Updated changelog. 40 * 41 * More notes in Platforms. 42 * 43 * Revision 1.11 2002/02/12 20:57:18 jgoerzen 44 * Fixed an incorrect comment and added parens 45 * 46 * Revision 1.10 2002/02/12 20:50:21 jgoerzen 47 * Beginning of MacOS X (Darwin) support. 48 * Many modifications to Regex.[ch], see debian/changelog for details. 49 * 50 * Revision 1.9 2002/02/12 19:54:18 jgoerzen 51 * Updated with regex fixes 52 * 53 * Revision 1.8 2002/01/10 18:48:31 jgoerzen 54 * Fix for Linux 55 * 56 * Revision 1.7 2002/01/10 18:43:18 jgoerzen 57 * * Changes to work with Solaris: 58 * * configure.in: Now looks for strings.h and string.h 59 * * object/Regex.h: Now include re_comp.h if available. 60 * Include regex.h only if re_comp.h is unavailable. 61 * Define the SYSVREGEX stuff only if HAVE_RE_COMP_H is not defined 62 * * object/String.h: Include string.h and strings.h based on configure 63 * test. 64 * 65 * Revision 1.6 2002/01/08 18:28:02 jgoerzen 66 * * object/Regex.h: now conditionally includes sys/types.h for regex.h 67 * 68 * Revision 1.5 2002/01/08 17:36:14 jgoerzen 69 * Finally builds! 70 * 71 * Changes: 72 * 73 * * config.h.in: rebuilt by autoheader 74 * 75 * * configure: rebuilt by autoconf 76 * 77 * * configure.in: 78 * * Added REGEXLIBS test for NetBSD -- look for re_comp in -lcompat 79 * * Added checkes for term.h, re_comp.h, regex.h 80 * 81 * * gopher/ourutils.c, gopher/CURcurses.c: Use term.h check 82 * 83 * * gopher/Makefile.in, gopherd/Makefile.in, gophfilt/Makefile.in: 84 * * Use REGEXLIBS 85 * 86 * * gopher/globals.h, gopher/gopher.c: Remove sys_errlist 87 * 88 * * object/GSgopherobj.c: Removed <regex.h> #include, now use 89 * "Regex.h" that has proper regex determining logic 90 * 91 * * object/Regex.h: Moved regex.h include to here. Make it conditional 92 * based on configure test. Add conditional re_comp.h include. 93 * 94 * Revision 1.4 2001/02/26 21:22:08 jgoerzen 95 * Updated 96 * 97 * Revision 1.3 2001/01/17 21:48:05 jgoerzen 98 * Many fixes and tune-ups. Now compiles cleanly with -Wall -Werror! 99 * 100 * Revision 1.2 2000/12/20 01:19:20 jgoerzen 101 * Added patches from David Allen <s2mdalle@titan.vcu.edu> 102 * 103 * Revision 1.1.1.1 2000/08/19 00:28:56 jgoerzen 104 * Import from UMN Gopher 2.3.1 after GPLization 105 * 106 * Revision 3.7 1994/07/25 13:56:54 lindner 107 * First crack at POSIX regular expressions 108 * 109 * Revision 3.6 1994/07/21 17:29:13 lindner 110 * Fix typo 111 * 112 * Revision 3.5 1994/03/08 04:04:16 lindner 113 * add regex.h for NeXT systems 114 * 115 * Revision 3.4 1994/03/04 17:42:00 lindner 116 * Fix for SCO machines 117 * 118 * Revision 3.3 1994/02/20 16:24:02 lindner 119 * no message 120 * 121 * Revision 3.2 1993/10/27 18:50:38 lindner 122 * Support for more sysv platforms 123 * 124 * Revision 3.1 1993/10/19 20:48:26 lindner 125 * Portable versions of Regular expression routines for System V and BSD.. 126 * 127 * 128 *********************************************************************/ 129 130 #ifndef __GOPHER_REGEX_H__ 131 #define __GOPHER_REGEX_H__ 132 133 #include "config.h" 134 135 /***************** 136 Basic POSIX support detection */ 137 138 #ifdef HAVE_SYS_TYPES_H 139 /* POSIX and Linux regex.h implementations want sys/types.h */ 140 #include <sys/types.h> 141 #endif 142 143 #ifdef HAVE_REGEX_H 144 #include <regex.h> 145 #endif 146 147 #if defined(HAVE_REGCOMP) && defined(HAVE_REGFREE) 148 #define REGEX_POSIX 149 #endif 150 151 /************* 152 OK, handle the POSIX case. */ 153 154 #ifdef REGEX_POSIX 155 156 /* Try including files until we get REG_EXTENDED. */ 157 158 #ifndef REG_EXTENDED 159 #ifdef HAVE_UNISTD_H 160 #include <unistd.h> 161 #endif 162 #endif 163 164 #ifndef REG_EXTENDED 165 #ifdef HAVE_REGEXP_H 166 #include <regexp.h> 167 #endif 168 #endif 169 170 #ifndef REG_EXTENDED 171 #warning REGEX_POSIX defined but REG_EXTENDED not found. 172 #endif 173 174 /* These are named posix_re_comp and then #defined to the original names 175 because MacOS X is nice enough to typedef re_comp and re_exec differently 176 in unistd.h. Eww. */ 177 178 char *posix_re_comp(char *regex); 179 int posix_re_exec(char *string); 180 #define re_comp(a) (posix_re_comp(a)) 181 #define re_exec(a) (posix_re_exec(a)) 182 #else 183 184 /* ********** Try to figure out what else they have. */ 185 186 #ifdef HAVE_RE_COMP 187 /* This generally means that they have re_comp themselves. Just 188 include it for them and leave it. */ 189 190 #ifdef HAVE_RE_COMP_H 191 #include <re_comp.h> 192 #else 193 #include <unistd.h> 194 #endif /* HAVE_RE_COMP_H */ 195 196 #else 197 #ifdef HAVE_REGEXP_H 198 /* This means SYSV... */ 199 #define SYSVREGEX 200 #define REGEX_SYSV 201 # include "Malloc.h" /** For NULL **/ 202 203 # ifdef REGEX_CODEIT 204 # define INIT register char *sp = instring; 205 # define GETC() (*sp++) 206 # define PEEKC() (*sp) 207 # define UNGETC(c) (--sp) 208 # define RETURN(c) return(NULL); 209 # define ERROR(c) return("error") 210 211 # include <regexp.h> 212 213 # endif /* REGEX_CODEIT */ 214 215 /* Prototypes for Regex.c */ 216 char *re_comp(char *expr); 217 int re_exec(char *string); 218 219 #else 220 221 #error "Unsupported or no regexp support." 222 223 #endif /* REGEX_SYSV */ 224 #endif /* HAVE_RE_COMP */ 225 #endif /* REGEX_POSIX */ 226 227 #endif /* __GOPHER_REGEX_H__ */ 228 229