expose DrawLine and BlitRect stubs. remove unwanted spaces and fix indentation of...
[AROS.git] / tools / genmodule / stringlist.c
blob4e8a2238434d72fc377af38209869d57822d7ba7
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Code to handle list of strings
6 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "stringlist.h"
13 struct stringlist *slist_append(struct stringlist **list, const char *s)
15 struct stringlist **listit = list;
16 struct stringlist *node = malloc(sizeof(struct stringlist));
18 if (node == NULL)
20 fprintf(stderr, "Out of memory!\n");
21 exit(20);
24 while (*listit != NULL) listit = &(*listit)->next;
26 *listit = node;
27 node->next = NULL;
28 node->s = strdup(s);
29 if (node->s == NULL)
31 fprintf(stderr, "Out of memory!\n");
32 exit(20);
35 return node;
38 struct stringlist *slist_prepend(struct stringlist **list, const char *s)
40 struct stringlist **listit = list;
41 struct stringlist *node = malloc(sizeof(struct stringlist));
43 if (node == NULL)
45 fprintf(stderr, "Out of memory!\n");
46 exit(20);
49 node->next = *listit;
50 node->s = strdup(s);
51 if (node->s == NULL)
53 fprintf(stderr, "Out of memory!\n");
54 exit(20);
56 *listit = node;
58 return node;
61 int slist_remove(struct stringlist **list, struct stringlist *node)
63 struct stringlist **listit = list;
65 while(*listit != NULL && *listit != node) listit = &(*listit)->next;
67 if (*listit == node)
69 *listit = (*listit)->next;
70 free(node->s);
71 free(node);
72 return 1;
74 else
75 return 0;
78 int slist_length(struct stringlist *slist)
80 int i;
82 for (i=0; slist; i++, slist=slist->next);
84 return i;