home *** CD-ROM | disk | FTP | other *** search
- /* hregex.c - use re_search () and re_match () on huge buffers
- Copyright (C) 1990 Free Software Foundation, Inc.
- Francois Pinard <pinard@iro.umontreal.ca>, 1988.
- Thorsten Ohl <ohl@gnu.ai.mit.edu>, 1990.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Header: e:/gnu/gptx/RCS/hregex.c 0.1.0.1 90/09/22 00:23:03 tho Exp $
- */
-
- #if defined (_MSC_VER) && (_MSC_VER >= 600)
- #define HUGE _huge
- #else
- #define HUGE huge
- #endif
-
- #define LONG long
- #define IMAX 0x7fffL
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <regex.h>
-
- extern char *program_name;
-
- /* Normalize a "huge" ix86 pointer by moving part of the offset into
- the segment. (We do it only if the offset is sufficiently large.)
- Note: Don't do this with pointers to memory blocks owned by malloc,
- as a subsequent free () or realloc () will fail! */
-
- #define FP_NORM(fp) \
- if (FP_OFF (fp) & 0xf000) \
- { \
- FP_SEG (fp) += (FP_OFF(fp) >> 4); \
- FP_OFF (fp) &= 0x0f; \
- }
-
- /* This is a kludge for using the GNU regex library on huge (>32k)
- buffers. This "implementation" assumes that a match will be found in
- the first 32k and will simply abort with a diagnostic message if not.
- While this is certainly not a clean solution, it is appropriate in
- cases where a failure is extremely unlikely, since it avoids the
- enormous computational overhead of using huge pointers for regexp
- matching, which is furthermore very error-prone.
- Note: once these functions are real implementation, they should return
- a long, but for the moment ints are more convenient. */
-
- int
- re_hsearch (struct re_pattern_buffer *pbufp, char HUGE *string, long size,
- long startpos, long range, struct re_registers *regs)
- {
- int match;
- int isize = (int) min (size, IMAX);
- int istartpos = (int) min (startpos, IMAX);
- int irange = (int) min (range, IMAX);
-
- FP_NORM (string);
-
- match = re_search (pbufp, string, isize, istartpos, irange, regs);
-
- if (match == -1 && size > IMAX)
- {
- fprintf (stderr, "%s: re_search() failed in truncated buffer\n"
- " buffer: `%.30s...'\n"
- " length: %ld\n",
- program_name, string, size);
- abort ();
- }
-
- return match;
- }
-
- int
- re_hmatch (struct re_pattern_buffer *pbufp, char HUGE *string, long size,
- long pos, struct re_registers *regs)
- {
- int match;
- int isize = (int) min (size, IMAX);
- int ipos = (int) min (pos, IMAX);
-
- FP_NORM (string);
-
- match = re_match (pbufp, string, isize, ipos, regs);
-
- if (match == -1 && size > IMAX)
- {
- fprintf (stderr, "%s: re_match() failed against truncated buffer\n"
- " buffer: `%.30s...'\n"
- " length: %ld\n",
- program_name, string, size);
- abort ();
- }
-
- return match;
- }
-
-
- /*
- Local Variables:
- mode:C
- ChangeLog:ChangeLog
- compile-command:make
- End:
- */
-
-
-