2008年12月17日水曜日

区切り文字で区切るモジュール

・FILE名:mdl_calc_one_dat.hsp

#module one_data NO,型,tmp_型,中身の数,中身,warn,n_warn

#modinit int number
NO=number
型=null
sdim tmp_中身,2000
sdim tmp_型,256
tmp_型=""
中身の数=0
sdim 中身,2000,32
repeat 32
中身.cnt=""
loop
n_warn=0
sdim warn,1000

sdim of_sep_A,1000
sdim of_sep_B,1000
return
#modfunc add_warn str w
if n_warn=0{ warn=w : n_warn++ }
else{ warn+="\n"+w : n_warn++ }
return
#defcfunc sep2 var to_sep,var from_sep_01,var from_sep_02
l2sep=strlen(to_sep)
ans_of_sep=instr(to_sep,0,"||")
if ans_of_sep==-1{
from_sep_01=to_sep
return 1
}else{
from_sep_01=strmid(to_sep,0,ans_of_sep)
l=l2sep-ans_of_sep-2
from_sep_02=strmid(to_sep,-1,l)
return 2
}
return -1
#modfunc search_sep_error
if tmp_型==""{add_warn thismod,"区切り文字の前に何もありません" }
ii=中身の数-1
if 中身の数>0{
if 中身.ii==""{add_warn thismod,"区切り文字の後に何もありません" }
}
n=中身の数
if n>=2{
repeat (n-1)
if 中身.cnt=""{add_warn thismod,"区切り文字の間に何もありません" }
loop
}
return
#modfunc set_one_data var data
ans=sep2(data,of_sep_A,of_sep_B)
tmp_型=of_sep_A : 中身の数=0
n_cnt=0
while ans==2
tmp_中身=of_sep_B
ans=sep2(tmp_中身,of_sep_A,of_sep_B)
中身.n_cnt=of_sep_A
中身の数++
n_cnt++
wend
search_sep_error thismod
return

#modfunc dump
logmes "NO = "+str(NO)
logmes "型 = "+tmp_型
logmes "中身の数 = "+中身の数
repeat 中身の数
logmes "中身"+cnt+" = "+中身.cnt
loop
if warn!=""{
logmes "警告:"+warn }
return
#global


テストコード その1

#include "mdl_calc_one_dat.hsp"
sdim sn,4000
sdim tmp_sn,256
sdim one_sc,256

sdim to_test,2000,32
to_test.0="this"
to_test.1="this||a"
to_test.2="this||a||b"
to_test.3="this||a||b||c"
to_test.4="this||a||b||c||d"

newmod one_dat_01,one_data,1
set_one_data one_dat_01,to_test.0
dump one_dat_01

newmod one_dat_02,one_data,2
set_one_data one_dat_02,to_test.1
dump one_dat_02

newmod one_dat_03,one_data,3
set_one_data one_dat_03,to_test.2
dump one_dat_03

newmod one_dat_04,one_data,4
set_one_data one_dat_04,to_test.3
dump one_dat_04

newmod one_dat_05,one_data,5
set_one_data one_dat_05,to_test.4
dump one_dat_05


・テストコード その2

#include "mdl_calc_one_dat.hsp"
sdim sn,4000
sdim tmp_sn,256
sdim one_sc,256

sdim to_test,2000,32
to_test.0="this"
to_test.1="this||"
to_test.2="||a||"
to_test.3="a||b||||||||c"
to_test.4="this||a||b||c||d||e||f||||g"

newmod one_dat_01,one_data,1
set_one_data one_dat_01,to_test.0
dump one_dat_01

newmod one_dat_02,one_data,2
set_one_data one_dat_02,to_test.1
dump one_dat_02

newmod one_dat_03,one_data,3
set_one_data one_dat_03,to_test.2
dump one_dat_03

newmod one_dat_04,one_data,4
set_one_data one_dat_04,to_test.3
dump one_dat_04

newmod one_dat_05,one_data,5
set_one_data one_dat_05,to_test.4
dump one_dat_05

0 件のコメント: