uniquify /tmp/xschem_web (--> /tmp/xschem_web_xxxxxx), also handle like /tmp/xschem_undo_xxxxx, create on startup and remove on exit.
This commit is contained in:
parent
9abc57cf8b
commit
8067f58b43
|
|
@ -2100,13 +2100,13 @@ void get_sch_from_sym(char *filename, xSymbol *sym, int inst, int fallback)
|
||||||
}
|
}
|
||||||
if(sch) my_free(_ALLOC_ID_, &sch);
|
if(sch) my_free(_ALLOC_ID_, &sch);
|
||||||
|
|
||||||
if(web_url && filename[0]) {
|
if(web_url && filename[0] && xschem_web_dirname[0]) {
|
||||||
char sympath[PATH_MAX];
|
char sympath[PATH_MAX];
|
||||||
|
|
||||||
/* build local cached filename of web_url */
|
/* build local cached filename of web_url */
|
||||||
my_snprintf(sympath, S(sympath), "%s/xschem_web/%s", tclgetvar("XSCHEM_TMP_DIR"), get_cell_w_ext(filename, 0));
|
my_snprintf(sympath, S(sympath), "%s/%s", xschem_web_dirname, get_cell_w_ext(filename, 0));
|
||||||
if(stat(sympath, &buf)) { /* not found, download */
|
if(stat(sympath, &buf)) { /* not found, download */
|
||||||
/* download item into ${XSCHEM_TMP_DIR}/xschem_web */
|
/* download item into ${XSCHEM_TMP_DIR}/xschem_web_xxxxx */
|
||||||
tclvareval("try_download_url {", xctx->current_dirname, "} {", filename, "}", NULL);
|
tclvareval("try_download_url {", xctx->current_dirname, "} {", filename, "}", NULL);
|
||||||
}
|
}
|
||||||
if(stat(sympath, &buf)) { /* not found !!! build abs_sym_path to look into local fs and hope fror the best */
|
if(stat(sympath, &buf)) { /* not found !!! build abs_sym_path to look into local fs and hope fror the best */
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,7 @@ char user_conf_dir[PATH_MAX];
|
||||||
char sel_file[PATH_MAX]="";
|
char sel_file[PATH_MAX]="";
|
||||||
char clip_file[PATH_MAX]="";
|
char clip_file[PATH_MAX]="";
|
||||||
char pwd_dir[PATH_MAX]; /* obtained via getcwd() */
|
char pwd_dir[PATH_MAX]; /* obtained via getcwd() */
|
||||||
|
char xschem_web_dirname[PATH_MAX]=""; /* cache dir for remote URLs */
|
||||||
int tcp_port = 0;
|
int tcp_port = 0;
|
||||||
int text_svg=1; /* use <text> svg element for text instead of xschem's internal vector font */
|
int text_svg=1; /* use <text> svg element for text instead of xschem's internal vector font */
|
||||||
int text_ps=1; /* use ps font for text instead of xschem's internal vector font */
|
int text_ps=1; /* use ps font for text instead of xschem's internal vector font */
|
||||||
|
|
|
||||||
19
src/save.c
19
src/save.c
|
|
@ -3151,11 +3151,11 @@ int load_schematic(int load_symbols, const char *fname, int reset_undo, int aler
|
||||||
my_strncpy(name, fname, S(name));
|
my_strncpy(name, fname, S(name));
|
||||||
dbg(1, "load_schematic(): fname=%s\n", fname);
|
dbg(1, "load_schematic(): fname=%s\n", fname);
|
||||||
/* remote web object specified */
|
/* remote web object specified */
|
||||||
if(is_from_web(fname)) {
|
if(is_from_web(fname) && xschem_web_dirname[0]) {
|
||||||
/* download into ${XSCHEM_TMP_DIR}/xschem_web */
|
/* download into ${XSCHEM_TMP_DIR}/xschem_web */
|
||||||
tclvareval("download_url {", fname, "}", NULL);
|
tclvareval("download_url {", fname, "}", NULL);
|
||||||
/* build local file name of downloaded object */
|
/* build local file name of downloaded object */
|
||||||
my_snprintf(name, S(name), "%s/xschem_web/%s", tclgetvar("XSCHEM_TMP_DIR"), get_cell_w_ext(fname, 0));
|
my_snprintf(name, S(name), "%s/%s", xschem_web_dirname, get_cell_w_ext(fname, 0));
|
||||||
/* build current_dirname by stripping off last filename from url */
|
/* build current_dirname by stripping off last filename from url */
|
||||||
my_snprintf(msg, S(msg), "get_directory {%s}", fname);
|
my_snprintf(msg, S(msg), "get_directory {%s}", fname);
|
||||||
my_strncpy(xctx->current_dirname, tcleval(msg), S(xctx->current_dirname));
|
my_strncpy(xctx->current_dirname, tcleval(msg), S(xctx->current_dirname));
|
||||||
|
|
@ -3165,10 +3165,10 @@ int load_schematic(int load_symbols, const char *fname, int reset_undo, int aler
|
||||||
my_strncpy(xctx->current_name, rel_sym_path(name), S(xctx->current_name));
|
my_strncpy(xctx->current_name, rel_sym_path(name), S(xctx->current_name));
|
||||||
|
|
||||||
/* local filename specified but coming (push, pop) from web object ... */
|
/* local filename specified but coming (push, pop) from web object ... */
|
||||||
} else if(is_from_web(xctx->current_dirname)) {
|
} else if(is_from_web(xctx->current_dirname) && xschem_web_dirname[0]) {
|
||||||
/* ... but not local file from web download --> reset current_dirname */
|
/* ... but not local file from web download --> reset current_dirname */
|
||||||
char sympath[PATH_MAX];
|
char sympath[PATH_MAX];
|
||||||
my_snprintf(sympath, S(sympath), "%s/xschem_web", tclgetvar("XSCHEM_TMP_DIR"));
|
my_snprintf(sympath, S(sympath), "%s", xschem_web_dirname);
|
||||||
/* fname does not begin with $XSCHEM_TMP_DIR/xschem_web and fname does not exist */
|
/* fname does not begin with $XSCHEM_TMP_DIR/xschem_web and fname does not exist */
|
||||||
|
|
||||||
if(strstr(fname, sympath) != fname /* && stat(fname, &buf)*/) {
|
if(strstr(fname, sympath) != fname /* && stat(fname, &buf)*/) {
|
||||||
|
|
@ -3831,16 +3831,12 @@ void sort_symbol_pins(xRect *pin_array, int npins, const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 1 if http or https url
|
/* return 1 if http or https url
|
||||||
* return 2 if cached /tmp/xschem_web/... file/directory
|
|
||||||
* return 0 otherwise
|
* return 0 otherwise
|
||||||
*/
|
*/
|
||||||
int is_from_web(const char *f)
|
int is_from_web(const char *f)
|
||||||
{
|
{
|
||||||
static char tmp[PATH_MAX] = "";
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
if(!tmp[0]) my_snprintf(tmp, S(tmp), "%s/xschem_web", tclgetvar("XSCHEM_TMP_DIR"));
|
|
||||||
if(strstr(f, "http://") == f || strstr(f, "https://") == f) res = 1;
|
if(strstr(f, "http://") == f || strstr(f, "https://") == f) res = 1;
|
||||||
/* if(strstr(f, tmp) == f) res = 2; */
|
|
||||||
dbg(1, "is_from_web(%s) = %d\n", f, res);
|
dbg(1, "is_from_web(%s) = %d\n", f, res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -3935,9 +3931,9 @@ int load_sym_def(const char *name, FILE *embed_fd)
|
||||||
if((lcc[level].fd=fopen(sympath,fopen_read_mode))==NULL) {
|
if((lcc[level].fd=fopen(sympath,fopen_read_mode))==NULL) {
|
||||||
/* not found: try web URL */
|
/* not found: try web URL */
|
||||||
if(is_from_web(xctx->current_dirname)) {
|
if(is_from_web(xctx->current_dirname)) {
|
||||||
my_snprintf(sympath, S(sympath), "%s/xschem_web/%s", tclgetvar("XSCHEM_TMP_DIR"), get_cell_w_ext(name, 0));
|
my_snprintf(sympath, S(sympath), "%s/%s", xschem_web_dirname, get_cell_w_ext(name, 0));
|
||||||
if((lcc[level].fd=fopen(sympath,fopen_read_mode))==NULL) {
|
if((lcc[level].fd=fopen(sympath,fopen_read_mode))==NULL) {
|
||||||
/* not already cached in .../xschem_web/ so download */
|
/* not already cached in .../xschem_web_xxxxx/ so download */
|
||||||
tclvareval("try_download_url {", xctx->current_dirname, "} {", name, "}", NULL);
|
tclvareval("try_download_url {", xctx->current_dirname, "} {", name, "}", NULL);
|
||||||
}
|
}
|
||||||
lcc[level].fd=fopen(sympath,fopen_read_mode);
|
lcc[level].fd=fopen(sympath,fopen_read_mode);
|
||||||
|
|
@ -4892,8 +4888,7 @@ void descend_symbol(void)
|
||||||
/* ... we are in a schematic downloaded from web ... */
|
/* ... we are in a schematic downloaded from web ... */
|
||||||
if(web_url) {
|
if(web_url) {
|
||||||
/* symbols have already been downloaded while loading parent schematic: set local file path */
|
/* symbols have already been downloaded while loading parent schematic: set local file path */
|
||||||
my_mstrcat(_ALLOC_ID_, &sympath, tclgetvar("XSCHEM_TMP_DIR"),
|
my_mstrcat(_ALLOC_ID_, &sympath, xschem_web_dirname, "/", get_cell_w_ext(tcl_hook2(name), 0), NULL);
|
||||||
"/xschem_web/", get_cell_w_ext(tcl_hook2(name), 0), NULL);
|
|
||||||
my_strdup(_ALLOC_ID_, ¤t_dirname_save, xctx->current_dirname); /* save http url */
|
my_strdup(_ALLOC_ID_, ¤t_dirname_save, xctx->current_dirname); /* save http url */
|
||||||
}
|
}
|
||||||
if(!sympath || stat(sympath, &buf)) { /* not found */
|
if(!sympath || stat(sympath, &buf)) { /* not found */
|
||||||
|
|
|
||||||
|
|
@ -1585,7 +1585,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
if(!strcmp(argv[2], "xorigin")) { /* x coordinate of origin */
|
if(!strcmp(argv[2], "xschem_web_dirname")) {
|
||||||
|
Tcl_SetResult(interp, xschem_web_dirname, TCL_STATIC);
|
||||||
|
} else if(!strcmp(argv[2], "xorigin")) { /* x coordinate of origin */
|
||||||
char s[128];
|
char s[128];
|
||||||
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
|
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
|
||||||
my_snprintf(s, S(s), "%.16g", xctx->xorigin);
|
my_snprintf(s, S(s), "%.16g", xctx->xorigin);
|
||||||
|
|
|
||||||
14
src/xinit.c
14
src/xinit.c
|
|
@ -965,6 +965,7 @@ static void xwin_exit(void)
|
||||||
tcleval("if {[info exists xschem_server_getdata(server)]} { close $xschem_server_getdata(server) }");
|
tcleval("if {[info exists xschem_server_getdata(server)]} { close $xschem_server_getdata(server) }");
|
||||||
tcleval("if {[info exists bespice_server_getdata(server)]} { close $bespice_server_getdata(server) }");
|
tcleval("if {[info exists bespice_server_getdata(server)]} { close $bespice_server_getdata(server) }");
|
||||||
if(!cli_opt_detach) printf("\n");
|
if(!cli_opt_detach) printf("\n");
|
||||||
|
if(xschem_web_dirname[0]) tclvareval("file delete -force ", xschem_web_dirname, NULL);
|
||||||
init_done=0; /* 20150409 to avoid multiple calls */
|
init_done=0; /* 20150409 to avoid multiple calls */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2274,6 +2275,7 @@ void tclmainloop(void)
|
||||||
|
|
||||||
int Tcl_AppInit(Tcl_Interp *inter)
|
int Tcl_AppInit(Tcl_Interp *inter)
|
||||||
{
|
{
|
||||||
|
const char *tmp_ptr;
|
||||||
char name[PATH_MAX]; /* overflow safe 20161122 */
|
char name[PATH_MAX]; /* overflow safe 20161122 */
|
||||||
char tmp[2*PATH_MAX+100]; /* 20161122 overflow safe */
|
char tmp[2*PATH_MAX+100]; /* 20161122 overflow safe */
|
||||||
#ifndef __unix__
|
#ifndef __unix__
|
||||||
|
|
@ -2456,7 +2458,7 @@ int Tcl_AppInit(Tcl_Interp *inter)
|
||||||
Tcl_Exit(EXIT_FAILURE);
|
Tcl_Exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute tcl script given on command line with --preinit, before sourcing xschemrc */
|
/* Execute tcl script given on command line with --preinit, before sourcing xschemrc */
|
||||||
if(cli_opt_preinit_command) {
|
if(cli_opt_preinit_command) {
|
||||||
|
|
@ -2612,7 +2614,6 @@ int Tcl_AppInit(Tcl_Interp *inter)
|
||||||
my_strdup(_ALLOC_ID_, &xschem_executable, get_file_path(xschem_executable));
|
my_strdup(_ALLOC_ID_, &xschem_executable, get_file_path(xschem_executable));
|
||||||
dbg(1, "Tcl_AppInit(): resolved xschem_executable=%s\n", xschem_executable);
|
dbg(1, "Tcl_AppInit(): resolved xschem_executable=%s\n", xschem_executable);
|
||||||
|
|
||||||
|
|
||||||
/* get xschem globals from tcl variables set in xschemrc/xschem.tcl */
|
/* get xschem globals from tcl variables set in xschemrc/xschem.tcl */
|
||||||
cairo_font_line_spacing = tclgetdoublevar("cairo_font_line_spacing");
|
cairo_font_line_spacing = tclgetdoublevar("cairo_font_line_spacing");
|
||||||
|
|
||||||
|
|
@ -2638,6 +2639,15 @@ int Tcl_AppInit(Tcl_Interp *inter)
|
||||||
/* [m]allocate dynamic memory */
|
/* [m]allocate dynamic memory */
|
||||||
/* */
|
/* */
|
||||||
alloc_xschem_data("", ".drw");
|
alloc_xschem_data("", ".drw");
|
||||||
|
|
||||||
|
/* create /tmp/xschem_web_xxx directory for remote objects */
|
||||||
|
tmp_ptr = create_tmpdir("xschem_web_");
|
||||||
|
if(!tmp_ptr) {
|
||||||
|
dbg(0, "xinit(): problems creating /tmp/xschem_web_xxxx dir\n");
|
||||||
|
} else {
|
||||||
|
my_strncpy(xschem_web_dirname, tmp_ptr, S(xschem_web_dirname));
|
||||||
|
}
|
||||||
|
|
||||||
/* initialize current schematic name to empty string to avoid gazillion checks in the code for NULL */
|
/* initialize current schematic name to empty string to avoid gazillion checks in the code for NULL */
|
||||||
my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], "");
|
my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], "");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1197,6 +1197,7 @@ extern char user_conf_dir[PATH_MAX]; /* usually ~/.xschem */
|
||||||
extern char sel_file[PATH_MAX];
|
extern char sel_file[PATH_MAX];
|
||||||
extern char clip_file[PATH_MAX];
|
extern char clip_file[PATH_MAX];
|
||||||
extern char pwd_dir[PATH_MAX]; /* obtained via getcwd() */
|
extern char pwd_dir[PATH_MAX]; /* obtained via getcwd() */
|
||||||
|
extern char xschem_web_dirname[PATH_MAX];
|
||||||
extern int tcp_port;
|
extern int tcp_port;
|
||||||
extern int text_svg;
|
extern int text_svg;
|
||||||
extern int text_ps;
|
extern int text_ps;
|
||||||
|
|
|
||||||
|
|
@ -5821,20 +5821,21 @@ proc fix_symbols {n} {
|
||||||
proc download_url {url} {
|
proc download_url {url} {
|
||||||
global XSCHEM_TMP_DIR download_url_helper OS has_x
|
global XSCHEM_TMP_DIR download_url_helper OS has_x
|
||||||
# puts "download_url: $url"
|
# puts "download_url: $url"
|
||||||
if {![file exists ${XSCHEM_TMP_DIR}/xschem_web]} {
|
# puts "xschem_web_dirname: $xschem_web_dirname"
|
||||||
if {[catch {file mkdir "${XSCHEM_TMP_DIR}/xschem_web"} err]} {
|
set xschem_web_dirname [xschem get xschem_web_dirname]
|
||||||
puts $err
|
if {![file exists $xschem_web_dirname]} {
|
||||||
if {[info exists has_x]} {
|
set msg {xschem_web_xxxxx directory was not created. Remote url download will not work}
|
||||||
tk_messageBox -message "$err" -icon error -parent [xschem get topwindow] -type ok
|
puts stderr $msg
|
||||||
}
|
if {[info exists has_x]} {
|
||||||
}
|
alert_ $msg {} 0 0
|
||||||
|
}
|
||||||
|
return 1 ;# fail
|
||||||
}
|
}
|
||||||
if {$OS eq "Windows"} {
|
if {$OS eq "Windows"} {
|
||||||
set cmd "cmd /c \"cd ${XSCHEM_TMP_DIR}/xschem_web & $download_url_helper $url\""
|
set cmd "cmd /c \"cd ${xschem_web_dirname} & $download_url_helper $url\""
|
||||||
set r [catch {eval exec $cmd } res]
|
set r [catch {eval exec $cmd } res]
|
||||||
} else {
|
} else {
|
||||||
set r [catch {exec sh -c "cd ${XSCHEM_TMP_DIR}/xschem_web; $download_url_helper $url"} res]
|
set r [catch {exec sh -c "cd ${xschem_web_dirname}; $download_url_helper $url"} res]
|
||||||
}
|
}
|
||||||
# puts "download_url: url=$url, exit code=$r, res=$res"
|
# puts "download_url: url=$url, exit code=$r, res=$res"
|
||||||
return $r
|
return $r
|
||||||
|
|
@ -6000,7 +6001,7 @@ proc swap_compare_schematics {} {
|
||||||
set current [xschem get schname]
|
set current [xschem get schname]
|
||||||
# Use "file tail" to handle equality of
|
# Use "file tail" to handle equality of
|
||||||
# https://raw.githubusercon...tb_reram.sch and /tmp/xschem_web/tb_reram.sch
|
# https://raw.githubusercon...tb_reram.sch and /tmp/xschem_web/tb_reram.sch
|
||||||
if {( [regexp "^${XSCHEM_TMP_DIR}/xschem_web/" $current] && [file tail $current] eq [file tail $sch2] ) ||
|
if {( [regexp "^${XSCHEM_TMP_DIR}/xschem_web_" $current] && [file tail $current] eq [file tail $sch2] ) ||
|
||||||
( $current eq $sch2 )} { ;# user did not cancel loading
|
( $current eq $sch2 )} { ;# user did not cancel loading
|
||||||
puts "swapping..."
|
puts "swapping..."
|
||||||
if {$compare_sch} {
|
if {$compare_sch} {
|
||||||
|
|
@ -8291,12 +8292,6 @@ if {$OS == "Windows"} {
|
||||||
set_ne XSCHEM_TMP_DIR {/tmp}
|
set_ne XSCHEM_TMP_DIR {/tmp}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove temporary location for web objects
|
|
||||||
if {[file exists ${XSCHEM_TMP_DIR}/xschem_web] } {
|
|
||||||
# -force deletes also if not empty
|
|
||||||
file delete -force ${XSCHEM_TMP_DIR}/xschem_web
|
|
||||||
}
|
|
||||||
|
|
||||||
# used in C code
|
# used in C code
|
||||||
set_ne xschem_libs {}
|
set_ne xschem_libs {}
|
||||||
set_ne noprint_libs {}
|
set_ne noprint_libs {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue