diff --git a/src/actions.c b/src/actions.c index 67c043e4..40a121d8 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1673,7 +1673,7 @@ void new_wire(int what, double mx_snap, double my_snap) printf("xschem wire %g %g %g %g %d\n", xx1, yy1, xx2, yy2, -1); fflush(stdout); } - hash_wire(XINSERT, xctx->wires-1); + hash_wire(XINSERT, xctx->wires-1, 1); /* prepared_hash_wires = 0; */ prepared_hilight_structs = 0; update_conn_cues(1,1); diff --git a/src/check.c b/src/check.c index a1f18766..68f33a47 100644 --- a/src/check.c +++ b/src/check.c @@ -32,12 +32,14 @@ void check_touch(int i, int j, int touch1=0,touch2=0,touch3=0,touch4=0; double delta1x,delta1y,delta2x,delta2y; double x1,y1,x2,y2; - x1=xctx->wire[i].x1; - x2=xctx->wire[i].x2; - y1=xctx->wire[i].y1; - y2=xctx->wire[i].y2; + xWire * const wire = xctx->wire; + + x1=wire[i].x1; + x2=wire[i].x2; + y1=wire[i].y1; + y2=wire[i].y2; delta1x = x2-x1;delta1y = y1-y2 ; - delta2x = xctx->wire[j].x2-xctx->wire[j].x1;delta2y = xctx->wire[j].y1-xctx->wire[j].y2 ; + delta2x = wire[j].x2-wire[j].x1;delta2y = wire[j].y1-wire[j].y2 ; *included = 0; *includes = 0; @@ -47,32 +49,32 @@ void check_touch(int i, int j, *parallel = (delta1x*delta2y == delta2x*delta1y ? 1:0); /* the order of the following 4 if(touch...) is not don't care !!! */ - if(touch(xctx->wire[j].x1,xctx->wire[j].y1,xctx->wire[j].x2,xctx->wire[j].y2,x1,y1) ) + if(touch(wire[j].x1,wire[j].y1,wire[j].x2,wire[j].y2,x1,y1) ) { *touches = 1;touch3 =1; *xt = x1; *yt = y1; - if((*xt > xctx->wire[j].x1 && *xt < xctx->wire[j].x2)|| - (*yt > xctx->wire[j].y1 && *yt < xctx->wire[j].y2)) *breaks = 1; + if((*xt > wire[j].x1 && *xt < wire[j].x2)|| + (*yt > wire[j].y1 && *yt < wire[j].y2)) *breaks = 1; } - if(touch(xctx->wire[j].x1,xctx->wire[j].y1,xctx->wire[j].x2,xctx->wire[j].y2,x2,y2) ) + if(touch(wire[j].x1,wire[j].y1,wire[j].x2,wire[j].y2,x2,y2) ) { *touches = 1;touch4 =1; *xt = x2; *yt = y2; - if((*xt > xctx->wire[j].x1 && *xt < xctx->wire[j].x2)|| - (*yt > xctx->wire[j].y1 && *yt < xctx->wire[j].y2)) *breaks = 1; + if((*xt > wire[j].x1 && *xt < wire[j].x2)|| + (*yt > wire[j].y1 && *yt < wire[j].y2)) *breaks = 1; } if(touch3 && touch4) *included = 1; - if(touch(x1,y1,x2,y2,xctx->wire[j].x1,xctx->wire[j].y1) ) + if(touch(x1,y1,x2,y2,wire[j].x1,wire[j].y1) ) { *touches = 1;touch1=1; - *xt = xctx->wire[j].x1; *yt = xctx->wire[j].y1; + *xt = wire[j].x1; *yt = wire[j].y1; if((*xt > x1 && *xt < x2)||(*yt > y1 && *yt < y2)) *broken = 1; } - if(touch(x1,y1,x2,y2,xctx->wire[j].x2,xctx->wire[j].y2) ) + if(touch(x1,y1,x2,y2,wire[j].x2,wire[j].y2) ) { *touches = 1;touch2=1; - *xt = xctx->wire[j].x2; *yt = xctx->wire[j].y2; + *xt = wire[j].x2; *yt = wire[j].y2; if((*xt > x1 && *xt < x2)||(*yt > y1 && *yt < y2)) *broken = 1; } if(touch1 && touch2) *includes = 1; @@ -86,6 +88,7 @@ void update_conn_cues(int draw_cues, int dr_win) double x0, y0; double x1, y1, x2, y2; struct wireentry *wireptr; + xWire * const wire = xctx->wire; hash_wires(); /* must be done also if xctx->wires==0 to clear wiretable */ if(!xctx->wires) return; @@ -98,18 +101,18 @@ void update_conn_cues(int draw_cues, int dr_win) for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { k=wireptr->n; /* optimization when editing small areas (detailed zoom) of a huge schematic */ - if(LINE_OUTSIDE(xctx->wire[k].x1, xctx->wire[k].y1, xctx->wire[k].x2, xctx->wire[k].y2, x1, y1, x2, y2)) continue; + if(LINE_OUTSIDE(wire[k].x1, wire[k].y1, wire[k].x2, wire[k].y2, x1, y1, x2, y2)) continue; for(l = 0;l < 2;l++) { if(l==0 ) { - if(xctx->wire[k].end1 !=-1) continue; - xctx->wire[k].end1=0; - x0 = xctx->wire[k].x1; - y0 = xctx->wire[k].y1; + if(wire[k].end1 !=-1) continue; + wire[k].end1=0; + x0 = wire[k].x1; + y0 = wire[k].y1; } else { - if(xctx->wire[k].end2 !=-1) continue; - xctx->wire[k].end2=0; - x0 = xctx->wire[k].x2; - y0 = xctx->wire[k].y2; + if(wire[k].end2 !=-1) continue; + wire[k].end2=0; + x0 = wire[k].x2; + y0 = wire[k].y2; } get_square(x0, y0, &sqx, &sqy); for(wptr = wiretable[sqx][sqy] ; wptr ; wptr = wptr->next) { @@ -117,14 +120,14 @@ void update_conn_cues(int draw_cues, int dr_win) if(i == k) { continue; /* no check wire against itself */ } - if( touch(xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2, x0,y0) ) { - if( (x0 != xctx->wire[i].x1 && x0 != xctx->wire[i].x2) || - (y0 != xctx->wire[i].y1 && y0 != xctx->wire[i].y2) ) { - if(l == 0) xctx->wire[k].end1 += 2; - else xctx->wire[k].end2 += 2; + if( touch(wire[i].x1, wire[i].y1, wire[i].x2, wire[i].y2, x0,y0) ) { + if( (x0 != wire[i].x1 && x0 != wire[i].x2) || + (y0 != wire[i].y1 && y0 != wire[i].y2) ) { + if(l == 0) wire[k].end1 += 2; + else wire[k].end2 += 2; } else { - if(l == 0) xctx->wire[k].end1 += 1; - else xctx->wire[k].end2 += 1; + if(l == 0) wire[k].end1 += 1; + else wire[k].end2 += 1; } } } @@ -136,13 +139,13 @@ void update_conn_cues(int draw_cues, int dr_win) for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { i = wireptr->n; /* optimization when editing small areas (detailed zoom) of a huge schematic */ - if(LINE_OUTSIDE(xctx->wire[i].x1, xctx->wire[i].y1, - xctx->wire[i].x2, xctx->wire[i].y2, x1, y1, x2, y2)) continue; - if( xctx->wire[i].end1 >1 ) { /* 20150331 draw_dots */ - filledarc(WIRELAYER, ADD, xctx->wire[i].x1, xctx->wire[i].y1, cadhalfdotsize, 0, 360); + if(LINE_OUTSIDE(wire[i].x1, wire[i].y1, + wire[i].x2, wire[i].y2, x1, y1, x2, y2)) continue; + if( wire[i].end1 >1 ) { /* 20150331 draw_dots */ + filledarc(WIRELAYER, ADD, wire[i].x1, wire[i].y1, cadhalfdotsize, 0, 360); } - if( xctx->wire[i].end2 >1 ) { /* 20150331 draw_dots */ - filledarc(WIRELAYER, ADD, xctx->wire[i].x2, xctx->wire[i].y2, cadhalfdotsize, 0, 360); + if( wire[i].end2 >1 ) { /* 20150331 draw_dots */ + filledarc(WIRELAYER, ADD, wire[i].x2, wire[i].y2, cadhalfdotsize, 0, 360); } } filledarc(WIRELAYER, END, 0.0, 0.0, 0.0, 0.0, 0.0); @@ -157,14 +160,16 @@ void trim_wires(void) unsigned short parallel,breaks,broken,touches,included,includes; double xt=0,yt=0; int loops=0; + xWire * const wire = xctx->wire; + int const wires = xctx->wires; do { loops++; - for(i=0;iwires;i++) xctx->wire[i].end1=xctx->wire[i].end2=0; + for(i=0;iwires;i++) + for(i=0;iwires;j++) + for(j=i+1;jwire[xctx->wires].x1=xctx->wire[i].x1; - xctx->wire[xctx->wires].y1=xctx->wire[i].y1; - xctx->wire[xctx->wires].end1=xctx->wire[i].end1; - xctx->wire[xctx->wires].end2=1; - xctx->wire[xctx->wires].x2=xt; - xctx->wire[xctx->wires].y2=yt; - xctx->wire[xctx->wires].sel=0; - xctx->wire[xctx->wires].prop_ptr=NULL; - my_strdup(27, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[i].prop_ptr); - if(!strcmp(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0), "true")) - xctx->wire[xctx->wires].bus=1; + wire[wires].x1=wire[i].x1; + wire[wires].y1=wire[i].y1; + wire[wires].end1=wire[i].end1; + wire[wires].end2=1; + wire[wires].x2=xt; + wire[wires].y2=yt; + wire[wires].sel=0; + wire[wires].prop_ptr=NULL; + my_strdup(27, &wire[wires].prop_ptr, wire[i].prop_ptr); + if(!strcmp(get_tok_value(wire[wires].prop_ptr,"bus",0), "true")) + wire[wires].bus=1; else - xctx->wire[xctx->wires].bus=0; - xctx->wire[xctx->wires].node=NULL; - my_strdup(28, &xctx->wire[xctx->wires].node, xctx->wire[i].node); + wire[wires].bus=0; + wire[wires].node=NULL; + my_strdup(28, &wire[wires].node, wire[i].node); xctx->wires++; - xctx->wire[i].x1 = xt; - xctx->wire[i].y1 = yt; - xctx->wire[i].end1 = 1; + wire[i].x1 = xt; + wire[i].y1 = yt; + wire[i].end1 = 1; } /* end if broken */ - else if(breaks) /*xctx->wire[i] breaks xctx->wire[j] */ + else if(breaks) /*wire[i] breaks wire[j] */ { changed=1; - if(xctx->wire[i].x1==xt && xctx->wire[i].y1==yt) xctx->wire[i].end1+=1; - else if(xctx->wire[i].x2==xt && xctx->wire[i].y2==yt) xctx->wire[i].end2+=1; + if(wire[i].x1==xt && wire[i].y1==yt) wire[i].end1+=1; + else if(wire[i].x2==xt && wire[i].y2==yt) wire[i].end2+=1; check_wire_storage(); - xctx->wire[xctx->wires].x1=xctx->wire[j].x1; - xctx->wire[xctx->wires].y1=xctx->wire[j].y1; - xctx->wire[xctx->wires].end1=xctx->wire[j].end1; - xctx->wire[xctx->wires].end2=1; - xctx->wire[xctx->wires].x2=xt; - xctx->wire[xctx->wires].y2=yt; - xctx->wire[xctx->wires].sel=0; - xctx->wire[xctx->wires].prop_ptr=NULL; - my_strdup(29, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[j].prop_ptr); - if(!strcmp(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0), "true")) - xctx->wire[xctx->wires].bus=1; + wire[wires].x1=wire[j].x1; + wire[wires].y1=wire[j].y1; + wire[wires].end1=wire[j].end1; + wire[wires].end2=1; + wire[wires].x2=xt; + wire[wires].y2=yt; + wire[wires].sel=0; + wire[wires].prop_ptr=NULL; + my_strdup(29, &wire[wires].prop_ptr, wire[j].prop_ptr); + if(!strcmp(get_tok_value(wire[wires].prop_ptr,"bus",0), "true")) + wire[wires].bus=1; else - xctx->wire[xctx->wires].bus=0; - xctx->wire[xctx->wires].node=NULL; - my_strdup(30, &xctx->wire[xctx->wires].node, xctx->wire[j].node); + wire[wires].bus=0; + wire[wires].node=NULL; + my_strdup(30, &wire[wires].node, wire[j].node); xctx->wires++; - xctx->wire[j].x1 = xt; - xctx->wire[j].y1 = yt; - xctx->wire[j].end1 = 1; + wire[j].x1 = xt; + wire[j].y1 = yt; + wire[j].end1 = 1; } /* end else if breaks */ - else /* xctx->wire[i] touches but does not break xctx->wire[j] */ + else /* wire[i] touches but does not break wire[j] */ { - if(xctx->wire[i].x1==xctx->wire[j].x1 && xctx->wire[i].y1==xctx->wire[j].y1) - {xctx->wire[i].end1++;xctx->wire[j].end1++;} - else if(xctx->wire[i].x1==xctx->wire[j].x2 && xctx->wire[i].y1==xctx->wire[j].y2) - {xctx->wire[i].end1++;xctx->wire[j].end2++;} - else if(xctx->wire[i].x2==xctx->wire[j].x1 && xctx->wire[i].y2==xctx->wire[j].y1) - {xctx->wire[i].end2++;xctx->wire[j].end1++;} + if(wire[i].x1==wire[j].x1 && wire[i].y1==wire[j].y1) + {wire[i].end1++;wire[j].end1++;} + else if(wire[i].x1==wire[j].x2 && wire[i].y1==wire[j].y2) + {wire[i].end1++;wire[j].end2++;} + else if(wire[i].x2==wire[j].x1 && wire[i].y2==wire[j].y1) + {wire[i].end2++;wire[j].end1++;} else - {xctx->wire[i].end2++;xctx->wire[j].end2++;} + {wire[i].end2++;wire[j].end2++;} } } /* end if touches */ } /* end for j */ } /* end for i */ - for(i=0;iwires;i++) { - for(j=i+1;jwires;j++) { + for(i=0;iwire[j].x1 == xt && xctx->wire[j].y1 == yt) /* touch in x1, y1 */ + if(wire[j].x1 == xt && wire[j].y1 == yt) /* touch in x1, y1 */ { - if(xctx->wire[i].end2 == 1 && xctx->wire[j].end1 == 1) /* merge wire */ + if(wire[i].end2 == 1 && wire[j].end1 == 1) /* merge wire */ { changed=1; - xctx->wire[i].x2 = xctx->wire[j].x2;xctx->wire[i].y2 = xctx->wire[j].y2; - xctx->wire[i].end2=xctx->wire[j].end2; + wire[i].x2 = wire[j].x2;wire[i].y2 = wire[j].y2; + wire[i].end2=wire[j].end2; freenet_nocheck(j); j--; break; @@ -269,11 +274,11 @@ void trim_wires(void) } else /* touch in x2,y2 */ { - if(xctx->wire[i].end1 == 1 && xctx->wire[j].end2 == 1) /* merge wire */ + if(wire[i].end1 == 1 && wire[j].end2 == 1) /* merge wire */ { changed=1; - xctx->wire[i].x1 = xctx->wire[j].x1;xctx->wire[i].y1 = xctx->wire[j].y1; - xctx->wire[i].end1=xctx->wire[j].end1; + wire[i].x1 = wire[j].x1;wire[i].y1 = wire[j].y1; + wire[i].end1=wire[j].end1; freenet_nocheck(j); j--; break; @@ -300,8 +305,10 @@ void break_wires_at_pins(void) xRect *rct; double x0, y0, rx1, ry1; int changed=0; - hash_wires(); + xWire * const wire = xctx->wire; + int const wires = xctx->wires; + hash_wires(); need_rebuild_selected_array=1; rebuild_selected_array(); @@ -323,31 +330,31 @@ void break_wires_at_pins(void) get_square(x0, y0, &sqx, &sqy); for(wptr=wiretable[sqx][sqy]; wptr; wptr=wptr->next) { i = wptr->n; - if( touch(xctx->wire[i].x1, xctx->wire[i].y1, - xctx->wire[i].x2, xctx->wire[i].y2, x0,y0) ) + if( touch(wire[i].x1, wire[i].y1, + wire[i].x2, wire[i].y2, x0,y0) ) { - if( (x0!=xctx->wire[i].x1 && x0!=xctx->wire[i].x2) || - (y0!=xctx->wire[i].y1 && y0!=xctx->wire[i].y2) ) { + if( (x0!=wire[i].x1 && x0!=wire[i].x2) || + (y0!=wire[i].y1 && y0!=wire[i].y2) ) { if(!changed) { push_undo(); changed=1;} check_wire_storage(); - xctx->wire[xctx->wires].x1=xctx->wire[i].x1; - xctx->wire[xctx->wires].y1=xctx->wire[i].y1; - xctx->wire[xctx->wires].x2=x0; - xctx->wire[xctx->wires].y2=y0; - xctx->wire[xctx->wires].sel=SELECTED; - xctx->wire[xctx->wires].prop_ptr=NULL; - my_strdup(31, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[i].prop_ptr); - if(!strcmp(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0), "true")) - xctx->wire[xctx->wires].bus=1; + wire[wires].x1=wire[i].x1; + wire[wires].y1=wire[i].y1; + wire[wires].x2=x0; + wire[wires].y2=y0; + wire[wires].sel=SELECTED; + wire[wires].prop_ptr=NULL; + my_strdup(31, &wire[wires].prop_ptr, wire[i].prop_ptr); + if(!strcmp(get_tok_value(wire[wires].prop_ptr,"bus",0), "true")) + wire[wires].bus=1; else - xctx->wire[xctx->wires].bus=0; - xctx->wire[xctx->wires].node=NULL; - hash_wire(XINSERT, xctx->wires); - my_strdup(32, &xctx->wire[xctx->wires].node, xctx->wire[i].node); + wire[wires].bus=0; + wire[wires].node=NULL; + hash_wire(XINSERT, wires, 0); + my_strdup(32, &wire[wires].node, wire[i].node); need_rebuild_selected_array=1; xctx->wires++; - xctx->wire[i].x1 = x0; - xctx->wire[i].y1 = y0; + wire[i].x1 = x0; + wire[i].y1 = y0; } } } @@ -358,17 +365,17 @@ void break_wires_at_pins(void) /* hash_wires(); */ rebuild_selected_array(); for(j=0;jwires; k++) { */ + /* for(k=0; k < wires; k++) { */ int l; k = selectedgroup[j].n; for(l=0;l<2;l++) { if(l==0 ) { - x0 = xctx->wire[k].x1; - y0 = xctx->wire[k].y1; + x0 = wire[k].x1; + y0 = wire[k].y1; } else { - x0 = xctx->wire[k].x2; - y0 = xctx->wire[k].y2; + x0 = wire[k].x2; + y0 = wire[k].y2; } get_square(x0, y0, &sqx, &sqy); /* printf(" k=%d, x0=%g, y0=%g\n", k, x0, y0); */ @@ -378,31 +385,31 @@ void break_wires_at_pins(void) if(i==k) { continue; /* no check wire against itself */ } - if( touch(xctx->wire[i].x1, xctx->wire[i].y1, - xctx->wire[i].x2, xctx->wire[i].y2, x0,y0) ) + if( touch(wire[i].x1, wire[i].y1, + wire[i].x2, wire[i].y2, x0,y0) ) { - if( (x0!=xctx->wire[i].x1 && x0!=xctx->wire[i].x2) || - (y0!=xctx->wire[i].y1 && y0!=xctx->wire[i].y2) ) { + if( (x0!=wire[i].x1 && x0!=wire[i].x2) || + (y0!=wire[i].y1 && y0!=wire[i].y2) ) { /* printf("touch in mid point: %d\n", l+1); */ if(!changed) { push_undo(); changed=1;} check_wire_storage(); - xctx->wire[xctx->wires].x1=xctx->wire[i].x1; - xctx->wire[xctx->wires].y1=xctx->wire[i].y1; - xctx->wire[xctx->wires].x2=x0; - xctx->wire[xctx->wires].y2=y0; - xctx->wire[xctx->wires].sel=SELECTED; - xctx->wire[xctx->wires].prop_ptr=NULL; - my_strdup(33, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[i].prop_ptr); - if(!strcmp(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0), "true")) - xctx->wire[xctx->wires].bus=1; + wire[wires].x1=wire[i].x1; + wire[wires].y1=wire[i].y1; + wire[wires].x2=x0; + wire[wires].y2=y0; + wire[wires].sel=SELECTED; + wire[wires].prop_ptr=NULL; + my_strdup(33, &wire[wires].prop_ptr, wire[i].prop_ptr); + if(!strcmp(get_tok_value(wire[wires].prop_ptr,"bus",0), "true")) + wire[wires].bus=1; else - xctx->wire[xctx->wires].bus=0; - xctx->wire[xctx->wires].node=NULL; - hash_wire(XINSERT, xctx->wires); + wire[wires].bus=0; + wire[wires].node=NULL; + hash_wire(XINSERT, wires, 0); need_rebuild_selected_array=1; xctx->wires++; - xctx->wire[i].x1 = x0; - xctx->wire[i].y1 = y0; + wire[i].x1 = x0; + wire[i].y1 = y0; } } } diff --git a/src/editprop.c b/src/editprop.c index 758c17c4..e2188a24 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -376,16 +376,6 @@ char *strtoupper(char* s) { return s; } -/* given a dest_string of size 'size', allocate space to make sure it can - * hold additional 'add' characters starting at position 'pos' */ -void str_alloc( char **dest_string, int add, int pos, int *size) -{ - if (pos + add >= *size) { - *size = (1 + (pos + add) / CADCHUNKALLOC) * CADCHUNKALLOC; - my_realloc(1212, dest_string, *size); - } -} - void set_inst_prop(int i) { char *ptr = NULL; diff --git a/src/move.c b/src/move.c index 99f72be7..6c466043 100644 --- a/src/move.c +++ b/src/move.c @@ -506,6 +506,10 @@ void copy_objects(int what) /* int customfont; */ #endif + int const instances = xctx->instances; + xInstance * const inst = xctx->inst; + xLine ** const line = xctx->line; + xWire * const wire = xctx->wire; if(what & BEGIN) { rotatelocal=0; @@ -573,33 +577,33 @@ void copy_objects(int what) } check_wire_storage(); /* - if(xctx->wire[n].bus){ + if(wire[n].bus){ int ov, y1, y2; ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(xctx->wire[n].y1 < xctx->wire[n].y2) { y1 = xctx->wire[n].y1-ov; y2 = xctx->wire[n].y2+ov; } - else { y1 = xctx->wire[n].y1+ov; y2 = xctx->wire[n].y2-ov; } - bbox(ADD, xctx->wire[n].x1-ov, y1 , xctx->wire[n].x2+ov , y2 ); + if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } + else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } + bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); } else { int ov, y1, y2; ov = cadhalfdotsize; - if(xctx->wire[n].y1 < xctx->wire[n].y2) { y1 = xctx->wire[n].y1-ov; y2 = xctx->wire[n].y2+ov; } - else { y1 = xctx->wire[n].y1+ov; y2 = xctx->wire[n].y2-ov; } - bbox(ADD, xctx->wire[n].x1-ov, y1 , xctx->wire[n].x2+ov , y2 ); + if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } + else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } + bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); } */ if(rotatelocal) { - ROTATION(xctx->wire[n].x1, xctx->wire[n].y1, xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1); - ROTATION(xctx->wire[n].x1, xctx->wire[n].y1, xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2); + ROTATION(wire[n].x1, wire[n].y1, wire[n].x1, wire[n].y1, rx1,ry1); + ROTATION(wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1); - ROTATION(x1, y_1, xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2); + ROTATION(x1, y_1, wire[n].x1, wire[n].y1, rx1,ry1); + ROTATION(x1, y_1, wire[n].x2, wire[n].y2, rx2,ry2); } - if( xctx->wire[n].sel & (SELECTED|SELECTED1) ) + if( wire[n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( xctx->wire[n].sel & (SELECTED|SELECTED2) ) + if( wire[n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; @@ -609,13 +613,13 @@ void copy_objects(int what) ORDER(rx1,ry1,rx2,ry2); if( tmpx == rx2 && tmpy == ry2) { - if(xctx->wire[n].sel == SELECTED1) xctx->wire[n].sel = SELECTED2; - else if(xctx->wire[n].sel == SELECTED2) xctx->wire[n].sel = SELECTED1; + if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2; + else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1; } selectedgroup[i].n=xctx->wires; - storeobject(-1, rx1,ry1,rx2,ry2,WIRE,0,xctx->wire[n].sel,xctx->wire[n].prop_ptr); - xctx->wire[n].sel=0; - if(xctx->wire[n].bus) + storeobject(-1, rx1,ry1,rx2,ry2,WIRE,0,wire[n].sel,wire[n].prop_ptr); + wire[n].sel=0; + if(wire[n].bus) drawline(WIRELAYER, THICK, rx1,ry1,rx2,ry2, 0); else drawline(WIRELAYER, ADD, rx1,ry1,rx2,ry2, 0); @@ -633,20 +637,20 @@ void copy_objects(int what) { case LINE: if(c!=k) break; - /* bbox(ADD, xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x2, xctx->line[c][n].y2) */ + /* bbox(ADD, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2) */ if(rotatelocal) { - ROTATION(xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1); - ROTATION(xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2); + ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x1, line[c][n].y1, rx1,ry1); + ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1); - ROTATION(x1, y_1, xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2); + ROTATION(x1, y_1, line[c][n].x1, line[c][n].y1, rx1,ry1); + ROTATION(x1, y_1, line[c][n].x2, line[c][n].y2, rx2,ry2); } - if( xctx->line[c][n].sel & (SELECTED|SELECTED1) ) + if( line[c][n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( xctx->line[c][n].sel & (SELECTED|SELECTED2) ) + if( line[c][n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; @@ -656,16 +660,16 @@ void copy_objects(int what) ORDER(rx1,ry1,rx2,ry2); if( tmpx == rx2 && tmpy == ry2) { - if(xctx->line[c][n].sel == SELECTED1) xctx->line[c][n].sel = SELECTED2; - else if(xctx->line[c][n].sel == SELECTED2) xctx->line[c][n].sel = SELECTED1; + if(line[c][n].sel == SELECTED1) line[c][n].sel = SELECTED2; + else if(line[c][n].sel == SELECTED2) line[c][n].sel = SELECTED1; } - if(xctx->line[c][n].bus) - drawline(k, THICK, rx1,ry1,rx2,ry2, xctx->line[c][n].dash); + if(line[c][n].bus) + drawline(k, THICK, rx1,ry1,rx2,ry2, line[c][n].dash); else - drawline(k, ADD, rx1,ry1,rx2,ry2, xctx->line[c][n].dash); + drawline(k, ADD, rx1,ry1,rx2,ry2, line[c][n].dash); selectedgroup[i].n=xctx->lines[c]; - storeobject(-1, rx1, ry1, rx2, ry2, LINE, c, xctx->line[c][n].sel, xctx->line[c][n].prop_ptr); - xctx->line[c][n].sel=0; + storeobject(-1, rx1, ry1, rx2, ry2, LINE, c, line[c][n].sel, line[c][n].prop_ptr); + line[c][n].sel=0; break; case POLYGON: @@ -862,34 +866,34 @@ void copy_objects(int what) check_inst_storage(); if(rotatelocal) { - ROTATION(xctx->inst[n].x0, xctx->inst[n].y0, xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1); + ROTATION(inst[n].x0, inst[n].y0, inst[n].x0, inst[n].y0, rx1,ry1); } else { - ROTATION(x1, y_1, xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1); + ROTATION(x1, y_1, inst[n].x0, inst[n].y0, rx1,ry1); } - xctx->inst[xctx->instances] = xctx->inst[n]; - xctx->inst[xctx->instances].prop_ptr=NULL; - xctx->inst[xctx->instances].instname=NULL; - xctx->inst[xctx->instances].node=NULL; - xctx->inst[xctx->instances].name=NULL; - my_strdup(232, &xctx->inst[xctx->instances].name, xctx->inst[n].name); - my_strdup(233, &xctx->inst[xctx->instances].prop_ptr, xctx->inst[n].prop_ptr); - my_strdup2(234, &xctx->inst[xctx->instances].instname, get_tok_value(xctx->inst[n].prop_ptr, "name",0)); - xctx->inst[n].sel=0; - xctx->inst[xctx->instances].flags = xctx->inst[n].flags; - xctx->inst[xctx->instances].flags &= ~4; /* do not propagate hilight */ - xctx->inst[xctx->instances].x0 = rx1+deltax; - xctx->inst[xctx->instances].y0 = ry1+deltay; - xctx->inst[xctx->instances].sel = SELECTED; - xctx->inst[xctx->instances].rot = (xctx->inst[xctx->instances].rot + - ( (flip && (xctx->inst[xctx->instances].rot & 1) ) ? rot+2 : rot) ) & 0x3; - xctx->inst[xctx->instances].flip = (flip? !xctx->inst[n].flip:xctx->inst[n].flip); + inst[instances] = inst[n]; + inst[instances].prop_ptr=NULL; + inst[instances].instname=NULL; + inst[instances].node=NULL; + inst[instances].name=NULL; + my_strdup(232, &inst[instances].name, inst[n].name); + my_strdup(233, &inst[instances].prop_ptr, inst[n].prop_ptr); + my_strdup2(234, &inst[instances].instname, get_tok_value(inst[n].prop_ptr, "name",0)); + inst[n].sel=0; + inst[instances].flags = inst[n].flags; + inst[instances].flags &= ~4; /* do not propagate hilight */ + inst[instances].x0 = rx1+deltax; + inst[instances].y0 = ry1+deltay; + inst[instances].sel = SELECTED; + inst[instances].rot = (inst[instances].rot + + ( (flip && (inst[instances].rot & 1) ) ? rot+2 : rot) ) & 0x3; + inst[instances].flip = (flip? !inst[n].flip:inst[n].flip); /* the newpropcnt argument is zero for the 1st call and used in */ /* new_prop_string() for cleaning some internal caches. */ - if(!newpropcnt) hash_all_names(xctx->instances); - new_prop_string(xctx->instances, xctx->inst[n].prop_ptr,newpropcnt++, dis_uniq_names); - my_strdup2(235, &xctx->inst[xctx->instances].instname, - get_tok_value(xctx->inst[xctx->instances].prop_ptr, "name", 0)); - n=selectedgroup[i].n=xctx->instances; + if(!newpropcnt) hash_all_names(instances); + new_prop_string(instances, inst[n].prop_ptr,newpropcnt++, dis_uniq_names); + my_strdup2(235, &inst[instances].instname, + get_tok_value(inst[instances].prop_ptr, "name", 0)); + n=selectedgroup[i].n=instances; xctx->instances++; } @@ -918,16 +922,16 @@ void copy_objects(int what) if(k == 0) { if(selectedgroup[i].type == ELEMENT) { int p; - symbol_bbox(n, &xctx->inst[n].x1, &xctx->inst[n].y1, &xctx->inst[n].x2, &xctx->inst[n].y2 ); - bbox(ADD, xctx->inst[n].x1, xctx->inst[n].y1, xctx->inst[n].x2, xctx->inst[n].y2 ); - if(show_pin_net_names) for(p = 0; p < (xctx->inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) { - if( xctx->inst[n].node && xctx->inst[n].node[p]) { - find_inst_to_be_redrawn(xctx->inst[n].node[p]); + symbol_bbox(n, &inst[n].x1, &inst[n].y1, &inst[n].x2, &inst[n].y2 ); + bbox(ADD, inst[n].x1, inst[n].y1, inst[n].x2, inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) { + if( inst[n].node && inst[n].node[p]) { + find_inst_to_be_redrawn(inst[n].node[p]); } } } if(show_pin_net_names && selectedgroup[i].type == WIRE) { - find_inst_to_be_redrawn(xctx->wire[n].node); + find_inst_to_be_redrawn(wire[n].node); } } } @@ -967,6 +971,9 @@ void move_objects(int what, int merge, double dx, double dy) #ifdef HAS_CAIRO char *textfont; #endif + xInstance * const inst = xctx->inst; + xLine ** const line = xctx->line; + xWire * const wire = xctx->wire; if(what & BEGIN) { @@ -1042,16 +1049,16 @@ void move_objects(int what, int merge, double dx, double dy) n = selectedgroup[i].n; if( selectedgroup[i].type == ELEMENT) { int p; - symbol_bbox(n, &xctx->inst[n].x1, &xctx->inst[n].y1, &xctx->inst[n].x2, &xctx->inst[n].y2 ); - bbox(ADD, xctx->inst[n].x1, xctx->inst[n].y1, xctx->inst[n].x2, xctx->inst[n].y2 ); - if(show_pin_net_names) for(p = 0; p < (xctx->inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) { - if( xctx->inst[n].node && xctx->inst[n].node[p]) { - find_inst_to_be_redrawn(xctx->inst[n].node[p]); + symbol_bbox(n, &inst[n].x1, &inst[n].y1, &inst[n].x2, &inst[n].y2 ); + bbox(ADD, inst[n].x1, inst[n].y1, inst[n].x2, inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) { + if( inst[n].node && inst[n].node[p]) { + find_inst_to_be_redrawn(inst[n].node[p]); } } } if(show_pin_net_names && selectedgroup[i].type == WIRE) { - find_inst_to_be_redrawn(xctx->wire[n].node); + find_inst_to_be_redrawn(wire[n].node); } } if(show_pin_net_names) find_inst_hash_clear(); @@ -1068,95 +1075,95 @@ void move_objects(int what, int merge, double dx, double dy) firstw = 0; } if(k == 0) { - if(xctx->wire[n].bus){ + if(wire[n].bus){ int ov, y1, y2; ov = bus_width> cadhalfdotsize ? bus_width : CADHALFDOTSIZE; - if(xctx->wire[n].y1 < xctx->wire[n].y2) { y1 = xctx->wire[n].y1-ov; y2 = xctx->wire[n].y2+ov; } - else { y1 = xctx->wire[n].y1+ov; y2 = xctx->wire[n].y2-ov; } - bbox(ADD, xctx->wire[n].x1-ov, y1 , xctx->wire[n].x2+ov , y2 ); + if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } + else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } + bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); } else { int ov, y1, y2; ov = cadhalfdotsize; - if(xctx->wire[n].y1 < xctx->wire[n].y2) { y1 = xctx->wire[n].y1-ov; y2 = xctx->wire[n].y2+ov; } - else { y1 = xctx->wire[n].y1+ov; y2 = xctx->wire[n].y2-ov; } - bbox(ADD, xctx->wire[n].x1-ov, y1 , xctx->wire[n].x2+ov , y2 ); + if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; } + else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; } + bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 ); } if(rotatelocal) { - ROTATION(xctx->wire[n].x1, xctx->wire[n].y1, xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1); - ROTATION(xctx->wire[n].x1, xctx->wire[n].y1, xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2); + ROTATION(wire[n].x1, wire[n].y1, wire[n].x1, wire[n].y1, rx1,ry1); + ROTATION(wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1); - ROTATION(x1, y_1, xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2); + ROTATION(x1, y_1, wire[n].x1, wire[n].y1, rx1,ry1); + ROTATION(x1, y_1, wire[n].x2, wire[n].y2, rx2,ry2); } - if( xctx->wire[n].sel & (SELECTED|SELECTED1) ) + if( wire[n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( xctx->wire[n].sel & (SELECTED|SELECTED2) ) + if( wire[n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; } - xctx->wire[n].x1=rx1; - xctx->wire[n].y1=ry1; + wire[n].x1=rx1; + wire[n].y1=ry1; ORDER(rx1,ry1,rx2,ry2); - if( xctx->wire[n].x1 == rx2 && xctx->wire[n].y1 == ry2) + if( wire[n].x1 == rx2 && wire[n].y1 == ry2) { - if(xctx->wire[n].sel == SELECTED1) xctx->wire[n].sel = SELECTED2; - else if(xctx->wire[n].sel == SELECTED2) xctx->wire[n].sel = SELECTED1; + if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2; + else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1; } - xctx->wire[n].x1=rx1; - xctx->wire[n].y1=ry1; - xctx->wire[n].x2=rx2; - xctx->wire[n].y2=ry2; + wire[n].x1=rx1; + wire[n].y1=ry1; + wire[n].x2=rx2; + wire[n].y2=ry2; } else if(k == WIRELAYER) { - if(xctx->wire[n].bus) - drawline(WIRELAYER, THICK, xctx->wire[n].x1, xctx->wire[n].y1, xctx->wire[n].x2, xctx->wire[n].y2, 0); + if(wire[n].bus) + drawline(WIRELAYER, THICK, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, 0); else - drawline(WIRELAYER, ADD, xctx->wire[n].x1, xctx->wire[n].y1, xctx->wire[n].x2, xctx->wire[n].y2, 0); + drawline(WIRELAYER, ADD, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, 0); } break; case LINE: if(c!=k) break; - bbox(ADD, xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x2, xctx->line[c][n].y2); + bbox(ADD, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2); if(rotatelocal) { - ROTATION(xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1); - ROTATION(xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2); + ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x1, line[c][n].y1, rx1,ry1); + ROTATION(line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, rx2,ry2); } else { - ROTATION(x1, y_1, xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1); - ROTATION(x1, y_1, xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2); + ROTATION(x1, y_1, line[c][n].x1, line[c][n].y1, rx1,ry1); + ROTATION(x1, y_1, line[c][n].x2, line[c][n].y2, rx2,ry2); } - if( xctx->line[c][n].sel & (SELECTED|SELECTED1) ) + if( line[c][n].sel & (SELECTED|SELECTED1) ) { rx1+=deltax; ry1+=deltay; } - if( xctx->line[c][n].sel & (SELECTED|SELECTED2) ) + if( line[c][n].sel & (SELECTED|SELECTED2) ) { rx2+=deltax; ry2+=deltay; } - xctx->line[c][n].x1=rx1; - xctx->line[c][n].y1=ry1; + line[c][n].x1=rx1; + line[c][n].y1=ry1; ORDER(rx1,ry1,rx2,ry2); - if( xctx->line[c][n].x1 == rx2 && xctx->line[c][n].y1 == ry2) + if( line[c][n].x1 == rx2 && line[c][n].y1 == ry2) { - if(xctx->line[c][n].sel == SELECTED1) xctx->line[c][n].sel = SELECTED2; - else if(xctx->line[c][n].sel == SELECTED2) xctx->line[c][n].sel = SELECTED1; + if(line[c][n].sel == SELECTED1) line[c][n].sel = SELECTED2; + else if(line[c][n].sel == SELECTED2) line[c][n].sel = SELECTED1; } - xctx->line[c][n].x1=rx1; - xctx->line[c][n].y1=ry1; - xctx->line[c][n].x2=rx2; - xctx->line[c][n].y2=ry2; - if(xctx->line[c][n].bus) - drawline(k, THICK, xctx->line[c][n].x1, xctx->line[c][n].y1, - xctx->line[c][n].x2, xctx->line[c][n].y2, xctx->line[c][n].dash); + line[c][n].x1=rx1; + line[c][n].y1=ry1; + line[c][n].x2=rx2; + line[c][n].y2=ry2; + if(line[c][n].bus) + drawline(k, THICK, line[c][n].x1, line[c][n].y1, + line[c][n].x2, line[c][n].y2, line[c][n].dash); else - drawline(k, ADD, xctx->line[c][n].x1, xctx->line[c][n].y1, - xctx->line[c][n].x2, xctx->line[c][n].y2, xctx->line[c][n].dash); + drawline(k, ADD, line[c][n].x1, line[c][n].y1, + line[c][n].x2, line[c][n].y2, line[c][n].dash); break; case POLYGON: @@ -1389,15 +1396,15 @@ void move_objects(int what, int merge, double dx, double dy) firsti = 0; } if(rotatelocal) { - ROTATION(xctx->inst[n].x0, xctx->inst[n].y0, xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1); + ROTATION(inst[n].x0, inst[n].y0, inst[n].x0, inst[n].y0, rx1,ry1); } else { - ROTATION(x1, y_1, xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1); + ROTATION(x1, y_1, inst[n].x0, inst[n].y0, rx1,ry1); } - xctx->inst[n].x0 = rx1+deltax; - xctx->inst[n].y0 = ry1+deltay; - xctx->inst[n].rot = (xctx->inst[n].rot + - ( (flip && (xctx->inst[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; - xctx->inst[n].flip = flip ^ xctx->inst[n].flip; + inst[n].x0 = rx1+deltax; + inst[n].y0 = ry1+deltay; + inst[n].rot = (inst[n].rot + + ( (flip && (inst[n].rot & 1) ) ? rot+2 : rot) ) & 0x3; + inst[n].flip = flip ^ inst[n].flip; } break; @@ -1420,16 +1427,16 @@ void move_objects(int what, int merge, double dx, double dy) if(k == 0) { if(selectedgroup[i].type == ELEMENT) { int p; - symbol_bbox(n, &xctx->inst[n].x1, &xctx->inst[n].y1, &xctx->inst[n].x2, &xctx->inst[n].y2 ); - bbox(ADD, xctx->inst[n].x1, xctx->inst[n].y1, xctx->inst[n].x2, xctx->inst[n].y2 ); - if(show_pin_net_names) for(p = 0; p < (xctx->inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) { - if( xctx->inst[n].node && xctx->inst[n].node[p]) { - find_inst_to_be_redrawn(xctx->inst[n].node[p]); + symbol_bbox(n, &inst[n].x1, &inst[n].y1, &inst[n].x2, &inst[n].y2 ); + bbox(ADD, inst[n].x1, inst[n].y1, inst[n].x2, inst[n].y2 ); + if(show_pin_net_names) for(p = 0; p < (inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) { + if( inst[n].node && inst[n].node[p]) { + find_inst_to_be_redrawn(inst[n].node[p]); } } } if(show_pin_net_names && selectedgroup[i].type == WIRE) { - find_inst_to_be_redrawn(xctx->wire[n].node); + find_inst_to_be_redrawn(wire[n].node); } } /* draw_symbol(ADD,k, n,k, 0, 0, 0.0, 0.0); */ diff --git a/src/netlist.c b/src/netlist.c index ca18279d..42288899 100644 --- a/src/netlist.c +++ b/src/netlist.c @@ -309,36 +309,36 @@ void hash_inst_pin(int what, int i, int j) * 0, XINSERT : add to hash * 1, XDELETE : remove from hash */ -void hash_wire(int what, int n) +void hash_wire(int what, int n, int incremental) { int tmpi,tmpj, counti,countj,i,j; double tmpd; double x1, y1, x2, y2; int x1a, x2a, y1a, y2a; struct wireentry *wptr; + xWire * const wire = xctx->wire; + /* wire[n].node=NULL; */ + my_free(827, &wire[n].node); - /* xctx->wire[n].node=NULL; */ - my_free(827, &xctx->wire[n].node); - - xctx->wire[n].end1 = xctx->wire[n].end2=-1; - x1=xctx->wire[n].x1; - x2=xctx->wire[n].x2; - y1=xctx->wire[n].y1; - y2=xctx->wire[n].y2; + wire[n].end1 = wire[n].end2=-1; + x1=wire[n].x1; + x2=wire[n].x2; + y1=wire[n].y1; + y2=wire[n].y2; /* ordered bbox */ if( x2 < x1) { tmpd=x2;x2=x1;x1=tmpd;} if( y2 < y1) { tmpd=y2;y2=y1;y1=tmpd;} - /* calculate square 4 1st bbox point of xctx->wire[k] */ + /* calculate square 4 1st bbox point of wire[k] */ x1a=floor(x1/BOXSIZE) ; y1a=floor(y1/BOXSIZE) ; - /* calculate square 4 2nd bbox point of xctx->wire[k] */ + /* calculate square 4 2nd bbox point of wire[k] */ x2a=floor(x2/BOXSIZE); y2a=floor(y2/BOXSIZE); - /*loop thru all squares that intersect bbox of xctx->wire[k] */ + /*loop thru all squares that intersect bbox of wire[k] */ counti=0; for(i=x1a; i<=x2a && counti < NBOXES; i++) { @@ -349,13 +349,13 @@ void hash_wire(int what, int n) { countj++; tmpj=j%NBOXES; if(tmpj<0) tmpj+=NBOXES; - /* insert xctx->wire[n] in region [tmpi, tmpj] */ + /* insert wire[n] in region [tmpi, tmpj] */ if(what==XINSERT) wireinsert(n, tmpi, tmpj); else wiredelete(n, tmpi, tmpj); - /* reset ends of all wires that *could* touch xctx->wire[n] */ - for(wptr = wiretable[tmpi][tmpj] ; wptr ; wptr = wptr->next) { - xctx->wire[wptr->n].end1 = xctx->wire[wptr->n].end2 = -1; + /* reset ends of all wires that *could* touch wire[n] */ + if(incremental) for(wptr = wiretable[tmpi][tmpj] ; wptr ; wptr = wptr->next) { + wire[wptr->n].end1 = wire[wptr->n].end2 = -1; } } } @@ -367,7 +367,8 @@ void hash_wires(void) if(prepared_hash_wires) return; del_wire_table(); - for(n=0; nwires; n++) hash_wire(XINSERT, n); + + for(n=0; nwires; n++) hash_wire(XINSERT, n, 0); prepared_hash_wires=1; } @@ -469,23 +470,24 @@ static void wirecheck(int k) /* recursive routine */ double x1, y1, x2, y2; int x1a, x2a, y1a, y2a; struct wireentry *ptr2; + xWire * const wire = xctx->wire; - x1=xctx->wire[k].x1; - x2=xctx->wire[k].x2; - y1=xctx->wire[k].y1; - y2=xctx->wire[k].y2; + x1=wire[k].x1; + x2=wire[k].x2; + y1=wire[k].y1; + y2=wire[k].y2; /* ordered bbox */ RECTORDER(x1, y1, x2, y2); - /* calculate square 4 1st bbox point of xctx->wire[k] */ + /* calculate square 4 1st bbox point of wire[k] */ x1a=floor(x1/BOXSIZE) ; y1a=floor(y1/BOXSIZE) ; - /* calculate square 4 2nd bbox point of xctx->wire[k] */ + /* calculate square 4 2nd bbox point of wire[k] */ x2a=floor(x2/BOXSIZE); y2a=floor(y2/BOXSIZE); - /*loop thru all squares that intersect bbox of xctx->wire[k] */ + /*loop thru all squares that intersect bbox of wire[k] */ counti=0; for(i=x1a; i<=x2a && counti < NBOXES; i++) { @@ -496,25 +498,25 @@ static void wirecheck(int k) /* recursive routine */ { countj++; tmpj=j%NBOXES; if(tmpj<0) tmpj+=NBOXES; - /*check if xctx->wire[k] touches wires in square [tmpi, tmpj] */ + /*check if wire[k] touches wires in square [tmpi, tmpj] */ ptr2=wiretable[tmpi][tmpj]; while(ptr2) { - if(xctx->wire[ptr2->n].node) {ptr2=ptr2->next; continue;} /* 20171207 net already checked. Move on */ + if(wire[ptr2->n].node) {ptr2=ptr2->next; continue;} /* 20171207 net already checked. Move on */ if(ptr2->n != k) { /* 20171204 avoid checking wire against itself */ - touches = touch(xctx->wire[k].x1,xctx->wire[k].y1,xctx->wire[k].x2,xctx->wire[k].y2, - xctx->wire[ptr2->n].x1,xctx->wire[ptr2->n].y1) || - touch(xctx->wire[k].x1,xctx->wire[k].y1,xctx->wire[k].x2,xctx->wire[k].y2, - xctx->wire[ptr2->n].x2,xctx->wire[ptr2->n].y2) || - touch(xctx->wire[ptr2->n].x1,xctx->wire[ptr2->n].y1,xctx->wire[ptr2->n].x2, - xctx->wire[ptr2->n].y2, xctx->wire[k].x1,xctx->wire[k].y1) || - touch(xctx->wire[ptr2->n].x1,xctx->wire[ptr2->n].y1,xctx->wire[ptr2->n].x2, - xctx->wire[ptr2->n].y2, xctx->wire[k].x2,xctx->wire[k].y2); + touches = touch(wire[k].x1,wire[k].y1,wire[k].x2,wire[k].y2, + wire[ptr2->n].x1,wire[ptr2->n].y1) || + touch(wire[k].x1,wire[k].y1,wire[k].x2,wire[k].y2, + wire[ptr2->n].x2,wire[ptr2->n].y2) || + touch(wire[ptr2->n].x1,wire[ptr2->n].y1,wire[ptr2->n].x2, + wire[ptr2->n].y2, wire[k].x1,wire[k].y1) || + touch(wire[ptr2->n].x1,wire[ptr2->n].y1,wire[ptr2->n].x2, + wire[ptr2->n].y2, wire[k].x2,wire[k].y2); if( touches ) { - my_strdup(239, &xctx->wire[ptr2->n].node, xctx->wire[k].node); - my_strdup(240, &xctx->wire[ptr2->n].prop_ptr, - subst_token(xctx->wire[ptr2->n].prop_ptr, "lab", xctx->wire[ptr2->n].node)); + my_strdup(239, &wire[ptr2->n].node, wire[k].node); + my_strdup(240, &wire[ptr2->n].prop_ptr, + subst_token(wire[ptr2->n].prop_ptr, "lab", wire[ptr2->n].node)); wirecheck(ptr2->n); /* recursive check */ } } @@ -635,6 +637,8 @@ void prepare_netlist_structs(int for_netlist) int inst_mult, pin_mult; int print_erc; static int startlevel = 0; + xInstance * const inst = xctx->inst; + int const instances = xctx->instances; if (for_netlist>0 && prepared_netlist_structs) return; else if (!for_netlist && prepared_hilight_structs) return; @@ -649,32 +653,32 @@ void prepare_netlist_structs(int for_netlist) /* reset wire & inst node labels */ dbg(1, "prepare_netlist_structs(): resetting node hash tables\n"); hash_wires(); - for (i=0;iinstances;i++) + for (i=0;iinst[i].ptr<0) continue; + if (inst[i].ptr<0) continue; delete_inst_node(i); - rects=(xctx->inst[i].ptr+ xctx->sym)->rects[PINLAYER] + - (xctx->inst[i].ptr+ xctx->sym)->rects[GENERICLAYER]; + rects=(inst[i].ptr+ xctx->sym)->rects[PINLAYER] + + (inst[i].ptr+ xctx->sym)->rects[GENERICLAYER]; if (rects > 0) { - xctx->inst[i].node = my_malloc(247, sizeof(char *) * rects); + inst[i].node = my_malloc(247, sizeof(char *) * rects); for (j=0;jinst[i].node[j]=NULL; + inst[i].node[j]=NULL; hash_inst_pin(XINSERT, i, j); } } } dbg(2, "prepare_netlist_structs(): naming pins from attrs\n"); - for (i=0;iinstances;i++) + for (i=0;iinst[i].ptr<0) continue; + if (inst[i].ptr<0) continue; - my_strdup(248, &type,(xctx->inst[i].ptr+ xctx->sym)->type); - if(print_erc && (!xctx->inst[i].instname || !xctx->inst[i].instname[0]) && - !get_tok_value((xctx->inst[i].ptr+ xctx->sym)->templ, "name", 0)[0] + my_strdup(248, &type,(inst[i].ptr+ xctx->sym)->type); + if(print_erc && (!inst[i].instname || !inst[i].instname[0]) && + !get_tok_value((inst[i].ptr+ xctx->sym)->templ, "name", 0)[0] ) { char str[2048]; if( type && @@ -684,30 +688,30 @@ void prepare_netlist_structs(int for_netlist) strcmp(type, "arch_declarations") && strcmp(type, "attributes") && strcmp(type, "use")) { - my_snprintf(str, S(str), "instance: %d (%s): no name attribute set", i, xctx->inst[i].name); + my_snprintf(str, S(str), "instance: %d (%s): no name attribute set", i, inst[i].name); statusmsg(str,2); - xctx->inst[i].flags |=4; + inst[i].flags |=4; hilight_nets=1; } } if(print_erc && (!type || !type[0]) ) { char str[2048]; - my_snprintf(str, S(str), "xSymbol: %s: no type attribute set", xctx->inst[i].name); + my_snprintf(str, S(str), "xSymbol: %s: no type attribute set", inst[i].name); statusmsg(str,2); - xctx->inst[i].flags |=4; + inst[i].flags |=4; hilight_nets=1; } - if(type && xctx->inst[i].node && IS_LABEL_OR_PIN(type) ) { /* instance must have a pin! */ + if(type && inst[i].node && IS_LABEL_OR_PIN(type) ) { /* instance must have a pin! */ if (for_netlist>0) { /* 20150918 skip labels / pins if ignore property specified on instance */ if( netlist_type == CAD_VERILOG_NETLIST && - strcmp(get_tok_value(xctx->inst[i].prop_ptr,"verilog_ignore",0),"true")==0 ) continue; + strcmp(get_tok_value(inst[i].prop_ptr,"verilog_ignore",0),"true")==0 ) continue; if( netlist_type == CAD_SPICE_NETLIST && - strcmp(get_tok_value(xctx->inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; + strcmp(get_tok_value(inst[i].prop_ptr,"spice_ignore",0),"true")==0 ) continue; if( netlist_type == CAD_VHDL_NETLIST && - strcmp(get_tok_value(xctx->inst[i].prop_ptr,"vhdl_ignore",0),"true")==0 ) continue; + strcmp(get_tok_value(inst[i].prop_ptr,"vhdl_ignore",0),"true")==0 ) continue; if( netlist_type == CAD_TEDAX_NETLIST && - strcmp(get_tok_value(xctx->inst[i].prop_ptr,"tedax_ignore",0),"true")==0 ) continue; + strcmp(get_tok_value(inst[i].prop_ptr,"tedax_ignore",0),"true")==0 ) continue; } port=0; if (strcmp(type,"label")) { /* instance is a port (not a label) */ @@ -715,11 +719,11 @@ void prepare_netlist_structs(int for_netlist) /* 20071204 only define a dir property if instance is not a label */ if (!for_netlist) my_strdup(249, &dir, ""); else - my_strdup(250, &dir, get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][0].prop_ptr, "dir",0)); + my_strdup(250, &dir, get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][0].prop_ptr, "dir",0)); } else { /* handle global nodes (global=1 set as symbol property) 28032003 */ - my_strdup(251, &global_node,get_tok_value((xctx->inst[i].ptr+ xctx->sym)->prop_ptr,"global",0)); + my_strdup(251, &global_node,get_tok_value((inst[i].ptr+ xctx->sym)->prop_ptr,"global",0)); /*20071204 if instance is a label dont define a dir property for more precise erc checking */ my_strdup(252, &dir,"none"); } @@ -734,54 +738,54 @@ void prepare_netlist_structs(int for_netlist) my_free(833, &value); my_free(834, &class); } else { - my_strdup(258, &sig_type,get_tok_value(xctx->inst[i].prop_ptr,"sig_type",0)); - my_strdup(259, &verilog_type,get_tok_value(xctx->inst[i].prop_ptr,"verilog_type",0)); - my_strdup(260, &value,get_tok_value(xctx->inst[i].prop_ptr,"value",2)); - my_strdup(261, &class,get_tok_value(xctx->inst[i].prop_ptr,"class",0)); + my_strdup(258, &sig_type,get_tok_value(inst[i].prop_ptr,"sig_type",0)); + my_strdup(259, &verilog_type,get_tok_value(inst[i].prop_ptr,"verilog_type",0)); + my_strdup(260, &value,get_tok_value(inst[i].prop_ptr,"value",2)); + my_strdup(261, &class,get_tok_value(inst[i].prop_ptr,"class",0)); } - my_strdup(262, &xctx->inst[i].node[0], get_tok_value(xctx->inst[i].prop_ptr,"lab",1)); + my_strdup(262, &inst[i].node[0], get_tok_value(inst[i].prop_ptr,"lab",1)); - if (!(xctx->inst[i].node[0])) { - my_strdup(65, &xctx->inst[i].node[0], get_tok_value((xctx->inst[i].ptr+ xctx->sym)->templ, "lab",1)); - dbg(1, "no lab attr on instance, pick from symbol: %s\n", xctx->inst[i].node[0]); + if (!(inst[i].node[0])) { + my_strdup(65, &inst[i].node[0], get_tok_value((inst[i].ptr+ xctx->sym)->templ, "lab",1)); + dbg(1, "no lab attr on instance, pick from symbol: %s\n", inst[i].node[0]); } /* handle global nodes (global=1 set as symbol property) 28032003 */ if (!strcmp(type,"label") && global_node && !strcmp(global_node, "true")) { - dbg(1, "prepare_netlist_structs(): global node: %s\n",xctx->inst[i].node[0]); - record_global_node(1,NULL, xctx->inst[i].node[0]); + dbg(1, "prepare_netlist_structs(): global node: %s\n",inst[i].node[0]); + record_global_node(1,NULL, inst[i].node[0]); } /* do not count multiple labels/pins with same name */ - bus_hash_lookup(xctx->inst[i].node[0], /* insert node in hash table */ + bus_hash_lookup(inst[i].node[0], /* insert node in hash table */ dir, XINSERT, port, sig_type, verilog_type, value, class); dbg(2, "prepare_netlist_structs(): name=%s\n", - get_tok_value( xctx->inst[i].prop_ptr, "lab",0)); + get_tok_value( inst[i].prop_ptr, "lab",0)); dbg(2, "prepare_netlist_structs(): pin=%s\n", - get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][0].prop_ptr, "name",0)); + get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][0].prop_ptr, "name",0)); dbg(2, "prepare_netlist_structs(): dir=%s\n", - get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][0].prop_ptr, "dir",0)); + get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][0].prop_ptr, "dir",0)); /* name nets that touch ioin opin alias instances */ - rct=(xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER]; + rct=(inst[i].ptr+ xctx->sym)->rect[PINLAYER]; x0=(rct[0].x1+rct[0].x2)/2; y0=(rct[0].y1+rct[0].y2)/2; - rot=xctx->inst[i].rot; - flip=xctx->inst[i].flip; + rot=inst[i].rot; + flip=inst[i].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=xctx->inst[i].x0+rx1; - y0=xctx->inst[i].y0+ry1; + x0=inst[i].x0+rx1; + y0=inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); wptr=wiretable[sqx][sqy]; - if (xctx->inst[i].node[0]) while(wptr) + if (inst[i].node[0]) while(wptr) { if (touch(xctx->wire[wptr->n].x1, xctx->wire[wptr->n].y1, xctx->wire[wptr->n].x2, xctx->wire[wptr->n].y2, x0,y0)) { /* short circuit check */ - if (for_netlist>0) signal_short(xctx->wire[wptr->n].node, xctx->inst[i].node[0]); - my_strdup(263, &xctx->wire[wptr->n].node, xctx->inst[i].node[0]); + if (for_netlist>0) signal_short(xctx->wire[wptr->n].node, inst[i].node[0]); + my_strdup(263, &xctx->wire[wptr->n].node, inst[i].node[0]); my_strdup(264, &xctx->wire[wptr->n].prop_ptr, subst_token(xctx->wire[wptr->n].prop_ptr, "lab", xctx->wire[wptr->n].node)); wirecheck(wptr->n); @@ -789,7 +793,7 @@ void prepare_netlist_structs(int for_netlist) wptr=wptr->next; } } /* if(type && ... */ - } /* for(i=0;iinstances... */ + } /* for(i=0;iinstances;i++) { /* ... assign node fields on all (non label) instances */ - if (xctx->inst[i].ptr<0) continue; - my_strdup(267, &type,(xctx->inst[i].ptr+ xctx->sym)->type); + if(for_netlist) for (i=0;isym)->type); if (type && !IS_LABEL_OR_PIN(type) ) { - if ((generic_rects = (xctx->inst[i].ptr+ xctx->sym)->rects[GENERICLAYER]) > 0) + if ((generic_rects = (inst[i].ptr+ xctx->sym)->rects[GENERICLAYER]) > 0) { - rects = (xctx->inst[i].ptr+ xctx->sym)->rects[PINLAYER]; + rects = (inst[i].ptr+ xctx->sym)->rects[PINLAYER]; for (j=rects;jinst[i].node[j]) continue; /* already named node */ - rct=(xctx->inst[i].ptr+ xctx->sym)->rect[GENERICLAYER]; + if (inst[i].node[j]) continue; /* already named node */ + rct=(inst[i].ptr+ xctx->sym)->rect[GENERICLAYER]; x0=(rct[j-rects].x1+rct[j-rects].x2)/2; y0=(rct[j-rects].y1+rct[j-rects].y2)/2; - rot=xctx->inst[i].rot; - flip=xctx->inst[i].flip; + rot=inst[i].rot; + flip=inst[i].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=xctx->inst[i].x0+rx1; - y0=xctx->inst[i].y0+ry1; + x0=inst[i].x0+rx1; + y0=inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); iptr=instpintable[sqx][sqy]; @@ -847,33 +851,33 @@ void prepare_netlist_structs(int for_netlist) } if ((iptr->x0==x0) && (iptr->y0==y0)) { - if ((xctx->inst[iptr->n].ptr+ xctx->sym)->type && xctx->inst[iptr->n].node[iptr->pin] != NULL && - !strcmp((xctx->inst[iptr->n].ptr+ xctx->sym)->type, "label")) + if ((inst[iptr->n].ptr+ xctx->sym)->type && inst[iptr->n].node[iptr->pin] != NULL && + !strcmp((inst[iptr->n].ptr+ xctx->sym)->type, "label")) { dbg(2, "prepare_netlist_structs(): naming generic %s\n", - xctx->inst[iptr->n].node[iptr->pin]); + inst[iptr->n].node[iptr->pin]); - my_strdup(268, &xctx->inst[i].node[j], - get_tok_value(xctx->inst[iptr->n].prop_ptr,"value",2) ); + my_strdup(268, &inst[i].node[j], + get_tok_value(inst[iptr->n].prop_ptr,"value",2) ); - /*my_strdup(269, &xctx->inst[i].node[j], xctx->inst[iptr->n].node[iptr->pin] ); */ + /*my_strdup(269, &inst[i].node[j], inst[iptr->n].node[iptr->pin] ); */ if (!for_netlist) { my_strdup(270, &sig_type,""); - bus_hash_lookup(xctx->inst[iptr->n].node[iptr->pin],"none", + bus_hash_lookup(inst[iptr->n].node[iptr->pin],"none", XINSERT, 1, sig_type,"", "",""); } else { my_strdup(271, &sig_type,get_tok_value( - (xctx->inst[i].ptr+ xctx->sym)->rect[GENERICLAYER][j-rects].prop_ptr, "sig_type",0)); + (inst[i].ptr+ xctx->sym)->rect[GENERICLAYER][j-rects].prop_ptr, "sig_type",0)); /* insert generic label in hash table as a port so it will not */ /* be declared as a signal in the vhdl netlist. this is a workaround */ /* that should be fixed 25092001 */ - bus_hash_lookup(xctx->inst[iptr->n].node[iptr->pin], - get_tok_value((xctx->inst[i].ptr+ xctx->sym)->rect[GENERICLAYER][j-rects].prop_ptr, "dir",0), + bus_hash_lookup(inst[iptr->n].node[iptr->pin], + get_tok_value((inst[i].ptr+ xctx->sym)->rect[GENERICLAYER][j-rects].prop_ptr, "dir",0), XINSERT, 1, sig_type,"", "",""); } - } /* end if(xctx->inst[iptr->n].node[iptr->pin] != NULL) */ + } /* end if(inst[iptr->n].node[iptr->pin] != NULL) */ } /* end if( (iptr->x0==x0) && (iptr->y0==y0) ) */ iptr=iptr->next; } @@ -886,26 +890,26 @@ void prepare_netlist_structs(int for_netlist) /* name instance pins of non (label,pin) instances */ dbg(2, "prepare_netlist_structs(): assigning node names on instance pins\n"); - for (i=0;iinstances;i++) /* ... assign node fields on all (non label) instances */ + for (i=0;iinst[i].ptr<0) continue; - expandlabel(xctx->inst[i].instname, &inst_mult); - my_strdup(272, &type,(xctx->inst[i].ptr+ xctx->sym)->type); + if(inst[i].ptr<0) continue; + expandlabel(inst[i].instname, &inst_mult); + my_strdup(272, &type,(inst[i].ptr+ xctx->sym)->type); if (type && !IS_LABEL_OR_PIN(type) ) { - if ((rects = (xctx->inst[i].ptr+ xctx->sym)->rects[PINLAYER]) > 0) + if ((rects = (inst[i].ptr+ xctx->sym)->rects[PINLAYER]) > 0) { for (j=0;jinst[i].node[j]) continue; /* already named node */ - rct=(xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER]; + if (inst[i].node[j]) continue; /* already named node */ + rct=(inst[i].ptr+ xctx->sym)->rect[PINLAYER]; x0=(rct[j].x1+rct[j].x2)/2; y0=(rct[j].y1+rct[j].y2)/2; - rot=xctx->inst[i].rot; - flip=xctx->inst[i].flip; + rot=inst[i].rot; + flip=inst[i].flip; ROTATION(0.0,0.0,x0,y0,rx1,ry1); - x0=xctx->inst[i].x0+rx1; - y0=xctx->inst[i].y0+ry1; + x0=inst[i].x0+rx1; + y0=inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); /* name instance nodes that touch named nets */ wptr=wiretable[sqx][sqy]; @@ -919,21 +923,21 @@ void prepare_netlist_structs(int for_netlist) /* short circuit check */ if (touches) { - if (for_netlist>0) signal_short(xctx->inst[i].node[j], xctx->wire[wptr->n].node); + if (for_netlist>0) signal_short(inst[i].node[j], xctx->wire[wptr->n].node); } if (!touches) { - my_strdup(273, &xctx->inst[i].node[j], xctx->wire[wptr->n].node ); - bus_hash_lookup(xctx->inst[i].node[j], - get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), + my_strdup(273, &inst[i].node[j], xctx->wire[wptr->n].node ); + bus_hash_lookup(inst[i].node[j], + get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); if (xctx->wire[wptr->n].node[0]=='#') /* unnamed node, update its multiplicity */ { expandlabel(get_tok_value( - (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0),&pin_mult); + (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0),&pin_mult); - get_unnamed_node(2, pin_mult * inst_mult, atoi((xctx->inst[i].node[j])+4) ); + get_unnamed_node(2, pin_mult * inst_mult, atoi((inst[i].node[j])+4) ); } } /* end if(!touches) */ touches=1; @@ -953,35 +957,35 @@ void prepare_netlist_structs(int for_netlist) } if ((iptr->x0==x0) && (iptr->y0==y0)) { - if (xctx->inst[iptr->n].node[iptr->pin] != NULL) + if (inst[iptr->n].node[iptr->pin] != NULL) { /* short circuit check */ if (touches) { - if (for_netlist>0) signal_short(xctx->inst[i].node[j], xctx->inst[iptr->n].node[iptr->pin]); + if (for_netlist>0) signal_short(inst[i].node[j], inst[iptr->n].node[iptr->pin]); } if (!touches) { - my_strdup(274, &xctx->inst[i].node[j], xctx->inst[iptr->n].node[iptr->pin] ); + my_strdup(274, &inst[i].node[j], inst[iptr->n].node[iptr->pin] ); if (!for_netlist) { - bus_hash_lookup(xctx->inst[i].node[j],"none", XINSERT, 0,"","","",""); + bus_hash_lookup(inst[i].node[j],"none", XINSERT, 0,"","","",""); } else { - bus_hash_lookup(xctx->inst[i].node[j], - get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), + bus_hash_lookup(inst[i].node[j], + get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); } - if ((xctx->inst[i].node[j])[0] == '#') + if ((inst[i].node[j])[0] == '#') { expandlabel(get_tok_value( - (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0),&pin_mult ); + (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0),&pin_mult ); /* done at beginning of for(i) loop 20171210 */ /* expandlabel(get_tok_value( */ - /* xctx->inst[i].prop_ptr,"name",0), &inst_mult); */ - get_unnamed_node(2, pin_mult * inst_mult, atoi((xctx->inst[i].node[j])+4)); + /* inst[i].prop_ptr,"name",0), &inst_mult); */ + get_unnamed_node(2, pin_mult * inst_mult, atoi((inst[i].node[j])+4)); } } touches=1; - } /* end if(xctx->inst[iptr->n].node[iptr->pin] != NULL) */ + } /* end if(inst[iptr->n].node[iptr->pin] != NULL) */ else /* touches instance with unnamed pins */ { touches_unnamed=1; @@ -997,17 +1001,17 @@ void prepare_netlist_structs(int for_netlist) if (!(CAD_VHDL_NETLIST && !touches_unnamed)) { expandlabel(get_tok_value( - (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0), &pin_mult); + (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0), &pin_mult); /* done at beginning of for(i) loop 20171210 */ /* expandlabel(get_tok_value( */ - /* xctx->inst[i].prop_ptr,"name",0), &inst_mult); */ + /* inst[i].prop_ptr,"name",0), &inst_mult); */ my_snprintf( tmp_str, S(tmp_str), "#net%d", get_unnamed_node(1, pin_mult * inst_mult, 0)); - my_strdup(275, &xctx->inst[i].node[j], tmp_str ); + my_strdup(275, &inst[i].node[j], tmp_str ); if (!for_netlist) { - bus_hash_lookup(xctx->inst[i].node[j],"none", XINSERT, 0,"","","",""); + bus_hash_lookup(inst[i].node[j],"none", XINSERT, 0,"","","",""); } else { - bus_hash_lookup(xctx->inst[i].node[j], - get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), + bus_hash_lookup(inst[i].node[j], + get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); } } diff --git a/src/save.c b/src/save.c index 46bbf762..8da44eef 100644 --- a/src/save.c +++ b/src/save.c @@ -1544,6 +1544,8 @@ int load_sym_def(const char *name, FILE *embed_fd) const char *str; char *skip_line; const char *dash; + xSymbol * const symbol = xctx->sym; + int const symbols = xctx->symbols; dbg(1, "l_s_d(): recursion_counter=%d, name=%s\n", recursion_counter, name); recursion_counter++; @@ -1581,11 +1583,11 @@ int load_sym_def(const char *name, FILE *embed_fd) lastt=0; tt=NULL; check_symbol_storage(); - xctx->sym[xctx->symbols].prop_ptr = NULL; - xctx->sym[xctx->symbols].type = NULL; - xctx->sym[xctx->symbols].templ = NULL; - xctx->sym[xctx->symbols].name=NULL; - my_strdup(352, &xctx->sym[xctx->symbols].name,name); + symbol[symbols].prop_ptr = NULL; + symbol[symbols].type = NULL; + symbol[symbols].templ = NULL; + symbol[symbols].name=NULL; + my_strdup(352, &symbol[symbols].name,name); while(1) { if(endfile && embed_fd && level == 0) break; /* ']' line encountered --> exit */ @@ -1620,25 +1622,25 @@ int load_sym_def(const char *name, FILE *embed_fd) break; case 'K': /* 1.2 file format: symbol attributes for schematics placed as symbols */ if (level==0) { - load_ascii_string(&xctx->sym[xctx->symbols].prop_ptr, lcc[level].fd); - if(!xctx->sym[xctx->symbols].prop_ptr) break; - my_strdup2(424, &xctx->sym[xctx->symbols].templ, - get_tok_value(xctx->sym[xctx->symbols].prop_ptr, "template",2)); - my_strdup2(515, &xctx->sym[xctx->symbols].type, - get_tok_value(xctx->sym[xctx->symbols].prop_ptr, "type",0)); + load_ascii_string(&symbol[symbols].prop_ptr, lcc[level].fd); + if(!symbol[symbols].prop_ptr) break; + my_strdup2(424, &symbol[symbols].templ, + get_tok_value(symbol[symbols].prop_ptr, "template",2)); + my_strdup2(515, &symbol[symbols].type, + get_tok_value(symbol[symbols].prop_ptr, "type",0)); } else { load_ascii_string(&aux_ptr, lcc[level].fd); } break; case 'G': /* .sym files or pre-1.2 symbol attributes for schematics placed as symbols */ - if (level==0 && !xctx->sym[xctx->symbols].prop_ptr) { - load_ascii_string(&xctx->sym[xctx->symbols].prop_ptr, lcc[level].fd); - if(!xctx->sym[xctx->symbols].prop_ptr) break; - my_strdup2(341, &xctx->sym[xctx->symbols].templ, - get_tok_value(xctx->sym[xctx->symbols].prop_ptr, "template",2)); - my_strdup2(342, &xctx->sym[xctx->symbols].type, - get_tok_value(xctx->sym[xctx->symbols].prop_ptr, "type",0)); + if (level==0 && !symbol[symbols].prop_ptr) { + load_ascii_string(&symbol[symbols].prop_ptr, lcc[level].fd); + if(!symbol[symbols].prop_ptr) break; + my_strdup2(341, &symbol[symbols].templ, + get_tok_value(symbol[symbols].prop_ptr, "template",2)); + my_strdup2(342, &symbol[symbols].type, + get_tok_value(symbol[symbols].prop_ptr, "type",0)); } else { load_ascii_string(&aux_ptr, lcc[level].fd); @@ -2017,28 +2019,28 @@ int load_sym_def(const char *name, FILE *embed_fd) fclose(lcc[0].fd); } if(embed_fd || strstr(name, ".xschem_embedded_")) { - xctx->sym[xctx->symbols].flags |= EMBEDDED; + symbol[symbols].flags |= EMBEDDED; } else { - xctx->sym[xctx->symbols].flags &= ~EMBEDDED; + symbol[symbols].flags &= ~EMBEDDED; } dbg(2, "l_d_s(): finished parsing file\n"); for(c=0;csym[xctx->symbols].arcs[c] = lasta[c]; - xctx->sym[xctx->symbols].lines[c] = lastl[c]; - xctx->sym[xctx->symbols].rects[c] = lastr[c]; - xctx->sym[xctx->symbols].polygons[c] = lastp[c]; - xctx->sym[xctx->symbols].arc[c] = aa[c]; - xctx->sym[xctx->symbols].line[c] = ll[c]; - xctx->sym[xctx->symbols].poly[c] = pp[c]; - xctx->sym[xctx->symbols].rect[c] = bb[c]; + symbol[symbols].arcs[c] = lasta[c]; + symbol[symbols].lines[c] = lastl[c]; + symbol[symbols].rects[c] = lastr[c]; + symbol[symbols].polygons[c] = lastp[c]; + symbol[symbols].arc[c] = aa[c]; + symbol[symbols].line[c] = ll[c]; + symbol[symbols].poly[c] = pp[c]; + symbol[symbols].rect[c] = bb[c]; } - xctx->sym[xctx->symbols].texts = lastt; - xctx->sym[xctx->symbols].text = tt; - calc_symbol_bbox(xctx->symbols); + symbol[symbols].texts = lastt; + symbol[symbols].text = tt; + calc_symbol_bbox(symbols); /* given a .sch file used as instance in LCC schematics, order its pin * as in corresponding .sym file if it exists */ - align_sch_pins_with_sym(name, xctx->symbols); + align_sch_pins_with_sym(name, symbols); xctx->symbols++; my_free(910, &prop_ptr); my_free(901, &lastl); diff --git a/src/token.c b/src/token.c index 57ec773f..7274ab7f 100644 --- a/src/token.c +++ b/src/token.c @@ -306,8 +306,8 @@ int set_different_token(char **s,const char *new, const char *old, int object, i else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote && !escape) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XVALUE) { value[value_pos++]=c; @@ -353,8 +353,8 @@ int set_different_token(char **s,const char *new, const char *old, int object, i else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote && !escape) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XVALUE) { value[value_pos++]=c; @@ -421,7 +421,7 @@ const char *list_tokens(const char *s, int with_quotes) else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote && !escape ) state=XEND; - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&token, token_pos, &sizetok); if(c=='"') { if(!escape) quote=!quote; } @@ -490,8 +490,15 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote && !escape ) state=XEND; - str_alloc(&result, 0, value_pos, &size); - str_alloc(&token, 0, token_pos, &sizetok); + /* don't use STR_ALLOC() for efficiency reasons */ + if(value_pos>=size) { + size+=CADCHUNKALLOC; + my_realloc(436, &result,size); + } + if(token_pos>=sizetok) { + sizetok+=CADCHUNKALLOC; + my_realloc(437, &token,sizetok); + } if(c=='"') { if(!escape) quote=!quote; } @@ -566,7 +573,7 @@ const char *get_sym_template(char *s,char *extra) return ""; } l = strlen(s); - str_alloc(&result, l+1, 0, &sizeres); + STR_ALLOC(&result, l+1, &sizeres); sizetok = sizeval = CADCHUNKALLOC; my_realloc(438, &value,sizeval); my_realloc(439, &token,sizetok); @@ -578,8 +585,8 @@ const char *get_sym_template(char *s,char *extra) else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XBEGIN) { result[result_pos++] = c; } else if(state==XTOKEN) { @@ -772,8 +779,8 @@ const char *subst_token(const char *s, const char *tok, const char *new_val) space=SPACE(c); if(c == '"' && !escape) quote=!quote; /* alloc data */ - str_alloc(&result, 0, result_pos, &size); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&result, result_pos, &size); + STR_ALLOC(&token, token_pos, &sizetok); /* parsing state machine */ /* states: */ @@ -807,7 +814,7 @@ const char *subst_token(const char *s, const char *tok, const char *new_val) tmp = 2; } - str_alloc(&result, tmp+2, result_pos, &size); + STR_ALLOC(&result, tmp+2 + result_pos, &size); memcpy(result + result_pos, "=", 1); memcpy(result + result_pos+1, new_val, tmp); memcpy(result + result_pos+1+tmp, " ", 1); @@ -845,7 +852,7 @@ const char *subst_token(const char *s, const char *tok, const char *new_val) new_val = "\"\""; tmp = 2; } - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result + result_pos ,new_val, tmp + 1); result_pos += tmp; done_subst = 1; @@ -879,7 +886,7 @@ const char *subst_token(const char *s, const char *tok, const char *new_val) if(new_val) { if(!new_val[0]) new_val = "\"\""; tmp = strlen(new_val) + strlen(tok) + 2; - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); my_snprintf(result + result_pos - 1, size, " %s=%s", tok, new_val ); /* result_pos guaranteed to be > 0 */ } } @@ -1004,8 +1011,8 @@ void print_vhdl_element(FILE *fd, int inst) else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XVALUE) { if(c=='"' && !escape) quote=!quote; @@ -1143,8 +1150,8 @@ void print_generic(FILE *fd, char *ent_or_comp, int symbol) else if( (state==XTOKEN || state==XENDTOK) && c=='=') state=XSEPARATOR; else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XVALUE) { @@ -1248,8 +1255,8 @@ void print_verilog_param(FILE *fd, int symbol) else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XVALUE) { @@ -1340,7 +1347,7 @@ void print_spice_subckt(FILE *fd, int symbol) state = XSEPARATOR; } - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) { token[token_pos++]=c; } @@ -1443,7 +1450,7 @@ void print_spice_element(FILE *fd, int inst) while(1) { /* always make room for some characters so the single char writes to result do not need reallocs */ - str_alloc(&result, 100, result_pos, &size); + STR_ALLOC(&result, 100 + result_pos, &size); c=*s++; if(c=='\\') { escape=1; @@ -1463,7 +1470,7 @@ void print_spice_element(FILE *fd, int inst) dbg(1, "print_spice_element: c=%c, space=%d, escape=%d roken_pos=%d\n", c, space, escape, token_pos); state=XSEPARATOR; } - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) { token[token_pos++]=c; } @@ -1485,7 +1492,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(token + 1) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", token + 1); /* fputs(token + 1, fd); */ } else if (value && value[0]!='\0') { @@ -1497,7 +1504,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(lab) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", lab); /* fputs(lab,fd); */ @@ -1507,7 +1514,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(value) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", value); /* fputs(value,fd); */ } @@ -1518,7 +1525,7 @@ void print_spice_element(FILE *fd, int inst) const char *s = skip_dir(xctx->inst[inst].name); tmp = strlen(s) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", s); /* fputs(s,fd); */ } @@ -1528,7 +1535,7 @@ void print_spice_element(FILE *fd, int inst) const char *s = get_cell_w_ext(xctx->inst[inst].name, 0); tmp = strlen(s) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", s); /* fputs(s,fd); */ } @@ -1537,7 +1544,7 @@ void print_spice_element(FILE *fd, int inst) { tmp = strlen(xctx->current_name) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", xctx->current_name); /* fputs(xctx->current_name, fd); */ @@ -1553,7 +1560,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", mult, str_ptr); } } @@ -1567,7 +1574,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", mult, str_ptr); } break; @@ -1586,7 +1593,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", mult, str_ptr); } } @@ -1604,7 +1611,7 @@ void print_spice_element(FILE *fd, int inst) tmp = strlen(res) + 100; /* always make room for some extra chars * so 1-char writes to result do not need reallocs */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "%s", res); /* fprintf(fd, "%s", tclresult()); */ my_free(1018, &tclcmd); @@ -1775,7 +1782,7 @@ void print_tedax_element(FILE *fd, int inst) state=XSEPARATOR; } - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) { token[token_pos++]=c; /* 20171029 remove escaping backslashes */ } @@ -1985,8 +1992,8 @@ void print_verilog_element(FILE *fd, int inst) else if( state==XSEPARATOR && !space) state=XVALUE; else if( state==XVALUE && space && !quote) state=XEND; - str_alloc(&value, 0, value_pos, &sizeval); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&value, value_pos, &sizeval); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XVALUE) { @@ -2172,7 +2179,7 @@ void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 20071217 * state=XSEPARATOR; } - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) { token[token_pos++]=c; /* 20171029 remove escaping backslashes */ } @@ -2345,7 +2352,7 @@ void print_verilog_primitive(FILE *fd, int inst) /* netlist switch level primiti state=XSEPARATOR; } - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) { token[token_pos++]=c; } @@ -2550,8 +2557,8 @@ const char *translate(int inst, const char* s) && token_pos > 1 ) state=XSEPARATOR; - str_alloc(&result, 0, result_pos, &size); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&result, result_pos, &size); + STR_ALLOC(&token, token_pos, &sizetok); if(state==XTOKEN) token[token_pos++]=c; else if(state==XSEPARATOR) { @@ -2568,7 +2575,7 @@ 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); + 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; @@ -2576,19 +2583,19 @@ const char *translate(int inst, const char* s) token_pos = 0; if(get_tok_size) { tmp=get_tok_value_size; /* strlen(value); */ - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos, value, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@symname")==0) { tmp_sym_name=xctx->inst[inst].name ? get_cell(xctx->inst[inst].name, 0) : ""; tmp=strlen(tmp_sym_name); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,tmp_sym_name, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@symname_ext")==0) { tmp_sym_name=xctx->inst[inst].name ? get_cell_w_ext(xctx->inst[inst].name, 0) : ""; tmp=strlen(tmp_sym_name); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,tmp_sym_name, tmp+1); result_pos+=tmp; @@ -2655,7 +2662,7 @@ const char *translate(int inst, const char* s) my_free(1177, &tmpstr); } tmp=strlen(value); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos, value, tmp+1); result_pos+=tmp; my_free(1064, &pin_attr_value); @@ -2673,7 +2680,7 @@ const char *translate(int inst, const char* s) if(!stat(file_name , &time_buf)) { tm=localtime(&(time_buf.st_mtime) ); tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos, date, tmp+1); result_pos+=tmp; } @@ -2682,7 +2689,7 @@ const char *translate(int inst, const char* s) if(!stat(file_name , &time_buf)) { tm=localtime(&(time_buf.st_mtime) ); tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos, date, tmp+1); result_pos+=tmp; } @@ -2691,27 +2698,27 @@ const char *translate(int inst, const char* s) if(!stat(file_name , &time_buf)) { tm=localtime(&(time_buf.st_mtime) ); tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos, date, tmp+1); result_pos+=tmp; } } else if(strcmp(token,"@schname")==0) { /* tmp=strlen(xctx->sch[xctx->currsch]);*/ tmp = strlen(xctx->current_name); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); /* memcpy(result+result_pos,xctx->sch[xctx->currsch], tmp+1); */ memcpy(result+result_pos, xctx->current_name, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@prop_ptr")==0 && xctx->inst[inst].prop_ptr) { tmp=strlen(xctx->inst[inst].prop_ptr); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,xctx->inst[inst].prop_ptr, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@schvhdlprop")==0 && xctx->schvhdlprop) { tmp=strlen(xctx->schvhdlprop); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,xctx->schvhdlprop, tmp+1); result_pos+=tmp; } @@ -2719,7 +2726,7 @@ const char *translate(int inst, const char* s) else if(strcmp(token,"@schprop")==0 && xctx->schprop) { tmp=strlen(xctx->schprop); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,xctx->schprop, tmp+1); result_pos+=tmp; } @@ -2728,14 +2735,14 @@ const char *translate(int inst, const char* s) else if(strcmp(token,"@schsymbolprop")==0 && xctx->schsymbolprop) { tmp=strlen(xctx->schsymbolprop); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,xctx->schsymbolprop, tmp+1); result_pos+=tmp; } else if(strcmp(token,"@schtedaxprop")==0 && xctx->schtedaxprop) { tmp=strlen(xctx->schtedaxprop); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,xctx->schtedaxprop, tmp+1); result_pos+=tmp; } @@ -2744,7 +2751,7 @@ const char *translate(int inst, const char* s) else if(strcmp(token,"@schverilogprop")==0 && xctx->schverilogprop) { tmp=strlen(xctx->schverilogprop); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result+result_pos,xctx->schverilogprop, tmp+1); result_pos+=tmp; } @@ -2806,8 +2813,8 @@ const char *translate2(struct Lcc *lcc, int level, char* s) else if (state == XTOKEN && ( (space && !escape) || c == '@' || (!space && escape)) && token_pos > 1) { state = XSEPARATOR; } - str_alloc(&result, 0, result_pos, &size); - str_alloc(&token, 0, token_pos, &sizetok); + STR_ALLOC(&result, result_pos, &size); + STR_ALLOC(&token, token_pos, &sizetok); if (state == XTOKEN) token[token_pos++] = c; else if (state == XSEPARATOR) { token[token_pos] = '\0'; @@ -2840,7 +2847,7 @@ const char *translate2(struct Lcc *lcc, int level, char* s) i--; } tmp = get_tok_value_size; /* strlen(value); */ - str_alloc(&result, tmp + 1, result_pos, &size); /* +1 to add leading '$' */ + STR_ALLOC(&result, tmp + 1 + result_pos, &size); /* +1 to add leading '$' */ /* prefix substituted token with a '$' so it will be recognized by translate() for last level translation with instance placement prop_ptr attributes at drawing/netlisting time. */ memcpy(result + result_pos , "$", 1); @@ -2850,14 +2857,14 @@ const char *translate2(struct Lcc *lcc, int level, char* s) else if (strcmp(token, "@symname") == 0) { tmp_sym_name = lcc[level].symname ? get_cell(lcc[level].symname, 0) : ""; tmp = strlen(tmp_sym_name); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result + result_pos, tmp_sym_name, tmp + 1); result_pos += tmp; } else if (strcmp(token, "@symname_ext") == 0) { tmp_sym_name = lcc[level].symname ? get_cell_w_ext(lcc[level].symname, 0) : ""; tmp = strlen(tmp_sym_name); - str_alloc(&result, tmp, result_pos, &size); + STR_ALLOC(&result, tmp + result_pos, &size); memcpy(result + result_pos, tmp_sym_name, tmp + 1); result_pos += tmp; } diff --git a/src/xschem.h b/src/xschem.h index 5cd77d30..65934f94 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -298,6 +298,17 @@ extern char win_temp_dir[PATH_MAX]; #define X_TO_XSCHEM(x) ((x)*xctx->zoom -xctx->xorigin) #define Y_TO_XSCHEM(y) ((y)*xctx->zoom -xctx->yorigin) +/* given a dest_string of size 'size', allocate space to make sure it can + * hold additional 'add' characters starting at position 'pos' */ +#define STR_ALLOC(dest_string, add, size) \ +do { \ + register int __str_alloc_tmp__ = add; \ + if( __str_alloc_tmp__ >= *size) { \ + *size = __str_alloc_tmp__ + CADCHUNKALLOC; \ + my_realloc(1212, dest_string, *size); \ + } \ +} while(0) \ + typedef struct { unsigned short type; @@ -753,7 +764,7 @@ extern void hash_inst(int what, int n); extern void hash_inst_pin(int what, int i, int j); extern void del_inst_table(void); extern void hash_wires(void); -extern void hash_wire(int what, int n); +extern void hash_wire(int what, int n, int incremental); extern void hash_instances(void); /* 20171203 insert instance bbox in spatial hash table */ #ifdef HAS_CAIRO @@ -941,7 +952,6 @@ extern char* strtolower(char* s); extern char* strtoupper(char* s); extern void *my_malloc(int id, size_t size); extern void my_realloc(int id, void *ptr,size_t size); -extern void str_alloc( char **dest_string, int add, int pos, int *size); extern void *my_calloc(int id, size_t nmemb, size_t size); extern void my_free(int id, void *ptr); extern size_t my_strcat(int id, char **, const char *);