* Text IO for files not using the standard line termination for the OS
@ 2018-11-18 2:01 jdgressett
2018-11-18 3:44 ` Shark8
2018-11-18 4:40 ` Keith Thompson
0 siblings, 2 replies; 6+ messages in thread
From: jdgressett @ 2018-11-18 2:01 UTC (permalink / raw)
I use Ada 2012 to write Windows programs; my usual compiler is 32-bit TDM-gcc which implements the gcc-5.1.0 version of the Ada compiler.
My problem is a simple one: i need to produce a program which reads lines from a text file; if a line meets a requirement, it is written to an output file; if it does not meet the requirement it is not written to the output file.
The annoyance that I must deal with is the fact that the files are not Windows text files, which use the <cr><lf> convention to terminate text lines.
The files use a single <cr> as the line terminator.
Is there a way to get Ada.Text_IO to use a line terminator that is not the default for the operation system on which the program runs?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Text IO for files not using the standard line termination for the OS
2018-11-18 2:01 Text IO for files not using the standard line termination for the OS jdgressett
@ 2018-11-18 3:44 ` Shark8
2018-11-18 9:26 ` Jeffrey R. Carter
2018-11-18 4:40 ` Keith Thompson
1 sibling, 1 reply; 6+ messages in thread
From: Shark8 @ 2018-11-18 3:44 UTC (permalink / raw)
On Saturday, November 17, 2018 at 7:01:45 PM UTC-7, jdgre...@hotmail.com wrote:
> I use Ada 2012 to write Windows programs; my usual compiler is 32-bit TDM-gcc which implements the gcc-5.1.0 version of the Ada compiler.
>
> My problem is a simple one: i need to produce a program which reads lines from a text file; if a line meets a requirement, it is written to an output file; if it does not meet the requirement it is not written to the output file.
>
> The annoyance that I must deal with is the fact that the files are not Windows text files, which use the <cr><lf> convention to terminate text lines.
>
> The files use a single <cr> as the line terminator.
>
> Is there a way to get Ada.Text_IO to use a line terminator that is not the default for the operation system on which the program runs?
I think you have to do it character-by-character in this case.
There's a library called PragmaARC (IIRC) that has Text_IO packages for non-native text, you might want to take a look there.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Text IO for files not using the standard line termination for the OS
2018-11-18 3:44 ` Shark8
@ 2018-11-18 9:26 ` Jeffrey R. Carter
2018-11-18 23:41 ` jdgressett
0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey R. Carter @ 2018-11-18 9:26 UTC (permalink / raw)
On 11/18/18 4:44 AM, Shark8 wrote:
>
> I think you have to do it character-by-character in this case.
> There's a library called PragmaARC (IIRC) that has Text_IO packages for non-native text, you might want to take a look there.
These are the PragmAda Reusable Components. Package PragmARC.Text_IO handles
files with 3 kinds of line terminators:
type EOL_ID is (DOS_Windows_EOL, Mac_EOL, Unix_EOL);
-- Used to specify what line terminator to use on output
-- DOS_Windows_EOL = CR-LF
-- Mac_EOL = CR
-- Unix_EOL = LF
For reading, it automatically handles EOLs of all 3 kinds, which may be mixed in
the same file (though I've never encountered this). For output, when the files
is created/opened, the desired EOL kind is specified.
The PragmARCs are at
https://github.com/jrcarter/PragmARC
HTH
--
Jeff Carter
"Ditto, you provincial putz?"
Blazing Saddles
86
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Text IO for files not using the standard line termination for the OS
2018-11-18 9:26 ` Jeffrey R. Carter
@ 2018-11-18 23:41 ` jdgressett
0 siblings, 0 replies; 6+ messages in thread
From: jdgressett @ 2018-11-18 23:41 UTC (permalink / raw)
On Sunday, November 18, 2018 at 3:26:31 AM UTC-6, Jeffrey R. Carter wrote:
> On 11/18/18 4:44 AM, Shark8 wrote:
> >
> > I think you have to do it character-by-character in this case.
> > There's a library called PragmaARC (IIRC) that has Text_IO packages for non-native text, you might want to take a look there.
>
> These are the PragmAda Reusable Components. Package PragmARC.Text_IO handles
> files with 3 kinds of line terminators:
>
> type EOL_ID is (DOS_Windows_EOL, Mac_EOL, Unix_EOL);
> -- Used to specify what line terminator to use on output
> -- DOS_Windows_EOL = CR-LF
> -- Mac_EOL = CR
> -- Unix_EOL = LF
>
> For reading, it automatically handles EOLs of all 3 kinds, which may be mixed in
> the same file (though I've never encountered this). For output, when the files
> is created/opened, the desired EOL kind is specified.
>
> The PragmARCs are at
>
> https://github.com/jrcarter/PragmARC
>
> HTH
>
> --
> Jeff Carter
> "Ditto, you provincial putz?"
> Blazing Saddles
> 86
That is what I need - thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Text IO for files not using the standard line termination for the OS
2018-11-18 2:01 Text IO for files not using the standard line termination for the OS jdgressett
2018-11-18 3:44 ` Shark8
@ 2018-11-18 4:40 ` Keith Thompson
2018-11-18 10:10 ` Simon Wright
1 sibling, 1 reply; 6+ messages in thread
From: Keith Thompson @ 2018-11-18 4:40 UTC (permalink / raw)
jdgressett@hotmail.com writes:
> I use Ada 2012 to write Windows programs; my usual compiler is 32-bit
> TDM-gcc which implements the gcc-5.1.0 version of the Ada compiler.
>
> My problem is a simple one: i need to produce a program which reads
> lines from a text file; if a line meets a requirement, it is written
> to an output file; if it does not meet the requirement it is not
> written to the output file.
>
> The annoyance that I must deal with is the fact that the files are not
> Windows text files, which use the <cr><lf> convention to terminate
> text lines.
>
> The files use a single <cr> as the line terminator.
That's unusual. The most recent system system I know of that uses that
representation is pre-OSX MacOS.
> Is there a way to get Ada.Text_IO to use a line terminator that is not
> the default for the operation system on which the program runs?
There's no standard way to do it. GNAT does provide some non-standard
Form parameters for Text_IO.Create and Text_IO.Open, but none of then do
just what you want. ("Text_Translation=No" would let you handle
Unix-style text files on Windows, with line endings marked by <lf>.)
http://docs.adacore.com/live/wave/gnat_rm/html/gnat_rm/gnat_rm/the_implementation_of_standard_i_o.html#text-translation
Your best bet might be to translate the files before you feed them to
your program. Or you can read the files in binary mode.
--
Keith Thompson (The_Other_Keith) kst@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-11-18 23:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-18 2:01 Text IO for files not using the standard line termination for the OS jdgressett
2018-11-18 3:44 ` Shark8
2018-11-18 9:26 ` Jeffrey R. Carter
2018-11-18 23:41 ` jdgressett
2018-11-18 4:40 ` Keith Thompson
2018-11-18 10:10 ` Simon Wright
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox