chars: add a helper function for stripping leading blanks from a string

And apply this function to the formatter and linter command strings,
to complement the bug fixes in the previous two commits.
This commit is contained in:
Benno Schulenberg 2024-01-25 16:28:14 +01:00
parent 88c8da143f
commit 0e72c0d372
4 changed files with 18 additions and 6 deletions

View File

@ -654,3 +654,12 @@ bool white_string(const char *string)
return !*string;
}
#if defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
/* Remove leading whitespace from the given string. */
void strip_leading_blanks_from(char *string)
{
while (string && (*string == ' ' || *string == '\t'))
memmove(string, string + 1, strlen(string));
}
#endif

View File

@ -2208,9 +2208,7 @@ int main(int argc, char **argv)
free(alt_speller);
alt_speller = alt_speller_cmdline;
}
/* Strip leading whitespace from the speller command, if any. */
while (alt_speller && (*alt_speller == ' ' || *alt_speller == '\t'))
memmove(alt_speller, alt_speller + 1, strlen(alt_speller));
strip_leading_blanks_from(alt_speller);
#endif
/* If an rcfile undid the default setting, copy it to the new flag. */

View File

@ -238,6 +238,9 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer);
bool has_blank_char(const char *string);
#endif
bool white_string(const char *string);
#if defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
void strip_leading_blanks_from(char *string);
#endif
/* Most functions in color.c. */
#ifdef ENABLE_COLOR

View File

@ -1332,11 +1332,13 @@ bool parse_syntax_commands(char *keyword, char *ptr)
#endif
} else if (strcmp(keyword, "tabgives") == 0) {
pick_up_name("tabgives", ptr, &live_syntax->tabstring);
} else if (strcmp(keyword, "linter") == 0)
} else if (strcmp(keyword, "linter") == 0) {
pick_up_name("linter", ptr, &live_syntax->linter);
else if (strcmp(keyword, "formatter") == 0)
strip_leading_blanks_from(live_syntax->linter);
} else if (strcmp(keyword, "formatter") == 0) {
pick_up_name("formatter", ptr, &live_syntax->formatter);
else
strip_leading_blanks_from(live_syntax->formatter);
} else
return FALSE;
return TRUE;