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