1 /* attr.c - backend routines for dealing with attributes */
11 #include "back-ldbm.h"
13 extern char **str2charray();
21 return( strcasecmp( type, a->ai_type ) );
30 return( strcasecmp( a->ai_type, b->ai_type ) );
34 * Called when a duplicate "index" line is encountered.
36 * returns 1 => original from init code, indexmask updated
37 * 2 => original not from init code, warn the user
47 * if the duplicate definition is because we initialized the attr,
48 * just add what came from the config file. otherwise, complain.
50 if ( a->ai_indexmask & INDEX_FROMINIT ) {
51 a->ai_indexmask |= b->ai_indexmask;
71 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
72 ainfo_type_cmp )) == NULL ) {
73 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
74 ainfo_type_cmp )) == NULL ) {
78 *indexmask = a->ai_indexmask;
79 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
80 *syntaxmask = attr_syntax( type );
82 *syntaxmask = a->ai_syntaxmask;
97 char **attrs, **indexes;
100 attrs = str2charray( argv[0], "," );
102 indexes = str2charray( argv[1], "," );
104 for ( i = 0; attrs[i] != NULL; i++ ) {
105 a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
106 a->ai_type = strdup( attrs[i] );
107 a->ai_syntaxmask = attr_syntax( a->ai_type );
109 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
110 INDEX_APPROX | INDEX_SUB);
113 for ( j = 0; indexes[j] != NULL; j++ ) {
114 if ( strncasecmp( indexes[j], "pres", 4 )
116 a->ai_indexmask |= INDEX_PRESENCE;
117 } else if ( strncasecmp( indexes[j], "eq", 2 )
119 a->ai_indexmask |= INDEX_EQUALITY;
120 } else if ( strncasecmp( indexes[j], "approx",
122 a->ai_indexmask |= INDEX_APPROX;
123 } else if ( strncasecmp( indexes[j], "sub", 3 )
125 a->ai_indexmask |= INDEX_SUB;
126 } else if ( strncasecmp( indexes[j], "none", 4 )
128 if ( a->ai_indexmask != 0 ) {
130 "%s: line %d: index type \"none\" cannot be combined with other types\n",
136 "%s: line %d: unknown index type \"%s\" (ignored)\n",
137 fname, lineno, indexes[j] );
139 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
144 a->ai_indexmask |= INDEX_FROMINIT;
147 switch (avl_insert( &li->li_attrs, (caddr_t) a, ainfo_cmp, 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 );