work on strings too
This commit is contained in:
parent
f1ca33fa3a
commit
5b82720814
24
source/lib.c
24
source/lib.c
@ -20,17 +20,24 @@ struct psql_state *psql_new(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
st->buffer_state = NULL;
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
void psql_free(struct psql_state *st)
|
||||
void psql_free(struct psql_state *pstate)
|
||||
{
|
||||
if (!st)
|
||||
if (!pstate)
|
||||
return;
|
||||
|
||||
yylex_destroy(st->scanner);
|
||||
if (pstate->buffer_state) {
|
||||
yy_delete_buffer(pstate->buffer_state, pstate->scanner);
|
||||
}
|
||||
|
||||
free(st);
|
||||
yylex_destroy(pstate->scanner);
|
||||
|
||||
|
||||
free(pstate);
|
||||
}
|
||||
|
||||
void psql_set_input(struct psql_state *pstate, FILE *in_f)
|
||||
@ -38,6 +45,15 @@ void psql_set_input(struct psql_state *pstate, FILE *in_f)
|
||||
yyset_in(in_f, pstate->scanner);
|
||||
}
|
||||
|
||||
void psql_set_string_input(struct psql_state *pstate, char *in_str)
|
||||
{
|
||||
if (pstate->buffer_state) {
|
||||
yy_delete_buffer(pstate->buffer_state, pstate->scanner);
|
||||
}
|
||||
|
||||
pstate->buffer_state = yy_scan_string(in_str, pstate->scanner);
|
||||
}
|
||||
|
||||
int psql_parse(struct psql_state *pstate)
|
||||
{
|
||||
return yyparse(pstate->scanner, pstate);
|
||||
|
@ -25,7 +25,6 @@ main(int ac, char **av)
|
||||
abort();
|
||||
|
||||
if(ac > 1) {
|
||||
puts("wut?");
|
||||
if((in_f = fopen(av[1], "r")) == NULL) {
|
||||
perror(av[1]);
|
||||
exit(1);
|
||||
|
@ -54,13 +54,19 @@ enum sqlp_date_intervals {
|
||||
SDI_HOUR_SECOND = 8,
|
||||
};
|
||||
|
||||
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
|
||||
typedef void* YY_BUFFER_STATE;
|
||||
#endif
|
||||
|
||||
struct psql_state {
|
||||
yyscan_t scanner;
|
||||
YY_BUFFER_STATE buffer_state;
|
||||
};
|
||||
|
||||
extern struct psql_state *psql_new(void);
|
||||
extern void psql_free(struct psql_state *st);
|
||||
extern void psql_set_input(struct psql_state *st, FILE *f);
|
||||
extern void psql_set_string_input(struct psql_state *pstate, char *in_str);
|
||||
extern int psql_parse(struct psql_state *st);
|
||||
|
||||
extern void sqlp_alias(struct psql_state *pstate, const char *alias);
|
||||
|
@ -325,7 +325,7 @@ struct psql_state;
|
||||
%start stmt_list
|
||||
|
||||
%{
|
||||
void yyerror(YYLTYPE *, yyscan_t scanner, struct psql_state *pstate, const char *s, ...);
|
||||
void yyerror(YYLTYPE *t, yyscan_t scanner, struct psql_state *pstate, const char *s, ...);
|
||||
void lyyerror(YYLTYPE t, const char *s, ...);
|
||||
%}
|
||||
/* free discarded tokens */
|
||||
@ -975,9 +975,10 @@ yyerror(YYLTYPE *t, yyscan_t scanner, struct psql_state *pstate, const char *s,
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
|
||||
if(t->first_line)
|
||||
if (t->first_line) {
|
||||
fprintf(stderr, "%s:%d.%d-%d.%d: error: ", t->filename, t->first_line, t->first_column,
|
||||
t->last_line, t->last_column);
|
||||
t->last_line, t->last_column);
|
||||
}
|
||||
vfprintf(stderr, s, ap);
|
||||
fprintf(stderr, "\n");
|
||||
yyerrno = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user