diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-26 22:49:10 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-26 22:49:10 +0000 |
commit | f420965b8e48aff65f0c181cb36cbd9410e88b1b (patch) | |
tree | 2765cce0a55cdbdd1a94e016469bdf8d086728c6 /list.c | |
parent | 632e8a138dd16efe41384a4335ec46530da4a04b (diff) |
merge latest (4.3.99.16) from XFree86 (vendor) branch
Diffstat (limited to 'list.c')
-rw-r--r-- | list.c | 88 |
1 files changed, 81 insertions, 7 deletions
@@ -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; } } - |