added "xschem samefile" command to verify if 2 files are the same entity by comparing inodes, pwd_dir set in xinit.c to $env(PWD) if PWD var is defined as it does not dereference symlinks

This commit is contained in:
Stefan Schippers 2020-10-13 17:51:14 +02:00
parent 8ea275013e
commit 1c2bbc609f
6 changed files with 35 additions and 13 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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
}
}