From: David Griffith Date: Fri, 27 Jul 2018 03:55:54 +0000 (-0700) Subject: Fixed and tested old memmove() replacement and moved from curses to common. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=dcb4542f5c8647cf1b9630ab89f00f7d08d84465;p=liskon_frotz.git Fixed and tested old memmove() replacement and moved from curses to common. --- diff --git a/Makefile b/Makefile index e20ed51..03972cd 100644 --- 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 diff --git a/src/common/Makefile b/src/common/Makefile index 00d36fa..bffa0e1 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -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 diff --git a/src/common/frotz.h b/src/common/frotz.h index b02f1a2..fb1eb34 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -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 index 0000000..e1ecfbb --- /dev/null +++ b/src/common/missing.c @@ -0,0 +1,46 @@ +/* + * missing.c - Assorted standard functions that may be missing on older systems + * Written by David Griffith + * + * 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 index 0000000..b622346 --- /dev/null +++ b/src/common/missing.h @@ -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 */ diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index 091e362..25fe4a7 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -5,6 +5,9 @@ * */ +#ifndef UX_FROTZ_H +#define UX_FROTZ_H + #include #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 */ diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index 00cd934..d4ec737 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -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