"Fossies" - the Fresh Open Source Software Archive

Member "libgcgi.a-0.9.5/examples/gcgitest.c" (22 Jun 2002, 3053 Bytes) of package /linux/www/old/gcgi-0.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include "gcgi.h"
    4 #include "common.h"
    5 
    6 FILE *out;
    7 int main (int argc, char *argv[], char *envp[]) {
    8 
    9   char tstring[128], qstring[128], *qs, **bands, tf1[256], tf2[256], mulstr[128], **mmulstr;
   10   int i, j, k, l, m, *n, o;
   11   double d;
   12   char *morebands[] = {"phish", "wsp", "moe." };
   13   char *colors[]    = {"red", "green", "blue" };
   14 
   15   //gcgiDebug("../examples/urlencodedenv", "../examples/urlencodedquery");
   16 
   17   //out = fopen("./buglog.txt","a");
   18   
   19   if (initCgi() < 0)
   20     return -1;
   21   
   22   //gcgiSaveEnvVariables();
   23 
   24   gcgiNumFormFields(&k);
   25   
   26   gcgiNumFields("band",&l);
   27 
   28   gcgiFetchString("string", tstring, 128);
   29 
   30   gcgiFetchStringNoNewLines("nonewlines", qstring, 128);
   31 
   32   gcgiFetchInteger("integer", &i, -1);
   33 
   34   gcgiFetchDouble("double", &d, -1.0);
   35 
   36   gcgiFetchCheckbox("choice", &j);
   37 
   38   gcgiFetchMultipleString("band", &bands);
   39 
   40   n = XMALLOC(int, 3);
   41 
   42   gcgiFetchMultipleCheckbox("band", morebands, 3, &n);
   43 
   44   gcgiFetchSelectIndex("radio", colors, 3, &o, -1);
   45 
   46   gcgiFetchString("tf1", tf1, 255);
   47 
   48   gcgiFetchStringNoNewLines("tf2", tf2, 255);
   49 
   50   qs = gcgiFetchEnvVar(gcgiQueryString);
   51 
   52   fprintf(gcgiOut,"Content-Type: Text/HTML\n\n");
   53 
   54   fprintf(gcgiOut,
   55       "<html>\n"
   56       "<head>\n"
   57       "    <title>GCGI Test Results</title>\n"
   58       "</head>\n\n"
   59       "<body>\n"
   60       "    <p><b>Total number of form fields:</b> %d</p>\n"
   61       "    <p><b>Text String:</b>  %s</p>\n"
   62       "    <p><b>Text String (no new lines):</b>  %s</p>\n"
   63       "    <p><b>Integer:</b>      %d</p>\n"
   64       "    <p><b>Double:</b>       %f</p>\n"
   65       "    <p><b>Single Checkbox:</b> %s</p>\n"
   66       "    <p><b>Number of checkboxes for \"band\":</b> %d\n"
   67       "    <p><b>Bands:</b><ol>\n",
   68       k, tstring, qstring, i, d, j? "checked":"unchecked", l);
   69 
   70   if (bands != NULL)
   71     for (m = 0; bands[m] != NULL; m++) {
   72       fprintf(gcgiOut,"<li>%s</li>\n",bands[m]);
   73     }
   74 
   75   fprintf(gcgiOut,
   76       "</ol></p>\n"
   77       "<p><b>Radio Button Selected Index:</b> %d"
   78       "<p><b>Bands that were checked:</b><ol> ",o);
   79 
   80   for (m = 0; m < 3; m++)
   81     fprintf(gcgiOut,"<li><b>%s:</b> %s</li>",morebands[m], n[m]? "checked":"unchecked");
   82 
   83   fprintf(gcgiOut,"</ol>\n<p><b>Fetch Multiple Strings one at a time:</b>\n<ol>\n");
   84   while (gcgiFetchStringNext("mulstr", mulstr, 127) != GCGIFIELDNOTFOUND)
   85     fprintf(gcgiOut,"<li>%s</li>", mulstr);
   86 
   87   gcgiResetMultipleField("mulstr");
   88 
   89   gcgiFetchMultipleString("mulstr", &mmulstr);
   90 
   91   fprintf(gcgiOut, "</ol>\n<p><b>Fetch Multiple Strings all at once:</b>\n<ol>\n");
   92   for (m = 0; mmulstr[m] != NULL; m++) {
   93     fprintf(gcgiOut,"<li>%s</li>\n", mmulstr[m]);
   94   }
   95   fprintf(gcgiOut, "</ol>\n</p>\n");
   96 
   97   gcgiFreeMultipleString(mmulstr);
   98 
   99   fprintf(gcgiOut,
  100       "<p><b>Text Field One:</b><br><pre>%s</pre><br>\n"
  101       "<p><b>Text Field Two (No Newlines):</b><br><pre>%s</pre><br>\n",
  102       tf1, tf2);
  103 
  104   fprintf(gcgiOut,
  105       "</p>\n"
  106       "<pre>\n"
  107       "QUERY_STRING: %s\n",
  108       qs);
  109   printQuery(gcgiOut);
  110   fprintf(gcgiOut,
  111       "</pre>\n"
  112       "</body>\n"
  113       "</html>\n");
  114   
  115   gcgiFreeMultipleString(bands);
  116   XFREE(n);
  117 
  118   freeCgi();
  119 
  120   return 0;
  121 }