当前位置:操作系统 > Unix/Linux >>

webalizer汉化后图表乱码的处理

webalizer是一个简单易用的日志分析软件,但安装好中文版本后,出来的图表中总有让人心烦的乱码。本文用一个简单的perl处理脚本就可让乱码不再出现。

  #!/usr/bin/perl

  $file_graph = "$ARGV[0]/graphs.c";

  if(!(-e $file_graph)) {

  print "error open $file_graph

  ";

  print "Usage:

  perl $0 DIR

  ";

  #DIR是源文件目录,比如 ./

  exit;

  }

  #把图表中的月份和注释改成英文

  @old_var = ("msg_h_hits",

  "msg_h_pages",

  "msg_h_visits",

  "msg_h_files",

  "msg_h_sites",

  "msg_h_xfer",

  "s_month");

  @new_var = ("msg_gh_hits",

  "msg_gh_pages",

  "msg_gh_visits",

  "msg_gh_files",

  "msg_gh_sites",

  "msg_gh_xfer",

  "s_gmonth");

  open(IN,"<$file_graph");

  @lines = ;

  $size = @lines;

  close(IN);

  `mv $file_graph $file_graph.bak`;

  open(OUT,">$file_graph");

  for($i=0;$i<$size;$i++) {

  for($k=0;$k<@old_var;$k++) {

  if($lines[$i] =~ s/$old_var[$k]/$new_var[$k]/g) {

  print "$i $old_var[$k] -> $new_var[$k]

  ";

  print OUT "/* --- Modified --- */

  ";

  }

  }

  print OUT $lines[$i];

  }

  close(OUT);

  #把图表中的标题改成英文显示

  $file_output = "$ARGV[0]/output.c";

  open(IN,"<$file_output");

  @lines = ;

  $size = @lines;

  close(IN);

  `mv $file_output $file_output.bak`;

  open(OUT,">$file_output");

  for($i=0;$i<$size;$i++) {

  if($lines[$i] =~ s/msg_hmth_du,l_month/"Daily Usage for",s_gmonth/xg) {

  print "$i patched

  ";

  print OUT "/* --- Modified --- */

  ";

  } elsif($lines[$i] =~ s/msg_hmth_hu,l_month/"Hourly Usage for",s_gmonth/xg) {

  print "$i patched

  ";

  print OUT "/* --- Modified --- */

  ";

  } elsif($lines[$i] =~ s/msg_ctry_use,l_month/"Usage by Country for",s_gmonth/xg) {

  print "$i patched

  ";

  print OUT "/* --- Modified --- */

  ";

  } elsif($lines[$i] =~ s/msg_main_us/"Usage summary for"/xg) {

  print "$i patched

  ";

  print OUT "/* --- Modified --- */

  ";

  }

  print OUT $lines[$i];

  }

  close(OUT);

  #加入新的函数给前面显示的程序用

  print "

  patch $ARGV[0]/webalizer_lang.h

  ";

  $file_lang = "$ARGV[0]/webalizer_lang.h";

  open(OUT,">>$file_lang");

  print OUT qq~

  /* --- start Add ---*/

  char *msg_gh_hits = "Hits";

  char *msg_gh_pages = "Pages";

  char *msg_gh_visits= "Visits";

  char *msg_gh_files = "Files";

  char *msg_gh_sites = "Sites";

  char *msg_gh_xfer = "KBytes";

  char *s_gmonth[12]={ "Jan", "Feb", "Mar",

  "Apr", "May", "Jun",

  "Jul", "Aug", "Sep",

  "Oct", "Nov", "Dec"};

  /* -------------End------------- */

  ~;

  #补充声明这些新加的函数

  print "

  patch $ARGV[0]/lang.h

  ";

  $file_lang = "$ARGV[0]/lang.h";

  open(OUT,">>$file_lang");

  print OUT qq~

  /* --- start Add ---*/

  extern char *msg_gh_hits ;

  extern char *msg_gh_pages ;

  extern char *msg_gh_visits;

  extern char *msg_gh_files ;

  extern char *msg_gh_sites ;

  extern char *msg_gh_xfer ;

  extern char *s_gmonth[12];

  /* -------------End------------- */

  ~;

  print "Done ^_^

  ";

  ############################################################

  

上一个:Linux中文化之RedHat7.2/7.3中文字体设置工具fm
下一个:汉化SuSe8.0的过程

更多Unix/Linux疑问解答:
路由原理介绍
子网掩码快速算法
改变网络接口的速度和协商方式的工具miitool和ethtool
Loopback口的作用汇总
OSPF的童话
增强的ACL修改功能
三层交换机和路由器的比较
用三层交换机组建校园网
4到7层交换识别内容
SPARC中如何安装Linux系统(2)
SPARC中如何安装Linux系统(1)
用Swatch做Linux日志分析
实战多种Linux操作系统共存
浅析Linux系统帐户的管理和审计
Linux2.6对新型CPU的支持(2)
电脑通通透
玩转网络
IE/注册表
DOS/Win9x
Windows Xp
Windows 2000
Windows 2003
Windows Vista
Windows 2008
Windows7
Unix/Linux
苹果机Mac OS
windows8
安卓/Android
Windows10
如果你遇到操作系统难题:
访问www.zzzyk.com 试试
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,