]> granicus.if.org Git - fortune-mod/commitdiff
Extract a method or a function.
authorShlomi Fish <shlomif@shlomifish.org>
Sat, 20 Nov 2021 07:10:49 +0000 (09:10 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Sat, 20 Nov 2021 07:10:49 +0000 (09:10 +0200)
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
fortune-mod/util/fortune-mod-common.h
fortune-mod/util/randstr.c
fortune-mod/util/strfile.c

index f67e5fc960c130b28e25870d0d91997696bdbd4b..7767fb7d8956f7602805b4942cf4382b0df96891 100644 (file)
@@ -1850,7 +1850,7 @@ int main(int argc, char *argv[])
     }
     else
     {
-        srandom((unsigned int)(time((time_t *)NULL) + getpid()));
+        call_srandom();
         do
         {
             get_fort();
index e6d479adeddc2d7df6d01242c126eddc456449d7..78cebc8f3dd1ea988c39cf4290fcc7392e51c83b 100644 (file)
@@ -64,3 +64,7 @@
 #endif /* MAXPATHLEN */
 #include <rinutils/count.h>
 #include <rinutils/unused.h>
+static void call_srandom(void)
+{
+    srandom((unsigned)(time((time_t *)NULL) + getpid()));
+}
index 5f3922efc12c47f62a4dd97e37554b4f66902910..4a49f5a2022abbefad4000e8dab4140ff4acf0a7 100644 (file)
@@ -192,7 +192,7 @@ int main(int argc GCC_UNUSED, char **argv)
     tbl.str_shortlen = ntohl(tbl.str_shortlen);
     tbl.str_flags = ntohl(tbl.str_flags);
 
-    srandom((int)(time((time_t *)NULL) + getpid()));
+    call_srandom();
     get_fort(tbl);
     display(Inf, tbl);
 
index 2333dba42b8cd4fbc22446da81efd2775516869f..ba30f97e74c88508e773094f2dec1f7bef01aeb0 100644 (file)
@@ -323,8 +323,7 @@ static void do_order(void)
  */
 static void randomize(void)
 {
-    srandom((unsigned int)(time((time_t *)NULL) + getpid()));
-
+    call_srandom();
     Tbl.str_flags |= STR_RANDOM;
     /*      cnt = Tbl.str_numstr;
      * See comment above.  Isn't this stuff distributed worldwide?  How