From: howard@hasse.ericsson.se (Howard Gayle) Newsgroups: alt.sources Subject: GNU Emacs 8-bit mods part 07 of 12 Message-ID: <1990Apr5.133859.8993@ericsson.se> Date: 5 Apr 90 13:38:59 GMT *** ../18.55/src/regex.c Thu Aug 18 20:24:38 1988 --- src/regex.c Thu Apr 5 09:15:22 1990 *************** *** 1,5 **** /* Extended regular expression matching and search. ! Copyright (C) 1985 Free Software Foundation, Inc. NO WARRANTY --- 1,5 ---- /* Extended regular expression matching and search. ! Copyright (C) 1985, 1990 Free Software Foundation, Inc. NO WARRANTY *************** *** 103,108 **** --- 103,112 ---- what you give them. Help stamp out software-hoarding! */ + /* Modified 1990 for 8-bit character support by Howard Gayle. + * See chartab.c for details. */ + + /* To test, compile with -Dtest. This Dtestable feature turns this into a self-contained program which reads a pattern, describes how it compiles, *************** *** 117,122 **** --- 121,127 ---- #include "config.h" #include "lisp.h" #include "buffer.h" + #include "sorttab.h" #include "syntax.h" #else /* not emacs */ *************** *** 218,242 **** after re_compile_pattern returns. */ ! #define PATPUSH(ch) (*b++ = (char) (ch)) #define PATFETCH(c) \ {if (p == pend) goto end_of_pattern; \ ! c = * (unsigned char *) p++; \ ! if (translate) c = translate[c]; } ! ! #define PATFETCH_RAW(c) \ ! {if (p == pend) goto end_of_pattern; \ ! c = * (unsigned char *) p++; } #define PATUNFETCH p-- #define EXTEND_BUFFER \ ! { char *old_buffer = bufp->buffer; \ if (bufp->allocated == (1<<16)) goto too_big; \ bufp->allocated *= 2; \ if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \ ! if (!(bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated))) \ goto memory_exhausted; \ c = bufp->buffer - old_buffer; \ b += c; \ --- 223,242 ---- after re_compile_pattern returns. */ ! #define PATPUSH(ch) (*b++ = (unsigned char) (ch)) #define PATFETCH(c) \ {if (p == pend) goto end_of_pattern; \ ! c = *p++; } #define PATUNFETCH p-- #define EXTEND_BUFFER \ ! { unsigned char *old_buffer = bufp->buffer; \ if (bufp->allocated == (1<<16)) goto too_big; \ bufp->allocated *= 2; \ if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \ ! if (!(bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated))) \ goto memory_exhausted; \ c = bufp->buffer - old_buffer; \ b += c; \ *************** *** 251,274 **** static int store_jump (), insert_jump (); char * re_compile_pattern (pattern, size, bufp) ! char *pattern; int size; struct re_pattern_buffer *bufp; { ! register char *b = bufp->buffer; ! register char *p = pattern; ! char *pend = pattern + size; register unsigned c, c1; ! char *p1; ! unsigned char *translate = (unsigned char *) bufp->translate; /* address of the count-byte of the most recently inserted "exactn" command. This makes it possible to tell whether a new exact-match character can be added to that command or requires a new "exactn" command. */ ! char *pending_exact = 0; /* address of the place where a forward-jump should go to the end of the containing expression. --- 251,691 ---- static int store_jump (), insert_jump (); + #ifdef emacs + + void + set_bits (b, c, st) + register unsigned char *b; + register int c; + register struct Lisp_Sorttab *st; + { + register int i; + register int hi; + register int ec; + + if (st == NULL_SORT_TABLE) + b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH); + else + { + ec = st->srt_ec[c]; + hi = st->srt_dope[ec].ec_hi; + for (i = st->srt_dope[ec].ec_lo; i <= hi; ++i) + { + c = st->srt_chars[i]; + b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH); + } + } + } + + char * + re_compile_pattern_sort (pattern, size, bufp, sorttab) + unsigned char *pattern; + int size; + struct re_pattern_buffer *bufp; + struct Lisp_Sorttab *sorttab; + { + register unsigned char *b = bufp->buffer; + register unsigned char *p = pattern; + unsigned char *pend = pattern + size; + register unsigned c, c1; + unsigned char *p1; + + /* address of the count-byte of the most recently inserted "exactn" command. + This makes it possible to tell whether a new exact-match character + can be added to that command or requires a new "exactn" command. */ + + unsigned char *pending_exact = 0; + + /* address of the place where a forward-jump should go + to the end of the containing expression. + Each alternative of an "or", except the last, ends with a forward-jump + of this sort. */ + + unsigned char *fixup_jump = 0; + + /* address of start of the most recently finished expression. + This tells postfix * where to find the start of its operand. */ + + unsigned char *laststart = 0; + + /* In processing a repeat, 1 means zero matches is allowed */ + + unsigned char zero_times_ok; + + /* In processing a repeat, 1 means many matches is allowed */ + + unsigned char many_times_ok; + + /* address of beginning of regexp, or inside of last \( */ + + unsigned char *begalt = b; + + /* Stack of information saved by \( and restored by \). + Four stack elements are pushed by each \(: + First, the value of b. + Second, the value of fixup_jump. + Third, the value of regnum. + Fourth, the value of begalt. */ + + int stackb[40]; + int *stackp = stackb; + int *stacke = stackb + 40; + int *stackt; + + /* Counts \('s as they are encountered. Remembered for the matching \), + where it becomes the "register number" to put in the stop_memory command */ + + int regnum = 1; + + bufp->fastmap_accurate = 0; + + if (bufp->allocated == 0) + { + bufp->allocated = 28; + if (bufp->buffer) + /* EXTEND_BUFFER loses when bufp->allocated is 0 */ + bufp->buffer = (unsigned char *) realloc (bufp->buffer, 28); + else + /* Caller did not allocate a buffer. Do it for him */ + bufp->buffer = (unsigned char *) malloc (28); + if (!bufp->buffer) goto memory_exhausted; + begalt = b = bufp->buffer; + } + + while (p != pend) + { + if (b - bufp->buffer > bufp->allocated - 10) + /* Note that EXTEND_BUFFER clobbers c */ + EXTEND_BUFFER; + + PATFETCH (c); + + switch (c) + { + case '$': + /* $ means succeed if at end of line, but only in special contexts. + If randonly in the middle of a pattern, it is a normal character. */ + if (p == pend || (*p == '\\' && (p[1] == ')' || p[1] == '|'))) + { + PATPUSH (endline); + break; + } + goto normal_char; + + case '^': + /* ^ means succeed if at beg of line, but only if no preceding pattern. */ + if (laststart) goto normal_char; + PATPUSH (begline); + break; + + case '*': + case '+': + case '?': + /* If there is no previous pattern, char not special. */ + if (!laststart) + goto normal_char; + /* If there is a sequence of repetition chars, + collapse it down to equivalent to just one. */ + zero_times_ok = 0; + many_times_ok = 0; + while (1) + { + zero_times_ok |= c != '+'; + many_times_ok |= c != '?'; + if (p == pend) + break; + PATFETCH (c); + if (!(c == '*' || c == '+' || c == '?')) + { + PATUNFETCH; + break; + } + } + + /* Now we know whether 0 matches is allowed, + and whether 2 or more matches is allowed. */ + if (many_times_ok) + { + /* If more than one repetition is allowed, + put in a backward jump at the end. */ + store_jump (b, maybe_finalize_jump, laststart - 3); + b += 3; + } + insert_jump (on_failure_jump, laststart, b + 3, b); + pending_exact = 0; + b += 3; + if (!zero_times_ok) + { + /* At least one repetition required: insert before the loop + a skip over the initial on-failure-jump instruction */ + insert_jump (dummy_failure_jump, laststart, laststart + 6, b); + b += 3; + } + break; + + case '.': + laststart = b; + PATPUSH (anychar); + break; + + case '[': + if (b - bufp->buffer + > bufp->allocated - 3 - (1 << BYTEWIDTH) / BYTEWIDTH) + /* Note that EXTEND_BUFFER clobbers c */ + EXTEND_BUFFER; + + laststart = b; + if (*p == '^') + PATPUSH (charset_not), p++; + else + PATPUSH (charset); + p1 = p; + + PATPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); + /* Clear the whole map */ + bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); + /* Read in characters and ranges, setting map bits */ + while (1) + { + PATFETCH (c); + if (c == ']' && p != p1 + 1) break; + if (*p == '-') + { + PATFETCH (c1); + PATFETCH (c1); + while (c <= c1) + set_bits (b, c++, sorttab); + } + else + set_bits (b, c, sorttab); + } + /* Discard any bitmap bytes that are all 0 at the end of the map. + Decrement the map-length byte too. */ + while (b[-1] > 0 && b[b[-1] - 1] == 0) + b[-1]--; + b += b[-1]; + break; + + case '\\': + if (p == pend) goto invalid_pattern; + PATFETCH (c); + switch (c) + { + case '(': + if (stackp == stacke) goto nesting_too_deep; + if (regnum < RE_NREGS) + { + PATPUSH (start_memory); + PATPUSH (regnum); + } + *stackp++ = b - bufp->buffer; + *stackp++ = fixup_jump ? fixup_jump - bufp->buffer + 1 : 0; + *stackp++ = regnum++; + *stackp++ = begalt - bufp->buffer; + fixup_jump = 0; + laststart = 0; + begalt = b; + break; + + case ')': + if (stackp == stackb) goto unmatched_close; + begalt = *--stackp + bufp->buffer; + if (fixup_jump) + store_jump (fixup_jump, jump, b); + if (stackp[-1] < RE_NREGS) + { + PATPUSH (stop_memory); + PATPUSH (stackp[-1]); + } + stackp -= 2; + fixup_jump = 0; + if (*stackp) + fixup_jump = *stackp + bufp->buffer - 1; + laststart = *--stackp + bufp->buffer; + break; + + case '|': + insert_jump (on_failure_jump, begalt, b + 6, b); + pending_exact = 0; + b += 3; + if (fixup_jump) + store_jump (fixup_jump, jump, b); + fixup_jump = b; + b += 3; + laststart = 0; + begalt = b; + break; + + case '=': + PATPUSH (at_dot); + break; + + case 's': + laststart = b; + PATPUSH (syntaxspec); + PATFETCH (c); + PATPUSH (syntax_spec_code[c]); + break; + + case 'S': + laststart = b; + PATPUSH (notsyntaxspec); + PATFETCH (c); + PATPUSH (syntax_spec_code[c]); + break; + + case 'w': + laststart = b; + PATPUSH (wordchar); + break; + + case 'W': + laststart = b; + PATPUSH (notwordchar); + break; + + case '<': + PATPUSH (wordbeg); + break; + + case '>': + PATPUSH (wordend); + break; + + case 'b': + PATPUSH (wordbound); + break; + + case 'B': + PATPUSH (notwordbound); + break; + + case '`': + PATPUSH (begbuf); + break; + + case '\'': + PATPUSH (endbuf); + break; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + c1 = c - '0'; + if (c1 >= regnum) + goto normal_char; + for (stackt = stackp - 2; stackt > stackb; stackt -= 4) + if (*stackt == c1) + goto normal_char; + laststart = b; + PATPUSH (duplicate); + PATPUSH (c1); + break; + default: + goto normal_char; + } + break; + + default: + normal_char: + if ((sorttab == NULL_SORT_TABLE) || + (sorttab->srt_dope[sorttab->srt_ec[c]].ec_lo == + sorttab->srt_dope[sorttab->srt_ec[c]].ec_hi)) + { + if (!pending_exact || pending_exact + *pending_exact + 1 != b + || *pending_exact == 0177 || *p == '*' || *p == '^' + || *p == '+' || *p == '?') + { + laststart = b; + PATPUSH (exactn); + pending_exact = b; + PATPUSH (0); + } + PATPUSH (c); + (*pending_exact)++; + } + else + { + if (b - bufp->buffer + > bufp->allocated - 3 - (1 << BYTEWIDTH) / BYTEWIDTH) + /* Note that EXTEND_BUFFER clobbers c */ + { + c1 = c; + EXTEND_BUFFER; + c = c1; + } + + laststart = b; + PATPUSH (charset); + + PATPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); + /* Clear the whole map */ + bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); + set_bits (b, c, sorttab); + /* Discard any bitmap bytes that are all 0 at the end of the map. + Decrement the map-length byte too. */ + while (b[-1] > 0 && b[b[-1] - 1] == 0) + b[-1]--; + b += b[-1]; + } + } + } + + if (fixup_jump) + store_jump (fixup_jump, jump, b); + + if (stackp != stackb) goto unmatched_open; + + bufp->used = b - bufp->buffer; + return 0; + + invalid_pattern: + return "Invalid regular expression"; + + unmatched_open: + return "Unmatched \\("; + + unmatched_close: + return "Unmatched \\)"; + + end_of_pattern: + return "Premature end of regular expression"; + + nesting_too_deep: + return "Nesting too deep"; + + too_big: + return "Regular expression too big"; + + memory_exhausted: + return "Memory exhausted"; + } + + #else /* not emacs */ + char * re_compile_pattern (pattern, size, bufp) ! unsigned char *pattern; int size; struct re_pattern_buffer *bufp; { ! register unsigned char *b = bufp->buffer; ! register unsigned char *p = pattern; ! unsigned char *pend = pattern + size; register unsigned c, c1; ! unsigned char *p1; /* address of the count-byte of the most recently inserted "exactn" command. This makes it possible to tell whether a new exact-match character can be added to that command or requires a new "exactn" command. */ ! unsigned char *pending_exact = 0; /* address of the place where a forward-jump should go to the end of the containing expression. *************** *** 275,298 **** Each alternative of an "or", except the last, ends with a forward-jump of this sort. */ ! char *fixup_jump = 0; /* address of start of the most recently finished expression. This tells postfix * where to find the start of its operand. */ ! char *laststart = 0; /* In processing a repeat, 1 means zero matches is allowed */ ! char zero_times_ok; /* In processing a repeat, 1 means many matches is allowed */ ! char many_times_ok; /* address of beginning of regexp, or inside of last \( */ ! char *begalt = b; /* Stack of information saved by \( and restored by \). Four stack elements are pushed by each \(: --- 692,715 ---- Each alternative of an "or", except the last, ends with a forward-jump of this sort. */ ! unsigned char *fixup_jump = 0; /* address of start of the most recently finished expression. This tells postfix * where to find the start of its operand. */ ! unsigned char *laststart = 0; /* In processing a repeat, 1 means zero matches is allowed */ ! unsigned char zero_times_ok; /* In processing a repeat, 1 means many matches is allowed */ ! unsigned char many_times_ok; /* address of beginning of regexp, or inside of last \( */ ! unsigned char *begalt = b; /* Stack of information saved by \( and restored by \). Four stack elements are pushed by each \(: *************** *** 313,319 **** bufp->fastmap_accurate = 0; - #ifndef emacs #ifndef SYNTAX_TABLE /* * Initialize the syntax table. --- 730,735 ---- *************** *** 320,326 **** */ init_syntax_once(); #endif - #endif if (bufp->allocated == 0) { --- 736,741 ---- *************** *** 327,336 **** bufp->allocated = 28; if (bufp->buffer) /* EXTEND_BUFFER loses when bufp->allocated is 0 */ ! bufp->buffer = (char *) realloc (bufp->buffer, 28); else /* Caller did not allocate a buffer. Do it for him */ ! bufp->buffer = (char *) malloc (28); if (!bufp->buffer) goto memory_exhausted; begalt = b = bufp->buffer; } --- 742,751 ---- bufp->allocated = 28; if (bufp->buffer) /* EXTEND_BUFFER loses when bufp->allocated is 0 */ ! bufp->buffer = (unsigned char *) realloc (bufp->buffer, 28); else /* Caller did not allocate a buffer. Do it for him */ ! bufp->buffer = (unsigned char *) malloc (28); if (!bufp->buffer) goto memory_exhausted; begalt = b = bufp->buffer; } *************** *** 534,540 **** case '\\': if (p == pend) goto invalid_pattern; ! PATFETCH_RAW (c); switch (c) { case '(': --- 949,955 ---- case '\\': if (p == pend) goto invalid_pattern; ! PATFETCH (c); switch (c) { case '(': *************** *** 672,681 **** default: normal_backsl: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - if (translate) c = translate[c]; goto normal_char; } break; --- 1087,1092 ---- *************** *** 728,733 **** --- 1139,1146 ---- return "Memory exhausted"; } + #endif /* emacs */ + /* Store where `from' points a jump operation to jump to where `to' points. `opcode' is the opcode to store. */ *************** *** 750,760 **** static int insert_jump (op, from, to, current_end) ! char op; ! char *from, *to, *current_end; { ! register char *pto = current_end + 3; ! register char *pfrom = current_end; while (pfrom != from) *--pto = *--pfrom; store_jump (from, op, to); --- 1163,1173 ---- static int insert_jump (op, from, to, current_end) ! unsigned char op; ! unsigned char *from, *to, *current_end; { ! register unsigned char *pto = current_end + 3; ! register unsigned char *pfrom = current_end; while (pfrom != from) *--pto = *--pfrom; store_jump (from, op, to); *************** *** 773,785 **** re_compile_fastmap (bufp) struct re_pattern_buffer *bufp; { ! unsigned char *pattern = (unsigned char *) bufp->buffer; int size = bufp->used; ! register char *fastmap = bufp->fastmap; register unsigned char *p = pattern; register unsigned char *pend = pattern + size; register int j, k; - unsigned char *translate = (unsigned char *) bufp->translate; unsigned char *stackb[NFAILURES]; unsigned char **stackp = stackb; --- 1186,1197 ---- re_compile_fastmap (bufp) struct re_pattern_buffer *bufp; { ! unsigned char *pattern = bufp->buffer; int size = bufp->used; ! register unsigned char *fastmap = bufp->fastmap; register unsigned char *p = pattern; register unsigned char *pend = pattern + size; register int j, k; unsigned char *stackb[NFAILURES]; unsigned char **stackp = stackb; *************** *** 802,811 **** #endif { case exactn: ! if (translate) ! fastmap[translate[p[1]]] = 1; ! else ! fastmap[p[1]] = 1; break; case begline: --- 1214,1220 ---- #endif { case exactn: ! fastmap[p[1]] = 1; break; case begline: *************** *** 821,830 **** continue; case endline: ! if (translate) ! fastmap[translate['\n']] = 1; ! else ! fastmap['\n'] = 1; if (bufp->can_be_null != 1) bufp->can_be_null = 2; break; --- 1230,1236 ---- continue; case endline: ! fastmap['\n'] = 1; if (bufp->can_be_null != 1) bufp->can_be_null = 2; break; *************** *** 911,940 **** case charset: for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) ! { ! if (translate) ! fastmap[translate[j]] = 1; ! else ! fastmap[j] = 1; ! } break; case charset_not: /* Chars beyond end of map must be allowed */ for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) ! if (translate) ! fastmap[translate[j]] = 1; ! else ! fastmap[j] = 1; for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) ! { ! if (translate) ! fastmap[translate[j]] = 1; ! else ! fastmap[j] = 1; ! } break; } --- 1317,1333 ---- case charset: for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) ! fastmap[j] = 1; break; case charset_not: /* Chars beyond end of map must be allowed */ for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) ! fastmap[j] = 1; for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) ! fastmap[j] = 1; break; } *************** *** 953,959 **** int re_search (pbufp, string, size, startpos, range, regs) struct re_pattern_buffer *pbufp; ! char *string; int size, startpos, range; struct re_registers *regs; { --- 1346,1352 ---- int re_search (pbufp, string, size, startpos, range, regs) struct re_pattern_buffer *pbufp; ! unsigned char *string; int size, startpos, range; struct re_registers *regs; { *************** *** 975,981 **** int re_search_2 (pbufp, string1, size1, string2, size2, startpos, range, regs, mstop) struct re_pattern_buffer *pbufp; ! char *string1, *string2; int size1, size2; int startpos; register int range; --- 1368,1374 ---- int re_search_2 (pbufp, string1, size1, string2, size2, startpos, range, regs, mstop) struct re_pattern_buffer *pbufp; ! unsigned char *string1, *string2; int size1, size2; int startpos; register int range; *************** *** 982,989 **** struct re_registers *regs; int mstop; { ! register char *fastmap = pbufp->fastmap; ! register unsigned char *translate = (unsigned char *) pbufp->translate; int total = size1 + size2; int val; --- 1375,1381 ---- struct re_registers *regs; int mstop; { ! register unsigned char *fastmap = pbufp->fastmap; int total = size1 + size2; int val; *************** *** 1023,1049 **** p = ((unsigned char *) &(startpos >= size1 ? string2 - size1 : string1)[startpos]); ! if (translate) ! { ! while (range > lim && !fastmap[translate[*p++]]) ! range--; ! } ! else ! { ! while (range > lim && !fastmap[*p++]) ! range--; ! } startpos += irange - range; } else { register unsigned char c; ! if (startpos >= size1) ! c = string2[startpos - size1]; ! else ! c = string1[startpos]; ! c &= 0xff; ! if (translate ? !fastmap[translate[c]] : !fastmap[c]) goto advance; } } --- 1415,1430 ---- p = ((unsigned char *) &(startpos >= size1 ? string2 - size1 : string1)[startpos]); ! while (range > lim && !fastmap[*p++]) ! range--; startpos += irange - range; } else { register unsigned char c; ! if (startpos >= size1) c = string2[startpos - size1]; ! else c = string1[startpos]; ! if (!fastmap[c]) goto advance; } } *************** *** 1075,1081 **** int re_match (pbufp, string, size, pos, regs) struct re_pattern_buffer *pbufp; ! char *string; int size, pos; struct re_registers *regs; { --- 1456,1462 ---- int re_match (pbufp, string, size, pos, regs) struct re_pattern_buffer *pbufp; ! unsigned char *string; int size, pos; struct re_registers *regs; { *************** *** 1087,1093 **** int re_max_failures = 2000; - static int bcmp_translate(); /* Match the pattern described by PBUFP against data which is the virtual concatenation of STRING1 and STRING2. SIZE1 and SIZE2 are the sizes of the two data strings. --- 1468,1473 ---- *************** *** 1123,1129 **** unsigned char *end_match_1, *end_match_2; register unsigned char *d, *dend; register int mcnt; - unsigned char *translate = (unsigned char *) pbufp->translate; /* Failure point stack. Each place that can handle a failure further down the line pushes a failure point on this stack. It consists of two char *'s. --- 1503,1508 ---- *************** *** 1295,1301 **** if (mcnt > dend2 - d2) mcnt = dend2 - d2; /* Compare that many; failure if mismatch, else skip them. */ ! if (translate ? bcmp_translate (d, d2, mcnt, translate) : bcmp (d, d2, mcnt)) goto fail; d += mcnt, d2 += mcnt; } --- 1674,1680 ---- if (mcnt > dend2 - d2) mcnt = dend2 - d2; /* Compare that many; failure if mismatch, else skip them. */ ! if (bcmp (d, d2, mcnt)) goto fail; d += mcnt, d2 += mcnt; } *************** *** 1306,1312 **** /* fetch a data character */ PREFETCH; /* Match anything but a newline. */ ! if ((translate ? translate[*d++] : *d++) == '\n') goto fail; break; --- 1685,1691 ---- /* fetch a data character */ PREFETCH; /* Match anything but a newline. */ ! if (*d++ == '\n') goto fail; break; *************** *** 1322,1331 **** /* fetch a data character */ PREFETCH; ! if (translate) ! c = translate [*d]; ! else ! c = *d; if (c < *p * BYTEWIDTH && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) --- 1701,1707 ---- /* fetch a data character */ PREFETCH; ! c = *d; if (c < *p * BYTEWIDTH && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) *************** *** 1371,1378 **** if (stacke - stackb > re_max_failures) return -2; stackx = (unsigned char **) alloca (2 * (stacke - stackb) ! * sizeof (char *)); ! bcopy (stackb, stackx, (stacke - stackb) * sizeof (char *)); stackp = stackx + (stackp - stackb); stacke = stackx + 2 * (stacke - stackb); stackb = stackx; --- 1747,1754 ---- if (stacke - stackb > re_max_failures) return -2; stackx = (unsigned char **) alloca (2 * (stacke - stackb) ! * sizeof (unsigned char *)); ! bcopy (stackb, stackx, (stacke - stackb) * sizeof (unsigned char *)); stackp = stackx + (stackp - stackb); stacke = stackx + 2 * (stacke - stackb); stackb = stackx; *************** *** 1444,1451 **** { unsigned char **stackx = (unsigned char **) alloca (2 * (stacke - stackb) ! * sizeof (char *)); ! bcopy (stackb, stackx, (stacke - stackb) * sizeof (char *)); stackp = stackx + (stackp - stackb); stacke = stackx + 2 * (stacke - stackb); stackb = stackx; --- 1820,1827 ---- { unsigned char **stackx = (unsigned char **) alloca (2 * (stacke - stackb) ! * sizeof (unsigned char *)); ! bcopy (stackb, stackx, (stacke - stackb) * sizeof (unsigned char *)); stackp = stackx + (stackp - stackb); stacke = stackx + 2 * (stacke - stackb); stackb = stackx; *************** *** 1563,1586 **** /* Match the next few pattern characters exactly. mcnt is how many characters to match. */ mcnt = *p++; ! if (translate) { ! do ! { ! PREFETCH; ! if (translate[*d++] != *p++) goto fail; ! } ! while (--mcnt); ! } ! else ! { ! do ! { ! PREFETCH; ! if (*d++ != *p++) goto fail; ! } ! while (--mcnt); } break; } continue; /* Successfully matched one pattern command; keep matching */ --- 1939,1950 ---- /* Match the next few pattern characters exactly. mcnt is how many characters to match. */ mcnt = *p++; ! do { ! PREFETCH; ! if (*d++ != *p++) goto fail; } + while (--mcnt); break; } continue; /* Successfully matched one pattern command; keep matching */ *************** *** 1604,1624 **** } return -1; /* Failure to match */ } - - static int - bcmp_translate (s1, s2, len, translate) - unsigned char *s1, *s2; - register int len; - unsigned char *translate; - { - register unsigned char *p1 = s1, *p2 = s2; - while (len) - { - if (translate [*p1++] != translate [*p2++]) return 1; - len--; - } - return 0; - } /* Entry points compatible with bsd4.2 regex library */ --- 1968,1973 ---- *************** *** 1628,1634 **** char * re_comp (s) ! char *s; { if (!s) { --- 1977,1983 ---- char * re_comp (s) ! unsigned char *s; { if (!s) { *************** *** 1639,1648 **** if (!re_comp_buf.buffer) { ! if (!(re_comp_buf.buffer = (char *) malloc (200))) return "Memory exhausted"; re_comp_buf.allocated = 200; ! if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH))) return "Memory exhausted"; } return re_compile_pattern (s, strlen (s), &re_comp_buf); --- 1988,1997 ---- if (!re_comp_buf.buffer) { ! if (!(re_comp_buf.buffer = (unsigned char *) malloc (200))) return "Memory exhausted"; re_comp_buf.allocated = 200; ! if (!(re_comp_buf.fastmap = (unsigned char *) malloc (1 << BYTEWIDTH))) return "Memory exhausted"; } return re_compile_pattern (s, strlen (s), &re_comp_buf); *************** *** 1650,1656 **** int re_exec (s) ! char *s; { int len = strlen (s); return 0 <= re_search (&re_comp_buf, s, len, 0, len, 0); --- 1999,2005 ---- int re_exec (s) ! unsigned char *s; { int len = strlen (s); return 0 <= re_search (&re_comp_buf, s, len, 0, len, 0); *************** *** 1664,1670 **** /* Indexed by a character, gives the upper case equivalent of the character */ ! static char upcase[0400] = { 000, 001, 002, 003, 004, 005, 006, 007, 010, 011, 012, 013, 014, 015, 016, 017, 020, 021, 022, 023, 024, 025, 026, 027, --- 2013,2019 ---- /* Indexed by a character, gives the upper case equivalent of the character */ ! static unsigned char upcase[0400] = { 000, 001, 002, 003, 004, 005, 006, 007, 010, 011, 012, 013, 014, 015, 016, 017, 020, 021, 022, 023, 024, 025, 026, 027, *************** *** 1703,1713 **** int argc; char **argv; { ! char pat[80]; struct re_pattern_buffer buf; int i; ! char c; ! char fastmap[(1 << BYTEWIDTH)]; /* Allow a command argument to specify the style of syntax. */ if (argc > 1) --- 2052,2062 ---- int argc; char **argv; { ! unsigned char pat[80]; struct re_pattern_buffer buf; int i; ! unsigned char c; ! unsigned char fastmap[(1 << BYTEWIDTH)]; /* Allow a command argument to specify the style of syntax. */ if (argc > 1) *************** *** 1714,1722 **** obscure_syntax = atoi (argv[1]); buf.allocated = 40; ! buf.buffer = (char *) malloc (buf.allocated); buf.fastmap = fastmap; - buf.translate = upcase; while (1) { --- 2063,2070 ---- obscure_syntax = atoi (argv[1]); buf.allocated = 40; ! buf.buffer = (unsigned char *) malloc (buf.allocated); buf.fastmap = fastmap; while (1) { *************** *** 1763,1773 **** for (i = 0; i < (1 << BYTEWIDTH); i++) if (bufp->fastmap[i]) printchar (i); - printf ("\nAllowed by translate: "); - if (bufp->translate) - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->translate[i]) - printchar (i); printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't"); printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not"); } --- 2111,2116 ---- *************** *** 1774,1780 **** #endif printchar (c) ! char c; { if (c < 041 || c >= 0177) { --- 2117,2123 ---- #endif printchar (c) ! unsigned char c; { if (c < 041 || c >= 0177) { *************** *** 1788,1794 **** } error (string) ! char *string; { puts (string); exit (1); --- 2131,2137 ---- } error (string) ! unsigned char *string; { puts (string); exit (1); *** ../18.55/src/regex.h Sat Aug 13 20:15:10 1988 --- src/regex.h Thu Apr 5 09:15:46 1990 *************** *** 1,5 **** /* Definitions for data structures callers pass the regex library. ! Copyright (C) 1985 Free Software Foundation, Inc. NO WARRANTY --- 1,5 ---- /* Definitions for data structures callers pass the regex library. ! Copyright (C) 1985, 1990 Free Software Foundation, Inc. NO WARRANTY *************** *** 103,108 **** --- 103,112 ---- what you give them. Help stamp out software-hoarding! */ + /* Modified 1990 for 8-bit character support by Howard Gayle. + * See chartab.c for details. */ + + /* Define number of parens for which we record the beginnings and ends. This affects how much space the `struct re_registers' type takes up. */ #ifndef RE_NREGS *************** *** 149,168 **** #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) #define RE_SYNTAX_EMACS 0 /* This data structure is used to represent a compiled pattern. */ struct re_pattern_buffer { ! char *buffer; /* Space holding the compiled pattern commands. */ int allocated; /* Size of space that buffer points to */ int used; /* Length of portion of buffer actually occupied */ ! char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ /* re_search uses the fastmap, if there is one, to skip quickly over totally implausible characters */ - char *translate; /* Translate table to apply to all characters before comparing. - Or zero for no translation. - The translation is applied to a pattern when it is compiled - and to data when it is matched. */ char fastmap_accurate; /* Set to zero when a new pattern is stored, set to one when the fastmap is updated from it. */ --- 153,172 ---- #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) #define RE_SYNTAX_EMACS 0 + #ifndef emacs + typedef unsigned char char_t; + #endif + /* This data structure is used to represent a compiled pattern. */ struct re_pattern_buffer { ! char_t *buffer; /* Space holding the compiled pattern commands. */ int allocated; /* Size of space that buffer points to */ int used; /* Length of portion of buffer actually occupied */ ! char_t *fastmap; /* Pointer to fastmap, if any, or zero if none. */ /* re_search uses the fastmap, if there is one, to skip quickly over totally implausible characters */ char fastmap_accurate; /* Set to zero when a new pattern is stored, set to one when the fastmap is updated from it. */ *************** *** 252,258 **** --- 256,267 ---- notsyntaxspec /* Matches any character whose syntax differs from the specified. */ }; + #ifdef emacs + extern char *re_compile_pattern_sort (); + #else extern char *re_compile_pattern (); + #endif + /* Is this really advertised? */ extern void re_compile_fastmap (); extern int re_search (), re_search_2 (); *** ../18.55/src/scroll.c Sat Mar 19 08:55:25 1988 --- src/scroll.c Thu Apr 5 09:16:04 1990 *************** *** 1,5 **** /* Calculate what ins/del line to do, and do it, for Emacs redisplay. ! Copyright (C) 1985, 1986 Free Software Foundation, Inc. This file is part of GNU Emacs. --- 1,5 ---- /* Calculate what ins/del line to do, and do it, for Emacs redisplay. ! Copyright (C) 1985, 1986, 1990 Free Software Foundation, Inc. This file is part of GNU Emacs. *************** *** 19,25 **** --- 19,30 ---- and this notice must be preserved on all copies. */ + /* Modified 1990 for 8-bit character support by Howard Gayle. + * See chartab.c for details. */ + + #include "config.h" + #include "lisp.h" #include "termchar.h" #include "dispextern.h"