aboutsummaryrefslogtreecommitdiffstats
path: root/devel/lemon/files/patch-aa
blob: aa7da97bbca21508fd5551a331897c51a79f5696 (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
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
212
--- lemon.c Tue Dec  5 20:52:24 2000
+++ lemon.c Mon Jul 14 18:43:15 2003
@@ -27,13 +27,14 @@
 */
 #include <stdio.h>
-#include <varargs.h>
+#include <stdarg.h>
 #include <string.h>
 #include <ctype.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/param.h>
 
 extern void qsort();
 extern double strtod();
 extern long strtol();
-extern void free();
-extern int access();
 extern int atoi();
 
@@ -54,5 +55,4 @@
 
 char *msort();
-extern void *malloc();
 
 /******** From the file "action.h" *************************************/
@@ -90,5 +90,5 @@
 
 /********* From the file "error.h" ***************************************/
-void ErrorMsg( /* char *, int, char *, ... */ );
+static void ErrorMsg(const char *, int, const char *, ... );
 
 /****** From the file "option.h" ******************************************/
@@ -1109,10 +1109,7 @@
 #define LINEWIDTH      79 /* Max width of any output line */
 #define PREFIXLIMIT    30 /* Max width of the prefix on each line */
-void ErrorMsg(va_alist)
-va_dcl
+static void
+ErrorMsg(const char *filename, int lineno, const char *format, ...)
 {
-  char *filename;
-  int lineno;
-  char *format;
   char errmsg[ERRMSGSIZE];
   char prefix[PREFIXLIMIT+10];
@@ -1123,8 +1120,5 @@
   int end, restart, base;
 
-  va_start(ap);
-  filename = va_arg(ap,char*);
-  lineno = va_arg(ap,int);
-  format = va_arg(ap,char*);
+  va_start(ap, format);
   /* Prepare a prefix to be prepended to every output line */
   if( lineno>0 ){
@@ -1168,4 +1162,26 @@
 }
 
+static char *lempar_locations[] = {
+   NULL, "lempar.c", LEMPAR
+};
+
+void setlempar(lempar)
+char *lempar;
+{
+   if (access(lempar, R_OK)) {
+       perror(lempar);
+       exit(1);
+   }
+   lempar_locations[0] = lempar;
+}
+
+static char *output_file = NULL;
+
+void setoutput(base)
+char *base;
+{
+   if (output_file = malloc(strlen(base) + 1))
+       sprintf(output_file, "%s.", base);
+}
 
 /* The main program.  Parse the command line and do it... */
@@ -1185,7 +1201,12 @@
     {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
     {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
-    {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file"},
+    {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
+    {OPT_FSTR, "o", (char*)setoutput, "Set the dirname/basename for the "
+               "output file(s)."},
     {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
     {OPT_FLAG, "s", (char*)&statistics, "Print parser stats to standard output."},
+    {OPT_FSTR, "t", (char*)setlempar, "An alternative template -- instead of"
+               " ``./lempar.c''\n\t\tor the system wide ``"
+               LEMPAR"''."},
     {OPT_FLAG, "x", (char*)&version, "Print the version number."},
     {OPT_FLAG,0,0,0}
@@ -2305,4 +2326,5 @@
   }
 }
+
 /*********************** From the file "report.c" **************************/
 /*
@@ -2318,13 +2340,14 @@
 char *suffix;
 {
-  char *name;
-  char *cp;
+  char *name = NULL;
+  char *cp, *fname;
 
-  name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 );
+  fname = output_file ? output_file : lemp->filename;
+  name = malloc( strlen(fname) + strlen(suffix));
   if( name==0 ){
     fprintf(stderr,"Can't allocate space for a filename.\n");
     exit(1);
   }
-  strcpy(name,lemp->filename);
+  strcpy(name, fname);
   cp = strrchr(name,'.');
   if( cp ) *cp = 0;
@@ -2524,47 +2547,14 @@
 }
 
-/* Search for the file "name" which is in the same directory as
-** the exacutable */
-PRIVATE char *pathsearch(argv0,name,modemask)
-char *argv0;
-char *name;
-int modemask;
+PRIVATE const char *pathsearch()
 {
-  char *pathlist;
-  char *path,*cp;
-  char c;
-  extern int access();
+  int i;
+  const char *path = NULL;
 
-#ifdef __WIN32__
-  cp = strrchr(argv0,'\\');
-#else
-  cp = strrchr(argv0,'/');
-#endif
-  if( cp ){
-    c = *cp;
-    *cp = 0;
-    path = (char *)malloc( strlen(argv0) + strlen(name) + 2 );
-    if( path ) sprintf(path,"%s/%s",argv0,name);
-    *cp = c;
-  }else{
-    extern char *getenv();
-    pathlist = getenv("PATH");
-    if( pathlist==0 ) pathlist = ".:/bin:/usr/bin";
-    path = (char *)malloc( strlen(pathlist)+strlen(name)+2 );
-    if( path!=0 ){
-      while( *pathlist ){
-        cp = strchr(pathlist,':');
-        if( cp==0 ) cp = &pathlist[strlen(pathlist)];
-        c = *cp;
-        *cp = 0;
-        sprintf(path,"%s/%s",pathlist,name);
-        *cp = c;
-        if( c==0 ) pathlist = "";
-        else pathlist = &cp[1];
-        if( access(path,modemask)==0 ) break;
-      }
-    }
-  }
-  return path;
+  for (i = 0; i < sizeof(lempar_locations)/sizeof(char *); i++)
+    if (lempar_locations[i] && access(lempar_locations[i], R_OK) == 0)
+      return lempar_locations[i];
+
+  return(NULL);
 }
 
@@ -2630,8 +2620,7 @@
 struct lemon *lemp;
 {
-  static char templatename[] = "lempar.c";
-  char buf[1000];
+  char buf[MAXPATHLEN];
   FILE *in;
-  char *tpltname;
+  const char *tpltname;
   char *cp;
 
@@ -2642,12 +2631,11 @@
     sprintf(buf,"%s.lt",lemp->filename);
   }
-  if( access(buf,004)==0 ){
+  if( access(buf, R_OK)==0 ){
     tpltname = buf;
   }else{
-    tpltname = pathsearch(lemp->argv0,templatename,0);
+    tpltname = pathsearch();
   }
   if( tpltname==0 ){
-    fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
-    templatename);
+    fprintf(stderr,"Can't find the parser driver template file.\n");
     lemp->errorcnt++;
     return 0;
@@ -2655,5 +2643,5 @@
   in = fopen(tpltname,"r");
   if( in==0 ){
-    fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
+    fprintf(stderr,"Can't open the template file \"%s\".\n", tpltname);
     lemp->errorcnt++;
     return 0;