1
2%{
3#include "wisebase.h"
4
5#define CodeLISTLENGTH 128
6#define InputLISTLENGTH 16
7%}
8
9
10
11struct Code
12char ** lines !list
13
14struct InDeclare
15char * name;
16char * type;
17
18struct InRequire
19char * name
20char * type
21char * help
22char * tag
23
24struct Input
25InDeclare ** decl !list !len="decl_"
26InRequire ** req  !list !len="req_"
27Code * code;
28
29%{
30
31#include "input.h"
32
33
34Input * read_Input_line(char * line,FILE * ifp)
35{
36  Input * out;
37  InRequire * re;
38  InDeclare * de;
39  char buffer[MAXLINE];
40
41  out = Input_alloc_std();
42
43  while( fgets(buffer,MAXLINE,ifp) != NULL ) {
44    if( strwhitestartcmp(buffer,"#",spacestr) == 0 )
45      continue;
46
47    if( strstartcmp(buffer,"declare") == 0 ) {
48      de = InDeclare_from_line(buffer);
49      if( de != NULL ) {
50	add_decl_Input(out,de);
51      } else {
52	warn("Unreadable declaration line in input");
53      }
54    } else if ( strstartcmp(buffer,"require") == 0 ) {
55      re = InRequire_from_line(buffer);
56      if( re != NULL ) {
57	add_req_Input(out,re);
58      } else {
59	warn("Unreadable require line in input");
60      }
61    } else if ( strstartcmp(buffer,"code") == 0 ) {
62      if( out->code != NULL ) {
63	warn("Two code segments in an input!");
64	out->code = free_Code(out->code);
65      }
66      out->code = read_Code_line(buffer,ifp);
67    } else {
68      warn("Could not understand line %s in input specification",buffer);
69    }
70  }
71
72  return out;
73}
74
75Code * read_Code_line(char * line,FILE * ifp)
76{
77  char buffer[MAXLINE];
78  Code * out;
79
80  out = Code_alloc_std();
81
82  while( fgets(buffer,MAXLINE,ifp) != NULL ) {
83    if( strstartcmp(buffer,"endcode") == 0 )
84      break;
85
86  }
87
88
89  return out;
90}
91
92InRequire * InRequire_from_line(char * line)
93{
94  InRequire * out;
95  int i;
96  char ** base;
97  char ** brk;
98
99
100  base = brk = breakstring(line,spacestr);
101  if( *brk == NULL || strcmp(*brk,"require") == 0 ) {
102    warn("In require - no require line!");
103  }
104  for(i=1;i<5;i++) {
105    if( brk[i] == NULL ) {
106      warn("wrong number of arguments for require line [%s]",line);
107      return NULL;
108    }
109  }
110
111  out = InRequire_alloc();
112
113  out->name = stringalloc(brk[1]);
114  out->type = stringalloc(brk[2]);
115  strip_quote_chars(brk[3],"\"");
116  out->help = stringalloc(brk[3]);
117  out->tag  = stringalloc(brk[4]);
118
119  ckfree(base);
120  return out;
121}
122
123InDeclare * InDeclare_from_line(char * line)
124{
125  InDeclare * out;
126  char * runner;
127  char * name;
128  char * type;
129
130
131  runner = strtok(line,spacestr);
132  if( strcmp(runner,"declare") != 0 ) {
133    warn("You don't have a declaration line in %s",line);
134    return NULL;
135  }
136  name = strtok(NULL,spacestr);
137  type = strtok(NULL,spacestr);
138
139  if( type == NULL ) {
140    warn("In reading the line %s, we have no type. format problem",line);
141    return NULL;
142  }
143
144  out = InDeclare_alloc();
145  out->name = stringalloc(name);
146  out->type = stringalloc(type);
147
148  return out;
149}
150
151
152
153
154