View | Details | Raw Unified | Return to bug 8314
Collapse All | Expand All

(-)../mawk-1.3.3-orig/configure.in (+11 lines)
Lines 32-41 Link Here
32
dnl
32
dnl
33
AC_INIT(mawk.h)
33
AC_INIT(mawk.h)
34
builtin(include,mawk.ac.m4)
34
builtin(include,mawk.ac.m4)
35
35
GET_USER_DEFAULTS
36
GET_USER_DEFAULTS
36
PROG_CC_NO_MINUS_G_NONSENSE
37
PROG_CC_NO_MINUS_G_NONSENSE
37
AC_PROG_CPP
38
AC_PROG_CPP
38
NOTSET_THEN_DEFAULT(CFLAGS,-O)
39
NOTSET_THEN_DEFAULT(CFLAGS,-O)
40
41
AC_ARG_WITH(local-regexp,
42
[  --with-local-regexp             use the mawk's regexp engine],
43
[
44
if test "x${withval}" = xyes; then
45
    CFLAGS="$CFLAGS -DLOCAL_REGEXP"
46
fi
47
])
48
39
LOOK_FOR_MATH_LIBRARY
49
LOOK_FOR_MATH_LIBRARY
40
WHICH_YACC
50
WHICH_YACC
41
COMPILER_ATTRIBUTES
51
COMPILER_ATTRIBUTES
Lines 45-49 Link Here
45
FPRINTF_IN_STDIO
55
FPRINTF_IN_STDIO
46
FIND_OR_COMPUTE_MAX__INT
56
FIND_OR_COMPUTE_MAX__INT
47
DREADED_FPE_TESTS
57
DREADED_FPE_TESTS
58
48
DO_CONFIG_H
59
DO_CONFIG_H
49
AC_OUTPUT(Makefile)
60
AC_OUTPUT(Makefile)
(-)../mawk-1.3.3-orig/main.c (-1 / +16 lines)
Lines 44-49 Link Here
44
44
45
/*  main.c  */
45
/*  main.c  */
46
46
47
#ifndef LOCAL_REGEXP
48
#		include <locale.h>
49
#endif
50
47
#include "mawk.h"
51
#include "mawk.h"
48
#include "init.h"
52
#include "init.h"
49
#include "code.h"
53
#include "code.h"
Lines 53-63 Link Here
53
short mawk_state ;		 /* 0 is compiling */
57
short mawk_state ;		 /* 0 is compiling */
54
int exit_code ;
58
int exit_code ;
55
59
60
static void initialize_locale (void)
61
{
62
#ifndef LOCAL_REGEXP
63
   setlocale(LC_CTYPE, "");
64
   setlocale(LC_COLLATE, "");
65
   setlocale(LC_MESSAGES, "");
66
   setlocale(LC_NUMERIC, "C");
67
   setlocale(LC_TIME, "");
68
#endif
69
}
70
56
int
71
int
57
main(argc, argv)
72
main(argc, argv)
58
int argc ; char **argv ;
73
int argc ; char **argv ;
59
{
74
{
60
75
   initialize_locale ();
61
   initialize(argc, argv) ;
76
   initialize(argc, argv) ;
62
77
63
   parse() ;
78
   parse() ;
(-)../mawk-1.3.3-orig/Makefile.in (-8 / +4 lines)
Lines 6-12 Link Here
6
CC = @CC@
6
CC = @CC@
7
7
8
CFLAGS =   @CFLAGS@
8
CFLAGS =   @CFLAGS@
9
9
LDFLAGS = @LDFLAGS@
10
MATHLIB = @MATHLIB@
10
MATHLIB = @MATHLIB@
11
11
12
YACC = @YACC@ 
12
YACC = @YACC@ 
Lines 25-41 Link Here
25
  fin.o files.o  scancode.o matherr.o  fcall.o version.o\
25
  fin.o files.o  scancode.o matherr.o  fcall.o version.o\
26
  missing.o
26
  missing.o
27
27
28
REXP_O=rexp/rexp.o rexp/rexp0.o rexp/rexp1.o rexp/rexp2.o\
28
REXP_O=rexp/regexp.o
29
    rexp/rexp3.o 
29
REXP_C=rexp/regexp.c
30
31
REXP_C=rexp/rexp.c rexp/rexp0.c rexp/rexp1.c rexp/rexp2.c\
32
    rexp/rexp3.c 
33
34
30
35
mawk_and_test :  mawk  mawk_test  fpe_test
31
mawk_and_test :  mawk  mawk_test  fpe_test
36
32
37
mawk : $(O)  rexp/.done
33
mawk : $(O)  rexp/.done
38
	$(CC) $(CFLAGS) -o mawk $(O) $(REXP_O) $(MATHLIB) 
34
	$(CC) $(LDFLAGS) -o mawk $(O) $(REXP_O) $(MATHLIB) 
39
35
40
mawk_test :  mawk  # test that we have a sane mawk
36
mawk_test :  mawk  # test that we have a sane mawk
41
	@cp mawk test/mawk
37
	@cp mawk test/mawk
(-)../mawk-1.3.3-orig/re_cmpl.c (-2 / +2 lines)
Lines 102-111 Link Here
102
   if (!(p->re = REcompile(s)))
102
   if (!(p->re = REcompile(s)))
103
   {
103
   {
104
      if (mawk_state == EXECUTION)
104
      if (mawk_state == EXECUTION)
105
	 rt_error(efmt, REerrlist[REerrno], s) ;
105
	 rt_error(efmt, REerror (), s) ;
106
      else  /* compiling */
106
      else  /* compiling */
107
      {
107
      {
108
	 compile_error(efmt, REerrlist[REerrno], s) ;
108
	 compile_error(efmt, REerror(), s) ;
109
	 return (PTR) 0 ;
109
	 return (PTR) 0 ;
110
      }
110
      }
111
   }
111
   }
(-)../mawk-1.3.3-orig/regexp.h (-5 / +1 lines)
Lines 25-32 Link Here
25
int   PROTO( REtest, (char *, PTR) ) ;
25
int   PROTO( REtest, (char *, PTR) ) ;
26
char *PROTO( REmatch, (char *, PTR, unsigned *) ) ;
26
char *PROTO( REmatch, (char *, PTR, unsigned *) ) ;
27
void  PROTO( REmprint, (PTR , FILE*) ) ;
27
void  PROTO( REmprint, (PTR , FILE*) ) ;
28
28
char *PROTO( REerror, (void)) ;
29
extern  int  REerrno ;
30
extern  char *REerrlist[] ;
31
32
(-)../mawk-1.3.3-orig/rexp/Makefile (-2 / +2 lines)
Lines 9-16 Link Here
9
CC = cc
9
CC = cc
10
CFLAGS = -O  -DMAWK -I..
10
CFLAGS = -O  -DMAWK -I..
11
11
12
O=rexp.o rexp0.o rexp1.o rexp2.o rexp3.o 
12
O=regexp.o
13
DB=rexpdb.o
13
DB=
14
14
15
all : $(O)
15
all : $(O)
16
	@cat </dev/null > .done
16
	@cat </dev/null > .done
(-)../mawk-1.3.3-orig/rexp/regexp.c (+12 lines)
Line 0 Link Here
1
#ifdef LOCAL_REGEXP
2
#		include "rexp.c"
3
#		include "rexp0.c"
4
#		include "rexp1.c"
5
#		include "rexp2.c"
6
#		include "rexp3.c"
7
#		include "rexp4.c"
8
#		include "rexpdb.c"
9
#else
10
#		include "rexp4.c"
11
#		include "regexp_system.c"
12
#endif
(-)../mawk-1.3.3-orig/rexp/regexp_system.c (+140 lines)
Line 0 Link Here
1
#include <sys/types.h>
2
#include <stdio.h>
3
#include <regex.h>
4
#include <string.h>
5
#include <stdlib.h>
6
#include <errno.h>
7
8
typedef struct {
9
   regex_t re;
10
   char *regexp;
11
} mawk_re_t;
12
13
static mawk_re_t *last_used_regexp = NULL;
14
static int err_code = 0;
15
16
void prepare_regexp (regexp)
17
   char *regexp;
18
{
19
   int bs = 0;
20
   char *tail = regexp;
21
   char ch;
22
23
   while ((ch = *regexp++) != 0){
24
      if (bs){
25
	 switch (ch){
26
	 case 'n': *tail++ = '\n';   break;
27
	 case 't': *tail++ = '\t';   break;
28
	 case 'f': *tail++ = '\f';   break;
29
	 case 'b': *tail++ = '\b';   break;
30
	 case 'r': *tail++ = '\r';   break;
31
	 case 'a': *tail++ = '\07';  break;
32
	 case 'v': *tail++ = '\013'; break;
33
	 default:  *tail++ = '\\'; *tail++ = ch;
34
	 }
35
36
	 bs = 0;
37
      }else{
38
	 if (ch == '\\'){
39
	    bs = 1;
40
	 }else{
41
	    *tail++ = ch;
42
	 }
43
      }
44
   }
45
46
   *tail = 0;
47
}
48
49
void * REcompile(regexp)
50
   char *regexp;
51
{
52
   mawk_re_t *re = (mawk_re_t*) malloc (sizeof (mawk_re_t));
53
   size_t len = strlen (regexp);
54
   char *new_regexp = (char *) malloc (len + 3);
55
/*   fprintf (stderr, "REcompile: %s\n", regexp); */
56
57
   if (!re || !new_regexp)
58
      return NULL;
59
60
   new_regexp [0] = '(';
61
   memcpy (new_regexp + 1, regexp, len);
62
   new_regexp [len+1] = ')';
63
   new_regexp [len+2] = 0;
64
65
   prepare_regexp (new_regexp);
66
67
   last_used_regexp = re;
68
69
   memset (re, 0, sizeof (mawk_re_t));
70
   re -> regexp = strdup (new_regexp);
71
   err_code = regcomp (&re->re, new_regexp, REG_EXTENDED | REG_NEWLINE);
72
73
   free (new_regexp);
74
75
   if (err_code)
76
      return NULL;
77
78
   return re;
79
}
80
81
int
82
REtest(str, re)
83
   char *str ;
84
   mawk_re_t* re ;
85
{
86
/*   fprintf (stderr, "REtest: \"%s\" ~ /%s/", str, re -> regexp); */
87
88
   last_used_regexp = re;
89
90
   if (regexec (&re->re, str, 0, NULL, 0)){
91
/*      fprintf (stderr, "=1\n"); */
92
      return 0;
93
   }else{
94
/*      fprintf (stderr, "=0\n"); */
95
      return 1;
96
   }
97
}
98
99
char *REmatch(str, re, lenp)
100
   char *str ;
101
   mawk_re_t* re ;
102
   unsigned *lenp ;
103
{
104
   regmatch_t match [100];
105
/*   fprintf (stderr, "REmatch: \"%s\" ~ /%s/", str, re -> regexp); */
106
107
   last_used_regexp = re;
108
109
   if (!regexec (&re->re, str, 100, match, 0)){
110
      *lenp = match [0].rm_eo - match[0].rm_so;
111
/*      fprintf (stderr, "=%i/%i\n", match [0].rm_so, *lenp); */
112
      return str + match [0].rm_so;
113
   }else{
114
/*      fprintf (stderr, "=0\n"); */
115
      return NULL;
116
   }
117
}
118
119
void  REmprint(m, f)
120
  void * m ; 
121
  FILE *f ;
122
{
123
   /* no debugging code available */
124
   abort ();
125
}
126
127
static char error_buffer [2048];
128
129
char *REerror ()
130
{
131
   size_t len;
132
   if (last_used_regexp){
133
      len = regerror (err_code, &last_used_regexp -> re,
134
		      error_buffer, sizeof (error_buffer));
135
      return error_buffer;
136
   }else{
137
      snprintf (error_buffer, sizeof (error_buffer), "malloc failed: %s",
138
		strerror (errno));
139
   }
140
}
(-)../mawk-1.3.3-orig/rexp/rexp2.c (-12 lines)
Lines 318-335 Link Here
318
318
319
#ifdef	MAWK
319
#ifdef	MAWK
320
320
321
char *
322
is_string_split(p, lenp)
323
   register STATE *p ;
324
   unsigned *lenp ;
325
{
326
   if (p[0].type == M_STR && p[1].type == M_ACCEPT)
327
   {
328
      *lenp = p->len ;
329
      return p->data.str ;
330
   }
331
   else	 return (char *) 0 ;
332
}
333
#else /* mawk provides its own str_str */
321
#else /* mawk provides its own str_str */
334
322
335
char *
323
char *
(-)../mawk-1.3.3-orig/rexp/rexp4.c (+14 lines)
Line 0 Link Here
1
#include "rexp.h"
2
3
char *
4
is_string_split(p, lenp)
5
   register STATE *p ;
6
   unsigned *lenp ;
7
{
8
   if (p[0].type == M_STR && p[1].type == M_ACCEPT)
9
   {
10
      *lenp = p->len ;
11
      return p->data.str ;
12
   }
13
   else	 return (char *) 0 ;
14
}
(-)../mawk-1.3.3-orig/rexp/rexp.c (+6 lines)
Lines 236-238 Link Here
236
   fprintf(stderr, "REcompile() - panic:  %s\n", s) ;
236
   fprintf(stderr, "REcompile() - panic:  %s\n", s) ;
237
   exit(100) ;
237
   exit(100) ;
238
}
238
}
239
240
/* getting regexp error message */
241
char *REerror (void)
242
{
243
   return REerrlist [REerrno];
244
}
(-)../mawk-1.3.3-orig/test/mawktest (-8 / +8 lines)
Lines 22-37 Link Here
22
echo
22
echo
23
echo testing input and field splitting
23
echo testing input and field splitting
24
24
25
mawk -f wc.awk $dat | cmp -s - wc-awk.out || exit
25
LC_ALL=C mawk -f wc.awk $dat | cmp -s - wc-awk.out || exit
26
26
27
echo input and field splitting OK
27
echo input and field splitting OK
28
#####################################
28
#####################################
29
29
30
echo
30
echo
31
echo testing regular expression matching
31
echo testing regular expression matching
32
mawk -f reg0.awk $dat > temp$$
32
LC_ALL=C mawk -f reg0.awk $dat > temp$$
33
mawk -f reg1.awk $dat >> temp$$
33
LC_ALL=C mawk -f reg1.awk $dat >> temp$$
34
mawk -f reg2.awk $dat >> temp$$
34
LC_ALL=C mawk -f reg2.awk $dat >> temp$$
35
35
36
cmp -s  reg-awk.out temp$$ || exit
36
cmp -s  reg-awk.out temp$$ || exit
37
37
Lines 42-51 Link Here
42
if [ -c /dev/full ]; then
42
if [ -c /dev/full ]; then
43
    echo testing checking for write errors
43
    echo testing checking for write errors
44
    # Check for write errors noticed when closing the file
44
    # Check for write errors noticed when closing the file
45
    mawk '{print}' <full-awk.dat >/dev/full 2>/dev/null && exit
45
    LC_ALL=C mawk '{print}' <full-awk.dat >/dev/full 2>/dev/null && exit
46
    # Check for write errors noticed on writing
46
    # Check for write errors noticed on writing
47
    # The file has to be bigger than the buffer size of the libc
47
    # The file has to be bigger than the buffer size of the libc
48
    mawk '{print}' <../scan.c >/dev/full 2>/dev/null && exit
48
    LC_ALL=C mawk '{print}' <../scan.c >/dev/full 2>/dev/null && exit
49
49
50
    echo checking for write errors OK
50
    echo checking for write errors OK
51
else
51
else
Lines 57-63 Link Here
57
echo
57
echo
58
echo testing arrays and flow of control
58
echo testing arrays and flow of control
59
59
60
mawk -f wfrq0.awk $dat | cmp -s - wfrq-awk.out || exit
60
LC_ALL=C mawk -f wfrq0.awk $dat | cmp -s - wfrq-awk.out || exit
61
61
62
echo array test OK
62
echo array test OK
63
#################################
63
#################################
Lines 65-71 Link Here
65
echo
65
echo
66
echo testing function calls and general stress test
66
echo testing function calls and general stress test
67
67
68
mawk -f ../examples/decl.awk $dat | cmp -s - decl-awk.out || exit 
68
LC_ALL=C mawk -f ../examples/decl.awk $dat | cmp -s - decl-awk.out || exit 
69
69
70
echo general stress test passed
70
echo general stress test passed
71
71

Return to bug 8314