cleanup set_netlist_dir tcl proc

This commit is contained in:
stefan schippers 2023-11-08 00:44:29 +01:00
parent a128df47e0
commit eb7ad4cd8e
3 changed files with 68 additions and 55 deletions

View File

@ -311,11 +311,23 @@ void set_grid(double newgrid)
tclsetdoublevar("cadgrid", cg);
}
int set_netlist_dir(int force, const char *dir)
/*
*
* change==0: force creation of $netlist_dir (if netlist_dir variable not empty)
*
* change==1: if no dir given prompt user
* else set netlist_dir to dir
*
* Return 1 if netlist_dir is a valid directory and existing
* Return 0 otherwise
*
*/
int set_netlist_dir(int change, const char *dir)
{
char cmd[PATH_MAX+200];
if(dir) my_snprintf(cmd, S(cmd), "set_netlist_dir %d {%s}", force, dir);
else my_snprintf(cmd, S(cmd), "set_netlist_dir %d", force);
if(dir) my_snprintf(cmd, S(cmd), "set_netlist_dir %d {%s}", change, dir);
else my_snprintf(cmd, S(cmd), "set_netlist_dir %d", change);
tcleval(cmd);
if(!strcmp("", tclresult()) ) {
return 0;

View File

@ -1233,7 +1233,7 @@ extern void dbg(int level, char *fmt, ...);
extern unsigned int hash_file(const char *f, int skip_path_lines);
extern void here(double i);
extern void print_version(void);
extern int set_netlist_dir(int force, const char *dir);
extern int set_netlist_dir(int change, const char *dir);
extern void netlist_options(int i);
extern int check_lib(int what, const char *s);
extern int floaters_from_selected_inst();

View File

@ -3769,18 +3769,11 @@ proc make_symbol_lcc {name} {
return {}
}
# create simulation dir 'simulation/' under current schematic directory
# point netlist_dir to simulation dir 'simulation/' under current schematic directory
proc simuldir {} {
global netlist_dir local_netlist_dir has_x
if { $local_netlist_dir == 1 } {
set simdir [xschem get current_dirname]/simulation
# if {[catch {file mkdir "$simdir"} err]} {
# puts $err
# if {[info exists has_x]} {
# tk_messageBox -message "$err" -icon error -parent [xschem get topwindow] -type ok
# }
# }
set netlist_dir $simdir
return $netlist_dir
}
@ -3788,64 +3781,72 @@ proc simuldir {} {
}
#
# force==0: force creation of $netlist_dir (if netlist_dir variable not empty)
# change==0: force creation of $netlist_dir (if netlist_dir variable not empty)
# and return current setting.
# if netlist_dir variable empty:
# if no dir given prompt user
# else set netlist_dir to dir
#
# force==1: if no dir given prompt user
# change==1: if no dir given prompt user
# else set netlist_dir to dir
#
# Return current netlist directory
#
proc set_netlist_dir { force {dir {} }} {
proc set_netlist_dir { change {dir {} }} {
global netlist_dir env OS has_x
#### set local-to-schematic-dir if local_netlist_dir tcl var is set
simuldir
if { ( $force == 0 ) && ( $netlist_dir ne {} ) } {
if {![file exist $netlist_dir]} {
if {[catch {file mkdir "$netlist_dir"} err]} {
puts $err
if {[info exists has_x]} {
tk_messageBox -message "$err" -icon error -parent [xschem get topwindow] -type ok
}
#### change == 0
if {$change == 0} {
if {$netlist_dir ne {}} {
if {![file exist $netlist_dir]} {
if {[catch {file mkdir "$netlist_dir"} err]} {
puts $err
if {[info exists has_x]} {
tk_messageBox -message "$err" -icon error -parent [xschem get topwindow] -type ok
}
}
}
}
regsub {^~/} $netlist_dir ${env(HOME)}/ netlist_dir
return $netlist_dir
}
if { $dir eq {} } {
if { $netlist_dir ne {} } {
set initdir $netlist_dir
} else {
if {$OS == "Windows"} {
set initdir $env(windir)
} else {
set initdir [pwd]
}
}
# 20140409 do not change netlist_dir if user Cancels action
set new_dir [tk_chooseDirectory -initialdir $initdir \
-parent [xschem get topwindow] -title {Select netlist DIR} -mustexist false]
}
#### change == 1
} else {
set new_dir $dir
}
if {$new_dir ne {} } {
if {![file exist $new_dir]} {
if {[catch {file mkdir "$new_dir"} err]} {
puts $err
if {[info exists has_x]} {
tk_messageBox -message "$err" -icon error -parent [xschem get topwindow] -type ok
}
if { $dir eq {} } {
if { $netlist_dir ne {} } {
set initdir $netlist_dir
} else {
if {$OS == "Windows"} {
set initdir $env(windir)
} else {
set initdir [pwd]
}
}
# prompt user for a dir
set new_dir [tk_chooseDirectory -initialdir $initdir \
-parent [xschem get topwindow] -title {Select netlist DIR} -mustexist false]
} else {
# use provided dir argument
set new_dir $dir
}
# create new dir if not already existing
if {$new_dir ne {} } {
if {![file exist $new_dir]} {
if {[catch {file mkdir "$new_dir"} err]} {
puts $err
if {[info exists has_x]} {
tk_messageBox -message "$err" -icon error -parent [xschem get topwindow] -type ok
}
}
}
set netlist_dir $new_dir
}
set netlist_dir $new_dir
}
regsub {^~/} $netlist_dir ${env(HOME)}/ netlist_dir
return $netlist_dir
# return $netlist_dir if valid and existing, else return empty string
if {$netlist_dir ne {} && [file exists $netlist_dir]} {
return $netlist_dir
}
return {}
}