00001
00020 #include "mfcpch.h"
00021 #include "strngs.h"
00022 #ifdef __UNIX__
00023 #include <unistd.h>
00024 #include <fcntl.h>
00025 #else
00026 #include <io.h>
00027 #endif
00028 #include <stdlib.h>
00029 #include "basedir.h"
00030 #include "notdll.h"
00031
00038 DLLSYM INT8 getpath(
00039 const char *code,
00040 STRING &path
00041 ) {
00042 char directory[MAX_PATH];
00043 #ifdef __UNIX__
00044 INT16 dirind;
00045 register char *pathlist;
00046 int fd;
00047
00048 strcpy(directory, code);
00049 dirind = strlen (directory);
00050 while (dirind > 0 && directory[dirind - 1] != '/')
00051 dirind--;
00052 directory[dirind] = '\0';
00053 if (dirind != 0) {
00054 path = directory;
00055 return 0;
00056 }
00057 pathlist = getenv ("PATH");
00058 while (pathlist != NULL && *pathlist) {
00059 for (dirind = 0; *pathlist != '\0' && *pathlist != ':';)
00060
00061 directory[dirind++] = *pathlist++;
00062 if (*pathlist == ':')
00063 pathlist++;
00064 if (dirind == 0)
00065 continue;
00066 if (directory[dirind - 1] != '/');
00067 directory[dirind++] = '/';
00068 directory[dirind++] = '\0';
00069 path = directory;
00070 strcat(directory, code);
00071 fd = open (directory, 0);
00072 if (fd >= 0) {
00073 close(fd);
00074 return 0;
00075 }
00076 }
00077 strcpy (directory, "./");
00078 path = directory;
00079 strcat(directory, code);
00080 fd = open (directory, 0);
00081 if (fd >= 0) {
00082 close(fd);
00083 return 0;
00084 }
00085 return -1;
00086 #endif
00087 #ifdef __MSW32__
00088 char *path_end;
00089
00090 if (GetModuleFileName (NULL, directory, MAX_PATH - 1) == 0) {
00091 return -1;
00092 }
00093 while ((path_end = strchr (directory, '\\')) != NULL)
00094 *path_end = '/';
00095 path_end = strrchr (directory, '/');
00096 if (path_end != NULL)
00097 path_end[1] = '\0';
00098 else
00099 strcpy (directory, "./");
00100 path = directory;
00101 return 0;
00102 #endif
00103 }