Board index » delphi » cgi in turbo pascal or freepascal in windows 95

cgi in turbo pascal or freepascal in windows 95

Could someone please post some simple code in turbo pascal or freepascal
that will do cgi in windows 95?

Thank you

 

Re:cgi in turbo pascal or freepascal in windows 95


In article <391BA598.A750A...@enztecNOS.PAMorg>, dbask

Quote
<db...@enztecNOS.PAMorg> wrote:
> Could someone please post some simple code in turbo pascal or freepascal
> that will do cgi in windows 95?

Here's one for FPC:
<http://www.freepascal.org/fpc-linux/cgi/uncgi-2.0.11.tar.gz>. It works
both on windows and linux.

Jonas

Re:cgi in turbo pascal or freepascal in windows 95


In article <391BA598.A750A...@enztecNOS.PAMorg>,
  dbask <db...@enztecNOS.PAMorg> wrote:
Quote
> Could someone please post some simple code in turbo pascal or
freepascal
> that will do cgi in windows 95?

> Thank you

When you install FreePascal you should find a unit in the RTL called
EZCGI.PAS. This unit does all the CGI basics and it works on Windows or
Linux. I've used it and it works really well with Apache (and probably
any other web server that supports standard CGI).

Garry.

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:cgi in turbo pascal or freepascal in windows 95


Quote
>  dbask <db...@enztecNOS.PAMorg> wrote:
>> Could someone please post some simple code in turbo pascal or
>freepascal
>> that will do cgi in windows 95?

>> Thank you

>When you install FreePascal you should find a unit in the RTL called
>EZCGI.PAS. This unit does all the CGI basics and it works on Windows or
>Linux. I've used it and it works really well with Apache (and probably
>any other web server that supports standard CGI).

This is in the component library FCL I believe.

Re:cgi in turbo pascal or freepascal in windows 95


Quote
Jonas Maebe wrote:

> In article <391BA598.A750A...@enztecNOS.PAMorg>, dbask
> <db...@enztecNOS.PAMorg> wrote:

> > Could someone please post some simple code in turbo pascal or freepascal
> > that will do cgi in windows 95?

> Here's one for FPC:
> <http://www.freepascal.org/fpc-linux/cgi/uncgi-2.0.11.tar.gz>. It works
> both on windows and linux.

> Jonas

I very much appreciate your information but this code is WAY to
complicated for me to make any use out of it at the present time. :(

Would you happen to have a 'Hello World' level freepascal or tpc CGI
program?

Thank you,

Re:cgi in turbo pascal or freepascal in windows 95


Quote
> > > Could someone please post some simple code in turbo pascal or freepascal
> > > that will do cgi in windows 95?

> > Here's one for FPC:
> > <http://www.freepascal.org/fpc-linux/cgi/uncgi-2.0.11.tar.gz>. It works
> > both on windows and linux.

> > Jonas

> I very much appreciate your information but this code is WAY to
> complicated for me to make any use out of it at the present time. :(

> Would you happen to have a 'Hello World' level freepascal or tpc CGI
> program?

The following (old code, untested with current compiler, and quickly
ported from linux) implements a BMP counter.

I chose for BMP because it is a simple format, but some older browsers
don't support BMP unless you view them fullscreen (iow they don't embed
it in the viewed html page)

program cntbmp;
{
    A CGI in pascal. Meant to be a web-counter

    HTML query (different variables) not implemented yet. Need to
reintegrate
    cgi_get again. The first argument will become the variable name.}

uses strings,
     dos;

const max_data = 1000;

type datarec = record
  name,value : string;
  end;

  bmpheadtype = packed record  {Headers for BMP. Putting them in one
record is easier}
           { bit map file header }
           bftype: word;                   { "BM" or $4D42 }
           bfsize: longint;                { size of file in bytes }
           bfreserved1: word;
           bfreserved2: word;
           bfoffbits: longint;             { ^ where graphic data begins

Quote
}

           { bit map information header }
           bisize: longint;                { length of this header, $28
Quote
}

           biwidth: longint;               { pixel width }
           biheight: longint;              { pixel height }
           biplanes: word;                 { = 1 }
           bibitcount: word;               { color bits per pixel }
           bicompression: longint;         { = 0 for no compression }
           bisizeimage: longint;           { = bfsize - bfoffbits }
           bixpel{*word*237}eter: longint;       { x pixels per meter }
           biypel{*word*237}eter: longint;       { y pixels per meter }
           biclrused: longint;             { \ I have never seen these }
           biclrimportant: longint;        { / two used for anything }
         end;

        { 10 characters (character 0..9) , 12x8 dimension
            (some VGA font with four colums zeros deleted)}

CONST Font : ARRAY[0..119] OF BYTE= (
                          0,24,36,36,66,66,66,36,36,24,0,0,
                          0,24,40,72,8,8,8,8,8,8,0,0,
                          0,60,66,2,4,8,16,32,64,126,0,0,
                          0,60,66,2,2,28,2,2,66,60,0,0,
                          0,4,12,20,36,68,254,4,4,4,0,0,
                          0,126,64,64,124,66,2,2,66,60,0,0,
                          0,28,34,64,64,92,98,66,66,60,0,0,
                          0,126,2,2,4,4,8,8,16,16,0,0,
                          0,60,66,66,66,60,66,66,66,60,0,0,
                          0,60,66,66,70,58,2,2,68,56,0,0);

VAR
    Thousands,                   {Counter digits}
    Hundreds,
    Tenths,
    one     : LONGINT;
    hdr     : bmpheadtype;      {BMP header}
    Rows    : LONGINT;          {Generic counter, and counter for
                                 Rows of picture}
    BytePtr : ^BYTE;            {Used to output header}

    data    : array[1..max_data] of datarec;
    i,
    nrdata  : longint;
    p       : PChar;
    literal,
    aname   : boolean;
    F       : file;
    Count   : LONGINT;
    Dummy   : LONGINT;

begin

if StrComp(GetEnv('REQUEST_METHOD'),'GET')<>0 then
   begin
   Writeln ('Content-type: text/html');
   Writeln;
   Writeln ('This script should be referenced with a METHOD of GET');
   halt(1);
   end;

   Writeln ('Content-type: image/x-MS-bmp');
   Writeln;
   p:=GetEnv('QUERY_STRING');

   Assign (f,'count');
   {$I-}
   reset(F,1);
   {$I+}
   IF IORESULT<>0 THEN
    BEGIN
    Assign(F,'count');
    rewrite(F);
    Close(F);
    Assign(F,'count');
    reset(F,1);
    Count:=0;
    END
   ELSE
    BEGIN
     Blockread(F,Count,4,Dummy);
     Seek(F,0);
    END;
    INC(Count);
    BlockWrite(F,Count,4);
    Close(F);

 {Set up BMP-header}

 FillChar(hdr,SIZEOF(Bmpheadtype),0);
 WITH Hdr DO
   BEGIN
    bftype:= $4D42;                 { "BM" or $4D42 }
    bfsize:= 54+8+4*12;             { size of file in bytes }
    bfreserved1:= 0;
    bfreserved2:= 0;
    bfoffbits:= $3E;            { where graphic data begins }
    bisize:= 40;                    { length of this header }
    biwidth:= 32;                  { pixel width }
    biheight:= 12;                 { pixel height }
    biplanes:= 1;                   { =1 }
    bibitcount:= 1;                 { color bits per pixel }
    bicompression:= 0;              { =0 for no compression }
    bisizeimage:= bfsize-bfoffbits;
    bixpel{*word*237}eter:= 0;
    biypel{*word*237}eter:= 0;
    biclrused:= 0;
    biclrimportant:= 0;
  end;

 {Output BMP-header to standard out}

 BytePtr:=@Hdr;
 FOR Rows:=0 TO 14+40-1 DO
   write(CHR(Byteptr[Rows]));

 {Output colors/palette}

 Write(#255,#255,#255,#0,#0,#0,#0,#0);

 { Split up into digits}

 Thousands:=Count DIV 1000; Count:=Count MOD 1000;
 Hundreds:=Count DIV 100; Count:=Count MOD 100;
 Tenths:=Count DIV 10; One:=Count MOD 10;
 IF Thousands>9 THEN Thousands:=9;

 { Print bitmapdata}

 FOR Rows := 11 DOWNTO 0 DO { Rows loop}
  BEGIN
   {Construct bitmap line}
   Write(CHR(Font[12*Thousands+Rows]));
   Write(CHR(Font[12*Hundreds+Rows]));
   Write(CHR(Font[12*Tenths+Rows]));
   Write(CHR(Font[12*One+Rows]));
  END;
end.

Re:cgi in turbo pascal or freepascal in windows 95


Quote
dbask wrote:

> Could someone please post some simple code in turbo pascal or
> freepascal that will do cgi in windows 95?

> Thank you

I had a need for a 'Hello World!' level cgi program and I wanted to use
pascal (turbo pascal, freepascal and console delphi pascal dialect)
because of pascal's great string handling functions, ease of programming
and small and fast exe's. All of which make it a great programming
language for use in cgi programming.

The first 'Hello World!' cgi program I compiled was the following Turbo
C++ code I recieved in an IRC channel :

#include <iostream>
int main()
{
cout << "Content-type: text/html\n\n <html><body><p>Hello
World!</p></body></html>";
return 0;

Quote
}

I translated it into the following turbo pascal, freepascal and console
delphi pascal dialect 'Hello World!' cgi program :

program cgi1;
const nl = chr(13) + chr(10);
begin
write('Content-type: text/html',nl,nl);
write('<html><body>');
write('<p>Hello World!</p>');
write('</body></html>');
end.

Then into the following ADA 'Hello World' cgi program :

With Text_IO; Use Text_IO;
Pragma RangeCheck(off); Pragma Debug(off); Pragma Arithcheck(Off);
Procedure cgi1 Is
Begin
Put("Content-type: text/html"); New_Line; New_Line;
Put("<html><body>");
Put("<p>Hello World!</p>");
Put("</body></html>");
End cgi1;

The Html code that calls the cgi is :

<!-html for cgi->
<HTML>
<BODY>
<TITLE>CGI Example</TITLE>
<H1>CGI Example</H1>
<FORM ACTION="/cgi-bin/cgi1.exe" METHOD="POST">
<INPUT TYPE="submit" VALUE="Press Here">
</FORM>
</BODY>
</HTML>

Of course these programs are completely stripped down stdin/stdout
programs, but that is all that is needed for a starting cgi program.

A cgi 'Hello World' program is very useful to test whether the web
server is set up properly, the internet and computer systems are
functioning as needed, as well as a 'first program' on which to begin
with and gain cgi programming confidence.

Thank you to Jonas Maebe, Garry Wood, and Marco van de Voort for
replying to my inquiry.

With freepascal running on both Windows and Linux it is the way to go.

Re:cgi in turbo pascal or freepascal in windows 95


Quote
> I translated it into the following turbo pascal, freepascal and
console
> delphi pascal dialect 'Hello World!' cgi program :

> program cgi1;
> const nl = chr(13) + chr(10);
> begin
> write('Content-type: text/html',nl,nl);
> write('<html><body>');
> write('<p>Hello World!</p>');
> write('</body></html>');
> end.

I think you should use writeln instead of using constants
to specify end-of-line. Like so

program cgi1;
begin
writeln('Content-type: text/html');
writeln;
write('<html><body>');
write('<p>Hello World!</p>');
write('</body></html>');
end.

Quote
> With freepascal running on both Windows and Linux it is the way to go.

Have you considered using Irie Pascal?
Before I go any further I must admit that I am biased becuase I am
the author of Irie Pascal but I think it is worth considering.

The website is www.irietoools.com.

The current version of Irie Pascal has a problem with
Microsoft Personal Web Server and IIS. A fix for this problem
is ready but I want to test with Apache for Windows before
I release the fix.

If you are at all interested then you can contact me
through this forum or through the website and I will
provide you with more information and the fix when it
becomes available.

PS: Irie Pascal also runs on both Windows and Linux.

Stuart

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:cgi in turbo pascal or freepascal in windows 95


In article <8fo2aq$6g...@nnrp1.deja.com>,

Quote
  sking9...@my-deja.com wrote:

Please, for everyone posting in this thread, trim out
comp.lang.ada, since as far as I can tell this thread
has zero Ada content???

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:cgi in turbo pascal or freepascal in windows 95


In the user manual in the fpc manual section "9.1.1 Data coming through
standard input." there is some "Post Method" CGI code there.

Could someone from fpc tell me why they are checking for '\'? (see code
sippet below from manual). I am unable to generate a '\' in the
URLencoded string from a form using Post Method - so I was wondering
what would generate a '\' in an URLencoded string.

while not eof(input) do
  begin
  literal:=false;
  read(c);
  if c='\' then      <---------****
     begin
     literal:=true;
     read(c);
     end;
  if literal or ((c<>'=') and (c<>'&')) then
     with data[nrdata] do
        if aname then name:=name+c else value:=value+c
  else
     begin
     if c='&' then
         begin
         inc (nrdata);
         aname:=true;
         end
      else
         aname:=false;
      end
  end;

Also are there any buffer overflow concerns using fpc or tpc in CGI
programming?

thanks,

Other Threads