]> granicus.if.org Git - fortune-mod/commitdiff
Extract a method or a function.
authorShlomi Fish <shlomif@shlomifish.org>
Sat, 4 Apr 2020 18:29:09 +0000 (21:29 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Sat, 4 Apr 2020 18:29:09 +0000 (21:29 +0300)
This is Refactoring / code cleanup.

See:

* https://refactoring.com/catalog/extractMethod.html

* https://en.wikipedia.org/wiki/Code_refactoring

* https://www.refactoring.com/

* https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/

Some small optimisations may have slipped in as well.

fortune-mod/fortune/fortune.c

index 28328f318f6a017cba095279229e57e887a9ff16..c242cfac30e4f75e657daf885f0f934176645bb1 100644 (file)
@@ -627,29 +627,22 @@ static int add_file(int percent, const char *file, const char *dir,
         {
             if (((sp = strrchr(file, '-')) != NULL) && (strcmp(sp, "-o") == 0))
             {
+#define CALL__add_file(dir) add_file(percent, file, dir, head, tail, parent)
                 /* BSD-style '-o' offensive file suffix */
                 *sp = '\0';
-                found =
-                    (add_file(percent, file, LOCOFFDIR, head, tail, parent)) ||
-                    add_file(percent, file, OFFDIR, head, tail, parent);
+                found = CALL__add_file(LOCOFFDIR) || CALL__add_file(OFFDIR);
                 /* put the suffix back in for better identification later */
                 *sp = '-';
             }
             else if (All_forts)
                 found =
-                    (add_file(percent, file, LOCFORTDIR, head, tail, parent) ||
-                        add_file(
-                            percent, file, LOCOFFDIR, head, tail, parent) ||
-                        add_file(percent, file, FORTDIR, head, tail, parent) ||
-                        add_file(percent, file, OFFDIR, head, tail, parent));
+                    (CALL__add_file(LOCFORTDIR) || CALL__add_file(LOCOFFDIR) ||
+                        CALL__add_file(FORTDIR) || CALL__add_file(OFFDIR));
             else if (Offend)
-                found =
-                    (add_file(percent, file, LOCOFFDIR, head, tail, parent) ||
-                        add_file(percent, file, OFFDIR, head, tail, parent));
+                found = (CALL__add_file(LOCOFFDIR) || CALL__add_file(OFFDIR));
             else
-                found =
-                    (add_file(percent, file, LOCFORTDIR, head, tail, parent) ||
-                        add_file(percent, file, FORTDIR, head, tail, parent));
+                found = (CALL__add_file(LOCFORTDIR) || CALL__add_file(FORTDIR));
+#undef CALL__add_file
         }
         if (!found && parent == NULL && dir == NULL)
         { /* don't display an error when trying language specific files */