3
* Written by Sebastien Tricaud (c) 2008
4
* Part of the PicViz project
18
static char *filename;
19
static char *realfile;
21
void yyerror (char *s);
22
#if defined(__FreeBSD__) || defined(__APPLE__)
23
char* strndup(const char* string, size_t n)
25
char* copy_string = 0;
27
if(0 == string || 0 == n)
30
copy_string = (char*) malloc(n + 1);
34
memcpy(copy_string, string, n);
35
*(copy_string + n) = '\0';
40
char * strndup (const char *s, size_t n);
43
#define MAX_INCLUDE_DEPTH 10
44
YY_BUFFER_STATE includes[MAX_INCLUDE_DEPTH];
45
char *filenames[MAX_INCLUDE_DEPTH];
46
int includes_index = 0;
48
extern int axis_position;
50
static char *escape_str(char *str)
55
for ( i = 1; str[i]; i++ ) {
57
if ( ! escape_next && str[i] == '\\' ) {
71
void yyset_lineno(int line_number) {
72
yylineno = line_number;
87
SECTION (header|engine|axes|data)
90
DATATYPE (timeline|integer|float|string|short|ipv4|gold|char|years|enum|ln|port)
93
PROPERTY (label|color|penwidth|relative|print)
94
SQSTRING \'([^\\\']|\\.)*\'
95
DQSTRING \"([^\\\"]|\\.)*\"
96
STRING (\"|\')([^\\(\"|\')]|\\.)*(\"|\')
98
WORD ([a-zA-Z0-9_\-]+(\(\-?[0-9\*]+\))?\.?)+
108
{INCLUDE} { BEGIN(incl); }
110
{PROPERTY} { yylval.string = strdup(yytext);
111
return TOK_PROPERTY; }
112
{OPEN_PROP} { return TOK_OPEN_PROP; }
113
{CLOSE_PROP} { return TOK_CLOSE_PROP; }
117
return TOK_SEMICOLON;
119
{COMMA} { return TOK_COMMA; }
121
{SECTION} { yylval.string = strdup(yytext);
124
{OPEN_SECTION} { return TOK_OPEN_SECTION; }
125
{CLOSE_SECTION} { return TOK_CLOSE_SECTION; }
127
{DATATYPE} { yylval.string = strdup(yytext);
132
yylval.string = strdup(escape_str(yytext));
136
{WORD} { yylval.string = strdup(yytext);
140
{EQUAL} { return TOK_EQUAL; }
143
yylval.string = strdup(escape_str(yytext));
157
/* We don't care (; is the separator)
158
* so we just inscrease the line number
160
yyset_lineno(yyget_lineno()+1);
163
<incl>[ \t]* /* eat the whitespace */
164
<incl>[^ \t\n]+ { /* got the include file name */
165
if (includes_index >= MAX_INCLUDE_DEPTH) {
166
yyerror("Includes nested too deeply");
170
filename = escape_str(strndup(yytext, yyleng));
173
filenames[includes_index] = filename;
174
includes[includes_index++] = YY_CURRENT_BUFFER;
176
realfile = strdup(filename);
178
yyin = fopen(realfile, "r");
180
printf("Can not open %s\n", realfile);
186
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
191
if (--includes_index < 0)
194
free(filenames[includes_index + 1]);
195
filename = filenames[includes_index];
196
yy_delete_buffer(YY_CURRENT_BUFFER);
197
yy_switch_to_buffer(includes[includes_index]);
203
/* remove unused functions */
204
typedef void (*dummy_function) ();
205
dummy_function picvizparser_unused[] =
207
(dummy_function) input, (dummy_function) yyunput