diff --git a/inst.c b/inst.c index 7534717..a296ca3 100644 --- a/inst.c +++ b/inst.c @@ -1,8 +1,8 @@ /* * inst.c - Instance structures * - * Written 2009-2011 by Werner Almesberger - * Copyright 2009-2011 by Werner Almesberger + * Written 2009-2012 by Werner Almesberger + * Copyright 2009-2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1051,6 +1051,7 @@ int inst_meas(struct obj *obj, struct coord from, struct coord to) assert(inst); inst->base = from; inst->u.meas.end = to; + inst->u.meas.valid = 1; /* @@@ we still need to consider the text size as well */ update_bbox(&inst->bbox, from); update_bbox(&inst->bbox, to); @@ -1073,6 +1074,7 @@ void inst_meas_hint(struct obj *obj, unit_type offset) inst = add_inst(&meas_ops, ip_meas, zero); inst->obj = obj; inst->u.meas.offset = offset; + inst->u.meas.valid = 0; inst->active = 1; /* measurements are always active */ } diff --git a/inst.h b/inst.h index daee9ae..badfb33 100644 --- a/inst.h +++ b/inst.h @@ -1,8 +1,8 @@ /* * inst.h - Instance structures * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009, 2010, 2012 by Werner Almesberger + * Copyright 2009, 2010, 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -113,6 +113,7 @@ struct inst { struct { struct coord end; double offset; + int valid; /* only set if references exist */ } meas; } u; struct inst *next; diff --git a/meas.c b/meas.c index d551a2f..e505c68 100644 --- a/meas.c +++ b/meas.c @@ -1,8 +1,8 @@ /* * meas.c - Measurements * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009, 2010, 2012 by Werner Almesberger + * Copyright 2009, 2010, 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -294,6 +294,22 @@ static int instantiate_meas_pkg(int n_frames) } +static void purge_meas(struct pkg *pkg) +{ + struct inst **anchor, *inst; + + anchor = pkg->insts+ip_meas; + while (*anchor) + if ((*anchor)->u.meas.valid) { + anchor = &(*anchor)->next; + } else { + inst = *anchor; + *anchor = inst->next; + free(inst); + } +} + + int instantiate_meas(int n_frames) { struct pkg *pkg; @@ -304,6 +320,7 @@ int instantiate_meas(int n_frames) inst_select_pkg(pkg->name); if (!instantiate_meas_pkg(n_frames)) return 0; + purge_meas(pkg); } return 1; }