correct implementation of previous commit

This commit is contained in:
stefan schippers 2023-09-20 11:04:30 +02:00
parent 1fdf117a84
commit 0119f013e3
2 changed files with 20 additions and 21 deletions

View File

@ -519,8 +519,6 @@ void saveas(const char *f, int type) /* changed name from ask_save_file to save
dbg(1, "saveas(): res = %s\n", res); dbg(1, "saveas(): res = %s\n", res);
save_schematic(res); save_schematic(res);
tclvareval("update_recent_file {", res,"}", NULL); tclvareval("update_recent_file {", res,"}", NULL);
my_strncpy(xctx->current_name, rel_sym_path(res), S(xctx->current_name));
return; return;
} }

View File

@ -2325,34 +2325,35 @@ static void make_schematic(const char *schname)
int save_schematic(const char *schname) /* 20171020 added return value */ int save_schematic(const char *schname) /* 20171020 added return value */
{ {
FILE *fd; FILE *fd;
char name[PATH_MAX]; /* overflow safe 20161122 */
struct stat buf; struct stat buf;
xRect *rect; xRect *rect;
int rects; int rects;
if(!schname || !strcmp(schname, "")) return 0; if(!schname || !strcmp(schname, "")) return 0;
dbg(1, "save_schematic(): currsch=%d name=%s\n",xctx->currsch, schname); dbg(1, "save_schematic(): currsch=%d schname=%s\n",xctx->currsch, schname);
dbg(1, "save_schematic(): sch[currsch]=%s\n", xctx->sch[xctx->currsch]); dbg(1, "save_schematic(): sch[currsch]=%s\n", xctx->sch[xctx->currsch] ? xctx->sch[xctx->currsch] : "NULL");
/* dbg(1, "save_schematic(): abs_sym_path=%s\n", abs_sym_path(xctx->sch[xctx->currsch], "")); */
my_strncpy(name, xctx->sch[xctx->currsch], S(name));
/* saving to a different filename */ if(!xctx->sch[xctx->currsch]) { /* no current schematic name -> assign new name */
if(!xctx->sch[xctx->currsch] || strcmp(schname, xctx->sch[xctx->currsch])) { my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], schname);
my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], schname); set_modify(-1); /* set title to new filename */
set_modify(-1); /* set title to new filename */
} }
/* saving to same filename */ else if(strcmp(schname, xctx->sch[xctx->currsch])) { /* user asks to save to a different filename */
else if(!stat(name, &buf)) { my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], schname);
if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) { set_modify(-1); /* set title to new filename */
tclvareval("ask_save \"Schematic file: ", name, }
"\nHas been changed since opening.\nSave anyway?\" 0", NULL); else { /* user asks to save to same filename */
if(strcmp(tclresult(), "yes") ) return 0; if(!stat(xctx->sch[xctx->currsch], &buf)) {
if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) {
tclvareval("ask_save \"Schematic file: ", xctx->sch[xctx->currsch],
"\nHas been changed since opening.\nSave anyway?\" 0", NULL);
if(strcmp(tclresult(), "yes") ) return 0;
}
} }
} }
if(!(fd=fopen(name,"w"))) if(!(fd=fopen(schname,"w")))
{ {
fprintf(errfp, "save_schematic(): problems opening file %s \n",name); fprintf(errfp, "save_schematic(): problems opening file %s \n",schname);
tcleval("alert_ {file opening for write failed!} {}"); tcleval("alert_ {file opening for write failed!} {}");
return 0; return 0;
} }
@ -2363,10 +2364,10 @@ int save_schematic(const char *schname) /* 20171020 added return value */
write_xschem_file(fd); write_xschem_file(fd);
fclose(fd); fclose(fd);
/* update time stamp */ /* update time stamp */
if(!stat(name, &buf)) { if(!stat(schname, &buf)) {
xctx->time_last_modify = buf.st_mtime; xctx->time_last_modify = buf.st_mtime;
} }
my_strncpy(xctx->current_name, rel_sym_path(name), S(xctx->current_name)); my_strncpy(xctx->current_name, rel_sym_path(schname), S(xctx->current_name));
/* why clear all these? */ /* why clear all these? */
/* /*
* xctx->prep_hi_structs=0; * xctx->prep_hi_structs=0;