[ROSAPPS][MAN] Don't hardcode C: drive (#2780)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Wed, 13 May 2020 13:21:17 +0000 (22:21 +0900)
committerGitHub <noreply@github.com>
Wed, 13 May 2020 13:21:17 +0000 (22:21 +0900)
CORE-13235

modules/rosapps/applications/sysutils/man/man.c

index e382972..825b795 100644 (file)
@@ -15,6 +15,7 @@
   */
 
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <windows.h>
@@ -37,7 +38,7 @@ int AnalyzeFile();
 /*====[Globals]====*/
 FILE* manfile;
 char OpenFlag=0;
-char manpath[MAXLINE]="c:\\man\\";
+char manpath[MAX_PATH];
 /*=================*/
 
 void
@@ -49,21 +50,34 @@ SetCl(WORD cl)
 int
 OpenF(char* name)
 {
-    int retval=0;
-    char *manpath_local=(char*)malloc(sizeof(char)*MAXLINE);
+    int ret = 0;
+    char *cp;
 
-    strcpy(manpath_local, manpath); //save mandir value
+    /* C:\man\\... */
+    cp = getenv("SystemDrive");
+    if (cp && *cp)
+    {
+        strcpy(manpath, cp);
+        strcat(manpath, "\\man\\");
+    }
+    else
+    {
+        strcpy(manpath, "C:\\man\\");
+    }
+    strcat(manpath, name);
 
-    if((manfile=fopen((strcat(manpath_local,name)),"r"))!=NULL)
-     {
-      OpenFlag=1;
-      AnalyzeFile();
-     }
+    manfile = fopen(manpath, "r");
+    if (manfile != NULL)
+    {
+        OpenFlag = 1;
+        AnalyzeFile();
+    }
     else
-     retval=-1;
+    {
+        ret = -1;
+    }
 
-    free(manpath_local);
-    return retval;
+    return ret;
 }
 
 int