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

メール等で使用しているJIS(ISO−2022−JP)コードを、
UNIX系のワークステーションで用いられるEUC(EUC-JP)コードに変換します。
SJISと同じく全角文字は2バイトであり、JISのようなKI/KOエスケープもありませんので、
元のJISコードを格納した変数と同等以上のサイズを設定先変数にも用意すれば十分でしょう。
当然、変換だけではなく、編集を行う場合は相応のサイズを準備する必要があります。
	

jistoeuc 設定先変数, 変換元変数
設定先変数変換したEUCコードテキストを格納する変数を指定する。
変換元変数EUCコードに変換する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
#module
#deffunc jistoeuc val, val
	mref euc, 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
			code.0 += 0x80
			code.1 += 0x80
			wpoke euc, cnt, (code.1 << 8) + code.0
			i += 2
			continue cnt + 2
		}
		// 1バイト文字
		poke euc, cnt, code.0
		i++
	loop
	return
#global

	sdim string, 3200, 2 // 足りない場合はサイズを大きくしてください
	sdim file, 512
	// 読込
	dialog "txt", 16, "Jisコードテキスト"
	if stat = 0 : end
	notesel string.0
	noteload refstr
	// 保存
	dialog "txt", 17, "Eucコードテキスト"
	if stat = 0 : end
	jistoeuc string.1, string.0
	notesel string.1
	notesave refstr
	dialog "JISコードからEUCコードに変換しました。"

jistoeuc 設定先変数, 変換元変数
設定先変数変換したEUCコードテキストを格納する変数を指定する。
変換元変数EUCコードに変換する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
#module
#deffunc jistoeuc var euc, 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)
			code.0 += 0x80
			code.1 += 0x80
			wpoke euc, cnt, (code.1 << 8) + code.0
			i += 2
			continue cnt + 2
		}
		// 1バイト文字
		poke euc, cnt, code.0
		i++
	loop
	return
#global

	sdim string, 3200, 2 // 足りない場合はサイズを大きくしてください
	sdim file, 512
	// 読込
	dialog "txt", 16, "Jisコードテキスト"
	if stat = 0 : end
	notesel string.0
	noteload refstr
	// 保存
	dialog "txt", 17, "Eucコードテキスト"
	if stat = 0 : end
	jistoeuc string.1, string.0
	notesel string.1
	notesave refstr
	dialog "JISコードからEUCコードに変換しました。"
	end