例題のページで用いられている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]% |
実行手順:
Gami[616]% ls common.c cpp2html.c cpp2html.h keydown.c samp_c.c common.h cpp2html.exe* cpp2html.lzh makefile Gami[617]% src2html -t 4 → オプションの指定(-plain or -t n) **common.c: output file:[common_c.html] **cpp2html.c: output file:[cpp2html_c.html] **keydown.c: output file:[keydown_c.html] **samp_c.c: output file:[samp_c_c.html] **common.h: output file:[common_h.html] **cpp2html.h: output file:[cpp2html_h.html] Gami[618]% ls common.c common_h.html cpp2html.h cpp2html_h.html makefile common.h cpp2html.c cpp2html.lzh keydown.c samp_c.c common_c.html cpp2html.exe* cpp2html_c.html keydown_c.html samp_c_c.html Gami[619]% |
#!/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); } } } } |