mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-29 20:53:55 +02:00
eeshow/sch-parse.c (sch_free): add cleanup of schematics data
This commit is contained in:
parent
5f0678097f
commit
c54bf3de06
@ -211,5 +211,7 @@ found:
|
|||||||
}
|
}
|
||||||
gfx_end();
|
gfx_end();
|
||||||
|
|
||||||
|
sch_free(&sch_ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -488,6 +488,8 @@ static bool parse_line(const struct file *file, void *user, const char *line)
|
|||||||
if (ctx->recurse)
|
if (ctx->recurse)
|
||||||
sheet_obj->u.sheet.sheet =
|
sheet_obj->u.sheet.sheet =
|
||||||
recurse_sheet(ctx, file);
|
recurse_sheet(ctx, file);
|
||||||
|
else
|
||||||
|
sheet_obj->u.sheet.sheet = NULL;
|
||||||
ctx->state = sch_basic;
|
ctx->state = sch_basic;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -553,3 +555,73 @@ void sch_init(struct sch_ctx *ctx, bool recurse)
|
|||||||
ctx->next_sheet = &ctx->sheets;
|
ctx->next_sheet = &ctx->sheets;
|
||||||
new_sheet(ctx);
|
new_sheet(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void free_comp_fields(struct comp_field *fields)
|
||||||
|
{
|
||||||
|
struct comp_field *next;
|
||||||
|
|
||||||
|
while (fields) {
|
||||||
|
next = fields->next;
|
||||||
|
free((char *) fields->txt.s);
|
||||||
|
free(fields);
|
||||||
|
fields = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void free_sheet_fields(struct sheet_field *fields)
|
||||||
|
{
|
||||||
|
struct sheet_field *next;
|
||||||
|
|
||||||
|
while (fields) {
|
||||||
|
next = fields->next;
|
||||||
|
free((char *) fields->s);
|
||||||
|
free(fields);
|
||||||
|
fields = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void free_sheet(struct sheet *sch)
|
||||||
|
{
|
||||||
|
struct sch_obj *obj, *next;
|
||||||
|
|
||||||
|
if (!sch)
|
||||||
|
return;
|
||||||
|
free((char *) sch->title);
|
||||||
|
for (obj = sch->objs; obj; obj = next) {
|
||||||
|
next = obj->next;
|
||||||
|
switch (obj->type) {
|
||||||
|
case sch_obj_text:
|
||||||
|
free((char *) obj->u.text.s);
|
||||||
|
break;
|
||||||
|
case sch_obj_comp:
|
||||||
|
free_comp_fields(obj->u.comp.fields);
|
||||||
|
break;
|
||||||
|
case sch_obj_sheet:
|
||||||
|
free((char *) obj->u.sheet.name);
|
||||||
|
free((char *) obj->u.sheet.file);
|
||||||
|
free_sheet((struct sheet *) obj->u.sheet.sheet);
|
||||||
|
free_sheet_fields(obj->u.sheet.fields);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
free(obj);
|
||||||
|
}
|
||||||
|
free(sch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sch_free(struct sch_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct sheet *next;
|
||||||
|
|
||||||
|
while (ctx->sheets) {
|
||||||
|
next = ctx->sheets->next;
|
||||||
|
free_sheet(ctx->sheets);
|
||||||
|
ctx->sheets = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ struct sch_obj {
|
|||||||
const char *file;
|
const char *file;
|
||||||
unsigned file_dim;
|
unsigned file_dim;
|
||||||
bool rotated;
|
bool rotated;
|
||||||
const struct sheet *sheet; /* pointer to sub-sheet */
|
const struct sheet *sheet;
|
||||||
|
/* pointer to sub-sheet; NULL if absent */
|
||||||
|
|
||||||
struct sheet_field {
|
struct sheet_field {
|
||||||
char *s;
|
char *s;
|
||||||
@ -91,7 +92,7 @@ struct sch_obj {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sheet {
|
struct sheet {
|
||||||
const char *title;
|
const char *title; /* malloced, unless delta */
|
||||||
struct sch_obj *objs;
|
struct sch_obj *objs;
|
||||||
struct sch_obj **next_obj;
|
struct sch_obj **next_obj;
|
||||||
struct sheet *parent;
|
struct sheet *parent;
|
||||||
@ -118,5 +119,6 @@ void decode_alignment(struct text *txt, char hor, char vert);
|
|||||||
void sch_render(const struct sheet *sheet);
|
void sch_render(const struct sheet *sheet);
|
||||||
void sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib);
|
void sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib);
|
||||||
void sch_init(struct sch_ctx *ctx, bool recurse);
|
void sch_init(struct sch_ctx *ctx, bool recurse);
|
||||||
|
void sch_free(struct sch_ctx *ctx);
|
||||||
|
|
||||||
#endif /* !SCH_H */
|
#endif /* !SCH_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user