From d623763e5888db753915ac0eac5ca9ea117d5df0 Mon Sep 17 00:00:00 2001 From: rlar Date: Wed, 31 Dec 2014 16:52:41 +0100 Subject: [PATCH] inpcom.c, cleanup inp_remove_ws(), reorder loop, reveal obscure behaviour --- src/frontend/inpcom.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 599c92c5e..358566174 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -2204,12 +2204,27 @@ inp_remove_ws(char *s) char *buffer; bool is_expression = FALSE; + /* preserve at least one whitespace at beginning of line + * fixme, + * is this really necessary ? + * or is this an artefact of original inp_remove_ws() implementation ? + */ + if (isspace(*s)) + *d++ = *s++; + while (*s != '\0') { if (*s == '{') is_expression = TRUE; if (*s == '}') is_expression = FALSE; + if (isspace(*s)) { + s = skip_ws(s); + if (!(*s == '\0' || *s == '=' || (is_expression && (is_arith_char(*s) || *s == ',')))) + *d++ = ' '; + continue; + } + if (*s == '=' || (is_expression && (is_arith_char(*s) || *s == ','))) { *d++ = *s++; s = skip_ws(s); @@ -2224,11 +2239,6 @@ inp_remove_ws(char *s) } *d++ = *s++; - if (isspace(*s)) { - s = skip_ws(s); - if (!(*s == '\0' || *s == '=' || (is_expression && (is_arith_char(*s) || *s == ',')))) - *d++ = ' '; - } } *d = '\0';