Make sure we display the correct file name and line in error messages.
This commit is contained in:
parent
34ef9824df
commit
3d4dcc2a25
|
@ -30,6 +30,7 @@ hex 0x{hexd}+
|
||||||
uuid {hexd}{8}-{hexd}{4}-{hexd}{4}-{hexd}{4}-{hexd}{12}
|
uuid {hexd}{8}-{hexd}{4}-{hexd}{4}-{hexd}{4}-{hexd}{12}
|
||||||
|
|
||||||
%x QUOTE
|
%x QUOTE
|
||||||
|
%x pp_line
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
|
@ -69,6 +70,8 @@ static int kw_token(const char *kw);
|
||||||
#define MAX_IMPORT_DEPTH 10
|
#define MAX_IMPORT_DEPTH 10
|
||||||
struct {
|
struct {
|
||||||
YY_BUFFER_STATE state;
|
YY_BUFFER_STATE state;
|
||||||
|
char *input_name;
|
||||||
|
int line_number;
|
||||||
char *temp_name;
|
char *temp_name;
|
||||||
} import_stack[MAX_IMPORT_DEPTH];
|
} import_stack[MAX_IMPORT_DEPTH];
|
||||||
int import_stack_ptr = 0;
|
int import_stack_ptr = 0;
|
||||||
|
@ -103,7 +106,26 @@ static UUID* parse_uuid(const char*u)
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
*/
|
*/
|
||||||
%%
|
%%
|
||||||
^#.*
|
<INITIAL>^{ws}*\#{ws}* yy_push_state(pp_line);
|
||||||
|
<pp_line>[^\n]* {
|
||||||
|
int lineno;
|
||||||
|
char *cptr, *fname;
|
||||||
|
yy_pop_state();
|
||||||
|
lineno = (int)strtol(yytext, &cptr, 10);
|
||||||
|
if(!lineno)
|
||||||
|
yyerror("Malformed '#...' line-directive; invalid linenumber");
|
||||||
|
fname = strchr(cptr, '"');
|
||||||
|
if(!fname)
|
||||||
|
yyerror("Malformed '#...' line-directive; missing filename");
|
||||||
|
fname++;
|
||||||
|
cptr = strchr(fname, '"');
|
||||||
|
if(!cptr)
|
||||||
|
yyerror("Malformed '#...' line-directive; missing terminating \"");
|
||||||
|
*cptr = '\0';
|
||||||
|
line_number = lineno - 1; /* We didn't read the newline */
|
||||||
|
free( input_name );
|
||||||
|
input_name = xstrdup(fname);
|
||||||
|
}
|
||||||
\" yy_push_state(QUOTE); cbufidx = 0;
|
\" yy_push_state(QUOTE); cbufidx = 0;
|
||||||
<QUOTE>\" {
|
<QUOTE>\" {
|
||||||
yy_pop_state();
|
yy_pop_state();
|
||||||
|
@ -127,7 +149,7 @@ static UUID* parse_uuid(const char*u)
|
||||||
return aNUM;
|
return aNUM;
|
||||||
}
|
}
|
||||||
{cident} return kw_token(yytext);
|
{cident} return kw_token(yytext);
|
||||||
\n
|
\n line_number++;
|
||||||
{ws}
|
{ws}
|
||||||
\<\< return SHL;
|
\<\< return SHL;
|
||||||
\>\> return SHR;
|
\>\> return SHR;
|
||||||
|
@ -314,6 +336,9 @@ static void pop_import(void)
|
||||||
free(temp_name);
|
free(temp_name);
|
||||||
}
|
}
|
||||||
temp_name = import_stack[ptr].temp_name;
|
temp_name = import_stack[ptr].temp_name;
|
||||||
|
free( input_name );
|
||||||
|
input_name = import_stack[ptr].input_name;
|
||||||
|
line_number = import_stack[ptr].line_number;
|
||||||
import_stack_ptr--;
|
import_stack_ptr--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,14 +350,15 @@ struct imports {
|
||||||
int do_import(char *fname)
|
int do_import(char *fname)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *hname, *path;
|
char *hname, *path, *p;
|
||||||
struct imports *import;
|
struct imports *import;
|
||||||
int ptr = import_stack_ptr;
|
int ptr = import_stack_ptr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!parse_only) {
|
if (!parse_only) {
|
||||||
hname = dup_basename(fname, ".idl");
|
hname = dup_basename(fname, ".idl");
|
||||||
strcat(hname, ".h");
|
p = hname + strlen(hname) - 2;
|
||||||
|
if (p <= hname || strcmp( p, ".h" )) strcat(hname, ".h");
|
||||||
|
|
||||||
fprintf(header, "#include \"%s\"\n", hname);
|
fprintf(header, "#include \"%s\"\n", hname);
|
||||||
free(hname);
|
free(hname);
|
||||||
|
@ -352,10 +378,13 @@ int do_import(char *fname)
|
||||||
yyerror("Unable to open include file %s", fname);
|
yyerror("Unable to open include file %s", fname);
|
||||||
|
|
||||||
import_stack[ptr].temp_name = temp_name;
|
import_stack[ptr].temp_name = temp_name;
|
||||||
|
import_stack[ptr].input_name = input_name;
|
||||||
|
import_stack[ptr].line_number = line_number;
|
||||||
import_stack_ptr++;
|
import_stack_ptr++;
|
||||||
|
input_name = path;
|
||||||
|
line_number = 1;
|
||||||
|
|
||||||
ret = wpp_parse_temp( path, NULL, &temp_name );
|
ret = wpp_parse_temp( path, NULL, &temp_name );
|
||||||
free( path );
|
|
||||||
if (ret) exit(1);
|
if (ret) exit(1);
|
||||||
|
|
||||||
if((f = fopen(temp_name, "r")) == NULL)
|
if((f = fopen(temp_name, "r")) == NULL)
|
||||||
|
|
|
@ -50,7 +50,7 @@ void make_print(char *str)
|
||||||
|
|
||||||
static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
|
static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s:%d:%d: %s: ", input_name ? input_name : "stdin", line_number, char_number, t);
|
fprintf(stderr, "%s:%d: %s: ", input_name ? input_name : "stdin", line_number, t);
|
||||||
vfprintf(stderr, s, ap);
|
vfprintf(stderr, s, ap);
|
||||||
#ifdef WANT_NEAR_INDICATION
|
#ifdef WANT_NEAR_INDICATION
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,7 +99,6 @@ char *proxy_token;
|
||||||
char *temp_name;
|
char *temp_name;
|
||||||
|
|
||||||
int line_number = 1;
|
int line_number = 1;
|
||||||
int char_number = 1;
|
|
||||||
|
|
||||||
FILE *header;
|
FILE *header;
|
||||||
FILE *proxy;
|
FILE *proxy;
|
||||||
|
@ -180,7 +179,7 @@ int main(int argc,char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(optind < argc) {
|
if(optind < argc) {
|
||||||
input_name = argv[optind];
|
input_name = xstrdup(argv[optind]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, usage);
|
fprintf(stderr, usage);
|
||||||
|
@ -266,7 +265,7 @@ int main(int argc,char *argv[])
|
||||||
if(ret) {
|
if(ret) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
header_name = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,6 +274,8 @@ static void rm_tempfile(void)
|
||||||
abort_import();
|
abort_import();
|
||||||
if(temp_name)
|
if(temp_name)
|
||||||
unlink(temp_name);
|
unlink(temp_name);
|
||||||
|
if (header_name)
|
||||||
|
unlink( header_name );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void segvhandler(int sig)
|
static void segvhandler(int sig)
|
||||||
|
|
Loading…
Reference in New Issue