Newsgroups: fj.unix
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!etlnews.etl.go.jp!etlinn.etl.go.jp!etl.go.jp!trc.rwcp!rwc-tyo!news.iij.ad.jp!jmasgw!nowhere!hoj
From: hoj@sysplan.co.jp (Masaaki Hojo)
Subject: Re: =?ISO-2022-JP?B?GyRCNEE7eiROGyhC?= SORT
 =?ISO-2022-JP?B?GyRAGyRCJEskRCQkJEYbKEI=?=
Message-ID: <1996Jan19.064120.13967@sysplan.co.jp>
Sender: news@sysplan.co.jp (Usenet News System)
Nntp-Posting-Host: sp01
Organization: sysplan Inc.
X-Newsreader: mnews [version 1.19] 1995-07/21(Fri)
References: <4dhrcc$69n@UINTER.uis-inf.co.jp>
	<sxn37njlsv.fsf_-_@xavier.tt.kubota.co.jp>
	<1996Jan18.015617.10748@sysplan.co.jp>
	<4dl6n2$l6c@ns.src.ricoh.co.jp>
Date: Fri, 19 Jan 1996 06:41:20 GMT
Lines: 128
Xref: galaxy.trc.rwcp.or.jp fj.unix:5307
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.unix&nb=5307&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.


$B$8$c!";d$bCQ$:$+$7$J$,$i(B
1byte$B7OJ8;z(B($B%+%J$b4^$`(B)$B$N<-=q=gHf3S4X?t$G$9!#(B

-------------------------------------------------------------------------------------
#include<stdio.h>

typedefunsigned charCHAR;

#defineEQ0
#defineGT1
#defineLS(-1)

/*
 *
 */
static CHAR
ktok( ch )
    CHAR    *ch;
{
    CHAR    x;

    if( *ch < 0xa6 ) {/* $B1Q?t5-9f(B */
if( *ch >= 'A' && *ch <= 'Z' ) return( *ch + 0x20 );/*$BBg"*>.J8;z(B */
if( *ch >= 'a' && *ch <= 'z' ) return( *ch );
if( *ch >= '0' && *ch <= '9' ) return( *ch );
return( 0x20 );/* $B5-9f$O(B SPACE$B07$$(B */
    } else {/* $B%+%J(B */
if( *ch == 0xa6 ) return( 0xb5 );/* $B$r(B $B"*(B $B$*(B */
if( *ch >= 0xa7 && *ch <= 0xab )/* $B$!$#$%$'$)(B  */
    return( *ch - 0xa7 + 0xb1 );/* $B"*(B $B$"$$$&$($*(B */
if( *ch >= 0xac && *ch <= 0xae )/* $B$c$e$g(B */
    return( *ch - 0xac + 0xd4 );/* $B"*!!$d$f$h(B */
if( *ch == 0xaf ) return( 0xc2 );/* $B$C(B $B"*!!$D(B */
if( *ch == 0xb0 ) {/* $BD92;5-9f(B */
    x = ch[-1];/* $BD92;$N(B1$BJ8;zA0(B */
    if( x == 0xde || x == 0xdf ) x = ch[-2];/* $BBy!&H>ByE@$O$b$&(B1$BJ8;zA0(B */
    if( x < 0xa7 || x == 0xb0 || x == 0xaf || x > 0xdc )
return( 0x20 );/* $BJQ$J0LCV$ND92;(B */
    if( x >= 0xa7 && x <= 0xab ) x = x - 0xa7 + 0xb1;
    if( x >= 0xac && x <= 0xae ) x = x - 0xac + 0xd4;
    if( x <= 0xd4 )/* $B0J9_Jl2;$r5a$a$k(B */
return( ( x - 0xb1 ) % 5 + 0xb1 );
    if( x == 0xd5 ) return( 0xb3 );
    return( ( x - 0xd2 ) % 5 + 0xb1 );
}
return( *ch );/* $BIaDL$N%+%J(B */
    }
}

/*
 *
 */
static int
knasub( x, y )
    CHAR    *x, *y;
{
    CHAR    xx, yy;

    if( ( xx = ktok( x ) ) == ( yy = ktok( y ) ) ) return( EQ );
    return( xx > yy ? GT: LS );
}

/*
 * $B$3$l$,Hf3S4X?t(B
 *xs $B$H(B ys $B$rHf3S$7(B
 *xs > ys $B$J$i(B $B@5(B (GT)
 *xs = ys $B$J$i(B 0  (EQ)
 *xs < ys $B$J$i(B $BIi(B (LT)
 *$B$r!"JV$7$^$9!#(B
 */
cmpkn( xs, ys )
    CHAR    *xs, *ys;
{
    intwk1, wk2;

    wk1 = EQ;
    for( ; ; xs++, ys++ ) {
if( *xs == 0 ) return( (*ys == NULL)?  wk1 : LS );
if( *ys == 0 ) return( (*xs == NULL)?  wk1 : GT );
if( *xs == *ys ) {
    if( *xs == NULL ) return( wk1 );
} else if( *xs > *ys ) {
    if( wk1 == EQ ) wk1 = GT;
    if( *xs >= 0xde ) {
--ys;
    } else {
if( *ys > 0xb0 ) return( GT );
if( ( wk2 = knasub( xs, ys ) ) != EQ ) return( wk2 );
    }
} else    {
    if( wk1 == EQ ) wk1 = LS;
    if( *ys >= 0xde ) {
--xs;
    } else {
if( *xs > 0xb0 ) return( LS );
if( ( wk2 = knasub( xs, ys ) ) != EQ ) return( wk2 );
    }
}
    }
}

#if KANA_DEBUG
main()
{
charx[100], y[100], dmy[100];
intcmplen;
intans;

for(;;) {
printf( "Enter Kana(1) : " );
gets( x );
if( *x == 0 ) break;
printf( "Enter Kana(2) : " );
gets( y );
ans = cmpkn( x, y );
if( ans == EQ )printf( "---> (1) EQ (2)\n" );
else if( ans == GT )printf( "---> (1) GT (2)\n" );
elseprintf( "---> (1) LS (2)\n" );
}
exit( 0 );
}
#endif
-------------------------------------------------------------------------------------
--
 $B!?!?(B)
($B!?!?(B  $BKL[j@582!J$[$&$8$g$&$^$5$"$-!K(B
$B!|!C(B     hoj@sysplan.co.jp
