From 88b284831c03242dd073bb658a67971931f0c0eb Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Tue, 7 Jun 1994 15:24:57 +0000 Subject: [PATCH] (init_environment): Clean up code and make the default EMACSPATH equal to the directory from which Emacs was started. (emacsroot): New variable. (rootrelativepath): New function. --- src/msdos.c | 63 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/msdos.c b/src/msdos.c index fd9ae23efee..0b738c4a050 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -657,6 +657,21 @@ sleep_or_kbd_hit (secs, kbdok) while (clnow < clthen); } +/* The Emacs root directory as determined by init_environment. */ +static char emacsroot[MAXPATHLEN]; + +char * +rootrelativepath (rel) + char *rel; +{ + static char result[MAXPATHLEN + 10]; + + strcpy (result, emacsroot); + strcat (result, "/"); + strcat (result, rel); + return result; +} + /* Define a lot of environment variables if not already defined. Don't remove anything unless you know what you're doing -- lots of code will break if one or more of these are missing. */ @@ -666,32 +681,30 @@ init_environment (argc, argv, skip_args) char **argv; int skip_args; { - char *s, *t; - - /* We default HOME to the directory from which Emacs was started, but with - a "/bin" suffix removed. */ - s = argv[0]; - t = alloca (strlen (s) + 1); - strcpy (t, s); - s = t + strlen (t); - while (s != t && *s != '/' && *s != ':') s--; - if (s == t) - t = "c:/emacs"; /* When run under debug32. */ + char *s, *t, *root; + int len; + + /* Find our root from argv[0]. Assuming argv[0] is, say, + "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */ + len = strlen (argv[0]); + root = alloca (len + 10); /* A little extra space for the stuff below. */ + strcpy (root, argv[0]); + while (len > 0 && root[len] != '/' && root[len] != ':') + len--; + root[len] = '\0'; + if (len > 4 && strcmp (root + len - 4, "/bin") == 0) + root[len - 4] = '\0'; else - { - if (*s == ':') s++; - *s = 0; - if (s - 4 >= t && strcmp (s - 4, "/bin") == 0) - s[strlen (s) - 4] = 0; - } - setenv ("HOME", t, 0); - - /* We set EMACSPATH to ~/bin (expanded) */ - s = getenv ("HOME"); - t = strcpy (alloca (strlen (s) + 6), s); - if (s[strlen (s) - 1] != '/') strcat (t, "/"); - strcat (t, "bin"); - setenv ("EMACSPATH", t, 0); + strcpy (root, "c:/emacs"); /* Only under debuggers, I think. */ + len = strlen (root); + strcpy (emacsroot, root); + + /* We default HOME to our root. */ + setenv ("HOME", root, 0); + + /* We default EMACSPATH to root + "/bin". */ + strcpy (root + len, "/bin"); + setenv ("EMACSPATH", root, 0); /* I don't expect anybody to ever use other terminals so the internal terminal is the default. */ -- 2.39.5