生成結構體網路編碼的perl指令碼(使用google protocal更為通用):
#! /usr/bin/perl -w
# usage : proto_hfile proto
my$classmane = "
--@@@@--";
for(@ar**
)
my$out = $in
;
$out =~ s/(\.\w+)?$/.h/; #
change suffix name
rename
$in, $in."
.proto
"; #
rename old file, use old name for new file
$in .= "
.proto
";
unless (open in,"
unless(open out, "
>$out")
print out "
#include \n";
while()
if( /}\s*;/)
print out $_
; }
}sub
addfuncdef
#! /usr/bin/perl -w
# usage : proto_cpp proto
# @ not support "long int"
my$classmane = "
--@@@@--";
my$prifix = "::"
;my@varshort =();
my@varint =();
my@varlong =();
for(@ar**
)
my$out = $in
;
$out =~ s/(\.\w+)?$/.cpp/; #
change suffix name
# rename $in, $in.".proto"; # rename old file, use old name for new file
# $in .= ".proto";
unless (-e $in
)
unless (open in,"
unless(open out, "
>$out")
print out "
#include \"$in\"\n\n";
print out "
#include \n";
print out "
#include \n";
print out "
#include \n\n";
while()
if( /}\s*;/)
if( /short\s+(\w+)/ || /int16_t\s+(\w+)/ || /uint16_t\s+(\w+)/)
if( /int\s+(\w+)/ || /int32_t\s+(\w+)/ || /uint32_t\s+(\w+)/)
if( /long\s+long\s+(\w+)/ || /int64_t\s+(\w+)/ || /uint64_t\s+(\w+)/)
if( /long\s+(\w+)/)
}}sub
addconstructfun
$classmane()\n";
print out "
\n\n";
}sub
addhtonfunc
hton()\n";
print out "
foreach (@varint
)
foreach (@varlong
)
print out "
}\n\n";
}sub
addntohfunc
ntoh()\n";
print out "
foreach (@varint
)
foreach (@varlong
)
print out "
}\n\n";
}sub
addprintfun
print() const\n";
print out "
\n\n";
}sub
cleanvar
#正規表示式測試指令碼:! /bin/bash
# usage : net_proto proto
if [[ $#
-lt 1 ]]
then
echo
"$0 proto_files ..."fi
/data/home/nolan/bin/proto_hfile $@;
/data/home/nolan/bin/proto_cpp $@;
#! /usr/bin/perl -w
# $pattern = "fred.*wilma|wilma.*fred";
# $pattern = "\\b\\w*a\\b"; #注意在字串中,\為轉義字元,\\才表示反斜線
# $pattern = "(fred|bar)";
# $pattern = "class\\s+(\\w+)\$";
# $pattern = "\\s*(\\w+\\s+)";
# $pattern = "\\w+\\s+(\\w|:)+\\s*\\(";
$pattern = "
class\\s+\\w+\\s*:\\s*public
"; #
class *** : public ***
while(<>)
else
}
指令碼工具類
指令碼工具類 public class scriptutility system.web.ui.page 返回前一頁 public static void goback 重新整理當前頁面 public static void refresh 重新整理父窗體,關閉當前窗體 public static ...
shell指令碼編碼問題
最近某個指令碼的執行經常導致編碼問題。指令碼從遠端mysql資料庫獲取影片中文名,然後再匯入本機的mysql中。發現由crontab自動執行的時候獲取的影片名稱都是亂碼,但手動執行指令碼卻正常輸出。幾天都是這個問題。今天突然想起以前也有類似問題,在終端執行 echo lang 然後在指令碼中加 ex...
Linux shell指令碼編碼問題
在linux中執行.sh指令碼,異常 bin sh m bad interpreter no such file or directory。分析 這是不同系統編碼格式引起的 在windows系統中編輯的.sh檔案可能有不可見字元,所以在linux系統下執行會報以上異常資訊。解決 1 在windows...