1 /* attr.c - backend routines for dealing with attributes */
11 #include "back-ldbm.h"
19 return( strcasecmp( type, a->ai_type ) );
28 return( strcasecmp( a->ai_type, b->ai_type ) );
32 * Called when a duplicate "index" line is encountered.
34 * returns 1 => original from init code, indexmask updated
35 * 2 => original not from init code, warn the user
45 * if the duplicate definition is because we initialized the attr,
46 * just add what came from the config file. otherwise, complain.
48 if ( a->ai_indexmask & INDEX_FROMINIT ) {
49 a->ai_indexmask |= b->ai_indexmask;
69 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
70 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
71 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
72 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
76 *indexmask = a->ai_indexmask;
77 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
78 *syntaxmask = attr_syntax( type );
80 *syntaxmask = a->ai_syntaxmask;
95 char **attrs, **indexes;
98 attrs = str2charray( argv[0], "," );
100 indexes = str2charray( argv[1], "," );
102 for ( i = 0; attrs[i] != NULL; i++ ) {
103 a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
104 a->ai_type = ch_strdup( attrs[i] );
105 a->ai_syntaxmask = attr_syntax( a->ai_type );
107 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
108 INDEX_APPROX | INDEX_SUB);
111 for ( j = 0; indexes[j] != NULL; j++ ) {
112 if ( strncasecmp( indexes[j], "pres", 4 )
114 a->ai_indexmask |= INDEX_PRESENCE;
115 } else if ( strncasecmp( indexes[j], "eq", 2 )
117 a->ai_indexmask |= INDEX_EQUALITY;
118 } else if ( strncasecmp( indexes[j], "approx",
120 a->ai_indexmask |= INDEX_APPROX;
121 } else if ( strncasecmp( indexes[j], "sub", 3 )
123 a->ai_indexmask |= INDEX_SUB;
124 } else if ( strncasecmp( indexes[j], "none", 4 )
126 if ( a->ai_indexmask != 0 ) {
128 "%s: line %d: index type \"none\" cannot be combined with other types\n",
134 "%s: line %d: unknown index type \"%s\" (ignored)\n",
135 fname, lineno, indexes[j] );
137 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
142 a->ai_indexmask |= INDEX_FROMINIT;
145 switch (avl_insert( &li->li_attrs, (caddr_t) a,
146 (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
148 case 1: /* duplicate - updating init version */
153 case 2: /* user duplicate - ignore and warn */
155 "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
156 fname, lineno, a->ai_type );
161 default:; /* inserted ok */
165 charray_free( attrs );
167 charray_free( indexes );