1 /******************************************************************************
3 * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
6 * Permission is granted to anyone to use this software for any purpose
7 * on any computer system, and to alter it and redistribute it, subject
8 * to the following restrictions:
10 * 1. The author is not responsible for the consequences of use of this
11 * software, no matter how awful, even if they arise from flaws in it.
13 * 2. The origin of this software must not be misrepresented, either by
14 * explicit claim or by omission. Since few users ever read sources,
15 * credits should appear in the documentation.
17 * 3. Altered versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software. Since few users
19 * ever read sources, credits should appear in the documentation.
21 * 4. This notice may not be removed or altered.
23 ******************************************************************************/
27 #include <ac/string.h>
29 #include "rewrite-int.h"
40 const struct rewrite_var *v1, *v2;
42 v1 = ( struct rewrite_var * )c1;
43 v2 = ( struct rewrite_var * )c2;
47 assert( v1->lv_name != NULL );
48 assert( v2->lv_name != NULL );
50 return strcasecmp( v1->lv_name, v2->lv_name );
62 struct rewrite_var *v1, *v2;
64 v1 = ( struct rewrite_var * )c1;
65 v2 = ( struct rewrite_var * )c2;
69 assert( v1->lv_name != NULL );
70 assert( v2->lv_name != NULL );
72 return ( strcasecmp( v1->lv_name, v2->lv_name ) == 0 ? -1 : 0 );
84 struct rewrite_var var;
86 assert( name != NULL );
88 var.lv_name = ( char * )name;
89 return ( struct rewrite_var * )avl_find( tree,
90 ( caddr_t )&var, rewrite_var_cmp );
94 * Inserts a newly created var
103 struct rewrite_var *var;
106 assert( tree != NULL );
107 assert( name != NULL );
108 assert( value != NULL );
110 var = calloc( sizeof( struct rewrite_var ), 1 );
114 var->lv_name = ( char * )strdup( name );
115 if ( var->lv_name == NULL ) {
119 var->lv_value.bv_val = strdup( value );
120 if ( var->lv_value.bv_val == NULL ) {
122 free( var->lv_name );
125 var->lv_value.bv_len = strlen( value );
126 rc = avl_insert( tree, ( caddr_t )var,
127 rewrite_var_cmp, rewrite_var_dup );
130 free( var->lv_name );
131 free( var->lv_value.bv_val );
149 struct rewrite_var *var;
151 assert( tree != NULL );
152 assert( name != NULL );
153 assert( value != NULL );
155 var = rewrite_var_find( *tree, name );
158 return rewrite_var_insert( tree, name, value );
163 assert( var->lv_value.bv_val != NULL );
165 free( var->lv_value.bv_val );
166 var->lv_value.bv_val = ( char * )value;
167 var->lv_value.bv_len = strlen( value );
178 struct rewrite_var *var
181 assert( var != NULL );
183 assert( var->lv_name != NULL );
184 assert( var->lv_value.bv_val != NULL );
186 free( var->lv_name );
187 free( var->lv_value.bv_val );
198 avl_free( tree, ( AVL_FREE )rewrite_var_free );
199 return REWRITE_SUCCESS;