linux程序内码,windows系统与linux系统的内码转换总结

我准备把我的Linux平台的编码从zh_CN.GB2312改为zh_CN.UTF-8,希望能够一切顺利。

我的系统是Debian/Linux, sid, 2.6。

1. 基本配置bash的设置没有改,.xsession是.xinitrc的软链接。

.xinitrc内容如下:

# .xinitrcsource

$HOME/.bash_profile

LANG=zh_CN.UTF-8

LC_MESSAGES=en_US

LC_TIME=en_US

export LANG LC_MESSAGES LC_TIME

export GDK_USE_XFT=1

export GTK_IM_MODULE='scim'

export XMODIFIERS="@im=SCIM"

scim -d

xscreensaver -no-splash &

esd &

icewmbg &

icewmtray &

exec icewm

2. 文件名可以用convmv来转换

convmv -f gb2312 -t utf8 -r --notest *

-r表示包含所有子目录

不加--notest就表示只看看有什么需要转换的,不做实际转换

3. 文件内容可以用iconv,不过我更喜欢用emacs.用emacs打开文件

C-x  f utf-8  C-x C-s

搞定。

4. xterm

理论上uxterm, rxvt-unicode-ml, mlterm, gnome-terminal都应该支持的,但似乎uxterm, rxvt总有莫名奇妙的问题,所以我用mlterm(gnome-terminal的粘贴风格我不喜欢)

5. Emacs只需加如下两句

(setq current-language-environment "Chinese-GB")(prefer-coding-system 'utf-8)

这时你用

C-h v coding-category-list

可以看到coding-category-list等于

(coding-category-utf-8

coding-category-iso-8-2 coding-category-big5 coding-category-iso-7-else

coding-category-iso-8-1 coding-category-utf-16-be

coding-category-utf-16-le coding-category-iso-7-tight

coding-category-iso-7 coding-category-iso-8-else

coding-category-emacs-mule coding-category-raw-text

coding-category-sjis coding-category-ccl coding-category-binary)

其中coding-category-iso-8-2就是chinese-iso-8bit,也就是gb2312

7. LaTeX

cjk-latex支持UTF8,但需要cyberb(debian没有提供),只好拿ttf-arphic-gbsn00lp伪装一个。

首先安装tetex-bin, cjk-latex, ttf-arphic-gbsn00lp,然后运行脚本unisong

unisong含两个文件,Makefile和c70song.fd

Makefile:

all:

buildbuild:

ln -s /usr/share/fonts/truetype/arphic/gbsn00lp.ttf unisong.ttf

ttf2tfm unisong.ttf -w unisong@Unicode@ > unisong.log

rm -f unisong.map

for i in *.tfm; do \

base=`basename $$i .tfm`;\

echo "$${base} unisong.map;\

done

install:

install -d /usr/share/texmf/fonts/tfm/arphic/unisong/

cp *.tfm /usr/share/texmf/fonts/tfm/arphic/unisong/

install -d /usr/share/texmf/dvips/arphic/

cp *.enc /usr/share/texmf/dvips/arphic/

cp unisong.map /etc/texmf/dvips/

cp unisong.map /usr/share/texmf/dvips/omega/

cp unisong.ttf /usr/share/texmf/fonts/truetype/arphic/

grep '^unisong@Unicode@ unisong.ttf' /etc/ttf2pk/ttfonts.map || \

echo "unisong@Unicode@ unisong.tff" >> /etc/ttf2pk/ttfonts.map

cp -f c70song.fd /usr/share/texmf/tex/latex/CJK/UTF8/

grep "^map +unisong.map" /etc/texmf/pdftex/pdftex.cfg || \

echo "map +unisong.map" >> /etc/texmf/pdftex/pdftex.cfg

mktexlsrclean:

rm -f unisong*.tfm

rm -f unisong*.enc

rm -f unisong.map

rm -f unisong.ttf

rm -f unisong.log

.PHONY: build

c70song.fd(cjk-latex自带的c70song.fd,再将cyberb改成unisong就可以了):

% This is the file c70song.fd of the CJK package

%   for using Asian logographs (Chinese/Japanese/Korean) with LaTeX2e

%

% created by Werner Lemberg

%

% Version 4.5.1 (17-Jun-2002)

\def\fileversion{4.5.1}

\def\filedate{2002/06/17}

\ProvidesFile{c70song.fd}[\filedate\space\fileversion]

% character set: Unicode U+0080 - U+FFFD

% font encoding: Unicode

\DeclareFontFamily{C70}{song}{\hyphenchar \font\m@ne}

\DeclareFontShape{C70}{song}{m}{n}{ CJK * unisong}{}

\DeclareFontShape{C70}{song}{bx}{n}{ CJKb * unisong}{\CJKbold}

\endinput

OK, make; su; make install就可以了

然后把你的latex文章转成UTF8编码,把\begin{CJK*}{GB}{song}改成\begin{CJK*}{UTF8}{song}就可以了。

8. MP3 ID3 tag

xmms

里边一堆的乱码,看来是ID3的编码的问题,没办法,又写了一个脚本。注意,这个脚本依赖于pyid3lib, 你可以到

下载,如果你用debian的话,可以直接用 apt-get install

python-id3lib 安装

#!/usr/bin/python

# mp3iconv.py

import os

import pyid3lib

def texticonv(text, fcode, tcode):

try:

text.decode(tcode)

except UnicodeDecodeError:

try:

newtext = text.decode(fcode)

except UnicodeDecodeError:

return False, None

newtext = newtext.encode(tcode)

return True, newtext

os.rename(fname, newfname)

return False, Nonedef mp3iconv(fname, fcode='gb2312', tcode='utf8'):

tag = pyid3lib.tag(fname)

needupdate = False

for key in ['artist', 'title', 'album']:

try:

text = getattr(tag, key)

except AttributeError:

continue

r, newtext = texticonv(text, fcode, tcode)

if r:

setattr(tag, key, newtext)

needupdate = True

if needupdate:

tag.update()

def main():

import sys

assert len(sys.argv) > 1

for x in sys.argv[1:]:

mp3iconv(x)

if __name__ == '__main__':

main()

9. FTP

很多FTP的文件名是GB2312编码的。解决方法有:

1. 用mozilla系列浏览器来访问FTP,可以自行设置编码。

2. 用lftp,在$HOME/.lftp/rc或/etc/lftp.conf文件中加入(感谢:yabozj AT zju.edu.cn)

set ftp:charset "gbk"

set file:charset "UTF-8"

阅读(1372) | 评论(0) | 转发(0) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值