From 5c3597eafb15cde48941830d0ded921aed3f3c82 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Wed, 16 Oct 2019 23:30:11 -0700 Subject: [PATCH] Allow .sfrotzrc to have fontdir specified relative to $HOME. --- doc/sfrotz.6 | 4 +++- src/sdl/sf_fonts.c | 4 ++-- src/sdl/sf_frotz.h | 6 ++++++ src/sdl/sf_resource.c | 31 +++++++++++++++++++++++++++++++ src/sdl/sf_util.c | 6 ------ 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/doc/sfrotz.6 b/doc/sfrotz.6 index d0a1a4d..4797cbc 100644 --- a/doc/sfrotz.6 +++ b/doc/sfrotz.6 @@ -585,7 +585,9 @@ Note that this option cannot be overridden by a command line switch. fontdir = .I folder .br -Specify the directory containing the Truetype fonts. +Specify the directory containing the Truetype fonts. If this does not +begin with a slash, then the directory is assumed to be relative to the +user's home directory. .HP 2 textroman = diff --git a/src/sdl/sf_fonts.c b/src/sdl/sf_fonts.c index 640b117..748c6e5 100644 --- a/src/sdl/sf_fonts.c +++ b/src/sdl/sf_fonts.c @@ -943,8 +943,8 @@ void sf_initfonts() : NULL); if (!b) fprintf(stderr, - "WARNING: could not load font%d [%s]\n", - i, m_fontfiles[i]); + "WARNING: could not load font%d [%s%c%s]\n", + i, m_fontdir, PATH_SEPARATOR, m_fontfiles[i]); else { setfontk(i, b); b->refcount = 1; diff --git a/src/sdl/sf_frotz.h b/src/sdl/sf_frotz.h index 0b4c962..ccb767e 100644 --- a/src/sdl/sf_frotz.h +++ b/src/sdl/sf_frotz.h @@ -39,6 +39,12 @@ bool sf_IsAdaptive(int picture); #define PATH1 "ZCODE_PATH" #define PATH2 "INFOCOM_PATH" +#ifdef WIN32 +#define HOMEDIR "USERPROFILE" +#else +#define HOMEDIR "HOME" +#endif + /* this assumes RGBA with lsb = R */ static inline ulong RGB5ToTrue(word w) { diff --git a/src/sdl/sf_resource.c b/src/sdl/sf_resource.c index 3a6f902..9e34a84 100644 --- a/src/sdl/sf_resource.c +++ b/src/sdl/sf_resource.c @@ -436,6 +436,37 @@ void sf_readsettings(void) m_gamma = sf_GetProfileDouble("Display", "Gamma", DEFAULT_GAMMA); sf_initcolours(); + fprintf(stderr, "m_fontdir == %s\n", m_fontdir); + + /* If the leading character of m_fontdir is not PATH_SEPARATOR, + * we should look in $HOME for our font files and directories. + */ + if (m_fontdir[0] != PATH_SEPARATOR) { + char *m_fontdir_temp; + char *myhome; + char path_separator[2]; + size_t fontdir_len, homedir_len; + + myhome = getenv(HOMEDIR); + path_separator[0] = PATH_SEPARATOR; + path_separator[1] = 0; + + fontdir_len = strlen(m_fontdir); + homedir_len = strlen(myhome); + + m_fontdir_temp = malloc(((fontdir_len + homedir_len) * sizeof(char)) + 3); + strncpy(m_fontdir_temp, myhome, homedir_len + 1); + strncat(m_fontdir_temp, path_separator, 2); + + if ((m_fontdir[0] == '~') && (m_fontdir[1] == PATH_SEPARATOR)) + strncat(m_fontdir_temp,m_fontdir + 2, fontdir_len); + else + strncat(m_fontdir_temp,m_fontdir, fontdir_len); + + free(m_fontdir); + m_fontdir = strdup(m_fontdir_temp); + } + sf_FinishProfile(); } diff --git a/src/sdl/sf_util.c b/src/sdl/sf_util.c index 6ca2065..eab42cf 100644 --- a/src/sdl/sf_util.c +++ b/src/sdl/sf_util.c @@ -809,12 +809,6 @@ void sf_FinishProfile() } -#ifdef WIN32 -#define HOMEDIR "USERPROFILE" -#else -#define HOMEDIR "HOME" -#endif - void sf_InitProfile(const char *fn) { FILE *f; -- 2.34.1