]> granicus.if.org Git - fortune-mod/commitdiff
Extract a method or a function.
authorShlomi Fish <shlomif@shlomifish.org>
Tue, 31 Mar 2020 07:54:25 +0000 (10:54 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Tue, 31 Mar 2020 07:54:25 +0000 (10:54 +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 aa3805cb58cc5ce682cf199c49c4dc1c3330ba11..a35156a78394c904f601acd680b93f7a82719c0d 100644 (file)
@@ -894,10 +894,19 @@ static int cond_top_level__add_file(
     return top_level__add_file(dirpath);
 }
 
+static int cond_top_level__LOCFORTDIR(void)
+{
+    return cond_top_level__add_file(FORTDIR, LOCFORTDIR);
+}
+
+static int cond_top_level__OFFDIR(void)
+{
+    return cond_top_level__add_file(OFFDIR, LOCOFFDIR);
+}
+
 static int top_level_LOCFORTDIR(void)
 {
-    return (top_level__add_file(LOCFORTDIR) |
-            cond_top_level__add_file(FORTDIR, LOCFORTDIR));
+    return (top_level__add_file(LOCFORTDIR) | cond_top_level__LOCFORTDIR());
 }
 
 static int form_file_list(register char **files, register int file_cnt)
@@ -910,13 +919,15 @@ static int form_file_list(register char **files, register int file_cnt)
     if (file_cnt == 0)
     {
         if (All_forts)
+        {
             return (top_level__add_file(LOCFORTDIR) |
                     top_level__add_file(LOCOFFDIR) |
-                    cond_top_level__add_file(FORTDIR, LOCFORTDIR) |
-                    cond_top_level__add_file(OFFDIR, LOCOFFDIR));
+                    cond_top_level__LOCFORTDIR() | cond_top_level__OFFDIR());
+        }
         else if (Offend)
-            return (top_level__add_file(LOCOFFDIR) |
-                    cond_top_level__add_file(OFFDIR, LOCOFFDIR));
+        {
+            return (top_level__add_file(LOCOFFDIR) | cond_top_level__OFFDIR());
+        }
         else
         {
             if (env_lang)
@@ -961,8 +972,10 @@ static int form_file_list(register char **files, register int file_cnt)
                 return top_level_LOCFORTDIR();
             }
             else
+            {
                 /* no locales available, use default */
                 return top_level_LOCFORTDIR();
+            }
         }
     }