;*************************************************************************
; ○文字列行をソートする
; sortline p1,p2
; p1:文字列変数
; p2:ソート順(0=昇順 1=降順)
; 改行コードで区切られた文字列を1バイトずつ文字コードの大小を比較してソートします
; 改行コードはCR+LF(\n)とCR(\r)に対応していますがソート後はCR+LFに変更されます
; 変更時に変数のサイズが足りない場合statに-1がセットされます
;-------------------------------------------------------------------
#module
#deffunc init_sortline
dim func1,10: ll_getptr func1 : ll_ret pfunc1
func1.0=$8bc03353,$330c244c,$ebd98bd2,$0dea8009,$8301fa80,$118a00d0,$75d20a41,$8bcb2bf0
func1.8=$4008245c,$c35b0b89
dim func2,22 : ll_getptr func2 : ll_ret pfunc2
func2.0=$24448b53,$245c8b08,$244c8b10,$ebd23314,$90909016,$fa809090,$8a11750d,$0afa8011
func2.8=$c6410175,$8900ff43,$04c08318,$8841118a,$d20a4313,$d38be075,$0c244c8b,$1024542b
func2.16=$8b4b1189,$d33bfc50,$e8830375,$24442b04,$02e8c108,$0000c35b
dim func3,44 : ll_getptr func3 : ll_ret pfunc3
func3.0=$04244c8b,$0824548b,$1774d20b,$57565355,$fc91548d,$fc246c8d,$63e8c033,$5f000000
func3.8=$c35d5b5e,$90909090,$da8b5251,$dbd1d903,$83fce383,$c28304e9,$eb1b8b04,$398b9009
func3.16=$3a89328b,$798b3189,$83f38b04,$078a04c1,$72063a47,$460575f1,$f275c00a,$8bfc728b
func3.24=$04ea83fb,$3a46068a,$75f17707,$c00a4705,$ca3bf275,$e983c872,$04c28304,$ca8b515b
func3.32=$598dd38b,$77d33b04,$8b1a759f,$8a3a8b31,$073a4606,$0a470575,$76f475c0,$8b318b08
func3.40=$8932893a,$3b595a39,$51d776e5,$0000e2ff
dim func4,20 : ll_getptr func4 : ll_ret pfunc4
func4.0=$448b5356,$5c8b0c24,$4c8b1024,$d2331424,$2474c90b,$0302e1c1,$6608ebcb,$0a0d00c7
func4.8=$8b02c083,$04c38333,$108803eb,$46168a40,$f675d20a,$e372d93b,$18247c83,$66087400
func4.16=$0a0d00c7,$c602c083,$5e5b0000,$000000c3
ll_getptr tmpsize : ll_ret ptmpsize
ll_getptr bsize : ll_ret pbsize
return
#deffunc sortline val,int
mref var,24
mref flag,1
mref pval,1024
mref _stat,64
if flag{
poke func3,$53,$77
poke func3,$69,$72
poke func3,$9b,$73
}else{
poke func3,$53,$72
poke func3,$69,$77
poke func3,$9b,$76
}
ll_getptr var : ll_ret pvar
para=ptmpsize,pvar
ll_callfunc para,2,pfunc1 : ll_ret linenum
sdim stmp,tmpsize : ll_getptr stmp : ll_ret pstmp
dim point,linenum : ll_getptr point : ll_ret ppoint
para=ppoint,pbsize,pstmp,pvar
ll_callfunc para,4,pfunc2 : ll_ret pointnum
if pval.2*4<(bsize+linenum-1): dim stmp,1:dim point,1:_stat=-1:return
para=ppoint,pointnum
ll_callfunc para,2,pfunc3
para=pvar,ppoint,pointnum,linenum-pointnum
ll_callfunc para,4,pfunc4
dim stmp,1
dim point,1
_stat=0
return
#global
init_sortline
;****************************************************
;以下使用例
cls 1
sdim s,32768
mesbox s,640,300,1 : id_mesbox=stat
button "ソート",*sort
chkbox "降順",sortopt
stop
*sort
sortline s,sortopt
objprm id_mesbox,s
stop
戻る