〜 テキスト 〜
JISをSJISに変換

メール等で使用しているJIS(ISO−2022−JP)コードを、
HSPで扱う標準のShift-JIS(SJIS)に変換します。
poke命令を用いて直接書き込んでいるため、HSP3以降であってもバッファサイズの自動拡張は行いません。
SJISは、JISよりもサイズが大きくならず、同じか小さくなるものですが、
設定先の変数は、元の変数と同等サイズ以上を確保するようにしましょう。
尚、下記モジュールの漢字INは、新JIS(JIS X 0208−1983)のみ対応しています。
旧JIS(JIS X 0208−1978)コード等のテキストでは正常に変換できません。
必要がある場合は、各自で書き換えてください。
	

jistosjis 設定先変数, 変換元変数
設定先変数変換したSJISコードテキストを格納する変数を指定する。
変換元変数SJISコードに変換するJISコードテキストを格納した変数を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#module
#deffunc jistosjis val, val
	mref sjis, 24 : mref jis, 25
	wbite = 0 // 2バイト文字フラグ
	i = 0     // 読込元インデクス
	strlen len, jis
	repeat len
		peek code.0, jis, i
		// 制御文字
		if code.0 = 0x1b {
			peek code.0, jis, i + 1
			peek code.1, jis, i + 2
			if code.0 = 0x24 & (code.1 = 0x42) : wbite = 1 // 2バイト開始エスケープシーケンス(KI)
			if code.0 = 0x28 & (code.1 = 0x42) : wbite = 0 // 2バイト終了エスケープシーケンス(KO)
			i += 3
			continue cnt
		}
		// 2バイト文字
		if wbite {
			peek code.1, jis, i + 1
			if code.0 \ 2 {
			  code.0 = ((code.0 + 1) / 2) + 0x70
			  code.1 += 0x1f
			} else {
			  code.0 = code.0 / 2 + 0x70
			  code.1 += 0x7d
			}
			if code.0 >= 0xa0 : code.0 += 0x40
			if code.1 >= 0x7f : code.1++
			wpoke sjis, cnt, (code.1 << 8) + code.0
			i += 2
			continue cnt + 2
		}
		// 1バイト文字
		poke sjis, cnt, code.0
		i++
	loop
	return
#global

	sdim string, 3200, 2 // 足りない場合はサイズを大きくしてください
	objsize winx, 25
	button "読み込む", *load
	mesbox string, winx, winy - 25, 5
	stop

*load
	dialog "txt", 16, "Jisコードテキスト"
	if stat {
		notesel string
		noteload refstr
		jistosjis string.1, string.0
		objprm 1, string.1
	}
	stop

jistosjis 設定先変数, 変換元変数
設定先変数変換したSJISコードテキストを格納する変数を指定する。
変換元変数SJISコードに変換するJISコードテキストを格納した変数を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#module
#deffunc jistosjis var sjis, var jis, local wbite, local i, local code
	repeat strlen(jis)
		code.0 = peek(jis, i)
		// 制御文字
		if code.0 = 0x1b {
			code.0 = peek(jis, i + 1)
			code.1 = peek(jis, i + 2)
			if code.0 = 0x24 & code.1 = 0x42 : wbite = 1 // 2バイト開始エスケープシーケンス(KI)
			if code.0 = 0x28 & code.1 = 0x42 : wbite = 0 // 2バイト終了エスケープシーケンス(KO)
			i += 3
			continue cnt
		}
		// 2バイト文字
		if wbite {
			code.1 = peek(jis, i + 1)
			if code.0 \ 2 {
			  code.0 = ((code.0 + 1) / 2) + 0x70
			  code.1 += 0x1f
			} else {
			  code.0 = code.0 / 2 + 0x70
			  code.1 += 0x7d
			}
			if code.0 >= 0xa0 : code.0 += 0x40
			if code.1 >= 0x7f : code.1++
			wpoke sjis, cnt, (code.1 << 8) + code.0
			i += 2
			continue cnt + 2
		}
		// 1バイト文字
		poke sjis, cnt, code.0
		i++
	loop
	return
#global

	sdim string, 3200, 2 // 足りない場合はサイズを大きくしてください
	objsize ginfo_winx, 25
	button gosub "読み込む", *load
	mesbox string, ginfo_winx, ginfo_winy - 25
	stop

*load
	dialog "txt", 16, "Jisコードテキスト"
	if stat {
		notesel string
		noteload refstr
		jistosjis string.1, string.0
		objprm 1, string.1
	}
	return