]> code.delx.au - gnu-emacs/blobdiff - src/regex.c
Port documentation to Texinfo 5.0.
[gnu-emacs] / src / regex.c
index 751006d57ba2fbdfda0796c057ed1cf1e5c91163..9c1cd937e5bd7bc53093335897fac602888ea1ee 100644 (file)
@@ -2,7 +2,7 @@
    0.12.  (Implements POSIX draft P1003.2/D11.2, except for some of the
    internationalization features.)
 
-   Copyright (C) 1993-201 Free Software Foundation, Inc.
+   Copyright (C) 1993-2013 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
@@ -15,9 +15,7 @@
    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, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-   USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* TODO:
    - structure the opcode space into opcode+flag.
    that make sense only in Emacs. */
 #ifdef emacs
 
-# include <setjmp.h>
 # include "lisp.h"
 # include "character.h"
 # include "buffer.h"
@@ -248,6 +245,7 @@ xrealloc (void *block, size_t size)
 # endif
 # define realloc xrealloc
 
+# include <stdbool.h>
 # include <string.h>
 
 /* Define the syntax stuff for \<, \>, etc.  */
@@ -255,8 +253,6 @@ xrealloc (void *block, size_t size)
 /* Sword must be nonzero for the wordchar pattern commands in re_match_2.  */
 enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 };
 
-#  define SWITCH_ENUM_CAST(x) (x)
-
 /* Dummy macros for non-Emacs environments.  */
 # define CHAR_CHARSET(c) 0
 # define CHARSET_LEADING_CODE_BASE(c) 0
@@ -537,8 +533,6 @@ typedef const unsigned char re_char;
 #endif
 
 typedef char boolean;
-#define false 0
-#define true 1
 
 static regoff_t re_match_2_internal (struct re_pattern_buffer *bufp,
                                     re_char *string1, size_t size1,
@@ -1739,20 +1733,6 @@ static int analyse_first (re_char *p, re_char *pend,
    be too small, many things would have to change.  */
 # define MAX_BUF_SIZE (1L << 15)
 
-#if 0  /* This is when we thought it could be 2^16 bytes.  */
-/* Any other compiler which, like MSC, has allocation limit below 2^16
-   bytes will have to use approach similar to what was done below for
-   MSC and drop MAX_BUF_SIZE a bit.  Otherwise you may end up
-   reallocating to 0 bytes.  Such thing is not going to work too well.
-   You have been warned!!  */
-#if defined _MSC_VER  && !defined WIN32
-/* Microsoft C 16-bit versions limit malloc to approx 65512 bytes.  */
-# define MAX_BUF_SIZE  65500L
-#else
-# define MAX_BUF_SIZE (1L << 16)
-#endif
-#endif /* 0 */
-
 /* Extend the buffer by twice its current size via realloc and
    reset the pointers that pointed into the old block to point to the
    correct places in the new one.  If extending the buffer results in it
@@ -1849,10 +1829,9 @@ typedef struct
 /* The next available element.  */
 #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
 
-/* Explicit quit checking is only used on NTemacs and whenever we
-   use polling to process input events.  */
-#if defined emacs && (defined WINDOWSNT || defined SYNC_INPUT) && defined QUIT
-extern int immediate_quit;
+/* Explicit quit checking is needed for Emacs, which uses polling to
+   process input events.  */
+#ifdef emacs
 # define IMMEDIATE_QUIT_CHECK                  \
     do {                                       \
       if (immediate_quit) QUIT;                        \
@@ -3927,7 +3906,7 @@ analyse_first (const re_char *p, const re_char *pend, char *fastmap, const int m
         as used for the *? operator.  */
       re_char *p1 = p;
 
-      switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
+      switch (*p++)
        {
        case succeed:
          return 1;
@@ -4102,7 +4081,7 @@ analyse_first (const re_char *p, const re_char *pend, char *fastmap, const int m
               visited.  `re_compile' should make sure this is true.  */
            break;
          p += j;
-         switch (SWITCH_ENUM_CAST ((re_opcode_t) *p))
+         switch (*p)
            {
            case on_failure_jump:
            case on_failure_keep_string_jump:
@@ -4635,7 +4614,7 @@ static int bcmp_translate (re_char *s1, re_char *s2,
 static re_char *
 skip_one_char (const re_char *p)
 {
-  switch (SWITCH_ENUM_CAST (*p++))
+  switch (*p++)
     {
     case anychar:
       break;
@@ -4680,7 +4659,7 @@ skip_noops (const re_char *p, const re_char *pend)
   int mcnt;
   while (p < pend)
     {
-      switch (SWITCH_ENUM_CAST ((re_opcode_t) *p))
+      switch (*p)
        {
        case start_memory:
        case stop_memory:
@@ -4725,7 +4704,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
 
   op2 = p2 == pend ? succeed : *p2;
 
-  switch (SWITCH_ENUM_CAST (op2))
+  switch (op2)
     {
     case succeed:
     case endbuf:
@@ -4849,7 +4828,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
       break;
 
     case charset_not:
-      switch (SWITCH_ENUM_CAST (*p1))
+      switch (*p1)
        {
        case exactn:
        case charset:
@@ -5327,7 +5306,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
        }
 
       /* Otherwise match next pattern command.  */
-      switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
+      switch (*p++)
        {
        /* Ignore these.  Used to ignore the n of succeed_n's which
           currently have n == 0.  */
@@ -6249,7 +6228,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
          /* A restart point is known.  Restore to that state.  */
          DEBUG_PRINT1 ("\nFAIL:\n");
          POP_FAILURE_POINT (str, pat);
-         switch (SWITCH_ENUM_CAST ((re_opcode_t) *pat++))
+         switch (*pat++)
            {
            case on_failure_keep_string_jump:
              assert (str == NULL);
@@ -6644,7 +6623,7 @@ regerror (int err_code, const regex_t *preg, char *errbuf, size_t errbuf_size)
     {
       if (msg_size > errbuf_size)
        {
-         strncpy (errbuf, msg, errbuf_size - 1);
+         memcpy (errbuf, msg, errbuf_size - 1);
          errbuf[errbuf_size - 1] = 0;
        }
       else