From cdcf63aa46e80f64cbfcfd1c760e493c12182ecd Mon Sep 17 00:00:00 2001 From: h_vogt Date: Tue, 23 Sep 2008 22:13:46 +0000 Subject: [PATCH] add *.cir file path as search path (MS Windows) --- src/main.c | 14 ++++++++++++- src/misc/util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index ffe8942d3..ee21d1c24 100644 --- a/src/main.c +++ b/src/main.c @@ -997,7 +997,8 @@ bot: startup time. */ FILE *tempfile; #ifdef HAS_WINDOWS - char *tpf; + char *tpf; /* temporary file */ + char *dname = NULL; /* directory of input file*/ bool has_smk = FALSE; #endif tempfile = tmpfile(); @@ -1030,13 +1031,24 @@ bot: err = 1; break; } +#ifdef HAS_WINDOWS + /* Copy the input file name which otherwise will be lost due to the + temporary file */ + dname = copy(arg); +#endif append_to_stream(tempfile, tp); fclose(tp); } fseek(tempfile, (long) 0, 0); if (tempfile && (!err || !ft_batchmode)) { +#ifdef HAS_WINDOWS + /* Copy the input file name for adding another file search path */ + inp_spsource(tempfile, FALSE, dname); + tfree(dname); +#else inp_spsource(tempfile, FALSE, NULL); +#endif gotone = TRUE; } #ifdef HAS_WINDOWS diff --git a/src/misc/util.c b/src/misc/util.c index 97a1a4775..41fc5f0cc 100644 --- a/src/misc/util.c +++ b/src/misc/util.c @@ -188,6 +188,58 @@ basename(const char *name) return base; } +#ifdef HAS_WINDOWS +/* allow back slashes \\ */ +char * +dirname(const char *name) +{ + static char *ret = NULL; + int len; + int size = 0; + const char *p; + + if (ret) { + free(ret); + ret = NULL; + } + + if (!name || !strcmp(name, "") || (!strstr(name, "/") && !strstr(name, "\\"))) + return("."); + + if (!strcmp(name, "/")) + return(name); + + if (!strcmp(name, "\\")) + return(name); + + // find the last slash in the string + + len = strlen(name); + p = &name[len - 1]; + + if (*p == '/') p--; // skip the trailing / + + if (*p == '\\') p--; // skip the trailing \ + + while (p != name && *p != '/' && *p != '\\') p--; + + size = p - name; + if (size) { + ret = malloc(size + 1); + memcpy(ret, name, size); + ret[size] = '\0'; + } else if (*p == '/') + return "/"; + else if (*p == '\\') + return "\\"; + else + return ""; + + return (const char *) ret; +} + +#else + char * dirname(const char *name) { @@ -228,5 +280,6 @@ dirname(const char *name) return (const char *) ret; } +#endif #endif