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