复制代码- /////////////////////helloword.c
- /* Change this if the SERVER_NAME environment variable does not report
- the true name of your web server. */
- #if 1
- #define SERVER_NAME cgiServerName
- #endif
- #if 0
- #define SERVER_NAME "www.boutell.com"
- #endif
- /* You may need to change this, particularly under Windows;
- it is a reasonable guess as to an acceptable place to
- store a saved environment in order to test that feature.
- If that feature is not important to you, you needn't
- concern yourself with this. */
- #ifdef WIN32
- #define SAVED_ENVIRONMENT "c:\\cgicsave.env"
- #else
- #define SAVED_ENVIRONMENT "/tmp/cgicsave.env"
- #endif /* WIN32 */
- #include <stdio.h>
- #include "cgic.h"
- #include <string.h>
- #include <stdlib.h>
- void HandleSubmit();
- void ShowForm();
- void CookieSet();
- void Name();
- void Address();
- void Hungry();
- void Temperature();
- void Frogs();
- void Color();
- void Flavors();
- void NonExButtons();
- void RadioButtons();
- void File();
- void Entries();
- void Cookies();
- void LoadEnvironment();
- void SaveEnvironment();
- int cgiMain() {
- cgiHeaderContentType("text/html");
- fprintf(cgiOut, "<HTML><HEAD>\n");
- fprintf(cgiOut, "<TITLE>cgic song1 test</TITLE></HEAD>\n");
- fprintf(cgiOut, "<BODY><H1>1cgic song test</H1>\n");
- /* Now show the form */
- ShowForm();
- /* Finish up the page */
- fprintf(cgiOut, "</BODY></HTML>\n");
- return 0;
- }
- void ShowForm()
- {
- fprintf(cgiOut, "<!-- 2.0: multipart/form-data is required for file uploads. -->");
- fprintf(cgiOut, "<form method=\"POST\" enctype=\"multipart/form-data\" ");
- fprintf(cgiOut, " action=\"helloworld_sub.cgi");
- cgiValueEscape(cgiScriptName);
- fprintf(cgiOut, "\">\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "Text Field containing Plaintext\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "<input type=\"text\" name=\"name\">Your Name\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "Multiple-Line Text Field\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "<textarea NAME=\"address\" ROWS=4 COLS=40>\n");
- fprintf(cgiOut, "Default song go here. \n");
- fprintf(cgiOut, "</textarea>\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "Checkbox\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "<input type=\"checkbox\" name=\"hungry\" checked>Hungry\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "Text Field containing a Numeric Value\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "<input type=\"text\" name=\"temperature\" value=\"98.6\">\n");
- fprintf(cgiOut, "Blood Temperature (80.0-120.0)\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "Text Field containing an Integer Value\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "<input type=\"text\" name=\"frogs\" value=\"1\">\n");
- fprintf(cgiOut, "Frogs Eaten\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "Single-SELECT\n");
- fprintf(cgiOut, "<br>\n");
- fprintf(cgiOut, "<select name=\"colors\">\n");
- fprintf(cgiOut, "<option value=\"Red\">Red\n");
- fprintf(cgiOut, "<option value=\"Green\">Green\n");
- fprintf(cgiOut, "<option value=\"Blue\">Blue\n");
- fprintf(cgiOut, "</select>\n");
- fprintf(cgiOut, "<br>\n");
- fprintf(cgiOut, "Multiple-SELECT\n");
- fprintf(cgiOut, "<br>\n");
- fprintf(cgiOut, "<select name=\"flavors\" multiple>\n");
- fprintf(cgiOut, "<option value=\"pistachio\">Pistachio\n");
- fprintf(cgiOut, "<option value=\"walnut\">Walnut\n");
- fprintf(cgiOut, "<option value=\"creme\">Creme\n");
- fprintf(cgiOut, "</select>\n");
- fprintf(cgiOut, "<p>Exclusive Radio Button Group: Age of Truck in Years\n");
- fprintf(cgiOut, "<input type=\"radio\" name=\"age\" value=\"1\">1\n");
- fprintf(cgiOut, "<input type=\"radio\" name=\"age\" value=\"2\">2\n");
- fprintf(cgiOut, "<input type=\"radio\" name=\"age\" value=\"3\" checked>3\n");
- fprintf(cgiOut, "<input type=\"radio\" name=\"age\" value=\"4\">4\n");
- fprintf(cgiOut, "<p>Nonexclusive Checkbox Group: Voting for Zero through Four Candidates\n");
- fprintf(cgiOut, "<input type=\"checkbox\" name=\"vote\" value=\"A\">A\n");
- fprintf(cgiOut, "<input type=\"checkbox\" name=\"vote\" value=\"B\">B\n");
- fprintf(cgiOut, "<input type=\"checkbox\" name=\"vote\" value=\"C\">C\n");
- fprintf(cgiOut, "<input type=\"checkbox\" name=\"vote\" value=\"D\">D\n");
- fprintf(cgiOut, "<p>File Upload:\n");
- fprintf(cgiOut, "<input type=\"file\" name=\"file\" value=\"\"> (Select A Local File)\n");
- fprintf(cgiOut, "<p>\n");
- fprintf(cgiOut, "<p>Set a Cookie<p>\n");
- fprintf(cgiOut, "<input name=\"cname\" value=\"\"> Cookie Name\n");
- fprintf(cgiOut, "<input name=\"cvalue\" value=\"\"> Cookie Value<p>\n");
- fprintf(cgiOut, "<input type=\"submit\" name=\"testcgic\" value=\"Submit Request\">\n");
- fprintf(cgiOut, "<input type=\"reset\" value=\"Reset Request\">\n");
- fprintf(cgiOut, "<p>Save the CGI Environment<p>\n");
- fprintf(cgiOut, "Pressing this button will submit the form, then save the CGI environment so that it can be replayed later by calling cgiReadEnvironment (in a debugger, for instance).<p>\n");
- fprintf(cgiOut, "<input type=\"submit\" name=\"saveenvironment\" value=\"Save Environment\">\n");
- fprintf(cgiOut, "</form>\n");
- }
|