?? yacgi.html
字號:
<html><head><title>yacgi: Yet Another C/C++ library for CGI Programming</title></head><BODY BGCOLOR="#ffffff"><h1>yacgi: Yet Another C/C++ library for CGI Programming</h1>version 1.2<br><STRONG>Andrew Girow / Andriy Zhyrov /</STRONG><BR><BR><FONT SIZE="-1">Copyright © 1997 Andrew Girow. All Rights Reserved.</FONT><P><h3>Table of Contents</h3><ul><li><a href="#whatnew">What's new in version 1.2?</a><li><a href="#whatis">Why yacgi?</a><li><a href="#basics">Basic concepts</a><li><a href="#credit">Credits and License Terms</a><li><a href="#obtain">Obtaining yacgi</a><li><a href="#using">Using yacgi</a><li><a href="#reference">yacgi reference</a></ul><hr><h2><a name="whatnew">What's new in version 1.2?</a></h2>Version 1.02 corrects bugs in previous versions: <ul> <li> cgiClose now works propertly. </ul>New examples are added <ul> <li> <a href="emailhd.html">YACGI Simple Email Handler (1.1)</a> </ul><h2><a name="whatis">Why yacgi?</a></h2>There are two main sources for yacgi:<ul><li><a href="http://www.boutell.com/cgic/">CGIC</a> is an ANSI C-language library for the creation of CGI-based World Wide Web applications by<a href="http://www.boutell.com/boutell/">Thomas Boutell</a><BR><li><a href="./bra.html"> Binary Relation Approach to Data Modelling</a><BR></ul><p>There are two main reasons for yacgi:<ul><li> CGIC is an exelect tool but there are some difficults in the library structure and the interface. <BR> <BR> From CGIC 1.05 documentation:<BR><em>Since all CGI applications must perform certain initialtasks, such as parsing form data and examiningenvironment variables, the cgic library provides itsown main() function. When you write applications thatuse cgic, you will begin your own programs by writinga cgiMain() function, which cgic will invoke whenthe initial cgi work has been successfully completed.<p>...<strong>Important:</strong> if you write your own main()function, your program will not link properly. Your owncode should begin with cgiMain(). The libraryprovides main() for you.<p>...This function takes advantage of cgiFormCheckboxMultiple(),which is used to identify one or more selected checkboxes withthe same name. This function performs identically tocgiFormSelectMultiple().That is, <SELECT> tags with the MULTIPLE attribute are handledjust like a group of several checkboxes with the same name.</em><p>... and so on.<p> <li> Using Binary Relation Model we can construct very simple and powerful model and library for CGI programming</ul><p><hr><h2><a name="basics">Basic concepts</a></h2>In general, <STRONG>a binary relation</STRONG> consists of two terms<STRONG>a key</STRONG> and <STRONG>a value</STRONG> which refer toentities, and a predicate <STRONG>an access function</STRONG> whichconnects the terms by saying something about them.<P><PRE><STRONG>example</STRONG>: "A person works in an enterprise."</PRE><P><center><IMG SRC="brapic1.gif"></center><P>Picture 1.<P>In general, an access function is a function which maps one objectinto the powerset of another (the set of all subset).While defining a relation one gives the key and value object typesinvolved, and one defines the access function and gives informationabout its cardinality. When the cardinal of an access function is<STRONG>unique</STRONG> then it is a function. When the cardinal of anaccess function is <STRONG>multiple</STRONG> then it is a multiple-valuedfunction.<p>For the CGI programming (about the CGI standard,see the <a href="http://hoohoo.ncsa.uiuc.edu/cgi/">CGI documentation</a> at NCSA.)we can use a very simple model:<ul><li>Name-Value Relation<li>State of Relation<li>CGI Environment</ul><center><IMG SRC="yacgi.gif"></center>Picture 2. Binary Relation Model of CGI Programming<p><hr><h2><a name="credit">Credits and License Terms</a></h2>yacgi can be used free of charge, provided that a credit notice is provided online. Alternatively, a nonexclusive Commercial License can be purchased, which grants the right to use cgic without apublic credit notice. <P>Please see the file <a href="license.txt">license</a> for the details of the Basic License and Commercial License,including ordering information for the Commercial License. <hr><h2><a name="obtain">Obtaining yacgi</a></h2>Your web browser should inquire whether to save the file to diskwhen you select the link below.<ul><li><a href="yacgi12_tar.gz">yacgi12_tar.gz</a></ul><hr><h2><a name="using">Using yacgi</a></h2>There are very few basic concepts that you need to know. Wedescribe the concepts as abstract data types. There is a 1:1correspondence between YACGI abstract data types and the BinaryRelations Approach to CGI basic items.<P><STRONG>Opening Relation</STRONG><BR>This code opens the relation.<P><PRE>#include <stdio.h>#include <stdlib.h>#include "yacgi.h"main(int argc, char *argv[]){ CGI *cgi; printf("Content-type: text/html%c%c",10,10); /*----------------------------------------------------------- * Opening Relation *-----------------------------------------------------------*/ cgi = cgiOpen(); if(!cgi) { printf("<H3>%s</H3>%c",cgiStateMsg(),10); exit(1); }</PRE><P><STRONG>Closing Relation</STRONG><BR>You should close the relation before exit the program.<PRE> /*------------------------------------------------------ * Closing Relation. *------------------------------------------------------*/ cgiClose(cgi);}</PRE><P><STRONG>Scanning Relation</STRONG><BR>You can use traversing or scanning the relation, accessing eachstored pair of names-values in turn to perform some test oraction.<P><PRE>#include <stdio.h>#include <stdlib.h>#include "yacgi.h"main(int argc, char *argv[]){ CGI *cgi; int more; char *string; printf("Content-type: text/html%c%c",10,10); /*----------------------------------------------------------- * Opening Relation *-----------------------------------------------------------*/ cgi = cgiOpen(); if(!cgi) { printf("<H3>%s</H3>%c",cgiStateMsg(),10); exit(1); } /*----------------------------------------------------------- * Scanning Relation *-----------------------------------------------------------*/ printf("<CENTER><H2>Scanning Name-Value Relation</H2></CENTER>"); printf("You submitted the following name/value pairs:<p>%c",10); printf("<ul>%c",10); more= cgiFirst(cgi); while(more) { printf("<li> <code>%s = %s</code>%c",cgiName(cgi), cgiValue(cgi),10); more = cgiNext(cgi); } printf("</ul>%c",10); /*------------------------------------------------------ * Closing Relation. *------------------------------------------------------*/ cgiClose(cgi);}</PRE><P><STRONG>Evaluating Relation</STRONG><BR><P>We can "navigate" from objects to objects using binaryrelation. To do this, we use cgiValueFirst and cgiValueNext functions.For instance, we have a Name "sex" and want to know value of sex.The code is:<P><PRE>#include <stdio.h>#include <stdlib.h>#include "yacgi.h"main(int argc, char *argv[]){ CGI *cgi; int more; char *string; printf("Content-type: text/html%c%c",10,10); /*----------------------------------------------------------- * Opening Relation *-----------------------------------------------------------*/ cgi = cgiOpen(); if(!cgi) { printf("<H3>%s</H3>%c",cgiStateMsg(),10); exit(1); } /*----------------------------------------------------------- * Evaluating Relation *-----------------------------------------------------------*/ printf("<CENTER><H2>Evaluating Name-Value Relation</H2></CENTER>"); printf("<p><b>%s</b><br>%c","First Name",10); string = cgiValueFirst(cgi, "First_Name"); if(string) printf("<code>%s</code><br>%c",string,10); printf("<p><b>%s</b><br>%c","Last Name",10); string = cgiValueFirst(cgi, "Last_Name"); if(string) printf("<code>%s</code><br>%c",string,10); printf("<p><b>%s</b><br>%c","Date of Birth",10); string = cgiValueFirst(cgi, "D_O_B"); if(string) printf("<code>%s</code><br>%c",string,10); printf("<p><b>%s</b><br>%c","Sex",10); string = cgiValueFirst(cgi, "Sex"); if(string) printf("<code>%s</code><br>%c",string,10); printf("<p><b>%s</b><br>%c","Degree",10); string = cgiValueFirst(cgi, "Degree"); if(string) printf("<code>%s</code><br>%c",string,10); printf("<p><b>%s</b><br>%c","Current Occupation",10); string = cgiValueFirst(cgi, "Occupation"); if(string) printf("<code>%s</code><br>%c",string,10); printf("<p><b>%s</b><br>%c","Duties",10); string = cgiValueFirst(cgi, "Duties"); if(string) printf("<code>%s</code><br>%c",string,10); /*---------------------------------------------------------- * Let us now look at multiple relations. Assume we want the * skills of the person. * We write: *---------------------------------------------------------*/ printf("<p><b>%s</b><br>%c","Skills",10); string = cgiValueFirst(cgi, "Skills"); while(string) { printf("<code>%s</code><br>%c",string,10); string = cgiValueNext(cgi, "Skills"); } /*------------------------------------------------------ * Closing Relation. *------------------------------------------------------*/ cgiClose(cgi);}</PRE><P>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -