inp.c, cleanup using new function `line_nconc()'

This commit is contained in:
rlar 2016-08-31 20:01:56 +02:00
parent c28c5d307a
commit b302dbe975
2 changed files with 18 additions and 14 deletions

View File

@ -293,6 +293,22 @@ line_free_x(struct line *deck, bool recurse)
}
/* concatenate two lists, destructively altering the first one */
struct line *
line_nconc(struct line *head, struct line *rest)
{
struct line *p = head;
if (!rest)
return head;
if (!head)
return rest;
while (p->li_next)
p = p->li_next;
p->li_next = rest;
return head;
}
/* reverse the linked list struct line */
struct line *
line_reverse(struct line *head)
@ -610,20 +626,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
options (comfile == FALSE, filled in from circuit with .OPTIONS)
into options, thus keeping com_options,
options is loaded into circuit and freed when circuit is removed */
if (!options && com_options)
options = inp_deckcopy(com_options);
else if (options && com_options) {
/* add a copy from com_options to end of options */
struct line *new_options = options;
while (options) {
if (!options->li_next)
break;
options = options->li_next;
}
options->li_next = inp_deckcopy(com_options);
options = new_options;
}
options = line_reverse(options);
options = line_reverse(line_nconc(options, inp_deckcopy(com_options)));
/* prepare parse trees from 'temper' expressions */
if (expr_w_temper)

View File

@ -214,6 +214,7 @@ extern void inp_list(FILE *file, struct line *deck, struct line *extras, int typ
extern struct line *inp_readall(FILE *fp, char *dir_name, bool comfile, bool intfile);
extern FILE *inp_pathopen(char *name, char *mode);
extern char *search_identifier(char *str, const char *identifier, char *str_begin);
extern struct line *line_nconc(struct line *head, struct line *rest);
extern struct line *line_reverse(struct line *head);
extern char** circarray;