aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/lists.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-15 21:09:44 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-15 21:09:44 +0100
commitc026706ca5560f2923011952d636fbbda0c37206 (patch)
tree3aed01590a9b355dfd3490dc4cdb97606cf233bb /FICS/lists.c
parent03003b46667be73b1cc5388d57d83ff0e6157748 (diff)
Reformatted list_find()
Diffstat (limited to 'FICS/lists.c')
-rw-r--r--FICS/lists.c107
1 files changed, 56 insertions, 51 deletions
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;
}
/*