UNIXworkcode

1 /******************************************************************************* 2 * * 3 * regularExp.h -- Nirvana Editor Regular Expression Package Header File * 4 * * 5 * Copyright 2002 The NEdit Developers * 6 * * 7 * This is free software; you can redistribute it and/or modify it under the * 8 * terms of the GNU General Public License as published by the Free Software * 9 * Foundation; either version 2 of the License, or (at your option) any later * 10 * version. In addition, you may distribute versions of this program linked to * 11 * Motif or Open Motif. See README for details. * 12 * * 13 * This software is distributed in the hope that it will be useful, but WITHOUT * 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * 16 * more details. * 17 * * 18 * You should have received a copy of the GNU General Public License along with * 19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple * 20 * Place, Suite 330, Boston, MA 02111-1307 USA * 21 * * 22 * Nirvana Text Editor * 23 * July 31, 2001 * 24 * * 25 *******************************************************************************/ 26 27 #include <X11/Intrinsic.h> 28 29 #ifndef NEDIT_REGULAREXP_H_INCLUDED 30 #define NEDIT_REGULAREXP_H_INCLUDED 31 32 /* Number of text capturing parentheses allowed. */ 33 34 #define NSUBEXP 50 35 36 /* Structure to contain the compiled form of a regular expression plus 37 pointers to matched text. `program' is the actual compiled regex code. */ 38 39 typedef struct regexp { 40 char *startp [NSUBEXP]; /* Captured text starting locations. */ 41 char *endp [NSUBEXP]; /* Captured text ending locations. */ 42 char *extentpBW; /* Points to the maximum extent of text scanned by 43 ExecRE in front of the string to achieve a match 44 (needed because of positive look-behind.) */ 45 char *extentpFW; /* Points to the maximum extent of text scanned by 46 ExecRE to achieve a match (needed because of 47 positive look-ahead.) */ 48 int top_branch; /* Zero-based index of the top branch that matches. 49 Used by syntax highlighting only. */ 50 char match_start; /* Internal use only. */ 51 char anchor; /* Internal use only. */ 52 char program [1]; /* Unwarranted chumminess with compiler. */ 53 } regexp; 54 55 /* Flags for CompileRE default settings (Markus Schwarzenberg) */ 56 57 typedef enum { 58 REDFLT_STANDARD = 0, 59 REDFLT_CASE_INSENSITIVE = 1 60 /* REDFLT_MATCH_NEWLINE = 2 Currently not used. */ 61 } RE_DEFAULT_FLAG; 62 63 /* Compiles a regular expression into the internal format used by `ExecRE'. */ 64 65 regexp * CompileRE ( 66 const char *exp, /* String containing the regex specification. */ 67 char **errorText, /* Text of any error message produced. */ 68 int defaultFlags); /* Flags for default RE-operation */ 69 70 /* Match a `regexp' structure against a string. */ 71 72 int ExecRE ( 73 regexp *prog, /* Compiled regex. */ 74 const char *string, /* Text to search within. */ 75 const char *end, /* Pointer to the end of `string'. If NULL will 76 scan from `string' until '\0' is found. */ 77 int reverse, /* Backward search. */ 78 char prev_char, /* Character immediately prior to `string'. Set 79 to '\n' or '\0' if true beginning of text. */ 80 char succ_char, /* Character immediately after `end'. Set 81 to '\n' or '\0' if true beginning of text. */ 82 const char *delimiters, /* Word delimiters to use (NULL for default) */ 83 const char *look_behind_to,/* Boundary for look-behind; defaults to 84 "string" if NULL */ 85 const char *match_till); /* Boundary to where match can extend. 86 \0 is assumed to be the boundary if not 87 set. Lookahead can cross the boundary. */ 88 89 /* Perform substitutions after a `regexp' match. */ 90 Boolean SubstituteRE(const regexp* prog, const char* source, char* dest, 91 int max); 92 93 /* Builds a default delimiter table that persists across `ExecRE' calls that 94 is identical to `delimiters'. Pass NULL for "default default" set of 95 delimiters. */ 96 97 void SetREDefaultWordDelimiters ( 98 char *delimiters); 99 100 #endif /* NEDIT_REGULAREXP_H_INCLUDED */ 101