tools/pcre/pcre_get.c
author Nicholas Hastings <skamonkey@gmail.com>
Sun Jul 15 12:31:06 2012 -0400 (2012-07-15)
changeset 3579 6d730190a3e4
parent 2762 d2d467bf1b5a
child 3831 babd0eee3c5e
permissions -rw-r--r--
Added missing files to each core and logic makefiles (NPOTB).
dvander@2762
     1
/*************************************************
dvander@2762
     2
*      Perl-Compatible Regular Expressions       *
dvander@2762
     3
*************************************************/
dvander@2762
     4
dvander@2762
     5
/* PCRE is a library of functions to support regular expressions whose syntax
dvander@2762
     6
and semantics are as close as possible to those of the Perl 5 language.
dvander@2762
     7
dvander@2762
     8
                       Written by Philip Hazel
dvander@2762
     9
           Copyright (c) 1997-2008 University of Cambridge
dvander@2762
    10
dvander@2762
    11
-----------------------------------------------------------------------------
dvander@2762
    12
Redistribution and use in source and binary forms, with or without
dvander@2762
    13
modification, are permitted provided that the following conditions are met:
dvander@2762
    14
dvander@2762
    15
    * Redistributions of source code must retain the above copyright notice,
dvander@2762
    16
      this list of conditions and the following disclaimer.
dvander@2762
    17
dvander@2762
    18
    * Redistributions in binary form must reproduce the above copyright
dvander@2762
    19
      notice, this list of conditions and the following disclaimer in the
dvander@2762
    20
      documentation and/or other materials provided with the distribution.
dvander@2762
    21
dvander@2762
    22
    * Neither the name of the University of Cambridge nor the names of its
dvander@2762
    23
      contributors may be used to endorse or promote products derived from
dvander@2762
    24
      this software without specific prior written permission.
dvander@2762
    25
dvander@2762
    26
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
dvander@2762
    27
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
dvander@2762
    28
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dvander@2762
    29
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
dvander@2762
    30
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
dvander@2762
    31
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
dvander@2762
    32
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dvander@2762
    33
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dvander@2762
    34
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
dvander@2762
    35
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
dvander@2762
    36
POSSIBILITY OF SUCH DAMAGE.
dvander@2762
    37
-----------------------------------------------------------------------------
dvander@2762
    38
*/
dvander@2762
    39
dvander@2762
    40
dvander@2762
    41
/* This module contains some convenience functions for extracting substrings
dvander@2762
    42
from the subject string after a regex match has succeeded. The original idea
dvander@2762
    43
for these functions came from Scott Wimer. */
dvander@2762
    44
dvander@2762
    45
dvander@2762
    46
#ifdef HAVE_CONFIG_H
dvander@2762
    47
#include "config.h"
dvander@2762
    48
#endif
dvander@2762
    49
dvander@2762
    50
#include "pcre_internal.h"
dvander@2762
    51
dvander@2762
    52
dvander@2762
    53
/*************************************************
dvander@2762
    54
*           Find number for named string         *
dvander@2762
    55
*************************************************/
dvander@2762
    56
dvander@2762
    57
/* This function is used by the get_first_set() function below, as well
dvander@2762
    58
as being generally available. It assumes that names are unique.
dvander@2762
    59
dvander@2762
    60
Arguments:
dvander@2762
    61
  code        the compiled regex
dvander@2762
    62
  stringname  the name whose number is required
dvander@2762
    63
dvander@2762
    64
Returns:      the number of the named parentheses, or a negative number
dvander@2762
    65
                (PCRE_ERROR_NOSUBSTRING) if not found
dvander@2762
    66
*/
dvander@2762
    67
dvander@2762
    68
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
    69
pcre_get_stringnumber(const pcre *code, const char *stringname)
dvander@2762
    70
{
dvander@2762
    71
int rc;
dvander@2762
    72
int entrysize;
dvander@2762
    73
int top, bot;
dvander@2762
    74
uschar *nametable;
dvander@2762
    75
dvander@2762
    76
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
dvander@2762
    77
  return rc;
dvander@2762
    78
if (top <= 0) return PCRE_ERROR_NOSUBSTRING;
dvander@2762
    79
dvander@2762
    80
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMEENTRYSIZE, &entrysize)) != 0)
dvander@2762
    81
  return rc;
dvander@2762
    82
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
dvander@2762
    83
  return rc;
dvander@2762
    84
dvander@2762
    85
bot = 0;
dvander@2762
    86
while (top > bot)
dvander@2762
    87
  {
dvander@2762
    88
  int mid = (top + bot) / 2;
dvander@2762
    89
  uschar *entry = nametable + entrysize*mid;
dvander@2762
    90
  int c = strcmp(stringname, (char *)(entry + 2));
dvander@2762
    91
  if (c == 0) return (entry[0] << 8) + entry[1];
dvander@2762
    92
  if (c > 0) bot = mid + 1; else top = mid;
dvander@2762
    93
  }
dvander@2762
    94
dvander@2762
    95
return PCRE_ERROR_NOSUBSTRING;
dvander@2762
    96
}
dvander@2762
    97
dvander@2762
    98
dvander@2762
    99
dvander@2762
   100
/*************************************************
dvander@2762
   101
*     Find (multiple) entries for named string   *
dvander@2762
   102
*************************************************/
dvander@2762
   103
dvander@2762
   104
/* This is used by the get_first_set() function below, as well as being
dvander@2762
   105
generally available. It is used when duplicated names are permitted.
dvander@2762
   106
dvander@2762
   107
Arguments:
dvander@2762
   108
  code        the compiled regex
dvander@2762
   109
  stringname  the name whose entries required
dvander@2762
   110
  firstptr    where to put the pointer to the first entry
dvander@2762
   111
  lastptr     where to put the pointer to the last entry
dvander@2762
   112
dvander@2762
   113
Returns:      the length of each entry, or a negative number
dvander@2762
   114
                (PCRE_ERROR_NOSUBSTRING) if not found
dvander@2762
   115
*/
dvander@2762
   116
dvander@2762
   117
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
   118
pcre_get_stringtable_entries(const pcre *code, const char *stringname,
dvander@2762
   119
  char **firstptr, char **lastptr)
dvander@2762
   120
{
dvander@2762
   121
int rc;
dvander@2762
   122
int entrysize;
dvander@2762
   123
int top, bot;
dvander@2762
   124
uschar *nametable, *lastentry;
dvander@2762
   125
dvander@2762
   126
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
dvander@2762
   127
  return rc;
dvander@2762
   128
if (top <= 0) return PCRE_ERROR_NOSUBSTRING;
dvander@2762
   129
dvander@2762
   130
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMEENTRYSIZE, &entrysize)) != 0)
dvander@2762
   131
  return rc;
dvander@2762
   132
if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
dvander@2762
   133
  return rc;
dvander@2762
   134
dvander@2762
   135
lastentry = nametable + entrysize * (top - 1);
dvander@2762
   136
bot = 0;
dvander@2762
   137
while (top > bot)
dvander@2762
   138
  {
dvander@2762
   139
  int mid = (top + bot) / 2;
dvander@2762
   140
  uschar *entry = nametable + entrysize*mid;
dvander@2762
   141
  int c = strcmp(stringname, (char *)(entry + 2));
dvander@2762
   142
  if (c == 0)
dvander@2762
   143
    {
dvander@2762
   144
    uschar *first = entry;
dvander@2762
   145
    uschar *last = entry;
dvander@2762
   146
    while (first > nametable)
dvander@2762
   147
      {
dvander@2762
   148
      if (strcmp(stringname, (char *)(first - entrysize + 2)) != 0) break;
dvander@2762
   149
      first -= entrysize;
dvander@2762
   150
      }
dvander@2762
   151
    while (last < lastentry)
dvander@2762
   152
      {
dvander@2762
   153
      if (strcmp(stringname, (char *)(last + entrysize + 2)) != 0) break;
dvander@2762
   154
      last += entrysize;
dvander@2762
   155
      }
dvander@2762
   156
    *firstptr = (char *)first;
dvander@2762
   157
    *lastptr = (char *)last;
dvander@2762
   158
    return entrysize;
dvander@2762
   159
    }
dvander@2762
   160
  if (c > 0) bot = mid + 1; else top = mid;
dvander@2762
   161
  }
dvander@2762
   162
dvander@2762
   163
return PCRE_ERROR_NOSUBSTRING;
dvander@2762
   164
}
dvander@2762
   165
dvander@2762
   166
dvander@2762
   167
dvander@2762
   168
/*************************************************
dvander@2762
   169
*    Find first set of multiple named strings    *
dvander@2762
   170
*************************************************/
dvander@2762
   171
dvander@2762
   172
/* This function allows for duplicate names in the table of named substrings.
dvander@2762
   173
It returns the number of the first one that was set in a pattern match.
dvander@2762
   174
dvander@2762
   175
Arguments:
dvander@2762
   176
  code         the compiled regex
dvander@2762
   177
  stringname   the name of the capturing substring
dvander@2762
   178
  ovector      the vector of matched substrings
dvander@2762
   179
dvander@2762
   180
Returns:       the number of the first that is set,
dvander@2762
   181
               or the number of the last one if none are set,
dvander@2762
   182
               or a negative number on error
dvander@2762
   183
*/
dvander@2762
   184
dvander@2762
   185
static int
dvander@2762
   186
get_first_set(const pcre *code, const char *stringname, int *ovector)
dvander@2762
   187
{
dvander@2762
   188
const real_pcre *re = (const real_pcre *)code;
dvander@2762
   189
int entrysize;
dvander@2762
   190
char *first, *last;
dvander@2762
   191
uschar *entry;
dvander@2762
   192
if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0)
dvander@2762
   193
  return pcre_get_stringnumber(code, stringname);
dvander@2762
   194
entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last);
dvander@2762
   195
if (entrysize <= 0) return entrysize;
dvander@2762
   196
for (entry = (uschar *)first; entry <= (uschar *)last; entry += entrysize)
dvander@2762
   197
  {
dvander@2762
   198
  int n = (entry[0] << 8) + entry[1];
dvander@2762
   199
  if (ovector[n*2] >= 0) return n;
dvander@2762
   200
  }
dvander@2762
   201
return (first[0] << 8) + first[1];
dvander@2762
   202
}
dvander@2762
   203
dvander@2762
   204
dvander@2762
   205
dvander@2762
   206
dvander@2762
   207
/*************************************************
dvander@2762
   208
*      Copy captured string to given buffer      *
dvander@2762
   209
*************************************************/
dvander@2762
   210
dvander@2762
   211
/* This function copies a single captured substring into a given buffer.
dvander@2762
   212
Note that we use memcpy() rather than strncpy() in case there are binary zeros
dvander@2762
   213
in the string.
dvander@2762
   214
dvander@2762
   215
Arguments:
dvander@2762
   216
  subject        the subject string that was matched
dvander@2762
   217
  ovector        pointer to the offsets table
dvander@2762
   218
  stringcount    the number of substrings that were captured
dvander@2762
   219
                   (i.e. the yield of the pcre_exec call, unless
dvander@2762
   220
                   that was zero, in which case it should be 1/3
dvander@2762
   221
                   of the offset table size)
dvander@2762
   222
  stringnumber   the number of the required substring
dvander@2762
   223
  buffer         where to put the substring
dvander@2762
   224
  size           the size of the buffer
dvander@2762
   225
dvander@2762
   226
Returns:         if successful:
dvander@2762
   227
                   the length of the copied string, not including the zero
dvander@2762
   228
                   that is put on the end; can be zero
dvander@2762
   229
                 if not successful:
dvander@2762
   230
                   PCRE_ERROR_NOMEMORY (-6) buffer too small
dvander@2762
   231
                   PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
dvander@2762
   232
*/
dvander@2762
   233
dvander@2762
   234
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
   235
pcre_copy_substring(const char *subject, int *ovector, int stringcount,
dvander@2762
   236
  int stringnumber, char *buffer, int size)
dvander@2762
   237
{
dvander@2762
   238
int yield;
dvander@2762
   239
if (stringnumber < 0 || stringnumber >= stringcount)
dvander@2762
   240
  return PCRE_ERROR_NOSUBSTRING;
dvander@2762
   241
stringnumber *= 2;
dvander@2762
   242
yield = ovector[stringnumber+1] - ovector[stringnumber];
dvander@2762
   243
if (size < yield + 1) return PCRE_ERROR_NOMEMORY;
dvander@2762
   244
memcpy(buffer, subject + ovector[stringnumber], yield);
dvander@2762
   245
buffer[yield] = 0;
dvander@2762
   246
return yield;
dvander@2762
   247
}
dvander@2762
   248
dvander@2762
   249
dvander@2762
   250
dvander@2762
   251
/*************************************************
dvander@2762
   252
*   Copy named captured string to given buffer   *
dvander@2762
   253
*************************************************/
dvander@2762
   254
dvander@2762
   255
/* This function copies a single captured substring into a given buffer,
dvander@2762
   256
identifying it by name. If the regex permits duplicate names, the first
dvander@2762
   257
substring that is set is chosen.
dvander@2762
   258
dvander@2762
   259
Arguments:
dvander@2762
   260
  code           the compiled regex
dvander@2762
   261
  subject        the subject string that was matched
dvander@2762
   262
  ovector        pointer to the offsets table
dvander@2762
   263
  stringcount    the number of substrings that were captured
dvander@2762
   264
                   (i.e. the yield of the pcre_exec call, unless
dvander@2762
   265
                   that was zero, in which case it should be 1/3
dvander@2762
   266
                   of the offset table size)
dvander@2762
   267
  stringname     the name of the required substring
dvander@2762
   268
  buffer         where to put the substring
dvander@2762
   269
  size           the size of the buffer
dvander@2762
   270
dvander@2762
   271
Returns:         if successful:
dvander@2762
   272
                   the length of the copied string, not including the zero
dvander@2762
   273
                   that is put on the end; can be zero
dvander@2762
   274
                 if not successful:
dvander@2762
   275
                   PCRE_ERROR_NOMEMORY (-6) buffer too small
dvander@2762
   276
                   PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
dvander@2762
   277
*/
dvander@2762
   278
dvander@2762
   279
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
   280
pcre_copy_named_substring(const pcre *code, const char *subject, int *ovector,
dvander@2762
   281
  int stringcount, const char *stringname, char *buffer, int size)
dvander@2762
   282
{
dvander@2762
   283
int n = get_first_set(code, stringname, ovector);
dvander@2762
   284
if (n <= 0) return n;
dvander@2762
   285
return pcre_copy_substring(subject, ovector, stringcount, n, buffer, size);
dvander@2762
   286
}
dvander@2762
   287
dvander@2762
   288
dvander@2762
   289
dvander@2762
   290
/*************************************************
dvander@2762
   291
*      Copy all captured strings to new store    *
dvander@2762
   292
*************************************************/
dvander@2762
   293
dvander@2762
   294
/* This function gets one chunk of store and builds a list of pointers and all
dvander@2762
   295
of the captured substrings in it. A NULL pointer is put on the end of the list.
dvander@2762
   296
dvander@2762
   297
Arguments:
dvander@2762
   298
  subject        the subject string that was matched
dvander@2762
   299
  ovector        pointer to the offsets table
dvander@2762
   300
  stringcount    the number of substrings that were captured
dvander@2762
   301
                   (i.e. the yield of the pcre_exec call, unless
dvander@2762
   302
                   that was zero, in which case it should be 1/3
dvander@2762
   303
                   of the offset table size)
dvander@2762
   304
  listptr        set to point to the list of pointers
dvander@2762
   305
dvander@2762
   306
Returns:         if successful: 0
dvander@2762
   307
                 if not successful:
dvander@2762
   308
                   PCRE_ERROR_NOMEMORY (-6) failed to get store
dvander@2762
   309
*/
dvander@2762
   310
dvander@2762
   311
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
   312
pcre_get_substring_list(const char *subject, int *ovector, int stringcount,
dvander@2762
   313
  const char ***listptr)
dvander@2762
   314
{
dvander@2762
   315
int i;
dvander@2762
   316
int size = sizeof(char *);
dvander@2762
   317
int double_count = stringcount * 2;
dvander@2762
   318
char **stringlist;
dvander@2762
   319
char *p;
dvander@2762
   320
dvander@2762
   321
for (i = 0; i < double_count; i += 2)
dvander@2762
   322
  size += sizeof(char *) + ovector[i+1] - ovector[i] + 1;
dvander@2762
   323
dvander@2762
   324
stringlist = (char **)(pcre_malloc)(size);
dvander@2762
   325
if (stringlist == NULL) return PCRE_ERROR_NOMEMORY;
dvander@2762
   326
dvander@2762
   327
*listptr = (const char **)stringlist;
dvander@2762
   328
p = (char *)(stringlist + stringcount + 1);
dvander@2762
   329
dvander@2762
   330
for (i = 0; i < double_count; i += 2)
dvander@2762
   331
  {
dvander@2762
   332
  int len = ovector[i+1] - ovector[i];
dvander@2762
   333
  memcpy(p, subject + ovector[i], len);
dvander@2762
   334
  *stringlist++ = p;
dvander@2762
   335
  p += len;
dvander@2762
   336
  *p++ = 0;
dvander@2762
   337
  }
dvander@2762
   338
dvander@2762
   339
*stringlist = NULL;
dvander@2762
   340
return 0;
dvander@2762
   341
}
dvander@2762
   342
dvander@2762
   343
dvander@2762
   344
dvander@2762
   345
/*************************************************
dvander@2762
   346
*   Free store obtained by get_substring_list    *
dvander@2762
   347
*************************************************/
dvander@2762
   348
dvander@2762
   349
/* This function exists for the benefit of people calling PCRE from non-C
dvander@2762
   350
programs that can call its functions, but not free() or (pcre_free)() directly.
dvander@2762
   351
dvander@2762
   352
Argument:   the result of a previous pcre_get_substring_list()
dvander@2762
   353
Returns:    nothing
dvander@2762
   354
*/
dvander@2762
   355
dvander@2762
   356
PCRE_EXP_DEFN void PCRE_CALL_CONVENTION
dvander@2762
   357
pcre_free_substring_list(const char **pointer)
dvander@2762
   358
{
dvander@2762
   359
(pcre_free)((void *)pointer);
dvander@2762
   360
}
dvander@2762
   361
dvander@2762
   362
dvander@2762
   363
dvander@2762
   364
/*************************************************
dvander@2762
   365
*      Copy captured string to new store         *
dvander@2762
   366
*************************************************/
dvander@2762
   367
dvander@2762
   368
/* This function copies a single captured substring into a piece of new
dvander@2762
   369
store
dvander@2762
   370
dvander@2762
   371
Arguments:
dvander@2762
   372
  subject        the subject string that was matched
dvander@2762
   373
  ovector        pointer to the offsets table
dvander@2762
   374
  stringcount    the number of substrings that were captured
dvander@2762
   375
                   (i.e. the yield of the pcre_exec call, unless
dvander@2762
   376
                   that was zero, in which case it should be 1/3
dvander@2762
   377
                   of the offset table size)
dvander@2762
   378
  stringnumber   the number of the required substring
dvander@2762
   379
  stringptr      where to put a pointer to the substring
dvander@2762
   380
dvander@2762
   381
Returns:         if successful:
dvander@2762
   382
                   the length of the string, not including the zero that
dvander@2762
   383
                   is put on the end; can be zero
dvander@2762
   384
                 if not successful:
dvander@2762
   385
                   PCRE_ERROR_NOMEMORY (-6) failed to get store
dvander@2762
   386
                   PCRE_ERROR_NOSUBSTRING (-7) substring not present
dvander@2762
   387
*/
dvander@2762
   388
dvander@2762
   389
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
   390
pcre_get_substring(const char *subject, int *ovector, int stringcount,
dvander@2762
   391
  int stringnumber, const char **stringptr)
dvander@2762
   392
{
dvander@2762
   393
int yield;
dvander@2762
   394
char *substring;
dvander@2762
   395
if (stringnumber < 0 || stringnumber >= stringcount)
dvander@2762
   396
  return PCRE_ERROR_NOSUBSTRING;
dvander@2762
   397
stringnumber *= 2;
dvander@2762
   398
yield = ovector[stringnumber+1] - ovector[stringnumber];
dvander@2762
   399
substring = (char *)(pcre_malloc)(yield + 1);
dvander@2762
   400
if (substring == NULL) return PCRE_ERROR_NOMEMORY;
dvander@2762
   401
memcpy(substring, subject + ovector[stringnumber], yield);
dvander@2762
   402
substring[yield] = 0;
dvander@2762
   403
*stringptr = substring;
dvander@2762
   404
return yield;
dvander@2762
   405
}
dvander@2762
   406
dvander@2762
   407
dvander@2762
   408
dvander@2762
   409
/*************************************************
dvander@2762
   410
*   Copy named captured string to new store      *
dvander@2762
   411
*************************************************/
dvander@2762
   412
dvander@2762
   413
/* This function copies a single captured substring, identified by name, into
dvander@2762
   414
new store. If the regex permits duplicate names, the first substring that is
dvander@2762
   415
set is chosen.
dvander@2762
   416
dvander@2762
   417
Arguments:
dvander@2762
   418
  code           the compiled regex
dvander@2762
   419
  subject        the subject string that was matched
dvander@2762
   420
  ovector        pointer to the offsets table
dvander@2762
   421
  stringcount    the number of substrings that were captured
dvander@2762
   422
                   (i.e. the yield of the pcre_exec call, unless
dvander@2762
   423
                   that was zero, in which case it should be 1/3
dvander@2762
   424
                   of the offset table size)
dvander@2762
   425
  stringname     the name of the required substring
dvander@2762
   426
  stringptr      where to put the pointer
dvander@2762
   427
dvander@2762
   428
Returns:         if successful:
dvander@2762
   429
                   the length of the copied string, not including the zero
dvander@2762
   430
                   that is put on the end; can be zero
dvander@2762
   431
                 if not successful:
dvander@2762
   432
                   PCRE_ERROR_NOMEMORY (-6) couldn't get memory
dvander@2762
   433
                   PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
dvander@2762
   434
*/
dvander@2762
   435
dvander@2762
   436
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
   437
pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,
dvander@2762
   438
  int stringcount, const char *stringname, const char **stringptr)
dvander@2762
   439
{
dvander@2762
   440
int n = get_first_set(code, stringname, ovector);
dvander@2762
   441
if (n <= 0) return n;
dvander@2762
   442
return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
dvander@2762
   443
}
dvander@2762
   444
dvander@2762
   445
dvander@2762
   446
dvander@2762
   447
dvander@2762
   448
/*************************************************
dvander@2762
   449
*       Free store obtained by get_substring     *
dvander@2762
   450
*************************************************/
dvander@2762
   451
dvander@2762
   452
/* This function exists for the benefit of people calling PCRE from non-C
dvander@2762
   453
programs that can call its functions, but not free() or (pcre_free)() directly.
dvander@2762
   454
dvander@2762
   455
Argument:   the result of a previous pcre_get_substring()
dvander@2762
   456
Returns:    nothing
dvander@2762
   457
*/
dvander@2762
   458
dvander@2762
   459
PCRE_EXP_DEFN void PCRE_CALL_CONVENTION
dvander@2762
   460
pcre_free_substring(const char *pointer)
dvander@2762
   461
{
dvander@2762
   462
(pcre_free)((void *)pointer);
dvander@2762
   463
}
dvander@2762
   464
dvander@2762
   465
/* End of pcre_get.c */