Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Patch: -configdir option for Unix

2 views
Skip to first unread message

Dan McGuirk

unread,
Apr 14, 1998, 3:00:00 AM4/14/98
to mozilla-patches

This patch adds a '-configdir' command line option to the XFE that allows
you to specify another directory to be used instead of '~/.netscape'.
E.g., run "mozilla -configdir .mozilla" and everything will be stored in
'~/.mozilla'. This is helpful if you're trying to debug Mozilla and run a
"regular" Netscape at the same time without them interfering with each
other. (Now I don't have to be jealous of Windows people with their
-P"profile" :))

If you copy your ~/.netscape to something else, make sure you change any
references to ~/.netscape in your preferences.js file. Also make sure you
don't have any old preferences files like ~/.netscape-preferences or
~/.netscape/preferences around, as that can cause some confusion.

Three functions were added to the fe code, and all hardcoded references to
'~/.netscape' changed to go through them:

char *fe_GetConfigDir(void);
char *fe_GetConfigDirFilename(char *filename);
char *fe_GetConfigDirFilenameWithPrefix(char *prefix, char *filename);

The first just returns the name of the '~/.netscape'-equivalent directory.
The last two are for convenience, returning the name of a file in the
above mentioned directory, or the name of a file there with a prefix (e.g.
"file://"). This is so you don't have to create your own fixed-length
static buffer and sprintf into it, as was being done in so many places in
the code. These functions return malloc'd strings that should be freed by
the caller.

Comments are appreciated.


Index: cmd/xfe/addrbk.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/addrbk.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 addrbk.c
--- addrbk.c 1998/03/31 21:25:24 1.1.1.1
+++ addrbk.c 1998/04/13 08:36:36
@@ -103,55 +103,58 @@
{

static XP_List *directories = NULL;
- char oldFile[1024];
+ char *oldFile;
XP_File oldFp = 0;

- char tmp[1024];
+ char *tmp;
char *home = getenv("HOME");
/*DIR_Server *dir;*/

if (!home) home = "";

- PR_snprintf(oldFile, sizeof (oldFile), "%.900s/.netscape/addrbook.db", home);
- oldFp = XP_FileOpen(oldFile, xpAddrBook, "r");
- if (oldFp) {
- char newFile[256];
- XP_File newFp = 0;
-
- /* extern int XP_FileClose(XP_File file);
- */
- XP_FileClose(oldFp);
-
- PR_snprintf(newFile, sizeof (newFile), "%s", "abook.nab");
- newFp = XP_FileOpen(newFile, xpAddrBookNew, "r");
- if (!newFp) {
- /* Rename file for backward compatibility reason
- * extern int XP_FileRename(const char * from, XP_FileType fromtype,
- * const char * to, XP_FileType totype);
- */
- XP_FileRename(oldFile, xpAddrBook,
- newFile, xpAddrBookNew);
- }/* !newFp */
- else
- XP_FileClose(newFp);
-
- }/* if */
+ oldFile = fe_GetConfigDirFilename("addrbook.db");
+ if(oldFile) {
+ oldFp = XP_FileOpen(oldFile, xpAddrBook, "r");
+ if (oldFp) {
+ char newFile[256];
+ XP_File newFp = 0;
+
+ /* extern int XP_FileClose(XP_File file);
+ */
+ XP_FileClose(oldFp);
+
+ PR_snprintf(newFile, sizeof (newFile), "%s", "abook.nab");
+ newFp = XP_FileOpen(newFile, xpAddrBookNew, "r");
+ if (!newFp) {
+ /* Rename file for backward compatibility reason
+ * extern int XP_FileRename(const char * from, XP_FileType fromtype,
+ * const char * to, XP_FileType totype);
+ */
+ XP_FileRename(oldFile, xpAddrBook,
+ newFile, xpAddrBookNew);
+ }/* !newFp */
+ else
+ XP_FileClose(newFp);
+ }/* if */
+ free(oldFile);
+ }

/* all right, lets do the list of directories and stuff */
directories = XP_ListNew();

/* first the addressbook stuff */
/* database file is not html anymore ... */
- PR_snprintf(tmp, sizeof (tmp), "abook.nab");
+ DIR_GetServerPreferences (&directories, "abook.nab");

- DIR_GetServerPreferences (&directories, tmp);
- PR_snprintf(tmp, sizeof (tmp),
- "%.900s/.netscape/address-book.html", home);
- {
- DIR_Server *pabDir = NULL;
- DIR_GetPersonalAddressBook(directories, &pabDir);
- AB_InitializeAddressBook(pabDir, &AddrBook, tmp);
- }
+ tmp = fe_GetConfigDirFilename("address-book.html");
+ if(tmp) {
+ {
+ DIR_Server *pabDir = NULL;
+ DIR_GetPersonalAddressBook(directories, &pabDir);
+ AB_InitializeAddressBook(pabDir, &AddrBook, tmp);
+ }
+ free(tmp);
+ }
}

void FE_CloseAddrBook() {
Index: cmd/xfe/fonts.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/fonts.c,v
retrieving revision 1.2
diff -u -r1.2 fonts.c
--- fonts.c 1998/04/12 05:54:54 1.2
+++ fonts.c 1998/04/13 23:47:22
@@ -1749,18 +1749,16 @@

void fe_ShutdownWebfonts(void)
{
- char buf[MAXPATHLEN];
- char *home = NULL;
+ char *buf;

/* Load Catalog */
- if (home = getenv("HOME"))
+
+ /* Form "$HOME/.netscape/dynfonts/fonts.cat" into buf */
+ buf = fe_GetConfigDirFilename("dynfonts/fonts.cat");
+ if (buf)
{
- /* Form "$HOME/.netscape/dynfonts/fonts.cat" into buf */
- strncpy(buf, home, sizeof(buf)-1);
- strncat(buf, "/.netscape/dynfonts/fonts.cat",
- sizeof(buf)-1 - strlen(buf));
- buf[sizeof(buf)-1] = '\0';
- nffbu_SaveCatalog(fe_FontUtility, buf, NULL);
+ nffbu_SaveCatalog(fe_FontUtility, buf, NULL);
+ free(buf);
}
}

@@ -3669,7 +3667,6 @@

#ifndef NO_WEB_FONTS

-#define WF_FONT_DISPLAYER_PATH_1 "~/.netscape/dynfonts"
#define WF_FONT_DISPLAYER_PATH_4 "/usr/local/lib/netscape/dynfonts"

/* This static is outside of fe_InitializeWebfonts() 'cause HPUX has a
@@ -3685,7 +3682,7 @@
struct nffbp *fbp;
char buf[MAXPATHLEN];
char *mozilla_home = NULL;
- char *home = NULL;
+ char *pathname;

/* Initialize and obtain the font broker and font utility provider. */
fe_FontBroker = NF_FontBrokerInitialize();
@@ -3693,14 +3690,13 @@
nffbc_getInterface(fe_FontBroker, &nffbu_ID, NULL);

/* Load Catalog */
- if (home = getenv("HOME"))
+
+ /* Form "$HOME/.netscape/dynfonts/fonts.cat" into buf */
+ pathname = fe_GetConfigDirFilename("dynfonts/fonts.cat");
+ if (pathname)
{
- /* Form "$HOME/.netscape/dynfonts/fonts.cat" into buf */
- strncpy(buf, home, sizeof(buf)-1);
- strncat(buf, "/.netscape/dynfonts/fonts.cat",
- sizeof(buf)-1 - strlen(buf));
- buf[sizeof(buf)-1] = '\0';
- nffbu_LoadCatalog(fe_FontUtility, buf, NULL);
+ nffbu_LoadCatalog(fe_FontUtility, pathname, NULL);
+ free(pathname);
}

/* Load all font displayers */
@@ -3718,7 +3714,10 @@
* the same name exists in more than one directory, then the
* first one takes priority.
*/
- nffbp_ScanForFontDisplayers(fbp, WF_FONT_DISPLAYER_PATH_1, NULL);
+ /* WF_FONT_DISPLAYER_PATH_1 */
+ pathname = fe_GetConfigDirFilename("dynfonts");
+ nffbp_ScanForFontDisplayers(fbp, pathname, NULL);
+ free(pathname);

/* WF_FONT_DISPLAYER_PATH_2 */
if (mozilla_home = getenv("MOZILLA_HOME"))
Index: cmd/xfe/mozilla.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/mozilla.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 mozilla.c
--- mozilla.c 1998/03/31 21:25:28 1.1.1.1
+++ mozilla.c 1998/04/14 04:30:25
@@ -368,6 +368,8 @@
{ "-no-irix-session-management", ".irixSessionManagement", XrmoptionNoArg, "False" },

{ "-dont-force-window-stacking", ".dontForceWindowStacking", XrmoptionNoArg, "True" },
+
+ { "-configdir", ".configdir", XrmoptionSepArg, NULL },
};

extern char *fe_fallbackResources[];
@@ -807,9 +809,13 @@
#if (defined(IRIX) && !defined(IRIX6_2) && !defined(IRIX6_3))
(XtPointer) False },
#else
- (XtPointer) True }
+ (XtPointer) True },
#endif

+ { "configdir", XtCString, XtRString, sizeof (String),
+ XtOffset (fe_GlobalData *, configdir), XtRString,
+ ".netscape" },
+
# undef RES_ERROR
};
Cardinal fe_GlobalResourcesSize = XtNumber (fe_GlobalResources);
@@ -837,6 +843,36 @@
fprintf (stderr, XP_GetString( XFE_USAGE_MSG5 ) );
}

+char *fe_GetConfigDirFilename(char *filename)
+{
+ return fe_GetConfigDirFilenameWithPrefix("", filename);
+}
+
+char *fe_GetConfigDirFilenameWithPrefix(char *prefix, char *filename)
+{
+ return PR_smprintf("%s%s/%s", prefix, fe_GetConfigDir(), filename);
+}
+
+char *fe_GetConfigDir(void)
+{
+ char *result, *home;
+
+ home = getenv("HOME");
+ if(!home) {
+ struct passwd *pw = getpwuid(getuid());
+
+ home = pw ? pw->pw_dir : "/";
+ }
+
+ if(fe_globalData.configdir) {
+ result = PR_smprintf("%s/%s", home, fe_globalData.configdir);
+ } else {
+ result = PR_smprintf("%s/.netscape", home);
+ }
+
+ return result;
+}
+
/*******************
* Signal handlers *
*******************/
@@ -1808,7 +1844,7 @@
Screen *fe_screen_kludge;

static char *fe_home_dir;
-static char *fe_config_dir;
+static char *fe_config_dir = 0;

/*
* build_simple_user_agent_string
@@ -2362,17 +2398,25 @@
while ((slash = strrchr(fe_home_dir, '/')) && slash[1] == '\0')
*slash = '\0';
}
+
+ toplevel = XtAppInitialize (&fe_XtAppContext, (char *) fe_progclass, options,
+ sizeof (options) / sizeof (options [0]),
+ &argc, argv, fe_fallbackResources, 0, 0);
+
+ fe_InitializeGlobalResources(toplevel);
+#ifdef DEBUG_djm
+ fprintf(stderr, "we got a configdir of '%s'\n", fe_globalData.configdir);
+#endif
+ fe_ensure_config_dir_exists(toplevel);
+
{
- char buf [1024];
- PR_snprintf (buf, sizeof (buf), "%s/%s", fe_home_dir,
#ifdef OLD_UNIX_FILES
- ".netscape-preferences"
-#else
- ".netscape/preferences.js"
+ char buf [1024];
+ PR_snprintf (buf, sizeof (buf), "%s/%s", fe_home_dir, ".netscape-preferences");
+ fe_globalData.user_prefs_file = strdup(buf);
+#else
+ fe_globalData.user_prefs_file = fe_GetConfigDirFilename("preferences.js");
#endif
- );
-
- fe_globalData.user_prefs_file = strdup (buf);

PREF_Init((char*) fe_globalData.user_prefs_file);
}
@@ -2381,12 +2425,6 @@
fe_mailNewsPrefs = MSG_CreatePrefs();
#endif

- toplevel = XtAppInitialize (&fe_XtAppContext, (char *) fe_progclass, options,
- sizeof (options) / sizeof (options [0]),
- &argc, argv, fe_fallbackResources, 0, 0);
-
-
-
FE_SetToplevelWidget(toplevel);

/* we need to set the drag/drop protocol style to dynamic
@@ -2610,7 +2648,7 @@
unsigned long addr;
pid_t pid;

- name = PR_smprintf ("%s/lock", fe_config_dir);
+ name = fe_GetConfigDirFilename("lock");
addr = 0;
pid = 0;
if (name == NULL)
@@ -2627,6 +2665,10 @@
else
{
char *fmt = NULL;
+ /* the hardcoded value below is only used if memory couldn't be */
+ /* allocated for the real filename. extremely unlikely, and */
+ /* if it happens, the program should probably just crash anyway */
+ /* because it's not going to be able to do much else. */
char *lock = name ? name : ".netscape/lock";

fmt = PR_sprintf_append(fmt, XP_GetString(XFE_APP_HAS_DETECTED_LOCK),
@@ -2695,7 +2737,11 @@
sigfillset(&act.sa_mask);
sigaction (SIGCHLD, &act, NULL);

- fe_InitializeGlobalResources (toplevel);
+ /* Add a timer to periodically flush out the global history and bookmark. */
+ fe_save_history_timer ((XtPointer) ((int) True), 0);
+
+ /* #### move to prefs */
+ LO_SetUserOverride (!fe_globalData.document_beats_user_p);

#ifndef OLD_UNIX_FILES

@@ -2741,11 +2787,14 @@
}

{
- char buf [1024];
- PR_snprintf (buf, sizeof (buf), "%s/%s", fe_home_dir, ".netscape/user.js");
- PREF_ReadUserJSFile(buf);
- PR_snprintf (buf, sizeof (buf), "%s/%s", fe_home_dir, ".netscape/hook.js");
- HK_ReadHookFile(buf);
+ char *buf;
+ buf = fe_GetConfigDirFilename("user.js");
+ PREF_ReadUserJSFile(buf);
+ free(buf);
+
+ buf = fe_GetConfigDirFilename("hooks.js");
+ HK_ReadHookFile(buf);
+ free(buf);
}

fe_startDisplayFactory(toplevel);
@@ -3488,7 +3537,10 @@
struct stat st;
XP_Bool exists;

- dir = PR_smprintf ("%s/.netscape", fe_home_dir);
+ if(fe_config_dir)
+ return TRUE;
+
+ dir = fe_GetConfigDir();
if (!dir)
return FALSE;

@@ -3742,21 +3794,18 @@
struct stat st1;
struct stat st2;
char file1 [512];
- char file2 [512];
- char *s1, *s2;
+ char *file2, *s1, *configdir_filename;

if (!fe_config_dir)
/* If we were unable to cause ~/.netscape/ to exist, give up now. */
return;

PR_snprintf (file1, sizeof (file1), "%s/", fe_home_dir);
- strcpy (file2, file1);
s1 = file1 + strlen (file1);
- s2 = file2 + strlen (file2);

#define FROB(OLD1, OLD2, NEW, PERMS) \
strcpy (s1, OLD1); \
- strcpy (s2, NEW); \
+ file2 = NEW; \
if (!stat (file2, &st2)) \
; /* new exists - leave it alone */ \
else if (!stat (file1, &st1)) \
@@ -3774,19 +3823,32 @@
} \
}

- FROB(".netscape-preferences",
- ".MCOM-preferences",
- ".netscape/preferences",
- 0)
- FROB(".netscape-bookmarks.html",
- ".MCOM-bookmarks.html",
- ".netscape/bookmarks.html",
- 0)
-
- FROB(".netscape-cookies",
- ".MCOM-HTTP-cookie-file",
- ".netscape/cookies",
- (S_IRUSR | S_IWUSR)) /* rw only by owner */
+ configdir_filename = fe_GetConfigDirFilename("preferences");
+ if(configdir_filename) {
+ FROB(".netscape-preferences",
+ ".MCOM-preferences",
+ configdir_filename,
+ 0)
+ free(configdir_filename);
+ }
+
+ configdir_filename = fe_GetConfigDirFilename("bookmarks.html");
+ if(configdir_filename) {
+ FROB(".netscape-bookmarks.html",
+ ".MCOM-bookmarks.html",
+ configdir_filename,
+ 0)
+ free(configdir_filename);
+ }
+
+ configdir_filename = fe_GetConfigDirFilename("cookies");
+ if(configdir_filename) {
+ FROB(".netscape-cookies",
+ ".MCOM-HTTP-cookie-file",
+ configdir_filename,
+ (S_IRUSR | S_IWUSR)) /* rw only by owner */
+ free(configdir_filename);
+ }

#undef FROB
}
@@ -3822,8 +3884,7 @@
/* spider begin */
/* TODO: where does this string get free'd? */
if (fe_globalPrefs.sar_cache_dir) free (fe_globalPrefs.sar_cache_dir);
- PR_snprintf (buf, sizeof (buf), "%s/.netscape/archive/", fe_home_dir);
- fe_globalPrefs.sar_cache_dir = strdup (buf);
+ fe_globalPrefs.sar_cache_dir = fe_GetConfigDirFilename("archive/");
/* spider end */

if (!fe_copied_init_files)
@@ -3832,12 +3893,10 @@
/* History and cache always go in the new place by default,
no matter what they were set to before. */
if (fe_globalPrefs.history_file) free (fe_globalPrefs.history_file);
- PR_snprintf (buf, sizeof (buf), "%s/.netscape/history.db", fe_home_dir);
- fe_globalPrefs.history_file = strdup (buf);
+ fe_globalPrefs.history_file = fe_GetConfigDirFilename("history.db");

if (fe_globalPrefs.cache_dir) free (fe_globalPrefs.cache_dir);
- PR_snprintf (buf, sizeof (buf), "%s/.netscape/cache/", fe_home_dir);
- fe_globalPrefs.cache_dir = strdup (buf);
+ fe_globalPrefs.cache_dir = fe_GetConfigDirFilename("cache/");

/* If they were already keeping their bookmarks file in a different
place, don't change that preferences setting. */
@@ -3846,9 +3905,7 @@
!XP_STRCMP (fe_globalPrefs.bookmark_file, buf))
{
if (fe_globalPrefs.bookmark_file) free (fe_globalPrefs.bookmark_file);
- PR_snprintf (buf, sizeof (buf), "%s/.netscape/bookmarks.html",
- fe_home_dir);
- fe_globalPrefs.bookmark_file = strdup (buf);
+ fe_globalPrefs.bookmark_file = fe_GetConfigDirFilename("bookmarks.html");
}

/* If their home page was set to their bookmarks file (and that was
@@ -3859,9 +3916,9 @@
!XP_STRCMP (fe_globalPrefs.home_document, buf))
{
if (fe_globalPrefs.home_document) free (fe_globalPrefs.home_document);
- PR_snprintf (buf, sizeof (buf), "file:%s/.netscape/bookmarks.html",
- fe_home_dir);
- fe_globalPrefs.home_document = strdup (buf);
+ fe_globalPrefs.home_document =
+ fe_GetConfigDirFilenameWithPrefix("file:", /* or "file://"? */
+ "bookmarks.html");
}

fe_copied_init_files = FALSE;
Index: cmd/xfe/name.h
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/name.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 name.h
--- name.h 1998/03/31 21:25:28 1.1.1.1
+++ name.h 1998/04/13 06:08:02
@@ -24,7 +24,7 @@
#define XFE_NAME Netscape
#define XFE_PROGNAME netscape
#define XFE_PROGCLASS Netscape
-#define XFE_LEGALESE "(c) 1995-1997 Netscape Communications Corp."
+#define XFE_LEGALESE "(c) 1995-1998 Netscape Communications Corp."

/* I don't pretend to understand this. */
#define cpp_stringify_noop_helper(x)#x
Index: cmd/xfe/xfe.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/xfe.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 xfe.c
--- xfe.c 1998/03/31 21:25:30 1.1.1.1
+++ xfe.c 1998/04/13 08:51:58
@@ -136,7 +136,7 @@

void fe_delete_cb (Widget, XtPointer, XtPointer);

-static void fe_save_history_timer (XtPointer closure, XtIntervalId *id);
+void fe_save_history_timer (XtPointer closure, XtIntervalId *id);
extern void fe_MakeAddressBookWidgets(Widget shell, MWContext *context);

extern void fe_ab_destroy_cb (Widget, XtPointer, XtPointer);
@@ -1971,12 +1971,6 @@
else
fe_globalData.wm_icon_policy = "color";
}
-
- /* Add a timer to periodically flush out the global history and bookmark. */
- fe_save_history_timer ((XtPointer) ((int) True), 0);
-
- /* #### move to prefs */
- LO_SetUserOverride (!fe_globalData.document_beats_user_p);
}


@@ -2096,7 +2090,7 @@
}


-static void
+void
fe_save_history_timer (XtPointer closure, XtIntervalId *id)
{
Boolean init_only_p = (Boolean) ((int) closure);
@@ -3364,10 +3358,14 @@
char* fe_GetLDAPTmpFile(char *name) {
char* home = getenv("HOME");
static char tmp[1024];
+ char *configdir;
+
if (!home) home = "";
if (!name) return NULL;

- sprintf(tmp, "%.900s/.netscape/", home);
+ configdir = fe_GetConfigDirFilename("");
+ strcpy(tmp, configdir);
+ free(configdir);

#ifdef _XP_TMP_FILENAME_FOR_LDAP_
/* we need to write this */
Index: cmd/xfe/xfe.h
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/xfe.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 xfe.h
--- xfe.h 1998/03/31 21:25:30 1.1.1.1
+++ xfe.h 1998/04/13 08:52:28
@@ -610,6 +610,12 @@

extern void fe_PrimarySelectionFetchURL(MWContext *context);

+/* return the name of the config directory (e.g. ~/.netscape)
+ or files therein. */
+extern char *fe_GetConfigDir(void);
+extern char *fe_GetConfigDirFilename(char *filename);
+extern char *fe_GetConfigDirFilenameWithPrefix(char *prefix, char *filename);
+
/*
* Search Callback
*/
@@ -1417,6 +1423,8 @@
Boolean all_databases_locked;

Cardinal editor_update_delay;
+
+ String configdir;
} fe_GlobalData;

extern fe_GlobalData fe_globalData;
@@ -2015,6 +2023,8 @@
extern MWContext* fe_FindNonCustomBrowserContext(MWContext *context);

extern void fe_DisplayFactoryColormapGoingAway(fe_colormap *);
+
+extern void fe_save_history_timer (XtPointer closure, XtIntervalId *id);

#ifdef __cplusplus
}
Index: cmd/xfe/src/MozillaApp.cpp
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/src/MozillaApp.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 MozillaApp.cpp
--- MozillaApp.cpp 1998/03/31 21:26:06 1.1.1.1
+++ MozillaApp.cpp 1998/04/13 08:37:05
@@ -1044,38 +1044,6 @@
XBell(XtDisplay(w), 0);
}

-// Stole this from xp_file.c
-static const char *
-fe_config_directory(char* buf)
-{
- static XP_Bool initted = FALSE;
- const char *dir = ".netscape";
- char *home;
- if (initted)
- return buf;
-
- home = getenv ("HOME");
- if (!home)
- home = "";
-
-#ifdef OLD_UNIX_FILES
-
- sprintf (buf, "%.900s", home);
- if (buf[strlen(buf)-1] == '/')
- buf[strlen(buf)-1] = 0;
-
-#else /* !OLD_UNIX_FILES */
-
- if (*home && home[strlen(home)-1] == '/')
- sprintf (buf, "%.900s%s", home, dir);
- else
- sprintf (buf, "%.900s/%s", home, dir);
-
-#endif /* !OLD_UNIX_FILES */
-
- return buf;
-}
-
typedef enum {
XFE_STAT_ISDIR,
XFE_STAT_ISREG
@@ -1183,8 +1151,7 @@
#endif
int filePrefixLen;
char *nethelpSuffix = "nethelp/";
- static char configBuf[1024];
- const char *conf_dir = fe_config_directory(configBuf);
+ char *conf_dir = fe_GetConfigDir();
char *helpPath = getenv("NS_NETHELP_PATH");
char *mozHome = getenv("MOZILLA_HOME");
char *lang = getenv("LANG");
@@ -1211,6 +1178,7 @@
// Found it - result already copied into nethelpDir
;
}
+ free(conf_dir);

// Found it or not, we return a valid URL
return XP_STRDUP(nethelpDir);
Index: cmd/xfe/src/Netcaster.cpp
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/src/Netcaster.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Netcaster.cpp
--- Netcaster.cpp 1998/03/31 21:26:07 1.1.1.1
+++ Netcaster.cpp 1998/04/13 08:37:13
@@ -152,6 +152,7 @@
* Netcaster by checking
* the following locations in order:
* $HOME/.netscape/netcast/tab.htm
+ * (now <configdir>/netcast/tab.htm)
* $MOZILLA_HOME/netcast/tab.htm
* Version Registry via VR_GetPath()
* fe_GetProgramDirectory()/netcast/tab.htm
@@ -190,16 +191,7 @@
char * home;
REGERR code;

- if (!private_xfe_netcaster_path)
- {
- private_xfe_netcaster_path = (char*)XP_ALLOC(MAXPATHLEN);
- if (private_xfe_netcaster_path)
- private_xfe_netcaster_path[0] = '\0';
- else
- return result;
- }
-
- if (private_xfe_netcaster_path[0])
+ if (private_xfe_netcaster_path && private_xfe_netcaster_path[0])
{
result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
@@ -208,28 +200,29 @@
return result;
}

+ /* who knows what was here before */
+ if (private_xfe_netcaster_path)
+ XP_FREE(private_xfe_netcaster_path);

//
// CHECK $HOME/.netscape
//
- home = getenv("HOME");
- if (home)
- {
- XP_STRCPY(private_xfe_netcaster_path, home);
- if (xfe_last_character(private_xfe_netcaster_path) != '/')
- XP_STRCAT(private_xfe_netcaster_path,"/");
- XP_STRCAT(private_xfe_netcaster_path,".netscape/");
- XP_STRCAT(private_xfe_netcaster_path,netcasterTabHtmlPath);
- if (xfe_path_exists(private_xfe_netcaster_path))
- {
- result = private_xfe_netcaster_path;
+ private_xfe_netcaster_path = fe_GetConfigDirFilename(netcasterTabHtmlPath);
+ if (private_xfe_netcaster_path &&
+ xfe_path_exists(private_xfe_netcaster_path))
+ {
+ result = private_xfe_netcaster_path;
#ifdef DEBUG_rodt
- printf("DEBUG_rodt: Netcaster path b %s\n",result);
+ printf("DEBUG_rodt: Netcaster path b %s\n",result);
#endif
- return result;
- }
- }
+ return result;
+ }

+ private_xfe_netcaster_path = (char*)XP_ALLOC(MAXPATHLEN);
+ if (private_xfe_netcaster_path)
+ private_xfe_netcaster_path[0] = '\0';
+ else
+ return result;

//
// CHECK $MOZILLA_HOME
Index: cmd/xfe/src/SpellHandler.cpp
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/src/SpellHandler.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 SpellHandler.cpp
--- SpellHandler.cpp 1998/03/31 21:26:10 1.1.1.1
+++ SpellHandler.cpp 1998/04/14 00:06:55
@@ -412,25 +412,17 @@
char *
XFE_SpellHandler::getSpellCheckerDir()
{
- char *home = NULL;
+ char *configdir_spelldir;
char *mozilla_home = NULL;
char buf[MAXPATHLEN];

-
- if (home = getenv("HOME")) {
- XP_MEMSET(buf, '\0', sizeof(buf));
-
- // Form "$HOME/.netscape/spell/" into buf...
- //
- XP_STRNCPY_SAFE(buf, home, sizeof(buf)-1);
- XP_STRNCAT_SAFE(buf, "/.netscape/spell/",
- sizeof(buf)-1 - XP_STRLEN(buf));
- buf[sizeof(buf)-1] = '\0';
-
- if (fe_isDir(buf)) {
- return XP_STRDUP(buf);
- }
- }
+ // check the "$HOME/.netscape"-type directory
+ configdir_spelldir = fe_GetConfigDirFilename("spell/");
+ if(configdir_spelldir) {
+ if(fe_isDir(configdir_spelldir))
+ return configdir_spelldir;
+ free(configdir_spelldir);
+ }

if (mozilla_home = getenv("MOZILLA_HOME")) {
XP_MEMSET(buf, '\0', sizeof(buf));
@@ -478,19 +470,7 @@
char *
XFE_SpellHandler::getPersonalDicPath()
{
- char buf[MAXPATHLEN];
- char *home = NULL;
-
- if (home = getenv("HOME"))
- {
- /* Form "$HOME/.netscape/custom.dic" into buf */
- XP_STRNCPY_SAFE(buf, home, sizeof(buf)-1);
- XP_STRNCAT_SAFE(buf, "/.netscape/custom.dic",
- sizeof(buf)-1 - XP_STRLEN(buf));
- buf[sizeof(buf)-1] = '\0';
- }
-
- return XP_STRDUP(buf);
+ return fe_GetConfigDirFilename("custom.dic");
}

XP_Bool
Index: cmd/xfe/src/plugin.cpp
===================================================================
RCS file: /usr/local/cvsroot/mozilla/cmd/xfe/src/plugin.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 plugin.cpp
--- plugin.cpp 1998/03/31 21:26:11 1.1.1.1
+++ plugin.cpp 1998/04/13 08:37:27
@@ -724,14 +724,15 @@
void FE_RegisterPlugins()
{
#ifdef X_PLUGINS
- char filename[MAXPATHLEN];
- char newFilename[MAXPATHLEN];
- char oldFilename[MAXPATHLEN];
+ char *filename;
+ char *newFilename;
+ char *oldFilename;
char *npxPluginPath = getenv("NPX_PLUGIN_PATH");
char *mozHome = getenv("MOZILLA_HOME");
char *pluginPath = NULL;
char *home = getenv ("HOME");
-
+ char *configdir_pluginsdir = fe_GetConfigDirFilename("plugins");
+
if (!home)
home = "";
else if (!strcmp (home, "/"))
@@ -751,10 +752,10 @@
} else {
/* Stuff in $MOZILLA_HOME if it's defined. */
if(mozHome) {
- pluginPath = PR_smprintf("%s:%s/plugins:%.900s/.netscape/plugins",
- DEFAULT_LEGACY_PLUGIN_PATH,
- mozHome,
- home);
+ pluginPath = PR_smprintf("%s:%s/plugins:%s",
+ DEFAULT_LEGACY_PLUGIN_PATH,
+ mozHome,
+ configdir_pluginsdir);
} else {
/* Try to stuff argv[0] into the path */
char buf[MAXPATHLEN];
@@ -764,16 +765,17 @@
strncat(buf, "plugins", sizeof(buf)-1 - strlen(buf));
buf[sizeof(buf)-1] = '\0';

- pluginPath = PR_smprintf("%s:%s:%.900s/.netscape/plugins",
- DEFAULT_LEGACY_PLUGIN_PATH,
- buf,
- home);
+ pluginPath = PR_smprintf("%s:%s:%s",
+ DEFAULT_LEGACY_PLUGIN_PATH,
+ buf,
+ configdir_pluginsdir);
}
}
+ free(configdir_pluginsdir);

- PR_snprintf(filename, sizeof(filename), "%.900s/.netscape/plugin-list", home);
- PR_snprintf(newFilename, sizeof(newFilename), "%.900s/.netscape/plugin-list.new", home);
- PR_snprintf(oldFilename, sizeof(oldFilename), "%.900s/.netscape/plugin-list.BAK", home);
+ filename = fe_GetConfigDirFilename("plugin-list");
+ newFilename = fe_GetConfigDirFilename("plugin-list.new");
+ oldFilename = fe_GetConfigDirFilename("plugin-list.BAK");

if (pluginList == NULL) {
pluginList = getPluginList(32);
@@ -786,7 +788,11 @@
rename(filename, oldFilename);
rename(newFilename, filename);
}
-
+
+ free(filename);
+ free(newFilename);
+ free(oldFilename);
+
if (!npxPluginPath)
XP_FREE(pluginPath); /* Free if we used PR_smprintf(). */

Index: lib/xp/xp_file.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/lib/xp/xp_file.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 xp_file.c
--- xp_file.c 1998/03/31 21:24:39 1.1.1.1
+++ xp_file.c 1998/04/13 20:35:57
@@ -491,33 +491,20 @@
PUBLIC char *FE_GlobalHist = 0;


+/* these should probably be promoted to FE_* exported functions */
+/* but then other front-ends would (kind of) be required to */
+/* implement them. Unix front ends will already have to */
+/* this or they will break--other front ends wouldn't have to */
+/* necessarily implement the FE_* versions because they'll */
+/* never be called. */
+extern char *fe_GetConfigDir(void);
+
static const char *
xp_unix_config_directory(char* buf)
{
- static XP_Bool initted = FALSE;
- const char *dir = ".netscape";
- char *home;
- if (initted)
- return buf;
-
- home = getenv ("HOME");
- if (!home)
- home = "";
-
-#ifdef OLD_UNIX_FILES
-
- sprintf (buf, "%.900s", home);
- if (buf[strlen(buf)-1] == '/')
- buf[strlen(buf)-1] = 0;
-
-#else /* !OLD_UNIX_FILES */
-
- if (*home && home[strlen(home)-1] == '/')
- sprintf (buf, "%.900s%s", home, dir);
- else
- sprintf (buf, "%.900s/%s", home, dir);
-
-#endif /* !OLD_UNIX_FILES */
+ char *configdir = fe_GetConfigDir();
+ strcpy(buf, configdir);
+ free(configdir);

return buf;
}
@@ -1091,7 +1078,6 @@
char *policyFN = "moz40p3";
char *mozHome = getenv("MOZILLA_HOME");
char *lang = getenv("LANG");
- int result;
char dirName[1024];

name = buf;
Index: modules/libpref/src/unix/unix.js
===================================================================
RCS file: /usr/local/cvsroot/mozilla/modules/libpref/src/unix/unix.js,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 unix.js
--- unix.js 1998/03/31 21:24:51 1.1.1.1
+++ unix.js 1998/04/13 21:10:14
@@ -29,8 +29,6 @@
pref("mail.sort_by", 0);
pref("news.sort_by", 0);
pref("browser.startup.license_accepted", "");
-pref("browser.cache.directory", "~/.netscape/cache");
-pref("browser.sarcache.directory", "~/.netscape/sarcache");
pref("browser.cache.memory_cache_size", 3000);
pref("browser.cache.disk_cache_size", 5000);
pref("mail.directory", "~/nsmail/");
@@ -57,9 +55,6 @@
pref("news.cache_xover", false);
pref("news.show_first_unread", false);
pref("news.sash_geometry", "");
-pref("browser.bookmark_file", "~/.netscape/bookmarks.html");
-pref("browser.history_file", "~/.netscape/history.db");
-pref("browser.user_history_file", "~/.netscape/history.list");
pref("helpers.global_mime_types_file", "/usr/local/lib/netscape/mime.types");
pref("helpers.global_mailcap_file", "/usr/local/lib/netscape/mailcap");
pref("helpers.private_mime_types_file", "~/.mime.types");
Index: modules/libpref/src/unix/unixpref.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/modules/libpref/src/unix/unixpref.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 unixpref.c
--- unixpref.c 1998/03/31 21:24:51 1.1.1.1
+++ unixpref.c 1998/04/13 21:15:16
@@ -41,6 +41,8 @@
* Needed by PREF_Init.
* Sets the default preferences.
*/
+extern char *fe_GetConfigDirFilename(char *filename);
+
JSBool
pref_InitInitialObjects(void)
{
@@ -49,6 +51,18 @@
XP_ASSERT(pref_init_buffer);

status = PREF_EvaluateJSBuffer(pref_init_buffer, strlen(pref_init_buffer));
+
+ /* these strings never get freed, but that's probably the way it should be */
+ PREF_SetDefaultCharPref("browser.cache.directory",
+ fe_GetConfigDirFilename("cache"));
+ PREF_SetDefaultCharPref("browser.sarcache.directory",
+ fe_GetConfigDirFilename("sarcache"));
+ PREF_SetDefaultCharPref("browser.bookmark_file",
+ fe_GetConfigDirFilename("bookmarks.html"));
+ PREF_SetDefaultCharPref("browser.history_file",
+ fe_GetConfigDirFilename("history.db"));
+ PREF_SetDefaultCharPref("browser.user_history_file",
+ fe_GetConfigDirFilename("history.list"));

#if defined(__sgi) || (defined(__sun) && defined(__svr4__))
PREF_SetDefaultCharPref("print.print_command", "lp");
Index: nsprpub/pr/src/linking/prlink.c
===================================================================
RCS file: /usr/local/cvsroot/mozilla/nsprpub/pr/src/linking/prlink.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 prlink.c
--- prlink.c 1998/04/10 02:38:13 1.1.1.2
+++ prlink.c 1998/04/13 08:15:41
@@ -309,6 +309,8 @@
if (home) {
strcat(p, ":");
strcat(p, home);
+ /* what happened to the "/.netscape"? */
+ /* ANYway... */
}
strcat(p, local);
}

--
Dan McGuirk
mcg...@indirect.com

Jamie Zawinski

unread,
Apr 14, 1998, 3:00:00 AM4/14/98
to

Dan McGuirk wrote:
>
> This patch adds a '-configdir' command line option to the XFE that allows
> you to specify another directory to be used instead of '~/.netscape'.

That's a whole lot of changed lines to get the same effect as

(setenv HOME /otherdir; netscape)

--
Jamie Zawinski http://people.netscape.com/jwz/ about:jwz

Dan McGuirk

unread,
Apr 14, 1998, 3:00:00 AM4/14/98
to mozilla-patches

On Tue, 14 Apr 1998, Jamie Zawinski wrote:
> Dan McGuirk wrote:
> > This patch adds a '-configdir' command line option to the XFE that allows
> > you to specify another directory to be used instead of '~/.netscape'.
>
> That's a whole lot of changed lines to get the same effect as
>
> (setenv HOME /otherdir; netscape)

That's basically true. There are still a few advantages, though-- (1) the
FE can control the location of these files from one centralized place in
the code, and the location doesn't necessarily have to be related to
$HOME; (2) the string ".netscape", which contains a proprietary trademark
which third parties don't have rights to use, isn't hard-coded into the
source in a bunch of different places; and (3) different bits of the code
don't have to write pathnames into their own local static buffers, whose
sizes they usually pick arbitrarily without referring to PATH_MAX or
pathconf() or whatever it is that tells you the actual size you're
supposed to use.

This way seems cleaner to me, but I'll leave it up to the mozilla.org
community to decide whether the patch is worth it or not.

--
Dan McGuirk
mcg...@indirect.com

Jeff Garzik

unread,
Apr 14, 1998, 3:00:00 AM4/14/98
to

Jamie Zawinski wrote:
>
> Dan McGuirk wrote:
> >
> > This patch adds a '-configdir' command line option to the XFE that allows
> > you to specify another directory to be used instead of '~/.netscape'.
>
> That's a whole lot of changed lines to get the same effect as
>
> (setenv HOME /otherdir; netscape)

That's a hack; His is more elegant and easier to use in scripts and
installation instructions (which don't have to be changed for the evil
csh).

Plus, it's much easier to use multiple configs by doing

pretzel$ netscape -cfgdir .netscape-jgarzik
pretzel$ netscape -cfgdir .netscape-alter_ego
pretzel$ netscape -cfgdir .netscape-derfladermaus

--
Jeff Garzik Typhoon, Cyclone, Diablo, and INN
http://www.spinne.com/usenet/ News tuning and consulting

Ramiro Estrugo

unread,
Apr 20, 1998, 3:00:00 AM4/20/98
to Dan McGuirk

I looked at your patch and tried it. It is true that you could change
HOME and run mozilla. You could do all kinds of shell hackery for that.

Still, I think the ability to specify the config dir on resources or
command line is very useful - not only for testing but for other things
as well.

I have no problem with all the xfe code (and the unix prefs code). Can
you break up the other stuff and send it to the responsible people ?
Its only 2 things: nspr (only comments as far as i can tell) and libXp.

I also think it is possible that we missed something. There are so many
things that depend on the config dir that it is hard to test. I've
tried as many things as I can think of, but who knows. I dont have a
problem if we missed something as long as we dont break the default
behavior - that is when there is no -configdir option or resource.

thanks

-re

--
Ramiro Estrugo
Unix Communicator, Netscape Communications

0 new messages