1*** bak/regex.c Wed Feb 15 13:11:50 1995 2--- regex.c Wed Feb 15 13:24:56 1995 3*************** 4*** 19,24 **** 5--- 19,41 ---- 6 along with this program; if not, write to the Free Software 7 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 8 9+ /* MODIFIED By Jan Wielemaker, Tue Feb 14 23:07:23 1995 to be included 10+ in XPCE 11+ */ 12+ 13+ #ifdef pce_source 14+ #define string PCEstring 15+ #include <h/kernel.h> 16+ #undef string 17+ #define Sword AN 18+ #define HASSYNTAX(c, s) ((char_flags[(unsigned int)(c)] & s) ? 1 : 0) 19+ #undef fail /* conflict */ 20+ #undef DEBUG /* conflict */ 21+ #define SYNTAX_TABLE 1 22+ #define CHAR_SET_SIZE 256 23+ 24+ #else /*pce_source*/ 25+ 26 /* AIX requires this to be the first thing in the file. */ 27 #if defined (_AIX) && !defined (REGEX_MALLOC) 28 #pragma alloca 29*************** 30*** 40,45 **** 31--- 57,64 ---- 32 /* We need this for `regex.h', and perhaps for the Emacs include files. */ 33 #include <sys/types.h> 34 35+ #endif /*pce_source*/ 36+ 37 /* The `emacs' switch turns on certain matching commands 38 that make sense only in Emacs. */ 39 #ifdef emacs 40*************** 41*** 131,140 **** 42 #endif /* not emacs */ 43 44 /* Get the interface, including the syntax bits. */ 45! #include "regex.h" 46 47 /* isalpha etc. are used for the character classes. */ 48 #include <ctype.h> 49 50 /* Jim Meyering writes: 51 52--- 150,161 ---- 53 #endif /* not emacs */ 54 55 /* Get the interface, including the syntax bits. */ 56! #include "gregex.h" 57 58 /* isalpha etc. are used for the character classes. */ 59+ #ifndef pce_source 60 #include <ctype.h> 61+ #endif 62 63 /* Jim Meyering writes: 64 65*************** 66*** 391,397 **** 67 wordbound, /* Succeeds if at a word boundary. */ 68 notwordbound /* Succeeds if not at a word boundary. */ 69 70! #ifdef emacs 71 ,before_dot, /* Succeeds if before point. */ 72 at_dot, /* Succeeds if at point. */ 73 after_dot, /* Succeeds if after point. */ 74--- 412,418 ---- 75 wordbound, /* Succeeds if at a word boundary. */ 76 notwordbound /* Succeeds if not at a word boundary. */ 77 78! #if defined(emacs) || defined(pce_source) 79 ,before_dot, /* Succeeds if before point. */ 80 at_dot, /* Succeeds if at point. */ 81 after_dot, /* Succeeds if after point. */ 82*************** 83*** 732,741 **** 84--- 753,767 ---- 85 case after_dot: 86 printf ("/after_dot"); 87 break; 88+ #endif /*emacs*/ 89 90+ #if defined(emacs) || defined(pce_source) 91 case syntaxspec: 92 printf ("/syntaxspec"); 93 mcnt = *p++; 94+ #ifdef pce_source 95+ mcnt |= (*p++ << 8); 96+ #endif /* pce_source */ 97 printf ("/%d", mcnt); 98 break; 99 100*************** 101*** 742,750 **** 102 case notsyntaxspec: 103 printf ("/notsyntaxspec"); 104 mcnt = *p++; 105 printf ("/%d", mcnt); 106 break; 107! #endif /* emacs */ 108 109 case wordchar: 110 printf ("/wordchar"); 111--- 768,779 ---- 112 case notsyntaxspec: 113 printf ("/notsyntaxspec"); 114 mcnt = *p++; 115+ #ifdef pce_source 116+ mcnt |= (*p++ << 8); 117+ #endif /* pce_source */ 118 printf ("/%d", mcnt); 119 break; 120! #endif /* emacs || pce_source */ 121 122 case wordchar: 123 printf ("/wordchar"); 124*************** 125*** 2362,2367 **** 126--- 2391,2413 ---- 127 break; 128 #endif /* emacs */ 129 130+ #ifdef pce_source 131+ case 's': 132+ laststart = b; 133+ PATFETCH (c); 134+ BUF_PUSH_3 (syntaxspec, 135+ syntax_spec_code[c] & 0xff, 136+ (syntax_spec_code[c] >> 8) & 0xff); 137+ break; 138+ 139+ case 'S': 140+ laststart = b; 141+ PATFETCH (c); 142+ BUF_PUSH_3 (notsyntaxspec, 143+ syntax_spec_code[c] & 0xff, 144+ (syntax_spec_code[c] >> 8 ) & 0xff); 145+ break; 146+ #endif /* pce_source */ 147 148 case 'w': 149 laststart = b; 150*************** 151*** 2842,2848 **** 152 153 case wordchar: 154 for (j = 0; j < (1 << BYTEWIDTH); j++) 155! if (SYNTAX (j) == Sword) 156 fastmap[j] = 1; 157 break; 158 159--- 2888,2894 ---- 160 161 case wordchar: 162 for (j = 0; j < (1 << BYTEWIDTH); j++) 163! if ( HASSYNTAX (j, Sword)) 164 fastmap[j] = 1; 165 break; 166 167*************** 168*** 2849,2855 **** 169 170 case notwordchar: 171 for (j = 0; j < (1 << BYTEWIDTH); j++) 172! if (SYNTAX (j) != Sword) 173 fastmap[j] = 1; 174 break; 175 176--- 2895,2901 ---- 177 178 case notwordchar: 179 for (j = 0; j < (1 << BYTEWIDTH); j++) 180! if ( !HASSYNTAX (j, Sword) ) 181 fastmap[j] = 1; 182 break; 183 184*************** 185*** 2879,2885 **** 186 case syntaxspec: 187 k = *p++; 188 for (j = 0; j < (1 << BYTEWIDTH); j++) 189! if (SYNTAX (j) == (enum syntaxcode) k) 190 fastmap[j] = 1; 191 break; 192 193--- 2925,2931 ---- 194 case syntaxspec: 195 k = *p++; 196 for (j = 0; j < (1 << BYTEWIDTH); j++) 197! if ( HASSYNTAX (j, k) ) 198 fastmap[j] = 1; 199 break; 200 201*************** 202*** 2887,2893 **** 203 case notsyntaxspec: 204 k = *p++; 205 for (j = 0; j < (1 << BYTEWIDTH); j++) 206! if (SYNTAX (j) != (enum syntaxcode) k) 207 fastmap[j] = 1; 208 break; 209 210--- 2933,2939 ---- 211 case notsyntaxspec: 212 k = *p++; 213 for (j = 0; j < (1 << BYTEWIDTH); j++) 214! if ( !HASSYNTAX (j, k) ) 215 fastmap[j] = 1; 216 break; 217 218*************** 219*** 2902,2907 **** 220--- 2948,2973 ---- 221 continue; 222 #endif /* not emacs */ 223 224+ #ifdef pce_source 225+ { unsigned short k; 226+ 227+ case syntaxspec: 228+ k = *p++; 229+ k |= (*p++ << 8); 230+ for (j = 0; j < (1 << BYTEWIDTH); j++) 231+ if ( HASSYNTAX (j, k)) 232+ fastmap[j] = 1; 233+ break; 234+ 235+ case notsyntaxspec: 236+ k = *p++; 237+ k |= (*p++ << 8); 238+ for (j = 0; j < (1 << BYTEWIDTH); j++) 239+ if ( !HASSYNTAX (j, k)) 240+ fastmap[j] = 1; 241+ break; 242+ } 243+ #endif /* pce_source */ 244 245 case no_op: 246 case begline: 247*************** 248*** 3261,3269 **** 249 the first character in string2; and if before the beginning of 250 string2, look at the last character in string1. */ 251 #define WORDCHAR_P(d) \ 252! (SYNTAX ((d) == end1 ? *string2 \ 253! : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ 254! == Sword) 255 256 /* Test if the character before D and the one at D differ with respect 257 to being word-constituent. */ 258--- 3327,3334 ---- 259 the first character in string2; and if before the beginning of 260 string2, look at the last character in string1. */ 261 #define WORDCHAR_P(d) \ 262! (HASSYNTAX (((d) == end1 ? *string2 \ 263! : (d) == string2 - 1 ? *(end1 - 1) : *(d)), Sword)) 264 265 /* Test if the character before D and the one at D differ with respect 266 to being word-constituent. */ 267*************** 268*** 4502,4508 **** 269 break; 270 goto fail; 271 272! #ifdef emacs 273 case before_dot: 274 DEBUG_PRINT1 ("EXECUTING before_dot.\n"); 275 if (PTR_CHAR_POS ((unsigned char *) d) >= point) 276--- 4567,4574 ---- 277 break; 278 goto fail; 279 280! #if defined(emacs) || defined(pce_source) 281! #ifndef pce_source 282 case before_dot: 283 DEBUG_PRINT1 ("EXECUTING before_dot.\n"); 284 if (PTR_CHAR_POS ((unsigned char *) d) >= point) 285*************** 286*** 4520,4536 **** 287 if (PTR_CHAR_POS ((unsigned char *) d) <= point) 288 goto fail; 289 break; 290! #if 0 /* not emacs19 */ 291! case at_dot: 292! DEBUG_PRINT1 ("EXECUTING at_dot.\n"); 293! if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point) 294! goto fail; 295! break; 296! #endif /* not emacs19 */ 297! 298 case syntaxspec: 299 DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); 300 mcnt = *p++; 301 goto matchsyntax; 302 303 case wordchar: 304--- 4586,4598 ---- 305 if (PTR_CHAR_POS ((unsigned char *) d) <= point) 306 goto fail; 307 break; 308! #endif /*pce_source*/ 309 case syntaxspec: 310 DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); 311 mcnt = *p++; 312+ #ifdef pce_source 313+ mcnt |= (*p++ << 8); 314+ #endif /* pce_source */ 315 goto matchsyntax; 316 317 case wordchar: 318*************** 319*** 4540,4546 **** 320 PREFETCH (); 321 /* Can't use *d++ here; SYNTAX may be an unsafe macro. */ 322 d++; 323! if (SYNTAX (d[-1]) != (enum syntaxcode) mcnt) 324 goto fail; 325 SET_REGS_MATCHED (); 326 break; 327--- 4602,4608 ---- 328 PREFETCH (); 329 /* Can't use *d++ here; SYNTAX may be an unsafe macro. */ 330 d++; 331! if ( !HASSYNTAX (d[-1], mcnt) ) 332 goto fail; 333 SET_REGS_MATCHED (); 334 break; 335*************** 336*** 4548,4553 **** 337--- 4610,4618 ---- 338 case notsyntaxspec: 339 DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt); 340 mcnt = *p++; 341+ #ifdef pce_source 342+ mcnt |= (*p++ << 8); 343+ #endif /* pce_source */ 344 goto matchnotsyntax; 345 346 case notwordchar: 347*************** 348*** 4557,4568 **** 349 PREFETCH (); 350 /* Can't use *d++ here; SYNTAX may be an unsafe macro. */ 351 d++; 352! if (SYNTAX (d[-1]) == (enum syntaxcode) mcnt) 353 goto fail; 354 SET_REGS_MATCHED (); 355 break; 356 357! #else /* not emacs */ 358 case wordchar: 359 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); 360 PREFETCH (); 361--- 4622,4633 ---- 362 PREFETCH (); 363 /* Can't use *d++ here; SYNTAX may be an unsafe macro. */ 364 d++; 365! if ( HASSYNTAX (d[-1], mcnt) ) 366 goto fail; 367 SET_REGS_MATCHED (); 368 break; 369 370! #else /* not emacs and not pce_source */ 371 case wordchar: 372 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); 373 PREFETCH (); 374