diff --git a/src/token.c b/src/token.c index 8f5819ca..bdb27ac1 100644 --- a/src/token.c +++ b/src/token.c @@ -520,7 +520,7 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) if(c=='"') { if((with_quotes & 1) || escape) result[value_pos++]=c; } - else if( !((c == '\\') && (with_quotes & 2)) ) result[value_pos++]=c; /* skip unescaped backslashes */ + else if( !quote || !((c == '\\') && (with_quotes & 2)) ) result[value_pos++]=c; /* skip unescaped backslashes */ else if( (c == '\\') && escape ) result[value_pos++]=c; /* 20170414 add escaped backslashes */ } else if(state==XENDTOK || state==XSEPARATOR) { if(token_pos) { @@ -1656,7 +1656,11 @@ void print_spice_element(FILE *fd, int inst) my_strdup(22, &result, translate(inst, result)); dbg(1, "print_spice_element(): after translate()result=%s\n", result); } - + /* do a second round of substitutions, but without calling tcl */ + if(result && strstr(result, "eval(") == result) { + result[strlen(result)-1] = '\0'; + my_strdup2(88, &result, translate(inst, result+5)); + } fprintf(fd, "%s", result); my_free(1019, &template); my_free(1020, &format); @@ -1665,10 +1669,6 @@ void print_spice_element(FILE *fd, int inst) my_free(1194, &result); } - - - - void print_tedax_element(FILE *fd, int inst) { int i=0, mult; @@ -2585,10 +2585,17 @@ const char *translate(int inst, const char* s) } if(!get_tok_size && token[0] =='$') { - tmp=token_pos -1 ; /* we need token_pos -1 chars, ( strlen(token+1) ) , excluding leading '$' */ - STR_ALLOC(&result, tmp + result_pos, &size); - dbg(2, "translate(): token=%s, token_pos = %d\n", token, token_pos); - memcpy(result+result_pos, token + 1, tmp+1); + char *env = getenv(token + 1); + if(env) { /* do environment var substitution if no xschem definition for $token */ + tmp = strlen(env); + STR_ALLOC(&result, tmp + result_pos, &size); + memcpy(result+result_pos, env, tmp+1); + } else { /* no definition found -> subst with token without leading $ */ + tmp=token_pos -1 ; /* we need token_pos -1 chars, ( strlen(token+1) ) , excluding leading '$' */ + STR_ALLOC(&result, tmp + result_pos, &size); + dbg(2, "translate(): token=%s, token_pos = %d\n", token, token_pos); + memcpy(result+result_pos, token + 1, tmp+1); + } result_pos+=tmp; } token_pos = 0; diff --git a/src/xschem.tcl b/src/xschem.tcl index f7e14e7b..c2db86de 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -843,11 +843,26 @@ proc edit_netlist {schname } { if { $netlist_type=="verilog" } { execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.v\"" } elseif { $netlist_type=="spice" } { - execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.spice\"" + if {$::OS == "Windows"} { + set cmd "$editor \"$netlist_dir/${tmpname}.spice\"" + eval exec $cmd + } else { + execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.spice\"" + } } elseif { $netlist_type=="tedax" } { - execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.tdx\"" + if {$::OS == "Windows"} { + set cmd "$editor \"$netlist_dir/${tmpname}.tdx\"" + eval exec $cmd + } else { + execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.tdx\"" + } } elseif { $netlist_type=="vhdl" } { - execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.vhdl\"" + if {$::OS == "Windows"} { + set cmd "$editor \"$netlist_dir/${tmpname}.vhdl\"" + eval exec $cmd + } else { + execute 0 sh -c "cd $netlist_dir; $editor $ftype \"${tmpname}.vhdl\"" + } } } return {} @@ -1868,14 +1883,14 @@ proc tclpropeval {s instname symname} { # this hook is called in translate() if whole string is contained in a tcleval(...) construct proc tclpropeval2 {s} { - global tcl_debug + global tcl_debug env if {$tcl_debug <=-1} {puts "tclpropeval2: $s"} set path [string range [xschem get sch_path] 1 end] regsub {^tcleval\(} $s {} s regsub {\)([ \n\t]*)$} $s {\1} s if { [catch {subst $s} res] } { - # puts "tclpropeval2 warning: $res" - set res {?} + if { $tcl_debug<=-1 } { puts "tclpropeval2 warning: $res"} + set res ?\n } return $res } @@ -2013,6 +2028,7 @@ proc edit_vi_netlist_prop {txtlabel} { if ![string compare $netlist_type "vhdl"] { set suffix vhd } else { set suffix v } set filename $filename.$suffix regsub -all {\\?"} $retval {"} retval + regsub -all {\\?\\} $retval {\\} retval write_data $retval $XSCHEM_TMP_DIR/$filename if { [regexp vim $editor] } { set ftype "\{-c :set filetype=$netlist_type\}" } else { set ftype {} } eval execute_wait 0 $editor $ftype $XSCHEM_TMP_DIR/$filename @@ -2022,7 +2038,7 @@ proc edit_vi_netlist_prop {txtlabel} { if $tcl_debug<=-1 then {puts "edit_vi_prop{}:\n--------\n$tmp\n---------\n"} if [string compare $tmp $retval] { set retval $tmp - regsub -all {(["\\])} $retval {\\\1} retval + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote set retval \"${retval}\" if $tcl_debug<=-1 then {puts "modified"} set rcode ok @@ -2123,7 +2139,7 @@ proc edit_prop {txtlabel} { set retval [.dialog.e1 get 1.0 {end - 1 chars}] if { $selected_tok ne {} } { - regsub -all {(["\\])} $retval {\\\1} retval + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote set retval \"${retval}\" set retval [xschem subst_tok $retval_orig $selected_tok $retval] set selected_tok {} @@ -2223,7 +2239,7 @@ proc edit_prop {txtlabel} { set retval_orig [.dialog.e1 get 1.0 {end - 1 chars}] } else { set retval [.dialog.e1 get 1.0 {end - 1 chars}] - regsub -all {(["\\])} $retval {\\\1} retval + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote set retval \"${retval}\" set retval_orig [xschem subst_tok $retval_orig $old_selected_tok $retval] } @@ -2246,7 +2262,7 @@ proc edit_prop {txtlabel} { } else { set retval [.dialog.e1 get 1.0 {end - 1 chars}] if {$retval ne {}} { - regsub -all {(["\\])} $retval {\\\1} retval + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote set retval \"${retval}\" set retval_orig [xschem subst_tok $retval_orig $old_selected_tok $retval] } @@ -2345,7 +2361,7 @@ proc text_line {txtlabel clear {preserve_disabled disabled} } { { set retval [.dialog.e1 get 1.0 {end - 1 chars}] if { $selected_tok ne {} } { - regsub -all {(["\\])} $retval {\\\1} retval + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote set retval \"${retval}\" set retval [xschem subst_tok $retval_orig $selected_tok $retval] set selected_tok {} @@ -2373,7 +2389,9 @@ proc text_line {txtlabel clear {preserve_disabled disabled} } { .dialog.e1 delete 1.0 end } label .dialog.f1.r4 -text { Edit Attr:} - ttk::combobox .dialog.f1.r5 -values $tok_list -textvariable selected_tok -width 14 + if { [ info tclversion] > 8.4} { + ttk::combobox .dialog.f1.r5 -values $tok_list -textvariable selected_tok -width 14 + } checkbutton .dialog.f0.l2 -text "preserve unchanged props" -variable preserve_unchanged_attrs -state $preserve_disabled pack .dialog.f0 -fill x @@ -2385,7 +2403,7 @@ proc text_line {txtlabel clear {preserve_disabled disabled} } { pack .dialog.f1.b3 -side left -fill x -expand yes pack .dialog.f1.b4 -side left -fill x -expand yes pack .dialog.f1.r4 -side left - pack .dialog.f1.r5 -side left + if { [ info tclversion] > 8.4} {pack .dialog.f1.r5 -side left} pack .dialog.yscroll -side right -fill y @@ -2397,49 +2415,51 @@ proc text_line {txtlabel clear {preserve_disabled disabled} } { } } - bind .dialog.f1.r5 <> { - if {$old_selected_tok ne $selected_tok} { - if { $old_selected_tok eq {} } { + if { [ info tclversion] > 8.4} { + bind .dialog.f1.r5 <> { + if {$old_selected_tok ne $selected_tok} { + if { $old_selected_tok eq {} } { + set retval_orig [.dialog.e1 get 1.0 {end - 1 chars}] + } else { + set retval [.dialog.e1 get 1.0 {end - 1 chars}] + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote + set retval \"${retval}\" + set retval_orig [xschem subst_tok $retval_orig $old_selected_tok $retval] + } + } + if {$selected_tok eq {} } { + set retval $retval_orig + } else { + set retval [xschem get_tok $retval_orig $selected_tok 2] + # regsub -all {\\?"} $retval {"} retval + } + .dialog.e1 delete 1.0 end + .dialog.e1 insert 1.0 $retval + set old_selected_tok $selected_tok + } + + bind .dialog.f1.r5 { + set selected_tok [.dialog.f1.r5 get] + if { $old_selected_tok eq {}} { set retval_orig [.dialog.e1 get 1.0 {end - 1 chars}] } else { set retval [.dialog.e1 get 1.0 {end - 1 chars}] - regsub -all {(["\\])} $retval {\\\1} retval - set retval \"${retval}\" - set retval_orig [xschem subst_tok $retval_orig $old_selected_tok $retval] + if {$retval ne {}} { + regsub -all {(["\\])} $retval {\\\1} retval ;#" editor is confused by the previous quote + set retval \"${retval}\" + set retval_orig [xschem subst_tok $retval_orig $old_selected_tok $retval] + } } - } - if {$selected_tok eq {} } { - set retval $retval_orig - } else { - set retval [xschem get_tok $retval_orig $selected_tok 2] - # regsub -all {\\?"} $retval {"} retval - } - .dialog.e1 delete 1.0 end - .dialog.e1 insert 1.0 $retval - set old_selected_tok $selected_tok - } - - bind .dialog.f1.r5 { - set selected_tok [.dialog.f1.r5 get] - if { $old_selected_tok eq {}} { - set retval_orig [.dialog.e1 get 1.0 {end - 1 chars}] - } else { - set retval [.dialog.e1 get 1.0 {end - 1 chars}] - if {$retval ne {}} { - regsub -all {(["\\])} $retval {\\\1} retval - set retval \"${retval}\" - set retval_orig [xschem subst_tok $retval_orig $old_selected_tok $retval] + if {$selected_tok eq {} } { + set retval $retval_orig + } else { + set retval [xschem get_tok $retval_orig $selected_tok 2] + # regsub -all {\\?"} $retval {"} retval } + .dialog.e1 delete 1.0 end + .dialog.e1 insert 1.0 $retval + set old_selected_tok $selected_tok } - if {$selected_tok eq {} } { - set retval $retval_orig - } else { - set retval [xschem get_tok $retval_orig $selected_tok 2] - # regsub -all {\\?"} $retval {"} retval - } - .dialog.e1 delete 1.0 end - .dialog.e1 insert 1.0 $retval - set old_selected_tok $selected_tok } bind .dialog {.dialog.f1.b1 invoke} diff --git a/src/xschemrc b/src/xschemrc index 4fd6b924..8fd6ae3f 100644 --- a/src/xschemrc +++ b/src/xschemrc @@ -197,6 +197,8 @@ set terminal {xterm -geometry 100x35 -fn 9x15 -bg black -fg white -cr white -ms ## editor must not detach from launching shell (-f mandatory for gvim) # set editor { xterm -geometry 100x40 -e nano } # set editor { xterm -geometry 100x40 -e pico } +# For Windows +# set editor {notepad.exe} set editor {gvim -f -geometry 90x28} #### show info window (ERC rules errors warnings etc) diff --git a/xschem_library/examples/0_examples_top.sch b/xschem_library/examples/0_examples_top.sch index 341c66bc..1ad03455 100644 --- a/xschem_library/examples/0_examples_top.sch +++ b/xschem_library/examples/0_examples_top.sch @@ -51,16 +51,16 @@ N 930 -310 960 -300 {lab=#net1} N 380 -530 700 -530 {lab=BUS[4:0]} N 510 -640 510 -540 {lab=BUS[1]} N 410 -600 410 -540 {lab=BUS[2]} -C {poweramp.sym} 160 -310 0 0 {name=x1 +C {poweramp.sym} 160 -440 0 0 {name=x1 tclcommand="xschem descend"} -C {tesla.sym} 160 -230 0 0 {name=x2} -C {test_ne555.sym} 160 -190 0 0 {name=x3} -C {test_lm324.sym} 160 -150 0 0 {name=x4} -C {osc.sym} 160 -270 0 0 {name=x5} +C {tesla.sym} 160 -360 0 0 {name=x2} +C {test_ne555.sym} 160 -320 0 0 {name=x3} +C {test_lm324.sym} 160 -280 0 0 {name=x4} +C {osc.sym} 160 -400 0 0 {name=x5} C {title.sym} 160 -30 0 0 {name=l1 author="Stefan Schippers"} -C {cmos_example.sym} 160 -350 0 0 {name=x6} -C {greycnt.sym} 160 -390 0 0 {name=x8} -C {loading.sym} 160 -430 0 0 {name=x9} +C {cmos_example.sym} 160 -480 0 0 {name=x6} +C {greycnt.sym} 160 -520 0 0 {name=x8} +C {loading.sym} 160 -560 0 0 {name=x9} C {inv_bsource.sym} 930 -200 0 0 {name=B1 TABLE="1.4 3.0 1.6 0.0"} C {launcher.sym} 460 -210 0 0 {name=h1 descr="XSCHEM ON REPO.HU" @@ -77,9 +77,10 @@ url="$\{XSCHEM_SHAREDIR\}/../doc/xschem/index.html" program=x-www-browser } -C {rlc.sym} 160 -470 0 0 {name=x0} +C {rlc.sym} 160 -600 0 0 {name=x0} C {lab_pin.sym} 700 -530 0 1 {name=l2 sig_type=std_logic lab=BUS[4:0]} C {bus_connect.sym} 500 -530 0 0 {name=l3 lab=BUS[1]} C {bus_connect_nolab.sym} 400 -530 0 0 {name=r1} C {lab_pin.sym} 410 -600 3 1 {name=l4 sig_type=std_logic lab=BUS[2]} -C {LCC_instances.sym} 160 -110 0 0 {name=x7} +C {LCC_instances.sym} 160 -240 0 0 {name=x7} +C {test_backannotated_subckt.sym} 160 -200 0 0 {name=x10} diff --git a/xschem_library/examples/rcline.sch b/xschem_library/examples/rcline.sch new file mode 100644 index 00000000..3eff70c3 --- /dev/null +++ b/xschem_library/examples/rcline.sch @@ -0,0 +1,29 @@ +v { version=2.9.8 file_version=1.2} +G {} +K {} +V {} +S {} +E {} +N 370 -180 420 -180 { lab=OUT} +N 270 -180 310 -180 { lab=#net1} +N 170 -180 210 -180 { lab=IN} +N 290 -180 290 -130 { lab=#net1} +N 290 -70 290 -40 { lab=0} +C {ipin.sym} 170 -180 0 0 {name=p1 lab=IN} +C {opin.sym} 420 -180 0 0 {name=p2 lab=OUT} +C {capa.sym} 290 -100 0 0 {name=C1 +m=1 +value='Cap/2' +footprint=1206 +device="ceramic capacitor"} +C {res.sym} 340 -180 3 0 {name=R1 +value='Res/2' +footprint=1206 +device=resistor +m=1} +C {res.sym} 240 -180 3 0 {name=R2 +value='Res/2' +footprint=1206 +device=resistor +m=1} +C {lab_pin.sym} 290 -40 0 0 {name=l1 sig_type=std_logic lab=0} diff --git a/xschem_library/examples/rcline.sym b/xschem_library/examples/rcline.sym new file mode 100644 index 00000000..ef061732 --- /dev/null +++ b/xschem_library/examples/rcline.sym @@ -0,0 +1,24 @@ +v {xschem version=2.9.8 file_version=1.2} +G {} +K {type=subcircuit +format="tcleval(@name @pinlist @symname [ calc_rc @L @W ])" +template="name=x1 Res=1e4 Cap=1e-6" + +} +V {} +S {} +E {} +L 4 -130 -20 130 -20 {} +L 4 -130 20 130 20 {} +L 4 -130 -20 -130 20 {} +L 4 130 -20 130 20 {} +L 4 130 0 150 0 {} +L 4 -150 0 -130 0 {} +B 5 147.5 -2.5 152.5 2.5 {name=OUT dir=out name=p2 } +B 5 -152.5 -2.5 -147.5 2.5 {name=IN dir=in name=p1 } +T {@symname} 2 -6 0 0 0.3 0.3 {hcenter=true} +T {@name} 135 -32 0 0 0.2 0.2 {} +T {OUT} 125 -4 0 1 0.2 0.2 {} +T {IN} -125 -4 0 0 0.2 0.2 {} +T {L=@L +W=@W} -70 -70 0 0 0.4 0.4 {} diff --git a/xschem_library/examples/test_backannotated_subckt.sch b/xschem_library/examples/test_backannotated_subckt.sch new file mode 100644 index 00000000..dd6a52e7 --- /dev/null +++ b/xschem_library/examples/test_backannotated_subckt.sch @@ -0,0 +1,36 @@ +v { version=2.9.8 file_version=1.2} +G {} +K {} +V {} +S {} +E {} +T {To run this example a 'calc_rc' procedure must be defined. +you can paste example procedure below into xschem command prompt before +creating a netlist. +Descend into the symbol ('i' key) and see how it is used in the 'format' +attribute to calculate "Res" and "Cap" subcircuit parameters from W and L +instance parameters. +Tcl scripts can be loaded in xcshemrc by appending a tcl file name to variable +tcl_files.} 40 -390 2 1 0.5 0.5 {layer=8 } +T {proc calc_rc \{ L W \} \{ return "Res=[expr 1200*$L/$W] Cap=[expr 1e-3*$W*$L]"\} } 30 -320 0 0 0.4 0.4 { font=monospace} +T {Dynamic calculation of subcircuit parameters} 80 -730 0 0 0.8 0.8 {} +N 140 -130 140 -100 { lab=0} +N 140 -210 160 -210 { lab=IN} +N 140 -210 140 -190 { lab=IN} +C {lab_pin.sym} 620 -190 0 1 {name=p1 lab=OUT} +C {lab_pin.sym} 320 -190 0 0 {name=p2 lab=IN} +C {title.sym} 160 -30 0 0 {name=l1 author="Stefan Schippers"} +C {vsource.sym} 140 -160 0 0 {name=V1 value="pwl 0 0 10n 0 11n 5"} +C {lab_pin.sym} 140 -100 0 0 {name=l2 sig_type=std_logic lab=0} +C {lab_pin.sym} 160 -210 0 1 {name=p3 lab=IN} +C {rcline.sym} 470 -190 0 0 {name=x1 L=1e-4 W=0.5e-6 +} +C {code_shown.sym} 890 -190 0 0 {name=STIMULI +only_toplevel=false + +value=" +.control +tran 0.1n 50n +plot in out +.endc +"} diff --git a/xschem_library/examples/test_backannotated_subckt.sym b/xschem_library/examples/test_backannotated_subckt.sym new file mode 100644 index 00000000..7566b5e0 --- /dev/null +++ b/xschem_library/examples/test_backannotated_subckt.sym @@ -0,0 +1,15 @@ +v {xschem version=2.9.8 file_version=1.2} +G {} +K {type=subcircuit +format="@name @pinlist @symname" +template="name=x1" +} +V {} +S {} +E {} +L 4 -130 -10 130 -10 {} +L 4 -130 10 130 10 {} +L 4 -130 -10 -130 10 {} +L 4 130 -10 130 10 {} +T {@symname} -100.5 -6 0 0 0.3 0.3 {} +T {@name} 135 -22 0 0 0.2 0.2 {} diff --git a/xschem_library/ngspice/autozero_comp.sch b/xschem_library/ngspice/autozero_comp.sch index 8593e9de..fda51e7e 100644 --- a/xschem_library/ngspice/autozero_comp.sch +++ b/xschem_library/ngspice/autozero_comp.sch @@ -210,7 +210,7 @@ value="* .option SCALE=1e-6 .control let run=1 - dowhile run <= 40 + dowhile run <= 10 if run > 1 reset set appendwrite