From bca111028253e6acb6d376fb42b4512f0b6d827c Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 11 Jan 2025 17:55:46 +0100 Subject: [PATCH] add option -nohier to `xschem netlist` command, correctly restore netlist_dir at end --- doc/xschem_man/developer_info.html | 4 ++- src/scheduler.c | 58 ++++++++++++++++++------------ src/xschem.tcl | 2 +- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index 5b984dda..4961ea54 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -1066,7 +1066,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
  • net_pin_mismatch
  •     Highlight nets attached to selected symbols with
        a different name than symbol pin 
    -
  • netlist [-messages] [filename]
  • +   
  • netlist [-messages | -erc | -nohier] [filename]
  •     do a netlist of current schematic in currently defined netlist format
        if 'filename'is given use specified name for the netlist
        if 'filename' contains path components place the file in specified path location.
    @@ -1076,6 +1076,8 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
        will create the netlist in different places.
        netlisting directory is reset to previous setting after completing this command
        If -messages is given return the ERC messages instead of just a fail (1)
    +   If -erc is given it means netlister is called from gui, enable show infowindow
    +   If -nohier is given netlist only current level
        or no fail (0) code. 
  • new_process [f]
  •     Start a new xschem process for a schematic.
    diff --git a/src/scheduler.c b/src/scheduler.c
    index cb0837dd..799a01e4 100644
    --- a/src/scheduler.c
    +++ b/src/scheduler.c
    @@ -3184,7 +3184,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
           hilight_net_pin_mismatches();
         }
     
    -    /* netlist [-messages] [filename]
    +    /* netlist [-messages | -erc | -nohier] [filename]
          *   do a netlist of current schematic in currently defined netlist format
          *   if 'filename'is given use specified name for the netlist
          *   if 'filename' contains path components place the file in specified path location.
    @@ -3194,51 +3194,62 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
          *   will create the netlist in different places.
          *   netlisting directory is reset to previous setting after completing this command
          *   If -messages is given return the ERC messages instead of just a fail (1)
    +     *   If -erc is given it means netlister is called from gui, enable show infowindow
    +     *   If -nohier is given netlist only current level
          *   or no fail (0) code. */
         else if(!strcmp(argv[1], "netlist") )
         {
           char *saveshow = NULL;
           int err = 0;
    -      int messages = 0;
    +      int hier_netlist = 1;
    +      int i, messages = 0;
    +      int erc = 0;
           const char *fname = NULL;
           const char *path;
    +      char savedir[PATH_MAX];
           int done_netlist = 0;
           if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
           yyparse_error = 0;
           my_strdup(_ALLOC_ID_, &saveshow, tclgetvar("show_infowindow_after_netlist"));
    -      if(argc <= 2 || (argc > 2 && strcmp(argv[2], "-erc"))) { /* xschem netlist NOT invoked from GUI */
    -        tclsetvar("show_infowindow_after_netlist", "never");
    -      }
    -      if(argc > 2) {
    -        if(!strcmp(argv[2], "-messages")) {
    -          messages = 1;
    -          if(argc > 3) fname = argv[3];
    -        } else if(strcmp(argv[2], "-erc")) {
    -          fname = argv[2];
    -        }
    -        if(fname) {
    -          my_strncpy(xctx->netlist_name, get_cell_w_ext(fname, 0), S(xctx->netlist_name));
    -          tclvareval("file dirname ", fname, NULL);
    -          path = tclresult();
    -          if(strchr(fname, '/')) {
    -            set_netlist_dir(1, path);
    +
    +      my_strncpy(savedir, tclgetvar("netlist_dir"), S(savedir));
    +      for(i = 2; i < argc; i++) {
    +        if(argv[i][0] == '-') {
    +          if(!strcmp(argv[i], "-messages")) {
    +            messages = 1;
    +          } else if(!strcmp(argv[i], "-erc")) {
    +            erc = 1;
    +          } else if(!strcmp(argv[i], "-nohier")) {
    +            hier_netlist = 0;
               }
    +        } else {
    +          fname = argv[i];
    +          break;
    +        }
    +      }
    +      if(erc == 0) tclsetvar("show_infowindow_after_netlist", "never");
    +      if(fname) {
    +        my_strncpy(xctx->netlist_name, get_cell_w_ext(fname, 0), S(xctx->netlist_name));
    +        tclvareval("file dirname ", fname, NULL);
    +        path = tclresult();
    +        if(strchr(fname, '/')) {
    +          set_netlist_dir(1, path);
             }
           }
           if(set_netlist_dir(0, NULL) ) {
             done_netlist = 1;
             if(xctx->netlist_type == CAD_SPICE_NETLIST)
    -          err = global_spice_netlist(1);                  /* 1 means global netlist */
    +          err = global_spice_netlist(hier_netlist);                  /* 1 means global netlist */
             else if(xctx->netlist_type == CAD_VHDL_NETLIST)
    -          err = global_vhdl_netlist(1);
    +          err = global_vhdl_netlist(hier_netlist);
             else if(xctx->netlist_type == CAD_VERILOG_NETLIST)
    -          err = global_verilog_netlist(1);
    +          err = global_verilog_netlist(hier_netlist);
             else if(xctx->netlist_type == CAD_TEDAX_NETLIST)
    -          global_tedax_netlist(1);
    +          global_tedax_netlist(hier_netlist);
             else
               if(has_x) tcleval("tk_messageBox -type ok -parent [xschem get topwindow] "
                                 "-message {Please Set netlisting mode (Options menu)}");
    -        if( (argc ==3 && strcmp(argv[2], "-erc") ) || argc > 3) {
    +        if( (erc == 0) ) {
               my_strncpy(xctx->netlist_name, "", S(xctx->netlist_name));
             }
           }
    @@ -3259,6 +3270,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
             }
           }
           tclsetvar("show_infowindow_after_netlist", saveshow);
    +      set_netlist_dir(1, savedir);
           if(done_netlist) {
             if(messages) {
               Tcl_SetResult(interp, xctx->infowindow_text, TCL_VOLATILE);
    diff --git a/src/xschem.tcl b/src/xschem.tcl
    index f20d0a69..fee05f7b 100644
    --- a/src/xschem.tcl
    +++ b/src/xschem.tcl
    @@ -1787,7 +1787,7 @@ proc cellview_setlabels {w symbol sym_sch default_sch sym_spice_sym_def} {
         $w configure -fg $symfg
       } else {
         if {[$w get] eq $default_sch} {
    -        puts "need to clear schematic attr in symbol"
    +        puts "$symbol: need to clear schematic attr in symbol"
         } elseif {[$w get] eq $sym_sch} {
           $w configure -bg $symbg
         } else {