inpcom.c: rewrite using new function find_lib()

This commit is contained in:
rlar 2013-02-09 19:51:49 +01:00
parent 97994080b4
commit 2c2a7d010b
1 changed files with 14 additions and 11 deletions

View File

@ -102,6 +102,17 @@ static void inp_poly_err(struct line *deck);
#endif #endif
static int
find_lib(char *s)
{
int i;
for (i = 0; i < num_libraries; i++)
if (cieq(library_file[i], s))
return i;
return -1;
}
static int static int
find_lib_name(int i, char *s) { find_lib_name(int i, char *s) {
int j; int j;
@ -400,7 +411,6 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name, bool c
/* library section reference: `.lib <library-file> <section-name>' */ /* library section reference: `.lib <library-file> <section-name>' */
char *copyy = NULL; char *copyy = NULL;
int i;
if (*y == '~') { if (*y == '~') {
copyy = cp_tildexpand(y); /* allocates memory, but can also return NULL */ copyy = cp_tildexpand(y); /* allocates memory, but can also return NULL */
@ -408,11 +418,7 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name, bool c
y = copyy; /* reuse y, but remember, buffer still points to allocated memory */ y = copyy; /* reuse y, but remember, buffer still points to allocated memory */
} }
for (i = 0; i < num_libraries; i++) if (find_lib(y) < 0) {
if (cieq(library_file[i], y))
break;
if (i >= num_libraries) {
bool dir_name_flag = FALSE; bool dir_name_flag = FALSE;
FILE *newfp = inp_pathopen(y, "r"); FILE *newfp = inp_pathopen(y, "r");
@ -2382,11 +2388,8 @@ inp_determine_libraries(struct line *deck, char *lib_name)
if (copys) if (copys)
s = copys; s = copys;
} }
for (i = 0; i < num_libraries; i++) i = find_lib(s);
if (cieq(library_file[i], s)) { if (i >= 0)
break;
}
if (i < num_libraries)
if (find_lib_name(i, y) < 0) { if (find_lib_name(i, y) < 0) {
new_lib_name(i, y, c); new_lib_name(i, y, c);
/* see if other libraries referenced */ /* see if other libraries referenced */