src/gedlib/charmaps.c
/*===================================================
 * custom_sort -- Compare two strings with custom sort
 * returns FALSE if no custom sort table
 * otherwise sets *rtn correctly & returns TRUE
 * Created: 2001/07/21 (Perry Rapp)
 *=================================================*/
- Compare two strings with custom sort
returns FALSE if no custom sort table
otherwise sets *rtn correctly & returns TRUE
Created: 2001/07/21 (Perry Rapp)
- Compare two strings with custom sort returns FALSE if no custom sort table otherwise sets * rtn correctly & returns TRUE Created : 2001 / 07 / 21 ( Perry Rapp )
BOOLEAN
custom_sort (const char *str1, const char *str2, INT * rtn)
{
	TRANTABLE tts = transl_get_legacy_tt(MSORT);
	TRANTABLE ttc = transl_get_legacy_tt(MCHAR);
	CNSTRING rep1, rep2;
	CNSTRING ptr1=str1, ptr2=str2;
	INT len1, len2;
	if (!tts) return FALSE;
#if 0 
	if (ptr1[0] && ptr2[0]) {
		len1 = translate_match(ttp, ptr1, &rep1);
		len2 = translate_match(ttp, ptr2, &rep2);
		if (len1 || len2) {
		}
		if (strchr(rep1,"s") && ptr1[len1]) {
			ptr1 += len1;
			len1 = translate_match(tts, ptr1, &rep1);
		}
		if (strchr(rep2,"s") && ptr2[len2]) {
			ptr2 += len2;
			len2 = translate_match(tts, ptr2, &rep1);
		}
	}
#endif
	while (1) {
		if (!ptr1[0] || !ptr2[0]) {
			*rtn = ptr1[0] - ptr2[0];
			return TRUE;
		}
		len1 = translate_match(tts, ptr1, &rep1);
		len2 = translate_match(tts, ptr2, &rep2);
		if (len1 && len2) {
			*rtn = atoi(rep1) - atoi(rep2);
			if (*rtn) return TRUE;
			ptr1 += len1;
			ptr2 += len2;
		} else {
			*rtn = ptr1[0] - ptr2[0];
			if (*rtn) return TRUE;
			if (ttc) {
				len1 = translate_match(ttc, ptr1, &rep1);
				len2 = translate_match(ttc, ptr2, &rep2);
				if (len1 || len2) {
					*rtn = strncmp(ptr1, ptr2, len1>len2?len1:len2);
				}
			} else {
				len1 = len2 = 1;
				*rtn = ptr1[0] - ptr2[0];
			}
			if (*rtn) return TRUE;
			ptr1 += len1 ? len1 : 1;
			ptr2 += len2 ? len2 : 1;
		}
	}
}
BOOLEAN custom_sort ( const char * str1 , const char * str2 , INT * rtn ) { TRANTABLE tts = transl_get_legacy_tt ( MSORT ) ; TRANTABLE ttc = transl_get_legacy_tt ( MCHAR ) ; CNSTRING rep1 , rep2 ; CNSTRING ptr1 = str1 , ptr2 = str2 ; INT len1 , len2 ; if ( ! tts ) return FALSE ; #if 0 if ( ptr1 [ 0 ] && ptr2 [ 0 ] ) { len1 = translate_match ( ttp , ptr1 , & rep1 ) ; len2 = translate_match ( ttp , ptr2 , & rep2 ) ; if ( len1 || len2 ) { } if ( strchr ( rep1 , " " ) && ptr1 [ len1 ] ) { ptr1 += len1 ; len1 = translate_match ( tts , ptr1 , & rep1 ) ; } if ( strchr ( rep2 , " " ) && ptr2 [ len2 ] ) { ptr2 += len2 ; len2 = translate_match ( tts , ptr2 , & rep1 ) ; } } #endif while ( 1 ) { if ( ! ptr1 [ 0 ] || ! ptr2 [ 0 ] ) { * rtn = ptr1 [ 0 ] - ptr2 [ 0 ] ; return TRUE ; } len1 = translate_match ( tts , ptr1 , & rep1 ) ; len2 = translate_match ( tts , ptr2 , & rep2 ) ; if ( len1 && len2 ) { * rtn = atoi ( rep1 ) - atoi ( rep2 ) ; if ( * rtn ) return TRUE ; ptr1 += len1 ; ptr2 += len2 ; } else { * rtn = ptr1 [ 0 ] - ptr2 [ 0 ] ; if ( * rtn ) return TRUE ; if ( ttc ) { len1 = translate_match ( ttc , ptr1 , & rep1 ) ; len2 = translate_match ( ttc , ptr2 , & rep2 ) ; if ( len1 || len2 ) { * rtn = strncmp ( ptr1 , ptr2 , len1 > len2 ? len1 : len2 ) ; } } else { len1 = len2 = 1 ; * rtn = ptr1 [ 0 ] - ptr2 [ 0 ] ; } if ( * rtn ) return TRUE ; ptr1 += len1 ? len1 : 1 ; ptr2 += len2 ? len2 : 1 ; } } }
custom_sort -- Compare two strings with custom sort
 returns FALSE if no custom sort table
 otherwise sets *rtn correctly & returns TRUE
 Created: 2001/07/21 (Perry Rapp)
custom_sort -- Compare two strings with custom sort returns FALSE if no custom sort table otherwise sets * rtn correctly & returns TRUE Created : 2001 / 07 / 21 ( Perry Rapp )
/* This was an attempt at handling skip-over prefixes (eg, Mc) */ /* must be done earlier */ /* check for prefix skips */ /* main loop thru both strings looking for differences */ /* stop when exhaust either string */ /* only zero if both end simultaneously */ /* look up in sort table */ /* compare sort table results */ /* at least one not in sort table */ /* try comparing single chars */ /* use charset to see how wide they are */ /* compare to width of wider char */ /* TO DO - can we use locale here ? ie, locale + custom sort */ /* advance both by at least one */