Dr Andrew Scott G7VAV

My photo
 
April 2024
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
6 7 8 9 10 11 12


regexp.h
001: /* Copyright (C) 1996, 1997, 1998, 1999, 2004, 2008
002:    Free Software Foundation, Inc.
003:    This file is part of the GNU C Library.
004:    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
005: 
006:    The GNU C Library is free software; you can redistribute it and/or
007:    modify it under the terms of the GNU Lesser General Public
008:    License as published by the Free Software Foundation; either
009:    version 2.1 of the License, or (at your option) any later version.
010: 
011:    The GNU C Library is distributed in the hope that it will be useful,
012:    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:    Lesser General Public License for more details.
015: 
016:    You should have received a copy of the GNU Lesser General Public
017:    License along with the GNU C Library; if not, write to the Free
018:    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
019:    02111-1307 USA.  */
020: 
021: #ifndef _REGEXP_H
022: #define _REGEXP_H       1
023: 
024: /* The contents of this header file was first standardized in X/Open
025:    System Interface and Headers Issue 2, originally coming from SysV.
026:    In issue 4, version 2, it is marked as TO BE WITDRAWN, and it has
027:    been withdrawn in SUSv3.
028: 
029:    This code shouldn't be used in any newly written code.  It is
030:    included only for compatibility reasons.  Use the POSIX definition
031:    in <regex.h> for portable applications and a reasonable interface.  */
032: 
033: #include <features.h>
034: #include <alloca.h>
035: #include <regex.h>
036: #include <stdlib.h>
037: #include <string.h>
038: 
039: /* The implementation provided here emulates the needed functionality
040:    by mapping to the POSIX regular expression matcher.  The interface
041:    for the here included function is weird (this really is a harmless
042:    word).
043: 
044:    The user has to provide six macros before this header file can be
045:    included:
046: 
047:    INIT         Declarations vor variables which can be used by the
048:                 other macros.
049: 
050:    GETC()       Return the value of the next character in the regular
051:                 expression pattern.  Successive calls should return
052:                 successive characters.
053: 
054:    PEEKC()      Return the value of the next character in the regular
055:                 expression pattern.  Immediately successive calls to
056:                 PEEKC() should return the same character which should
057:                 also be the next character returned by GETC().
058: 
059:    UNGETC(c)    Cause `c' to be returned by the next call to GETC() and
060:                 PEEKC().
061: 
062:    RETURN(ptr)  Used for normal exit of the `compile' function.  `ptr'
063:                 is a pointer to the character after the last character of
064:                 the compiled regular expression.
065: 
066:    ERROR(val)   Used for abnormal return from `compile'.  `val' is the
067:                 error number.  The error codes are:
068:                 11      Range endpoint too large.
069:                 16      Bad number.
070:                 25      \digit out of range.
071:                 36      Illegal or missing delimiter.
072:                 41      No remembered search string.
073:                 42      \( \) imbalance.
074:                 43      Too many \(.
075:                 44      More tan two numbers given in \{ \}.
076:                 45      } expected after \.
077:                 46      First number exceeds second in \{ \}.
078:                 49      [ ] imbalance.
079:                 50      Regular expression overflow.
080: 
081:   */
082: 
083: __BEGIN_DECLS
084: 
085: /* Interface variables.  They contain the results of the successful
086:    calls to `setp' and `advance'.  */
087: extern char *loc1;
088: extern char *loc2;
089: 
090: /* The use of this variable in the `advance' function is not
091:    supported.  */
092: extern char *locs;
093: 
094: 
095: #ifndef __DO_NOT_DEFINE_COMPILE
096: /* Get and compile the user supplied pattern up to end of line or
097:    string or until EOF is seen, whatever happens first.  The result is
098:    placed in the buffer starting at EXPBUF and delimited by ENDBUF.
099: 
100:    This function cannot be defined in the libc itself since it depends
101:    on the macros.  */
102: char *
103: compile (char *__restrict instring, char *__restrict expbuf,
104:          __const char *__restrict endbuf, int eof)
105: {
106:   char *__input_buffer = NULL;
107:   size_t __input_size = 0;
108:   size_t __current_size = 0;
109:   int __ch;
110:   int __error;
111:   INIT
112: 
113:   /* Align the expression buffer according to the needs for an object
114:      of type `regex_t'.  Then check for minimum size of the buffer for
115:      the compiled regular expression.  */
116:   regex_t *__expr_ptr;
117: # if defined __GNUC__ && __GNUC__ >= 2
118:   const size_t __req = __alignof__ (regex_t *);
119: # else
120:   /* How shall we find out?  We simply guess it and can change it is
121:      this really proofs to be wrong.  */
122:   const size_t __req = 8;
123: # endif
124:   expbuf += __req;
125:   expbuf -= (expbuf - ((char *) 0)) % __req;
126:   if (endbuf < expbuf + sizeof (regex_t))
127:     {
128:       ERROR (50);
129:     }
130:   __expr_ptr = (regex_t *) expbuf;
131:   /* The remaining space in the buffer can be used for the compiled
132:      pattern.  */
133:   __expr_ptr->__REPB_PREFIX (buffer) = expbuf + sizeof (regex_t);
134:   __expr_ptr->__REPB_PREFIX (allocated)
135:     = endbuf - (char *) __expr_ptr->__REPB_PREFIX (buffer);
136: 
137:   while ((__ch = (GETC ())) != eof)
138:     {
139:       if (__ch == '\0' || __ch == '\n')
140:         {
141:           UNGETC (__ch);
142:           break;
143:         }
144: 
145:       if (__current_size + 1 >= __input_size)
146:         {
147:           size_t __new_size = __input_size ? 2 * __input_size : 128;
148:           char *__new_room = (char *) alloca (__new_size);
149:           /* See whether we can use the old buffer.  */
150:           if (__new_room + __new_size == __input_buffer)
151:             {
152:               __input_size += __new_size;
153:               __input_buffer = (char *) memcpy (__new_room, __input_buffer,
154:                                                __current_size);
155:             }
156:           else if (__input_buffer + __input_size == __new_room)
157:             __input_size += __new_size;
158:           else
159:             {
160:               __input_size = __new_size;
161:               __input_buffer = (char *) memcpy (__new_room, __input_buffer,
162:                                                 __current_size);
163:             }
164:         }
165:       __input_buffer[__current_size++] = __ch;
166:     }
167:   if (__current_size)
168:     __input_buffer[__current_size++] = '\0';
169:   else
170:     __input_buffer = "";
171: 
172:   /* Now compile the pattern.  */
173:   __error = regcomp (__expr_ptr, __input_buffer, REG_NEWLINE);
174:   if (__error != 0)
175:     /* Oh well, we have to translate POSIX error codes.  */
176:     switch (__error)
177:       {
178:       case REG_BADPAT:
179:       case REG_ECOLLATE:
180:       case REG_ECTYPE:
181:       case REG_EESCAPE:
182:       case REG_BADRPT:
183:       case REG_EEND:
184:       case REG_ERPAREN:
185:       default:
186:         /* There is no matching error code.  */
187:         RETURN (36);
188:       case REG_ESUBREG:
189:         RETURN (25);
190:       case REG_EBRACK:
191:         RETURN (49);
192:       case REG_EPAREN:
193:         RETURN (42);
194:       case REG_EBRACE:
195:         RETURN (44);
196:       case REG_BADBR:
197:         RETURN (46);
198:       case REG_ERANGE:
199:         RETURN (11);
200:       case REG_ESPACE:
201:       case REG_ESIZE:
202:         ERROR (50);
203:       }
204: 
205:   /* Everything is ok.  */
206:   RETURN ((char *) (__expr_ptr->__REPB_PREFIX (buffer)
207:                     + __expr_ptr->__REPB_PREFIX (used)));
208: }
209: #endif
210: 
211: 
212: /* Find the next match in STRING.  The compiled regular expression is
213:    found in the buffer starting at EXPBUF.  `loc1' will return the
214:    first character matched and `loc2' points to the next unmatched
215:    character.  */
216: extern int step (__const char *__restrict __string,
217:                  __const char *__restrict __expbuf) __THROW;
218: 
219: /* Match the beginning of STRING with the compiled regular expression
220:    in EXPBUF.  If the match is successful `loc2' will contain the
221:    position of the first unmatched character.  */
222: extern int advance (__const char *__restrict __string,
223:                     __const char *__restrict __expbuf) __THROW;
224: 
225: 
226: __END_DECLS
227: 
228: #endif /* regexp.h */
229: 


for client 3.144.103.10
© Andrew Scott 2006 - 2024,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/