/*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 Lev Walkin . * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: sf_svect.h,v 1.4 2005/05/27 05:34:46 vlm Exp $ */ #ifndef __SF_SVECT_H__ #define __SF_SVECT_H__ #include #include #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /**********************/ /*** String vectors ***/ /**********************/ typedef struct { char **list; size_t count; size_t listlen; size_t maxlen; size_t *lens; } svect; /* Backward compatibility */ typedef svect slist; svect *sinit(void); /* Create empty structure */ void sclear(svect *); /* Clear elements of filled structure */ void sfree(svect *); /* Destroy entire object completely */ /* Add element to the end of list */ int sadd(svect *, const char *toadd); /* with strdup(toadd) */ int sadd2(svect *, const void *toadd, size_t len); /* With length. */ int sadd_attach(svect *, void *toadd, size_t len); /* Without strdup() */ /* Delete element */ int sdel(svect *, size_t idx); /* Delete specified element */ /* Insert element */ ssize_t sins(svect *, const char *, size_t idx); /* Insert element before idx */ /* Fetch element by index */ #define sget(sl, idx) ((sl)->list[(idx)]) /* * Split and join functions. */ /* Split functions, my aknowledgements to Larry Wall! */ svect *split(const char *what, const char *delim, int strict); /* creates new (svect *) */ int splitf(svect *sl, const char *what, const char *delim, int strict); int splitquotable(svect *, const char *); /* bash-like */ int split_network(const char *, unsigned int *ip, unsigned int *mask); int sf_iaton(const char *cp, unsigned int *pin); /* aka inet_aton */ /* Join function */ char *sjoin(svect *, const char *delimiter); /* Join values together */ /* * Search the list. */ /* Find element */ ssize_t sfind(svect *, const char *); /* Case-sensitive */ ssize_t scfind(svect *, const char *); /* Case-insensitive */ /* Find tofind in the a and display b's element with the same index */ char *sget2(svect *a, const char *tofind, svect *b); char *scget2(svect *, const char *, svect *); /* Case-insensitive */ /* * Manipulate the entire list. */ /* Add values from the char** */ int simport(svect *, char **vals); /* free()'s vals!!! */ /* Copy svect */ svect *scopy(svect *src); /* Make char ** from the list */ char **sarray(svect *, size_t startidx); /* leak-safe */ char **mkarray(svect *, size_t startidx); /* malloc()'ed "giveaway" */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __SF_SVECT_H__ */