Mail Archives: djgpp/1998/11/08/02:06:00
> It's possible to wite CGI programs with djgpp?.
YES.
> I use OMNI HTTPD server, WIN95 as OS.
Me too. I just finished setting up that. It was quite painful.
> Can you give me a hint, or can you show an exemple?
> Thank you
You need:
-a win32 console (provided by RSXNTDJ)
-a server that support win32 console (Omni httpd is ok, apache too).
- a cgi library for c
I use cgic.c programmed by Thomas Boutell (search the web, is free). It
is great. I have tried other cgi's but this is the best. It creates a
virtual file (called 'cgiout') which will constitutes the standard output.
Thus, every output you want to put in the html page by the cgi, you only
have to write to the file 'cgiout'. Nice !. Also, your main cgi program
MUST include cgiMain and not Main. Read the cgic documentation.
Here I attach a simple html form(test_form.html), a c program (test.c) to
process that form and the makefile. You only need to download 'cgic.h' and
'cgic.c', to compile and to test it.
htttp server:
- put test_form.html in c:\httpd\htdocs
- put test.exe in c:\httpd\cgi-bin
In your browser go to: http://localhost/test_form.html
Fill out the form and submit it. It should work.
Compilation (makefile) (I use RSX-IDE to compile, very nice !, but you can
also compile from the command line of the console rsxwin32 provided with
RSXNTDJ that should be located in C:\djgpp\RSXNTDJ\BIN directory):
all: test.exe
test.exe: test.o cgic.o
gcc -Zwin32 -o test.exe test.o cgic.o
test.o: test.c
gcc -Zwin32 -Wall -c -o test.o test.c
cgic.o: cgic.c
gcc -Zwin32 -Wall -c -o cgic.o cgic.c
test.c
/***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "cgic.h"
/* I have included this just in case, because of some warnings in the
djgpp documentation */
#define extern
int a, b, c;
int Obtain_Int_Form_String(char *);
int cgiMain() {
#if DEBUG
/* Load a saved CGI scenario if we're debugging */
cgiReadEnvironment("/home/boutell/public_html/capcgi.dat");
#endif
cgiHeaderContentType("text/html");
/* Preparing html page */
fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>CGI RESULTS</TITLE></HEAD>\n");
fprintf(cgiOut, "<BODY><CENTER><H1>CGI
RESULTS</H1></CENTER></font>\n");
fprintf(cgiOut, "\n\n");
/* Processing query form */
a = Obtain_Int_Form_String ("value1");
b = Obtain_Int_Form_String ("value2");
c = a*b;
fprintf(cgiOut, "<H3>%d multiplied by %d = %d</H3><BR><BR>\n\n", a,
b, c);
fprintf(cgiOut, "<H2>That's all !</H2>\n\n");
return (0);
}
/****** END MAIN ******/
int Obtain_Int_Form_String(char *field)
{
char array[81];
int value;
cgiFormStringNoNewlines(field, array, 81);
sscanf (array, "%d", &value);
return (value);
}
/***************************************************************************/
test_form.html
<HTML>
<BODY>
<HEAD> <TITLE>MY FIRST SERVER !!! (by Cro)</TITLE> </HEAD>
<H1>FORM THAT MULTIPLIES TWO INTEGER VALUES</H1><P><P><P>
<HR>
<FORM METHOD="POST" ACTION="/cgi-bin/test.exe">
<H3>Enter first value: </H3> <INPUT SIZE=8 NAME="value1" VALUE=""><p> <HR>
<H3>Enter second value: </H3> <INPUT SIZE=8 NAME="value2" VALUE=""><p>
<HR>
<H2>
<INPUT TYPE="submit" VALUE="SUBMIT TO SERVER"> <INPUT TYPE="reset"
VALUE="CLEAR INPUT"> </H2><P>
<HR>
</FORM>
</BODY></HTML>
Good luck !, this is the summary of at least one week trying to install
djgpp and RSXNTDJ in my computer. Now, all is working fine.
Best,
Francisco.
--
-----------------------------------
Francisco Melo Ledermann
Laboratory of Molecular Biophysics. The Rockefeller University.
1230 York Avenue, #270, New York, NY 10021-6399.
(1) (212) 879 5404 Home
(1) (212) 327 7206 Work (Voice)
(1) (212) 327 7540 Work (FAX)
www server: http://www.fundp.ac.be/pub/ANOLEA.html
home page: http://guitar.rockefeller.edu/~fmelo/index.html
- Raw text -