移植到UNICODE

很久以前写的一个简单的脚本,功能:
- 替换"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);
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值