CGI C Program Compiler for Apache
ApacheのC言語CGI作成支援プログラムです。
Rev. | Zeit | Autor | Nachricht |
---|---|---|---|
55ab7ca | 2010-02-25 00:51:57 | Hidetaka Sakai | master add option ( -t -n ) Changes to be committed: modified... |
f7384bf | 2010-01-07 22:09:18 | Hidetaka Sakai | README_ja.txt misstake fix modified: README_ja.txt |
a135fba | 2010-01-01 21:25:33 | Hidetaka Sakai | modified cgigenerator.pl and sample1 / add README_ja.txt ... |
70fcb6e | 2010-01-01 01:17:41 | Hidetaka Sakai | erase file deleted: sample.cgc |
2e167ca | 2009-12-30 18:10:16 | Hidetaka Sakai | first commit all files |
Name | Rev. | Zeit | Autor | Nachricht |
---|---|---|---|---|
master | 55ab7ca | 2010-02-25 00:51:57 | Hidetaka Sakai | add option ( -t -n ) Chang... |
= CGIジェネレータ ApacheのC言語CGI作成支援プログラムです。 JSPのように、HTMLへC言語ソースを含むタグを埋め込んだテキストを、本プログラムに通すことで、C言語CGIプログラムを生成します。 == タグの例 以下のような埋め込みタグを使用できます。 ●単純なテキスト→printf文変換 入力例: 入力してください→<input type="text" value="test" / > 出力例: printf( "入力してください→<input type=\"text\" value=\"test\" / >\n" ); ※ printf文に変換されます。 ※ 改行文字は、"\n"に、\文字は、"\\"に置き換えます。 ※ コマンドラインオプション(-f)で、printf関数の変更を行えます。 ●<% ... %> タグ 入力例: <% int main(int argc, char** argv ){ char buff[32]; memset( buff, 0x00, sizeof(buff) %> 出力例: int main(int argc, char** argv ){ char buff[32]; memset( buff, 0x00, sizeof(buff) ※そのまま出力されます。 ●<%d= %> タグ/<%s= %>タグ 入力例: <%d=10%> <%s="sample"%> 出力例: printf( "%d", 10 ); printf( "%s", 10 ); ※printfの %d/%sへ置き換えています。 == コマンドラインオプション CGIジェネレータでは、以下のコマンドオプションを使用できます。 -h ヘルプを出力します -i <入力ファイル名> 入力するファイル名(タグ付きHTMLファイル名)を指定します -o <出力ファイル名> 出力するファイル名(C言語ソースファイル名)を指定します 通常、.cの拡張子になるでしょう -f <printf関数名> printfでなく、異なる関数を指定したい場合、指定します。 -t <タブ数> printf 行頭に<タブ数>個のタブを挿入します -n コンパイラ用のタグを出力しません == 簡単なサンプル 簡単なサンプルとその出力例を示します。 ●タグ付きHTMLファイル(入力ファイル) <% #include <stdio.h> #include <stdlib.h> %> <% int main(int argc, char** argv) { int i; char* Title = "Table Test"; char buff[64]; printf( "Content-type:text/html\r\n" ); printf( "Cache-Control: no-cache\r\n" ); printf( "Pragma: no-cache\r\n\r\n" ); %> <html> <head> <title><%s=Title%> </title> </head> <body> <p><%s=Title%></p> <table> <tbody> <% for( i = 0; i< 10 ; i++ ){ %> <tr> <td> <%d=i%> </td> <% snprintf( buff, sizeof(buff), "test-%d", i ); %> <td> <%s=buff%> </td> <% snprintf( buff, sizeof(buff), "test:%d", i ); %> <td> <%s=buff%> </td> </tr> <% } %> </tbody> </table> </body> </html> <%} %> ●コマンド実行 ./cgigenerator.pl -i sample1.cgc -o sample1.c ●出力例 #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { int i; char* Title = "Table Test"; char buff[64]; printf( "Content-type:text/html\r\n" ); printf( "Cache-Control: no-cache\r\n" ); printf( "Pragma: no-cache\r\n\r\n" ); printf( "<html>\n" ); printf( "<head>\n" ); printf( "<title>" ); printf( "%s", Title ); printf( " </title>\n" ); printf( "</head>\n" ); printf( "<body>\n" ); printf( "<p>" ); printf( "%s", Title ); printf( "</p>\n" ); printf( "<table>\n" ); printf( "<tbody>\n" ); for( i = 0; i< 10 ; i++ ){ printf( "<tr>\n" ); printf( "<td> " ); printf( "%d", i ); printf( " </td>\n" ); snprintf( buff, sizeof(buff), "test-%d", i ); printf( "<td> " ); printf( "%s", buff ); printf( " </td>\n" ); snprintf( buff, sizeof(buff), "test:%d", i ); printf( "<td> " ); printf( "%s", buff ); printf( " </td>\n" ); printf( "</tr>\n" ); } printf( "</tbody>\n" ); printf( "</table>\n" ); printf( "</body>\n" ); printf( "</html>\n" ); } ※ 実際のコマンドでは、C言語コンパイル用に "#line <行数> "<ファイル名>" が追加出力されます