Changeset 6


Ignore:
Timestamp:
Aug 11, 2010, 2:51:39 PM (14 years ago)
Author:
djay
Message:

Update the cgic library to let run the ZOO Kernel from the command line.

Location:
trunk/thirds/cgic206
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/thirds/cgic206/Makefile

    r1 r6  
    33AR=ar
    44RANLIB=ranlib
    5 LIBS=-L./ -lcgic ../fcgi-2.4.0/libfcgi/.libs/libfcgi.a
     5LIBS=-L./ -lcgic /usr/lib/libfcgi.a
    66CFLAGS=-I//var/www/localhost/include
    77
  • trunk/thirds/cgic206/cgic.c

    r1 r6  
    136136        cgiGetenv(&cgiServerPort, "SERVER_PORT");
    137137        cgiGetenv(&cgiRequestMethod, "REQUEST_METHOD");
     138        if(strcmp(cgiRequestMethod,"")==0 && argc>=1)
     139                cgiRequestMethod="GET";
    138140        cgiGetenv(&cgiPathInfo, "PATH_INFO");
    139141        cgiGetenv(&cgiPathTranslated, "PATH_TRANSLATED");
    140142        cgiGetenv(&cgiScriptName, "SCRIPT_NAME");
    141143        cgiGetenv(&cgiQueryString, "QUERY_STRING");
     144        if(strcmp(cgiQueryString,"")==0 && argc>=2){
     145                cgiQueryString=argv[1];
     146        }else
     147                fprintf(stderr,"cgiQueryString : %s\n",cgiQueryString);
    142148        cgiGetenv(&cgiRemoteHost, "REMOTE_HOST");
    143149        cgiGetenv(&cgiRemoteAddr, "REMOTE_ADDR");
     
    190196        cgiGetenv(&cgiContentLengthString, "CONTENT_LENGTH");
    191197        cgiContentLength = atoi(cgiContentLengthString);       
     198        if(cgiContentLength==0 && argc>=2){
     199                cgiContentLength=strlen(argv[1]);
     200        }
     201        fprintf(stderr,"%d\n",cgiContentLength);
    192202        cgiGetenv(&cgiAccept, "HTTP_ACCEPT");
    193203        cgiGetenv(&cgiUserAgent, "HTTP_USER_AGENT");
     
    208218#endif /* WIN32 */
    209219        cgiFormEntryFirst = 0;
    210         cgiIn = stdin;
    211         cgiOut = stdout;
     220        cgiIn = FCGI_stdin;
     221        cgiOut = FCGI_stdout;
    212222        cgiRestored = 0;
    213223
     
    293303        cgiFreeResources();
    294304        }
     305        FCGI_Finish();
    295306        return result;
    296307}
  • trunk/thirds/cgic206/cgictest.c

    r1 r6  
    2323        cgiReadEnvironment("/home/boutell/public_html/capcgi.dat");
    2424#endif
    25         cgiHeaderContentType("text/html");
    26         fprintf(cgiOut, "<HTML><HEAD>\n");
    27         fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
    28         fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n");
     25        dup2(cgiOut,stdout);
     26        printf("Content-Type: text/html; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     27        //cgiHeaderContentType("text/html");
     28        printf( "<HTML><HEAD>\n");
     29        printf( "<TITLE>cgic test</TITLE></HEAD>\n");
     30        printf( "<BODY><H1>cgic test</H1>\n");
    2931        Name();
    3032        Address();
     
    3638        NonExButtons();
    3739        RadioButtons();
    38         fprintf(cgiOut, "</BODY></HTML>\n");
     40        printf( "</BODY></HTML>\n");
    3941        return 0;
    4042}
     
    4547        switch (result) {
    4648                case cgiFormSuccess:
    47                 fprintf(cgiOut, "Name fetched, result code: cgiFormSuccess<br>\n");
     49                printf( "Name fetched, result code: cgiFormSuccess<br>\n");
    4850                break;
    4951                case cgiFormTruncated:
    50                 fprintf(cgiOut, "Name fetched, result code: cgiFormTruncated<br>\n");
     52                printf( "Name fetched, result code: cgiFormTruncated<br>\n");
    5153                break;
    5254                case cgiFormEmpty:
    53                 fprintf(cgiOut, "Name fetched, result code: cgiFormEmpty<br>\n");
     55                printf( "Name fetched, result code: cgiFormEmpty<br>\n");
    5456                break;
    5557                case cgiFormNotFound:
    56                 fprintf(cgiOut, "Name fetched, result code: cgiFormNotFound<br>\n");
     58                printf( "Name fetched, result code: cgiFormNotFound<br>\n");
    5759                break;
    5860                case cgiFormMemory:
    59                 fprintf(cgiOut, "Name fetched, result code: cgiFormMemory<br>\n");
     61                printf( "Name fetched, result code: cgiFormMemory<br>\n");
    6062                break;
    6163                default:
    62                 fprintf(cgiOut, "Name fetched, unexpected result code: %d\n", result);
     64                printf( "Name fetched, unexpected result code: %d\n", result);
    6365                break;
    6466        }       
    65         fprintf(cgiOut, "Name: %s<BR>\n", name);
     67        printf( "Name: %s<BR>\n", name);
    6668}
    6769       
     
    6971        char address[241];
    7072        cgiFormString("address", address, 241);
    71         fprintf(cgiOut, "Address: <PRE>\n%s</PRE>\n", address);
     73        printf( "Address: <PRE>\n%s</PRE>\n", address);
    7274}
    7375
    7476void Hungry() {
    7577        if (cgiFormCheckboxSingle("hungry") == cgiFormSuccess) {
    76                 fprintf(cgiOut, "I'm Hungry!<BR>\n");
     78                printf( "I'm Hungry!<BR>\n");
    7779        } else {
    78                 fprintf(cgiOut, "I'm Not Hungry!<BR>\n");
     80                printf( "I'm Not Hungry!<BR>\n");
    7981        }
    8082}
     
    8385        double temperature;
    8486        cgiFormDoubleBounded("temperature", &temperature, 80.0, 120.0, 98.6);
    85         fprintf(cgiOut, "My temperature is %f.<BR>\n", temperature);
     87        printf( "My temperature is %f.<BR>\n", temperature);
    8688}
    8789       
     
    8991        int frogsEaten;
    9092        cgiFormInteger("frogs", &frogsEaten, 0);
    91         fprintf(cgiOut, "I have eaten %d frogs.<BR>\n", frogsEaten);
     93        printf( "I have eaten %d frogs.<BR>\n", frogsEaten);
    9294}
    9395
     
    101103        int colorChoice;
    102104        cgiFormSelectSingle("colors", colors, 3, &colorChoice, 0);
    103         fprintf(cgiOut, "I am: %s<BR>\n", colors[colorChoice]);
     105        printf( "I am: %s<BR>\n", colors[colorChoice]);
    104106}       
    105107
     
    118120                flavorChoices, &invalid);
    119121        if (result == cgiFormNotFound) {
    120                 fprintf(cgiOut, "I hate ice cream.<p>\n");
     122                printf( "I hate ice cream.<p>\n");
    121123        } else {       
    122                 fprintf(cgiOut, "My favorite ice cream flavors are:\n");
    123                 fprintf(cgiOut, "<ul>\n");
     124                printf( "My favorite ice cream flavors are:\n");
     125                printf( "<ul>\n");
    124126                for (i=0; (i < 3); i++) {
    125127                        if (flavorChoices[i]) {
    126                                 fprintf(cgiOut, "<li>%s\n", flavors[i]);
     128                                printf( "<li>%s\n", flavors[i]);
    127129                        }
    128130                }
    129                 fprintf(cgiOut, "</ul>\n");
     131                printf( "</ul>\n");
    130132        }
    131133}
     
    146148        cgiFormRadio("age", ages, 4, &ageChoice, 0);
    147149
    148         fprintf(cgiOut, "Age of Truck: %s (method #1)<BR>\n",
     150        printf( "Age of Truck: %s (method #1)<BR>\n",
    149151                ages[ageChoice]);
    150152
     
    157159        cgiFormString("age", ageText, 10);
    158160
    159         fprintf(cgiOut, "Age of Truck: %s (method #2)<BR>\n", ageText);
     161        printf( "Age of Truck: %s (method #2)<BR>\n", ageText);
    160162}
    161163
     
    178180                since votes for nonexistent candidates should probably
    179181                be discounted... */
    180         fprintf(cgiOut, "Votes (method 1):<BR>\n");
     182        printf( "Votes (method 1):<BR>\n");
    181183        result = cgiFormCheckboxMultiple("vote", votes, 4,
    182184                voteChoices, &invalid);
    183185        if (result == cgiFormNotFound) {
    184                 fprintf(cgiOut, "I hate them all!<p>\n");
     186                printf( "I hate them all!<p>\n");
    185187        } else {       
    186                 fprintf(cgiOut, "My preferred candidates are:\n");
    187                 fprintf(cgiOut, "<ul>\n");
     188                printf( "My preferred candidates are:\n");
     189                printf( "<ul>\n");
    188190                for (i=0; (i < 4); i++) {
    189191                        if (voteChoices[i]) {
    190                                 fprintf(cgiOut, "<li>%s\n", votes[i]);
     192                                printf( "<li>%s\n", votes[i]);
    191193                        }
    192194                }
    193                 fprintf(cgiOut, "</ul>\n");
     195                printf( "</ul>\n");
    194196        }
    195197
     
    198200                than the code and invented responses are not a danger
    199201                or can be checked in some other way. */
    200         fprintf(cgiOut, "Votes (method 2):<BR>\n");
     202        printf( "Votes (method 2):<BR>\n");
    201203        result = cgiFormStringMultiple("vote", &responses);
    202204        if (result == cgiFormNotFound) {       
    203                 fprintf(cgiOut, "I hate them all!<p>\n");
     205                printf( "I hate them all!<p>\n");
    204206        } else {
    205207                int i = 0;
    206                 fprintf(cgiOut, "My preferred candidates are:\n");
    207                 fprintf(cgiOut, "<ul>\n");
     208                printf( "My preferred candidates are:\n");
     209                printf( "<ul>\n");
    208210                while (responses[i]) {
    209                         fprintf(cgiOut, "<li>%s\n", responses[i]);
     211                        printf( "<li>%s\n", responses[i]);
    210212                        i++;
    211213                }
    212                 fprintf(cgiOut, "</ul>\n");
     214                printf( "</ul>\n");
    213215        }
    214216        /* We must be sure to free the string array or a memory
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png