]> Savannah Git Hosting - gnulib.git/commitdiff
unigbrk tests: Modernize code.
authorBruno Haible <bruno@clisp.org>
Sun, 15 Sep 2024 13:16:52 +0000 (15:16 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 15 Sep 2024 13:16:52 +0000 (15:16 +0200)
* tests/unigbrk/test-uc-grapheme-breaks.c (main): Reduce the scope of
local variables. Add comments.
* tests/unigbrk/test-uc-is-grapheme-break.c (main): Likewise.

ChangeLog
tests/unigbrk/test-uc-grapheme-breaks.c
tests/unigbrk/test-uc-is-grapheme-break.c

index d8396afb00697ff5b45cf14f275b95f2ac13d444..56ff30e8ef4d8758556a5f583e5a13391238ecf5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-09-15  Bruno Haible  <bruno@clisp.org>
+
+       unigbrk tests: Modernize code.
+       * tests/unigbrk/test-uc-grapheme-breaks.c (main): Reduce the scope of
+       local variables. Add comments.
+       * tests/unigbrk/test-uc-is-grapheme-break.c (main): Likewise.
+
 2024-09-15  Bruno Haible  <bruno@clisp.org>
 
        unilbrk: Fix conflicts between rules.
index e3f0005899c835d542f31bffe690cc9e65c20048..49eed04c305f9f2cee8063298165ce9d4cac612d 100644 (file)
@@ -97,9 +97,9 @@ int
 main (int argc, char *argv[])
 {
   const char *filename;
-  char line[1024];
   FILE *stream;
   int lineno;
+  char line[1024];
 
   if (argc != 2)
     {
@@ -118,22 +118,23 @@ main (int argc, char *argv[])
     }
 
   lineno = 0;
-  while (fgets (line, sizeof line, stream))
+  while (fgets (line, sizeof (line), stream))
     {
-      char *comment;
-      const char *p;
-      ucs4_t s[16];
-      char breaks[16];
-      size_t i = 0;
-
       lineno++;
 
-      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;
+      ucs4_t s[16];
+      char breaks[16];
+      size_t i = 0;
+
       s[0] = 0;
       p = line;
       do
index 92674a07fb9f18b8c29668dc18b5e266893a2467..939b09b3a99eea18707167f6b37b90ff3e783a1a 100644 (file)
@@ -59,10 +59,10 @@ int
 main (int argc, char *argv[])
 {
   const char *filename;
-  char line[1024];
-  int exit_code;
   FILE *stream;
+  int exit_code;
   int lineno;
+  char line[1024];
 
   if (argc != 2)
     {
@@ -82,9 +82,18 @@ main (int argc, char *argv[])
 
   exit_code = 0;
   lineno = 0;
-  while (fgets (line, sizeof line, stream))
+  while (fgets (line, sizeof (line), stream))
     {
-      char *comment;
+      lineno++;
+
+      /* 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;
       ucs4_t prev;
       int last_char_prop;
@@ -95,14 +104,6 @@ main (int argc, char *argv[])
       bool emoji_modifier_sequence_before_last_char;
       size_t ri_count;
 
-      lineno++;
-
-      comment = strchr (line, '#');
-      if (comment != NULL)
-        *comment = '\0';
-      if (line[strspn (line, " \t\r\n")] == '\0')
-        continue;
-
       last_char_prop = -1;
       incb_consonant_extended = false;
       incb_consonant_extended_linker = false;