This is Unofficial EPICS BASE Doxygen Site
antelope.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 #include <signal.h>
10 #include "defs.h"
11 
12 /* Need this before the Com library can build it */
13 #ifdef EPICS_BUILD_DLL
14 # undef EPICS_BUILD_DLL
15 #endif
16 #ifdef EPICS_CALL_DLL
17 # undef EPICS_CALL_DLL
18 #endif
19 
20 #include "epicsTempFile.c"
21 
22 char dflag;
23 char lflag;
24 char rflag;
25 char tflag;
26 char vflag;
27 
29 char *file_prefix = "y";
30 char *myname = "yacc";
31 char *temp_form = "yacc.XXXXXXX";
32 
33 int lineno;
34 int outline;
35 
38 char *input_file_name = "";
41 
42 FILE *action_file; /* a temp file, used to save actions associated */
43  /* with rules until the parser is written */
44 FILE *code_file; /* y.code.c (used when the -r option is specified) */
45 FILE *defines_file; /* y.tab.h */
46 FILE *input_file; /* the input file */
47 FILE *output_file; /* y.tab.c */
48 FILE *text_file; /* a temp file, used to save text until all */
49  /* symbols have been defined */
50 FILE *union_file; /* a temp file, used to save the union */
51  /* definition until all symbol have been */
52  /* defined */
53 FILE *verbose_file; /* y.output */
54 
55 int nitems;
56 int nrules;
57 int nsyms;
58 int ntokens;
59 int nvars;
60 
62 char **symbol_name;
63 short *symbol_value;
64 short *symbol_prec;
66 
67 short *ritem;
68 short *rlhs;
69 short *rrhs;
70 short *rprec;
71 char *rassoc;
72 short **derives;
73 char *nullable;
74 
75 
76 void
77 done(int k)
78 {
79  if (action_file) { fclose(action_file); }
80  if (text_file) { fclose(text_file); }
81  if (union_file) { fclose(union_file); }
82  exit(k);
83 }
84 
85 
86 static void
87 onintr(int StupidInconsistantSignalTypes)
88 {
89  done(1);
90 }
91 
92 
93 static void
94 set_signals(void)
95 {
96 #ifdef SIGINT
97  if (signal(SIGINT, SIG_IGN) != SIG_IGN)
98  signal(SIGINT, onintr);
99 #endif
100 #ifdef SIGTERM
101  if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
102  signal(SIGTERM, onintr);
103 #endif
104 #ifdef SIGHUP
105  if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
106  signal(SIGHUP, onintr);
107 #endif
108 }
109 
110 
111 static void
112 usage(void)
113 {
114  fprintf(stderr, "usage: %s [-dlrtv] [-b file_prefix] [-p symbol_prefix] filename\n", myname);
115  exit(1);
116 }
117 
118 
119 static int
120 getargs(int argc, char *argv[])
121 {
122  int i;
123  char *s;
124 
125  if (argc > 0) {
126  myname = strrchr(argv[0], '/');
127  if (myname) myname++;
128  else myname = argv[0];
129  }
130  for (i = 1; i < argc; ++i)
131  {
132  s = argv[i];
133  if (*s != '-') break;
134  switch (*++s)
135  {
136  case '\0':
137  input_file = stdin;
138  if (i + 1 < argc) usage();
139  return(0);
140 
141  case '-':
142  ++i;
143  goto no_more_options;
144 
145  case 'b':
146  if (*++s)
147  file_prefix = s;
148  else if (++i < argc)
149  file_prefix = argv[i];
150  else
151  usage();
152  continue;
153 
154  case 'd':
155  dflag = 1;
156  break;
157 
158  case 'l':
159  lflag = 1;
160  break;
161 
162  case 'p':
163  if (*++s)
164  symbol_prefix = s;
165  else if (++i < argc)
166  symbol_prefix = argv[i];
167  else
168  usage();
169  continue;
170 
171  case 'r':
172  rflag = 1;
173  break;
174 
175  case 't':
176  tflag = 1;
177  break;
178 
179  case 'v':
180  vflag = 1;
181  break;
182 
183  default:
184  usage();
185  }
186 
187  for (;;)
188  {
189  switch (*++s)
190  {
191  case '\0':
192  goto end_of_option;
193 
194  case 'd':
195  dflag = 1;
196  break;
197 
198  case 'l':
199  lflag = 1;
200  break;
201 
202  case 'r':
203  rflag = 1;
204  break;
205 
206  case 't':
207  tflag = 1;
208  break;
209 
210  case 'v':
211  vflag = 1;
212  break;
213 
214  default:
215  usage();
216  }
217  }
218 end_of_option:;
219  }
220 
221 no_more_options:;
222  if (i + 1 != argc) usage();
223  input_file_name = argv[i];
224 
225  return(0);
226 }
227 
228 
229 char *
230 allocate(unsigned int n)
231 {
232  char *p;
233 
234  p = NULL;
235  if (n)
236  {
237  p = CALLOC(1, n);
238  if (!p) no_space();
239  }
240  return (p);
241 }
242 
243 
244 static void
245 create_file_names(void)
246 {
247  int len;
248 
249  len = strlen(file_prefix);
250 
251  output_file_name = MALLOC(len + 7);
252  if (output_file_name == 0)
253  no_space();
254  strcpy(output_file_name, file_prefix);
255  strcpy(output_file_name + len, OUTPUT_SUFFIX);
256 
257  if (rflag)
258  {
259  code_file_name = MALLOC(len + 8);
260  if (code_file_name == 0)
261  no_space();
262  strcpy(code_file_name, file_prefix);
263  strcpy(code_file_name + len, CODE_SUFFIX);
264  }
265  else
267 
268  if (dflag)
269  {
270  defines_file_name = MALLOC(len + 7);
271  if (defines_file_name == 0)
272  no_space();
274  strcpy(defines_file_name + len, DEFINES_SUFFIX);
275  }
276 
277  if (vflag)
278  {
279  verbose_file_name = MALLOC(len + 8);
280  if (verbose_file_name == 0)
281  no_space();
283  strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
284  }
285 }
286 
287 
288 static void
289 open_files(void)
290 {
291  create_file_names();
292 
293  if (input_file == 0)
294  {
295  input_file = fopen(input_file_name, "r");
296  if (input_file == 0)
298  }
299 
301  if (action_file == 0)
302  open_error("temp action file");
303 
305  if (text_file == 0)
306  open_error("temp text file");
307 
308  if (vflag)
309  {
310  verbose_file = fopen(verbose_file_name, "w");
311  if (verbose_file == 0)
313  }
314 
315  if (dflag)
316  {
317  defines_file = fopen(defines_file_name, "w");
318  if (defines_file == 0)
321  if (union_file == 0)
322  open_error("temp union file");
323  }
324 
325  output_file = fopen(output_file_name, "w");
326  if (output_file == 0)
328 
329  if (rflag)
330  {
331  code_file = fopen(code_file_name, "w");
332  if (code_file == 0)
334  }
335  else
337 }
338 
339 
340 int
341 main(int argc, char *argv[])
342 {
343  set_signals();
344  getargs(argc, argv);
345  open_files();
346  reader();
347  lr0();
348  lalr();
349  make_parser();
350  verbose();
351  output();
352  done(0);
353  /*NOTREACHED*/
354 }
#define VERBOSE_SUFFIX
Definition: defs.h:59
void output(void)
Definition: output.c:51
FILE * verbose_file
Definition: antelope.c:53
FILE * union_file
Definition: antelope.c:50
char * verbose_file_name
Definition: antelope.c:40
#define OUTPUT_SUFFIX
Definition: defs.h:58
#define MALLOC(n)
Definition: defs.h:111
int lineno
Definition: antelope.c:33
int i
Definition: scan.c:967
LIBCOM_API FILE *epicsStdCall epicsTempFile(void)
Create and open a temporary file.
Definition: epicsTempFile.c:15
void open_error(char *filename) NORETURN
Definition: error.c:31
void lr0(void)
Definition: lr0.c:608
short * rlhs
Definition: antelope.c:68
int main(int argc, char *argv[])
Definition: antelope.c:341
FILE * code_file
Definition: antelope.c:44
char * rassoc
Definition: antelope.c:71
#define NULL
Definition: catime.c:38
int nrules
Definition: antelope.c:56
int nitems
Definition: antelope.c:55
FILE * defines_file
Definition: antelope.c:45
int nsyms
Definition: antelope.c:57
int nvars
Definition: antelope.c:59
FILE * text_file
Definition: antelope.c:48
char dflag
Definition: antelope.c:22
short * symbol_value
Definition: antelope.c:63
char * nullable
Definition: antelope.c:73
#define CALLOC(k, n)
Definition: defs.h:109
short ** derives
Definition: antelope.c:72
char * myname
Definition: antelope.c:30
char * allocate(unsigned int n)
Definition: antelope.c:230
short * ritem
Definition: antelope.c:67
short * symbol_prec
Definition: antelope.c:64
char rflag
Definition: antelope.c:24
char * code_file_name
Definition: antelope.c:36
void make_parser(void)
Definition: mkpar.c:37
char * defines_file_name
Definition: antelope.c:37
char * temp_form
Definition: antelope.c:31
int start_symbol
Definition: antelope.c:61
char tflag
Definition: antelope.c:25
short * rrhs
Definition: antelope.c:69
#define stdin
Definition: epicsStdio.h:28
void reader(void)
Definition: reader.c:1791
void done(int k)
Definition: antelope.c:77
char vflag
Definition: antelope.c:26
void verbose(void)
Definition: verbose.c:27
FILE * output_file
Definition: antelope.c:47
FILE * action_file
Definition: antelope.c:42
int ntokens
Definition: antelope.c:58
char * symbol_assoc
Definition: antelope.c:65
#define stderr
Definition: epicsStdio.h:32
char * file_prefix
Definition: antelope.c:29
char ** symbol_name
Definition: antelope.c:62
char * output_file_name
Definition: antelope.c:39
void no_space(void) NORETURN
Definition: error.c:23
short * rprec
Definition: antelope.c:70
char lflag
Definition: antelope.c:23
#define CODE_SUFFIX
Definition: defs.h:56
void usage(void)
Definition: cainfo.c:36
void lalr(void)
Definition: lalr.c:60
char * input_file_name
Definition: antelope.c:38
char * symbol_prefix
Definition: antelope.c:28
#define DEFINES_SUFFIX
Definition: defs.h:57
int outline
Definition: antelope.c:34
FILE * input_file
Definition: antelope.c:46