From c026706ca5560f2923011952d636fbbda0c37206 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Fri, 15 Dec 2023 21:09:44 +0100 Subject: Reformatted list_find() --- FICS/lists.c | 107 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 51 deletions(-) (limited to 'FICS') diff --git a/FICS/lists.c b/FICS/lists.c index cb1685f..2671d1d 100644 --- a/FICS/lists.c +++ b/FICS/lists.c @@ -1,6 +1,7 @@ /* lists.c -- new global lists code * * Added by Shaney, 29 May 1995. + * Revised by maxxe, 15 Dec 2023. * This file is part of FICS. */ @@ -45,58 +46,62 @@ PRIVATE ListTable ListArray[] = { {0, NULL}, }; -/* find a list. loads from disk if not in memory. */ -PRIVATE List *list_find(int p, enum ListWhich l) +/* + * find a list. + * loads from disk if not in memory. + */ +PRIVATE List * +list_find(int p, enum ListWhich l) { - List *prev, *tempList, **starter; - int personal; - int count = 0; - - personal = ListArray[l].rights == P_PERSONAL; - starter = personal ? &(parray[p].lists) : &firstGlobalList; - - for (prev = NULL, tempList = *starter; tempList != NULL; tempList = tempList->next) { - if (l == tempList->which) { - if (prev != NULL) { - prev->next = tempList->next; - tempList->next = *starter; - *starter = tempList; - } - return tempList; - } - prev = tempList; - } - - tempList = rmalloc(sizeof(List)); - if (tempList == NULL) - return NULL; - - if (!personal) { /* now we have to load the list */ - FILE *fp; - char listmember[100]; - char filename[MAX_FILENAME_SIZE]; - - /* fprintf(stderr,"SHANEDEBUG: Adding %s list\n", ListArray[l].name); */ - - sprintf(filename, "%s/%s", lists_dir, ListArray[l].name); - fp = fopen(filename, "r"); - if (!fp) { - rfree(tempList); - return NULL; - } - while (!feof(fp)) { - if (fgets(listmember, 100, fp) != NULL) { - listmember[strlen(listmember) - 1] = '\0'; - tempList->member[count++] = xstrdup(listmember); - } - } - fclose(fp); - } - tempList->which = l; - tempList->numMembers = count; - tempList->next = *starter; - *starter = tempList; - return tempList; + List *prev = NULL, *tempList, **starter; + int count = 0; + int personal; + + personal = ListArray[l].rights == P_PERSONAL; + starter = (personal ? &parray[p].lists : &firstGlobalList); + + for (tempList = *starter; tempList != NULL; tempList = tempList->next) { + if (l == tempList->which) { + if (prev != NULL) { + prev->next = tempList->next; + tempList->next = *starter; + *starter = tempList; + } + + return tempList; + } + + prev = tempList; + } + + if ((tempList = rmalloc(sizeof(List))) == NULL) + return NULL; + if (!personal) { // now we have to load the list + FILE *fp; + char filename[MAX_FILENAME_SIZE]; + char listmember[100]; + + sprintf(filename, "%s/%s", lists_dir, ListArray[l].name); + + if ((fp = fopen(filename, "r")) == NULL) { + rfree(tempList); + return NULL; + } + while (!feof(fp)) { + if (fgets(listmember, 100, fp) != NULL) { + listmember[strlen(listmember) - 1] = '\0'; + tempList->member[count++] = xstrdup(listmember); + } + } + + fclose(fp); + } + + tempList->which = l; + tempList->numMembers = count; + tempList->next = *starter; + *starter = tempList; + return tempList; } /* -- cgit v1.2.3