+ int i;
+
+ if( opt[optlen-1] == '-' ) {
+ desc.ad_flags |= SLAP_DESC_LANG_RANGE;
+ }
+
+ if( nlang >= MAX_LANG_OPTIONS ) {
+ *text = "too many language options";
+ return rtn;
+ }
+
+ /*
+ * tags should be presented in sorted order,
+ * so run the array in reverse.
+ */
+ for( i=nlang-1; i>=0; i-- ) {
+ int rc;
+
+ rc = strncasecmp( opt, langs[i].bv_val,
+ (unsigned) optlen < langs[i].bv_len
+ ? optlen : langs[i].bv_len );
+
+ if( rc == 0 && (unsigned)optlen == langs[i].bv_len ) {
+ /* duplicate (ignore) */
+ goto done;
+
+ } else if ( rc > 0 ||
+ ( rc == 0 && (unsigned)optlen > langs[i].bv_len ))
+ {
+ AC_MEMCPY( &langs[i+1], &langs[i],
+ (nlang-i)*sizeof(struct berval) );
+ langs[i].bv_val = opt;
+ langs[i].bv_len = optlen;
+ goto done;
+ }