shithub: pokecrystal

ref: 7dc495b3c9269eba88abe1168cc694a2ec3e5e0f
dir: /textpre.awk/

View raw version
BEGIN {
FS = "\""

char["ガ"] = "$05"
char["ギ"] = "$06"
char["グ"] = "$07"
char["ゲ"] = "$08"
char["ゴ"] = "$09"
char["ザ"] = "$0A"
char["ジ"] = "$0B"
char["ズ"] = "$0C"
char["ゼ"] = "$0D"
char["ゾ"] = "$0E"
char["ダ"] = "$0F"
char["ヂ"] = "$10"
char["ヅ"] = "$11"
char["デ"] = "$12"
char["ド"] = "$13"
char["バ"] = "$19"
char["ビ"] = "$1A"
char["ブ"] = "$1B"
char["ボ"] = "$1C"
char["が"] = "$26"
char["ぎ"] = "$27"
char["ぐ"] = "$28"
char["げ"] = "$29"
char["ご"] = "$2A"
char["ざ"] = "$2B"
char["じ"] = "$2C"
char["ず"] = "$2D"
char["ぜ"] = "$2E"
char["ぞ"] = "$2F"
char["だ"] = "$30"
char["ぢ"] = "$31"
char["づ"] = "$32"
char["で"] = "$33"
char["ど"] = "$34"
char["ば"] = "$3A"
char["び"] = "$3B"
char["ぶ"] = "$3C"
char["べ"] = "$3D"
char["ぼ"] = "$3E"
char["パ"] = "$40"
char["ピ"] = "$41"
char["プ"] = "$42"
char["ポ"] = "$43"
char["ぱ"] = "$44"
char["ぴ"] = "$45"
char["ぷ"] = "$46"
char["ぺ"] = "$47"
char["ぽ"] = "$48"
char["ア"] = "$80"
char["イ"] = "$81"
char["ウ"] = "$82"
char["エ"] = "$83"
char["ォ"] = "$84"
char["カ"] = "$85"
char["キ"] = "$86"
char["ク"] = "$87"
char["ケ"] = "$88"
char["コ"] = "$89"
char["サ"] = "$8A"
char["シ"] = "$8B"
char["ス"] = "$8C"
char["セ"] = "$8D"
char["ソ"] = "$8E"
char["タ"] = "$8F"
char["チ"] = "$90"
char["ツ"] = "$91"
char["テ"] = "$92"
char["ト"] = "$93"
char["ナ"] = "$94"
char["ニ"] = "$95"
char["ヌ"] = "$96"
char["ネ"] = "$97"
char["ノ"] = "$98"
char["ハ"] = "$99"
char["ヒ"] = "$9A"
char["フ"] = "$9B"
char["ホ"] = "$9C"
char["マ"] = "$9D"
char["ミ"] = "$9E"
char["ム"] = "$9F"
char["メ"] = "$A0"
char["モ"] = "$A1"
char["ヤ"] = "$A2"
char["ユ"] = "$A3"
char["ヨ"] = "$A4"
char["ラ"] = "$A5"
char["ル"] = "$A6"
char["レ"] = "$A7"
char["ロ"] = "$A8"
char["ワ"] = "$A9"
char["ヲ"] = "$AA"
char["ン"] = "$AB"
char["ッ"] = "$AC"
char["ャ"] = "$AD"
char["ュ"] = "$AE"
char["ョ"] = "$AF"
char["ィ"] = "$B0"
char["あ"] = "$B1"
char["い"] = "$B2"
char["う"] = "$B3"
char["え"] = "$B4"
char["お"] = "$B5"
char["か"] = "$B6"
char["き"] = "$B7"
char["く"] = "$B8"
char["け"] = "$B9"
char["こ"] = "$BA"
char["さ"] = "$BB"
char["し"] = "$BC"
char["す"] = "$BD"
char["せ"] = "$BE"
char["そ"] = "$BF"
char["た"] = "$C0"
char["ち"] = "$C1"
char["つ"] = "$C2"
char["て"] = "$C3"
char["と"] = "$C4"
char["な"] = "$C5"
char["に"] = "$C6"
char["ぬ"] = "$C7"
char["ね"] = "$C8"
char["の"] = "$C9"
char["は"] = "$CA"
char["ひ"] = "$CB"
char["ふ"] = "$CC"
char["へ"] = "$CD"
char["ほ"] = "$CE"
char["ま"] = "$CF"
char["み"] = "$D0"
char["む"] = "$D1"
char["め"] = "$D2"
char["も"] = "$D3"
char["や"] = "$D4"
char["ゆ"] = "$D5"
char["よ"] = "$D6"
char["ら"] = "$D7"
char["り"] = "$D8"
char["る"] = "$D9"
char["れ"] = "$DA"
char["ろ"] = "$DB"
char["わ"] = "$DC"
char["を"] = "$DD"
char["ん"] = "$DE"
char["っ"] = "$DF"
char["ゃ"] = "$E0"
char["ゅ"] = "$E1"
char["ょ"] = "$E2"
char["ー"] = "$E3"


char["@"] = "$50"
char["#"] = "$54"
char["…"] = "$75"

# textbox borders
char["┌"] = "$79"
char["─"] = "$7A"
char["┐"] = "$7B"
char["│"] = "$7C"
char["└"] = "$7D"
char["┘"] = "$7E"

char["№"] = "$74"

char[" "] = "$7F"
char["A"] = "$80"
char["B"] = "$81"
char["C"] = "$82"
char["D"] = "$83"
char["E"] = "$84"
char["F"] = "$85"
char["G"] = "$86"
char["H"] = "$87"
char["I"] = "$88"
char["J"] = "$89"
char["K"] = "$8A"
char["L"] = "$8B"
char["M"] = "$8C"
char["N"] = "$8D"
char["O"] = "$8E"
char["P"] = "$8F"
char["Q"] = "$90"
char["R"] = "$91"
char["S"] = "$92"
char["T"] = "$93"
char["U"] = "$94"
char["V"] = "$95"
char["W"] = "$96"
char["X"] = "$97"
char["Y"] = "$98"
char["Z"] = "$99"
char["("] = "$9A"
char[")"] = "$9B"
char[":"] = "$9C"
char[";"] = "$9D"
char["["] = "$9E"
char["]"] = "$9F"
char["a"] = "$A0"
char["b"] = "$A1"
char["c"] = "$A2"
char["d"] = "$A3"
char["e"] = "$A4"
char["f"] = "$A5"
char["g"] = "$A6"
char["h"] = "$A7"
char["i"] = "$A8"
char["j"] = "$A9"
char["k"] = "$AA"
char["l"] = "$AB"
char["m"] = "$AC"
char["n"] = "$AD"
char["o"] = "$AE"
char["p"] = "$AF"
char["q"] = "$B0"
char["r"] = "$B1"
char["s"] = "$B2"
char["t"] = "$B3"
char["u"] = "$B4"
char["v"] = "$B5"
char["w"] = "$B6"
char["x"] = "$B7"
char["y"] = "$B8"
char["z"] = "$B9"
char["é"] = "$BA"
char["'t"] = "$BE"
char["'s"] = "$D4"
char["'"] = "$E0"
char["-"] = "$E3"
char["?"] = "$E6"
char["!"] = "$E7"
char["."] = "$E8"
char["&"] = "$E9"
char["♂"] = "$EF"
char["/"] = "$F3"
char[","] = "$F4"
char["♀"] = "$F5"
char["0"] = "$F6"
char["1"] = "$F7"
char["2"] = "$F8"
char["3"] = "$F9"
char["4"] = "$FA"
char["5"] = "$FB"
char["6"] = "$FC"
char["7"] = "$FD"
char["8"] = "$FE"
char["9"] = "$FF"
}

# skip lines that actually do use ASCII in quotes
tolower($1) ~ /section/ ||
tolower($1) ~ /include/ || 
tolower($1) ~ /incbin/

!(tolower($1) ~ /section/ || tolower($1) ~ /include/ || tolower($1) ~ /incbin/) {
i = 1
ORS = ""

while (i <= NF) {
if (i % 2 == 1)
	print $(i)
else {
	f = $(i)
	while (f != "") {
		c = substr(f,1,1)
		f = substr(f,2,length(f) - 1)
		if (c > "𐀀") { # U+10000
			c = c substr(f,1,3)
			f = substr(f,4,length(f) - 3)
		} else if (c > "ࠀ") { # U+0800
			c = c substr(f,1,2)
			f = substr(f,3,length(f) - 2)
		} else if (c > "€") { # U+0080
			c = c substr(f,1,1)
			f = substr(f,2,length(f) - 1)
		}

		if (c == "'") {
			if (substr(f,1,1) == "m" ||
			    substr(f,1,1) == "r" ||
			    substr(f,1,1) == "t" ||
			    substr(f,1,1) == "s" ||
			    substr(f,1,1) == "v" ||
			    substr(f,1,1) == "l") {
				c = c substr(f,1,1)
				f = substr(f,2,length(f) - 1)
			}
		}

		print char[c]
		if (length(f))
			print ","
	}
}

i = i + 1
}
print "\n"
ORS = "\n"
}