what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
-#include "common.h"
+#ifdef _WIN32
+#include <ctype.h>
+#include <windows.h>
+#endif
+#include <sys/stat.h>
+#include "SDCCglobl.h"
#include "SDCCmacro.h"
#include "SDCCutil.h"
#include "newalloc.h"
-#include <sys/stat.h>
/** Given an array of name, value string pairs creates a new hash
containing all of the pairs.
#endif
}
-static bool
-pathEquivalent(const char *p1, const char *p2)
-{
- while (*p1 != '\0' && *p2 != '\0')
- {
- if (pathCharsEquivalent (*p1, *p2) == FALSE)
- {
- break;
- }
- p1++;
- p2++;
- }
-
- return *p1 == *p2;
-}
-
static char
pathCharTransform(char c)
{
return fixupPath(pinto);
}
+
/** Given a file with path information in the binary files directory,
- returns what PREFIX must be to get this path. Used for discovery
- of where SDCC is installed. Returns NULL if the path is
+ returns the directory component. Used for discovery of bin
+ directory of SDCC installation. Returns NULL if the path is
impossible.
*/
+#ifdef _WIN32
char *
-getPrefixFromBinPath (const char *prel)
+getBinPath(const char *prel)
{
- strncpyz(scratchFileName, prel, PATH_MAX);
- /* Strip off the /sdcc at the end */
- *strrchr(scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
- /* Compute what the difference between the prefix and the bin dir
- should be. */
- getPathDifference (buffer, PREFIX, BINDIR);
-
- /* Verify that the path in has the expected suffix */
- if (strlen(buffer) > strlen(scratchFileName))
- {
- /* Not long enough */
- return NULL;
- }
-
- if (pathEquivalent (buffer, scratchFileName + strlen(scratchFileName) - strlen(buffer)) == FALSE)
- {
- /* Doesn't match */
- return NULL;
- }
+ char *p;
+ size_t len;
+ static char path[PATH_MAX];
+
+ /* try DOS and *nix dir separator on WIN32 */
+ if (NULL != (p = strrchr(prel, DIR_SEPARATOR_CHAR)) ||
+ NULL != (p = strrchr(prel, UNIX_DIR_SEPARATOR_CHAR))) {
+ len = min((sizeof path) - 1, p - prel);
+ strncpy(path, prel, len);
+ path[len] = '\0';
+ return path;
+ }
+ /* not enough info in prel; do it with module name */
+ else if (0 != GetModuleFileName(NULL, path, sizeof path) != 0 &&
+ NULL != (p = strrchr(path, DIR_SEPARATOR_CHAR))) {
+ *p = '\0';
+ return path;
+ }
+ else
+ return NULL;
+}
+#else
+char *
+getBinPath(const char *prel)
+{
+ char *p;
+ size_t len;
+ static char path[PATH_MAX];
+
+ if ((p = strrchr(prel, DIR_SEPARATOR_CHAR)) == NULL)
+ return NULL;
- scratchFileName[strlen(scratchFileName) - strlen(buffer)] = '\0';
+ len = min((sizeof path) - 1, p - prel);
+ strncpy(path, prel, len);
+ path[len] = '\0';
- return Safe_strdup (scratchFileName);
+ return path;
}
+#endif
/** Returns true if the given path exists.
*/