summaryrefslogtreecommitdiff
path: root/lang/moscow_ml/files/patch-dynlibs__mregex__mregex.c
blob: aa1645c172cf3e6ba4be43ebe51dbbe60d104642 (plain) (blame)
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
--- dynlibs/mregex/mregex.c.orig	Fri Feb  6 13:35:06 2004
+++ dynlibs/mregex/mregex.c	Fri Feb  6 13:45:45 2004
@@ -7,7 +7,7 @@
 
 #include <stdlib.h>
 #include <sys/types.h>
-#include "regex-0.12/regex.h"
+#include <regex.h>
 
 /* Moscow ML specific includes: */
 
@@ -17,10 +17,6 @@
 #include <str.h>		/* For string_length                       */
 #include <fail.h>		/* For failwith                            */
 
-/* Special version of regexec, defined at the end of this file */
-
-int mosml_regexec();
-
 #ifdef WIN32
 #define EXTERNML __declspec(dllexport)
 #else
@@ -135,8 +131,7 @@
 value regmatch_sus(regex_t* preg, int nmatch, regmatch_t pmatch[], 
 		   int eflags, value susval) {
   char* str = susaddr_susval(susval);
-  int len = len_susval(susval);
-  int matcherror = mosml_regexec(preg, str, len, nmatch, pmatch, eflags);
+  int matcherror = regexec(preg, str, nmatch, pmatch, eflags);
   if (matcherror == 0) {
     /* Find actual number of named substrings */
     value res;
@@ -208,8 +203,7 @@
 
 value regmatch_bool(regex_t* preg, int eflags, value susval) {
   char* str = susaddr_susval(susval);
-  int len = len_susval(susval);
-  int matcherror = mosml_regexec(preg, str, len, 0, NULL, eflags | REG_NOSUB);
+  int matcherror = regexec(preg, str, 0, NULL, eflags);
   return Val_bool(matcherror == 0);
 }
 
@@ -278,86 +272,4 @@
   }
   /* Unreachable: */
   return Val_false;
-}
-
-/* This is copied from GNU regex-0.12 file regex.c, and renamed from
-   regexec to mosml_regexec.  The only change is that mosml_regexec
-   receives the (sub)string's length as an argument, and so avoids
-   calling strlen.  This dramatically speeds up the replace,
-   substitute, tokens, and fields functions in the Regex ML structure:
-   the asymptotic execution time changes from quadratic to linear.
-
-   It is pretty silly to have to copy the entire function just to
-   achieve this.  Superficially, the fault is with POSIX 1003.2 for
-   not accommodating searches in substrings of long strings.  More
-   fundamentally, C's notion of null-terminated string is lame: taking
-   time O(n) to determine the length of a string is damn poor.
-   
-   sestoft@dina.kvl.dk 
-*/
-
-typedef char boolean;
-#define false 0
-#define true 1
-#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
-
-int
-mosml_regexec (preg, string, len /* NEW */, nmatch, pmatch, eflags)
-    const regex_t *preg;
-    const char *string; 
-    int len;			/* NEW */
-    size_t nmatch; 
-    regmatch_t pmatch[]; 
-    int eflags;
-{
-  int ret;
-  struct re_registers regs;
-  regex_t private_preg;
-  boolean want_reg_info = !preg->no_sub && nmatch > 0;
-
-  private_preg = *preg;
-  
-  private_preg.not_bol = !!(eflags & REG_NOTBOL);
-  private_preg.not_eol = !!(eflags & REG_NOTEOL);
-  
-  /* The user has told us exactly how many registers to return
-     information about, via `nmatch'.  We have to pass that on to the
-     matching routines.  */
-  private_preg.regs_allocated = REGS_FIXED;
-  
-  if (want_reg_info)
-    {
-      regs.num_regs = nmatch;
-      regs.start = TALLOC (nmatch, regoff_t);
-      regs.end = TALLOC (nmatch, regoff_t);
-      if (regs.start == NULL || regs.end == NULL)
-        return (int) REG_NOMATCH;
-    }
-
-  /* Perform the searching operation.  */
-  ret = re_search (&private_preg, string, len,
-                   /* start: */ 0, /* range: */ len,
-                   want_reg_info ? &regs : (struct re_registers *) 0);
-  
-  /* Copy the register information to the POSIX structure.  */
-  if (want_reg_info)
-    {
-      if (ret >= 0)
-        {
-          unsigned r;
-
-          for (r = 0; r < nmatch; r++)
-            {
-              pmatch[r].rm_so = regs.start[r];
-              pmatch[r].rm_eo = regs.end[r];
-            }
-        }
-
-      /* If we needed the temporary register info, free the space now.  */
-      free (regs.start);
-      free (regs.end);
-    }
-
-  /* We want zero return to mean success, unlike `re_search'.  */
-  return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
 }