diff --git a/src/actions.c b/src/actions.c index 0470a0d7..3b699a94 100644 --- a/src/actions.c +++ b/src/actions.c @@ -440,6 +440,21 @@ const char *get_file_path(char *f) return tclresult(); } + +int samefile(const char *fa, const char *fb) +{ + + struct stat a, b; + int statusa, statusb; + + statusa = stat(fa, &a); + statusb = stat(fb, &b); + if(statusa == 0 && statusb == 0 && a.st_ino == b.st_ino) { + return 1; + } + return 0; /* not same of one of the two not existing */ +} + int save(int confirm) /* 20171006 add confirm */ { int cancel; diff --git a/src/save.c b/src/save.c index 613992bf..c7598d3a 100644 --- a/src/save.c +++ b/src/save.c @@ -901,6 +901,7 @@ void make_symbol(void) } +/* ALWAYS call with absolute path in schname!!! */ int save_schematic(const char *schname) /* 20171020 added return value */ { FILE *fd; @@ -959,7 +960,7 @@ void link_symbols_to_instances(void) /* 20150326 separated from load_schematic() } } - +/* ALWAYS use absolute pathname for filename!!! */ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 20150327 added reset_undo */ { FILE *fd; diff --git a/src/scheduler.c b/src/scheduler.c index 6706a73a..d7987a32 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1110,6 +1110,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } } + else if(!strcmp(argv[1], "samefile") && argc == 4) { + int r; + r = samefile(argv[2], argv[3]); + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, r ? "1" : "0" , NULL); + } + else if(!strcmp(argv[1],"create_plot_cmd") ) { if(argc>2) { if(!strcmp(argv[2], "gaw")) { @@ -1220,7 +1227,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg unselect_all(); remove_symbols(); /* load_symbol(argv[2]); */ - load_schematic(0, argv[2], 1); + load_schematic(0, abs_sym_path(argv[2], ""), 1); my_strdup(374, &xctx.sch_path[xctx.currsch],"."); xctx.sch_inst_number[xctx.currsch] = 1; zoom_full(1, 0); diff --git a/src/xinit.c b/src/xinit.c index f13ffa7d..9a146f8d 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1433,17 +1433,15 @@ int Tcl_AppInit(Tcl_Interp *inter) enable_layers(); + /* prefer using env(PWD) if existing since it does not dereference symlinks */ + if(tcleval("info exists env(PWD)")[0] == '1') { + my_snprintf(pwd_dir, S(pwd_dir), "%s", tclgetvar("env(PWD)")); + } + if(filename) { char f[PATH_MAX]; if(filename[0] !='/') { - /* prefer not use pwd_dir since it dereferences symlinks - | - \|/ */ - if(tcleval("info exists env(PWD)")[0] == '1') { - my_snprintf(f, S(f), "%s/%s", tclgetvar("env(PWD)"), filename); - } else { - my_snprintf(f, S(f), "%s/%s", pwd_dir, filename); - } + my_snprintf(f, S(f), "%s/%s", pwd_dir, filename); } else { my_snprintf(f, S(f), "%s", filename); } diff --git a/src/xschem.h b/src/xschem.h index 0c11668f..f157ec33 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -717,6 +717,7 @@ extern void schematic_in_new_window(void); extern void symbol_in_new_window(void); extern void new_window(const char *cell, int symbol); extern void ask_new_file(void); +extern int samefile(const char *fa, const char *fb); extern void saveas(const char *f, int type); extern const char *get_file_path(char *f); extern int save(int confirm); diff --git a/src/xschem.tcl b/src/xschem.tcl index 694803d1..d3380e91 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -2625,7 +2625,7 @@ proc rel_sym_path {symbol} { break } } - if { ![string compare $name {} ] } { + if {$name eq {} } { # no known lib, so return full path set name ${symbol} } @@ -2655,8 +2655,8 @@ proc abs_sym_path {fname {ext {} } } { while { [regsub {^\./} $fname {} fname] } {} if { $fname eq {} } { set fname . } - # if fname is just "." or "./" return $current_dirname - if {[regexp {^\./*$} $fname] } { + # if fname is just "." return $current_dirname + if {[regexp {^\.$} $fname] } { return $current_dirname } }