diff options
Diffstat (limited to 'win32caml/startocaml.c')
-rw-r--r-- | win32caml/startocaml.c | 78 |
1 files changed, 34 insertions, 44 deletions
diff --git a/win32caml/startocaml.c b/win32caml/startocaml.c index 491fab8ca4..f1a3562d9c 100644 --- a/win32caml/startocaml.c +++ b/win32caml/startocaml.c @@ -138,50 +138,40 @@ Errors: Almost all system calls will be verified ------------------------------------------------------------------------*/ int GetOcamlPath(void) { - char path[1024], *p; - -again: - if (! ReadRegistry(HKEY_CURRENT_USER, - "Software", "Objective Caml", - "InterpreterPath", path) - && - ! ReadRegistry(HKEY_LOCAL_MACHINE, - "Software", "Objective Caml", - "InterpreterPath", path)) { - /* Key doesn't exist? Ask user */ - if (!BrowseForFile("Ocaml interpreter|ocaml.exe", path)) { - ShowDbgMsg("Impossible to find ocaml.exe. I quit"); - exit(0); - } - WriteRegistry(HKEY_CURRENT_USER, - "Software", "Objective Caml", - "InterpreterPath", path); - } - /* Check if file exists */ - if (_access(path, 0) != 0) { - char *errormsg = malloc(1024); - wsprintf(errormsg,"Incorrect path for ocaml.exe:\n%s", path); - ShowDbgMsg(errormsg); - free(errormsg); - path[0] = 0; - WriteRegistry(HKEY_CURRENT_USER, - "Software", "Objective Caml", - "InterpreterPath", path); - goto again; - } - strcpy(OcamlPath, path); - p = strrchr(OcamlPath,'\\'); - if (p) { - *p = 0; - strcpy(LibDir,OcamlPath); - *p = '\\'; - p = strrchr(LibDir,'\\'); - if (p && !stricmp(p,"\\bin")) { - *p = 0; - strcat(LibDir,"\\lib"); - } - } - return 1; + char path[1024], *p; + + while (( !ReadRegistry(HKEY_CURRENT_USER, + "Software", "Objective Caml", + "InterpreterPath", path) + && + !ReadRegistry(HKEY_LOCAL_MACHINE, + "Software", "Objective Caml", + "InterpreterPath", path)) + || _access(path, 0) != 0) { + /* Registry key doesn't exist or contains invalid path */ + /* Ask user */ + if (!BrowseForFile("Ocaml interpreter|ocaml.exe", path)) { + ShowDbgMsg("Impossible to find ocaml.exe. I quit"); + exit(0); + } + WriteRegistry(HKEY_CURRENT_USER, + "Software", "Objective Caml", + "InterpreterPath", path); + /* Iterate to validate again */ + } + strcpy(OcamlPath, path); + p = strrchr(OcamlPath,'\\'); + if (p) { + *p = 0; + strcpy(LibDir,OcamlPath); + *p = '\\'; + p = strrchr(LibDir,'\\'); + if (p && !stricmp(p,"\\bin")) { + *p = 0; + strcat(LibDir,"\\lib"); + } + } + return 1; } static HANDLE hChildStdinRd, hChildStdinWr,hChildStdoutRd, hChildStdoutWr; |