1

I have a text file that I am splitting into two files. I am going through the input file line by line looking for CRLF, and with an if statement, performing an action when a CRLF is found. Here is a short snip-it of the input file with CRLFs. I am new to Ada, so if there is a better way to do this, please let me know

message format with CRLF showing

I want to be able to use ASCII.CR and ASCII.LF in an if that is possible.

I can get the single CRs that are on their own line with the code below, but I am having issues when trying to get the CRLF lines.

procedure readFrom is
   My_File  : FILE_TYPE;
   File_Name : String := "input.txt";
   CR : String := "" & ASCII.CR;

   begin

      open(My_File, In_File, File_Name);
      create(out1, Out_File, "out1.txt";
      create(out, Out_File, "out2.txt";

      while not Ada.Text_IO.End_Of_File (My_File) loop
        declare
         line : String := Get_Line(My_File);
        begin

           if (line = CR) then
              <*search the line and do stuff*>
           end if;
        end:
      end loop:
      Close(My_File);

end readFrom;
Jeff Kyzer
  • 616
  • 2
  • 7
  • 14

2 Answers2

3

That’s not really a text file; not with that mix of line delimiters!

Much better to use Ada.Streams.Stream_IO (ARM A.12.1) and use Character’Read until you get an End_Error exception.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
2

Get_Line already strips off the line separator (which is CRLF on a windows platform, or just LF on linux or other *nix platforms), so your approach won't work. Try reading character by character instead.

Also, the ASCII package is deprecated. You're better off with Ada.Characters.Latin_1.

(Of course it would be better to let the runtime decide which line terminator to use with the Get_Line and then process the line, but I assume this is a homework assignment and finding the end of line is a requirement?)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
egilhh
  • 6,464
  • 1
  • 18
  • 19
  • Thank you for the info. No, not a homework, but a government project where I am stuck is Ada83. It is for a system that was put into use back in the 1980s – Jeff Kyzer Mar 14 '16 at 21:23