From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Out_File , excess line Date: Wed, 27 Jan 2016 09:26:22 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="d1f7d2633ee45ab9629ebafbf83c9647"; logging-data="2614"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184YdL/3J3TCtsKaCAroPMMKCbr3dPhX3w=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:EHfFmUEmGG0i5fhwBWxujDELYJw= sha1:74amTB3jaA45c8XtuAaubiD9+4w= Xref: news.eternal-september.org comp.lang.ada:29257 Date: 2016-01-27T09:26:22+00:00 List-Id: comicfanzine@gmail.com writes: > But , when we try to open the file manually , the text editor print : > > " This is not a text file . Type unknown . " > PACKAGE ST_IO RENAMES Ada.Streams.Stream_IO ; > > test_file : ST_IO.File_type ; > > Input_Stream : ST_IO.Stream_Access ; [...] > ST_IO.Create( File => test_file , > Mode => ST_IO.Out_File , > Name => "test" ); > > Input_Stream := ST_IO.Stream( test_file ); > > for j in 1..case_array'Length loop > Unbounded_String'Write( Input_Stream , case_array(j) ); > end loop; 'Input_Stream' is a very odd name for a stream you're going to *output* to. What's happening is that (reasonably, though not as far as I can see discussed by the standard) GNAT treats Unbounded_String'Write as if an unbounded string is a discriminated type whose discriminants have defaults; that is, the discriminants (the array bounds) are output to the stream first, followed by the characters of the string. (This is what happens for String'Output; String'Write doesn't include the bounds; is the Unbounded_String'Write behaviour a bug or a feature?). So, if you Unbounded_String'Write "foo", you will get - 4 bytes containing binary 1, the first index of the content - 4 bytes containing binary 3, the last index of the content - 3 bytes of content, 'f' 'o' 'o'. Which looks nothing like a text file. You could try String'Write (Input_Stream, To_String (case_array (j)) & ASCII.LF); (should be OK on Unix systems, don't know about Windows. A text editor should be OK with LF-terminated lines, Notepad not so much.) [1] http://www.ada-auth.org/standards/12rm/html/RM-13-13-2.html#p9.1