]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Improve code style.
authorBruno Haible <bruno@clisp.org>
Mon, 7 Sep 2020 00:08:26 +0000 (02:08 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 4 Oct 2020 12:52:54 +0000 (14:52 +0200)
* gettext-tools/src/cldr-plural-exp.c: Indent and parenthesize for better
readability.

gettext-tools/src/cldr-plural-exp.c

index 69f9997896ddf3c32962120bcc48bcff2a95a9bf..60d3d0bafe2d72dae5d88af89e3b29aa8219bee2 100644 (file)
@@ -1,5 +1,5 @@
 /* Unicode CLDR plural rule parser and converter
-   Copyright (C) 2015, 2018-2019 Free Software Foundation, Inc.
+   Copyright (C) 2015, 2018-2020 Free Software Foundation, Inc.
 
    This file was written by Daiki Ueno <ueno@gnu.org>, 2015.
 
@@ -119,10 +119,10 @@ cldr_plural_parse (const char *input)
 }
 
 #define OPERAND_ZERO_P(o)                               \
-    (((o)->type == CLDR_PLURAL_OPERAND_INTEGER          \
-      && (o)->value.ival == 0)                          \
-    || ((o)->type == CLDR_PLURAL_OPERAND_DECIMAL        \
-        && (o)->value.dval.d == 0))
+  (((o)->type == CLDR_PLURAL_OPERAND_INTEGER            \
+    && (o)->value.ival == 0)                            \
+   || ((o)->type == CLDR_PLURAL_OPERAND_DECIMAL         \
+       && (o)->value.dval.d == 0))
 
 static enum cldr_plural_condition
 eval_relation (struct cldr_plural_relation_ty *relation)
@@ -140,14 +140,15 @@ eval_relation (struct cldr_plural_relation_ty *relation)
               {
                 int truncated = (int) range->start->value.dval.d;
                 range->start->type = CLDR_PLURAL_OPERAND_INTEGER;
-                range->start->value.ival
-                  = range->start->value.dval.d == truncated
-                  ? truncated : truncated + 1;
+                range->start->value.ival =
+                  (range->start->value.dval.d == truncated
+                   ? truncated
+                   : truncated + 1);
               }
             if (range->end->type == CLDR_PLURAL_OPERAND_DECIMAL)
               {
                 range->end->type = CLDR_PLURAL_OPERAND_INTEGER;
-                range->end->value.ival = (int) (range->end->value.dval.d);
+                range->end->value.ival = (int) range->end->value.dval.d;
               }
           }
         relation->expression->operand = 'i';
@@ -187,19 +188,19 @@ eval_condition (struct cldr_plural_condition_ty *condition)
       eval_condition (condition->value.conditions[0]);
       eval_condition (condition->value.conditions[1]);
 
-      if (condition->value.conditions[0]->type
-          == CLDR_PLURAL_CONDITION_FALSE
-          || condition->value.conditions[1]->type
-          == CLDR_PLURAL_CONDITION_FALSE)
+      if ((condition->value.conditions[0]->type
+           == CLDR_PLURAL_CONDITION_FALSE)
+          || (condition->value.conditions[1]->type
+              == CLDR_PLURAL_CONDITION_FALSE))
         {
           cldr_plural_condition_free (condition->value.conditions[0]);
           cldr_plural_condition_free (condition->value.conditions[1]);
           condition->type = CLDR_PLURAL_CONDITION_FALSE;
         }
-      else if (condition->value.conditions[0]->type
-               == CLDR_PLURAL_CONDITION_TRUE
-               && condition->value.conditions[1]->type
-               == CLDR_PLURAL_CONDITION_TRUE)
+      else if ((condition->value.conditions[0]->type
+                == CLDR_PLURAL_CONDITION_TRUE)
+               && (condition->value.conditions[1]->type
+                   == CLDR_PLURAL_CONDITION_TRUE))
         {
           cldr_plural_condition_free (condition->value.conditions[0]);
           cldr_plural_condition_free (condition->value.conditions[1]);
@@ -208,8 +209,8 @@ eval_condition (struct cldr_plural_condition_ty *condition)
       else if (condition->value.conditions[0]->type
                == CLDR_PLURAL_CONDITION_TRUE)
         {
-          struct cldr_plural_condition_ty *original
-            condition->value.conditions[1];
+          struct cldr_plural_condition_ty *original =
+            condition->value.conditions[1];
           cldr_plural_condition_free (condition->value.conditions[0]);
           condition->type = condition->value.conditions[1]->type;
           condition->value = condition->value.conditions[1]->value;
@@ -218,8 +219,8 @@ eval_condition (struct cldr_plural_condition_ty *condition)
       else if (condition->value.conditions[1]->type
                == CLDR_PLURAL_CONDITION_TRUE)
         {
-          struct cldr_plural_condition_ty *original
-            condition->value.conditions[0];
+          struct cldr_plural_condition_ty *original =
+            condition->value.conditions[0];
           cldr_plural_condition_free (condition->value.conditions[1]);
           condition->type = condition->value.conditions[0]->type;
           condition->value = condition->value.conditions[0]->value;
@@ -231,19 +232,19 @@ eval_condition (struct cldr_plural_condition_ty *condition)
       eval_condition (condition->value.conditions[0]);
       eval_condition (condition->value.conditions[1]);
 
-      if (condition->value.conditions[0]->type
-          == CLDR_PLURAL_CONDITION_TRUE
-          || condition->value.conditions[1]->type
-          == CLDR_PLURAL_CONDITION_TRUE)
+      if ((condition->value.conditions[0]->type
+           == CLDR_PLURAL_CONDITION_TRUE)
+          || (condition->value.conditions[1]->type
+              == CLDR_PLURAL_CONDITION_TRUE))
         {
           cldr_plural_condition_free (condition->value.conditions[0]);
           cldr_plural_condition_free (condition->value.conditions[1]);
           condition->type = CLDR_PLURAL_CONDITION_TRUE;
         }
-      else if (condition->value.conditions[0]->type
-               == CLDR_PLURAL_CONDITION_FALSE
-               && condition->value.conditions[1]->type
-               == CLDR_PLURAL_CONDITION_FALSE)
+      else if ((condition->value.conditions[0]->type
+                == CLDR_PLURAL_CONDITION_FALSE)
+               && (condition->value.conditions[1]->type
+                   == CLDR_PLURAL_CONDITION_FALSE))
         {
           cldr_plural_condition_free (condition->value.conditions[0]);
           cldr_plural_condition_free (condition->value.conditions[1]);
@@ -252,8 +253,8 @@ eval_condition (struct cldr_plural_condition_ty *condition)
       else if (condition->value.conditions[0]->type
                == CLDR_PLURAL_CONDITION_FALSE)
         {
-          struct cldr_plural_condition_ty *original
-            condition->value.conditions[1];
+          struct cldr_plural_condition_ty *original =
+            condition->value.conditions[1];
           cldr_plural_condition_free (condition->value.conditions[0]);
           condition->type = condition->value.conditions[1]->type;
           condition->value = condition->value.conditions[1]->value;
@@ -262,8 +263,8 @@ eval_condition (struct cldr_plural_condition_ty *condition)
       else if (condition->value.conditions[1]->type
                == CLDR_PLURAL_CONDITION_FALSE)
         {
-          struct cldr_plural_condition_ty *original
-            condition->value.conditions[0];
+          struct cldr_plural_condition_ty *original =
+            condition->value.conditions[0];
           cldr_plural_condition_free (condition->value.conditions[1]);
           condition->type = condition->value.conditions[0]->type;
           condition->value = condition->value.conditions[0]->value;
@@ -342,14 +343,13 @@ apply_condition (struct cldr_plural_condition_ty *condition, int value)
 {
   if (condition->type == CLDR_PLURAL_CONDITION_AND)
     return apply_condition (condition->value.conditions[0], value)
-      && apply_condition (condition->value.conditions[1], value);
+           && apply_condition (condition->value.conditions[1], value);
   else if (condition->type == CLDR_PLURAL_CONDITION_OR)
     return apply_condition (condition->value.conditions[0], value)
-      || apply_condition (condition->value.conditions[1], value);
+           || apply_condition (condition->value.conditions[1], value);
   else if (condition->type == CLDR_PLURAL_CONDITION_RELATION)
     {
-      struct cldr_plural_relation_ty *relation
-        = condition->value.relation;
+      struct cldr_plural_relation_ty *relation = condition->value.relation;
       int number = value;
       size_t i;
 
@@ -397,8 +397,8 @@ print_relation (struct cldr_plural_relation_ty *relation,
             {
               print_expression (relation->expression, space, fp);
               fprintf (fp,
-                       space && relation->ranges->nitems == 1
-                       ? " == %d" : "==%d",
+                       (space && relation->ranges->nitems == 1
+                        ? " == %d" : "==%d"),
                        range->start->value.ival);
             }
           else if (range->start->value.ival == 0)
@@ -434,33 +434,33 @@ print_relation (struct cldr_plural_relation_ty *relation,
       for (i = 0; i < relation->ranges->nitems; i++)
         {
           struct cldr_plural_range_ty *range = relation->ranges->items[i];
-         if (i > 0)
-           fprintf (fp," && ");
-         if (range->start->value.ival == range->end->value.ival)
-           {
-             print_expression (relation->expression, space, fp);
-             fprintf (fp, space && relation->ranges->nitems == 1
-                      ? " != %d" : "!=%d", range->start->value.ival);
-           }
-         else if (range->start->value.ival == 0)
-           {
-             print_expression (relation->expression, false, fp);
-             fprintf (fp, ">%d", range->end->value.ival);
-           }
-         else
-           {
-             if (parent == CLDR_PLURAL_CONDITION_AND
-                 || relation->ranges->nitems > 1)
-               fputc ('(', fp);
-             print_expression (relation->expression, false, fp);
-             fprintf (fp, "<%d", range->start->value.ival);
-             fprintf (fp, " || ");
-             print_expression (relation->expression, false, fp);
-             fprintf (fp, ">%d", range->end->value.ival);
-             if (parent == CLDR_PLURAL_CONDITION_AND
-                 || relation->ranges->nitems > 1)
-               fputc (')', fp);
-           }
+          if (i > 0)
+            fprintf (fp," && ");
+          if (range->start->value.ival == range->end->value.ival)
+            {
+              print_expression (relation->expression, space, fp);
+              fprintf (fp, space && relation->ranges->nitems == 1
+                       ? " != %d" : "!=%d", range->start->value.ival);
+            }
+          else if (range->start->value.ival == 0)
+            {
+              print_expression (relation->expression, false, fp);
+              fprintf (fp, ">%d", range->end->value.ival);
+            }
+          else
+            {
+              if (parent == CLDR_PLURAL_CONDITION_AND
+                  || relation->ranges->nitems > 1)
+                fputc ('(', fp);
+              print_expression (relation->expression, false, fp);
+              fprintf (fp, "<%d", range->start->value.ival);
+              fprintf (fp, " || ");
+              print_expression (relation->expression, false, fp);
+              fprintf (fp, ">%d", range->end->value.ival);
+              if (parent == CLDR_PLURAL_CONDITION_AND
+                  || relation->ranges->nitems > 1)
+                fputc (')', fp);
+            }
         }
       if (parent == CLDR_PLURAL_CONDITION_OR
           && relation->ranges->nitems > 1)