Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Bug somewhere...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Bug somewhere...


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