From 750b42e7670cb4e19f6051d663ccc8031bdb4e16 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 14 Sep 2013 10:18:40 +0200 Subject: [PATCH] inpcom.c: add fcn delete_libs to free libraries[] --- src/frontend/inpcom.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 2ba961b35..24c17b188 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -261,6 +261,7 @@ read_a_lib(char *y, int call_depth, char *dir_name) dir_name_flag = TRUE; } + /* lib points to a new entry in global lib array libraries[N_LIBRARIES] */ lib = new_lib(); lib->name = strdup(y); @@ -281,6 +282,24 @@ read_a_lib(char *y, int call_depth, char *dir_name) return TRUE; } +/* remove all library entries from global libraries[] */ +static void +delete_libs(void) +{ + int i; + struct line *tmpdeck, *tmpdeck2; + for (i = 0; i < N_LIBRARIES; i++) { + if (libraries[i].name == NULL) + continue; + tfree(libraries[i].name); + tmpdeck = libraries[i].deck; + while (tmpdeck) { /* cannot use line_free_x(tmpdeck, TRUE); due to stack overflow */ + tmpdeck2 = tmpdeck; + tmpdeck = tmpdeck->li_next; + line_free_x(tmpdeck2, FALSE); + } + } +} static struct names * new_names(void) @@ -554,8 +573,9 @@ inp_readall(FILE *fp, int call_depth, char *dir_name, bool comfile, bool intfile *buffer = '*'; /* change .TITLE line to comment line */ } - /* now handle .lib statements */ - if (ciprefix(".lib", buffer)) { + /* now handle old style .lib entries */ + /* new style .lib entries handling is in expand_section_references() */ + if (ciprefix(".lib", buffer)) if (inp_compat_mode == COMPATMODE_PS) { /* compatibility mode, * this is neither a libray section definition nor a reference @@ -567,8 +587,6 @@ inp_readall(FILE *fp, int call_depth, char *dir_name, bool comfile, bool intfile memcpy(buffer, ".inc", 4); } - } /* end of .lib handling */ - /* now handle .include statements */ if (ciprefix(".include", buffer) || ciprefix(".inc", buffer)) { @@ -680,10 +698,11 @@ inp_readall(FILE *fp, int call_depth, char *dir_name, bool comfile, bool intfile !ciprefix("load", buffer) ) { + /* lower case for all lines (exceptions see above!) */ for (s = buffer; *s && (*s != '\n'); s++) *s = (char) tolower(*s); } else { - // exclude some commands to preserve filename case + /* exclude some commands to preserve filename case */ for (s = buffer; *s && (*s != '\n'); s++) ; } @@ -2516,6 +2535,7 @@ expand_section_references(struct line *c, int call_depth, char *dir_name) } } + delete_libs(); }