Fixed whitespaces within directives

This commit is contained in:
Pierre Pronchery 2013-06-04 03:32:55 +02:00
parent bd0fc7289a
commit 8c8f4b99b7

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2007-2012 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2007-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel cpp */ /* This file is part of DeforaOS Devel cpp */
/* This program is free software: you can redistribute it and/or modify /* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
@ -242,6 +242,8 @@ static int _cpp_token_set(CppParser * cp, Token * token, TokenCode code,
string = " "; string = " ";
if(cp->queue_string == NULL) if(cp->queue_string == NULL)
{ {
/* left-trim spaces */
for(; isspace((unsigned char)string[0]); string++);
if((cp->queue_string = string_new(string)) == NULL) if((cp->queue_string = string_new(string)) == NULL)
return -1; return -1;
} }
@ -452,7 +454,7 @@ static int _cpp_callback_newline(Parser * parser, Token * token, int c,
static int _cpp_callback_otherspace(Parser * parser, Token * token, int c, static int _cpp_callback_otherspace(Parser * parser, Token * token, int c,
void * data) void * data)
{ {
CppParser * cppparser = data; CppParser * cp = data;
char * str = NULL; char * str = NULL;
size_t len = 0; size_t len = 0;
char * p; char * p;
@ -472,15 +474,14 @@ static int _cpp_callback_otherspace(Parser * parser, Token * token, int c,
str[len++] = c; str[len++] = c;
} }
while(isspace((c = parser_scan_filter(parser))) && c != '\n'); while(isspace((c = parser_scan_filter(parser))) && c != '\n');
token_set_code(token, CPP_CODE_WHITESPACE);
if(str != NULL) if(str != NULL)
{ {
str[len] = '\0'; str[len] = '\0';
token_set_string(token, str); _cpp_token_set(cp, token, CPP_CODE_WHITESPACE, str);
free(str); free(str);
} }
else else
token_set_string(token, " "); _cpp_token_set(cp, token, CPP_CODE_WHITESPACE, " ");
return 0; return 0;
} }
@ -943,7 +944,7 @@ static char * _include_path(CppParser * cpp, char const * str)
char * p; char * p;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%p, \"%s\")\n", __func__, cpp, str); fprintf(stderr, "DEBUG: %s(%p, \"%s\")\n", __func__, (void *)cpp, str);
#endif #endif
if(str[0] == '"') if(str[0] == '"')
d = str[0]; d = str[0];
@ -998,7 +999,7 @@ static char * _path_lookup(CppParser * cp, char const * path, int system)
} }
string_delete(p); string_delete(p);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: stat(\"%s\", %p)\n", r, &st); fprintf(stderr, "DEBUG: stat(\"%s\", %p)\n", r, (void *)&st);
#endif #endif
if(stat(r, &st) == 0) if(stat(r, &st) == 0)
return r; return r;
@ -1025,8 +1026,8 @@ int cppparser_inject(CppParser * cp, char const * string)
return 1; return 1;
cp->inject_first = 1; cp->inject_first = 1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%p, \"%s\") => \"%s\"\n", __func__, cp, fprintf(stderr, "DEBUG: %s(%p, \"%s\") => \"%s\"\n", __func__,
string, cp->inject); (void *)cp, string, cp->inject);
#endif #endif
return 0; return 0;
} }