Commit 62063462 authored by Bernhard Link's avatar Bernhard Link

added strlist.{c,h}

parent 35631c72
......@@ -3,9 +3,9 @@ bin_PROGRAMS = mirrorer
CPPFLAGS = @CPPFLAGS@ -D_GNU_SOURCE=1 -DPKGDATADIR=\"$(pkgdatadir)\" -Wall
mirrorer_SOURCES = main.c files.c md5.c md5sum.c dirs.c chunks.c reference.c packages.c binaries.c sources.c names.c dpkgversions.c release.c mprintf.c download.c updates.c
mirrorer_SOURCES = main.c files.c md5.c md5sum.c dirs.c chunks.c reference.c packages.c binaries.c sources.c names.c dpkgversions.c release.c mprintf.c download.c updates.c strlist.c
mirrorer_LDFLAGS += -ldb3
noinst_HEADERS = md5.h md5sum.h dirs.h files.h chunks.h reference.h packages.h binaries.h sources.h names.h release.h error.h mprintf.h download.h updates.h
noinst_HEADERS = md5.h md5sum.h dirs.h files.h chunks.h reference.h packages.h binaries.h sources.h names.h release.h error.h mprintf.h download.h updates.h strlist.h
MAINTAINERCLEANFILES = Makefile.in configure install-sh stamp-h.in aclocal.m4 config.h.in mkinstalldirs
/* This file is part of "mirrorer" (TODO: find better title)
* Copyright (C) 2003 Bernhard R. Link
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <config.h>
#include <errno.h>
#include <assert.h>
#include <malloc.h>
#include "error.h"
#include "strlist.h"
retvalue strlist_in(const struct strlist *strlist,const char *element) {
int c;
char **t;
assert(strlist != NULL);
c = strlist->count;
t = strlist->values;
while( c-- ) {
if( strcmp(*(t++),element) == 0 )
return RET_OK;
}
return RET_NOTHING;
}
retvalue strlist_new(struct strlist *strlist) {
assert(strlist != NULL);
strlist->count = 0;
strlist->size = 0;
strlist->values = NULL;
return RET_OK;
}
void strlist_free(struct strlist *strlist) {
int c;
char **t;
assert(strlist != NULL);
c = strlist->count;
t = strlist->values;
while( c-- ) {
if( *t )
free(*t);
t++;
}
free(strlist->values);
strlist->values = NULL;
}
retvalue strlist_add(struct strlist *strlist, char *element) {
char **v;
assert(strlist != NULL);
if( strlist->count >= strlist->size ) {
strlist->size += 8;
v = realloc(strlist->values, strlist->size*sizeof(char *));
if( !v ) {
free(element);
return RET_ERROR_OOM;
}
strlist->values = v;
}
strlist->values[strlist->count++] = element;
return RET_OK;
}
#ifndef __MIRRORER_STRLIST_H
#define __MIRRORER_STRLIST_H
#ifndef __MIRRORER_ERROR_H
#include "error.h"
#warning "What's hapening here?"
#endif
struct strlist {
char **values;
int count,size;
};
retvalue strlist_new(struct strlist *strlist);
void strlist_free(struct strlist *strlist);
/* add a string, will get property of the strlist and free'd by it */
retvalue strlist_add(struct strlist *strlist,char *element);
retvalue strlist_in(const struct strlist *strlist,const char *element);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment