|
Common Gateway Interface
A Common Gateway Interface (CGI) program can be written in any language that allows it to be executed on a computer. The most commonly used languages for CGI at present are C and Perl. CGI programs written in C typically have to be compiled. They are difficult to modify and maintain. Therefore, many people prefer to write CGI programs in Perl, which is interpretive and resembles C language. However, writing and maintaining a large program in Perl is dreadful. Ch is a superset of C interpreter with classes in C++. Existing C code can readily be used for CGI. The Ch language environment has been developed to be especially suitable for Web programming. The classes CResponse, CRequest, CServer, and CCookie are the basic building blocks for CGI in Ch. These CGI classes support wide character. They significantly simplify Web-based application development. For example, the code below can be used to display all environmental variables in common gateway interface in different platforms of Unix, Linux, and Windows. Environment values\n"); for(i=0; environ[i] != NULL; i++) { printf("%s\n", environ[i]); } Response.end(); } CGI programming in Ch is simple, easy, and fun. This Web Calculator is just one of the typical application examples. The following extensions of Ch over C make it ideal for programming in Common Gateway Interface.
in a web browser. Using verbatim output features, the above Ch CGI program can be simplified as
If the value of a variable is used inside a verbatim output block,
a dollar sign $ can be used to retrieve the value of the variable
as demonstrated by variable hello in the above program.
Test of Request.getForm\n"); //get name name = Request.getForm(L"name"); printf("name is : "); fputws(name ? name : L"NULL", stdout); printf(" \n"); //get favorites value = Request.getForm(L"flavor"); prntf("flavor is :"); fputws(value ? value : L"NULL", stdout); printf(" \n"); Response.end(); } The following on-line examples will further demonstrate the capabilities of Ch for CGI. The source code for HTML and Ch CGI programs for these examples and sample code for using each member function of CGI classes are available in the distribution of the Ch language environment. They can be accessed through a Web page http://your_web_site/chhtml/lang/index.html after Ch is installed on your Web server. Examples of using Ch CGI for web-based plotting, 3D graphics, numerical analysis, design and analysis of control systems are available. |