如何将应用程序从 Borland Pascal 移植到 FreePascal 和 Unicode 终端
How to port app from Borland Pascal to FreePascal and Unicode terminal
我正在尝试将我从旧 Borland Pascal 编写的第一个应用程序移植到 FreePascal 并 运行 它在 Linux unicode shell.
不幸的是,该应用程序使用 CRT 单元并写入非标准的 ASCII 图形字符。所以我试着重写这样的语句:
gotoxy(2,3); write(#204);
writeln('3. Intro');
这些:
gotoxy(2,3); write('╠');
write('3. Intro', #10);
两个注意事项:
- 我直接在代码中使用unicode字符,因为我没有找到如何通过他们的代码编写unicode字符。
- 我使用
write
过程而不是 writeln
来确保生成 unix 行结尾。
但在替换所有非标准 ASCII 字符并删除所有 writeln
语句后,情况变得更糟。
变更前:
修改后:
为什么会变成这样?我可以做得更好吗?
一段时间后,这是我发现的更新。
1) 移植不了
正如用户@dmsc 正确指出的那样,CRT 不支持 UTF-8。他建议的技巧对我不起作用。
2)无法移植时,模拟环境。
我需要的图形字符是 CP-437. There is a program called luit 的一部分,用于将应用程序输出从语言环境编码转换为 UTF-8。不幸的是,这对我不起作用。它简单地删除了字符:
# Via iconv, everything is OK:
$ printf "top right corner in CP437: \xbf \n" | iconv -f CP437 -t UTF-8
top right corner in CP437: ┐
# But not via luit, that simply omit the character:
$ luit -gr g2 -g2 'CP 437' printf "top right corner in CP437: \xbf \n"
top right corner in CP437:
所以我的解决方案是 运行 gnome-terminal,添加并设置希伯来语 (IBM862) 编码 (tutorial here) 并享受您的应用程序!
CRT 单元当前不适用于 UTF-8,因为它假定屏幕上的每个字符正好是一个字节,请参阅 http://www.freepascal.org/docs-html-3.0.0/rtl/crt/index.html
但是,简单的应用程序可以通过 "tricking" GotoXY 来运行,以始终进行完整的光标定位,方法是:
GotoXY(1,1);
GotoXY(x, y);
要替换源文件中的所有字符串,您可以使用重新编码,在终端类型中:
recode cp437..u8 < original.pas > fixed.pas
然后,您需要将所有数字字符(如您的#204 示例)替换为等效的 UTF-8,您可以使用:
echo -e '\xCC' | recode cp437/..u8
'CC'是16进制的204,所以会打印'╠'字符。
我正在尝试将我从旧 Borland Pascal 编写的第一个应用程序移植到 FreePascal 并 运行 它在 Linux unicode shell.
不幸的是,该应用程序使用 CRT 单元并写入非标准的 ASCII 图形字符。所以我试着重写这样的语句:
gotoxy(2,3); write(#204);
writeln('3. Intro');
这些:
gotoxy(2,3); write('╠');
write('3. Intro', #10);
两个注意事项:
- 我直接在代码中使用unicode字符,因为我没有找到如何通过他们的代码编写unicode字符。
- 我使用
write
过程而不是writeln
来确保生成 unix 行结尾。
但在替换所有非标准 ASCII 字符并删除所有 writeln
语句后,情况变得更糟。
变更前:
修改后:
为什么会变成这样?我可以做得更好吗?
一段时间后,这是我发现的更新。
1) 移植不了
正如用户@dmsc 正确指出的那样,CRT 不支持 UTF-8。他建议的技巧对我不起作用。
2)无法移植时,模拟环境。
我需要的图形字符是 CP-437. There is a program called luit 的一部分,用于将应用程序输出从语言环境编码转换为 UTF-8。不幸的是,这对我不起作用。它简单地删除了字符:
# Via iconv, everything is OK:
$ printf "top right corner in CP437: \xbf \n" | iconv -f CP437 -t UTF-8
top right corner in CP437: ┐
# But not via luit, that simply omit the character:
$ luit -gr g2 -g2 'CP 437' printf "top right corner in CP437: \xbf \n"
top right corner in CP437:
所以我的解决方案是 运行 gnome-terminal,添加并设置希伯来语 (IBM862) 编码 (tutorial here) 并享受您的应用程序!
CRT 单元当前不适用于 UTF-8,因为它假定屏幕上的每个字符正好是一个字节,请参阅 http://www.freepascal.org/docs-html-3.0.0/rtl/crt/index.html
但是,简单的应用程序可以通过 "tricking" GotoXY 来运行,以始终进行完整的光标定位,方法是:
GotoXY(1,1);
GotoXY(x, y);
要替换源文件中的所有字符串,您可以使用重新编码,在终端类型中:
recode cp437..u8 < original.pas > fixed.pas
然后,您需要将所有数字字符(如您的#204 示例)替换为等效的 UTF-8,您可以使用:
echo -e '\xCC' | recode cp437/..u8
'CC'是16进制的204,所以会打印'╠'字符。