From 01b3401e43eb55f40b5473226b2d162f34c4dd3d Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sun, 28 Nov 2021 13:16:01 +0100 Subject: [PATCH] in memory undo now saves / restores all symbol definitions, so no re-link to instances operation is needed --- src/in_memory_undo.c | 450 ++++++++++++++++++++++++++++--------------- src/select.c | 3 +- src/token.c | 12 +- src/xinit.c | 4 +- 4 files changed, 309 insertions(+), 160 deletions(-) diff --git a/src/in_memory_undo.c b/src/in_memory_undo.c index 0ccbc188..7ca94883 100644 --- a/src/in_memory_undo.c +++ b/src/in_memory_undo.c @@ -24,28 +24,12 @@ #ifdef IN_MEMORY_UNDO -void init_undo() -{ - int slot; - - for(slot=0;slotuslot[slot].lines=my_calloc(165, cadlayers, sizeof(int)); - xctx->uslot[slot].rects=my_calloc(166, cadlayers, sizeof(int)); - xctx->uslot[slot].arcs=my_calloc(167, cadlayers, sizeof(int)); - xctx->uslot[slot].polygons=my_calloc(168, cadlayers, sizeof(int)); - xctx->uslot[slot].lptr=my_calloc(169, cadlayers, sizeof(xLine *)); - xctx->uslot[slot].bptr=my_calloc(170, cadlayers, sizeof(xRect *)); - xctx->uslot[slot].aptr=my_calloc(171, cadlayers, sizeof(xArc *)); - xctx->uslot[slot].pptr=my_calloc(172, cadlayers, sizeof(xPoly *)); - } -} - -void free_lines(int slot) +static void free_undo_lines(int slot) { int i, c; - for(c=0;cuslot[slot].lines[c]; i++) { + for(c = 0;cuslot[slot].lines[c]; i++) { my_free(783, &xctx->uslot[slot].lptr[c][i].prop_ptr); } my_free(784, &xctx->uslot[slot].lptr[c]); @@ -53,12 +37,12 @@ void free_lines(int slot) } } -void free_rects(int slot) +static void free_undo_rects(int slot) { int i, c; - for(c=0;cuslot[slot].rects[c]; i++) { + for(c = 0;cuslot[slot].rects[c]; i++) { my_free(785, &xctx->uslot[slot].bptr[c][i].prop_ptr); } my_free(786, &xctx->uslot[slot].bptr[c]); @@ -66,12 +50,12 @@ void free_rects(int slot) } } -void free_polygons(int slot) +static void free_undo_polygons(int slot) { int i, c; - for(c=0;cuslot[slot].polygons[c]; i++) { + for(c = 0;cuslot[slot].polygons[c]; i++) { my_free(787, &xctx->uslot[slot].pptr[c][i].prop_ptr); my_free(788, &xctx->uslot[slot].pptr[c][i].x); my_free(789, &xctx->uslot[slot].pptr[c][i].y); @@ -82,12 +66,12 @@ void free_polygons(int slot) } } -void free_arcs(int slot) +static void free_undo_arcs(int slot) { int i, c; - for(c=0;cuslot[slot].arcs[c]; i++) { + for(c = 0;cuslot[slot].arcs[c]; i++) { my_free(792, &xctx->uslot[slot].aptr[c][i].prop_ptr); } my_free(793, &xctx->uslot[slot].aptr[c]); @@ -95,22 +79,22 @@ void free_arcs(int slot) } } -void free_wires(int slot) +static void free_undo_wires(int slot) { int i; - for(i=0;iuslot[slot].wires; i++) { + for(i = 0;iuslot[slot].wires; i++) { my_free(794, &xctx->uslot[slot].wptr[i].prop_ptr); } my_free(795, &xctx->uslot[slot].wptr); xctx->uslot[slot].wires = 0; } -void free_texts(int slot) +static void free_undo_texts(int slot) { int i; - for(i=0;iuslot[slot].texts; i++) { + for(i = 0;iuslot[slot].texts; i++) { my_free(796, &xctx->uslot[slot].tptr[i].prop_ptr); my_free(797, &xctx->uslot[slot].tptr[i].txt_ptr); my_free(798, &xctx->uslot[slot].tptr[i].font); @@ -119,11 +103,11 @@ void free_texts(int slot) xctx->uslot[slot].texts = 0; } -void free_instances(int slot) +static void free_undo_instances(int slot) { int i; - for(i=0;iuslot[slot].instances; i++) { + for(i = 0;iuslot[slot].instances; i++) { my_free(800, &xctx->uslot[slot].iptr[i].name); my_free(801, &xctx->uslot[slot].iptr[i].prop_ptr); my_free(802, &xctx->uslot[slot].iptr[i].instname); @@ -133,9 +117,9 @@ void free_instances(int slot) xctx->uslot[slot].instances = 0; } -void free_symbols(int slot) +static void free_undo_symbols(int slot) { - int i, c, symbols; + int i, j, c, symbols; xSymbol *sym; symbols = xctx->uslot[slot].symbols; @@ -146,56 +130,55 @@ void free_symbols(int slot) my_free(373, &sym->type); my_free(660, &sym->templ); - for(c=0;cpolygons[c];i++) { - if(sym->poly[c][i].prop_ptr != NULL) { - my_free(892, &sym->poly[c][i].prop_ptr); + for(c = 0;cpolygons[c];j++) { + if(sym->poly[c][j].prop_ptr != NULL) { + my_free(892, &sym->poly[c][j].prop_ptr); } - my_free(914, &sym->poly[c][i].x); - my_free(915, &sym->poly[c][i].y); - my_free(918, &sym->poly[c][i].selected_point); + my_free(914, &sym->poly[c][j].x); + my_free(915, &sym->poly[c][j].y); + my_free(918, &sym->poly[c][j].selected_point); } my_free(1137, &sym->poly[c]); sym->polygons[c] = 0; - for(i=0;ilines[c];i++) { - if(sym->line[c][i].prop_ptr != NULL) { - my_free(1142, &sym->line[c][i].prop_ptr); + for(j = 0;jlines[c];j++) { + if(sym->line[c][j].prop_ptr != NULL) { + my_free(1142, &sym->line[c][j].prop_ptr); } } my_free(1290, &sym->line[c]); sym->lines[c] = 0; - for(i=0;iarcs[c];i++) { - if(sym->arc[c][i].prop_ptr != NULL) { - my_free(1291, &sym->arc[c][i].prop_ptr); + for(j = 0;jarcs[c];j++) { + if(sym->arc[c][j].prop_ptr != NULL) { + my_free(1291, &sym->arc[c][j].prop_ptr); } } my_free(1292, &sym->arc[c]); sym->arcs[c] = 0; - for(i=0;irects[c];i++) { - if(sym->rect[c][i].prop_ptr != NULL) { - my_free(1293, &sym->rect[c][i].prop_ptr); + for(j = 0;jrects[c];j++) { + if(sym->rect[c][j].prop_ptr != NULL) { + my_free(1293, &sym->rect[c][j].prop_ptr); } } my_free(1294, &sym->rect[c]); sym->rects[c] = 0; - } /* for(c=0;ctexts;i++) { - if(sym->text[i].prop_ptr != NULL) { - my_free(1297, &sym->text[i].prop_ptr); + } + for(j = 0;jtexts;j++) { + if(sym->text[j].prop_ptr != NULL) { + my_free(1297, &sym->text[j].prop_ptr); } - if(sym->text[i].txt_ptr != NULL) { - my_free(1298, &sym->text[i].txt_ptr); + if(sym->text[j].txt_ptr != NULL) { + my_free(1298, &sym->text[j].txt_ptr); } - if(sym->text[i].font != NULL) { - my_free(1299, &sym->text[i].font); + if(sym->text[j].font != NULL) { + my_free(1299, &sym->text[j].font); } } my_free(1300, &sym->text); sym->texts = 0; - my_free(1301, &sym->line); my_free(1302, &sym->rect); my_free(1303, &sym->poly); @@ -204,37 +187,60 @@ void free_symbols(int slot) my_free(1306, &sym->rects); my_free(1307, &sym->polygons); my_free(1308, &sym->arcs); - /* <<<< */ } my_free(48, &xctx->uslot[slot].symptr); xctx->uslot[slot].symbols = 0; } +static void init_undo() +{ + int slot; + + dbg(1, "init_undo(): undo_initialized = %d\n", xctx->undo_initialized); + if(!xctx->undo_initialized) { + for(slot = 0;slotuslot[slot].lines = my_calloc(165, cadlayers, sizeof(int)); + xctx->uslot[slot].rects = my_calloc(166, cadlayers, sizeof(int)); + xctx->uslot[slot].arcs = my_calloc(167, cadlayers, sizeof(int)); + xctx->uslot[slot].polygons = my_calloc(168, cadlayers, sizeof(int)); + xctx->uslot[slot].lptr = my_calloc(169, cadlayers, sizeof(xLine *)); + xctx->uslot[slot].bptr = my_calloc(170, cadlayers, sizeof(xRect *)); + xctx->uslot[slot].aptr = my_calloc(171, cadlayers, sizeof(xArc *)); + xctx->uslot[slot].pptr = my_calloc(172, cadlayers, sizeof(xPoly *)); + xctx->undo_initialized = 1; + } + } +} + +/* called when program resets undo stack (for example when loading a new file */ void clear_undo(void) { int slot; + dbg(1, "clear_undo(): undo_initialized = %d\n", xctx->undo_initialized); xctx->cur_undo_ptr = 0; xctx->tail_undo_ptr = 0; xctx->head_undo_ptr = 0; if(!xctx->undo_initialized) return; - for(slot=0; slotundo_initialized); + if(!xctx->undo_initialized) return; clear_undo(); - for(slot=0;slotuslot[slot].lines); my_free(805, &xctx->uslot[slot].rects); my_free(806, &xctx->uslot[slot].arcs); @@ -244,19 +250,17 @@ void delete_undo(void) my_free(810, &xctx->uslot[slot].aptr); my_free(811, &xctx->uslot[slot].pptr); } - + xctx->undo_initialized = 0; } void push_undo(void) { - int slot, i, j, c; + int slot, i, c; xSymbol *sym; + int j; if(xctx->no_undo)return; - if(!xctx->undo_initialized) { - xctx->undo_initialized=1; - init_undo(); - } + init_undo(); slot = xctx->cur_undo_ptr%MAX_UNDO; my_strdup(173, &xctx->uslot[slot].gptr, xctx->schvhdlprop); @@ -265,21 +269,20 @@ void push_undo(void) my_strdup(359, &xctx->uslot[slot].kptr, xctx->schsymbolprop); my_strdup(176, &xctx->uslot[slot].eptr, xctx->schtedaxprop); - free_lines(slot); - free_rects(slot); - free_polygons(slot); - free_arcs(slot); - free_wires(slot); - free_texts(slot); - free_instances(slot); - free_symbols(slot); + free_undo_lines(slot); + free_undo_rects(slot); + free_undo_polygons(slot); + free_undo_arcs(slot); + free_undo_wires(slot); + free_undo_texts(slot); + free_undo_instances(slot); + free_undo_symbols(slot); - - for(c=0;cuslot[slot].lines[c] = xctx->lines[c]; - xctx->uslot[slot].rects[c] = xctx->rects[c]; - xctx->uslot[slot].arcs[c] = xctx->arcs[c]; - xctx->uslot[slot].polygons[c] = xctx->polygons[c]; + memcpy(xctx->uslot[slot].lines, xctx->lines, sizeof(xctx->lines[0]) * cadlayers); + memcpy(xctx->uslot[slot].rects, xctx->rects, sizeof(xctx->rects[0]) * cadlayers); + memcpy(xctx->uslot[slot].arcs, xctx->arcs, sizeof(xctx->arcs[0]) * cadlayers); + memcpy(xctx->uslot[slot].polygons, xctx->polygons, sizeof(xctx->polygons[0]) * cadlayers); + for(c = 0;cuslot[slot].lptr[c] = my_calloc(177, xctx->lines[c], sizeof(xLine)); xctx->uslot[slot].bptr[c] = my_calloc(178, xctx->rects[c], sizeof(xRect)); xctx->uslot[slot].pptr[c] = my_calloc(179, xctx->polygons[c], sizeof(xPoly)); @@ -294,33 +297,30 @@ void push_undo(void) xctx->uslot[slot].symbols = xctx->symbols; xctx->uslot[slot].wires = xctx->wires; - for(c=0;clines[c];i++) { + for(i = 0;ilines[c];i++) { xctx->uslot[slot].lptr[c][i] = xctx->line[c][i]; xctx->uslot[slot].lptr[c][i].prop_ptr = NULL; my_strdup(184, &xctx->uslot[slot].lptr[c][i].prop_ptr, xctx->line[c][i].prop_ptr); } /* rects */ - for(i=0;irects[c];i++) { + for(i = 0;irects[c];i++) { xctx->uslot[slot].bptr[c][i] = xctx->rect[c][i]; xctx->uslot[slot].bptr[c][i].prop_ptr = NULL; my_strdup(185, &xctx->uslot[slot].bptr[c][i].prop_ptr, xctx->rect[c][i].prop_ptr); } /* arcs */ - for(i=0;iarcs[c];i++) { + for(i = 0;iarcs[c];i++) { xctx->uslot[slot].aptr[c][i] = xctx->arc[c][i]; xctx->uslot[slot].aptr[c][i].prop_ptr = NULL; my_strdup(186, &xctx->uslot[slot].aptr[c][i].prop_ptr, xctx->arc[c][i].prop_ptr); } /*polygons */ - for(i=0;ipolygons[c];i++) { + for(i = 0;ipolygons[c];i++) { int points = xctx->poly[c][i].points; xctx->uslot[slot].pptr[c][i] = xctx->poly[c][i]; xctx->uslot[slot].pptr[c][i].prop_ptr = NULL; - xctx->uslot[slot].pptr[c][i].x = NULL; - xctx->uslot[slot].pptr[c][i].y = NULL; - xctx->uslot[slot].pptr[c][i].selected_point = NULL; xctx->uslot[slot].pptr[c][i].x = my_malloc(187, points * sizeof(double)); xctx->uslot[slot].pptr[c][i].y = my_malloc(188, points * sizeof(double)); xctx->uslot[slot].pptr[c][i].selected_point = my_malloc(189, points * sizeof(unsigned short)); @@ -332,7 +332,7 @@ void push_undo(void) } } /* instances */ - for(i=0;iinstances;i++) { + for(i = 0;iinstances;i++) { xctx->uslot[slot].iptr[i] = xctx->inst[i]; xctx->uslot[slot].iptr[i].prop_ptr = NULL; xctx->uslot[slot].iptr[i].name = NULL; @@ -346,7 +346,7 @@ void push_undo(void) } /* symbols */ - for(i=0;isymbols;i++) { + for(i = 0;isymbols;i++) { sym = &xctx->uslot[slot].symptr[i]; xctx->uslot[slot].symptr[i] = xctx->sym[i]; sym->name = NULL; @@ -357,16 +357,59 @@ void push_undo(void) my_strdup2(1317, &sym->type, xctx->sym[i].type); my_strdup2(1318, &sym->templ, xctx->sym[i].templ); my_strdup2(1319, &sym->prop_ptr, xctx->sym[i].prop_ptr); - sym->line=my_calloc(1309, cadlayers, sizeof(xLine *)); - sym->poly=my_calloc(1324, cadlayers, sizeof(xPoly *)); - sym->arc=my_calloc(1310, cadlayers, sizeof(xArc *)); - sym->rect=my_calloc(1311, cadlayers, sizeof(xRect *)); - sym->lines=my_calloc(1312, cadlayers, sizeof(int)); - sym->rects=my_calloc(1313, cadlayers, sizeof(int)); - sym->arcs=my_calloc(1314, cadlayers, sizeof(int)); - sym->polygons=my_calloc(1315, cadlayers, sizeof(int)); + sym->line = my_calloc(1309, cadlayers, sizeof(xLine *)); + sym->poly = my_calloc(1324, cadlayers, sizeof(xPoly *)); + sym->arc = my_calloc(1310, cadlayers, sizeof(xArc *)); + sym->rect = my_calloc(1311, cadlayers, sizeof(xRect *)); + sym->lines = my_calloc(1312, cadlayers, sizeof(int)); + sym->rects = my_calloc(1313, cadlayers, sizeof(int)); + sym->arcs = my_calloc(1314, cadlayers, sizeof(int)); + sym->polygons = my_calloc(1315, cadlayers, sizeof(int)); sym->text = my_calloc(1320, xctx->sym[i].texts, sizeof(xText)); + memcpy(sym->lines, xctx->sym[i].lines, sizeof(sym->lines[0]) * cadlayers); + memcpy(sym->rects, xctx->sym[i].rects, sizeof(sym->rects[0]) * cadlayers); + memcpy(sym->arcs, xctx->sym[i].arcs, sizeof(sym->arcs[0]) * cadlayers); + memcpy(sym->polygons, xctx->sym[i].polygons, sizeof(sym->polygons[0]) * cadlayers); + for(c = 0;cline[c] = my_calloc(1359, xctx->sym[i].lines[c], sizeof(xLine)); + for(j = 0; j < xctx->sym[i].lines[c]; j++) { + sym->line[c][j] = xctx->sym[i].line[c][j]; + sym->line[c][j].prop_ptr = NULL; + my_strdup(1358, &sym->line[c][j].prop_ptr, xctx->sym[i].line[c][j].prop_ptr); + } + /* symbol rects */ + sym->rect[c] = my_calloc(1360, xctx->sym[i].rects[c], sizeof(xRect)); + for(j = 0; j < xctx->sym[i].rects[c]; j++) { + sym->rect[c][j] = xctx->sym[i].rect[c][j]; + sym->rect[c][j].prop_ptr = NULL; + my_strdup(1362, &sym->rect[c][j].prop_ptr, xctx->sym[i].rect[c][j].prop_ptr); + } + /* symbol arcs */ + sym->arc[c] = my_calloc(1361, xctx->sym[i].arcs[c], sizeof(xArc)); + for(j = 0; j < xctx->sym[i].arcs[c]; j++) { + sym->arc[c][j] = xctx->sym[i].arc[c][j]; + sym->arc[c][j].prop_ptr = NULL; + my_strdup(1375, &sym->arc[c][j].prop_ptr, xctx->sym[i].arc[c][j].prop_ptr); + } + /* symbol polygons */ + sym->poly[c] = my_calloc(1363, xctx->sym[i].polygons[c], sizeof(xPoly)); + for(j = 0; j < xctx->sym[i].polygons[c]; j++) { + int points = xctx->sym[i].poly[c][j].points; + sym->poly[c][j] = xctx->sym[i].poly[c][j]; + sym->poly[c][j].prop_ptr = NULL; + sym->poly[c][j].x = my_malloc(1365, points * sizeof(double)); + sym->poly[c][j].y = my_malloc(1366, points * sizeof(double)); + sym->poly[c][j].selected_point = my_malloc(1367, points * sizeof(unsigned short)); + my_strdup(1364, &sym->poly[c][j].prop_ptr, xctx->sym[i].poly[c][j].prop_ptr); + memcpy(sym->poly[c][j].x, xctx->sym[i].poly[c][j].x, points * sizeof(double)); + memcpy(sym->poly[c][j].y, xctx->sym[i].poly[c][j].y, points * sizeof(double)); + memcpy(sym->poly[c][j].selected_point, xctx->sym[i].poly[c][j].selected_point, + points * sizeof(unsigned short)); + } + } + /* symbol texts */ for(j = 0; j < xctx->sym[i].texts; j++) { sym->text[j] = xctx->sym[i].text[j]; sym->text[j].prop_ptr = NULL; @@ -376,12 +419,10 @@ void push_undo(void) my_strdup(1322, &sym->text[j].txt_ptr, xctx->sym[i].text[j].txt_ptr); my_strdup(1323, &sym->text[j].font, xctx->sym[i].text[j].font); } - + } - /* <<<< */ - /* texts */ - for(i=0;itexts;i++) { + for(i = 0;itexts;i++) { xctx->uslot[slot].tptr[i] = xctx->text[i]; xctx->uslot[slot].tptr[i].prop_ptr = NULL; xctx->uslot[slot].tptr[i].txt_ptr = NULL; @@ -392,7 +433,7 @@ void push_undo(void) } /* wires */ - for(i=0;iwires;i++) { + for(i = 0;iwires;i++) { xctx->uslot[slot].wptr[i] = xctx->wire[i]; xctx->uslot[slot].wptr[i].prop_ptr = NULL; xctx->uslot[slot].wptr[i].node = NULL; @@ -419,6 +460,8 @@ void push_undo(void) void pop_undo(int redo, int set_modify_status) { int slot, i, c; + xSymbol *sym; + int j; if(xctx->no_undo)return; if(redo == 1) { @@ -434,76 +477,102 @@ void pop_undo(int redo, int set_modify_status) xctx->head_undo_ptr--; xctx->cur_undo_ptr--; } - if(xctx->cur_undo_ptr<=0) return; /* check undo tail */ + if(xctx->cur_undo_ptr<= 0) return; /* check undo tail */ xctx->cur_undo_ptr--; } else { /* redo == 2, get data without changing undo stack */ - if(xctx->cur_undo_ptr<=0) return; /* check undo tail */ - xctx->cur_undo_ptr--; /* will be restored after building file name */ + if(xctx->cur_undo_ptr<= 0) return; /* check undo tail */ + xctx->cur_undo_ptr--; /* will be restored at end */ } slot = xctx->cur_undo_ptr%MAX_UNDO; clear_drawing(); unselect_all(); + my_free(1345, &xctx->wire); + my_free(1346, &xctx->text); + my_free(1347, &xctx->inst); + + for(i = 0;irect[i]); + my_free(1342, &xctx->line[i]); + my_free(1343, &xctx->poly[i]); + my_free(1344, &xctx->arc[i]); + } + + remove_symbols(); + + + for(i = 0;imaxs;i++) { + my_free(1349, &xctx->sym[i].line); + my_free(1350, &xctx->sym[i].rect); + my_free(1351, &xctx->sym[i].arc); + my_free(1352, &xctx->sym[i].poly); + my_free(1353, &xctx->sym[i].lines); + my_free(1354, &xctx->sym[i].polygons); + my_free(1355, &xctx->sym[i].arcs); + my_free(1356, &xctx->sym[i].rects); + } + + + my_free(0, &xctx->sym); + + my_strdup(198, &xctx->schvhdlprop, xctx->uslot[slot].gptr); my_strdup(199, &xctx->schverilogprop, xctx->uslot[slot].vptr); my_strdup(200, &xctx->schprop, xctx->uslot[slot].sptr); my_strdup(389, &xctx->schsymbolprop, xctx->uslot[slot].kptr); my_strdup(201, &xctx->schtedaxprop, xctx->uslot[slot].eptr); - for(c=0;cmaxl[c] = xctx->lines[c] = xctx->uslot[slot].lines[c]; xctx->line[c] = my_calloc(202, xctx->lines[c], sizeof(xLine)); - for(i=0;ilines[c];i++) { + for(i = 0;ilines[c];i++) { xctx->line[c][i] = xctx->uslot[slot].lptr[c][i]; - xctx->line[c][i].prop_ptr=NULL; + xctx->line[c][i].prop_ptr = NULL; my_strdup(203, &xctx->line[c][i].prop_ptr, xctx->uslot[slot].lptr[c][i].prop_ptr); } /* rects */ xctx->maxr[c] = xctx->rects[c] = xctx->uslot[slot].rects[c]; xctx->rect[c] = my_calloc(204, xctx->rects[c], sizeof(xRect)); - for(i=0;irects[c];i++) { + for(i = 0;irects[c];i++) { xctx->rect[c][i] = xctx->uslot[slot].bptr[c][i]; - xctx->rect[c][i].prop_ptr=NULL; + xctx->rect[c][i].prop_ptr = NULL; my_strdup(205, &xctx->rect[c][i].prop_ptr, xctx->uslot[slot].bptr[c][i].prop_ptr); } /* arcs */ xctx->maxa[c] = xctx->arcs[c] = xctx->uslot[slot].arcs[c]; xctx->arc[c] = my_calloc(206, xctx->arcs[c], sizeof(xArc)); - for(i=0;iarcs[c];i++) { + for(i = 0;iarcs[c];i++) { xctx->arc[c][i] = xctx->uslot[slot].aptr[c][i]; - xctx->arc[c][i].prop_ptr=NULL; + xctx->arc[c][i].prop_ptr = NULL; my_strdup(207, &xctx->arc[c][i].prop_ptr, xctx->uslot[slot].aptr[c][i].prop_ptr); } /* polygons */ xctx->maxp[c] = xctx->polygons[c] = xctx->uslot[slot].polygons[c]; xctx->poly[c] = my_calloc(208, xctx->polygons[c], sizeof(xPoly)); - for(i=0;ipolygons[c];i++) { + for(i = 0;ipolygons[c];i++) { int points = xctx->uslot[slot].pptr[c][i].points; xctx->poly[c][i] = xctx->uslot[slot].pptr[c][i]; - xctx->poly[c][i].prop_ptr=NULL; - xctx->poly[c][i].x=NULL; - xctx->poly[c][i].y=NULL; - xctx->poly[c][i].selected_point=NULL; + xctx->poly[c][i].prop_ptr = NULL; my_strdup(209, &xctx->poly[c][i].prop_ptr, xctx->uslot[slot].pptr[c][i].prop_ptr); - my_realloc(210, &xctx->poly[c][i].x, points * sizeof(double)); - my_realloc(211, &xctx->poly[c][i].y, points * sizeof(double)); - my_realloc(212, &xctx->poly[c][i].selected_point, points * sizeof(unsigned short)); + xctx->poly[c][i].x = my_malloc(210, points * sizeof(double)); + xctx->poly[c][i].y = my_malloc(211, points * sizeof(double)); + xctx->poly[c][i].selected_point = my_malloc(212, points * sizeof(unsigned short)); memcpy(xctx->poly[c][i].x, xctx->uslot[slot].pptr[c][i].x, points * sizeof(double)); memcpy(xctx->poly[c][i].y, xctx->uslot[slot].pptr[c][i].y, points * sizeof(double)); memcpy(xctx->poly[c][i].selected_point, xctx->uslot[slot].pptr[c][i].selected_point, points * sizeof(unsigned short)); } - } /* instances */ xctx->maxi = xctx->instances = xctx->uslot[slot].instances; xctx->inst = my_calloc(213, xctx->instances, sizeof(xInstance)); - for(i=0;iinstances;i++) { + for(i = 0;iinstances;i++) { xctx->inst[i] = xctx->uslot[slot].iptr[i]; - xctx->inst[i].prop_ptr=NULL; - xctx->inst[i].name=NULL; - xctx->inst[i].instname=NULL; - xctx->inst[i].lab=NULL; + xctx->inst[i].prop_ptr = NULL; + xctx->inst[i].name = NULL; + xctx->inst[i].instname = NULL; + xctx->inst[i].lab = NULL; my_strdup(214, &xctx->inst[i].prop_ptr, xctx->uslot[slot].iptr[i].prop_ptr); my_strdup2(215, &xctx->inst[i].name, xctx->uslot[slot].iptr[i].name); my_strdup2(216, &xctx->inst[i].instname, xctx->uslot[slot].iptr[i].instname); @@ -514,17 +583,91 @@ void pop_undo(int redo, int set_modify_status) xctx->maxs = xctx->symbols = xctx->uslot[slot].symbols; xctx->sym = my_calloc(1325, xctx->symbols, sizeof(xSymbol)); + for(i = 0;isymbols;i++) { + sym = &xctx->uslot[slot].symptr[i]; + xctx->sym[i] = *sym; + xctx->sym[i].name = NULL; + xctx->sym[i].prop_ptr = NULL; + xctx->sym[i].type = NULL; + xctx->sym[i].templ = NULL; + my_strdup2(1326, &xctx->sym[i].name, sym->name); + my_strdup2(1327, &xctx->sym[i].type, sym->type); + my_strdup2(1328, &xctx->sym[i].templ, sym->templ); + my_strdup2(1329, &xctx->sym[i].prop_ptr, sym->prop_ptr); - /* <<<< */ + xctx->sym[i].line = my_calloc(1330, cadlayers, sizeof(xLine *)); + xctx->sym[i].poly = my_calloc(1331, cadlayers, sizeof(xPoly *)); + xctx->sym[i].arc = my_calloc(1332, cadlayers, sizeof(xArc *)); + xctx->sym[i].rect = my_calloc(1333, cadlayers, sizeof(xRect *)); + xctx->sym[i].lines = my_calloc(1334, cadlayers, sizeof(int)); + xctx->sym[i].rects = my_calloc(1335, cadlayers, sizeof(int)); + xctx->sym[i].arcs = my_calloc(1336, cadlayers, sizeof(int)); + xctx->sym[i].polygons = my_calloc(1337, cadlayers, sizeof(int)); + xctx->sym[i].text = my_calloc(1338, xctx->sym[i].texts, sizeof(xText)); + + memcpy(xctx->sym[i].lines, sym->lines, sizeof(sym->lines[0]) * cadlayers); + memcpy(xctx->sym[i].rects, sym->rects, sizeof(sym->rects[0]) * cadlayers); + memcpy(xctx->sym[i].arcs, sym->arcs, sizeof(sym->arcs[0]) * cadlayers); + memcpy(xctx->sym[i].polygons, sym->polygons, sizeof(sym->polygons[0]) * cadlayers); + + for(c = 0;csym[i].line[c] = my_calloc(1371, sym->lines[c], sizeof(xLine)); + for(j = 0; j < xctx->sym[i].lines[c]; j++) { + xctx->sym[i].line[c][j] = sym->line[c][j]; + xctx->sym[i].line[c][j].prop_ptr = NULL; + my_strdup(1368, & xctx->sym[i].line[c][j].prop_ptr, sym->line[c][j].prop_ptr); + } + /* symbol rects */ + xctx->sym[i].rect[c] = my_calloc(1372, sym->rects[c], sizeof(xRect)); + for(j = 0; j < xctx->sym[i].rects[c]; j++) { + xctx->sym[i].rect[c][j] = sym->rect[c][j]; + xctx->sym[i].rect[c][j].prop_ptr = NULL; + my_strdup(1369, & xctx->sym[i].rect[c][j].prop_ptr, sym->rect[c][j].prop_ptr); + } + /* symbol arcs */ + xctx->sym[i].arc[c] = my_calloc(1373, sym->arcs[c], sizeof(xArc)); + for(j = 0; j < xctx->sym[i].arcs[c]; j++) { + xctx->sym[i].arc[c][j] = sym->arc[c][j]; + xctx->sym[i].arc[c][j].prop_ptr = NULL; + my_strdup(1370, & xctx->sym[i].arc[c][j].prop_ptr, sym->arc[c][j].prop_ptr); + } + /* symbol polygons */ + xctx->sym[i].poly[c] = my_calloc(1374, sym->polygons[c], sizeof(xPoly)); + for(j = 0; j < xctx->sym[i].polygons[c]; j++) { + int points = sym->poly[c][j].points; + xctx->sym[i].poly[c][j] = sym->poly[c][j]; + xctx->sym[i].poly[c][j].prop_ptr = NULL; + xctx->sym[i].poly[c][j].x = my_malloc(1376, points * sizeof(double)); + xctx->sym[i].poly[c][j].y = my_malloc(1377, points * sizeof(double)); + xctx->sym[i].poly[c][j].selected_point = my_malloc(1378, points * sizeof(unsigned short)); + memcpy(xctx->sym[i].poly[c][j].x, sym->poly[c][j].x, points * sizeof(double)); + memcpy(xctx->sym[i].poly[c][j].y, sym->poly[c][j].y, points * sizeof(double)); + memcpy(xctx->sym[i].poly[c][j].selected_point, sym->poly[c][j].selected_point, + points * sizeof(unsigned short)); + my_strdup(1357, & xctx->sym[i].poly[c][j].prop_ptr, sym->poly[c][j].prop_ptr); + } + } + /* symbol texts */ + for(j = 0; j < xctx->sym[i].texts; j++) { + xctx->sym[i].text[j] = sym->text[j]; + xctx->sym[i].text[j].prop_ptr = NULL; + xctx->sym[i].text[j].txt_ptr = NULL; + xctx->sym[i].text[j].font = NULL; + my_strdup(1339, &xctx->sym[i].text[j].prop_ptr, sym->text[j].prop_ptr); + my_strdup(1340, &xctx->sym[i].text[j].txt_ptr, sym->text[j].txt_ptr); + my_strdup(1341, &xctx->sym[i].text[j].font, sym->text[j].font); + } + } /* texts */ xctx->maxt = xctx->texts = xctx->uslot[slot].texts; xctx->text = my_calloc(217, xctx->texts, sizeof(xText)); - for(i=0;itexts;i++) { + for(i = 0;itexts;i++) { xctx->text[i] = xctx->uslot[slot].tptr[i]; - xctx->text[i].txt_ptr=NULL; - xctx->text[i].font=NULL; - xctx->text[i].prop_ptr=NULL; + xctx->text[i].txt_ptr = NULL; + xctx->text[i].font = NULL; + xctx->text[i].prop_ptr = NULL; my_strdup(218, &xctx->text[i].prop_ptr, xctx->uslot[slot].tptr[i].prop_ptr); my_strdup(219, &xctx->text[i].txt_ptr, xctx->uslot[slot].tptr[i].txt_ptr); my_strdup(220, &xctx->text[i].font, xctx->uslot[slot].tptr[i].font); @@ -533,19 +676,20 @@ void pop_undo(int redo, int set_modify_status) /* wires */ xctx->maxw = xctx->wires = xctx->uslot[slot].wires; xctx->wire = my_calloc(221, xctx->wires, sizeof(xWire)); - for(i=0;iwires;i++) { + for(i = 0;iwires;i++) { xctx->wire[i] = xctx->uslot[slot].wptr[i]; - xctx->wire[i].prop_ptr=NULL; - xctx->wire[i].node=NULL; + xctx->wire[i].prop_ptr = NULL; + xctx->wire[i].node = NULL; my_strdup(222, &xctx->wire[i].prop_ptr, xctx->uslot[slot].wptr[i].prop_ptr); } - link_symbols_to_instances(-1); + /* unnecessary since in_memory_undo saves all symbols */ + /* link_symbols_to_instances(-1); */ if(redo == 2) xctx->cur_undo_ptr++; /* restore undo stack pointer */ if(set_modify_status) set_modify(1); - xctx->prep_hash_inst=0; - xctx->prep_hash_wires=0; - xctx->prep_net_structs=0; - xctx->prep_hi_structs=0; + xctx->prep_hash_inst = 0; + xctx->prep_hash_wires = 0; + xctx->prep_net_structs = 0; + xctx->prep_hi_structs = 0; update_conn_cues(0, 0); } diff --git a/src/select.c b/src/select.c index 2ebdf02e..b9cea358 100644 --- a/src/select.c +++ b/src/select.c @@ -586,6 +586,7 @@ void unselect_all(void) #if HAS_CAIRO==1 int customfont; #endif + dbg(1, "unselect_all(): start\n"); xctx->ui_state = 0; xctx->lastsel = 0; @@ -681,7 +682,7 @@ void unselect_all(void) /*\statusmsg("",2); */ my_snprintf(str, S(str), "%s/%s", user_conf_dir, ".selection.sch"); /* 20161115 PWD->HOME */ xunlink(str); - + dbg(1, "unselect_all(): done\n"); } void select_wire(int i,unsigned short select_mode, int fast) diff --git a/src/token.c b/src/token.c index c7dc6d15..e48551cb 100644 --- a/src/token.c +++ b/src/token.c @@ -452,14 +452,16 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) int escape=0; int cmp = 1; + xctx->get_tok_size = 0; if(s==NULL) { - my_free(976, &result); - my_free(977, &token); - size = sizetok = 0; - xctx->get_tok_size = 0; + if(tok == NULL) { + my_free(976, &result); + my_free(977, &token); + size = sizetok = 0; + dbg(2, "get_tok_value(): clear static data\n"); + } return ""; } - xctx->get_tok_size = 0; /* dbg(2, "get_tok_value(): looking for <%s> in <%s>\n",tok,s); */ if( size == 0 ) { sizetok = size = CADCHUNKALLOC; diff --git a/src/xinit.c b/src/xinit.c index 85955ae1..b7eaa499 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -592,6 +592,9 @@ void delete_schematic_data(void) { dbg(1, "delete_schematic_data()\n"); unselect_all(); + /* clear static data in get_tok_value() must be done after unselect_all() + * as this functions re-uses get_tok_value() */ + get_tok_value(NULL, NULL, 0); /* clear static data in function */ delete_netlist_structs(); /* netlist - specific data and hash tables */ clear_all_hilights(); /* data structs for hilighting nets/instances */ get_unnamed_node(0, 0, 0); /* net### enumerator used for netlisting */ @@ -612,7 +615,6 @@ void xwin_exit(void) dbg(0, "xwin_exit() double call, doing nothing...\n"); return; } - get_tok_value(NULL, NULL, 0); /* clear static data in function */ delete_schematic_data(); if(has_x) { Tk_DestroyWindow(mainwindow);