1 /* $Header: /home/agc/src/libutf-2.10/RCS/ure.h,v 1.13 1997/02/24 12:22:36 agc Exp $ */ 2 3 /* 4 * Copyright © 1996-1997 Alistair G. Crooks. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Alistair G. Crooks. 17 * 4. The name of the author may not be used to endorse or promote 18 * products derived from this software without specific prior written 19 * permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 #ifndef URE_H_ 34 #define URE_H_ 35 36 #include <sys/types.h> 37 38 /* we need this for the Rune definition */ 39 #include "utf.h" 40 41 /* someone was working overtime when they specified how large a range could be */ 42 typedef off_t ureoff_t; 43 44 /* bits used later on... */ 45 enum { 46 URE_COMP_BIT= 0x4000, 47 URE_EXEC_BIT = 0x8000, 48 URE_FLAG_BITS = 0xff 49 }; 50 51 /* urecomp() flags */ 52 enum { 53 URE_BASIC = (URE_COMP_BIT | 0x00), 54 URE_EXTENDED = (URE_COMP_BIT | 0x01), 55 URE_COMP_ICASE = (URE_COMP_BIT | 0x02), 56 URE_NOSUB = (URE_COMP_BIT | 0x04), 57 URE_NEWLINE = (URE_COMP_BIT | 0x08), 58 URE_NOSPEC = (URE_COMP_BIT | 0x10), 59 URE_PEND = (URE_COMP_BIT | 0x20), 60 URE_DUMP = (URE_COMP_BIT | 0x80) 61 }; 62 63 /* ureexec flags */ 64 enum { 65 URE_NOTBOL = (URE_EXEC_BIT | 0x01), 66 URE_NOTEOL = (URE_EXEC_BIT | 0x02), 67 URE_STARTEND = (URE_EXEC_BIT | 0x04), 68 URE_ICASE = (URE_EXEC_BIT | 0x08), 69 URE_TRACE = (URE_EXEC_BIT | 0x10), 70 URE_LARGE = (URE_EXEC_BIT | 0x20), 71 URE_BACKR = (URE_EXEC_BIT | 0x40) 72 }; 73 74 /* URE error numbers - see ureerror */ 75 enum UREErrs { 76 URE_SUCCESS, 77 URE_NOMATCH, 78 URE_ERR_UNMATCHED_BRACKET, 79 URE_ERR_INTERNAL_MESS, 80 URE_ERR_REPEAT_FOLLOWS_NOTHING, 81 URE_ERR_TRAILING_BACKSLASH, 82 URE_ERR_INTERNAL_DISASTER, 83 URE_ERR_OPERAND_EMPTY, 84 URE_ERR_NESTED_REPEAT, 85 URE_ERR_TOO_MANY_PARENS, 86 URE_ERR_UNMATCHED_PAREN, 87 URE_ERR_JUNK_ON_END, 88 URE_ERR_NULL_ARG, 89 URE_ERR_TOO_BIG, 90 URE_ERR_EXECUTION_BUG, 91 URE_ERR_MEMORY_CORRUPTION, 92 URE_ERR_CORRUPTED_POINTERS, 93 URE_ERR_NULL_PARAM, 94 URE_ERR_BAD_MAGIC, 95 URE_ERR_CORRUPTED_OPCODE, 96 URE_ERR_SUBST_NULL_ARG, 97 URE_ERR_SUBST_BAD_MAGIC, 98 URE_ERR_SUBST_DAMAGED_MATCH, 99 URE_ERR_OUT_OF_SPACE, 100 URE_ERR_UNKNOWN 101 }; 102 103 #define URE_NSUBEXP 0x2000 104 105 /* this structure describes a compiled utf-aware regular expression */ 106 typedef struct ure_t { 107 int u_subc; /* # of sub expressions */ 108 int u_flags; /* compilation flags */ 109 Rune u_start; /* Internal use only. */ 110 Rune u_anch; /* Internal use only. */ 111 Rune *u_must; /* Internal use only. */ 112 int u_mlen; /* Internal use only. */ 113 Rune *u_prog; /* Compiled form of expression. */ 114 } ure_t; 115 116 /* a match structure - describes the start and end points */ 117 typedef struct { 118 ureoff_t rm_so; /* start of match */ 119 ureoff_t rm_eo; /* end of match */ 120 } urematch_t; 121 122 int urecomp(ure_t *up, char *exp, int cflags); 123 int ureexec(ure_t *up, char *s, int matchc, urematch_t *matchv, int flags, char *collseq); 124 int ureerror(int errcode, ure_t *up, char *buf, int size); 125 void urefree(ure_t *up); 126 127 #endif /* !URE_H_ */ 128