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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.116.5 with SMTP id p5mr1987536ywc.23.1465169172932; Sun, 05 Jun 2016 16:26:12 -0700 (PDT) X-Received: by 10.157.25.166 with SMTP id k35mr54755otk.6.1465169172894; Sun, 05 Jun 2016 16:26:12 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!p34no3108498qgp.1!news-out.google.com!107ni250qgx.1!nntp.google.com!q32no4128223qgq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 5 Jun 2016 16:26:12 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.195.27.153; posting-account=AvekzAoAAABj-TclKcOWQmXwA49MFPGX NNTP-Posting-Host: 50.195.27.153 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9c32c60f-99b2-423f-8a13-db8abc9806f0@googlegroups.com> Subject: An extra CR character when writing to file (in addition to CR LF) From: John Smith Injection-Date: Sun, 05 Jun 2016 23:26:12 +0000 Content-Type: text/plain; charset=UTF-8 X-Received-Bytes: 4868 X-Received-Body-CRC: 959367808 Xref: news.eternal-september.org comp.lang.ada:30624 Date: 2016-06-05T16:26:12-07:00 List-Id: Here is my little example. The problem that I have with it is that when it comes time to writing to the output file, the newline characters for some reason are CR CR LF. I'm working in Windows, so I don't understand why I have the extra carriage return. ====================================================================== with Ada.Text_IO.Unbounded_IO; with Ada.Strings.Unbounded; with Ada.Command_Line; with Ada.Directories; with Ada.Direct_IO; with Ada.Text_IO; procedure stuff is Original_File : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String( Source => ""); procedure Manipulate_Contents( Contents : in out Ada.Strings.Unbounded.Unbounded_String) is begin Ada.Strings.Unbounded.Append(Contents, " A hello!"); end Manipulate_Contents; procedure Write_File( Contents : in out Ada.Strings.Unbounded.Unbounded_String; File_Name : in Ada.Strings.Unbounded.Unbounded_String) is New_File : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String( Source => ""); F_Type : Ada.Text_IO.File_Type; begin Ada.Text_IO.Put("Enter the name of the new file: "); New_File := Ada.Text_IO.Unbounded_IO.Get_Line; begin Ada.Text_IO.Open( File => F_Type, Mode => Ada.Text_IO.Out_File, Name => Ada.Strings.Unbounded.To_String(New_File)); exception when Ada.Text_IO.Name_Error => Ada.Text_IO.Create( File => F_Type, Mode => Ada.Text_IO.Out_File, Name => Ada.Strings.Unbounded.To_String(New_File)); end; Ada.Text_IO.Put( File => F_Type, Item => Ada.Strings.Unbounded.To_String(Contents)); Ada.Text_IO.Close( File => F_Type); end Write_File; begin if Ada.Command_Line.Argument_Count = 1 then Original_File := Ada.Strings.Unbounded.To_Unbounded_String(Ada.Command_Line.Argument(1)); else Ada.Text_IO.Put_Line( File => Ada.Text_IO.Standard_Error, Item => "ERROR: Incorrect number of command line arguments passed in."); return; end if; declare File_Size : Natural := Natural(Ada.Directories.Size(Ada.Strings.Unbounded.To_String(Original_File))); subtype File_String is String(1 .. File_Size); package File_String_IO is new Ada.Direct_IO(File_String); F_Type : File_String_IO.File_Type; File_Contents : File_String; U_File_Contents : Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String(""); begin File_String_IO.Open( File => F_Type, Mode => File_String_IO.In_File, Name => Ada.Strings.Unbounded.To_String(Original_File)); File_String_IO.Read( File => F_Type, Item => File_Contents); File_String_IO.Close( File => F_Type); U_File_Contents := Ada.Strings.Unbounded.To_Unbounded_String(File_Contents); Manipulate_Contents( Contents => U_File_Contents); Write_File( Contents => U_File_Contents, File_Name => Original_File); exception when Ada.Text_IO.Name_Error => Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "ERROR:Name_Error: The file does not exist. Exiting."); return; when Ada.Text_IO.Status_Error => Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "ERROR:Status_Error: The file does not exist. Exiting."); return; when Ada.Text_IO.Use_Error => Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "ERROR:Use_Error: The file does not exist. Exiting."); return; when others => Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, "Error encountered, exiting."); return; end; end stuff; ======================================================================