+
+void oidm_unparse( BerVarray *res )
+{
+ OidMacro *om;
+ int i, j, num;
+ struct berval bv, *bva = NULL, idx;
+ char ibuf[32], *ptr;
+
+ /* count the result size */
+ i = 0;
+ LDAP_SLIST_FOREACH( om, &om_list, som_next ) {
+ for ( j=0; !BER_BVISNULL(&om->som_names[j]); j++ );
+ i += j;
+ }
+ num = i;
+ bva = ch_malloc( (num+1) * sizeof(struct berval) );
+ BER_BVZERO( bva+num );
+ idx.bv_val = ibuf;
+ LDAP_SLIST_FOREACH( om, &om_list, som_next ) {
+ for ( j=0; !BER_BVISNULL(&om->som_names[j]); j++ );
+ for ( i=num-j, j=0; i<num; i++,j++ ) {
+ idx.bv_len = sprintf(idx.bv_val, "{%d}", i );
+ bva[i].bv_len = idx.bv_len + om->som_names[j].bv_len +
+ om->som_subs[j].bv_len + 1;
+ bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
+ ptr = lutil_strcopy( bva[i].bv_val, ibuf );
+ ptr = lutil_strcopy( ptr, om->som_names[j].bv_val );
+ *ptr++ = ' ';
+ ptr = lutil_strcopy( ptr, om->som_subs[j].bv_val );
+ }
+ num -= j;
+ }
+ *res = bva;
+}