/* ファイル名 ZTOMETA.MAC 目的 文字列内の全角英数字(°φ±□⌒)をメタキャラに変換する。 °→ \M0 φ→ \M1 ±→ \M2 □→ \M3 ⌒→ \M4 入力変数 inptxt 出力変数 outtxt */ extern inptxt, outtxt; zenkaku = "°φ±□⌒"; metachar = "\M0\M1\M2\M3\M4"; outtxt = inptxt; first = 1; inplng = length(inptxt); for (inppos = 0; inppos < inplng; inppos += 1) { /* inptxt から1バイト取り出す -> ch */ ch = inptxt[inppos]; if (ch > "\000" && ch < "\200") { /* 半角文字 */ /* ch を outtxt にコピーする */ if (first) { first = 0; outtxt = ch; } else { outtxt += ch; } } else { /* 全角文字 */ if (inppos + 1 >= inplng) { /* 不都合な全角文字 */ /* ch を outtxt にコピーする */ if (first) { first = 0; outtxt = ch; } else { outtxt += ch; } } else { /* 正常な全角文字 */ /* inptxt からもう1バイト取り出す -> ch */ j2 = inppos + 1; ch = inptxt[inppos:j2]; inppos += 1; /* 全角英数字を半角英数字に変換する */ zlng = length(zenkaku); for (zpos1 = 0; zpos1 < zlng; zpos1 += 2) { zpos2 = zpos1 + 1; z = zenkaku[zpos1:zpos2]; m = metachar[zpos1:zpos2]; /**** n = subs(ch, z, h); if (n > 0) { /* 変換された */ break; } *****/ if (ch == z) { /* 一致した */ ch = m; break; } } /* ch を outtxt にコピー */ if (first) { first = 0; outtxt = ch; } else { outtxt += ch; } } } } /* End of file */