comp.lang.ada
 help / color / mirror / Atom feed
* Binary Files in Text Editor
@ 1998-11-10  0:00 robinsoj
  1998-11-11  0:00 ` Dizzy Casablanca
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: robinsoj @ 1998-11-10  0:00 UTC (permalink / raw)


Is it possible to view binary files with a text editor or do you always have
to convert the binary file into a text file?  Also, is there a Web site where
I can get more information on Sequential_IO and what it does?

--
James H. Robinson, III

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-10  0:00 Binary Files in Text Editor robinsoj
@ 1998-11-11  0:00 ` Dizzy Casablanca
  1998-11-11  0:00 ` Marc A. Criley
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Dizzy Casablanca @ 1998-11-11  0:00 UTC (permalink / raw)




robinsoj@my-dejanews.com wrote:

> Is it possible to view binary files with a text editor or do you always have
> to convert the binary file into a text file?  Also, is there a Web site where
> I can get more information on Sequential_IO and what it does?
>
> --
> James H. Robinson, III
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

I am uncertain, myself... however - I suspect that to view a binary file in a
text-editor
would make for astronomically long documents... maybe...

I have a couple of Hex editors.. one (with a rather innocuous application despite
its name)
is called HackMan - it lets you look at the binary code...

I am uncertain why anyone would want to do so... as Hexadecimal seems to
abbreviate things more conveniently.. but the software is free for download.... I
foregte where - one of the major download sites.. just search for it by name.

-Graeme.


-----------------------------------------------------------
Have A Nice Day. :-)
 http://www.geocities.com/SouthBeach/Surf/4269/index.html





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-10  0:00 Binary Files in Text Editor robinsoj
                   ` (3 preceding siblings ...)
  1998-11-11  0:00 ` robinsoj
@ 1998-11-11  0:00 ` John McCabe
  4 siblings, 0 replies; 10+ messages in thread
From: John McCabe @ 1998-11-11  0:00 UTC (permalink / raw)


robinsoj@my-dejanews.com wrote:
>Is it possible to view binary files with a text editor or do you always
>have to convert the binary file into a text file?

You could try using Emacs. Load the file into Emacs and then enter 
hexl-mode.

>Also, is there a Web site where I can get more information on
>Sequential_IO and what it does?

This is defined fairly clearly in Section A.8 of the ARM

-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-10  0:00 Binary Files in Text Editor robinsoj
  1998-11-11  0:00 ` Dizzy Casablanca
@ 1998-11-11  0:00 ` Marc A. Criley
  1998-11-11  0:00 ` David C. Hoos, Sr.
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Marc A. Criley @ 1998-11-11  0:00 UTC (permalink / raw)


robinsoj@my-dejanews.com wrote:
> 
> Is it possible to view binary files with a text editor or do you always have
> to convert the binary file into a text file?

Use the hexl-mode in Emacs.

> 
> --
> James H. Robinson, III
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

-- 
Marc A. Criley
Chief Software Architect
Lockheed Martin ATWCS
marc.a.criley@lmco.com
Phone: (610) 354-7861
Fax  : (610) 354-7308




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-10  0:00 Binary Files in Text Editor robinsoj
                   ` (2 preceding siblings ...)
  1998-11-11  0:00 ` David C. Hoos, Sr.
@ 1998-11-11  0:00 ` robinsoj
  1998-11-12  0:00   ` John McCabe
  1998-11-11  0:00 ` John McCabe
  4 siblings, 1 reply; 10+ messages in thread
From: robinsoj @ 1998-11-11  0:00 UTC (permalink / raw)


Let me re-phrase the question:

I would like to display the contents of a binary file to the screen.  My
machine is running GNAT Ada on	Windows NT.  Do I have to convert a binary
file into a text file before displaying its contents on the screen (or
re-directing it to the printer)?

In article <72aiik$c1u$1@nnrp1.dejanews.com>,
  robinsoj@my-dejanews.com wrote:
> Is it possible to view binary files with a text editor or do you always have
> to convert the binary file into a text file?  Also, is there a Web site where
> I can get more information on Sequential_IO and what it does?
>
> --
> James H. Robinson, III
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
>


--
James H. Robinson, III

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-10  0:00 Binary Files in Text Editor robinsoj
  1998-11-11  0:00 ` Dizzy Casablanca
  1998-11-11  0:00 ` Marc A. Criley
@ 1998-11-11  0:00 ` David C. Hoos, Sr.
  1998-11-11  0:00 ` robinsoj
  1998-11-11  0:00 ` John McCabe
  4 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 1998-11-11  0:00 UTC (permalink / raw)



robinsoj@my-dejanews.com wrote in message
<72aiik$c1u$1@nnrp1.dejanews.com>...
>Is it possible to view binary files with a text editor or do you always
have
>to convert the binary file into a text file?  Also, is there a Web site
where
>I can get more information on Sequential_IO and what it does?

Emacs will view/edit binary files, displaying non-printable ASCII characters
as octal escape sequences.  It can handle files at least up to ten
megabytes.
>
Sequential I/O simply writes or reads (according to the mode with which the
file was opened), items of the type for which the instantiation was done.

With Ada95, the combination of tagged types and Stream IO attributes, one
can write and read heterogeneous files, rendering Sequential I/O largely a
relic, in my view.

David C. Hoos, Sr.







^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-11  0:00 ` robinsoj
@ 1998-11-12  0:00   ` John McCabe
  1998-11-12  0:00     ` robinsoj
  0 siblings, 1 reply; 10+ messages in thread
From: John McCabe @ 1998-11-12  0:00 UTC (permalink / raw)


robinsoj@my-dejanews.com wrote:
>Let me re-phrase the question:
>
>I would like to display the contents of a binary file to the screen.  My
>machine is running GNAT Ada on	Windows NT.  Do I have to convert a
>binary file into a text file before displaying its contents on the
>screen (or re-directing it to the printer)?

You can display it on the screen if you like, but how you do it depends 
on exactly what you are expecting to see on the screen.

Tell us more about what you want to see and we may be able to help more.

One possibility is to use Sequential_IO or Direct_IO to read in a byte at 
a time then display the equivalent ASCII character representation. 
Alternatively, you could display each byte as a hexadecimal numeric 
representation. Both of these are very easy but, as I said, it depends on 
what you want to see. 


-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-12  0:00   ` John McCabe
@ 1998-11-12  0:00     ` robinsoj
  1998-11-13  0:00       ` John McCabe
  1998-11-14  0:00       ` Jerry van Dijk
  0 siblings, 2 replies; 10+ messages in thread
From: robinsoj @ 1998-11-12  0:00 UTC (permalink / raw)


I have an array of records (there are two string fields, an integer field, and
a float field) that I converted from a text file to a binary file.  Now I want
to display those records to the screen like a list.

In article <72e9el$top@gcsin3.geccs.gecm.com>,
  John McCabe <john@assen.demon.co.uk> wrote:
> robinsoj@my-dejanews.com wrote:
> >Let me re-phrase the question:
> >
> >I would like to display the contents of a binary file to the screen.  My
> >machine is running GNAT Ada on	Windows NT.  Do I have to convert a
> >binary file into a text file before displaying its contents on the
> >screen (or re-directing it to the printer)?
>
> You can display it on the screen if you like, but how you do it depends
> on exactly what you are expecting to see on the screen.
>
> Tell us more about what you want to see and we may be able to help more.
>
> One possibility is to use Sequential_IO or Direct_IO to read in a byte at
> a time then display the equivalent ASCII character representation.
> Alternatively, you could display each byte as a hexadecimal numeric
> representation. Both of these are very easy but, as I said, it depends on
> what you want to see.
>
> --
> Best Regards
> John McCabe
> ---------------------------------------------------------------------
> Marconi Electronic Systems
> Simulation & Training Division
> =====================================================================
> Not necessarily my company or service providers opinions.
> =====================================================================
>
>


--
James H. Robinson, III

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-12  0:00     ` robinsoj
@ 1998-11-13  0:00       ` John McCabe
  1998-11-14  0:00       ` Jerry van Dijk
  1 sibling, 0 replies; 10+ messages in thread
From: John McCabe @ 1998-11-13  0:00 UTC (permalink / raw)


robinsoj@my-dejanews.com wrote:
>I have an array of records (there are two string fields, an integer
>field, and a float field) that I converted from a text file to a binary
>file.  Now I want to display those records to the screen like a list.

If they're in a binary file then you need to use something like 
Sequential_IO or Direct_IO to retrieve them. Presumably the records are 
fixed length.

If you want to see the interpreted contents of the record on the screen 
then just use Ada.Text_IO, Ada.Integer_Text_IO and Ada.Float_Text_IO to 
output the fields individually.

If you want to see the records as a series of bytes on the screen, then 
you'll have to convert them individually into a representation that can 
be displayed.

I'm not sure that this answers your question though. If it doesn't can 
you give us an example of what you'd like to see?

-- 
Best Regards
John McCabe
---------------------------------------------------------------------
Marconi Electronic Systems
Simulation & Training Division
=====================================================================
Not necessarily my company or service providers opinions.
=====================================================================






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Binary Files in Text Editor
  1998-11-12  0:00     ` robinsoj
  1998-11-13  0:00       ` John McCabe
@ 1998-11-14  0:00       ` Jerry van Dijk
  1 sibling, 0 replies; 10+ messages in thread
From: Jerry van Dijk @ 1998-11-14  0:00 UTC (permalink / raw)


robinsoj@my-dejanews.com wrote:

: I have an array of records (there are two string fields, an integer field, and
: a float field) that I converted from a text file to a binary file.  Now I want
: to display those records to the screen like a list.

The problem in the discussion seems to be the persistent use of the term
'binary file'.

For reading/writing records Ada offers several options (Direct_IO,
Sequential_IO and Stream_IO). The easiest is using sequential IO, see
example below.

So, the question is: is something like the example below what you meant,
and why do you need a 'binary file'.

Jerry.

----- records.ads -----------------------------------------------------

package Records is

   type Data_Type is
      record
         Name   : String (1 .. 8);
         Active : Boolean;
         Salary : Float;
      end record;

   File_Name : constant String := "data.dat";

end Records;

----- write.adb -------------------------------------------------------

with Records;
with Ada.Sequential_IO;

procedure Write is

   package Data_Files is new Ada.Sequential_IO (Records.Data_Type);
   use Data_Files;

   File : File_Type;
   Data : array (1 .. 3) of Records.Data_Type;

begin

   Data(1) := ("Jerry   ", True,  120_000.00);
   Data(2) := ("Carolien", True,   40_000.00);
   Data(3) := ("Peter   ", False,  65_000.00);

   Create (File, Out_File, Records.File_Name);
   for I in Data'Range loop
      Write (File, Data(I));
   end loop;
   Close (File);

end Write;

----- read.adb --------------------------------------------------------

with Records;
with Ada.Text_IO;
with Ada.Sequential_IO;

procedure Read is

   package Data_Files is new Ada.Sequential_IO (Records.Data_Type);
   use Data_Files;

   File : File_Type;
   Data : Records.Data_Type;

begin

   Open (File, In_File, Records.File_Name);

   while not End_Of_File (File) loop

      Read (File, Data);

      Ada.Text_IO.Put (Data.Name & ASCII.HT);
      Ada.Text_IO.Put (Boolean'Image (Data.Active) & ASCII.HT);
      Ada.Text_IO.Put (Float'Image (Data.Salary));
      Ada.Text_IO.New_Line;

   end loop;

   Close (File);

end Read;


-- 
-- Jerry van Dijk  | email: jdijk@acm.org
-- Leiden, Holland | member Team-Ada
-- Ada & Win32: http://stad.dsl.nl/~jvandyk




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1998-11-14  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-10  0:00 Binary Files in Text Editor robinsoj
1998-11-11  0:00 ` Dizzy Casablanca
1998-11-11  0:00 ` Marc A. Criley
1998-11-11  0:00 ` David C. Hoos, Sr.
1998-11-11  0:00 ` robinsoj
1998-11-12  0:00   ` John McCabe
1998-11-12  0:00     ` robinsoj
1998-11-13  0:00       ` John McCabe
1998-11-14  0:00       ` Jerry van Dijk
1998-11-11  0:00 ` John McCabe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox