Revisión | d53c4f3350f9e85274596ad07229a0ffe8d3130c (tree) |
---|---|
Tiempo | 2014-12-22 23:41:59 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
Implement converting UTF-8 source code to EUC-JP dist files
Convert option sample:
for UTF-8 to UTF-8:
for UTF-8 to EUC-JP:
for EUC-JP to UTF-8:
for EUC-JP to EUC-JP:
@@ -18,7 +18,9 @@ usage(){ | ||
18 | 18 | warn " --nopkg Suppress creating archive (Extract and chmod only)" |
19 | 19 | warn " --norm --nopkg, and remove nothing (.cvsignore etc)" |
20 | 20 | 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" | |
22 | 24 | warn " -z|--zip Create *.zip archive" |
23 | 25 | warn " --move-dist Move *.ini.php => *.ini-dist.php" |
24 | 26 | warn " --copy-dist Move, and Copy *.ini.php <= *.ini-dist.php" |
@@ -88,6 +90,8 @@ getopt(){ _arg=noarg | ||
88 | 90 | --co|--checkout ) echo _nopkg _noremove _checkout 1 ;; |
89 | 91 | -z|--zip ) echo _zip 1 ;; |
90 | 92 | --ut|--utf|--utf8|--utf-8 ) echo _utf8 1 ;; |
93 | + --eucjp ) echo _eucjp 1 ;; | |
94 | + --fromeucjp ) echo _fromeucjp 1 ;; | |
91 | 95 | --copy-dist ) echo _copy_dist 1 ;; |
92 | 96 | --move-dist ) echo _move_dist 1 ;; |
93 | 97 | -d ) echo _CVSROOT 2 ; _arg="$2" ;; |
@@ -134,7 +138,12 @@ if [ $# -eq 0 ] ; then usage ; exit ; fi | ||
134 | 138 | |
135 | 139 | # Utility check --------------------------------------------- |
136 | 140 | |
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 | |
138 | 147 | |
139 | 148 | # nkf |
140 | 149 | which nkf || err "nkf version 2.0 or later (UTF-8 enabled) not found" |
@@ -153,9 +162,13 @@ if [ "$__utf8" ] ; then | ||
153 | 162 | fi |
154 | 163 | |
155 | 164 | convert(){ |
165 | + __nkfopt="--ic=eucJP-ms -w" | |
166 | + if [ "$__eucjp" ] ; then | |
167 | + __nkfopt="--ic=UTF8 --oc=eucJP-ms" | |
168 | + fi | |
156 | 169 | for list in "$@" ; do |
157 | 170 | # 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" | |
159 | 172 | done |
160 | 173 | } |
161 | 174 | convert_EUCJP2UTF8(){ |
@@ -165,6 +178,13 @@ if [ "$__utf8" ] ; then | ||
165 | 178 | sed 's#^//UTF-8:##' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" |
166 | 179 | done |
167 | 180 | } |
181 | + convert_UTF82EUCJP(){ | |
182 | + for list in "$@" ; do | |
183 | + # Very rough conversion! | |
184 | + #sed 's/EUC-JP/UTF-8/g' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" | |
185 | + sed 's#^\(.*//UTF-8 only\)$#//UTF-8:\0#' "$list" > "$list.$$.tmp" && mv "$list.$$.tmp" "$list" | |
186 | + done | |
187 | + } | |
168 | 188 | fi > /dev/null |
169 | 189 | |
170 | 190 | if [ -z "$__zip" ] |
@@ -241,8 +261,12 @@ mv $pkg_dir/cache/_recent.dat $pkg_dir/cache/recent.dat | ||
241 | 261 | |
242 | 262 | # Conversion ------------------------------------------------ |
243 | 263 | |
244 | -if [ "$__utf8" ] ; then | |
245 | - echo "Converting EUC-JP => UTF-8 ..." | |
264 | +if [ "$__charconv" ] ; then | |
265 | + if [ "$__utf8" ] ; then | |
266 | + echo "Converting EUC-JP => UTF-8 ..." | |
267 | + else | |
268 | + echo "Converting UTF-8 => EUC-JP ..." | |
269 | + fi | |
246 | 270 | find "$pkg_dir" -type f \( -name "*.txt" -or -name "*.php" -or -name "*.lng" -or -name "*.dat" -or -name "*.ref" \) | |
247 | 271 | while read line; do |
248 | 272 | case "$line" in |
@@ -251,10 +275,17 @@ if [ "$__utf8" ] ; then | ||
251 | 275 | esac |
252 | 276 | done |
253 | 277 | |
254 | - # Replace 'EUC-JP' => 'UTF-8' | |
255 | - ( cd "$pkg_dir" && | |
256 | - convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php | |
257 | - ) | |
278 | + if [ "$__utf8" ] ; then | |
279 | + # Replace 'EUC-JP' => 'UTF-8' | |
280 | + ( cd "$pkg_dir" && | |
281 | + convert_EUCJP2UTF8 lib/init.php skin/pukiwiki.skin*.php | |
282 | + ) | |
283 | + else | |
284 | + # Replace 'UTF-8' => 'EUC-JP' | |
285 | + ( cd "$pkg_dir" && | |
286 | + convert_UTF82EUCJP lib/init.php skin/pukiwiki.skin*.php | |
287 | + ) | |
288 | + fi | |
258 | 289 | |
259 | 290 | # Filename encoded 'encoded-EUC-JP' to 'encoded-UTF-8' |
260 | 291 | echo "Renaming encoded-EUC-JP => encoded-UTF-8 ..." |