From 32042058455058ecaacf484d27a3bacb173685a5 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 27 Feb 2008 18:16:58 +0000 Subject: [PATCH] Forcing the filename to be set upon token creation --- src/token.c | 15 ++++++++++++--- src/token.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/token.c b/src/token.c index c71a432..f074fa7 100644 --- a/src/token.c +++ b/src/token.c @@ -33,6 +33,7 @@ struct _Token { TokenCode code; char * string; + char * filename; unsigned int line; unsigned int col; }; @@ -40,8 +41,9 @@ struct _Token /* protected */ /* functions */ -/* token_new */ -Token * token_new(unsigned int line, unsigned int col) +/* token_new + * PRE filename must be non-NULL */ +Token * token_new(char const * filename, unsigned int line, unsigned int col) { Token * token; @@ -51,9 +53,16 @@ Token * token_new(unsigned int line, unsigned int col) if((token = object_new(sizeof(*token))) == NULL) return NULL; token->code = 0; + token->string = NULL; + token->filename = strdup(filename); token->line = line; token->col = col; - token->string = NULL; + if(token->filename == NULL) + { + error_set_code(1, "%s", strerror(errno)); + object_delete(token); + return NULL; + } return token; } diff --git a/src/token.h b/src/token.h index da9c10f..be4b56e 100644 --- a/src/token.h +++ b/src/token.h @@ -22,6 +22,6 @@ /* Token */ /* functions */ -Token * token_new(unsigned int line, unsigned int col); +Token * token_new(char const * filename, unsigned int line, unsigned int col); #endif /* !_LIBSYSTEM_TOKEN_H */