home *** CD-ROM | disk | FTP | other *** search
- /* > H.Defns - Extended regular expression matching and search */
-
- /* Definitions for data structures callers pass the regex library.
- Copyright (C) 1985 Free Software Foundation, Inc.
-
- NO WARRANTY
-
- BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
- NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
- WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
- RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
- WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
- AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
- DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
- CORRECTION.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
- STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
- WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
- LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
- OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
- USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
- DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
- A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
- PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
- DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
-
- GENERAL PUBLIC LICENSE TO COPY
-
- 1. You may copy and distribute verbatim copies of this source file
- as you receive it, in any medium, provided that you conspicuously and
- appropriately publish on each copy a valid copyright notice "Copyright
- (C) 1985 Free Software Foundation, Inc."; and include following the
- copyright notice a verbatim copy of the above disclaimer of warranty
- and of this License. You may charge a distribution fee for the
- physical act of transferring a copy.
-
- 2. You may modify your copy or copies of this source file or
- any portion of it, and copy and distribute such modifications under
- the terms of Paragraph 1 above, provided that you also do the following:
-
- a) cause the modified files to carry prominent notices stating
- that you changed the files and the date of any change; and
-
- b) cause the whole of any work that you distribute or publish,
- that in whole or in part contains or is a derivative of this
- program or any part thereof, to be licensed at no charge to all
- third parties on terms identical to those contained in this
- License Agreement (except that you may choose to grant more extensive
- warranty protection to some or all third parties, at your option).
-
- c) You may charge a distribution fee for the physical act of
- transferring a copy, and you may at your option offer warranty
- protection in exchange for a fee.
-
- Mere aggregation of another unrelated program with this program (or its
- derivative) on a volume of a storage or distribution medium does not bring
- the other program under the scope of these terms.
-
- 3. You may copy and distribute this program (or a portion or derivative
- of it, under Paragraph 2) in object code or executable form under the terms
- of Paragraphs 1 and 2 above provided that you also do one of the following:
-
- a) accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- b) accompany it with a written offer, valid for at least three
- years, to give any third party free (except for a nominal
- shipping charge) a complete machine-readable copy of the
- corresponding source code, to be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- c) accompany it with the information you received as to where the
- corresponding source code may be obtained. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form alone.)
-
- For an executable file, complete source code means all the source code for
- all modules it contains; but, as a special exception, it need not include
- source code for modules which are standard libraries that accompany the
- operating system on which the executable file runs.
-
- 4. You may not copy, sublicense, distribute or transfer this program
- except as expressly provided under this License Agreement. Any attempt
- otherwise to copy, sublicense, distribute or transfer this program is void and
- your rights to use the program under this License agreement shall be
- automatically terminated. However, parties who have received computer
- software programs from you with this License Agreement will not have
- their licenses terminated so long as such parties remain in full compliance.
-
- 5. If you wish to incorporate parts of this program into other free
- programs whose distribution conditions are different, write to the Free
- Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
- worked out a simple rule that can be stated here, but we will often permit
- this. We will be guided by the two goals of preserving the free status of
- all derivatives of our free software and of promoting the sharing and reuse of
- software.
-
-
- In other words, you are welcome to use, share and improve this program.
- You are forbidden to forbid anyone else to use, share and improve
- what you give them. Help stamp out software-hoarding! */
-
- /***** Macro definitions *****/
-
- #define JUMP_LEN 3 /* Length of a jump instruction */
-
- #define BITMAP_LEN ( (UCHAR_MAX + CHAR_BIT) / CHAR_BIT )
- /* Number of bytes in a bitmap */
-
- #define NONE (-1) /* Offset value not set */
-
- #define MAX(x,y) ( (x) > (y) ? (x) : (y) )
- #define MAX_ADD MAX((BITMAP_LEN+2),(JUMP_LEN*3))
- /* Maximum number of bytes added to
- buffer for a single operator */
-
- #define STACK_SIZE 10 /* Levels of bracket nesting */
- #define MAX_FAILURES 80 /* Number of failure points stacked */
- #define ALLOC_INCR 100 /* Bytes increase per buffer extension */
-
- #define FAIL_STACK_INCR 100 /* Increment size for failure stack */
-
- #define SIGN_EXTEND_CHAR(x) ((signed char)(x))
- #define SYNTAX(ch) (re_syntax_table[ch])
- #define TRANSLATE(ch) (translate ? translate[ch] : (ch))
-
- #define BACKSLASH_BIT (1 << CHAR_BIT)
- #define BACKSLASH(ch) ((ch) | BACKSLASH_BIT)
- #define IS_BACKSLASH(ch) ((ch) & BACKSLASH_BIT)
- #define LITERAL(ch) ((ch) & ~BACKSLASH_BIT)
-
- #define ADDR(offset) ((offset) + re->buffer)
- #define OFFSET(addr) ((addr) - re->buffer)
- #define SETBIT(b,c) ( (b)[(c)/CHAR_BIT] |= ( 1 << ((c)%CHAR_BIT) ) )
- #define GETBIT(b,c) ( (b)[(c)/CHAR_BIT] & ( 1 << ((c)%CHAR_BIT) ) )
- #define JUMP_DEST(j) ( SIGN_EXTEND_CHAR((j)[1]) << CHAR_BIT | (j)[0] )
-
- #define MEMNO(ch) (LITERAL(ch)-'0')
-
- #define PATPUSH(ch) (*b++ = (char)(ch))
-
- #define PATUNFETCH(ch) (IS_BACKSLASH(ch) ? p -= 2 : p--)
-
- #define PATFETCH(ch) \
- { \
- if ( *p == '\0' ) \
- goto end_of_pattern; \
- ch = *(unsigned char *)p++; \
- if ( ch != '\\' ) \
- ch = TRANSLATE(ch); \
- else \
- { \
- if ( *p == '\0' ) \
- goto end_of_pattern; \
- ch = *(unsigned char *)p++; \
- ch = BACKSLASH(ch); \
- } \
- }
-
- /* These are the command codes that appear in compiled regular expressions,
- one per byte. Some command codes are followed by argument bytes.
- A command code can specify any interpretation whatever for its arguments.
- Zero-bytes may appear in the compiled regular expression.
- */
-
- /* ----- 0-character RE's ----- */
-
- #define startline 1 /* fails unless at beginning of line */
- #define endline 2 /* fails unless at end of line */
- #define startbuf 3 /* fails unless at start of buffer */
- #define endbuf 4 /* fails unless at end of buffer */
- #define startword 5 /* fails unless at start of word */
- #define endword 6 /* fails unless at end of word */
- #define wordbound 7 /* fails unless at a word boundary */
-
- /* ----- 1-character RE's ----- */
-
- #define anychar 8 /* matches any one character */
- #define wordchar 9 /* matches any word-constituent character */
- #define notchar 10 /* matches any character other than that following */
- /* Next byte = character to exclude
- */
- #define charset 11 /* matches any character belonging to specified set */
- /* Next byte = bitmap number of bytes
- Then comes a bitmap specifying characters
- in the set (each byte ordered low bit first)
- */
-
- /* ----- multi-character RE's ----- */
-
- #define duplicate 12 /* matches a duplicate of something remembered */
- /* Next byte = index of memory register */
- #define exactn 13 /* matches a number of literal bytes */
- /* Next byte = number of literal bytes
- Then comes that number of characters
- */
-
- /* ----- RE operators: jumps ----- */
-
- /* All jumps are followed by JUMP_LEN-1 bytes containing relative jump */
-
- #define jump 14 /* Always jump */
- #define on_failure_jump 15 /* Save destination. If match fails,
- use saved destination as restart
- point.
- */
- #define finalise_jump 16 /* Throw away the latest saved failure
- destination, and jump
- */
- #define maybe_finalise_jump 17 /* Jump with the possibility of
- finalisation. The procedure
- `resolve_jumps' converts this
- to "jump" or "finalise_jump",
- depending on whether or not the
- next portion of the pattern could
- match the same as the jump
- destination point.
- */
- #define dummy_failure_jump 18 /* Jump and push a dummy failure
- point. This will be thrown away if
- used as a failure destination.
- */
-
- /* ----- RE operators: memory ----- */
-
- /* Both followed by 1 byte containing register number (1-NREGS) */
-
- #define start_memory 19 /* remember start of text */
- #define stop_memory 20 /* remember end of text */
-
- /* ----- RE operators: negated RE code ----- */
-
- #define NOT_BIT (1 << (CHAR_BIT-1))
- #define NOT(op) ((op) | NOT_BIT)
- #define IS_NOT(op) ((op) & NOT_BIT)
-