diff options
| author | Richard M. Stallman | 1996-06-03 15:44:32 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-06-03 15:44:32 +0000 |
| commit | 662463d904ef88b85055490ffb4a8b6b4d3d07df (patch) | |
| tree | 107873d75bef20491317fa69e3aa8d41dc20e4e3 | |
| parent | 4302ef50105ec50802937d1a0154b27260cfffda (diff) | |
| download | emacs-662463d904ef88b85055490ffb4a8b6b4d3d07df.tar.gz emacs-662463d904ef88b85055490ffb4a8b6b4d3d07df.zip | |
(CHOOSE_NEWEST_EXE): New parameter macro.
Not defined by default.
(WinMain): Add conditional testing CHOOSE_NEWEST_EXE.
(WinMain): Convert backslashes to slashes in env var values.
| -rw-r--r-- | nt/runemacs.c | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/nt/runemacs.c b/nt/runemacs.c index 720c6ca7241..fe10021e98f 100644 --- a/nt/runemacs.c +++ b/nt/runemacs.c | |||
| @@ -5,6 +5,21 @@ | |||
| 5 | use Emacs in windowing (GUI) mode, and will not want to have an extra | 5 | use Emacs in windowing (GUI) mode, and will not want to have an extra |
| 6 | console window lying around. */ | 6 | console window lying around. */ |
| 7 | 7 | ||
| 8 | /* | ||
| 9 | You may want to define this if you want to be able to install updated | ||
| 10 | emacs binaries even when other users are using the current version. | ||
| 11 | The problem with some file servers (notably Novell) is that an open | ||
| 12 | file cannot be overwritten, deleted, or even renamed. So if someone | ||
| 13 | is running emacs.exe already, you cannot install a newer version. | ||
| 14 | By defining CHOOSE_NEWEST_EXE, you can name your new emacs.exe | ||
| 15 | something else which matches "emacs*.exe", and runemacs will | ||
| 16 | automatically select the newest emacs executeable in the bin directory. | ||
| 17 | (So you'll probably be able to delete the old version some hours/days | ||
| 18 | later). | ||
| 19 | */ | ||
| 20 | |||
| 21 | /* #define CHOOSE_NEWEST_EXE */ | ||
| 22 | |||
| 8 | #define WIN32 | 23 | #define WIN32 |
| 9 | 24 | ||
| 10 | #include <windows.h> | 25 | #include <windows.h> |
| @@ -20,8 +35,8 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) | |||
| 20 | PROCESS_INFORMATION child; | 35 | PROCESS_INFORMATION child; |
| 21 | int wait_for_child = FALSE; | 36 | int wait_for_child = FALSE; |
| 22 | DWORD ret_code = 0; | 37 | DWORD ret_code = 0; |
| 23 | char * new_cmdline; | 38 | char *new_cmdline; |
| 24 | char * p; | 39 | char *p; |
| 25 | char modname[MAX_PATH]; | 40 | char modname[MAX_PATH]; |
| 26 | 41 | ||
| 27 | if (!GetModuleFileName (NULL, modname, MAX_PATH)) | 42 | if (!GetModuleFileName (NULL, modname, MAX_PATH)) |
| @@ -32,23 +47,58 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) | |||
| 32 | 47 | ||
| 33 | new_cmdline = alloca (MAX_PATH + strlen (cmdline) + 1); | 48 | new_cmdline = alloca (MAX_PATH + strlen (cmdline) + 1); |
| 34 | strcpy (new_cmdline, modname); | 49 | strcpy (new_cmdline, modname); |
| 35 | strcat (new_cmdline, "\\emacs.exe "); | ||
| 36 | 50 | ||
| 37 | /* append original arguments if any; first look for -wait as first | 51 | #ifdef CHOOSE_NEWEST_EXE |
| 38 | argument, and apply that ourselves */ | ||
| 39 | if (strncmp (cmdline, "-wait", 5) == 0) | ||
| 40 | { | 52 | { |
| 41 | wait_for_child = TRUE; | 53 | /* Silly hack to allow new versions to be installed on |
| 42 | cmdline += 5; | 54 | server even when current version is in use. */ |
| 55 | |||
| 56 | char * best_name = alloca (MAX_PATH + 1); | ||
| 57 | FILETIME best_time = {0,0}; | ||
| 58 | WIN32_FIND_DATA wfd; | ||
| 59 | HANDLE fh; | ||
| 60 | p = new_cmdline + strlen (new_cmdline); | ||
| 61 | strcpy (p, "\\emacs*.exe"); | ||
| 62 | fh = FindFirstFile (new_cmdline, &wfd); | ||
| 63 | if (fh == INVALID_HANDLE_VALUE) | ||
| 64 | goto error; | ||
| 65 | do | ||
| 66 | { | ||
| 67 | if (wfd.ftLastWriteTime.dwHighDateTime > best_time.dwHighDateTime | ||
| 68 | || (wfd.ftLastWriteTime.dwHighDateTime == best_time.dwHighDateTime | ||
| 69 | && wfd.ftLastWriteTime.dwLowDateTime > best_time.dwLowDateTime)) | ||
| 70 | { | ||
| 71 | best_time = wfd.ftLastWriteTime; | ||
| 72 | strcpy (best_name, wfd.cFileName); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | while (FindNextFile (fh, &wfd)); | ||
| 76 | FindClose (fh); | ||
| 77 | *p++ = '\\'; | ||
| 78 | strcpy (p, best_name); | ||
| 79 | strcat (p, " "); | ||
| 43 | } | 80 | } |
| 81 | #else | ||
| 82 | strcat (new_cmdline, "\\emacs.exe"); | ||
| 83 | #endif | ||
| 84 | |||
| 85 | /* Append original arguments if any; first look for -wait as first | ||
| 86 | argument, and apply that ourselves. */ | ||
| 87 | if (strncmp (cmdline, "-wait", 5) == 0) | ||
| 88 | { | ||
| 89 | wait_for_child = TRUE; | ||
| 90 | cmdline += 5; | ||
| 91 | } | ||
| 44 | strcat (new_cmdline, cmdline); | 92 | strcat (new_cmdline, cmdline); |
| 45 | 93 | ||
| 46 | /* set emacs_dir variable if runemacs was in "%emacs_dir%\bin" */ | 94 | /* Set emacs_dir variable if runemacs was in "%emacs_dir%\bin". */ |
| 47 | if ((p = strrchr (modname, '\\')) && stricmp (p, "\\bin") == 0) | 95 | if ((p = strrchr (modname, '\\')) && stricmp (p, "\\bin") == 0) |
| 48 | { | 96 | { |
| 49 | *p = 0; | 97 | *p = 0; |
| 50 | SetEnvironmentVariable ("emacs_dir", modname); | 98 | for (p = modname; *p; p++) |
| 51 | } | 99 | if (*p == '\\') *p = '/'; |
| 100 | SetEnvironmentVariable ("emacs_dir", modname); | ||
| 101 | } | ||
| 52 | 102 | ||
| 53 | memset (&start, 0, sizeof (start)); | 103 | memset (&start, 0, sizeof (start)); |
| 54 | start.cb = sizeof (start); | 104 | start.cb = sizeof (start); |