cpp2html[C言語版]

例題のページで用いられているcpp2htmlのC言語版を掲載します。 cpp2htmlは、C及びC++で書かれたソースファイルをHTMLへと変換します。

ソースのダウンロード(リンク先にはcpp2htmlにより変換されたHTMLファイルが表示されます。):

実行時の引数は以下のようになります。

Gami[573]% cpp2html
USAGE: cpp2html srcfile [-disp] [-plain] [-out htmlfile] [-t n]
option:
	-disp   output to display (default _c.html file).
	-plain  do not display HTML header and footer.
	-t n    tab order(insert n spaces instead of a tab)
	-out htmlfile   output filename
Gami[574]%



ファイルの数が多く一括して変換したい場合には、VC++等でのGUIを作成すれば良いのですが、cygwin環境で一括して変換することができるように、perl用のスクリプトを準備しました。

実行手順:

src2html.pl [download]
#!/usr/bin/perl
#--------------------------------------------------
# cpp2html 一括変換用スクリプト
#   src2html.pl
#--------------------------------------------------
# cpp2html のパスを指定
$trcmd = "./cpp2html";
# 検索する拡張子のリスト
@Lext = ('cpp','cc','c','h','hh');
# 変換オプション
$opt  = 0;    # 1: ヘッダ,フッタを出力しない
$tab2spc = 0; # タブからスペースへの変換数
# 引数検索
for($i=0;$i<=$#ARGV;$i++){
    if($ARGV[$i] eq "-plain"){ $opt = 1; }
    if($ARGV[$i] eq "-t"){
        $i++; $tab2spc = $ARGV[$i];
    }
}
# 拡張子による検索
for($i=0;$i<=$#Lext;$i++){
    $trext = $Lext[$i];
    @file  = <*.$trext>;
    if($#file){
        foreach $fname (@file){
            ($name,$ext) = split(/\./,$fname);
            if($ext eq $trext){
                print "**$fname:\n";
                $cmd = "$trcmd $fname";
                if($opt){ $cmd = "$cmd -plain"; }
                if($tab2spc){ $cmd = "$cmd -t $tab2spc"; }
                system($cmd);
            }
        }
    }
}
inserted by FC2 system