Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 84 lines (73 sloc) 2.976 kB
7468446 @dmorissette New regex wrappers to solve issues with previous version (bug 1354)
dmorissette authored
1 /******************************************************************************
2 * $Id$
3 *
4 * Project: MapServer
5 * Purpose: Regex wrapper
6 * Author: Bill Binko
7 *
8 ******************************************************************************
9 * Copyright (c) 1996-2005 Regents of the University of Minnesota.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
8853727 @tbonfort fix formatting as modified by astyle.sh
tbonfort authored
18 * The above copyright notice and this permission notice shall be included in
7468446 @dmorissette New regex wrappers to solve issues with previous version (bug 1354)
dmorissette authored
19 * all copies of this Software or works derived from this Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
f754244 @dmorissette Added missing line at end of license text
dmorissette authored
27 * DEALINGS IN THE SOFTWARE.
71a54a7 @warmerdam strip CVS logs
warmerdam authored
28 ****************************************************************************/
7468446 @dmorissette New regex wrappers to solve issues with previous version (bug 1354)
dmorissette authored
29
18f2484 @dmorissette Renamed map.h to mapserver.h (ticket #1437)
dmorissette authored
30 /* we can't include mapserver.h, so we need our own basics */
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <math.h>
36
37 #if defined(_WIN32) && !defined(__CYGWIN__)
38 #include <direct.h>
39 #include <memory.h>
40 #include <malloc.h>
41 #else
42 #include <unistd.h>
43 #endif
44
45 /*Need to specify this so that mapregex.h doesn't defined constants and
46 doesn't #define away our ms_*/
47
c37f462 Add a define to fix build on windows (Bug 1354).
Assefa Yewondwossen authored
48 #if defined(_WIN32) && !defined(__CYGWIN__)
11603b3 Change define of off_t instead of _off_t since It seems off_t
Assefa Yewondwossen authored
49 #define off_t long
c37f462 Add a define to fix build on windows (Bug 1354).
Assefa Yewondwossen authored
50 #endif
51
58fc3ab Fixed: Memory allocation results should always be checked (#3559)
Alan Boudreault authored
52 #include "mapserver.h"
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
53 #include "mapregex.h"
54 #include <regex.h>
55
9e078db Fixed warnings in php/mapscript
Alan Boudreault authored
56 MS_API_EXPORT(int) ms_regcomp(ms_regex_t *regex, const char *expr, int cflags)
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
57 {
58 /* Must free in regfree() */
58fc3ab Fixed: Memory allocation results should always be checked (#3559)
Alan Boudreault authored
59 regex_t* sys_regex = (regex_t*) msSmallMalloc(sizeof(regex_t));
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
60 regex->sys_regex = (void*) sys_regex;
61 return regcomp(sys_regex, expr, cflags);
62 }
63
9e078db Fixed warnings in php/mapscript
Alan Boudreault authored
64 MS_API_EXPORT(size_t) ms_regerror(int errcode, const ms_regex_t *regex, char *errbuf, size_t errbuf_size)
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
65 {
66 return regerror(errcode, (regex_t*)(regex->sys_regex), errbuf, errbuf_size);
67 }
68
9e078db Fixed warnings in php/mapscript
Alan Boudreault authored
69 MS_API_EXPORT(int) ms_regexec(const ms_regex_t *regex, const char *string, size_t nmatch, ms_regmatch_t pmatch[], int eflags)
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
70 {
71 /*This next line only works because we know that regmatch_t
72 and ms_regmatch_t are exactly alike (POSIX STANDARD)*/
8853727 @tbonfort fix formatting as modified by astyle.sh
tbonfort authored
73 return regexec((const regex_t*)(regex->sys_regex),
74 string, nmatch,
75 (regmatch_t*) pmatch, eflags);
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
76 }
77
9e078db Fixed warnings in php/mapscript
Alan Boudreault authored
78 MS_API_EXPORT(void) ms_regfree(ms_regex_t *regex)
e717a9e @dmorissette Ooops.. forgot to commit the new regex wrapper files for bug 1354
dmorissette authored
79 {
80 regfree((regex_t*)(regex->sys_regex));
81 free(regex->sys_regex);
82 return;
83 }
Something went wrong with that request. Please try again.