From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA28204; Fri, 13 Sep 2002 02:06:53 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA28232 for ; Fri, 13 Sep 2002 02:06:52 +0200 (MET DST) Received: from lithinos.com ([192.41.68.34]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8D06p105202 for ; Fri, 13 Sep 2002 02:06:51 +0200 (MET DST) Received: from stone (42dbc309.dsl.aros.net [66.219.195.9]) by lithinos.com (8.12.5/8.11.0) with SMTP id g8D058km003930 for ; Thu, 12 Sep 2002 18:05:09 -0600 X-Authentication-Warning: lithinos.com: lought owned process doing -bs Message-ID: <000a01c25ab9$90a90200$0a00a8c0@stone> From: "Richard Lyman" To: Subject: [Caml-list] Setting the EOL character.... Date: Thu, 12 Sep 2002 18:07:35 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0007_01C25A87.4592D250" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C25A87.4592D250 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To start - I really don't know that much about programming (3 years = self-taught in scripted web languages - Perl/PHP/Ruby), and I'm trying = to learn OCaml... I've mostly dealt with persistent socket servers in other programming = languages, and I'd like to write one in OCaml. I've read most of the book - Developing Applications with Objective Caml = (English PDF), so I understand a little - but I'm still very unsure of = myself. Here's the problem I'm trying to solve... I have a proprietary format I'm trying to read in through a socket - = when I say proprietary I mean that the EOL character is the ASCII null = character (\000) and not the '\n' character. I've looked at the examples in the OReilly book, but I'm not sure how to = change the default End Of Line character (\n) to \000. Will I have to do some sort of pattern match on the stream so that I can = deal with 'each line' using \000 as the EOL character? Do the input, input_line, read, or read_line methods accept a different = EOL character as a parameter - or can I define the method differently? Since I can read in a certain amount of characters with methods like = read, can I find the location of the ASCII null character and read from = the stream until right after it? I hope I've asked good enough questions... Thanks for any help you guys can give! Let me know if anything's not clear enough... -Rich ------=_NextPart_000_0007_01C25A87.4592D250 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
To start - I really don't know that = much about=20 programming (3 years self-taught in scripted web languages - = Perl/PHP/Ruby), and=20 I'm trying to learn OCaml...
 
I've mostly dealt with persistent = socket servers in=20 other programming languages, and I'd like to write one in=20 OCaml.
 
I've read most of the book - Developing = Applications with Objective Caml (English PDF), so I understand a little = - but=20 I'm still very unsure of myself.
 
Here's the problem I'm trying to=20 solve...
 
I have a proprietary format I'm trying = to read in=20 through a socket - when I say proprietary I mean that the EOL character = is the=20 ASCII null character (\000) and not the '\n' character.
 
I've looked at the examples in the = OReilly book,=20 but I'm not sure how to change the default End Of Line character (\n) to = \000.
 
Will I have to do some sort of pattern = match on the=20 stream so that I can deal with 'each line' using \000 as the EOL=20 character?
 
Do the input, input_line, read, or = read_line=20 methods accept a different EOL character as a parameter - or can I = define the=20 method differently?
 
Since I can read in a certain amount of = characters=20 with methods like read, can I find the location of the ASCII null = character and=20 read from the stream until right after it?
 
I hope I've asked good enough=20 questions...
 
Thanks for any help you guys can = give!
 
Let me know if anything's not clear=20 enough...
 
-Rich
------=_NextPart_000_0007_01C25A87.4592D250-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA29287; Fri, 13 Sep 2002 04:24:41 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA29266 for ; Fri, 13 Sep 2002 04:24:39 +0200 (MET DST) Received: from imo-r08.mx.aol.com (imo-r08.mx.aol.com [152.163.225.104]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8D2Oc109422 for ; Fri, 13 Sep 2002 04:24:38 +0200 (MET DST) Received: from artboreb@netscape.net by imo-r08.mx.aol.com (mail_out_v34.10.) id 9.b5.4336443 (22683); Thu, 12 Sep 2002 22:24:22 -0400 (EDT) Received: from netscape.net (mow-m08.webmail.aol.com [64.12.184.136]) by air-in04.mx.aol.com (v88.20) with ESMTP id MAILININ44-0912222421; Thu, 12 Sep 2002 22:24:21 -0400 Date: Thu, 12 Sep 2002 22:24:21 -0400 From: artboreb@netscape.net (Arturo Borquez) To: rich@lithinos.com ("Richard Lyman") Cc: caml-list@inria.fr Subject: RE: [Caml-list] Setting the EOL character.... Message-ID: <4D5CA086.356E9A2F.00958B05@netscape.net> X-Mailer: Atlas Mailer 2.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk "Richard Lyman" wrote: >To start - I really don't know that much about programming (3 years self-taught in scripted web languages - Perl/PHP/Ruby), and I'm trying to learn OCaml... > >I've mostly dealt with persistent socket servers in other programming languages, and I'd like to write one in OCaml. > >I've read most of the book - Developing Applications with Objective Caml (English PDF), so I understand a little - but I'm still very unsure of myself. > >Here's the problem I'm trying to solve... > >I have a proprietary format I'm trying to read in through a socket - when I say proprietary I mean that the EOL character is the ASCII null character (\000) and not the '\n' character. > >I've looked at the examples in the OReilly book, but I'm not sure how to change the default End Of Line character (\n) to \000. > >Will I have to do some sort of pattern match on the stream so that I can deal with 'each line' using \000 as the EOL character? > >Do the input, input_line, read, or read_line methods accept a different EOL character as a parameter - or can I define the method differently? > >Since I can read in a certain amount of characters with methods like read, can I find the location of the ASCII null character and read from the stream until right after it? > >I hope I've asked good enough questions... > >Thanks for any help you guys can give! > >Let me know if anything's not clear enough... > >-Rich > Hi, you could try something like this let read_eol inchan = let rec f buf = let c = input_char inchan in if c = '\000' then Buffer.contents buf else begin Buffer.add_char buf c; f buf end in f (Buffer.create 64);; or in 'revised syntax which I prefer) value read_eol inchan = f (Buffer.create 64) where rec f buf = let c = input_char inchan in if c = '\000' then Buffer.contents buf else do { Buffer.add_char buf c; f buf } ; (Note there is no exception handling in examples) Regards -- Arturo Borquez __________________________________________________________________ The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA29296; Fri, 13 Sep 2002 04:36:04 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA29727 for ; Fri, 13 Sep 2002 04:36:04 +0200 (MET DST) Received: from lithinos.com ([192.41.68.34]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8D2a2109739 for ; Fri, 13 Sep 2002 04:36:02 +0200 (MET DST) Received: from stone (42dbc309.dsl.aros.net [66.219.195.9]) by lithinos.com (8.12.5/8.11.0) with SMTP id g8D2YJQZ007198 for ; Thu, 12 Sep 2002 20:34:19 -0600 X-Authentication-Warning: lithinos.com: lought owned process doing -bs Message-ID: <000401c25ace$6896c7b0$0a00a8c0@stone> From: "Richard Lyman" To: References: <4D5CA086.356E9A2F.00958B05@netscape.net> Subject: Re: [Caml-list] Setting the EOL character.... Date: Thu, 12 Sep 2002 20:36:45 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Ok... That doesn't look too bad - and I think I almost understand it. : ) ... so then - there's no OCaml concept of a global EOL variable, or method that deals with reading in from a stream until the EOL?? I was hoping more for something along the lines of - (start pseudocode) myStream = Unix.accepted_socket_stream while(true){ a_line = myStream.read_until("\000") deal_with_line(a_line) } (end pseudocode) Thanks for your thoughts! -Rich ----- Original Message ----- From: "Arturo Borquez" To: ""Richard Lyman"" Cc: Sent: Thursday, September 12, 2002 8:24 PM Subject: RE: [Caml-list] Setting the EOL character.... > "Richard Lyman" wrote: > > >To start - I really don't know that much about programming (3 years self-taught in scripted web languages - Perl/PHP/Ruby), and I'm trying to learn OCaml... > > > >I've mostly dealt with persistent socket servers in other programming languages, and I'd like to write one in OCaml. > > > >I've read most of the book - Developing Applications with Objective Caml (English PDF), so I understand a little - but I'm still very unsure of myself. > > > >Here's the problem I'm trying to solve... > > > >I have a proprietary format I'm trying to read in through a socket - when I say proprietary I mean that the EOL character is the ASCII null character (\000) and not the '\n' character. > > > >I've looked at the examples in the OReilly book, but I'm not sure how to change the default End Of Line character (\n) to \000. > > > >Will I have to do some sort of pattern match on the stream so that I can deal with 'each line' using \000 as the EOL character? > > > >Do the input, input_line, read, or read_line methods accept a different EOL character as a parameter - or can I define the method differently? > > > >Since I can read in a certain amount of characters with methods like read, can I find the location of the ASCII null character and read from the stream until right after it? > > > >I hope I've asked good enough questions... > > > >Thanks for any help you guys can give! > > > >Let me know if anything's not clear enough... > > > >-Rich > > > > Hi, > > you could try something like this > > let read_eol inchan = > let rec f buf = > let c = input_char inchan in > if c = '\000' then Buffer.contents buf > else begin Buffer.add_char buf c; f buf end > in f (Buffer.create 64);; > > or in 'revised syntax which I prefer) > > value read_eol inchan = > f (Buffer.create 64) where rec f buf = > let c = input_char inchan in > if c = '\000' then Buffer.contents buf > else do { Buffer.add_char buf c; f buf } > ; > > (Note there is no exception handling in examples) > Regards > -- > Arturo Borquez > > > __________________________________________________________________ > The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp > > Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA04273; Fri, 13 Sep 2002 11:01:04 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA03891 for ; Fri, 13 Sep 2002 11:01:03 +0200 (MET DST) Received: from athlon.baretta.com (host19-68.pool80116.interbusiness.it [80.116.68.19]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8D912928957 for ; Fri, 13 Sep 2002 11:01:02 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 27B3E273B9; Fri, 13 Sep 2002 11:10:01 +0200 (CEST) Message-ID: <3D81AB68.5010606@baretta.com> Date: Fri, 13 Sep 2002 11:10:00 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Richard Lyman , Ocaml Subject: Re: [Caml-list] Setting the EOL character.... References: <4D5CA086.356E9A2F.00958B05@netscape.net> <000401c25ace$6896c7b0$0a00a8c0@stone> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Richard Lyman wrote: > Ok... > > That doesn't look too bad - and I think I almost understand it. : ) > > ... so then - there's no OCaml concept of a global EOL variable, or method > that deals with reading in from a stream until the EOL?? > > I was hoping more for something along the lines of - > > (start pseudocode) > > myStream = Unix.accepted_socket_stream > while(true){ > a_line = myStream.read_until("\000") > deal_with_line(a_line) > } > > (end pseudocode) > > Thanks for your thoughts! > > -Rich How about the following: let process_line out_channel line = .... in let read_until_null in_channel out_channel = Scanf.fscanf in_channel "[^\000]\000" (process_line out_channel) in let process_request in_channel out_channel = try while true do read_until_null in_channel out_channel done with End_of_file -> () let sockaddr = in Unix.establish_server process_request sockaddr Nonetheless, let me suggest that you look into ocamllex and ocamlyacc--lexer and parser generators respectively. They are probably your best choice for lexing and parsing the input stream, no matter how weird its structure. Alex ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA14268; Fri, 13 Sep 2002 17:34:06 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA13846 for ; Fri, 13 Sep 2002 17:34:05 +0200 (MET DST) Received: from waco.inria.fr (waco.inria.fr [128.93.25.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8DFXw909004; Fri, 13 Sep 2002 17:33:58 +0200 (MET DST) Received: (from verlyck@localhost) by waco.inria.fr (8.11.1/8.11.1) id g8DFXwK30934; Fri, 13 Sep 2002 17:33:58 +0200 Date: Fri, 13 Sep 2002 17:33:58 +0200 Message-Id: <200209131533.g8DFXwK30934@waco.inria.fr> X-Authentication-Warning: waco.inria.fr: verlyck set sender to Bruno.Verlyck@inria.fr using -f To: rich@lithinos.com CC: caml-list@inria.fr In-reply-to: <000401c25ace$6896c7b0$0a00a8c0@stone> (rich@lithinos.com) Subject: Re: [Caml-list] Setting the EOL character.... From: Bruno.Verlyck@inria.fr References: <4D5CA086.356E9A2F.00958B05@netscape.net> <000401c25ace$6896c7b0$0a00a8c0@stone> Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: "Richard Lyman" Date: Thu, 12 Sep 2002 20:36:45 -0600 ... so then - there's no OCaml concept of a global EOL variable, or method that deals with reading in from a stream until the EOL?? I was hoping more for something along the lines of - myStream = Unix.accepted_socket_stream while(true){ a_line = myStream.read_until("\000") deal_with_line(a_line) } FWIW, Cash supports reading a line terminated by any char from a set of chars. If that's your only need, Cash may be overkill, except if you have a performance bottleneck here: its read_line should be at least as fast as Pervasives.read_line. Anyway, http://pauillac.inria.fr/cash/ Bruno. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA28540; Mon, 16 Sep 2002 12:07:43 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA28058 for caml-list@pauillac.inria.fr; Mon, 16 Sep 2002 12:07:43 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA14689 for ; Fri, 13 Sep 2002 17:50:20 +0200 (MET DST) Received: from orinoco.alve.com (orinoco.alve.com [209.99.70.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8DFoI113298 for ; Fri, 13 Sep 2002 17:50:19 +0200 (MET DST) Received: from yahoo.com (mattwb@valery4.alve.com [209.99.70.98]) by orinoco.alve.com (8.11.6/8.11.6) with ESMTP id g8DF5Jj28259 for ; Fri, 13 Sep 2002 10:05:19 -0500 Message-ID: <3D8209C8.2020604@yahoo.com> Date: Fri, 13 Sep 2002 10:52:40 -0500 From: Matt Boyd User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020606 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Setting the EOL character.... References: <4D5CA086.356E9A2F.00958B05@netscape.net> <000401c25ace$6896c7b0$0a00a8c0@stone> <200209131533.g8DFXwK30934@waco.inria.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Bruno.Verlyck@inria.fr wrote: > From: "Richard Lyman" > Date: Thu, 12 Sep 2002 20:36:45 -0600 > > ... so then - there's no OCaml concept of a global EOL variable, or > method that deals with reading in from a stream until the EOL?? > I make no promises of efficiency or thread safety, but this should do what you want: let read_until n = let buf = Buffer.create 100 in fun st -> let rec aux = function | n' when n' = n -> let str = Buffer.contents buf in Buffer.reset buf; str | n' -> Buffer.add_char buf n'; aux (Stream.next st); in aux (Stream.next st) let read_until_null = read_until '\000' > > Bruno. > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners