From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: Using "pure" (?) Ada, how to determine whether a file is a "text" file, not a binary? Date: Sat, 1 Jul 2023 22:39:27 +0200 Organization: A noiseless patient Spider Message-ID: References: <41a5cad2-b5ca-4996-b057-e1ae8b27f526n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 1 Jul 2023 20:39:27 -0000 (UTC) Injection-Info: dont-email.me; posting-host="4b0b3723792c49dee6ad8f9e712830d1"; logging-data="3083061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jkv/EymNrIJVRS3JmcTRPElv3kkqFMr0=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:q8b/4fEkAnsY3K46W67LcGYLado= Content-Language: en-US In-Reply-To: <41a5cad2-b5ca-4996-b057-e1ae8b27f526n@googlegroups.com> Xref: news.eternal-september.org comp.lang.ada:65394 List-Id: 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. -- Jeff Carter "Ada is the only language where users are happy to have compilation errors!" Jean-Pierre Rosen 166