The R Project SVN R

Rev

Rev 19912 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19912 Rev 24109
Line 171... Line 171...
171
 
171
 
172
#endif /* not emacs */
172
#endif /* not emacs */
173

173

174
/* Get the interface, including the syntax bits.  */
174
/* Get the interface, including the syntax bits.  */
175
#include "Rregex.h"
175
#include "Rregex.h"
-
 
176
/* Compile a fastmap for the compiled pattern in BUFFER; used to
-
 
177
   accelerate searches.  Return 0 if successful and -2 if was an
-
 
178
   internal error.  */
-
 
179
static int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
-
 
180
/* Search in the string STRING (with length LENGTH) for the pattern
-
 
181
   compiled into BUFFER.  Start searching at position START, for RANGE
-
 
182
   characters.  Return the starting position of the match, -1 for no
-
 
183
   match, or -2 for an internal error.  Also return register
-
 
184
   information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
-
 
185
static int re_search
-
 
186
  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
-
 
187
            int length, int start, int range, struct re_registers *regs));
-
 
188
 
-
 
189
 
-
 
190
/* Like `re_search', but search in the concatenation of STRING1 and
-
 
191
   STRING2.  Also, stop searching at index START + STOP.  */
-
 
192
static int re_search_2
-
 
193
  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
-
 
194
             int length1, const char *string2, int length2,
-
 
195
             int start, int range, struct re_registers *regs, int stop));
-
 
196
 
-
 
197
 
176
 
198
 
177
/* isalpha etc. are used for the character classes.  */
199
/* isalpha etc. are used for the character classes.  */
178
#include <ctype.h>
200
#include <ctype.h>
179
 
201
 
180
/* Jim Meyering writes:
202
/* Jim Meyering writes:
Line 979... Line 1001...
979
/* Set by `re_set_syntax' to the current regexp syntax to recognize.  Can
1001
/* Set by `re_set_syntax' to the current regexp syntax to recognize.  Can
980
   also be assigned to arbitrarily: each pattern buffer stores its own
1002
   also be assigned to arbitrarily: each pattern buffer stores its own
981
   syntax, so it can be changed between regex compilations.  */
1003
   syntax, so it can be changed between regex compilations.  */
982
/* This has no initializer because initialized variables in Emacs
1004
/* This has no initializer because initialized variables in Emacs
983
   become read-only after dumping.  */
1005
   become read-only after dumping.  */
-
 
1006
#if 0
984
reg_syntax_t re_syntax_options;
1007
static reg_syntax_t re_syntax_options;
985
 
1008
#endif
986
 
1009
 
987
/* Specify the precise syntax of regexps for compilation.  This provides
1010
/* Specify the precise syntax of regexps for compilation.  This provides
988
   for compatibility for various utilities which historically have
1011
   for compatibility for various utilities which historically have
989
   different, incompatible syntaxes.
1012
   different, incompatible syntaxes.
990
 
1013
 
991
   The argument SYNTAX is a bit mask comprised of the various bits
1014
   The argument SYNTAX is a bit mask comprised of the various bits
992
   defined in regex.h.  We return the old syntax.  */
1015
   defined in regex.h.  We return the old syntax.  */
993
 
1016
 
-
 
1017
#if 0
994
reg_syntax_t
1018
static reg_syntax_t
995
re_set_syntax (syntax)
1019
re_set_syntax (syntax)
996
    reg_syntax_t syntax;
1020
    reg_syntax_t syntax;
997
{
1021
{
998
  reg_syntax_t ret = re_syntax_options;
1022
  reg_syntax_t ret = re_syntax_options;
999
 
1023
 
Line 1007... Line 1031...
1007
  return ret;
1031
  return ret;
1008
}
1032
}
1009
#ifdef _LIBC
1033
#ifdef _LIBC
1010
weak_alias (__re_set_syntax, re_set_syntax)
1034
weak_alias (__re_set_syntax, re_set_syntax)
1011
#endif
1035
#endif
-
 
1036
#endif
1012

1037

1013
/* This table gives an error message for each of the error codes listed
1038
/* This table gives an error message for each of the error codes listed
1014
   in regex.h.  Obviously the order here has to be same as there.
1039
   in regex.h.  Obviously the order here has to be same as there.
1015
   POSIX doesn't require that we do anything for REG_NOERROR,
1040
   POSIX doesn't require that we do anything for REG_NOERROR,
1016
   but why not be nice?  */
1041
   but why not be nice?  */
Line 1157... Line 1182...
1157
#ifdef INT_IS_16BIT
1182
#ifdef INT_IS_16BIT
1158
 
1183
 
1159
# if defined MATCH_MAY_ALLOCATE
1184
# if defined MATCH_MAY_ALLOCATE
1160
/* 4400 was enough to cause a crash on Alpha OSF/1,
1185
/* 4400 was enough to cause a crash on Alpha OSF/1,
1161
   whose default stack limit is 2mb.  */
1186
   whose default stack limit is 2mb.  */
1162
const long int re_max_failures = 4000;
1187
static const long int re_max_failures = 4000;
1163
# else
1188
# else
1164
const long int re_max_failures = 2000;
1189
static const long int re_max_failures = 2000;
1165
# endif
1190
# endif
1166
 
1191
 
1167
union fail_stack_elt
1192
union fail_stack_elt
1168
{
1193
{
1169
  unsigned char *pointer;
1194
  unsigned char *pointer;
Line 1182... Line 1207...
1182
#else /* not INT_IS_16BIT */
1207
#else /* not INT_IS_16BIT */
1183
 
1208
 
1184
# if defined MATCH_MAY_ALLOCATE
1209
# if defined MATCH_MAY_ALLOCATE
1185
/* 4400 was enough to cause a crash on Alpha OSF/1,
1210
/* 4400 was enough to cause a crash on Alpha OSF/1,
1186
   whose default stack limit is 2mb.  */
1211
   whose default stack limit is 2mb.  */
1187
const int re_max_failures = 20000;
1212
static const int re_max_failures = 20000;
1188
# else
1213
# else
1189
const int re_max_failures = 2000;
1214
static const int re_max_failures = 2000;
1190
# endif
1215
# endif
1191
 
1216
 
1192
union fail_stack_elt
1217
union fail_stack_elt
1193
{
1218
{
1194
  unsigned char *pointer;
1219
  unsigned char *pointer;
Line 3203... Line 3228...
3203
   We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
3228
   We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
3204
   the pattern buffer.
3229
   the pattern buffer.
3205
 
3230
 
3206
   Returns 0 if we succeed, -2 if an internal error.   */
3231
   Returns 0 if we succeed, -2 if an internal error.   */
3207
 
3232
 
3208
int
3233
static int
3209
re_compile_fastmap (bufp)
3234
re_compile_fastmap (bufp)
3210
     struct re_pattern_buffer *bufp;
3235
     struct re_pattern_buffer *bufp;
3211
{
3236
{
3212
  int j, k;
3237
  int j, k;
3213
#ifdef MATCH_MAY_ALLOCATE
3238
#ifdef MATCH_MAY_ALLOCATE
Line 3509... Line 3534...
3509
 
3534
 
3510
   Unless this function is called, the first search or match using
3535
   Unless this function is called, the first search or match using
3511
   PATTERN_BUFFER will allocate its own register data, without
3536
   PATTERN_BUFFER will allocate its own register data, without
3512
   freeing the old data.  */
3537
   freeing the old data.  */
3513
 
3538
 
-
 
3539
#if 0
3514
void
3540
static void
3515
re_set_registers (bufp, regs, num_regs, starts, ends)
3541
re_set_registers (bufp, regs, num_regs, starts, ends)
3516
    struct re_pattern_buffer *bufp;
3542
    struct re_pattern_buffer *bufp;
3517
    struct re_registers *regs;
3543
    struct re_registers *regs;
3518
    unsigned num_regs;
3544
    unsigned num_regs;
3519
    regoff_t *starts, *ends;
3545
    regoff_t *starts, *ends;
Line 3533... Line 3559...
3533
    }
3559
    }
3534
}
3560
}
3535
#ifdef _LIBC
3561
#ifdef _LIBC
3536
weak_alias (__re_set_registers, re_set_registers)
3562
weak_alias (__re_set_registers, re_set_registers)
3537
#endif
3563
#endif
-
 
3564
#endif
3538

3565

3539
/* Searching routines.  */
3566
/* Searching routines.  */
3540
 
3567
 
3541
/* Like re_search_2, below, but only one string is specified, and
3568
/* Like re_search_2, below, but only one string is specified, and
3542
   doesn't let you say where to stop matching. */
3569
   doesn't let you say where to stop matching. */
3543
 
3570
 
3544
int
3571
static int
3545
re_search (bufp, string, size, startpos, range, regs)
3572
re_search (bufp, string, size, startpos, range, regs)
3546
     struct re_pattern_buffer *bufp;
3573
     struct re_pattern_buffer *bufp;
3547
     const char *string;
3574
     const char *string;
3548
     int size, startpos, range;
3575
     int size, startpos, range;
3549
     struct re_registers *regs;
3576
     struct re_registers *regs;
Line 3575... Line 3602...
3575
 
3602
 
3576
   We return either the position in the strings at which the match was
3603
   We return either the position in the strings at which the match was
3577
   found, -1 if no match, or -2 if error (such as failure
3604
   found, -1 if no match, or -2 if error (such as failure
3578
   stack overflow).  */
3605
   stack overflow).  */
3579
 
3606
 
3580
int
3607
static int
3581
re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
3608
re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
3582
     struct re_pattern_buffer *bufp;
3609
     struct re_pattern_buffer *bufp;
3583
     const char *string1, *string2;
3610
     const char *string1, *string2;
3584
     int size1, size2;
3611
     int size1, size2;
3585
     int startpos;
3612
     int startpos;
Line 3797... Line 3824...
3797
#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
3824
#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
3798
#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
3825
#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
3799

3826

3800
/* Matching routines.  */
3827
/* Matching routines.  */
3801
 
3828
 
-
 
3829
#if 0
3802
#ifndef emacs   /* Emacs never uses this.  */
3830
#ifndef emacs   /* Emacs never uses this.  */
3803
/* re_match is like re_match_2 except it takes only a single string.  */
3831
/* re_match is like re_match_2 except it takes only a single string.  */
3804
 
3832
 
3805
int
3833
static int
3806
re_match (bufp, string, size, pos, regs)
3834
re_match (bufp, string, size, pos, regs)
3807
     struct re_pattern_buffer *bufp;
3835
     struct re_pattern_buffer *bufp;
3808
     const char *string;
3836
     const char *string;
3809
     int size, pos;
3837
     int size, pos;
3810
     struct re_registers *regs;
3838
     struct re_registers *regs;
Line 3820... Line 3848...
3820
}
3848
}
3821
# ifdef _LIBC
3849
# ifdef _LIBC
3822
weak_alias (__re_match, re_match)
3850
weak_alias (__re_match, re_match)
3823
# endif
3851
# endif
3824
#endif /* not emacs */
3852
#endif /* not emacs */
-
 
3853
#endif
3825
 
3854
 
3826
static boolean group_match_null_string_p _RE_ARGS ((unsigned char **p,
3855
static boolean group_match_null_string_p _RE_ARGS ((unsigned char **p,
3827
						    unsigned char *end,
3856
						    unsigned char *end,
3828
						register_info_type *reg_info));
3857
						register_info_type *reg_info));
3829
static boolean alt_match_null_string_p _RE_ARGS ((unsigned char *p,
3858
static boolean alt_match_null_string_p _RE_ARGS ((unsigned char *p,
Line 3846... Line 3875...
3846
 
3875
 
3847
   We return -1 if no match, -2 if an internal error (such as the
3876
   We return -1 if no match, -2 if an internal error (such as the
3848
   failure stack overflowing).  Otherwise, we return the length of the
3877
   failure stack overflowing).  Otherwise, we return the length of the
3849
   matched substring.  */
3878
   matched substring.  */
3850
 
3879
 
3851
int
3880
#if 0
-
 
3881
static int
3852
re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3882
re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3853
     struct re_pattern_buffer *bufp;
3883
     struct re_pattern_buffer *bufp;
3854
     const char *string1, *string2;
3884
     const char *string1, *string2;
3855
     int size1, size2;
3885
     int size1, size2;
3856
     int pos;
3886
     int pos;
Line 3867... Line 3897...
3867
  return result;
3897
  return result;
3868
}
3898
}
3869
#ifdef _LIBC
3899
#ifdef _LIBC
3870
weak_alias (__re_match_2, re_match_2)
3900
weak_alias (__re_match_2, re_match_2)
3871
#endif
3901
#endif
-
 
3902
#endif
3872
 
3903
 
3873
/* This is a separate function so that we can force an alloca cleanup
3904
/* This is a separate function so that we can force an alloca cleanup
3874
   afterwards.  */
3905
   afterwards.  */
3875
static int
3906
static int
3876
re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
3907
re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
Line 5523... Line 5554...
5523
   Assumes the `allocated' (and perhaps `buffer') and `translate' fields
5554
   Assumes the `allocated' (and perhaps `buffer') and `translate' fields
5524
   are set in BUFP on entry.
5555
   are set in BUFP on entry.
5525
 
5556
 
5526
   We call regex_compile to do the actual compilation.  */
5557
   We call regex_compile to do the actual compilation.  */
5527
 
5558
 
-
 
5559
#if 0
5528
const char *
5560
static const char *
5529
re_compile_pattern (pattern, length, bufp)
5561
re_compile_pattern (pattern, length, bufp)
5530
     const char *pattern;
5562
     const char *pattern;
5531
     size_t length;
5563
     size_t length;
5532
     struct re_pattern_buffer *bufp;
5564
     struct re_pattern_buffer *bufp;
5533
{
5565
{
Line 5552... Line 5584...
5552
  return gettext (re_error_msgid + re_error_msgid_idx[(int) ret]);
5584
  return gettext (re_error_msgid + re_error_msgid_idx[(int) ret]);
5553
}
5585
}
5554
#ifdef _LIBC
5586
#ifdef _LIBC
5555
weak_alias (__re_compile_pattern, re_compile_pattern)
5587
weak_alias (__re_compile_pattern, re_compile_pattern)
5556
#endif
5588
#endif
-
 
5589
#endif
5557

5590

5558
/* Entry points compatible with 4.2 BSD regex library.  We don't define
5591
/* Entry points compatible with 4.2 BSD regex library.  We don't define
5559
   them unless specifically requested.  */
5592
   them unless specifically requested.  */
5560
 
5593
 
5561
#if defined _REGEX_RE_COMP || defined _LIBC
5594
#if defined _REGEX_RE_COMP || defined _LIBC