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 AAA29253; Mon, 7 Oct 2002 00:56:23 +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 AAA29237 for ; Mon, 7 Oct 2002 00:56:22 +0200 (MET DST) Received: from athlon.baretta.com (host186-68.pool80116.interbusiness.it [80.116.68.186]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g96MuLD09365 for ; Mon, 7 Oct 2002 00:56:21 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 12A72273AE for ; Mon, 7 Oct 2002 01:06:28 +0200 (CEST) Message-ID: <3DA0C1F3.5010308@baretta.com> Date: Mon, 07 Oct 2002 01:06:27 +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: Ocaml Subject: Re: [Caml-list] Bug somewhere... References: <3DA0BFE1.9050302@baretta.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Alessandro Baretta wrote: > It's either on my brain or in the Scanf module, the former possibility > being definitely more likely. > > I have written a very simple program to compute md5 checksums of a codes > taken from a text file. Here it is: > > let scan_line () = Scanf.scanf "%[^\n\r]\n" (fun a -> a) > let digest s = String.uppercase > (Digest.to_hex(Digest.string s)) > let digest_line s = print_endline (s ^ "#" ^ (digest s)) > let _ = try while true do digest_line (scan_line ()) done > with End_of_file -> () I have rewritten my program in ocamllex. This one works. Here it is. { } rule scanline = parse | [^'\n''\r']* {Lexing.lexeme lexbuf} | ['\n''\r']* {scanline lexbuf } | eof {raise End_of_file} { let lexbuf = Lexing.from_channel stdin in let digest s = String.uppercase (Digest.to_hex (Digest.string s)) in let digest_line s = print_endline (s ^ "#" ^ (digest s)) in try while true do digest_line (scanline lexbuf) done with End_of_file -> () } > Seems very reasonable... > > Here's the input file: > > (2002) DMD.CSB.1GL.001.01 > (2002) DMD.CSB.1GL.001.02 > (2002) DMD.CSB.1GL.001.03 > (2002) DMD.CSB.1GL.001.04 > (2002) DMD.CSB.1GL.001.05 > (2002) DMD.CSB.1GL.001.06 > (2002) DMD.CSB.1GL.001.07 > (2002) DMD.CSB.1GL.001.08 > (2002) DMD.CSB.1GL.001.09 > (2002) DMD.CSB.1GL.001.10 > (2002) DMD.CSB.1GL.001.11 > (2002) DMD.CSB.1GL.001.12 > (2002) DMD.CSB.1GL.001.13 > (2002) DMD.CSB.1GL.001.14 > (2002) DMD.CSB.1GL.001.15 > (2002) DMD.CSB.1GL.001.16 > (2002) DMD.CSB.1GL.001.17 > (2002) DMD.CSB.1GL.001.18 > (2002) DMD.CSB.1GL.001.19 > (2002) DMD.CSB.1GL.001.20 And the correct output: (2002) DMD.CSB.1GL.001.01#EA486F3F11C1D1E5BE6DDC2A444BC4E1 (2002) DMD.CSB.1GL.001.02#DA0E405C9E982D4C51F9D21A2FAB5644 (2002) DMD.CSB.1GL.001.03#9D78774667150BBF2FE473CC149A72DB (2002) DMD.CSB.1GL.001.04#72491ED198C8BAB5A659EF4730EBF76D (2002) DMD.CSB.1GL.001.05#AE3CF2982E265B582725AFE770F685F8 (2002) DMD.CSB.1GL.001.06#8825A66BB3C4D1CEB362631C41FF0633 (2002) DMD.CSB.1GL.001.07#AE4F3D477E43943B044E05D5A0BDD498 (2002) DMD.CSB.1GL.001.08#84E0420BB0B52931EF839FB2673116D3 (2002) DMD.CSB.1GL.001.09#144ABD1E3136EBC4BF9642599340326A (2002) DMD.CSB.1GL.001.10#92C65BDDFB8045D96D9B3DDE2580896C (2002) DMD.CSB.1GL.001.11#AB9A737B83B040BCD4CE310977B3667B (2002) DMD.CSB.1GL.001.12#20C1B0322756CC61D3792A6814FA175A (2002) DMD.CSB.1GL.001.13#20C76BA308A80C93CA2A7FFCCBCD9696 (2002) DMD.CSB.1GL.001.14#BDD11EF273D429A7460E4A010F28AF8D (2002) DMD.CSB.1GL.001.15#D55A8BEE54618241691AD349DB5D3B0A (2002) DMD.CSB.1GL.001.16#D655BDC9DB0C22A2A03B718125884778 (2002) DMD.CSB.1GL.001.17#4EA753AEF91A7F497689DF1E43E0D083 (2002) DMD.CSB.1GL.001.18#B37C19DBE5ED47E9F3F9C8E257BC8F3E (2002) DMD.CSB.1GL.001.19#A35BEE6D08F95935BFFC61ACFEAC54B7 (2002) DMD.CSB.1GL.001.20#FB357D47CF387E1EBFD94C9E79A1DD6A What's wrong with the Scanf version? 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