+#endif
+
+void
+at_unparse( BerVarray *res, AttributeType *start, AttributeType *end, int sys )
+{
+ AttributeType *at;
+ int i, num;
+ struct berval bv, *bva = NULL, idx;
+ char ibuf[32];
+
+ if ( !start )
+ start = LDAP_STAILQ_FIRST( &attr_list );
+
+ /* count the result size */
+ i = 0;
+ for ( at=start; at; at=LDAP_STAILQ_NEXT(at, sat_next)) {
+ if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
+ i++;
+ if ( at == end ) break;
+ }
+ if (!i) return;
+
+ num = i;
+ bva = ch_malloc( (num+1) * sizeof(struct berval) );
+ BER_BVZERO( bva );
+ idx.bv_val = ibuf;
+ if ( sys ) {
+ idx.bv_len = 0;
+ ibuf[0] = '\0';
+ }
+ i = 0;
+ for ( at=start; at; at=LDAP_STAILQ_NEXT(at, sat_next)) {
+ LDAPAttributeType lat, *latp;
+ if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
+ if ( at->sat_oidmacro ) {
+ lat = at->sat_atype;
+ lat.at_oid = at->sat_oidmacro;
+ latp = ⪫
+ } else {
+ latp = &at->sat_atype;
+ }
+ if ( ldap_attributetype2bv( latp, &bv ) == NULL ) {
+ ber_bvarray_free( bva );
+ }
+ if ( !sys ) {
+ idx.bv_len = sprintf(idx.bv_val, "{%d}", i);
+ }
+ bva[i].bv_len = idx.bv_len + bv.bv_len;
+ bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
+ strcpy( bva[i].bv_val, ibuf );
+ strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
+ i++;
+ bva[i].bv_val = NULL;
+ ldap_memfree( bv.bv_val );
+ if ( at == end ) break;
+ }
+ *res = bva;
+}