From: Bruno Haible Date: Sun, 15 Sep 2024 13:20:08 +0000 (+0200) Subject: uniwbrk tests: Modernize code. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=54d66d912df487a31aa10c6c35df3ba556c9c43a;p=gnulib.git uniwbrk tests: Modernize code. * tests/uniwbrk/test-uc-wordbreaks.c (main): Reduce the scope of local variables. Remove memset() calls. Align expected and actial output lines. Add comments. --- diff --git a/ChangeLog b/ChangeLog index 56ff30e8ef..a31bdc0861 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-09-15 Bruno Haible + + uniwbrk tests: Modernize code. + * tests/uniwbrk/test-uc-wordbreaks.c (main): Reduce the scope of local + variables. Remove memset() calls. Align expected and actial output + lines. Add comments. + 2024-09-15 Bruno Haible unigbrk tests: Modernize code. diff --git a/tests/uniwbrk/test-uc-wordbreaks.c b/tests/uniwbrk/test-uc-wordbreaks.c index 8213446f77..1c7bb1017e 100644 --- a/tests/uniwbrk/test-uc-wordbreaks.c +++ b/tests/uniwbrk/test-uc-wordbreaks.c @@ -65,10 +65,10 @@ int main (int argc, char *argv[]) { const char *filename; - char line[4096]; - int exit_code; FILE *stream; + int exit_code; int lineno; + char line[4096]; if (argc != 2) { @@ -88,26 +88,24 @@ main (int argc, char *argv[]) exit_code = 0; lineno = 0; - while (fgets (line, sizeof line, stream)) + while (fgets (line, sizeof (line), stream)) { - char *comment; - const char *p; - uint32_t input[100]; - char breaks[101]; - char breaks_expected[101]; - int i; - lineno++; - memset (breaks, 0, sizeof (breaks)); - memset (breaks_expected, 0, sizeof (breaks_expected)); - - comment = strchr (line, '#'); + /* Cut off the trailing comment, if any. */ + char *comment = strchr (line, '#'); if (comment != NULL) *comment = '\0'; + /* Is the remaining line blank? */ if (line[strspn (line, " \t\r\n")] == '\0') continue; + const char *p; + uint32_t input[100]; + char breaks[100]; + char breaks_expected[101]; + int i; + i = 0; p = line; do @@ -170,7 +168,7 @@ main (int argc, char *argv[]) input[j], wordbreakproperty_to_string (input_wbp)); } fprintf (stderr, "\n"); - fprintf (stderr, "%s:%d: actual: ", filename, lineno); + fprintf (stderr, "%s:%d: actual: ", filename, lineno); for (j = 0; j < i - 1; j++) { int input_wbp = uc_wordbreak_property (input[j]);