some little optimizations, redundant code removed, better formatting in globals.c

This commit is contained in:
Stefan Frederik 2021-12-02 13:28:40 +01:00
parent cb8ffce9cf
commit 02173373cb
7 changed files with 123 additions and 89 deletions

View File

@ -1130,7 +1130,7 @@ void go_back(int confirm) /* 20171006 add confirm */
if(from_embedded_sym) xctx->modified=save_modified; /* to force ask save embedded sym in parent schematic */
if(xctx->hilight_nets) {
if(prev_sch_type != CAD_SYMBOL_ATTRS) hilight_parent_pins();
if(prev_sch_type != CAD_SYMBOL_ATTRS) hilight_parent_pins();
propagate_hilights(1, 0, XINSERT_NOREPLACE);
}
xctx->xorigin=xctx->zoom_array[xctx->currsch].x;
@ -1632,10 +1632,8 @@ void new_wire(int what, double mx_snap, double my_snap)
* this clears both xctx->prep_hi_structs and xctx->prep_net_structs. */
if(!big) {
bbox(START , 0.0 , 0.0 , 0.0 , 0.0);
if(s_pnetname || xctx->hilight_nets) {
int_hash_lookup(xctx->node_redraw_table, xctx->wire[xctx->wires-1].node, 0, XINSERT_NOREPLACE);
find_inst_to_be_redrawn();
}
int_hash_lookup(xctx->node_redraw_table, xctx->wire[xctx->wires-1].node, 0, XINSERT_NOREPLACE);
find_inst_to_be_redrawn(1);
bbox(SET , 0.0 , 0.0 , 0.0 , 0.0);
}
draw();

View File

@ -30,71 +30,94 @@ Display *display;
Colormap colormap;
unsigned char **pixdata;
unsigned char pixdata_init[22][32]={ /* fill patterns... indexed by laynumb. */
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,/*0 */
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,/*1 */
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*2 */
{/*3 */
0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00,
0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00
},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,/*4 */
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,/*5 */
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{/*6 */
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{/*7 */
0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
},
{/*8 */
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{/*9 */
0x04, 0x41, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x41, 0x10, 0x00, 0x00,
0x04, 0x41, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x41, 0x10, 0x00, 0x00,
0x04, 0x41, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00
},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,/*10 */
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{/*11 */
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
0x44, 0x44, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00
},
{/*12 */
0x04, 0x04, 0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20,
0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01, 0x80, 0x80,
0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08
},
{/*13 */
0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88,
0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88
},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*14 */
{/*15 */
0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00,/*16 */
0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*17 */
{0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,/*18 */
0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*19 */
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*20 */
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}/*21 */
{ /* 0 */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
{ /* 1 */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
{ /* 2 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 3 */
0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00,
0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00
},
{ /* 4 */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
{ /* 5 */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
{ /* 6 */
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 7 */
0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
},
{ /* 8 */
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 9 */
0x04, 0x41, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x41, 0x10, 0x00, 0x00, 0x04, 0x41, 0x00, 0x00,
0x10, 0x04, 0x00, 0x00, 0x41, 0x10, 0x00, 0x00, 0x04, 0x41, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00
},
{ /* 10 */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
{ /* 11 */
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00
},
{ /* 12 */
0x04, 0x04, 0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08,
0x04, 0x04, 0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08
},
{ /*13 */
0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88,
0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88
},
{ /* 14 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 15 */
0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 16 */
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 17 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 18 */
0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa
},
{ /* 19 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 20 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ /* 21 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}
};
int screen_number;
int screendepth;

View File

@ -654,8 +654,8 @@ void prepare_netlist_structs(int for_netlist)
* a second prepare_netlist_structs() is called to name unnamed nets, in this second call
* print_erc must be set to 0 to avoid double erc printing
*/
print_erc = xctx->netlist_count == 0 || startlevel < xctx->currsch;
if (for_netlist>0) {
print_erc = (xctx->netlist_count == 0 || startlevel < xctx->currsch) && for_netlist;
if (for_netlist) {
my_snprintf(nn, S(nn), "-----------%s", xctx->sch[xctx->currsch]);
statusmsg(nn,2);
}

View File

@ -1469,7 +1469,7 @@ static void align_sch_pins_with_sym(const char *name, int pos)
if ((ptr = strrchr(name, '.')) && !strcmp(ptr, ".sch")) {
my_strncpy(symname, add_ext(name, ".sym"), S(symname));
for(i = 0; i < HASHSIZE; i++) pintable[i] = NULL;
memset(pintable, 0, HASHSIZE * sizeof(struct int_hashentry *));
/* hash all symbol pins with their position into pintable hash*/
get_sym_type(symname, &symtype, pintable, NULL, &sym_n_pins);
if(symtype[0]) { /* found a .sym for current .sch LCC instance */

View File

@ -140,6 +140,8 @@ void xschem_cmd_help(int argc, const char **argv)
" topwindow\n",
" version\n",
" wirelayer\n",
" xorigin\n",
" yorigin\n",
"get_tok\n",
"get_tok_size\n",
"getprop\n",
@ -901,6 +903,16 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
my_snprintf(s, S(s), "%d",WIRELAYER);
Tcl_SetResult(interp, s,TCL_VOLATILE);
}
else if(!strcmp(argv[2],"xorigin")) {
char s[128];
my_snprintf(s, S(s), "%.16g", xctx->xorigin);
Tcl_SetResult(interp, s,TCL_VOLATILE);
}
else if(!strcmp(argv[2],"yorigin")) {
char s[128];
my_snprintf(s, S(s), "%.16g", xctx->yorigin);
Tcl_SetResult(interp, s,TCL_VOLATILE);
}
else {
fprintf(errfp, "xschem get %s: invalid command.\n", argv[2]);
}

View File

@ -2875,19 +2875,20 @@ const char *translate(int inst, const char* s)
}
if(n>=0 && pin_attr[0] && n < (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER]) {
char *pin_attr_value = NULL;
int is_net_name = !strcmp(pin_attr, "net_name");
/* get pin_attr value from instance: "pinnumber(ENABLE)=5" --> return 5, attr "pinnumber" of pin "ENABLE"
* "pinnumber(3)=6 --> return 6, attr "pinnumber" of 4th pin */
if(!pin_attr_value) pin_attr_value = get_pin_attr_from_inst(inst, n, pin_attr);
/* get pin_attr from instance pin attribute string */
if(!pin_attr_value) {
my_strdup(499, &pin_attr_value,
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][n].prop_ptr, pin_attr, 0));
if(!is_net_name) {
pin_attr_value = get_pin_attr_from_inst(inst, n, pin_attr);
/* get pin_attr from instance pin attribute string */
if(!pin_attr_value) {
my_strdup(499, &pin_attr_value,
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][n].prop_ptr, pin_attr, 0));
}
}
/* @#n:net_name attribute (n = pin number or name) will translate to net name attached to pin
* if 'net_name=true' attribute is set in instance or symbol */
if( !pin_attr_value && !strcmp(pin_attr, "net_name")) {
if(!pin_attr_value && is_net_name) {
char *instprop = xctx->inst[inst].prop_ptr;
char *symprop = (xctx->inst[inst].ptr + xctx->sym)->prop_ptr;
if(s_pnetname && (!strcmp(get_tok_value(instprop, "net_name", 0), "true") ||

View File

@ -76,7 +76,7 @@ static int client_msg(Display *disp, Window win, char *msg, /* {{{ */
int window_state (Display *disp, Window win, char *arg) {/*{{{*/
static char *arg_copy=NULL;
char arg_copy[256]; /* overflow safe */
unsigned long action;
int i;
Atom prop1 = 0;
@ -85,18 +85,17 @@ int window_state (Display *disp, Window win, char *arg) {/*{{{*/
const char *argerr = "expects a list of comma separated parameters: "
"\"(remove|add|toggle),<PROP1>[,<PROP2>]\"\n";
char tmp_prop1[256], tmp1[256]; /* overflow safe */
char tmp_prop2[256], tmp2[256]; /* overflow safe */
my_strdup(604, &arg_copy, arg);
dbg(1,"window_state() , win=0x%x arg_copy=%s\n",
(int)win,arg_copy);
if (!arg_copy || strlen(arg_copy) == 0) {
if (!arg || strlen(arg) == 0) {
fputs(argerr, errfp);
return EXIT_FAILURE;
}
dbg(1,"window_state() , win=0x%x arg=%s\n", (int)win, arg);
my_strncpy(arg_copy, arg, S(arg_copy));
if ((p1 = strchr(arg_copy, ','))) {
static char tmp_prop1[1024], tmp1[1024]; /* overflow safe 20161122 */
*p1 = '\0';
@ -118,7 +117,6 @@ int window_state (Display *disp, Window win, char *arg) {/*{{{*/
/* the second property */
if ((p2 = strchr(p1, ','))) {
static char tmp_prop2[1024], tmp2[1024]; /* overflow safe */
*p2 = '\0';
p2++;
if (strlen(p2) == 0) {
@ -126,6 +124,7 @@ int window_state (Display *disp, Window win, char *arg) {/*{{{*/
return EXIT_FAILURE;
}
for( i = 0; p2[i]; i++) tmp2[i] = toupper( p2[i] );
tmp2[i] = '\0';
my_snprintf(tmp_prop2, S(tmp_prop2), "_NET_WM_STATE_%s", tmp2);
prop2 = XInternAtom(disp, tmp_prop2, False);
}
@ -136,6 +135,7 @@ int window_state (Display *disp, Window win, char *arg) {/*{{{*/
return EXIT_FAILURE;
}
for( i = 0; p1[i]; i++) tmp1[i] = toupper( p1[i] );
tmp1[i] = '\0';
my_snprintf(tmp_prop1, S(tmp_prop1), "_NET_WM_STATE_%s", tmp1);
prop1 = XInternAtom(disp, tmp_prop1, False);