移植到UNICODE

来源:互联网 发布:洮南网络花店 编辑:程序博客网 时间:2024/05/20 06:22
很久以前写的一个简单的脚本,功能:
- 替换"xxx" 到 _T("xxx")
- ...
 
虽然非常简陋,可是可以看到在开发中使用脚本会极大地提高开发效率。
# File:
# Purpose: A simple tools to change c/cpp file from ANSI to UNICODE
#          in windows.
# Author: xxxxxxxxxx
#
# Functions list:
# - Change all "xxx" string  to _T("xxx") except #include "xxx"
# - Change "strcpy","strcmp",strcat,substr,sprintf,strstr,strchr,
# - Change "sizeof(char)" to sizeof(TCHAR) # BTW: if you want to alloc bytes,pls use sizeof(BYTE)
# Notes: u can write a shell scirpt to change all files
#        in derectory recursively.
#
# TODO:
#

BEGIN{
  # flush temp file
  tmpfile = "tmp";
  flush = "cat /dev/null > " tmpfile;
  system(flush);
}
# skip '#include'
/[ /t]*#include/{print $0 > tmpfile; next}
# process each line
# from "xxx.tracer..." to "HWDEBUG(xxx.tracer...)"
{
  sub(/[a-zA-Z/)(1-9_/./-/>]+/.tracef/(.*/)/, "HWDEBUG(&)", $0)
}
 
# from "char" to "TCHAR", from "unsigned char" to "BYTE"
{
  gsub(/unsigned char/, "BYTE", $0);
  gsub(/char[ /t]+/, "TCHAR ", $0);
}
# from "char* " to "TCHAR* "
{
  gsub(/char*[ /t]+/, "TCHAR* ", $0);
}
# from "strxxx" to "_tcsxxx"
{
  if (match($0,/str[a-z]+[ /t]*/(/))
 {
   tmpstr = "_tcs" substr($0, RSTART+3, RLENGTH - 3);
   gsub(/str[a-z]+[ /t]*/(/, tmpstr, $0);
 }
}
# string printf functions
{
  gsub(/_vsnprintf[ /t]*/(/, "_vsntprintf(", $0);
  gsub(/_snprintf[ /t]*/(/, "_snprintf(", $0);
  gsub(/sprintf[ /t]*/(/, "_stprintf(", $0);
}
# from "xxx" to _T("xxx")
{
  gsub(/"[^"]*"/, "_T(&)", $0);print $0 > tmpfile;
}

END{
  system("cp " tmpfile " " FILENAME);
#  print filename; 
#  system("mv " + newname + " " + filename);
}
 
原创粉丝点击