Moved local strdup() and strndup() implementations to from dumb to core.
authorDavid Griffith <dave@661.org>
Thu, 31 Jan 2019 17:12:26 +0000 (09:12 -0800)
committerDavid Griffith <dave@661.org>
Thu, 31 Jan 2019 17:14:16 +0000 (09:14 -0800)
Makefile
src/common/missing.c
src/common/missing.h
src/dumb/dumb_frotz.h
src/dumb/dumb_init.c
src/dumb/dumb_input.c

index bdfdb320cf671104dc2612f19a3d0e0f7cf40fb8..de8d43f73c936219ac87d2d2007c00c52dadeb71 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -71,21 +71,28 @@ COLOR ?= yes
 # If this matters, you can choose -lcurses or -lncurses
 CURSES ?= -lncurses
 
-# Uncomment this if you're compiling Unix Frotz on a machine that lacks
-# the strrchr() libc library call.  If you don't know what this means,
-# leave it alone.
+# Uncomment this if you want to disable the compilation of Blorb support.
 #
-#NO_STRRCHR = yes
+#NO_BLORB = yes
 
-# Uncomment this if you're compiling Unix Frotz on a machine that lacks
-# the memmove(3) system call.  If you don't know what this means, leave it
-# alone.
-#
+
+# These are for enabling local version of certain functions which may be
+# missing or behave differently from what's expected in modern system.
+# If you're running on a system made in the past 20 years, you should be
+# safe leaving these alone.  If not or you're using something modern,
+# but very strange intended for very limited machines, you probably know
+# what you're doing.  Therefore further commentary on what these
+# functions do is probably not necessary.
+
+# For missing memmove()
 #NO_MEMMOVE = yes
 
-# Uncomment this if you want to disable the compilation of Blorb support.
-#
-#NO_BLORB = yes
+# For missing strdup() and strndup()
+NO_STRDUP = yes
+
+# For missing strrchr()
+#NO_STRRCHR = yes
+
 
 #########################################################################
 # This section is where Frotz is actually built.
@@ -223,14 +230,17 @@ $(COMMON_DEFINES):
        @echo "** Generating $@"
        @echo "#ifndef COMMON_DEFINES_H" > $@
        @echo "#define COMMON_DEFINES_H" >> $@
+ifdef NO_BLORB
+       @echo "#define NO_BLORB" >> $@
+endif
 ifdef NO_STRRCHR
        @echo "#define NO_STRRCHR" >> $@
 endif
 ifdef NO_MEMMOVE
        @echo "#define NO_MEMMOVE" >> $@
 endif
-ifdef NO_BLORB
-       @echo "#define NO_BLORB" >> $@
+ifdef NO_STRDUP
+       @echo "#define NO_STRDUP" >> $@
 endif
        @echo "#endif /* COMMON_DEFINES_H */" >> $@
 
index e1ecfbb73319577e92057df366f6197ecad1197d..cb32e13c212b97d29c88b6ad9d2be27ce6001391 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdlib.h>
 #include "frotz.h"
 
 #ifdef NO_MEMMOVE
 /*
  * Unix-ish operating systems based on 4.2BSD or older or SYSVR3 or older
- * lack the memmove(3) system call.
+ * lack memmove(3).
  *
  */
 void *my_memmove(void *dest, const void *src, size_t n)
@@ -44,3 +45,44 @@ void *my_memmove(void *dest, const void *src, size_t n)
        return dest;
 }
 #endif /* NO_MEMMOVE */
+
+
+#ifdef NO_STRDUP
+/*
+ * Unix-ish operating systems based on 4.2BSD or older or SYSVR3 or older
+ * lack strdup(3) and strndup(3).
+ *
+ */
+char *my_strdup(const char *src)
+{
+       char *str;
+       char *p;
+       int len = 0;
+
+       while (src[len])
+               len++;
+       str = malloc(len + 1);
+       p = str;
+       while (*src)
+       *p++ = *src++;
+       *p = '\0';
+       return str;
+}
+
+char *my_strndup(const char *src, size_t n)
+{
+       char *str;
+       char *p;
+       int len = 0;
+
+       while (src[len] && len < n)
+               len++;
+       str = malloc(len + 1);
+       p = str;
+       while (len--) {
+               *p++ = *src++;
+       }
+       *p = '\0';
+       return str;
+}
+#endif /* NO_STRDUP */
index b6223463eff3b980159fd7aaf7ec5a24a7d1d59e..8d84b5d8b1f54b05046485e9794bd004d143404f 100644 (file)
@@ -14,5 +14,11 @@ void *my_memmove(void *, const void *, size_t);
 #define memmove my_memmove
 #endif
 
+#ifdef NO_STRDUP
+char *my_strdup(const char *);
+char *my_strndup(const char *, size_t);
+#define strdup my_strdup
+#define strndup        my_strndup
+#endif
 
 #endif /* MISSING_H */
index 89fa887015e0528f035870ddb73596e1c87515ea..fb46efdfeca9858628c984ae32ab9c9ac17dcf40 100644 (file)
@@ -16,9 +16,6 @@
 #include <ctype.h>
 #include <time.h>
 
-extern char *my_strdup(char *);
-extern char *my_strndup(char *, size_t);
-
 /* from ../common/setup.h */
 extern f_setup_t f_setup;
 
index 0b1d678e082c41ddb5593997dcc3fbd47853332c..da3be119fc406459e861e09c701fe226baa2a0b9 100644 (file)
@@ -114,7 +114,7 @@ void os_process_arguments(int argc, char *argv[])
          case 'i': f_setup.ignore_errors = 1; break;
          case 'I': f_setup.interpreter_number = atoi(zoptarg); break;
        case 'L': f_setup.restore_mode = 1;
-                 f_setup.tmp_save_name = my_strdup(zoptarg);
+                 f_setup.tmp_save_name = strdup(zoptarg);
                  break;
          case 'm': do_more_prompts = FALSE; break;
          case 'o': f_setup.object_movement = 1; break;
@@ -122,7 +122,7 @@ void os_process_arguments(int argc, char *argv[])
          case 'P': f_setup.piracy = 1; break;
        case 'p': plain_ascii = 1; break;
        case 'r': dumb_handle_setting(zoptarg, FALSE, TRUE); break;
-       case 'R': f_setup.restricted_path =  my_strndup(zoptarg, PATH_MAX); break;
+       case 'R': f_setup.restricted_path = strndup(zoptarg, PATH_MAX); break;
        case 's': user_random_seed = atoi(zoptarg); break;
          case 'S': f_setup.script_cols = atoi(zoptarg); break;
        case 't': user_tandy_bit = 1; break;
@@ -147,8 +147,8 @@ void os_process_arguments(int argc, char *argv[])
 
     /* Save the story file name */
 
-    f_setup.story_file = my_strdup(argv[zoptind]);
-    f_setup.story_name = my_strdup(basename(argv[zoptind]));
+    f_setup.story_file = strdup(argv[zoptind]);
+    f_setup.story_name = strdup(basename(argv[zoptind]));
 
     /* Now strip off the extension */
     p = strrchr(f_setup.story_name, '.');
@@ -293,41 +293,6 @@ void os_init_setup(void)
        f_setup.sound = 1;
        f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE;
        f_setup.restore_mode = 0;
-
-}
-
-char *my_strdup(char *src)
-{
-       char *str;
-       char *p;
-       int len = 0;
-
-       while (src[len])
-               len++;
-       str = malloc(len + 1);
-       p = str;
-       while (*src)
-        *p++ = *src++;
-       *p = '\0';
-       return str;
-}
-
-char *my_strndup(char *src, size_t n)
-{
-       char *str;
-       char *p;
-       int len = 0;
-
-       while (src[len] && len < n)
-               len++;
-       str = malloc(len + 1);
-       p = str;
-       while (len--)
-       {
-               *p++ = *src++;
-       }
-       *p = '\0';
-       return str;
 }
 
 static void print_version(void)
index d01c150984e722e2ad9cf17507c54d3f012e9762..805b3f65474d98b46f5f10757b5598c8e7bd6f3e 100644 (file)
@@ -430,7 +430,7 @@ int os_read_file_name (char *file_name, const char *default_name, int flag)
          break;
        }
       }
-      tempname = my_strdup(default_name + i);
+      tempname = strdup(default_name + i);
       sprintf(prompt, "Please enter a filename [%s]: ", tempname);
     } else
       sprintf(prompt, "Please enter a filename [%s]: ", default_name);
@@ -451,7 +451,7 @@ int os_read_file_name (char *file_name, const char *default_name, int flag)
         break;
       }
     }
-    tempname = my_strdup(file_name + i);
+    tempname = strdup(file_name + i);
     strcpy(file_name, f_setup.restricted_path);
     if (file_name[strlen(file_name)-1] != PATH_SEPARATOR) {
       strcat(file_name, "/");