1 /*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
5 * Function:..Array-Handling-Functions *
7 * from LDAP3.2 University of Michigan *
9 * Patch: NULL-Pointers are caught in Arrays/Strings *
12 * Authors:...Dr. Kurt Spanier & Bernhard Winkler, *
13 * Zentrum fuer Datenverarbeitung, Bereich Entwicklung *
14 * neuer Dienste, Universitaet Tuebingen, GERMANY *
18 * Creation date: Z D D V V *
19 * April 16 1996 Z D D V V *
20 * Last modification: Z D D V V *
21 * December 21 1998 ZZZZ DDD V *
23 _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_*/
26 * $Id: charray.c,v 1.6 1999/09/10 15:01:16 zrnsk01 Exp $
31 #include "charray_exp.h"
32 #include "ch_malloc_exp.h"
34 /* charray.c - routines for dealing with char * arrays */
37 PUBLIC void charray_add( a, s )
47 *a = (char **) ch_malloc( 2 * sizeof(char *) );
50 for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) {
54 *a = (char **) ch_realloc( (char *) *a,
55 (n + 2) * sizeof(char *) );
58 (*a)[n++] = strdup(s);
61 /* end of function: charray_add */
63 PUBLIC void charray_merge( a, s )
72 for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) {
76 for ( nn = 0; s[nn] != NULL; nn++ ) {
80 *a = (char **) ch_realloc( (char *) *a, (n + nn + 1) * sizeof(char *) );
82 for ( i = 0; i < nn; i++ ) {
87 /* end of function: charray_merge */
89 PUBLIC void charray_free( array )
94 if ( array == NULL ) {
98 for ( a = array; *a != NULL; a++ ) {
103 free( (char *) array );
105 /* end of function: charray_free */
107 PUBLIC int charray_inlist( a, s )
113 if (( a == NULL ) || ( s == NULL ))
116 for ( i = 0; a[i] != NULL; i++ ) {
117 if ( strcasecmp( s, a[i] ) == 0 ) {
124 /* end of function: charray_inlist */
126 PUBLIC char ** charray_dup( a )
135 for ( i = 0; a[i] != NULL; i++ )
138 new = (char **) ch_malloc( (i + 1) * sizeof(char *) );
140 for ( i = 0; a[i] != NULL; i++ ) {
141 new[i] = strdup( a[i] );
147 /* end of function: charray_dup */
149 PUBLIC char ** str2charray( str, brkstr )
158 if (( str == NULL ) || ( brkstr == NULL )) return( (char **) NULL );
162 for ( s = str1; *s; s++ ) {
163 if ( strchr( brkstr, *s ) != NULL ) {
168 res = (char **) ch_malloc( (i + 1) * sizeof(char *) );
170 for ( s = strtok( str1, brkstr ); s != NULL; s = strtok( NULL,
172 res[i++] = strdup( s );
179 /* end of function: str2charray */