• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版1667bd04c79c30bec63efc0e86fceafb95fc127c (tree)
时间2014-12-22 23:51:54
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

Implement converting UTF-8 source code to EUC-JP dist files

Convert option sample:

for UTF-8 to UTF-8:

$ ./release.sh --utf8

for UTF-8 to EUC-JP:

$ ./release.sh --eucjp

for EUC-JP to UTF-8:

$ ./release.sh --utf8 --fromeucjp

for EUC-JP to EUC-JP:

$ ./release.sh --eucjp --fromeucjp

更改概述

差异

--- a/release.sh
+++ b/release.sh
@@ -18,7 +18,9 @@ usage(){
1818 warn " --nopkg Suppress creating archive (Extract and chmod only)"
1919 warn " --norm --nopkg, and remove nothing (.cvsignore etc)"
2020 warn " --co --norm, and use 'checkout' command instead of 'export'"
21- warn " --utf8 Create UTF-8 converted archive (EXPERIMENTAL)"
21+ warn " --utf8 Create UTF-8 converted archive"
22+ warn " --eucjp Create EUC_JP converted archive"
23+ warn " --fromeucjp Indicate source charset is EUC_JP"
2224 warn " -z|--zip Create *.zip archive"
2325 warn " --move-dist Move *.ini.php => *.ini-dist.php"
2426 warn " --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php"
@@ -88,6 +90,8 @@ getopt(){ _arg=noarg
8890 --co|--checkout ) echo _nopkg _noremove _checkout 1 ;;
8991 -z|--zip ) echo _zip 1 ;;
9092 --ut|--utf|--utf8|--utf-8 ) echo _utf8 1 ;;
93+ --eucjp ) echo _eucjp 1 ;;
94+ --fromeucjp ) echo _fromeucjp 1 ;;
9195 --copy-dist ) echo _copy_dist 1 ;;
9296 --move-dist ) echo _move_dist 1 ;;
9397 -d ) echo _CVSROOT 2 ; _arg="$2" ;;
@@ -134,7 +138,12 @@ if [ $# -eq 0 ] ; then usage ; exit ; fi
134138
135139 # Utility check ---------------------------------------------
136140
137-if [ "$__utf8" ] ; then
141+# Convert UTF-8 -> EUC_JP or EUC_JP -> UTF-8
142+if [ \( "$__eucjp" -a ! "$__fromeucjp" \) -o \( "$__utf8" -a "$__fromeucjp" \) ] ; then
143+ __charconv=1
144+fi
145+
146+if [ "$__charconv" ] ; then
138147
139148 # nkf
140149 which nkf || err "nkf version 2.0 or later (UTF-8 enabled) not found"
@@ -153,9 +162,13 @@ if [ "$__utf8" ] ; then
153162 fi
154163
155164 convert(){
165+ __nkfopt="--ic=eucJP-ms -w"
166+ if [ "$__eucjp" ] ; then
167+ __nkfopt="--ic=UTF8 --oc=eucJP-ms"
168+ fi
156169 for list in "$@" ; do
157170 # NOTE: Specify '-E'(From EUC-JP) otherwise skin file will be collapsed
158- nkf --ic=eucJP-ms -w "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" && echo " $list"
171+ nkf $__nkfopt "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" && echo " $list"
159172 done
160173 }
161174 convert_EUCJP2UTF8(){
@@ -165,6 +178,18 @@ if [ "$__utf8" ] ; then
165178 sed 's#^//UTF-8:##' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
166179 done
167180 }
181+ convert_UTF82EUCJP(){
182+ for list in "$@" ; do
183+ # Very rough conversion!
184+ #sed 's/UTF-8/EUC-JP/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list"
185+ # This is very specific logit for PukiWiki 1.5.x source code
186+ sed -i 's#^define('\''PKWK_UTF8_ENABLE'\'', *1);#//UTF-8:\0#' "$list"
187+ sed -i 's#^case \+'\''ko'\'': *define('\''MB_LANGUAGE'\'', *'\''Korean'\''#//UTF-8:\0#' "$list"
188+ sed -i 's#^[^a-zA-Z]*// *See *BugTrack2/13 *for *all#//UTF-8:\0#' "$list"
189+ sed -i 's#^[^a-zA-Z]*// *and *give *us *your *report#//UTF-8:\0#' "$list"
190+
191+ done
192+ }
168193 fi > /dev/null
169194
170195 if [ -z "$__zip" ]
@@ -241,8 +266,12 @@ mv $pkg_dir/cache/_recent.dat $pkg_dir/cache/recent.dat
241266
242267 # Conversion ------------------------------------------------
243268
244-if [ "$__utf8" ] ; then
245- echo "Converting EUC-JP => UTF-8 ..."
269+if [ "$__charconv" ] ; then
270+ if [ "$__utf8" ] ; then
271+ echo "Converting EUC-JP => UTF-8 ..."
272+ else
273+ echo "Converting UTF-8 => EUC-JP ..."
274+ fi
246275 find "$pkg_dir" -type f \( -name "*.txt" -or -name "*.php" -or -name "*.lng" -or -name "*.dat" -or -name "*.ref" \) |
247276 while read line; do
248277 case "$line" in
@@ -251,10 +280,17 @@ if [ "$__utf8" ] ; then
251280 esac
252281 done
253282
254- # Replace 'EUC-JP' => 'UTF-8'
255- ( cd "$pkg_dir" &&
256- convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php
257- )
283+ if [ "$__utf8" ] ; then
284+ # Replace 'EUC-JP' => 'UTF-8'
285+ ( cd "$pkg_dir" &&
286+ convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php
287+ )
288+ else
289+ # Replace 'UTF-8' => 'EUC-JP'
290+ ( cd "$pkg_dir" &&
291+ convert_UTF82EUCJP lib/init.php skin/pukiwiki.skin*.php
292+ )
293+ fi
258294
259295 # Filename encoded 'encoded-EUC-JP' to 'encoded-UTF-8'
260296 echo "Renaming encoded-EUC-JP => encoded-UTF-8 ..."