]> granicus.if.org Git - fortune-mod/commitdiff
Wrap C/etc. oneline blocks in {...}
authorShlomi Fish <shlomif@shlomifish.org>
Thu, 16 Dec 2021 17:08:23 +0000 (19:08 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Thu, 16 Dec 2021 17:08:23 +0000 (19:08 +0200)
See:
https://fc-solve.shlomifish.org/docs/distro/HACKING.html#one-line-clauses
.

fortune-mod/fortune/fortune.c

index 5ce377228026cbf4c79aff87d060e2697b343cd6..fa75c7d48d1eba50b415df888d36a938531f0a71 100644 (file)
 #ifdef DEBUG
 #define DPRINTF(l, x)                                                          \
     if (Debug >= l)                                                            \
-        fprintf x;
+    {                                                                          \
+        fprintf x;                                                             \
+    }
 #else
 #define DPRINTF(l, x)
 #endif
@@ -288,24 +290,36 @@ static void print_list(FILEDESC *list, int lev)
     {
         fprintf(stderr, "%*s", lev * 4, "");
         if (list->percent == NO_PROB)
+        {
             if (!Equal_probs)
+            {
                 /* This, with some changes elsewhere, gives proper percentages
                  * for every case fprintf(stderr, "___%%"); */
                 fprintf(stderr, "%5.2f%%",
                     (100.0 - Spec_prob) * list->tbl.str_numstr /
                         Noprob_tbl.str_numstr);
+            }
             else if (lev == 0)
+            {
                 fprintf(stderr, "%5.2f%%", 100.0 / Num_files);
+            }
             else
+            {
                 fprintf(stderr, "%5.2f%%", 100.0 / Num_kids);
+            }
+        }
         else
+        {
             fprintf(stderr, "%5.2f%%", 1.0 * list->percent);
+        }
         fprintf(stderr, " %s", STR(list->name));
         DPRINTF(1, (stderr, " (%s, %s, %s)\n", STR(list->path),
                        STR(list->datfile), STR(list->posfile)));
         putc('\n', stderr);
         if (list->child)
+        {
             print_list(list->child, lev + 1);
+        }
         list = list->next;
     }
 }
@@ -325,9 +339,13 @@ static char *conv_pat(const char *const orig_str)
     {
         const size_t prev_cnt = cnt;
         if (isalpha(*sp))
+        {
             cnt += 4;
+        }
         else
-            cnt++;
+        {
+            ++cnt;
+        }
         if (prev_cnt >= cnt)
         {
             fprintf(stderr, "%s",
@@ -360,7 +378,9 @@ static char *conv_pat(const char *const orig_str)
             *dest_ptr++ = ']';
         }
         else
+        {
             *dest_ptr++ = *orig;
+        }
     }
     *dest_ptr = '\0';
     return new_buf;
@@ -458,7 +478,9 @@ static int is_existant(char *file)
     struct stat staat;
 
     if (stat(file, &staat) == 0)
+    {
         return true;
+    }
     switch (errno)
     {
     case ENOENT:
@@ -487,9 +509,13 @@ static int is_fortfile(const char *const file, char **datp)
     DPRINTF(2, (stderr, "is_fortfile(%s) returns ", file));
 
     if (!sp)
+    {
         sp = file;
+    }
     else
+    {
         sp++;
+    }
     if (*sp == '.')
     {
         DPRINTF(2, (stderr, "%s", "false (file starts with '.')\n"));
@@ -499,11 +525,13 @@ static int is_fortfile(const char *const file, char **datp)
     {
         sp++;
         for (int i = 0; suflist[i]; ++i)
+        {
             if (strcmp(sp, suflist[i]) == 0)
             {
                 DPRINTF(2, (stderr, "false (file has suffix \".%s\")\n", sp));
                 return false;
             }
+        }
     }
 
     const size_t do_len = (strlen(file) + 6);
@@ -516,9 +544,13 @@ static int is_fortfile(const char *const file, char **datp)
         return false;
     }
     if (datp)
+    {
         *datp = datfile;
+    }
     else
+    {
         free(datfile);
+    }
     DPRINTF(2, (stderr, "%s", "true\n"));
     return true;
 }
@@ -607,16 +639,22 @@ static int add_file(int percent, const char *file, const char *dir,
                 *sp = '-';
             }
             else if (All_forts)
+            {
                 found =
                     (CALL__add_file(LOCFORTDIR) || CALL__add_file(LOCOFFDIR) ||
                         COND_CALL__add_file(LOCFORTDIR, FORTDIR) ||
                         COND_CALL__add_file(LOCOFFDIR, OFFDIR));
+            }
             else if (Offend)
+            {
                 found = (CALL__add_file(LOCOFFDIR) ||
                          COND_CALL__add_file(LOCOFFDIR, OFFDIR));
+            }
             else
+            {
                 found = (CALL__add_file(LOCFORTDIR) ||
                          COND_CALL__add_file(LOCFORTDIR, FORTDIR));
+            }
 #undef COND_CALL__add_file
 #undef CALL__add_file
         }
@@ -637,13 +675,19 @@ static int add_file(int percent, const char *file, const char *dir,
                 {
                     char *p = strchr(lang, ':');
                     if (p)
+                    {
                         *p++ = '\0';
+                    }
                     snprintf(langdir, sizeof(langdir), "%s/%s", FORTDIR, lang);
 
                     if (strncmp(path, lang, 2) == 0)
+                    {
                         ret = 1;
+                    }
                     else if (strncmp(path, langdir, strlen(FORTDIR) + 3) == 0)
+                    {
                         ret = 1;
+                    }
                     lang = p;
                 }
                 if (!ret)
@@ -678,7 +722,9 @@ static int add_file(int percent, const char *file, const char *dir,
     snprintf(testpath, do_len, "%s.u8", path);
     //    fprintf(stderr, "State mal: %s\n", testpath);
     if (stat(testpath, &statbuf) == 0)
+    {
         fp->utf8_charset = true;
+    }
 
     free(testpath);
     testpath = NULL;
@@ -689,8 +735,10 @@ static int add_file(int percent, const char *file, const char *dir,
     if ((isdir && !add_dir(fp)) || (!isdir && !is_fortfile(path, &fp->datfile)))
     {
         if (!parent)
+        {
             fprintf(
                 stderr, "fortune:%s not a fortune file or directory\n", path);
+        }
         free(path);
         path = NULL;
         free(fp->datfile);
@@ -698,7 +746,9 @@ static int add_file(int percent, const char *file, const char *dir,
         free(fp->name);
         free(fp->path);
         if (fp->fd >= 0)
+        {
             close(fp->fd);
+        }
         free(fp);
         return false;
     }
@@ -715,14 +765,18 @@ static int add_file(int percent, const char *file, const char *dir,
         free(fp->name);
         free(fp->path);
         if (fp->fd >= 0)
+        {
             close(fp->fd);
+        }
         free(fp);
         return true;
     }
     /* End hack. */
 
     if (!(*head))
+    {
         *head = *tail = fp;
+    }
     else if (fp->percent == NO_PROB)
     {
         (*tail)->next = fp;
@@ -778,7 +832,9 @@ static int add_dir(FILEDESC *const fp)
     while ((dirent = readdir(dir)))
     {
         if (dirent->d_name[0] == 0)
+        {
             continue;
+        }
         char *name = strdup(dirent->d_name);
         if (count_names == max_count_names)
         {
@@ -896,7 +952,9 @@ static int form_file_list(char **files, int file_cnt)
                 {
                     p = strchr(lang, ':');
                     if (p)
+                    {
                         *p++ = '\0';
+                    }
 
                     /* first try full locale */
                     ret = add_file(
@@ -915,7 +973,9 @@ static int form_file_list(char **files, int file_cnt)
 
                     /* if we have found one we have finished */
                     if (ret)
+                    {
                         return ret;
+                    }
                     lang = p;
                 }
                 /* default */
@@ -933,7 +993,9 @@ static int form_file_list(char **files, int file_cnt)
     {
         percent = NO_PROB;
         if (!isdigit(files[i][0]))
+        {
             sp = files[i];
+        }
         else
         {
             const int MAX_PERCENT = 100;
@@ -1030,7 +1092,9 @@ static int form_file_list(char **files, int file_cnt)
             {
                 char *p = strchr(lang, ':');
                 if (p)
+                {
                     *p++ = '\0';
+                }
 
                 /* first try full locale */
                 snprintf(
@@ -1055,13 +1119,16 @@ static int form_file_list(char **files, int file_cnt)
             }
             /* default */
             if (!ret)
+            {
                 ret = add_file(
                     percent, fullpathname, NULL, &File_list, &File_tail, NULL);
+            }
             if (!ret &&
                 strncmp(fullpathname, locpathname, sizeof(fullpathname)))
+            {
                 ret = add_file(
                     percent, locpathname, NULL, &File_list, &File_tail, NULL);
-
+            }
             if (!ret)
             {
                 snprintf(locpathname, sizeof(locpathname), "%s/%s",
@@ -1083,7 +1150,9 @@ static int form_file_list(char **files, int file_cnt)
         }
         else if (!add_file(
                      percent, fullpathname, NULL, &File_list, &File_tail, NULL))
+        {
             return false;
+        }
     }
     return true;
 }
@@ -1115,6 +1184,7 @@ static void getargs(int argc, char **argv)
 
     while ((ch = getopt(argc, argv,
                 "ac" DEBUG_GETOPT "efilm:n:" OFFENSIVE_GETOPT "suvw")) != EOF)
+    {
         switch (ch)
         {
         case 'a': /* any fortune */
@@ -1154,7 +1224,8 @@ static void getargs(int argc, char **argv)
         case 'i': /* case-insensitive match */
         case 'm': /* dump out the fortunes */
             (void)fprintf(stderr, "%s",
-                "fortune: can't match fortunes on this system (Sorry)\n");
+                "fortune: can't match fortunes on this system "
+                "(Sorry)\n");
             exit(0);
 #else             /* NO_REGEX */
         case 'm': /* dump out the fortunes */
@@ -1178,6 +1249,7 @@ static void getargs(int argc, char **argv)
         default:
             usage();
         }
+    }
     argc -= optind;
     argv += optind;
 
@@ -1202,7 +1274,9 @@ static void getargs(int argc, char **argv)
     if (pat)
     {
         if (ignore_case)
+        {
             pat = conv_pat(pat);
+        }
         if (BAD_COMP(RE_COMP(pat)))
         {
             fprintf(stderr, "bad pattern: %s\n", pat);
@@ -1232,14 +1306,20 @@ static void init_prob(void)
      */
     FILEDESC *last = NULL;
     for (fp = File_tail; fp; fp = fp->prev)
+    {
         if (fp->percent == NO_PROB)
         {
             num_noprob++;
             if (Equal_probs)
+            {
                 last = fp;
+            }
         }
         else
+        {
             percent += fp->percent;
+        }
+    }
     DPRINTF(1, (stderr, "summing probabilities:%d%% with %d NO_PROB's\n",
                    percent, num_noprob));
     if (percent > 100)
@@ -1250,16 +1330,19 @@ static void init_prob(void)
     else if (percent < 100 && num_noprob == 0)
     {
         fprintf(stderr,
-            "fortune: no place to put residual probability (%d%%)\n", percent);
+            "fortune: no place to put residual probability "
+            "(%d%%)\n",
+            percent);
         exit(1);
     }
     else if (percent == 100 && num_noprob != 0)
     {
-        fprintf(
-            stderr, "fortune: no probability left to put in residual files\n");
+        fprintf(stderr, "fortune: no probability left to put in "
+                        "residual files\n");
         exit(1);
     }
-    Spec_prob = percent; /* this is for -f when % is specified on cmd line */
+    Spec_prob = percent; /* this is for -f when % is specified on
+                            cmd line */
     percent = 100 - percent;
     if (Equal_probs)
     {
@@ -1270,11 +1353,13 @@ static void init_prob(void)
                 frac = percent / num_noprob;
                 DPRINTF(1, (stderr, ", frac = %d%%", frac));
                 for (fp = File_tail; fp != last; fp = fp->prev)
+                {
                     if (fp->percent == NO_PROB)
                     {
                         fp->percent = frac;
                         percent -= frac;
                     }
+                }
             }
             last->percent = percent;
             DPRINTF(1, (stderr, ", residual = %d%%", percent));
@@ -1290,7 +1375,9 @@ static void init_prob(void)
 #ifdef DEBUG
 #if 0
       if (Debug >= 1)
+    {
  print_list(File_list, 0); /* Causes crash with new %% code */
+    }
 
 #endif
 #endif
@@ -1315,9 +1402,13 @@ static void sum_tbl(STRFILE *t1, STRFILE *t2)
 {
     t1->str_numstr += t2->str_numstr;
     if (t1->str_longlen < t2->str_longlen)
+    {
         t1->str_longlen = t2->str_longlen;
+    }
     if (t1->str_shortlen > t2->str_shortlen)
+    {
         t1->str_shortlen = t2->str_shortlen;
+    }
 }
 
 /*
@@ -1330,7 +1421,9 @@ static void get_tbl(FILEDESC *fp)
     FILEDESC *child;
 
     if (fp->read_tbl)
+    {
         return;
+    }
     if (!(fp->child))
     {
         if ((fd = open4read(fp->datfile)) < 0)
@@ -1402,15 +1495,19 @@ static void sum_noprobs(FILEDESC *fp)
     static bool did_noprobs = false;
 
     if (did_noprobs)
+    {
         return;
+    }
     zero_tbl(&Noprob_tbl);
     while (fp)
     {
         get_tbl(fp);
-        /* This conditional should help us return correct values for -f
-         * when a percentage is specified */
+        /* This conditional should help us return correct values for
+         * -f when a percentage is specified */
         if (fp->percent == NO_PROB)
+        {
             sum_tbl(&Noprob_tbl, &fp->tbl);
+        }
         fp = fp->next;
     }
     did_noprobs = true;
@@ -1431,7 +1528,9 @@ static FILEDESC *pick_child(FILEDESC *parent)
         DPRINTF(1, (stderr, "    choice = %d (of %d)\n", choice,
                        parent->num_children));
         for (fp = parent->child; choice--; fp = fp->next)
+        {
             continue;
+        }
         DPRINTF(1, (stderr, "    using %s\n", fp->name));
         return fp;
     }
@@ -1468,8 +1567,8 @@ static void open_dat(FILEDESC *fp)
 
 /*
  * get_pos:
- *      Get the position from the pos file, if there is one.  If not,
- *      return a random number.
+ *      Get the position from the pos file, if there is one.  If
+ * not, return a random number.
  */
 static void get_pos(FILEDESC *fp)
 {
@@ -1479,13 +1578,16 @@ static void get_pos(FILEDESC *fp)
         fp->pos = (int32_t)(my_random(fp->tbl.str_numstr));
     }
     if (++(fp->pos) >= (int32_t)fp->tbl.str_numstr)
+    {
         fp->pos -= fp->tbl.str_numstr;
+    }
     DPRINTF(1, (stderr, "pos for %s is %ld\n", fp->name, fp->pos));
 }
 
 /*
  * get_fort:
- *      Get the fortune data file's seek pointer for the next fortune.
+ *      Get the fortune data file's seek pointer for the next
+ * fortune.
  */
 static void get_fort(void)
 {
@@ -1493,25 +1595,33 @@ static void get_fort(void)
     int choice;
 
     if (!File_list->next || File_list->percent == NO_PROB)
+    {
         fp = File_list;
+    }
     else
     {
         choice = my_random(100);
         DPRINTF(1, (stderr, "choice = %d\n", choice));
         for (fp = File_list; fp->percent != NO_PROB; fp = fp->next)
+        {
             if (choice < fp->percent)
+            {
                 break;
+            }
             else
             {
                 choice -= fp->percent;
                 DPRINTF(1, (stderr, "    skip \"%s\", %d%% (choice = %d)\n",
                                fp->name, fp->percent, choice));
             }
+        }
         DPRINTF(1, (stderr, "using \"%s\", %d%% (choice = %d)\n", fp->name,
                        fp->percent, choice));
     }
     if (fp->percent != NO_PROB)
+    {
         get_tbl(fp);
+    }
     else
     {
         if (fp->next)
@@ -1584,7 +1694,9 @@ static int maxlen_in_list(FILEDESC *list)
         if (fp->child)
         {
             if ((len = maxlen_in_list(fp->child)) > maxlen)
+            {
                 maxlen = len;
+            }
         }
         else
         {
@@ -1648,9 +1760,13 @@ static void matches_in_list(FILEDESC *list)
                     for (p = (unsigned char *)output; (ch = *p); ++p)
                     {
                         if (isupper(ch) && isascii(ch))
+                        {
                             *p = 'A' + (ch - 'A' + 13) % 26;
+                        }
                         else if (islower(ch) && isascii(ch))
+                        {
                             *p = 'a' + (ch - 'a' + 13) % 26;
+                        }
                     }
                 }
 
@@ -1683,7 +1799,8 @@ static void matches_in_list(FILEDESC *list)
 
 /*
  * find_matches:
- *      Find all the fortunes which match the pattern we've been given.
+ *      Find all the fortunes which match the pattern we've been
+ * given.
  */
 static int find_matches(void)
 {
@@ -1707,7 +1824,9 @@ static void display(FILEDESC *fp)
     open_fp(fp);
     fseek(fp->inf, (long)Seekpts[0], SEEK_SET);
     if (Show_filename)
+    {
         printf("(%s)\n%%\n", fp->name);
+    }
     for (Fort_len = 0; fgets((char *)line, sizeof line, fp->inf) &&
                        !STR_ENDSTRING(line, fp->tbl);
          Fort_len++)
@@ -1717,9 +1836,13 @@ static void display(FILEDESC *fp)
             for (p = (char *)line; (ch = *p); ++p)
             {
                 if (isupper(ch) && isascii(ch))
+                {
                     *p = 'A' + (ch - 'A' + 13) % 26;
+                }
                 else if (islower(ch) && isascii(ch))
+                {
                     *p = 'a' + (ch - 'a' + 13) % 26;
+                }
             }
         }
         if (fp->utf8_charset && (!No_recode))
@@ -1744,7 +1867,9 @@ static int fortlen(void)
     char line[BUFSIZ];
 
     if (!(Fortfile->tbl.str_flags & (STR_RANDOM | STR_ORDERED)))
+    {
         nchar = (Seekpts[1] - Seekpts[0]) - 2; /* for %^J delimiter */
+    }
     else
     {
         open_fp(Fortfile);
@@ -1752,7 +1877,9 @@ static int fortlen(void)
         nchar = 0;
         while (fgets(line, sizeof line, Fortfile->inf) &&
                !STR_ENDSTRING(line, Fortfile->tbl))
+        {
             nchar += strlen(line);
+        }
     }
     Fort_len = nchar;
     return nchar;
@@ -1789,11 +1916,17 @@ int main(int argc, char *argv[])
     int exit_code = 0;
     env_lang = getenv("LC_ALL");
     if (!env_lang)
+    {
         env_lang = getenv("LC_MESSAGES");
+    }
     if (!env_lang)
+    {
         env_lang = getenv("LANGUAGE");
+    }
     if (!env_lang)
+    {
         env_lang = getenv("LANG");
+    }
 #ifdef _WIN32
     if (!env_lang)
     {
@@ -1844,7 +1977,9 @@ int main(int argc, char *argv[])
     {
         sum_noprobs(File_list);
         if (Equal_probs)
+        {
             calc_equal_probs();
+        }
         print_list(File_list, 0);
     }
     else