From aed0255eb75a8655d189ff14d408a55783ce4d84 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Sun, 30 Aug 2015 15:43:15 -0700 Subject: [PATCH] Added a private implementation of strrchr(3) for systems that lack it. --- Makefile | 8 +++++++- src/curses/ux_frotz.h | 4 ++++ src/curses/ux_init.c | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ec38050..507cc58 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,12 @@ CURSES = -lcurses # #CURSES_DEF = -DUSE_NCURSES_H +# Uncomment this if youy'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. +# +#STRRCHR_DEF = -DNO_STRRCHR + # 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. @@ -187,7 +193,7 @@ OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \ -DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\"" CURSES_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \ - $(MEMMOVE_DEF) + $(MEMMOVE_DEF) $(STRRCHR_DEF) $(NAME): $(NAME)-curses diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index c780e36..1985053 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -95,6 +95,10 @@ void unix_do_scrollback(void); /* ux_screen.c */ FILE *pathopen(const char *, const char *, const char *, char *); +#ifdef NO_STRRCHR +char *strrchr(const char *, int); +#endif + #ifdef NO_MEMMOVE void *memmove(void *, void *); #endif diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index b1d3fac..57f154d 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -1087,3 +1087,23 @@ int ux_init_blorb(void) return blorb_err; } } + +#ifdef NO_STRRCHR +/* + * This is for operating systems that lack strrchr(3). + * + */ +char *strrchr(const char *s, int c) +{ + const char *save; + + if (c == 0) return (char *)s + strlen(s); + save = 0; + while (*s) { + if (*s == c) + save = s; + s++; + } + return (char *)save; +} +#endif -- 2.34.1