caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* "Hello web" please
@ 2006-07-08 15:05 Jonathan Hayward http://JonathansCorner.com
  2006-07-08 20:47 ` [Caml-list] " Christophe TROESTLER
  2006-07-10 14:49 ` Jonathan Hayward http://JonathansCorner.com
  0 siblings, 2 replies; 14+ messages in thread
From: Jonathan Hayward http://JonathansCorner.com @ 2006-07-08 15:05 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 840 bytes --]

I'm trying to figure out how to use CamlGI with OCaml, and am for the moment
working on hello world basics: for instance, how do I get ocaml to use a
specific library?

Could you send me a "Hello web" OCaml script that uses CamlGI and prints a
webpage saying only "Yes", "No", "Other" or "Undefined" depending on whether
the CGI variable "foo" has value 1, 0, some other defined value, or is
undefined (never mind about multiple values)?

If I see the syntax for that, I think I will be in a position to start
tinkering.

-- 
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!

[-- Attachment #2: Type: text/html, Size: 1074 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-08 15:05 "Hello web" please Jonathan Hayward http://JonathansCorner.com
@ 2006-07-08 20:47 ` Christophe TROESTLER
  2006-07-10 15:02   ` Jonathan Hayward http://JonathansCorner.com
  2006-07-10 14:49 ` Jonathan Hayward http://JonathansCorner.com
  1 sibling, 1 reply; 14+ messages in thread
From: Christophe TROESTLER @ 2006-07-08 20:47 UTC (permalink / raw)
  To: christos.jonathan.hayward; +Cc: caml-list

[-- Attachment #1: Type: Text/Plain, Size: 936 bytes --]

On Sat, 8 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" <christos.jonathan.hayward@gmail.com> wrote:
> 
> I'm trying to figure out how to use CamlGI with OCaml, [...]

CamlGI code has been integrated into the Netcgi component
<https://gps.dynxs.de/wwwsvn/trunk/code/src/netcgi/?root=lib-ocamlnet2>
of OcamlNet-2 <https://gps.dynxs.de/openapps/svnindex.cgi>, please use
that instead.

> [...] script that [...] prints a webpage saying only "Yes", "No",
> "Other" or "Undefined" depending on whether the CGI variable "foo"
> has value 1, 0, some other defined value, or is undefined (never
> mind about multiple values)?

You can find examples in the examples/ directory (add.ml is a very
simple one).  As for the specific example you desire, it is attached.
It is maybe a bit more complex that you expected because it
demonstrates additional features (text escaping, setting the header,
buffered output).

Hope it helps,
ChriS

[-- Attachment #2: hello.ml --]
[-- Type: Text/Plain, Size: 1213 bytes --]

open Netcgi

let text = Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&", double quotes, and Latin 1
     characters as character entities.  E.g. text "<" = "&lt;", and
     text "ä" = "&auml;" *)

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =
  let out = cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
        \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
  out ("<html>\n<head><title>" ^ text title ^"</title></head>
<body>\n");
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=\"iso-8859-1\""
    ();
  let foo = cgi#argument_value "foo"
  let html = match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run by
   another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: "Hello web" please
  2006-07-08 15:05 "Hello web" please Jonathan Hayward http://JonathansCorner.com
  2006-07-08 20:47 ` [Caml-list] " Christophe TROESTLER
@ 2006-07-10 14:49 ` Jonathan Hayward http://JonathansCorner.com
  2006-07-10 15:14   ` [Caml-list] " Christophe TROESTLER
  1 sibling, 1 reply; 14+ messages in thread
From: Jonathan Hayward http://JonathansCorner.com @ 2006-07-10 14:49 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 875 bytes --]

I've been urged to use Netcgi from OcamlNet-2 from
http://www.ocaml-programming.de/packages/ocamlnet-2.2test2.tar.gz .

When I tried to configure OcamlNet2 it said it needed PCRE -- and even
though I installed what was labelled as PCRE from
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ , OcamlNet-2 refused
to configure because it couldn't recognize PCRE as being installed, and when
I commented out the test for PCRE in the configure it still couldn't find
it.

How can I install OcamlNet-2? Right now I'm stuck on getting it to recognize
PCRE.

-- 
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!

[-- Attachment #2: Type: text/html, Size: 1186 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-08 20:47 ` [Caml-list] " Christophe TROESTLER
@ 2006-07-10 15:02   ` Jonathan Hayward http://JonathansCorner.com
  2006-07-10 15:48     ` Christophe TROESTLER
  2006-07-10 15:51     ` Jonathan Roewen
  0 siblings, 2 replies; 14+ messages in thread
From: Jonathan Hayward http://JonathansCorner.com @ 2006-07-10 15:02 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 4932 bytes --]

I need help getting Ocamlnet to work at a basic level.

I tried running the script from the command-like to more easily access
diagnostic output. What should the shebang line say? Right now I have the
following (mostly) paste of the demo script, plus shebang line; when I run
it from within apache I get an internal server error. (A copy of the command
line output follows the script).

--

#!/usr/local/bin/ocaml
open Netcgi

let text = Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&", double quotes, and Latin 1
     characters as character entities.  E.g. text "<" = "&lt;", and
     text "ä" = "&auml;" *)

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =
  let out = cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
        \" http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
  out ("<html>\n<head><title>" ^ text title ^"</title></head>
<body>\n");
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=\"iso-8859-1\""
    ();
  let foo = cgi#argument_value "foo"
  let html = match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run by
   another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main


--

Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
./demo.ml: line 4: let: =: syntax error: operand expected (error token is
"=")
./demo.ml: line 5: demo.ml: command not found
./demo.ml: line 6: characters: command not found
./demo.ml: line 7: text: command not found
./demo.ml: line 9: demo.ml: command not found
./demo.ml: line 10: syntax error near unexpected token `('
./demo.ml: line 10: `let html_page (cgi:cgi) title html ='


--

On 7/8/06, Christophe TROESTLER <Christophe.Troestler@umh.ac.be> wrote:
>
> On Sat, 8 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" <
> christos.jonathan.hayward@gmail.com> wrote:
> >
> > I'm trying to figure out how to use CamlGI with OCaml, [...]
>
> CamlGI code has been integrated into the Netcgi component
> <https://gps.dynxs.de/wwwsvn/trunk/code/src/netcgi/?root=lib-ocamlnet2>
> of OcamlNet-2 <https://gps.dynxs.de/openapps/svnindex.cgi>, please use
> that instead.
>
> > [...] script that [...] prints a webpage saying only "Yes", "No",
> > "Other" or "Undefined" depending on whether the CGI variable "foo"
> > has value 1, 0, some other defined value, or is undefined (never
> > mind about multiple values)?
>
> You can find examples in the examples/ directory (add.ml is a very
> simple one).  As for the specific example you desire, it is attached.
> It is maybe a bit more complex that you expected because it
> demonstrates additional features (text escaping, setting the header,
> buffered output).
>
> Hope it helps,
> ChriS
>
>
> open Netcgi
>
> let text = Netencoding.Html.encode_from_latin1
>   (* This function encodes "<", ">", "&", double quotes, and Latin 1
>      characters as character entities.  E.g. text "<" = "&lt;", and
>      text "ä" = "&auml;" *)
>
> (* Normally you would use a template system instead of this *)
> let html_page (cgi:cgi) title html =
>   let out = cgi#out_channel#output_string in
>   out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
>         \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
>   out ("<html>\n<head><title>" ^ text title ^"</title></head>
> <body>\n");
>   out html;
>   out "</body>\n</html>"
>
> let main (cgi:cgi) =
>   cgi#set_header
>     ~cache:`No_cache
>     ~content_type:"text/html; charset=\"iso-8859-1\""
>     ();
>   let foo = cgi#argument_value "foo"
>   let html = match foo with
>     | "1" -> "Yes"
>     | "0" -> "No"
>     | _ -> "Undefined" in
>   html_page cgi foo html
>
> (* You can buffer or not the output.  If buffered you can rollback
>    (useful in case of error). You can replace Netcgi_cgi.run by
>    another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
> let () =
>   let buffered _ ch = new Netchannels.buffered_trans_channel ch in
>   Netcgi_cgi.run ~output_type:(`Transactional buffered) main
>
>
>


-- 
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!

[-- Attachment #2: Type: text/html, Size: 7381 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Re: "Hello web" please
  2006-07-10 14:49 ` Jonathan Hayward http://JonathansCorner.com
@ 2006-07-10 15:14   ` Christophe TROESTLER
  0 siblings, 0 replies; 14+ messages in thread
From: Christophe TROESTLER @ 2006-07-10 15:14 UTC (permalink / raw)
  To: christos.jonathan.hayward; +Cc: caml-list

On Mon, 10 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" <christos.jonathan.hayward@gmail.com> wrote:
> 
> I've been urged to use Netcgi from OcamlNet-2 from
> http://www.ocaml-programming.de/packages/ocamlnet-2.2test2.tar.gz .

Ok.  I was pointing you to the subversion repository so you can browse
the files and see whether that is what you need.  You can download the
files with

  svn co https://gps.dynxs.de/svn/lib-ocamlnet2/trunk/ lib-ocamlnet2

> When I tried to configure OcamlNet2 it said it needed PCRE -- and even
> though I installed what was labelled as PCRE from
> ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ , OcamlNet-2 refused
> to configure because it couldn't recognize PCRE as being installed, and when
> I commented out the test for PCRE in the configure it still couldn't find
> it.

You need the OCaml interface to the C library.  Get it here:
	http://ocaml.info/home/ocaml_sources.html#toc13

Hope it helps,
ChriS


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-10 15:02   ` Jonathan Hayward http://JonathansCorner.com
@ 2006-07-10 15:48     ` Christophe TROESTLER
  2006-07-11 14:23       ` Jonathan Hayward http://JonathansCorner.com
  2006-07-10 15:51     ` Jonathan Roewen
  1 sibling, 1 reply; 14+ messages in thread
From: Christophe TROESTLER @ 2006-07-10 15:48 UTC (permalink / raw)
  To: christos.jonathan.hayward; +Cc: caml-list

[-- Attachment #1: Type: Text/Plain, Size: 745 bytes --]

On Mon, 10 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" <christos.jonathan.hayward@gmail.com> wrote:
> 
> What should the shebang line say?
> #!/usr/local/bin/ocaml

  #!/usr/local/bin/ocamlrun ocaml

You also need to load the necessary libraries:

  #load "pcre.cma";;
  #load "unix.cma";;
  ...
  #load "netcgi.cma";;

(see attached file).

> when I run it from within apache I get an internal server error. (A
> copy of the command line output follows the script).

Do you run is as CGI ?  Also beware that the newer Netcgi module is
not in the tarball you mentioned.  Get the SVN version if you want to
use it (I am not sure the build system already compiles it as its
insersion is very recent but I can fix that).

Cheers,
ChriS

[-- Attachment #2: script.ml --]
[-- Type: Text/Plain, Size: 1463 bytes --]

#!/usr/bin/ocamlrun ocaml

(* Change the directories as needed for your system. *)
#directory "+pcre";;
#load "pcre.cma";;
#load "unix.cma";;
#directory "+netstring";;
#load "netstring.cma";;
#directory "/path/to/netcgi/";;
#load "netcgi.cma";;

open Netcgi

let text = Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&", double quotes, and Latin 1
     characters as character entities.  E.g. text "<" = "&lt;", and
     text "ä" = "&auml;" *)

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =
  let out = cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
        \" http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
  out ("<html>\n<head><title>" ^ text title ^"</title></head>
<body>\n");
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=\"iso-8859-1\""
    ();
  let foo = cgi#argument_value "foo" in
  let html = match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run by
   another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-10 15:02   ` Jonathan Hayward http://JonathansCorner.com
  2006-07-10 15:48     ` Christophe TROESTLER
@ 2006-07-10 15:51     ` Jonathan Roewen
  1 sibling, 0 replies; 14+ messages in thread
From: Jonathan Roewen @ 2006-07-10 15:51 UTC (permalink / raw)
  To: Jonathan Hayward http://JonathansCorner.com; +Cc: caml-list

> #!/usr/local/bin/ocaml

you might want to try:

#!/usr/local/bin/ocamlrun ocaml

This is what I had to do with my webhost for some reason.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-10 15:48     ` Christophe TROESTLER
@ 2006-07-11 14:23       ` Jonathan Hayward http://JonathansCorner.com
  2006-07-11 14:33         ` Maxence Guesdon
  2006-07-11 14:42         ` Christophe TROESTLER
  0 siblings, 2 replies; 14+ messages in thread
From: Jonathan Hayward http://JonathansCorner.com @ 2006-07-11 14:23 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2623 bytes --]

I now have the script below. I was slightly surprised it didn't get an error
as I had it load /usr/lib/ocaml/3.08.3/cgi/netcgi.cma, and the directory
contains:

cgi.a       netcgi_env.cmi      netcgi_fcgi.mli         netcgi_jserv.cmi
cgi.cma     netcgi_env.mli      netcgi_jserv_ajp12.cmi  netcgi_jserv.mli
cgi.cmxa    netcgi_fcgi_10.cmi  netcgi_jserv_ajp12.mli  netcgi.mli
META        netcgi_fcgi_10.mli  netcgi_jserv_app.cmi    netcgi_types.cmi
netcgi.cmi  netcgi_fcgi.cmi     netcgi_jserv_app.mli    netcgi_types.mli



When I run it, I get a different and shorter error message:

File "./demo.ml", line 35, characters 2-5:
Syntax error

The line in question is:

    | "1" -> "Yes"

Is there some irritating little syntax error around line 35?

--

#!/usr/bin/ocamlrun ocaml

(* Change the directories as needed for your system. *)
#directory "+pcre";;
#load "pcre.cma";;
#load "unix.cma";;
#directory "+netstring";;
#load "netstring.cma";;
#directory "/usr/lib/ocaml/3.08.3/cgi/";;
#load "netcgi.cma";;

open Netcgi

let text = Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&", double quotes, and Latin 1
     characters as character entities.  E.g. text "<" = "&lt;", and
     text "ä" = "&auml;" *)

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =
  let out = cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
        \" http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
  out ("<html>\n<head><title>" ^ text title ^"</title></head>
<body>\n");
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=\"iso-8859-1\""
    ();
  let foo = cgi#argument_value "foo"
  let html = match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run by
   another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main


-- 
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!

[-- Attachment #2: Type: text/html, Size: 4099 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-11 14:23       ` Jonathan Hayward http://JonathansCorner.com
@ 2006-07-11 14:33         ` Maxence Guesdon
  2006-07-11 14:42         ` Christophe TROESTLER
  1 sibling, 0 replies; 14+ messages in thread
From: Maxence Guesdon @ 2006-07-11 14:33 UTC (permalink / raw)
  To: caml-list

On Tue, 11 Jul 2006 10:23:24 -0400
"Jonathan Hayward http://JonathansCorner.com"
>...

Hello,
 
> let main (cgi:cgi) =
>   cgi#set_header
>     ~cache:`No_cache
>     ~content_type:"text/html; charset=\"iso-8859-1\""
>     ();
>   let foo = cgi#argument_value "foo"
Maybe "in" is missing here ?            ^^

Hope this helps,



-- 
Maxence Guesdon
http://yquem.inria.fr/~guesdon/
http://devel.inria.fr/rocq/


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-11 14:23       ` Jonathan Hayward http://JonathansCorner.com
  2006-07-11 14:33         ` Maxence Guesdon
@ 2006-07-11 14:42         ` Christophe TROESTLER
  2006-07-11 17:40           ` Jonathan Hayward http://JonathansCorner.com
  1 sibling, 1 reply; 14+ messages in thread
From: Christophe TROESTLER @ 2006-07-11 14:42 UTC (permalink / raw)
  To: christos.jonathan.hayward; +Cc: caml-list

On Tue, 11 Jul 2006, "Jonathan Hayward http://JonathansCorner.com" <christos.jonathan.hayward@gmail.com> wrote:
> 
> File "./demo.ml", line 35, characters 2-5:
> Syntax error
> 
> The line in question is:
> 
>     | "1" -> "Yes"
> 
> Is there some irritating little syntax error around line 35?

Well, I do not know the reason but it is the second time "you"
suppresses the necessary "in".  The line

>   let foo = cgi#argument_value "foo"

should read

  let foo = cgi#argument_value "foo" in

(it is present in my attached file, what happened???)

ChriS


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-11 14:42         ` Christophe TROESTLER
@ 2006-07-11 17:40           ` Jonathan Hayward http://JonathansCorner.com
  2006-07-11 18:14             ` Christophe TROESTLER
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Hayward http://JonathansCorner.com @ 2006-07-11 17:40 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2527 bytes --]

Thank you; it seems to compile now, but it's crashing (runtime); there's a
library installed on my system that it's not picking up.

The error message is:

jonathan@inner-sanctum:~/csi/ml$ ocamlrun ocaml ./demo.ml
Cannot load required shared library dllpcre_stubs.
Reason: dllpcre_stubs.so: cannot open shared object file: No such file or
directory.
Reference to undefined global `Pcre'
jonathan@inner-sanctum:~/csi/ml$

Slocate finds the library in /usr/lib/ocaml/3.08.3/stublibs/dllpcre_stubs.so
; do I need to tell the script to search there?

The script (missing " in" appended to the appropriate line) is:

#!/usr/bin/ocamlrun ocaml

(* Change the directories as needed for your system. *)
#directory "/usr/lib/ocaml/3.08.3/pcre";;
#load "pcre.cma";;
#load "unix.cma";;
#directory "/usr/lib/ocaml/3.08.3/netstring";;
#load "netstring.cma";;
#directory "/usr/lib/ocaml/3.08.3/cgi/";;
#load "netcgi.cma";;

open Netcgi

let text = Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&", double quotes, and Latin 1
     characters as character entities.  E.g. text "<" = "&lt;", and
     text "ä" = "&auml;" *)

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =
  let out = cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
        \" http://www.w3.org/TR/REC-html40/strict.dtd\">\n";
  out ("<html>\n<head><title>" ^ text title ^"</title></head>
<body>\n");
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=\"iso-8859-1\""
    ();
  let foo = cgi#argument_value "foo" in
  let html = match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace Netcgi_cgi.run by
   another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main

--



-- 
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!

[-- Attachment #2: Type: text/html, Size: 3615 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-11 17:40           ` Jonathan Hayward http://JonathansCorner.com
@ 2006-07-11 18:14             ` Christophe TROESTLER
  2006-07-11 20:35               ` Jonathan Hayward http://JonathansCorner.com
  0 siblings, 1 reply; 14+ messages in thread
From: Christophe TROESTLER @ 2006-07-11 18:14 UTC (permalink / raw)
  To: christos.jonathan.hayward
  Cc: O'Caml Beginners Mailing List, O'Caml  Mailing List

On Tue, 11 Jul 2006, "Jonathan Hayward" <christos.jonathan.hayward@gmail.com> wrote:
> 
> Thank you; it seems to compile now, but it's crashing (runtime); there's a
> library installed on my system that it's not picking up.

The way it is, the script is NOT compiled, it is interpreted.  I
recommend you compile it to bytecode
(http://caml.inria.fr/pub/docs/manual-ocaml/manual022.html) or native
code (http://caml.inria.fr/pub/docs/manual-ocaml/manual025.html)
however.

> jonathan@inner-sanctum:~/csi/ml$ ocamlrun ocaml ./demo.ml
> Cannot load required shared library dllpcre_stubs.
> Reason: dllpcre_stubs.so: cannot open shared object file: No such file or
> directory.

I do not have that problem (get Debian :).  Does the script run from
the command line?  Maybe setting the environment variable
LD_LIBRARY_PATH can help?

I propose to continue this conversation on the beginner mailing list
(http://groups.yahoo.com/group/ocaml_beginners/) to which I also sent
this message.

ChriS


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-11 18:14             ` Christophe TROESTLER
@ 2006-07-11 20:35               ` Jonathan Hayward http://JonathansCorner.com
  2006-07-12 11:20                 ` Jonathan Roewen
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Hayward http://JonathansCorner.com @ 2006-07-11 20:35 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1917 bytes --]

>
> I propose to continue this conversation on the beginner mailing list
> (http://groups.yahoo.com/group/ocaml_beginners/) to which I also sent
> this message.


Sounds like a good idea; I'm waiting for my registration to be processed. In
the meantime, I'd really like to have this working soon, and am having more
trouble than I've had getting a first basic program working (in Python,
Perl, Java, etc.), and be on to asking real questions instead of "How do I
get this to run?"

At the moment I get:

jonathan@inner-sanctum:~/csi/ml$ !.
./demo.ml
Error while loading "/usr/lib/ocaml/3.08.3/netstring/netstring.cma":
interface mismatch on Filename
Error while loading "/usr/lib/ocaml/3.08.3/netstring/netstring.cma":
interface mismatch on Filename.
Preprocessor error

The segment of the script that I think is responsible for this is:

#directory "/usr/lib/ocaml/3.08.3/pcre";;
#load "pcre.cma";;
#directory "/usr/lib/ocaml/3.08.3";;
#load "unix.cma";;
#directory "/usr/lib/ocaml/3.08.3/netstring";;
#load "netstring.cma";;
#directory "/usr/lib/ocaml/3.08.3/cgi/";;
#load "netcgi.cma";;

The directory it's looking for netstring contains the following files (and
many others):

jonathan@inner-sanctum:~/csi/ml$ ls /usr/lib/ocaml/3.08.3/netstring/|grep
netstring
netstring.a
netstring.cma
netstring.cmxa
netstring_mt.cmi
netstring_mt.cmo
netstring_mt.cmx
netstring_mt.mli
netstring_mt.o
netstring_pcre.cmi
netstring_pcre.mli
netstring_str.cmi
netstring_str.mli
netstring_top.cmi
netstring_top.cmo
netstring_top.mli
jonathan@inner-sanctum:~/csi/ml$

What should I be doing next to get it to work?

-- 
++ Jonathan Hayward, jonathan.hayward@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com

** If you'd like a Google Mail (gmail.com) account, please tell me!

[-- Attachment #2: Type: text/html, Size: 2583 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] "Hello web" please
  2006-07-11 20:35               ` Jonathan Hayward http://JonathansCorner.com
@ 2006-07-12 11:20                 ` Jonathan Roewen
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Roewen @ 2006-07-12 11:20 UTC (permalink / raw)
  To: Jonathan Hayward http://JonathansCorner.com; +Cc: caml-list

Make your life simpler, and install findlib ;-) (The presence of
site-lib for the path to pcre indicates it'll work out of the box)

In a script, you can do:

#use "topfind";;

#require "pcre";;

at this point, it'll have loaded all the necessary .cma & .cmi files,
added path to the .cmi/.mli files to the search path, and also resolve
any dependencies.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-07-12 11:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-08 15:05 "Hello web" please Jonathan Hayward http://JonathansCorner.com
2006-07-08 20:47 ` [Caml-list] " Christophe TROESTLER
2006-07-10 15:02   ` Jonathan Hayward http://JonathansCorner.com
2006-07-10 15:48     ` Christophe TROESTLER
2006-07-11 14:23       ` Jonathan Hayward http://JonathansCorner.com
2006-07-11 14:33         ` Maxence Guesdon
2006-07-11 14:42         ` Christophe TROESTLER
2006-07-11 17:40           ` Jonathan Hayward http://JonathansCorner.com
2006-07-11 18:14             ` Christophe TROESTLER
2006-07-11 20:35               ` Jonathan Hayward http://JonathansCorner.com
2006-07-12 11:20                 ` Jonathan Roewen
2006-07-10 15:51     ` Jonathan Roewen
2006-07-10 14:49 ` Jonathan Hayward http://JonathansCorner.com
2006-07-10 15:14   ` [Caml-list] " Christophe TROESTLER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).