summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'list.c')
-rw-r--r--list.c88
1 files changed, 81 insertions, 7 deletions
diff --git a/list.c b/list.c
index da66d99..ff33a0e 100644
--- a/list.c
+++ b/list.c
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2002 by Juliusz Chroboczek
+ Copyright (c) 2002-2003 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -19,11 +19,12 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* $XFree86: xc/programs/mkfontscale/list.c,v 1.3 2002/12/14 04:41:12 dawes Exp $ */
+/* $XFree86: xc/programs/mkfontscale/list.c,v 1.6 2003/07/08 15:39:49 tsi Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
+#include <string.h>
#include "list.h"
#ifdef NEED_SNPRINTF
@@ -32,6 +33,17 @@
#include "snprintf.c"
#endif
+int
+listMember(char *elt, ListPtr list)
+{
+ while(list != NULL) {
+ if(strcmp(elt, list->value) == 0)
+ return 1;
+ list = list->next;
+ }
+ return 0;
+}
+
ListPtr
listCons(char *car, ListPtr cdr)
{
@@ -44,6 +56,44 @@ listCons(char *car, ListPtr cdr)
}
ListPtr
+listAdjoin(char *car, ListPtr cdr)
+{
+ if(listMember(car, cdr)) {
+ free(car);
+ return cdr;
+ }
+ return listCons(car, cdr);
+}
+
+char *
+dsprintf(char *f, ...)
+{
+ va_list args;
+ char *string;
+ {
+ int n, size = 20;
+ while(1) {
+ if(size > 4096)
+ return NULL;
+ string = malloc(size);
+ if(!string)
+ return NULL;
+ va_start(args, f);
+ n = vsnprintf(string, size, f, args);
+ va_end(args);
+ if(n >= 0 && n < size)
+ return string;
+ else if(n >= size)
+ size = n + 1;
+ else
+ size = size * 3 / 2 + 1;
+ free(string);
+ }
+ }
+}
+
+
+ListPtr
listConsF(ListPtr cdr, char *f, ...)
{
va_list args;
@@ -70,6 +120,33 @@ listConsF(ListPtr cdr, char *f, ...)
}
}
+ListPtr
+listAdjoinF(ListPtr cdr, char *f, ...)
+{
+ va_list args;
+ char *string;
+ {
+ int n, size = 20;
+ while(1) {
+ if(size > 4096)
+ return NULL;
+ string = malloc(size);
+ if(!string)
+ return NULL;
+ va_start(args, f);
+ n = vsnprintf(string, size, f, args);
+ va_end(args);
+ if(n >= 0 && n < size)
+ return listAdjoin(string, cdr);
+ else if(n >= size)
+ size = n + 1;
+ else
+ size = size * 3 / 2 + 1;
+ free(string);
+ }
+ }
+}
+
int
listLength(ListPtr list)
{
@@ -153,11 +230,10 @@ destroyList(ListPtr old)
ListPtr next;
if(!old)
return;
- next = old->next;
while(old) {
+ next = old->next;
free(old);
old = next;
- next = old->next;
}
}
@@ -167,12 +243,10 @@ deepDestroyList(ListPtr old)
ListPtr next;
if(!old)
return;
- next = old->next;
while(old) {
+ next = old->next;
free(old->value);
free(old);
old = next;
- next = old->next;
}
}
-