Skip to content

Support alternate directory (e.g. mods/text) for customized text (e.g. menu) files

Use 'mods/text' since mods is already where other modified files are expected to be placed. And don't use 'text/mods' since that would potentially create issues when the 'text' directory is in a Git repo.

We could do this automatically for menu() files without issue, but printfile() should require a new mode flag (P_MODS) to enable this behavior, otherwise, it'd be pretty impossible to display files in the stock text directory otherwise:

 /* for pauses, aborts and ANSI. 'str' is the path of the file to print      */
 /* Called from functions menu and text_sec                                  */
 /****************************************************************************/
-bool sbbs_t::printfile(const char* fname, int mode, int org_cols, JSObject* obj)
+bool sbbs_t::printfile(const char* inpath, int mode, int org_cols, JSObject* obj)
 {
        char* buf;
        char  fpath[MAX_PATH + 1];
@@ -45,7 +45,16 @@ bool sbbs_t::printfile(const char* fname, int mode, int org_cols, JSObject* obj)
        int   l, length, savcon = console;
        FILE *stream;

-       SAFECOPY(fpath, fname);
+       if (FULLPATH(fpath, inpath, sizeof fpath) == NULL)
+               SAFECOPY(fpath, inpath);
+       if ((mode & P_MODS) && cfg.mods_dir[0] != '\0') {
+               if (strncmp(fpath, cfg.text_dir, strlen(cfg.text_dir)) == 0) {
+                       char modpath[MAX_PATH + 1];
+                       snprintf(modpath, sizeof modpath, "%s%s", cfg.mods_dir, fpath + strlen(cfg.text_dir));
+                       if(fexistcase(modpath))
+                               SAFECOPY(fpath, modpath);
+               }
+       }

This would allow @include:filename@ to display a file from a mods/text dir if we also did the following in sbbs_t::atcode():

	if (!strncmp(sp, "INCLUDE:", 8)) {
		printfile(cmdstr(sp + 8, nulstr, nulstr, str), P_NOCRLF | P_SAVEATR | P_MODS);
		return nulstr;
	}

random_menu() would need a change like this:

@@ -374,6 +383,12 @@ bool sbbs_t::random_menu(const char *name, int mode, JSObject* obj)
        str_list_t names = NULL;

        SAFEPRINTF2(path, "%smenu/%s", cfg.text_dir, name);
+       if (cfg.mods_dir[0] != '\0') {
+               char modpath[MAX_PATH + 1];
+               SAFEPRINTF2(modpath, "%stext/menu/%s", cfg.mods_dir, name);
+               if (fexist(modpath))
+                       SAFECOPY(path, modpath);
+       }
        if (glob(path, GLOB_NOESCAPE | GLOB_MARK, NULL, &g) != 0) {
                return false;
        }

menu_exists() and menu() would need a lot of changes that will be tricky to test.

Edited by Rob Swindell