Code cleanup

This commit is contained in:
Pierre Pronchery 2009-08-01 01:54:26 +00:00
parent 397c08cebf
commit ec4a31ea90
2 changed files with 20 additions and 25 deletions

View File

@ -937,14 +937,9 @@ int cppparser_include(CppParser * cp, char const * include)
if((path = _include_path(cp, include)) == NULL) if((path = _include_path(cp, include)) == NULL)
return -1; return -1;
if((cp->subparser = cppparser_new(cp->cpp, cp, path, cp->filters)) cp->subparser = cppparser_new(cp->cpp, cp, path, cp->filters);
== NULL)
{
free(path);
return -1;
}
free(path); free(path);
return 0; return (cp->subparser != NULL) ? 0 : -1;
} }
static char * _include_path(CppParser * cpp, char const * str) static char * _include_path(CppParser * cpp, char const * str)

View File

@ -115,9 +115,9 @@ static int _scan_if(Cpp * cpp, Token ** token);
static int _scan_elif(Cpp * cpp, Token ** token); static int _scan_elif(Cpp * cpp, Token ** token);
static int _scan_else(Cpp * cpp, Token ** token); static int _scan_else(Cpp * cpp, Token ** token);
static int _scan_endif(Cpp * cpp, Token ** token); static int _scan_endif(Cpp * cpp, Token ** token);
static int _scan_define(Cpp * cpp, Token ** token); static int _scan_define(Cpp * cpp, Token * token);
static int _scan_include(Cpp * cpp, Token * token); static int _scan_include(Cpp * cpp, Token * token);
static int _scan_undef(Cpp * cpp, Token ** token); static int _scan_undef(Cpp * cpp, Token * token);
int cpp_scan(Cpp * cpp, Token ** token) int cpp_scan(Cpp * cpp, Token ** token)
{ {
@ -163,11 +163,11 @@ int cpp_scan(Cpp * cpp, Token ** token)
switch(code) switch(code)
{ {
case CPP_CODE_META_DEFINE: case CPP_CODE_META_DEFINE:
return _scan_define(cpp, token); return _scan_define(cpp, *token);
case CPP_CODE_META_INCLUDE: case CPP_CODE_META_INCLUDE:
return _scan_include(cpp, *token); return _scan_include(cpp, *token);
case CPP_CODE_META_UNDEF: case CPP_CODE_META_UNDEF:
return _scan_undef(cpp, token); return _scan_undef(cpp, *token);
case CPP_CODE_WORD: case CPP_CODE_WORD:
str = token_get_string(*token); str = token_get_string(*token);
if((s = cpp_define_get(cpp, str)) != NULL) if((s = cpp_define_get(cpp, str)) != NULL)
@ -283,7 +283,7 @@ static int _scan_endif(Cpp * cpp, Token ** token)
return 0; return 0;
} }
static int _scan_define(Cpp * cpp, Token ** token) static int _scan_define(Cpp * cpp, Token * token)
{ {
char * str; char * str;
int tmp; int tmp;
@ -293,7 +293,7 @@ static int _scan_define(Cpp * cpp, Token ** token)
char * var; char * var;
char const * val; char const * val;
str = token_get_data(*token); str = token_get_data(token);
/* fetch variable name */ /* fetch variable name */
for(i = 1; (tmp = str[i]) != '\0' && !isspace(tmp); i++) for(i = 1; (tmp = str[i]) != '\0' && !isspace(tmp); i++)
{ {
@ -310,20 +310,20 @@ static int _scan_define(Cpp * cpp, Token ** token)
val = (str[j] != '\0') ? &str[j] : NULL; val = (str[j] != '\0') ? &str[j] : NULL;
if((var = strdup(str)) == NULL) if((var = strdup(str)) == NULL)
{ {
token_set_code(*token, CPP_CODE_META_ERROR); token_set_code(token, CPP_CODE_META_ERROR);
token_set_string(*token, strerror(errno)); token_set_string(token, strerror(errno));
token_set_data(*token, NULL); token_set_data(token, NULL);
free(str); free(str);
return 0; return 0;
} }
var[k != 0 ? k : i] = '\0'; var[k != 0 ? k : i] = '\0';
if(cpp_define_add(cpp, var, val) != 0) if(cpp_define_add(cpp, var, val) != 0)
{ {
token_set_code(*token, CPP_CODE_META_ERROR); token_set_code(token, CPP_CODE_META_ERROR);
token_set_string(*token, error_get()); token_set_string(token, error_get());
} }
free(var); free(var);
token_set_data(*token, NULL); token_set_data(token, NULL);
free(str); free(str);
return 0; return 0;
} }
@ -337,7 +337,7 @@ static int _scan_include(Cpp * cpp, Token * token)
return 0; return 0;
} }
static int _scan_undef(Cpp * cpp, Token ** token) static int _scan_undef(Cpp * cpp, Token * token)
/* FIXME ignores what's after the spaces after the variable name */ /* FIXME ignores what's after the spaces after the variable name */
{ {
char * str; char * str;
@ -345,21 +345,21 @@ static int _scan_undef(Cpp * cpp, Token ** token)
size_t i; size_t i;
char * var; char * var;
str = token_get_data(*token); str = token_get_data(token);
/* fetch variable name */ /* fetch variable name */
for(i = 1; (tmp = str[i]) != '\0' && !isspace(tmp); i++); for(i = 1; (tmp = str[i]) != '\0' && !isspace(tmp); i++);
if((var = strdup(str)) == NULL) if((var = strdup(str)) == NULL)
{ {
token_set_code(*token, CPP_CODE_META_ERROR); token_set_code(token, CPP_CODE_META_ERROR);
token_set_string(*token, strerror(errno)); token_set_string(token, strerror(errno));
free(str); free(str);
return 0; return 0;
} }
var[i] = '\0'; var[i] = '\0';
if(cpp_define_remove(cpp, var) != 0) if(cpp_define_remove(cpp, var) != 0)
{ {
token_set_code(*token, CPP_CODE_META_ERROR); token_set_code(token, CPP_CODE_META_ERROR);
token_set_string(*token, error_get()); token_set_string(token, error_get());
} }
free(var); free(var);
free(str); free(str);