pleac-commits Mailing List for PLEAC (Page 5)
Status: Alpha
Brought to you by:
ggc
You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(94) |
Sep
(12) |
Oct
(9) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(3) |
Feb
(1) |
Mar
(4) |
Apr
(5) |
May
|
Jun
(5) |
Jul
(1) |
Aug
|
Sep
(8) |
Oct
(2) |
Nov
(2) |
Dec
|
2003 |
Jan
(7) |
Feb
(2) |
Mar
|
Apr
|
May
(1) |
Jun
(8) |
Jul
(13) |
Aug
(9) |
Sep
(5) |
Oct
(1) |
Nov
|
Dec
(2) |
2004 |
Jan
(10) |
Feb
(6) |
Mar
(10) |
Apr
(10) |
May
(10) |
Jun
(4) |
Jul
(1) |
Aug
(11) |
Sep
(21) |
Oct
(16) |
Nov
(12) |
Dec
(17) |
2005 |
Jan
(113) |
Feb
(15) |
Mar
(4) |
Apr
(2) |
May
(4) |
Jun
(52) |
Jul
(11) |
Aug
(5) |
Sep
(21) |
Oct
(24) |
Nov
(7) |
Dec
|
2006 |
Jan
(5) |
Feb
(3) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(4) |
Dec
(23) |
2007 |
Jan
(16) |
Feb
(3) |
Mar
(4) |
Apr
(19) |
May
(12) |
Jun
(4) |
Jul
(10) |
Aug
(11) |
Sep
(5) |
Oct
(21) |
Nov
(6) |
Dec
(13) |
2008 |
Jan
(3) |
Feb
|
Mar
(19) |
Apr
(10) |
May
(7) |
Jun
(15) |
Jul
(30) |
Aug
(28) |
Sep
(10) |
Oct
(42) |
Nov
(41) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2010 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
|
Oct
(3) |
Nov
|
Dec
|
2011 |
Jan
(19) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Dave B. <ram...@us...> - 2008-10-18 05:20:43
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22439 Modified Files: pleac_ocaml.data Log Message: 18.7: Pinging a Machine Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.218 retrieving revision 1.219 diff -u -r1.218 -r1.219 --- pleac_ocaml.data 16 Oct 2008 21:21:15 -0000 1.218 +++ pleac_ocaml.data 18 Oct 2008 05:20:31 -0000 1.219 @@ -15435,6 +15435,133 @@ Unix.shutdown_connection ic; close_out oc +(* @@PLEAC@@_18.7 *) +#!/usr/bin/ocaml + +#use "topfind";; +#thread;; +#require "unix";; + +module Packet = struct + exception Invalid_length of int + exception Invalid_checksum of int * int + + type t = { type' : int; + code : int; + id : int; + seq : int; + data : string } + + let make ?(type'=8) ?(code=0) ~id ~seq data = + {type'=type'; code=code; id=id; seq=seq; data=data} + + let checksum s = + let num_bytes = String.length s in + let num_shorts = num_bytes / 2 in + let rec sum_shorts i sum = + if i < num_shorts then + let short = Int32.of_int (int_of_char s.[i * 2] lsl 8 + + int_of_char s.[i * 2 + 1]) in + sum_shorts (i + 1) (Int32.add sum short) + else sum in + let sum = sum_shorts 0 0l in + let sum = + if num_bytes mod 2 = 1 then + Int32.add sum + (Int32.of_int (int_of_char s.[num_bytes - 1] lsl 8)) + else sum in + let sum = + Int32.add + (Int32.shift_right sum 16) + (Int32.logand sum 0xffffl) in + Int32.to_int + (Int32.logand + (Int32.lognot (Int32.add (Int32.shift_right sum 16) sum)) + 0xffffl) + + let to_string {type'=type'; code=code; id=id; seq=seq; data=data} = + let b = Buffer.create 20 in + Buffer.add_char b (char_of_int type'); + Buffer.add_char b (char_of_int code); + Buffer.add_char b '\000'; (* checksum hi *) + Buffer.add_char b '\000'; (* checksum lo *) + Buffer.add_char b (char_of_int (id lsr 8 land 0xff)); + Buffer.add_char b (char_of_int (id land 0xff)); + Buffer.add_char b (char_of_int (seq lsr 8 land 0xff)); + Buffer.add_char b (char_of_int (seq land 0xff)); + Buffer.add_string b data; + let packet = Buffer.contents b in + let sum = checksum packet in + packet.[2] <- char_of_int (sum lsr 8 land 0xff); + packet.[3] <- char_of_int (sum land 0xff); + packet + + let of_string s = + if String.length s < 8 then raise (Invalid_length (String.length s)); + let s' = String.copy s in + s'.[2] <- '\000'; + s'.[3] <- '\000'; + let sum = int_of_char s.[2] lsl 8 + int_of_char s.[3] in + let sum' = checksum s' in + if sum <> sum' then raise (Invalid_checksum (sum, sum')); + {type'=int_of_char s.[0]; + code=int_of_char s.[1]; + id=int_of_char s.[4] lsl 8 + int_of_char s.[5]; + seq=int_of_char s.[6] lsl 8 + int_of_char s.[7]; + data=String.sub s 8 (String.length s - 8)} +end + +let ping socket sockaddr id seq = + let timestamp = Marshal.to_string (Unix.gettimeofday ()) [] in + let message = Packet.to_string (Packet.make ~id ~seq timestamp) in + ignore (Unix.sendto socket message 0 (String.length message) [] sockaddr); + Unix.sleep 1 + +let pong socket id = + while true do + let buffer = String.make 256 '\000' in + let length, sockaddr = Unix.recvfrom socket buffer 0 (String.length buffer) [] in + let response = Packet.of_string (String.sub buffer 20 (length - 20)) in + match sockaddr, response with + | Unix.ADDR_INET (addr, port), + {Packet.type'=0; code=0; id=id'; seq=seq; data=data} when id = id' -> + let host_entry = Unix.gethostbyaddr addr in + let timestamp = Marshal.from_string data 0 in + Printf.printf "%d bytes from %s (%s): icmp_seq=%d time=%.3f ms\n%!" + (String.length data) + host_entry.Unix.h_name + (Unix.string_of_inet_addr addr) + seq + ((Unix.gettimeofday () -. timestamp) *. 1000.) + | _ -> () + done + +let host = + if Array.length Sys.argv <> 2 + then (Printf.eprintf "Usage: %s host\n" Sys.argv.(0); exit 1) + else Sys.argv.(1) + +let name, addr = + try + let h = Unix.gethostbyname host in + h.Unix.h_name, h.Unix.h_addr_list.(0) + with Not_found -> + Printf.eprintf "%s: unknown host %s\n" Sys.argv.(0) host; + exit 2 + +let () = + Printf.printf "PING %s (%s)\n" name (Unix.string_of_inet_addr addr); + let proto = (Unix.getprotobyname "icmp").Unix.p_proto in + let socket = Unix.socket Unix.PF_INET Unix.SOCK_RAW proto in + let sockaddr = Unix.ADDR_INET (addr, 22) in + let id = Unix.getpid () in + let seq = ref 0 in + ignore (Thread.create (pong socket) id); + while true do + incr seq; + ping socket sockaddr id !seq + done + (* @@PLEAC@@_20.9 *) let template filename fillings = |
From: Dave B. <ram...@us...> - 2008-10-16 21:21:22
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8036 Modified Files: pleac_ocaml.data Log Message: Use Buffer.add_substring in slurp_channel to avoid wasting memory Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.217 retrieving revision 1.218 diff -u -r1.217 -r1.218 --- pleac_ocaml.data 16 Oct 2008 14:36:54 -0000 1.217 +++ pleac_ocaml.data 16 Oct 2008 21:21:15 -0000 1.218 @@ -6643,7 +6643,7 @@ let chars_read = ref 1 in while !chars_read <> 0 do chars_read := input channel string 0 buffer_size; - Buffer.add_string buffer (String.sub string 0 !chars_read) + Buffer.add_substring buffer string 0 !chars_read done; Buffer.contents buffer |
From: Dave B. <ram...@us...> - 2008-10-16 14:37:01
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12309 Modified Files: pleac_ocaml.data Log Message: 18.5: Reading mail with POP3 Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.216 retrieving revision 1.217 diff -u -r1.216 -r1.217 --- pleac_ocaml.data 16 Oct 2008 13:48:39 -0000 1.216 +++ pleac_ocaml.data 16 Oct 2008 14:36:54 -0000 1.217 @@ -15376,6 +15376,65 @@ "; ignore (Unix.close_process_out sendmail) +(* @@PLEAC@@_18.5 *) +(* Use Netpop, which is part of Ocamlnet. *) +#use "topfind";; +#require "pop";; + +(* To create a Netpop client, you need to look up the server address + and build a network connection first. Netpop uses wrappers called + Netchannels to abstract the input and output channels. *) +let inet_addr = + (Unix.gethostbyname mail_server).Unix.h_addr_list.(0) +let addr = Unix.ADDR_INET (inet_addr, Netpop.tcp_port) +let ic, oc = Unix.open_connection addr +let pop = + new Netpop.client + (new Netchannels.input_channel ic) + (new Netchannels.output_channel oc) +let () = + pop#user username; + pop#pass password + +(* Messages are retreived as a hashtable from message IDs to tuples, + each tuple containing the message size in bytes and a string of + server-specific extension data. *) +let messages = pop#list () +let () = + Hashtbl.iter + (fun msgid (size, ext) -> + let message = pop#retr msgid in + (* message is a Netchannels.in_obj_channel *) + pop#dele msgid) + messages + +(*-----------------------------*) + +(* Use pop#apop instead of pop#user/pop#pass to avoid sending passwords + in plaintext across the network. *) +let () = pop#apop username password + +(*-----------------------------*) + +(* Get a message by number and print it to the console. *) +let () = + Printf.printf "Retrieving %d : %!" msgnum; + try + let message = pop#retr msgnum in + print_newline (); + print_endline + (Netchannels.string_of_in_obj_channel message) + with Netpop.Err_status e -> + Printf.printf "failed (%s)\n%!" e + +(*-----------------------------*) + +(* Gracefully tear down the connection. *) +let () = + pop#quit (); + Unix.shutdown_connection ic; + close_out oc + (* @@PLEAC@@_20.9 *) let template filename fillings = |
From: Dave B. <ram...@us...> - 2008-10-16 13:48:49
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8888 Modified Files: pleac_ocaml.data Log Message: 18.3: Sending Mail Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.215 retrieving revision 1.216 diff -u -r1.215 -r1.216 --- pleac_ocaml.data 16 Oct 2008 04:32:43 -0000 1.215 +++ pleac_ocaml.data 16 Oct 2008 13:48:39 -0000 1.216 @@ -15342,6 +15342,40 @@ ~command:`QUIT ~process_result:(fun _ _ -> ftp#abort ()) ()) +(* @@PLEAC@@_18.3 *) +(* Use Netsendmail, part of the Netstring package that comes with + Ocamlnet, to send mail through a command-line mailer program. *) + +#use "topfind";; +#require "netstring";; + +let () = + Netsendmail.sendmail + ~mailer:"/usr/sbin/sendmail" (* defaults to "/usr/lib/sendmail" *) + (Netsendmail.compose + ~from_addr:(from_name, from_address) + ~to_addrs:[(to_name, to_address)] + ~subject:subject + body) + +(*-----------------------------*) + +(* You can also open a pipe directly to sendmail. *) + +#load "unix.cma";; + +let () = + let sendmail = + Unix.open_process_out "/usr/lib/sendmail -oi -t -odq" in + output_string sendmail "\ +From: User Originating Mail <me@host> +To: Final Destination <you@otherhost> +Subject: A relevant subject line + +Body of the message goes here, in as many lines as you like. +"; + ignore (Unix.close_process_out sendmail) + (* @@PLEAC@@_20.9 *) let template filename fillings = |
From: Dave B. <ram...@us...> - 2008-10-16 04:32:55
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17035 Modified Files: pleac_ocaml.data Log Message: 18.2: Being an FTP Client Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.214 retrieving revision 1.215 diff -u -r1.214 -r1.215 --- pleac_ocaml.data 15 Oct 2008 15:06:29 -0000 1.214 +++ pleac_ocaml.data 16 Oct 2008 04:32:43 -0000 1.215 @@ -15237,6 +15237,8 @@ (Perl.string_of_sv exchange)) mx +(*-----------------------------*) + #!/usr/bin/ocaml (* hostaddrs - canonize name and show addresses *) #load "unix.cma";; @@ -15251,6 +15253,95 @@ Unix.string_of_inet_addr hent.Unix.h_addr_list))) +(* @@PLEAC@@_18.2 *) +(* The Netclient package from Ocamlnet provides an event-driven FTP client. + This client does not currently support uploading. + + Ocamlnet is available here: + http://projects.camlcity.org/projects/ocamlnet.html + + This recipe assumes it has been installed with findlib. *) + +#use "topfind";; +#require "netclient";; + +(* Create an FTP client instance. *) +let ftp = new Ftp_client.ftp_client () + +(* Build and execute a chain of FTP methods. *) +let () = + ftp#add (new Ftp_client.connect_method ~host:"127.0.0.1" ()); + ftp#add (new Ftp_client.login_method + ~user:"anonymous" + ~get_password:(fun () -> "us...@ex...") + ~get_account:(fun () -> "anonymous") ()); + ftp#add (new Ftp_client.walk_method (`Dir "/pub")); + let ch = new Netchannels.output_channel (open_out "output.txt") in + ftp#add (new Ftp_client.get_method + ~file:(`Verbatim "index.txt") + ~representation:`Image + ~store:(fun _ -> `File_structure ch) ()); + ftp#run () + +(*-----------------------------*) + +(* If an error occurs, it will be exposed by the "state" property. *) +let () = + match ftp#state with + | `Error (Ftp_client.FTP_error (Unix.Unix_error (e, _, _))) -> + Printf.eprintf "Error: %s\n%!" + (Unix.error_message e) + | _ -> () + +(*-----------------------------*) + +(* To determine the current working directory, send invoke the `PWD + command and inspect the result in a callback. *) +let () = + ftp#add (new Ftp_client.invoke_method + ~command:`PWD + ~process_result:(fun state (code, message) -> + Printf.printf + "I'm in the directory %s\n%!" + message) ()) + +(*-----------------------------*) + +(* Use mkdir_method and rmdir_method to make and remove directories from + the remote server. Use the optional ~onerror argument to specify an + error handler. *) +let () = + ftp#add + ~onerror:(fun e -> + Printf.eprintf "Can't create /ocaml: %s\n%!" + (Printexc.to_string e)) + (new Ftp_client.mkdir_method (`Verbatim "/pub/ocaml")) + +(*-----------------------------*) + +(* Use a list_method to get a list of files in a remote directory. *) +let () = + let buffer = Buffer.create 256 in + let ch = new Netchannels.output_buffer buffer in + ftp#add + ~onsuccess:(fun () -> print_endline (Buffer.contents buffer)) + ~onerror:(fun e -> + Printf.eprintf "Can't get a list of files in /pub: %s\n%!" + (Printexc.to_string e)) + (new Ftp_client.list_method + ~dir:(`Verbatim "/pub") + ~representation:`Image + ~store:(fun _ -> `File_structure ch) ()) + +(*-----------------------------*) + +(* Use `QUIT followed by ftp#abort to close the connection and exit + the event loop. *) +let () = + ftp#add (new Ftp_client.invoke_method + ~command:`QUIT + ~process_result:(fun _ _ -> ftp#abort ()) ()) + (* @@PLEAC@@_20.9 *) let template filename fillings = |
From: Dave B. <ram...@us...> - 2008-10-15 16:47:27
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28987 Modified Files: pleac_ocaml.data Log Message: 18.1: Simple DNS Lookups (complete) Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.213 retrieving revision 1.214 diff -u -r1.213 -r1.214 --- pleac_ocaml.data 15 Oct 2008 05:43:28 -0000 1.213 +++ pleac_ocaml.data 15 Oct 2008 15:06:29 -0000 1.214 @@ -15206,7 +15206,50 @@ with Not_found -> Printf.printf "Can't look up %s\n" address -(* @@INCOMPLETE@@ *) +(*-----------------------------*) + +#!/usr/bin/ocaml +(* mxhost - find mx exchangers for a host *) + +(* Though there is an experimental new DNS resolver for OCaml called + Netdns, it does not yet support resolving MX records. For now, we'll + use Net::DNS through perl4caml until a better solution is available. +*) +#directory "+perl";; +#load "perl4caml.cma";; +let _ = Perl.eval "use Net::DNS" + +let host = Sys.argv.(1) +let res = Perl.call_class_method "Net::DNS::Resolver" "new" [] +let mx = Perl.call_array ~fn:"mx" [res; Perl.sv_of_string host] +let () = + if mx = [] then + Printf.eprintf "Can't find MX records for %s (%s)\n" + host (Perl.string_of_sv (Perl.call_method res "errorstring" [])) + +let () = + List.iter + (fun record -> + let preference = Perl.call_method record "preference" [] in + let exchange = Perl.call_method record "exchange" [] in + Printf.printf "%s %s\n" + (Perl.string_of_sv preference) + (Perl.string_of_sv exchange)) + mx + +#!/usr/bin/ocaml +(* hostaddrs - canonize name and show addresses *) +#load "unix.cma";; +let name = Sys.argv.(1) +let hent = Unix.gethostbyname name +let () = + Printf.printf "%s => %s\n" + hent.Unix.h_name (* in case different *) + (String.concat " " + (Array.to_list + (Array.map + Unix.string_of_inet_addr + hent.Unix.h_addr_list))) (* @@PLEAC@@_20.9 *) |
From: Dave B. <ram...@us...> - 2008-10-15 05:43:35
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23265 Modified Files: pleac_ocaml.data Log Message: 17.18: Program: fwdport Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.212 retrieving revision 1.213 diff -u -r1.212 -r1.213 --- pleac_ocaml.data 4 Oct 2008 18:07:50 -0000 1.212 +++ pleac_ocaml.data 15 Oct 2008 05:43:28 -0000 1.213 @@ -14967,6 +14967,203 @@ Syslog.closelog log; exit 0 +(* @@PLEAC@@_17.18 *) +#!/usr/bin/ocaml +(* fwdport -- act as proxy forwarder for dedicated services *) + +#load "str.cma";; +#load "unix.cma";; + +let children = Hashtbl.create 0 (* hash of outstanding child processes *) +let remote = ref "" (* whom we connect to on the outside *) +let local = ref "" (* where we listen to on the inside *) +let service = ref "" (* our service name or port number *) +let proxy_server = ref Unix.stdin (* the socket we accept() from *) + +(* process command line switches using the extended *) +(* version of the getopts library. *) +let check_args () = + Arg.parse + [ + "-r", Arg.Set_string remote, "Remote host"; + "-remote", Arg.Set_string remote, "Remote host"; + "-l", Arg.Set_string local, "Local interface"; + "-local", Arg.Set_string local, "Local interface"; + "-s", Arg.Set_string service, "Service"; + "-service", Arg.Set_string service, "Service"; + ] + (fun s -> + raise (Arg.Bad (Printf.sprintf "unexpected argument `%s'" s))) + (Printf.sprintf "usage: %s [ -remote host ] [ -local interface ] [ -service service ]" Sys.argv.(0)); + if !remote = "" + then (prerr_endline "Need remote"; exit 1); + if !local = "" && !service = "" + then (prerr_endline "Need local or service"; exit 1); + if !local = "" + then local := "localhost" + +let parse_host host = + match Str.split (Str.regexp ":") host with + | [] -> "", "" + | host :: [] -> host, "" + | host :: service :: _ -> host, service + +let resolve_host host = + try (Unix.gethostbyname host).Unix.h_addr_list.(0) + with Not_found -> + Printf.eprintf "Host not found: %s\n" host; + exit 1 + +let resolve_service service = + try int_of_string service + with Failure _ -> + try (Unix.getservbyname service "tcp").Unix.s_port + with Not_found -> + Printf.eprintf "Service not found: %s\n" service; + exit 1 + +(* begin our server *) +let start_proxy () = + try + let proto = (Unix.getprotobyname "tcp").Unix.p_proto in + let addr, port = + match parse_host (!local ^ ":" ^ !service) with + | host, service -> + (resolve_host host, + resolve_service service) in + proxy_server := Unix.socket Unix.PF_INET Unix.SOCK_STREAM proto; + Unix.setsockopt !proxy_server Unix.SO_REUSEADDR true; + Unix.bind !proxy_server (Unix.ADDR_INET (addr, port)); + Unix.listen !proxy_server 128; + Printf.printf "[Proxy server on %s initialized.]\n%!" + (if !local <> "" then !local else !service) + with Unix.Unix_error (e, _, _) -> + Printf.eprintf "Can't create proxy server: %s\n%!" + (Unix.error_message e); + exit 1 + +(* helper function to produce a nice string in the form HOST:PORT *) +let peerinfo sock = + match Unix.getpeername sock with + | Unix.ADDR_INET (addr, port) -> + let hostinfo = Unix.gethostbyaddr addr in + Printf.sprintf "%s:%d" hostinfo.Unix.h_name port + | _ -> assert false + +(* somebody just died. keep harvesting the dead until *) +(* we run out of them. check how long they ran. *) +let rec reaper signal = + begin + let result = + try Some (Unix.waitpid [Unix.WNOHANG] (-1)) + with Unix.Unix_error (Unix.ECHILD, _, _) -> None in + match result with + | Some (child, status) when Hashtbl.mem children child -> + let start = Hashtbl.find children child in + let runtime = Unix.time () -. start in + Printf.printf "Child %d ran %dm%fs\n%!" + child + (int_of_float (runtime /. 60.)) + (mod_float runtime 60.); + Hashtbl.remove children child; + reaper signal + | Some (child, status) -> + Printf.printf "Bizarre kid %d exited with %s\n%!" + child + (match status with + | Unix.WEXITED code -> + "code " ^ string_of_int code + | Unix.WSTOPPED signal + | Unix.WSIGNALED signal -> + "signal " ^ string_of_int signal); + reaper signal + | None -> () + end; + (* If I had to choose between System V and 4.2, I'd resign. *) + (* --Peter Honeyman *) + Sys.set_signal Sys.sigchld (Sys.Signal_handle reaper) + +let service_clients () = + (* harvest the moribund *) + Sys.set_signal Sys.sigchld (Sys.Signal_handle reaper); + + (* an accepted connection here means someone inside wants out *) + while true do + try + begin + let local_client = fst (Unix.accept !proxy_server) in + let lc_info = peerinfo local_client in + Printf.printf "[Connect from %s]\n%!" lc_info; + + let proto = (Unix.getprotobyname "tcp").Unix.p_proto in + let addr, port = + match parse_host (!remote ^ ":" ^ !service) with + | host, service -> + (resolve_host host, + resolve_service service) in + Printf.printf "[Connecting to %s...%!" !remote; + let remote_server = Unix.socket Unix.PF_INET Unix.SOCK_STREAM proto in + Unix.connect remote_server (Unix.ADDR_INET (addr, port)); + Printf.printf "done]\n%!"; + + let local_in = Unix.in_channel_of_descr local_client in + let local_out = Unix.out_channel_of_descr local_client in + let remote_in = Unix.in_channel_of_descr remote_server in + let remote_out = Unix.out_channel_of_descr remote_server in + + match Unix.fork () with + | 0 -> + (* at this point, we are the forked child process dedicated *) + (* to the incoming client. but we want a twin to make i/o *) + (* easier. *) + + Unix.close !proxy_server; (* no use to slave *) + + (* now each twin sits around and ferries lines of data. *) + (* see how simple the algorithm is when you can have *) + (* multiple threads of control? *) + + (match Unix.fork () with + | 0 -> + (* this is the fork's child, the master's grandchild *) + (try + while true do + let line = input_line local_in in + Printf.fprintf remote_out "%s\n%!" line + done + with End_of_file -> + (* kill my twin cause we're done *) + Unix.kill (Unix.getppid ()) Sys.sigterm) + | kidpid -> + (* this is the fork's parent, the master's child *) + (try + while true do + let line = input_line remote_in in + Printf.fprintf local_out "%s\n%!" line + done + with End_of_file -> + (* kill my twin cause we're done *) + Unix.kill kidpid Sys.sigterm)); + + exit 0 (* whoever's still alive bites it *) + + | kidpid -> + (* remember his start time *) + Hashtbl.replace children kidpid (Unix.time ()); + Unix.close remote_server; (* no use to master *) + Unix.close local_client; (* likewise *) + end + with Unix.Unix_error (Unix.EINTR, "accept", _) -> () + done + +let () = + check_args (); (* processing switches *) + start_proxy (); (* launch our own server *) + service_clients (); (* wait for incoming *) + prerr_endline "NOT REACHED"; (* you can't get here from there *) + exit 1 + + (* @@PLEAC@@_18.1 *) #load "unix.cma";; |
From: Anthony B. <aj...@us...> - 2008-10-09 07:05:15
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv2042/pleac/pleac Modified Files: AUTHORS.currently-working Log Message: More realistic commitment Index: AUTHORS.currently-working =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/AUTHORS.currently-working,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- AUTHORS.currently-working 23 Aug 2008 22:01:58 -0000 1.41 +++ AUTHORS.currently-working 9 Oct 2008 07:05:06 -0000 1.42 @@ -3,10 +3,6 @@ Anthony Borla C/Posix/GNU: 1, 2, 3, 4, 5, 7, 8, 9 C++/STL/Boost: 2, 3, 4, 5, 7, 8, 9, 13 - PHP: 7, 8, 13 - Pike: 7, 8, 12, 13 - Guile: 12, 13 - REXX: 4, 17 Dave Benjamin OCaml: 17 |
From: Guillaume C. <gg...@us...> - 2008-10-06 21:41:44
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20873 Modified Files: index-skeleton.html Log Message: forget this beta1 thing Index: index-skeleton.html =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/index-skeleton.html,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- index-skeleton.html 6 Oct 2008 21:35:45 -0000 1.38 +++ index-skeleton.html 6 Oct 2008 21:41:27 -0000 1.39 @@ -129,7 +129,7 @@ beginning of implementations (forth, common lisp, pike). This main-page sees an average of 50 visitors per day. -<p><b>20011023 (beta1).</b> The project is in good shape: we now have +<p><b>200110.</b> The project is in good shape: we now have decent versions in Python (43%), Merd (30%), Guile (27%), Ruby (25%), Haskell (21%), Tcl (17%), and Java (14%). It can already be used to make basic comparisons between languages, and begins to be referred in some @@ -139,12 +139,12 @@ and Pliant (1.71%). </p> -<p><b>20010803.</b> Project registered in <a +<p><b>200108.</b> Project registered in <a href="http://freshmeat.net/releases/54133/">Freshmeat</a>. Versions status are: Merd 30%, Ruby 25%, Haskell and Python around 10%. </p> -<p><b>20010523 (project founding).</b> The project has been accepted by +<p><b>200105 (project founding).</b> The project has been accepted by SourceForge. Great! Time to work on the generic sourcecode-colorized web pages, and to begin implementations in Ruby and Merd. </p> |
From: Guillaume C. <gg...@us...> - 2008-10-06 21:35:53
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20073 Modified Files: index-skeleton.html Log Message: typo thx philip durbin & some more minor improvements Index: index-skeleton.html =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/index-skeleton.html,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- index-skeleton.html 6 Sep 2008 21:39:03 -0000 1.37 +++ index-skeleton.html 6 Oct 2008 21:35:45 -0000 1.38 @@ -18,28 +18,27 @@ height="31" border="0" alt="SourceForge Logo"></img></a> -<h2>Overall</h2> +<h2>Summary</h2> <p> Following the great <a href="http://www.oreilly.com/catalog/cookbook">Perl Cookbook</a> (by Tom Christiansen & Nathan Torkington, published by O'Reilly; you can freely browse an excerpt of the book -<a -href="http://safari.oreilly.com/0596003137">here</a>) -which presents a suite of common programming problems solved in -the Perl language, this project aims to gather fans of programming, in -order to implement the solutions in other programming languages. +<a href="http://safari.oreilly.com/0596003137">here</a>) which +presents a suite of common programming problems solved in the +Perl language, this project aims to implement the solutions in +other programming languages. </p> <p> If successful, this project may become a primary resource for quick, handy and free reference to solve most common programming problems using -higher-level programming languages, and for comparison on ease-of-use and +various programming languages, and for comparison on ease-of-use and power/efficiency of these languages. </p> <p> -The material, considered as some Documentation, is wholy released under +The material, considered as some Documentation, is wholly released under the Gnu <a href="http://www.gnu.org/copyleft/fdl.html">Free Documentation License</a>, except the Perl part, which is copyrighted by O'Reilly & Associates yet <a href="http://examples.oreilly.com/cookbook/">freely |
From: <ram...@us...> - 2008-10-04 18:08:02
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv6811 Modified Files: pleac_ocaml.data Log Message: 17.17: Program: backsniff Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.211 retrieving revision 1.212 diff -u -r1.211 -r1.212 --- pleac_ocaml.data 4 Oct 2008 16:33:34 -0000 1.211 +++ pleac_ocaml.data 4 Oct 2008 18:07:50 -0000 1.212 @@ -14910,6 +14910,62 @@ read_config (); Sys.set_signal Sys.sighup (Sys.Signal_handle read_config) +(* @@PLEAC@@_17.17 *) +Oct 4 11:01:16 pedro sniffer: Connection from 10.0.0.4 to 10.0.0.1:echo + +(*-----------------------------*) + +echo stream tcp nowait nobody /usr/bin/ocaml ocaml /path/to/backsniff.ml + +(*-----------------------------*) + +(* backsniff - log attempts to connect to particular ports *) +#load "unix.cma";; + +(* This recipe uses syslog-ocaml, which is available at: + http://www.cs.cmu.edu/~ecc/software.html *) +#directory "+syslog";; +#load "syslog.cma";; + +(* identify my port and address *) +let sockname = + try Unix.getsockname Unix.stdin + with Unix.Unix_error (e, _, _) -> + Printf.eprintf "Couldn't identify myself: %s\n%!" + (Unix.error_message e); + exit 1 +let iaddr, port = + match sockname with + | Unix.ADDR_INET (iaddr, port) -> iaddr, port + | _ -> assert false +let my_address = Unix.string_of_inet_addr iaddr + +(* get a name for the service *) +let service = + try (Unix.getservbyport port "tcp").Unix.s_name + with Not_found -> string_of_int port + +(* now identify remote address *) +let sockname = + try Unix.getpeername Unix.stdin + with Unix.Unix_error (e, _, _) -> + Printf.eprintf "Couldn't identify other end: %s\n%!" + (Unix.error_message e); + exit 1 +let iaddr, port = + match sockname with + | Unix.ADDR_INET (iaddr, port) -> iaddr, port + | _ -> assert false +let ex_address = Unix.string_of_inet_addr iaddr + +(* and log the information *) +let () = + let log = Syslog.openlog ~flags:[] ~facility:`LOG_DAEMON "sniffer" in + Syslog.syslog log `LOG_NOTICE + (Printf.sprintf "Connection from %s to %s:%s\n" + ex_address my_address service); + Syslog.closelog log; + exit 0 (* @@PLEAC@@_18.1 *) #load "unix.cma";; |
From: <ram...@us...> - 2008-10-04 16:33:45
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv32547 Modified Files: pleac_ocaml.data Log Message: 17.14: Writing a Multi-Homed Server (complete) Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.210 retrieving revision 1.211 diff -u -r1.210 -r1.211 --- pleac_ocaml.data 4 Oct 2008 16:12:47 -0000 1.210 +++ pleac_ocaml.data 4 Oct 2008 16:33:34 -0000 1.211 @@ -14794,7 +14794,7 @@ let () = Unix.setsockopt server Unix.SO_REUSEADDR true; Unix.bind server (Unix.ADDR_INET (Unix.inet_addr_any, server_port)); - Unix.listen server 1; + Unix.listen server 10; (* accept loop *) while true do @@ -14805,7 +14805,26 @@ | _ -> assert false done -(* @@INCOMPLETE@@ *) +(*-----------------------------*) + +#load "unix.cma";; + +let port = 4269 (* port to bind to *) +let host = "specific.host.com" (* virtual host to listen on *) + +let server = + Unix.socket Unix.PF_INET Unix.SOCK_STREAM + (Unix.getprotobyname "tcp").Unix.p_proto + +let () = + let addr = (Unix.gethostbyname host).Unix.h_addr_list.(0) in + Unix.bind server (Unix.ADDR_INET (addr, port)); + Unix.listen server 10; + while true do + let client, sockaddr = Unix.accept server in + (* ... *) + () + done (* @@PLEAC@@_17.15 *) #load "unix.cma";; |
From: <ram...@us...> - 2008-10-04 16:12:54
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31494 Modified Files: pleac_ocaml.data Log Message: 17.16: Restarting a Server on Demand Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.209 retrieving revision 1.210 diff -u -r1.209 -r1.210 --- pleac_ocaml.data 27 Sep 2008 06:58:19 -0000 1.209 +++ pleac_ocaml.data 4 Oct 2008 16:12:47 -0000 1.210 @@ -14840,6 +14840,57 @@ () done +(* @@PLEAC@@_17.16 *) +#load "unix.cma";; + +let self = "/usr/bin/ocaml" +let args = self :: Array.to_list Sys.argv + +let phoenix _ = + (* close all your connections, kill your children, and *) + (* generally prepare to be reincarnated with dignity. *) + try + ignore (Unix.sigprocmask Unix.SIG_UNBLOCK [Sys.sighup]); + Unix.execv self (Array.of_list args) + with Unix.Unix_error (e, _, _) -> + Printf.eprintf "Couldn't restart: %s\n%!" + (Unix.error_message e) + +let () = + Sys.set_signal Sys.sighup (Sys.Signal_handle phoenix) + +(*-----------------------------*) + +(* This recipe uses the Ocaml-Syck YAML parser available at: + http://ocaml-syck.sourceforge.net/ *) + +#directory "+yaml";; +#load "yaml.cma";; +#load "unix.cma";; + +let yaml_parser = YamlParser.make () + +let config_file = "/usr/local/etc/myprog/server_conf.yaml" +let config = ref (YamlNode.SCALAR ("", "")) + +let read_config _ = + let in_channel = open_in config_file in + let lines = ref [] in + try + while true do + let line = input_line in_channel in + lines := line :: !lines + done + with End_of_file -> + close_in in_channel; + config := + YamlParser.parse_string yaml_parser + (String.concat "\n" (List.rev !lines)) + +let () = + read_config (); + Sys.set_signal Sys.sighup (Sys.Signal_handle read_config) + (* @@PLEAC@@_18.1 *) #load "unix.cma";; |
From: <gg...@us...> - 2008-10-04 14:11:49
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv24548 Modified Files: pleac_ruby.data Log Message: 7.15->7.14 Index: pleac_ruby.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ruby.data,v retrieving revision 1.85 retrieving revision 1.86 diff -u -r1.85 -r1.86 --- pleac_ruby.data 4 Oct 2008 13:47:22 -0000 1.85 +++ pleac_ruby.data 4 Oct 2008 14:11:37 -0000 1.86 @@ -3169,7 +3169,7 @@ end -# @@PLEAC@@_7.15 +# @@PLEAC@@_7.14 # It throws exception on EOF, instead of sysread, you can use read_nonblock(), too. begin File.open fname, (File::RDONLY | File::NONBLOCK) do |io| |
From: <gg...@us...> - 2008-10-04 14:03:50
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv23705 Modified Files: Makefile Log Message: ocaml is now over python; SF has changed upload mechanism Index: Makefile =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/Makefile,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- Makefile 12 May 2008 20:39:15 -0000 1.63 +++ Makefile 4 Oct 2008 14:03:39 -0000 1.64 @@ -19,7 +19,7 @@ #***************************************************************************** # IMPLS must be sorted by percentage of completion -IMPLS = perl groovy python ocaml ruby guile rexx tcl php commonlisp pike merd ada haskell haskell-on-steroids java cposix pliant c++ factor smalltalk forth erlang R masd nasm +IMPLS = perl groovy ocaml python ruby guile rexx tcl php commonlisp pike merd ada haskell haskell-on-steroids java cposix pliant c++ factor smalltalk forth erlang R masd nasm DATAFILES = $(wildcard pleac_*.data) @@ -77,6 +77,5 @@ rm -rf ../t mkdir ../t cp -a * ../t - cd ../t; rm -rf `find -type d -name CVS`; scp -r * gg...@sh...:/home/groups/p/pl/pleac/htdocs -# cd ../t; rm -rf `find -type d -name CVS`; scp -r * mandrakesoft.com:www/pleac + cd ../t; rm -rf `find -type d -name CVS`; scp -r * ggc,pl...@we...:/home/groups/p/pl/pleac/htdocs rm -rf ../t |
From: <gg...@us...> - 2008-10-04 13:48:19
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22820 Modified Files: AUTHORS Log Message: *** empty log message *** Index: AUTHORS =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/AUTHORS,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- AUTHORS 6 Sep 2008 21:05:04 -0000 1.56 +++ AUTHORS 4 Oct 2008 13:48:09 -0000 1.57 @@ -178,3 +178,6 @@ Ramsey Nasser <ramsey at ramseynasser dot com> Ruby + +Sandor Szuecs <sandor dot szuecs at fu-berlin dot de> + Ruby |
From: <gg...@us...> - 2008-10-04 13:47:34
|
Update of /cvsroot/pleac/pleac/pleac In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22775 Modified Files: pleac_ruby.data Log Message: from Sandor Szücs Index: pleac_ruby.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ruby.data,v retrieving revision 1.84 retrieving revision 1.85 diff -u -r1.84 -r1.85 --- pleac_ruby.data 6 Sep 2008 21:05:04 -0000 1.84 +++ pleac_ruby.data 4 Oct 2008 13:47:22 -0000 1.85 @@ -3169,6 +3169,29 @@ end +# @@PLEAC@@_7.15 +# It throws exception on EOF, instead of sysread, you can use read_nonblock(), too. +begin + File.open fname, (File::RDONLY | File::NONBLOCK) do |io| + puts io.sysread(4096) # throws exception + end +rescue EOFError +rescue IOError => e + puts e.exception +rescue Errno::ENOENT + puts "no such file #{fname}" +end + +# return nil on EOF +begin + File.open fname, (File::RDONLY | File::NONBLOCK) do |io| + puts io.read(4096) # returns nil + end +rescue Errno::ENOENT + puts "no such file #{fname}" +end + + # @@PLEAC@@_8.0 #----------------------------- # datafile is a file or IO object |
From: Dave B. <ram...@us...> - 2008-09-27 06:58:34
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31191 Modified Files: pleac_ocaml.data Log Message: Alternative implementation for 2.6 by Ken Wakita. Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.208 retrieving revision 1.209 diff -u -r1.208 -r1.209 --- pleac_ocaml.data 27 Sep 2008 05:42:38 -0000 1.208 +++ pleac_ocaml.data 27 Sep 2008 06:58:19 -0000 1.209 @@ -1131,6 +1131,17 @@ (*-----------------------------*) +(* Alternative version by Ken Wakita. *) +let roman arabic = + let nstr s n = String.concat "" (Array.to_list (Array.make n s)) in + snd (List.fold_left + (fun (arabic, roman) (arab, rom) -> + arabic mod arab, roman ^ (nstr rom (arabic / arab))) + (arabic, "") + roman_map) + +(*-----------------------------*) + let () = let roman_fifteen = roman 15 in Printf.printf "Roman for fifteen is %s\n" roman_fifteen; |
From: Dave B. <ram...@us...> - 2008-09-27 05:42:55
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1381 Modified Files: pleac_ocaml.data Log Message: 17.14: Writing a Multi-Homed Server (incomplete) Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.207 retrieving revision 1.208 diff -u -r1.207 -r1.208 --- pleac_ocaml.data 3 Sep 2008 23:45:07 -0000 1.207 +++ pleac_ocaml.data 27 Sep 2008 05:42:38 -0000 1.208 @@ -14773,6 +14773,29 @@ has_exception; done +(* @@PLEAC@@_17.14 *) +#load "unix.cma";; + +let server = + Unix.socket Unix.PF_INET Unix.SOCK_STREAM + (Unix.getprotobyname "tcp").Unix.p_proto + +let () = + Unix.setsockopt server Unix.SO_REUSEADDR true; + Unix.bind server (Unix.ADDR_INET (Unix.inet_addr_any, server_port)); + Unix.listen server 1; + + (* accept loop *) + while true do + let client, sockaddr = Unix.accept server in + match Unix.getsockname client with + | Unix.ADDR_INET (addr, port) -> + print_endline (Unix.string_of_inet_addr addr) + | _ -> assert false + done + +(* @@INCOMPLETE@@ *) + (* @@PLEAC@@_17.15 *) #load "unix.cma";; |
From: Guillaume C. <gg...@us...> - 2008-09-06 21:56:10
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9592 Modified Files: pleac_groovy.data Log Message: minorissimo fix Index: pleac_groovy.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_groovy.data,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- pleac_groovy.data 25 Mar 2007 03:20:44 -0000 1.4 +++ pleac_groovy.data 6 Sep 2008 21:56:18 -0000 1.5 @@ -8252,7 +8252,7 @@ //---------------------------------------------------------------------------------- print "${(char)7}" -/ Using jline constant +// Using jline constant print "${jline.ConsoleOperations.KEYBOARD_BELL}" // Also available through ConsoleReader.beep() |
From: Guillaume C. <gg...@us...> - 2008-09-06 21:38:56
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2472 Modified Files: index-skeleton.html Added Files: simple_sample.data Log Message: enhance "contribute" --- NEW FILE: simple_sample.data --- # @@PLEAC@@_2.3 Implementation in the programming language of the code shown in section 2.3 of the Perl CookBook. # @@PLEAC@@_4.7 Implementation in the programming language of the code shown in section 4.7 of the Perl CookBook. # @@PLEAC@@_5.3 Implementation in the programming language of the code shown in section 4.7 of the Perl CookBook. # @@INCOMPLETE@@ Note: the above tag, @@INCOMPLETE@@, tells the statistics computing that the section is incomplete. One tag counts for 50% incompleteness, so if you don't do the section at all and puts an explanation about it, you will want to put two tags (there is no need to do so if you have no explanation to put). If you simply cannot do the section, don't put @@INCOMPLETE@@ tags, just put the explanation why. # @@PLEAC@@_7.3 # @@INCLUDE@@ include/{name}/slowcat.ext Note: the above tag, @@INCLUDE@@, allows to inline a short standalone program/script. It is useful to keep it separated so that users can easily run it, and we can also give a direct download for it on the published version. Index: index-skeleton.html =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/index-skeleton.html,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- index-skeleton.html 3 May 2008 20:09:21 -0000 1.36 +++ index-skeleton.html 6 Sep 2008 21:39:03 -0000 1.37 @@ -157,16 +157,24 @@ <p> To contribute to this projet, you may implement the Solutions shown in the Perl Cookbook in your language of choice, writing them in a simple -description language made of <tt>@@PLEAC@@_KEYWORD</tt> sections, as shown in -this <a href="sample.data">sample</a> or following the "code" -links upper. +description language made of <tt>@@PLEAC@@_KEYWORD</tt> sections: +<ul> +<li>If you're adding a new part for an existing programming language +(already some done in PLEAC for that language, for example Ruby), follow what's in +this <a href="simple_sample.data">simple sample</a>. +</li> +<li>If you're adding a new programming language (nothing done in +PLEAC for that language), follow what's in +this <a href="sample.data">sample</a>.</li> +</ul> +You may also follow the "code" links upper. </p> <p> -You may add or correct code for existing languages, or extend the project -by beginning work for another language. In all cases, please <a -href="http://lists.sourceforge.net/lists/listinfo/pleac-discuss">subscribe</a> -to the discussion mailing-list so we can discuss and include your work. +In all cases, +please <a href="http://lists.sourceforge.net/lists/listinfo/pleac-discuss">subscribe</a> +to the discussion mailing-list and post your submission there, so +we can discuss and include your work. </p> <p> |
From: Guillaume C. <gg...@us...> - 2008-09-06 21:04:57
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21212 Modified Files: AUTHORS pleac_ruby.data Log Message: from Ramsey Nasser <ramsey at ramseynasser dot com> Index: AUTHORS =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/AUTHORS,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- AUTHORS 12 May 2008 12:49:24 -0000 1.55 +++ AUTHORS 6 Sep 2008 21:05:04 -0000 1.56 @@ -175,3 +175,6 @@ Stefan Scholl <stesch at no-spoon dot de> Factor + +Ramsey Nasser <ramsey at ramseynasser dot com> + Ruby Index: pleac_ruby.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ruby.data,v retrieving revision 1.83 retrieving revision 1.84 diff -u -r1.83 -r1.84 --- pleac_ruby.data 28 Apr 2008 19:43:46 -0000 1.83 +++ pleac_ruby.data 6 Sep 2008 21:05:04 -0000 1.84 @@ -5680,6 +5680,81 @@ # 18.0 ************************************** +# @@PLEAC@@_15.5 +# Ruby's standard distribution doesn't have an ANSI color module, but we can use +# Term::ANSIColor (http://term-ansicolor.rubyforge.org/) instead. +#----------------------------- +require 'term/ansicolor' +include Term::ANSIColor + +# Text can be colored using constants +print red, "Danger Will Robinson!", reset, "\n" +print "This is just normal text\n" +print blink, "Do you hurt yet?", reset, "\n" +#----------------------------- +# Or by using functions. Functions automatically reset colors at the end. +print red("Danger Will Ronbinson!"), "\n" +print red( on_black( "venom lack" )), "\n" +print red( on_yellow( "kill that fellow" )), "\n" +print green( on_cyan( blink( "garish!" ))), "\n" +#----------------------------- +# Or by using block forms. Block forms automatically reset colors at the end. +print red { "Danger Will Robinson!" }, "\n" +print red { on_black { "venom lack" } }, "\n" +print red { on_yellow { "kill that fellow" } }, "\n" +#----------------------------- +# Or by using a String Mixin +class String + include Term::ANSIColor +end + +print "Danger Will Robinson!".red, "\n" +print "venom lack".red.on_black, "\n" +print "kill that fellow".red.on_yellow, "\n" + +#----------------------------- +# To color text without using a third party library, constants can be created +# manually using ANSI escape codes. (A complete list of all codes can be found +# at http://en.wikipedia.org/wiki/Ansi_escape_codes) +# Note that \e means \033 (The escape character) +#----------------------------- +# Foreground constants +BLACK = "\e[30m" +RED = "\e[31m" +GREEN = "\e[32m" +WHITE = "\e[37m" + +# Background constants +ON_BLACK = "\e[40m" +ON_WHITE = "\e[47m" +ON_YELLOW = "\e[43m" +ON_CYAN = "\e[46m" + +# Style constants +BLINK = "\e[5m" +NOBLINK = "\e[25m" +BOLD = "\e[1m" +NOBOLD = "\e[22m" + +RESET = "\e[0m" +#----------------------------- +puts "#{RED}Danger Will Ronbinson!#{RESET}" +puts "This is just normal text." +puts "#{BLINK}Do you hurt yet?#{NOBLINK}" +#----------------------------- +puts "#{RED}Danger Will Ronbinson!#{RESET}" +puts "#{RED}#{ON_BLACK}venom lack" +puts "#{RED}#{ON_YELLOW}kill that fellow" +puts "#{GREEN}#{ON_CYAN}#{BLINK}garish!" +#----------------------------- +print BLACK, ON_WHITE, "black on white\n" +print WHITE, ON_BLACK, "white on black\n" +print GREEN, ON_CYAN, BLINK, "garish!\n" + +print RESET +#----------------------------- + + # @@PLEAC@@_16.1 output = `program args` # collect output into one multiline string output = `program args`.split # collect output into array, one line per |
From: Dave B. <ram...@us...> - 2008-09-03 23:44:58
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32271 Modified Files: pleac_ocaml.data Log Message: 17.10: Writing Bidirectional Clients Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.206 retrieving revision 1.207 diff -u -r1.206 -r1.207 --- pleac_ocaml.data 3 Sep 2008 14:59:48 -0000 1.206 +++ pleac_ocaml.data 3 Sep 2008 23:45:07 -0000 1.207 @@ -14455,6 +14455,51 @@ shutdown sock SHUTDOWN_SEND ; (* send eof; no more writing *) let answer = sock_recv sock 4096 ;; (* but you can still read *) +(* @@PLEAC@@_17.10 *) +#!/usr/bin/ocaml +(* biclient - bidirectional forking client *) +#load "unix.cma";; + +let host, port = + match Array.to_list Sys.argv with + | [_; host; port] -> host, int_of_string port + | _ -> Printf.eprintf "usage: %s host port\n" Sys.argv.(0); exit 1 + +let sockaddr = + let addr = (Unix.gethostbyname host).Unix.h_addr_list.(0) in + Unix.ADDR_INET (addr, port) + +let () = + let socket = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in + Unix.connect socket sockaddr; + Printf.eprintf "[Connected to %s:%d]\n%!" host port; + + (* split the program into two processes, identical twins *) + match Unix.fork () with + | 0 -> + (* child copies standard input to the socket *) + let output = Unix.out_channel_of_descr socket in + while true do + let line = input_line stdin in + output_string output line; + output_string output "\n"; + flush output + done + | kidpid -> + (* parent copies the socket to standard output *) + let input = Unix.in_channel_of_descr socket in + try + while true do + let line = input_line input in + output_string stdout line; + output_string stdout "\n"; + flush stdout + done + with End_of_file -> + Unix.kill kidpid Sys.sigterm + +let () = exit 0 + (* @@PLEAC@@_17.11 *) (* set up the socket SERVER, bind and listen ... *) #load "unix.cma";; |
From: Dave B. <ram...@us...> - 2008-09-03 14:59:39
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14565 Modified Files: pleac_ocaml.data Log Message: 17.6: Using Unix domain sockets Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.205 retrieving revision 1.206 diff -u -r1.205 -r1.206 --- pleac_ocaml.data 3 Sep 2008 07:52:56 -0000 1.205 +++ pleac_ocaml.data 3 Sep 2008 14:59:48 -0000 1.206 @@ -14366,6 +14366,18 @@ ignore (Unix.alarm 0); Printf.printf "Server %s responded ``%s''\n" hishost msg +(* @@PLEAC@@_17.6 *) +#load "unix.cma";; + +(* Create a Unix domain socket server - you can also use SOCK_STREAM. *) +let server = Unix.socket Unix.PF_UNIX Unix.SOCK_DGRAM 0 +let () = try Unix.unlink "/tmp/mysock" with Unix.Unix_error _ -> () +let () = Unix.bind server (Unix.ADDR_UNIX "/tmp/mysock") + +(* Create a Unix domain socket client - you can also use SOCK_STREAM. *) +let client = Unix.socket Unix.PF_UNIX Unix.SOCK_DGRAM 0 +let () = Unix.connect client (Unix.ADDR_UNIX "/tmp/mysock") + (* @@PLEAC@@_17.7 *) #load "unix.cma";; |
From: Dave B. <ram...@us...> - 2008-09-03 07:52:49
|
Update of /cvsroot/pleac/pleac/pleac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4186 Modified Files: pleac_ocaml.data Log Message: 17.5: Setting Up a UDP Server Index: pleac_ocaml.data =================================================================== RCS file: /cvsroot/pleac/pleac/pleac/pleac_ocaml.data,v retrieving revision 1.204 retrieving revision 1.205 diff -u -r1.204 -r1.205 --- pleac_ocaml.data 1 Sep 2008 18:47:35 -0000 1.204 +++ pleac_ocaml.data 3 Sep 2008 07:52:56 -0000 1.205 @@ -14223,7 +14223,6 @@ (*-----------------------------*) (* Receive a UDP message. *) -let () = Unix.bind socket portaddr let msg = String.create maxlen let len, portaddr = Unix.recvfrom socket msg 0 maxlen [] @@ -14271,6 +14270,102 @@ Printf.printf "Clock on %s is %d seconds ahead of this one.\n" host (int_of_float delta) +(* @@PLEAC@@_17.5 *) +#load "unix.cma";; +let () = + begin + try + Unix.bind socket (Unix.ADDR_INET (Unix.inet_addr_any, server_port)); + with Unix.Unix_error (e, _, _) -> + Printf.eprintf "Couldn't be a udp server on port %d: %s\n" + server_port (Unix.error_message e); + exit 1 + end; + let him = String.create max_to_read in + while true do + ignore (Unix.recvfrom socket him 0 max_to_read []); + (* do something *) + done + +(*-----------------------------*) + +#!/usr/bin/ocaml +(* udpqotd - UDP message server *) +#load "unix.cma";; + +let maxlen = 1024 +let portno = 5151 + +let sock = + Unix.socket Unix.PF_INET Unix.SOCK_DGRAM + (Unix.getprotobyname "udp").Unix.p_proto + +let () = + Unix.bind sock (Unix.ADDR_INET (Unix.inet_addr_any, portno)); + Printf.printf "Awaiting UDP messages on port %d\n%!" portno + +let oldmsg = ref "This is the starting message." + +let () = + let newmsg = String.create maxlen in + while true do + let newmsg, hishost, sockaddr = + match Unix.recvfrom sock newmsg 0 maxlen [] with + | len, (Unix.ADDR_INET (addr, port) as sockaddr) -> + String.sub newmsg 0 len, + (Unix.gethostbyaddr addr).Unix.h_name, + sockaddr + | _ -> assert false in + Printf.printf "Client %s said ``%s''\n%!" hishost newmsg; + ignore + (Unix.sendto sock !oldmsg 0 (String.length !oldmsg) [] sockaddr); + oldmsg := Printf.sprintf "[%s] %s" hishost newmsg + done + +(*-----------------------------*) + +#!/usr/bin/ocaml +(* udpmsg - send a message to the udpqotd server *) +#load "unix.cma";; + +let maxlen = 1024 +let portno = 5151 +let timeout = 5 + +let server_host, msg = + match Array.to_list Sys.argv with + | _ :: head :: tail -> head, String.concat " " tail + | _ -> + Printf.eprintf "Usage: %s server_host msg ...\n" Sys.argv.(0); + exit 1 + +let sock = + Unix.socket Unix.PF_INET Unix.SOCK_DGRAM + (Unix.getprotobyname "udp").Unix.p_proto + +let sockaddr = + let addr = (Unix.gethostbyname server_host).Unix.h_addr_list.(0) in + Unix.ADDR_INET (addr, portno) + +let handle_alarm signal = + Printf.eprintf "recv from %s timed out after %d seconds.\n" + server_host timeout; + exit 1 + +let () = + ignore (Unix.sendto sock msg 0 (String.length msg) [] sockaddr); + Sys.set_signal Sys.sigalrm (Sys.Signal_handle handle_alarm); + ignore (Unix.alarm timeout); + let msg = String.create maxlen in + let msg, hishost = + match Unix.recvfrom sock msg 0 maxlen [] with + | len, Unix.ADDR_INET (addr, port) -> + String.sub msg 0 len, + (Unix.gethostbyaddr addr).Unix.h_name + | _ -> assert false in + ignore (Unix.alarm 0); + Printf.printf "Server %s responded ``%s''\n" hishost msg + (* @@PLEAC@@_17.7 *) #load "unix.cma";; |