Retained new lines in whitespaces

This commit is contained in:
Pierre Pronchery 2008-02-26 15:26:18 +00:00
parent 2ba87713b4
commit b501ac22c6

View File

@ -282,21 +282,37 @@ static int _trigraph_get(int last, int * c)
static int _cpp_callback_whitespace(Parser * parser, Token * token, int c, static int _cpp_callback_whitespace(Parser * parser, Token * token, int c,
void * data) void * data)
{ {
char * str = " "; char * str = NULL;
size_t len = 0;
char * p;
if(!isspace(c)) if(!isspace(c))
return 1; return 1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: cpp_callback_whitespace()\n"); fprintf(stderr, "%s", "DEBUG: cpp_callback_whitespace()\n");
#endif #endif
do do
{ {
if(c == '\n') if(c != '\n')
str = "\n"; continue;
if((p = realloc(str, len + 1)) == NULL)
{
free(str);
return -1;
}
str = p;
str[len++] = '\n';
} }
while(isspace((c = parser_scan_filter(parser)))); while(isspace((c = parser_scan_filter(parser))));
token_set_code(token, CPP_CODE_WHITESPACE); token_set_code(token, CPP_CODE_WHITESPACE);
if(str != NULL)
{
str[len] = '\0';
token_set_string(token, str); token_set_string(token, str);
free(str);
}
else
token_set_string(token, " ");
return 0; return 0;
} }