Using "pure" (?) Ada, how to determine whether a file is a "text" file, not a binary?
As a side question, how does one read "binary" files in Ada?
On 2023-07-01 19:15, Kenneth Wolcott wrote:
Using "pure" (?) Ada, how to determine whether a file is a "text" file, not a binary?That depends on the definition of a text file. Under Unix and Windows, all files
are sequences of bytes, and so may be considered sequences of Characters, and so
text files.
If you can define what distinguishes text files from binary files, then it should be fairly easy to write Ada to distinguish them.
For example, if a text file is one in which all the characters, except line terminators, are graphic characters, then it should be clear how to determine
whether a file meets that definition of a text file.
As a side question, how does one read "binary" files in Ada?Ada has Direct_IO, Sequential_IO, and Stream_IO for reading binary files. Which
you would use and how to use it depends on what's in the file and what you need
to do with it.
Kenneth Wolcott writes:
On Saturday, July 1, 2023 at 1:39:30 PM UTC-7, Jeffrey R.Carter wrote:[...]
On 2023-07-01 19:15, Kenneth Wolcott wrote:
For example, if a text file is one in which all the characters, except line
terminators, are graphic characters, then it should be clear how to determine
whether a file meets that definition of a text file.
I think that is the definition that I'm going to pursue as theThink about how you want to handle tab characters (non-graphic but
simplest and effective definition.
common in some text) and carriage return characters (non-graphic but
part of a line terminator for Windows-style text files).
Also think about the various ways of representing text: ASCII, Latin-1, UTF-8, UTF-16, etc.
On Saturday, July 1, 2023 at 1:39:30 PM UTC-7, Jeffrey R.Carter wrote:[...]
On 2023-07-01 19:15, Kenneth Wolcott wrote:
For example, if a text file is one in which all the characters, except line >> terminators, are graphic characters, then it should be clear how to determine
whether a file meets that definition of a text file.
I think that is the definition that I'm going to pursue as the
simplest and effective definition.
On Saturday, July 1, 2023 at 2:39:06 PM UTC-7, Keith Thompson wrote:
Kenneth Wolcott writes:
On Saturday, July 1, 2023 at 1:39:30 PM UTC-7, Jeffrey R.Carter wrote: >>>> On 2023-07-01 19:15, Kenneth Wolcott wrote:[...]
Think about how you want to handle tab characters (non-graphic butFor example, if a text file is one in which all the characters, except line
terminators, are graphic characters, then it should be clear how to determine
whether a file meets that definition of a text file.
I think that is the definition that I'm going to pursue as the
simplest and effective definition.
common in some text) and carriage return characters (non-graphic but
part of a line terminator for Windows-style text files).
Also think about the various ways of representing text: ASCII, Latin-1,
UTF-8, UTF-16, etc.
Thanks, Keith!
It looks like just need to more carefully examine the existing Ada I/O packages and experiment with the possibilities...
Ken
On 01/07/2023 22:50, Kenneth Wolcott wrote:
On Saturday, July 1, 2023 at 2:39:06 PM UTC-7, Keith Thompson wrote:
Kenneth Wolcott writes:
On Saturday, July 1, 2023 at 1:39:30 PM UTC-7, Jeffrey R.Carter wrote: >>>> On 2023-07-01 19:15, Kenneth Wolcott wrote:[...]
Think about how you want to handle tab characters (non-graphic butFor example, if a text file is one in which all the characters, except line
terminators, are graphic characters, then it should be clear how to determine
whether a file meets that definition of a text file.
I think that is the definition that I'm going to pursue as the
simplest and effective definition.
common in some text) and carriage return characters (non-graphic but
part of a line terminator for Windows-style text files).
Also think about the various ways of representing text: ASCII, Latin-1, >> UTF-8, UTF-16, etc.
Thanks, Keith!
It looks like just need to more carefully examine the existing Ada I/O packages and experiment with the possibilities...
KenMaybe worth looking at the unix file utility, docs and source are available
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (2 / 14) |
Uptime: | 128:16:39 |
Calls: | 7,612 |
Files: | 12,789 |
Messages: | 5,685,053 |