From 324cfb1744c2c3cc253dd0f63c2252206eb72249 Mon Sep 17 00:00:00 2001 From: Kaleb Keithley Date: Tue, 25 Nov 2003 19:29:02 +0000 Subject: XFree86 4.3.99.16 Bring the tree up to date for the Cygwin folks --- list.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 7 deletions(-) (limited to 'list.c') 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 #include #include +#include #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) { @@ -43,6 +55,44 @@ listCons(char *car, ListPtr cdr) return lcar; } +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, ...) { @@ -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; } } - -- cgit v1.2.3