unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 898c0f2aea9bce45dc9d25a9530dd3ac79dc4bf9 7932 bytes (raw)
name: src/regex-emacs.h 	 # note: path name is non-authoritative(*)

  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
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 
/* Definitions for data structures and routines for the regular
   expression library, version 0.12.

   Copyright (C) 1985, 1989-1993, 1995, 2000-2018 Free Software
   Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

#ifndef EMACS_REGEX_H
#define EMACS_REGEX_H 1

#include <stddef.h>

/* This is the structure we store register match data in.  See
   regex.texinfo for a full description of what registers match.
   Declare this before including lisp.h, since lisp.h (via thread.h)
   uses struct re_registers.  */
struct re_registers
{
  unsigned num_regs;
  ptrdiff_t *start;
  ptrdiff_t *end;
};

#include "lisp.h"

/* In Emacs, this is the string or buffer in which we are matching.
   It is used for looking up syntax properties.

   If the value is a Lisp string object, we are matching text in that
   string; if it's nil, we are matching text in the current buffer; if
   it's t, we are matching text in a C string.

   This value is effectively another parameter to re_search_2 and
   re_match_2.  No calls into Lisp or thread switches are allowed
   before setting re_match_object and calling into the regex search
   and match functions.  These functions capture the current value of
   re_match_object into gl_state on entry.

   TODO: turn into an actual function parameter.  */
extern Lisp_Object re_match_object;

/* Roughly the maximum number of failure points on the stack.  */
extern size_t emacs_re_max_failures;

/* Amount of memory that we can safely stack allocate.  */
extern ptrdiff_t emacs_re_safe_alloca;

\f
/* This data structure represents a compiled pattern.  Before calling
   the pattern compiler, the fields `buffer', `allocated', `fastmap',
   `translate', and `no_sub' can be set.  After the pattern has been
   compiled, the `re_nsub' field is available.  All other fields are
   private to the regex routines.  */

struct re_pattern_buffer
{
	/* Space that holds the compiled pattern.  It is declared as
          `unsigned char *' because its elements are
           sometimes used as array indexes.  */
  unsigned char *buffer;

	/* Number of bytes to which `buffer' points.  */
  size_t allocated;

	/* Number of bytes actually used in `buffer'.  */
  size_t used;

        /* Charset of unibyte characters at compiling time. */
  int charset_unibyte;

        /* Pointer to a fastmap, if any, otherwise zero.  re_search uses
           the fastmap, if there is one, to skip over impossible
           starting points for matches.  */
  char *fastmap;

        /* Either a translate table to apply to all characters before
           comparing them, or zero for no translation.  The translation
           is applied to a pattern when it is compiled and to a string
           when it is matched.  */
  Lisp_Object translate;

	/* Number of subexpressions found by the compiler.  */
  size_t re_nsub;

        /* Zero if this pattern cannot match the empty string, one else.
           Well, in truth it's used only in `re_search_2', to see
           whether or not we should use the fastmap, so we don't set
           this absolutely perfectly; see `re_compile_fastmap'.  */
  unsigned can_be_null : 1;

        /* If REGS_UNALLOCATED, allocate space in the `regs' structure
             for `max (RE_NREGS, re_nsub + 1)' groups.
           If REGS_REALLOCATE, reallocate space if necessary.
           If REGS_FIXED, use what's there.  */
  unsigned regs_allocated : 2;

        /* Set to zero when `regex_compile' compiles a pattern; set to one
           by `re_compile_fastmap' if it updates the fastmap.  */
  unsigned fastmap_accurate : 1;

        /* If set, `re_match_2' does not return information about
           subexpressions.  */
  unsigned no_sub : 1;

        /* If set, a beginning-of-line anchor doesn't match at the
           beginning of the string.  */
  unsigned not_bol : 1;

        /* Similarly for an end-of-line anchor.  */
  unsigned not_eol : 1;

  /* If true, the compilation of the pattern had to look up the syntax table,
     so the compiled pattern is only valid for the current syntax table.  */
  unsigned used_syntax : 1;

  /* If true, multi-byte form in the regexp pattern should be
     recognized as a multibyte character.  */
  unsigned multibyte : 1;

  /* If true, multi-byte form in the target of match should be
     recognized as a multibyte character.  */
  unsigned target_multibyte : 1;
};
\f
/* Declarations for routines.  */

/* Compile the regular expression PATTERN, with length LENGTH
   and syntax given by the global `re_syntax_options', into the buffer
   BUFFER.  Return NULL if successful, and an error string if not.  */
extern const char *re_compile_pattern (const char *pattern, size_t length,
				       bool posix_backtracking,
				       const char *whitespace_regexp,
				       struct re_pattern_buffer *buffer);


/* Search in the string STRING (with length LENGTH) for the pattern
   compiled into BUFFER.  Start searching at position START, for RANGE
   characters.  Return the starting position of the match, -1 for no
   match, or -2 for an internal error.  Also return register
   information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
extern ptrdiff_t re_search (struct re_pattern_buffer *buffer,
			   const char *string, size_t length,
			   ptrdiff_t start, ptrdiff_t range,
			   struct re_registers *regs);


/* Like `re_search', but search in the concatenation of STRING1 and
   STRING2.  Also, stop searching at index START + STOP.  */
extern ptrdiff_t re_search_2 (struct re_pattern_buffer *buffer,
			     const char *string1, size_t length1,
			     const char *string2, size_t length2,
			     ptrdiff_t start, ptrdiff_t range,
			     struct re_registers *regs,
			     ptrdiff_t stop);


/* Like 're_search_2', but return how many characters in STRING the regexp
   in BUFFER matched, starting at position START.  */
extern ptrdiff_t re_match_2 (struct re_pattern_buffer *buffer,
			    const char *string1, size_t length1,
			    const char *string2, size_t length2,
			    ptrdiff_t start, struct re_registers *regs,
			    ptrdiff_t stop);


/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
   ENDS.  Subsequent matches using BUFFER and REGS will use this memory
   for recording register information.  STARTS and ENDS must be
   allocated with malloc, and must each be at least `NUM_REGS * sizeof
   (ptrdiff_t)' bytes long.

   If NUM_REGS == 0, then subsequent matches should allocate their own
   register data.

   Unless this function is called, the first search or match using
   PATTERN_BUFFER will allocate its own register data, without
   freeing the old data.  */
extern void re_set_registers (struct re_pattern_buffer *buffer,
			      struct re_registers *regs,
			      unsigned num_regs,
			      ptrdiff_t *starts, ptrdiff_t *ends);

/* Character classes.  */
typedef enum { RECC_ERROR = 0,
	       RECC_ALNUM, RECC_ALPHA, RECC_WORD,
	       RECC_GRAPH, RECC_PRINT,
	       RECC_LOWER, RECC_UPPER,
	       RECC_PUNCT, RECC_CNTRL,
	       RECC_DIGIT, RECC_XDIGIT,
	       RECC_BLANK, RECC_SPACE,
	       RECC_MULTIBYTE, RECC_NONASCII,
	       RECC_ASCII, RECC_UNIBYTE
} re_wctype_t;

extern bool re_iswctype (int ch, re_wctype_t cc);
extern re_wctype_t re_wctype_parse (const unsigned char **strp,
				    unsigned limit);

#endif /* regex-emacs.h */

debug log:

solving 898c0f2aea ...
found 898c0f2aea in https://yhetil.org/emacs-bugs/d32f5409-cdf4-e0f9-76e1-671013feea0b@cs.ucla.edu/ ||
	https://yhetil.org/emacs-bugs/15823bbe-8298-0d69-c7a6-edf2001e4513@cs.ucla.edu/
found 8a15e5793f in https://yhetil.org/emacs-bugs/d32f5409-cdf4-e0f9-76e1-671013feea0b@cs.ucla.edu/ ||
	https://yhetil.org/emacs-bugs/20180717234729.15507-1-eggert@cs.ucla.edu/ ||
	https://yhetil.org/emacs-bugs/15823bbe-8298-0d69-c7a6-edf2001e4513@cs.ucla.edu/
found 3a2d74d86a in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 3a2d74d86a1227a962d789b9f807ef5f2860198b	src/regex.h

applying [1/2] https://yhetil.org/emacs-bugs/d32f5409-cdf4-e0f9-76e1-671013feea0b@cs.ucla.edu/
diff --git a/src/regex.h b/src/regex-emacs.h
similarity index 98%
rename from src/regex.h
rename to src/regex-emacs.h
index 3a2d74d86a..8a15e5793f 100644

Checking patch src/regex.h => src/regex-emacs.h...
Applied patch src/regex.h => src/regex-emacs.h cleanly.

skipping https://yhetil.org/emacs-bugs/20180717234729.15507-1-eggert@cs.ucla.edu/ for 8a15e5793f
skipping https://yhetil.org/emacs-bugs/15823bbe-8298-0d69-c7a6-edf2001e4513@cs.ucla.edu/ for 8a15e5793f
index at:
100644 8a15e5793fa97b1b3a109d30693eceec9f59bd0e	src/regex-emacs.h

applying [2/2] https://yhetil.org/emacs-bugs/d32f5409-cdf4-e0f9-76e1-671013feea0b@cs.ucla.edu/
diff --git a/src/regex-emacs.h b/src/regex-emacs.h
index 8a15e5793f..898c0f2aea 100644

Checking patch src/regex-emacs.h...
Applied patch src/regex-emacs.h cleanly.

skipping https://yhetil.org/emacs-bugs/15823bbe-8298-0d69-c7a6-edf2001e4513@cs.ucla.edu/ for 898c0f2aea
index at:
100644 898c0f2aea9bce45dc9d25a9530dd3ac79dc4bf9	src/regex-emacs.h

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).