]> granicus.if.org Git - fortune-mod/commitdiff
Extract a common expression into a variable/const.
authorShlomi Fish <shlomif@shlomifish.org>
Wed, 29 Apr 2020 11:42:29 +0000 (14:42 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Wed, 29 Apr 2020 11:42:29 +0000 (14:42 +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/util/unstr.c

index 93790f2de1cbdf3d07dbfc7c2fdccc4ddb66b105..a52e81d1f89134a3ef1532ee0a3cd2ccce6a6e10 100644 (file)
@@ -118,14 +118,14 @@ static void getargs(int ac, char *av[])
             perror("input is too long");
             exit(1);
         }
-        if (!strrchr(input_filename, '.'))
+        char *const extc = strrchr(input_filename, '.');
+        if (!extc)
         {
             sprintf(data_filename, "%s.dat", input_filename);
         }
         else
         {
             strcpy(data_filename, input_filename);
-            char *extc = strrchr(input_filename, '.');
             *extc = '\0';
         }
         if (*++av)