Fixed and tested old memmove() replacement and moved from curses to common.
authorDavid Griffith <dave@661.org>
Fri, 27 Jul 2018 03:55:54 +0000 (20:55 -0700)
committerDavid Griffith <dave@661.org>
Tue, 31 Jul 2018 08:45:29 +0000 (01:45 -0700)
Makefile
src/common/Makefile
src/common/frotz.h
src/common/missing.c [new file with mode: 0644]
src/common/missing.h [new file with mode: 0644]
src/curses/ux_frotz.h
src/curses/ux_input.c

index e20ed519655b2c1977cbbb27cc91f6995a827c62..03972cddc4f8c3304bcdd01da79eb1c1ef932a30 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,8 @@ SRCDIR = src
 
 COMMON_DIR = $(SRCDIR)/common
 COMMON_LIB = $(COMMON_DIR)/frotz_common.a
-COMMON_DEFINES = $(COMMON_DIR)/version.c
+COMMON_STRINGS = $(COMMON_DIR)/version.c
+COMMON_DEFINES = $(COMMON_DIR)/defines.h
 HASH = $(COMMON_DIR)/git_hash.h
 
 CURSES_DIR = $(SRCDIR)/curses
@@ -180,10 +181,10 @@ dumb_lib: $(DUMB_LIB)
 blorb_lib:     $(BLORB_LIB)
 
 
-# Defines
+# Compile-time generated defines and strings
 
-common_defines:        $(COMMON_DEFINES)
-$(COMMON_DEFINES):
+common_strings:        $(COMMON_STRINGS)
+$(COMMON_STRINGS):
        @echo "Generating $@"
        @echo "#include \"frotz.h\"" > $@
        @echo "const char frotz_version[] = \"$(VERSION)\";" >> $@
@@ -191,6 +192,16 @@ $(COMMON_DEFINES):
        @echo "const char frotz_v_minor[] = \"$(MINOR)\";" >> $@
        @echo "const char frotz_v_build[] = \"$(BUILD_DATE_TIME)\";" >> $@
 
+common_defines: $(COMMON_DEFINES)
+$(COMMON_DEFINES):
+       @echo "Generating $@"
+       @echo "#ifndef COMMON_DEFINES_H" > $@
+       @echo "#define COMMON_DEFINES_H" >> $@
+ifdef NO_MEMMOVE
+       @echo "#define NO_MEMMOVE" >> $@
+endif
+       @echo "#endif /* COMMON_DEFINES_H */" >> $@
+
 curses_defines: $(CURSES_DEFINES)
 $(CURSES_DEFINES):
        @echo "Generating $@"
@@ -214,10 +225,6 @@ ifdef COLOR
        @echo "#define COLOR_SUPPORT" >> $@
 endif
 
-ifdef NO_MEMMOVE
-       @echo "#define NO_MEMMOVE" >> $@
-endif
-
        @echo "#endif /* CURSES_DEFINES_H */" >> $@
 
 
@@ -278,4 +285,4 @@ help:
        blorb_lib common_lib curses_lib dumb_lib \
        install install_dfrotz install_dumb \
        uninstall uninstall_dfrotz uninstall_dumb $(SUBDIRS) $(SUB_CLEAN) \
-       $(COMMON_DIR)/version.c $(CURSES_DIR)/defines.h
+       $(COMMON_DIR)/defines.h $(COMMON_DIR)/version.c $(CURSES_DIR)/defines.h
index 00d36fa9a5b7a580c45ca36bc0eda1738a0a7732..bffa0e17f75f87b9fbfee6cd3c744f0f5cf0b5d2 100644 (file)
@@ -1,8 +1,9 @@
 # For GNU Make.
 
 SOURCES = buffer.c err.c fastmem.c files.c getopt.c hotkey.c input.c \
-       main.c math.c object.c process.c quetzal.c random.c redirect.c \
-       screen.c sound.c stream.c table.c text.c variable.c version.c
+       main.c math.c missing.c object.c process.c quetzal.c random.c \
+       redirect.c screen.c sound.c stream.c table.c text.c variable.c \
+       version.c
 
 HEADERS = frotz.h setup.h unused.h
 
index b02f1a2441f8e4f6da36ec53de1cf657e5c013e9..fb1eb342e53d0a6143cb72f28032fd9c8ac5546f 100644 (file)
@@ -125,6 +125,8 @@ typedef struct {
 
 
 #include "setup.h"
+#include "defines.h"
+#include "missing.h"
 #include "unused.h"
 
 /*** Constants that may be set at compile time ***/
diff --git a/src/common/missing.c b/src/common/missing.c
new file mode 100644 (file)
index 0000000..e1ecfbb
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * missing.c - Assorted standard functions that may be missing on older systems
+ *     Written by David Griffith <dave@661.org>
+ *
+ * This file is part of Frotz.
+ *
+ * Frotz is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Frotz is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#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.
+ *
+ */
+void *my_memmove(void *dest, const void *src, size_t n)
+{
+       char *d =(char *)dest;
+       char *s =(char *)src;
+
+       if(s == d) return dest;
+
+       if(s < d) {     // copy from back
+               s=s+n-1;
+               d=d+n-1;
+               while(n--) *d-- = *s--;
+       } else          // copy from front
+               while(n--) *d++=*s++;
+
+       return dest;
+}
+#endif /* NO_MEMMOVE */
diff --git a/src/common/missing.h b/src/common/missing.h
new file mode 100644 (file)
index 0000000..b622346
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * missing.h
+ *
+ * Declarations and definitions for standard things that may be missing
+ * on older systems.
+ *
+ */
+
+#ifndef MISSING_H
+#define MISSING_H
+
+#ifdef NO_MEMMOVE
+void *my_memmove(void *, const void *, size_t);
+#define memmove my_memmove
+#endif
+
+
+#endif /* MISSING_H */
index 091e3629dc7894ed755758d5882988ace9b316fa..25fe4a75e130bb9061ab9a4cbaff22e1d6493b4f 100644 (file)
@@ -5,6 +5,9 @@
  *
  */
 
+#ifndef UX_FROTZ_H
+#define UX_FROTZ_H
+
 #include <signal.h>
 
 #include "defines.h"
@@ -96,6 +99,4 @@ void unix_get_terminal_size(void);      /* ux_init.c */
 char *strrchr(const char *, int);
 #endif
 
-#ifdef NO_MEMMOVE
-void *memmove(void *, void *);
-#endif
+#endif /* UX_FROTZ_H */
index 00cd934c0a097caee8e40a37da089ab28e373385..d4ec7379426443b33eb3a7298d372f4eee0b0ca9 100644 (file)
@@ -806,31 +806,6 @@ zword os_read_mouse (void)
  */
 
 
-#ifdef NO_MEMMOVE
-/*
- * This is for operating systems based on 4.2BSD or older or SYSVR3 or
- * older.  Since they lack the memmove(3) system call, it is provided
- * here.  Because I don't have a machine like this to play with, this code
- * is untested.  If you happen to have a spare SunOS 4.1.x install CD
- * lying around, please consider sending it my way.  Dave.
- *
- */
-void *memmove(void *s, void *t, size_t n)
-{
-       char *p = s; char *q = t;
-
-       if (p < q) {
-               while (n--) *p++ = *q++;
-       } else {
-               p += n; q += n;
-               while (n--) *--p = *--q;
-       }
-       return;
-}
-
-#endif /* NO_MEMMOVE */
-
-
 /*
  * Search for start of preceding word
  * param currpos marker position