日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cgic: 为C语言编写CGI的C函数库

發布時間:2024/9/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cgic: 为C语言编写CGI的C函数库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://www.qqread.com/cgi-perl/v223877.html

cgic: 為c語言編寫CGI的C函數庫 由Thomas Boutell開發 目錄 CGIC介紹 怎樣寫CGIC應用程序 怎樣產生圖片在CGIC中? CGI調試特征: 利用捕獲 cgic函數參考 cgic變量參考 cgic結果編碼參考 cgic快速索引 一般的UNIX系統都支持ANSIC。
  作者:siyu?

cgic: 為C語言編寫CGI的C函數庫?
由Thomas Boutell開發?
目錄?

CGIC介紹?
怎樣寫CGIC應用程序?
怎樣產生圖片在CGIC中??
CGI調試特征: 利用捕獲?
cgic函數參考?
cgic變量參考?
cgic結果編碼參考?
cgic快速索引?

一般的UNIX系統都支持ANSIC,增加相應的庫函數(和相應的h文件)就可以實現CGI。在此我向大家推薦一個用于CGI編程的ANSIC庫:cgic。?

cgic是用來生成基于CGI的WWW應用程序的C語言函數庫,它有以下功能:?

*對數據進行語法分析?

*接收以GET和PSOT兩種方式發送的數據?

*把FORM中的不同域連接成連續的串?

*為檢索FORM數據而提供字符串,整數,浮點以及單項和多項選擇功能?

*為數字字段提供邊界檢測?

*把CGI環境變量加載到非空的C串中?

*為調試而捕捉CGI狀態?

*提供相對安全的系統調用功能?

用一般ANSI C或C++編譯器就可以編譯cgic程序,不過與通常C程序不同的是,用cgic寫的源碼其主函數是cgiMain(),而不是通常的main()。cgic的函數庫會自動把cgiMain連接到相應的main()上去。?


--------------------------------------------------------------------------------?


寫CGIC程序?
Note: 所有的cgic應用程序必須連接cgic.c.?
用cgimain()替代main() 必須包含: #include"cgic.h."?

基本結構cgictest.c:?


int cgiMain() {?
#if DEBUG?
/* Load a saved CGI scenario if we're debugging */?
cgiReadEnvironment("/path/to/capcgi.dat");?
#endif?
/* Important: we must indicate the type of document */?
cgiHeaderContentType("text/html");?
/* Now invoke other functions to handle each part of the form */?
fprintf(cgiOut, "<HTML><HEAD>\n");?
fprintf(cgiOut, "<T99vLE>cgic test</T99vLE></HEAD>\n"):?
fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n");?
Name();?
Address();?
Hungry();?
Temperature();?
Frogs();?
Color();?
Flavors();?
NonExButtons();?
RadioButtons();?
fprintf(cgiOut, "</BODY></HTML>\n");?
/* This value will be the exit code of the program; 0?
generally indicates success among Unix and DOS programs */?
return 0;?
}?

capture?
輸出標頭?
cgiHeaderContentType()在輸出文擋之前簡要說明MIME內型,如 "text/html"。?
cgiHeaderStatus()代替輸出錯誤代碼 cgiHeaderLocation()代替重新引導至其他頁面。在一個獨立的應用程序中只能有一個cgiHeader函數。?

重點:在cgiHeader函數組中, cgiHeaderContentType(), 在任何向瀏覽器輸出之前被調用. 否則將出錯或瀏覽器不能識別。 cgiOut?

接著, cgiMain() 調用不同的函數.當函數結束后,將返回0?


處理輸入文本?
void Name() {?
char name[81];?
cgiFormStringNoNewlines("name", name, 81);?
fprintf(cgiOut, "Name: %s<BR>\n", name);?
}?

這個函數的功能就是取的并顯示由用戶輸入的name .?
處理輸出?
Important: cgiOut通常相當于stdout?

cgiFormString 確保斷航?

處理單一Checkboxes輸入?
這個Hungry() function確定用戶是否選擇"hungry"這個 checkbox:?
void Hungry() {?
if (cgiFormCheckboxSingle("hungry") == cgiFormSuccess) {?
fprintf(cgiOut, "I'm Hungry!<BR>\n");?
} else {?
fprintf(cgiOut, "I'm Not Hungry!<BR>\n");?
}?
}?

這個函數依靠 cgiFormCheckboxSingle() 確定單一的checkbox 被選擇。 cgiFormCheckboxSingle() 接受checkbox名字的屬性值,如果存在就返回 cgiFormSuccess,否則返回cgiFormNotFound 如果是多項checkboxes,就用 cgiFormCheckboxMultiple()和cgiFormStringMultiple() 函數.?
處理數字輸入?
Temperature() 返回浮點書的值確保在特定的返回內。?
void Temperature() {?
double temperature;?
cgiFormDoubleBounded("temperature", &temperature, 80.0, 120.0, 98.6);?
fprintf(cgiOut, "My temperature is %f.<BR>\n", temperature);?
}?

依靠cgiFormDoubleBounded()得到數據.第一個數據是返回數據中輸入域的名字。最后一個值是用戶沒有提交時的默認值。?
這個函數總是找回在特定返回內合適的值; cgiFormDoubleBounded返回的值被檢查確信用戶輸入的資料在規定范圍內, 而不是其他無效的數據。查看 cgiFormDoubleBounded() 更多的資料. 如果限度檢查不理想,可以用 cgiFormDouble() 替代.?

在整數輸入,cgiFormInteger 和 cgiFormIntegerBounded 可以利用. 這些函數的功能類似.?

處理單一選擇輸入?
<SELECT> HTML標簽被用于向用戶提供幾個選擇. Radio buttons 和checkboxes 椰油這樣的用途,大門、能夠選擇的數量很小時. Color()?
char *colors[] = {?
"Red",?
"Green",?
"Blue"?
};?

void Color() {?
int colorChoice;?
cgiFormSelectSingle("colors", colors, 3, &colorChoice, 0);?
fprintf(cgiOut, "I am: %s<BR>\n", colors[colorChoice]);?
}?

這個函數確定用戶選擇了幾個選項從<SELECT> 在表但的列表. cgiFormSelectSingle()?
cgiFormSelectSingle() 總是顯示合理的選項值.?

radio button也可以用這個函數.另外還有 cgiFormRadio(), 也是一樣的?


處理多項選擇的輸入?
NonExButtons()?
char *votes[] = {?
"A",?
"B",?
"C",?
"D"?
};?

void NonExButtons() {?
int voteChoices[4];?
int i;?
int result;?
int invalid;?

char **responses;?

/* Method #1: check for valid votes. This is a good idea,?
since votes for nonexistent candidates should probably?
be discounted... */?
fprintf(cgiOut, "Votes (method 1):<BR>\n");?
result = cgiFormCheckboxMultiple("vote", votes, 4,?
voteChoices, &invalid);?
if (result == cgiFormNotFound) {?
fprintf(cgiOut, "I hate them all!<p>\n");?
} else {?
fprintf(cgiOut, "My preferred candidates are:\n");?
fprintf(cgiOut, "<ul>\n");?
for (i=0; (i < 4); i++) {?
if (voteChoices[i]) {?
fprintf(cgiOut, "<li>%s\n", votes[i]);?
}?
}?
fprintf(cgiOut, "</ul>\n");?
}?

參考cgiFormCheckboxMultiple(), cgiFormSelectMultiple().?
cgiFormCheckboxMultiple() cgiFormCheckboxMultiple?

NonExButtons() 函數在 cgictest.c:?

/* Method #2: get all the names voted for and trust them.?
This is good if the form will change more often?
than the code and invented responses are not a danger?
or can be checked in some other way. */?
fprintf(cgiOut, "Votes (method 2):<BR>\n");?
result = cgiFormStringMultiple("vote", &responses);?
if (result == cgiFormNotFound) {?
fprintf(cgiOut, "I hate them all!<p>\n");?
} else {?
int i = 0;?
fprintf(cgiOut, "My preferred candidates are:\n");?
fprintf(cgiOut, "<ul>\n");?
while (responses[i]) {?
fprintf(cgiOut, "<li>%s\n", responses[i]);?
i++;?
}?
fprintf(cgiOut, "</ul>\n");?
}?
/* We must be sure to free the string array or a memory?
leak will occur. Simply calling free() would free?
the array but not the individual strings. The?
function cgiStringArrayFree() does the job completely. */?
cgiStringArrayFree(responses);?
}

回顧文章:用 c 寫 CGI 程序簡要指南

CGI程序可以用任何程序設計語言編寫,如Shell腳本語言、Perl、Fortran、Pascal、c語言等。但是用C語言編寫的CGI程序具有執行速度快、安全性高等特點。Web服務器在調用使用POST方法的CGI程序時設置此環境變量,它的文本值表示Web服務器傳送給CGI程序的輸入中的字符數目,因此我們使用函數a。


總結

以上是生活随笔為你收集整理的cgic: 为C语言编写CGI的C函数库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。