From c6b604aad43d000c4e41cd3188eec95158831c99 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 14 Dec 2004 16:19:53 +0000 Subject: [PATCH] Clean-up interface to os::init. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@9371 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 4 +++ src/main.C | 2 +- src/support/ChangeLog | 5 ++++ src/support/os.h | 2 +- src/support/os_os2.C | 64 +++++++++++++++++++++--------------------- src/support/os_unix.C | 5 ++-- src/support/os_win32.C | 8 +++--- 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 17bc2fc474..c9da2d6671 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-12-14 Angus Leeming + + * main.C: (main): no longer pass pointers to os::init. + 2004-12-14 Angus Leeming * BufferView_pimpl.C: remove unnecessary #include . diff --git a/src/main.C b/src/main.C index 7c10c5dde6..dbf52f9420 100644 --- a/src/main.C +++ b/src/main.C @@ -16,7 +16,7 @@ int main(int argc, char * argv[]) { - os::init(&argc, &argv); + os::init(argc, argv); // lyx_localedir is used by gettext_init() is we have // i18n support built-in diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 4e3ac4b2a1..608860d114 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2004-12-14 Angus Leeming + + * os.h, os_{os2,unix,win32}.C (init): change interface to no longer + pass the addresses of the parameters received by main. + 2004-12-14 Angus Leeming * copy.C (copy): open the ifstream with ios::binary. diff --git a/src/support/os.h b/src/support/os.h index f5a9b2e1ea..c7e0a9af39 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -15,7 +15,7 @@ public: }; // - static void init(int * argc, char ** argv[]); + static void init(int argc, char * argv[]); // static string binpath() {return binpath_;} diff --git a/src/support/os_os2.C b/src/support/os_os2.C index 6021cc1b8d..0d3cfa7dc8 100644 --- a/src/support/os_os2.C +++ b/src/support/os_os2.C @@ -18,40 +18,40 @@ string os::tmpdir_ = string(); os::shell_type os::_shell = os::UNIX; unsigned long os::cp_ = 0; -void os::init(int * argc, char ** argv[]) { - if (argc != 0 /* This is a hack! */) { - _wildcard(argc, argv); - PTIB ptib = new TIB[1]; - PPIB ppib = new PIB[1]; - APIRET rc = DosGetInfoBlocks(&ptib, &ppib); - if (rc != NO_ERROR) - exit(rc); - char* tmp = new char[256]; - // This is the only reliable way to retrieve the executable name. - rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp); - if (rc != NO_ERROR) - exit(rc); - string p(tmp); - p = slashify_path(p); - binname_ = OnlyFilename(p); - binname_.erase(binname_.length()-4, string::npos); - binpath_ = OnlyPath(p); +void os::init(int argc, char * argv[]) +{ + _wildcard(&argc, &argv); + PTIB ptib = new TIB[1]; + PPIB ppib = new PIB[1]; + APIRET rc = DosGetInfoBlocks(&ptib, &ppib); + if (rc != NO_ERROR) + exit(rc); + char* tmp = new char[256]; + // This is the only reliable way to retrieve the executable name. + rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp); + if (rc != NO_ERROR) + exit(rc); + string p(tmp); + p = slashify_path(p); + binname_ = OnlyFilename(p); + binname_.erase(binname_.length()-4, string::npos); + binpath_ = OnlyPath(p); - // OS/2 cmd.exe has another use for '&' - string sh = OnlyFilename(GetEnvPath("EMXSHELL")); - if (sh.empty()) { - // COMSPEC is set, unless user unsets - sh = OnlyFilename(GetEnvPath("COMSPEC")); - if (sh.empty()) - sh = "cmd.exe"; - } - sh = lowercase(sh); // DosMapCase() is an overkill here - if (contains(sh, "cmd.exe") - || contains(sh, "4os2.exe")) - _shell = os::CMD_EXE; - else - _shell = os::UNIX; + // OS/2 cmd.exe has another use for '&' + string sh = OnlyFilename(GetEnvPath("EMXSHELL")); + if (sh.empty()) { + // COMSPEC is set, unless user unsets + sh = OnlyFilename(GetEnvPath("COMSPEC")); + if (sh.empty()) + sh = "cmd.exe"; } + sh = lowercase(sh); // DosMapCase() is an overkill here + if (contains(sh, "cmd.exe") + || contains(sh, "4os2.exe")) + _shell = os::CMD_EXE; + else + _shell = os::UNIX; + static bool initialized = false; if (initialized) return; initialized = true; diff --git a/src/support/os_unix.C b/src/support/os_unix.C index 26778e85df..d3eea1d35b 100644 --- a/src/support/os_unix.C +++ b/src/support/os_unix.C @@ -13,14 +13,15 @@ string os::tmpdir_ = string(); os::shell_type os::_shell = os::UNIX; unsigned long os::cp_ = 0; -void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ { +void os::init(int /*argc*/, char * argv[]) /* :cp_(0), _shell(os::UNIX) */ +{ static bool initialized = false; if (initialized) return; initialized = true; - string tmp = *argv[0]; + string tmp = argv[0]; binname_ = OnlyFilename(tmp); tmp = ExpandPath(tmp); // This expands ./ and ~/ if (!os::is_absolute_path(tmp)) { diff --git a/src/support/os_win32.C b/src/support/os_win32.C index cbe6a7235b..793027b5ef 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -1,4 +1,4 @@ -// os_win32.C copyright "Ruurd A. Reitsma" +// os_win32.C copyright "Ruurd A. Reitsma" // Various OS specific functions #include @@ -21,11 +21,11 @@ unsigned long os::cp_ = 0; using std::endl; -void os::init(int * /* argc */, char ** argv[]) { +void os::init(int /* argc */, char * argv[]) { static bool initialized = false; if (initialized) return; initialized = true; - string tmp = *argv[0]; + string tmp = argv[0]; binname_ = OnlyFilename(tmp); tmp = ExpandPath(tmp); // This expands ./ and ~/ @@ -33,7 +33,7 @@ void os::init(int * /* argc */, char ** argv[]) { string binsearchpath = GetEnvPath("PATH"); // This will make "src/lyx" work always :-) binsearchpath += ";."; - tmp = *argv[0]; + tmp = argv[0]; tmp = FileOpenSearch(binsearchpath, tmp); }