home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / ada / tutorial / dat2txt.ada < prev    next >
Text File  |  1991-03-25  |  2KB  |  48 lines

  1. -- DAT2TXT.ADA   Ver. 2.00   25-MAR-1991   Copyright 1988-1991 John J. Herro
  2. -- Software Innovations Technology
  3. -- 1083 Mandarin Drive NE, Palm Bay, FL  32905-4706   (407)951-0233
  4. --
  5. -- Run this program on a PC before installing ADA-TUTR on another computer.
  6. -- It translates ADA_TUTR.DAT to TUTOR.TXT, a text file that can be easily
  7. -- transferred to other computers.  Then compile and run TXT2DAT.ADA on the
  8. -- other machine to create ADA_TUTR.DAT from TUTOR.TXT.
  9. --
  10. with DIRECT_IO, TEXT_IO;
  11. procedure DAT2TXT is
  12.    subtype BLOCK_SUBTYPE is STRING(1 .. 64);
  13.    package RANDOM_IO is new DIRECT_IO(BLOCK_SUBTYPE);
  14.    DATA_FILE  : RANDOM_IO.FILE_TYPE;                         -- The input file.
  15.    TEXT_FILE  : TEXT_IO.FILE_TYPE;                          -- The output file.
  16.    BLOCK      : BLOCK_SUBTYPE;             -- A block of 64 bytes being copied.
  17.    OK         : BOOLEAN := TRUE;     -- True when both files open successfully.
  18.    LEGAL_NOTE : constant STRING := " Copyright 1988-91 John J. Herro ";
  19.                        -- LEGAL_NOTE isn't used by the program, but it causes
  20.                        -- most compilers to place this string in the .EXE file.
  21. begin
  22.    begin
  23.       RANDOM_IO.OPEN(DATA_FILE, RANDOM_IO.IN_FILE, NAME => "ADA_TUTR.DAT");
  24.    exception
  25.       when RANDOM_IO.NAME_ERROR =>
  26.          TEXT_IO.PUT_LINE(
  27.               "I'm sorry.  The file ADA_TUTR.DAT seems to be missing.");
  28.          OK := FALSE;
  29.    end;
  30.    begin
  31.       TEXT_IO.CREATE(TEXT_FILE, NAME => "TUTOR.TXT");
  32.    exception
  33.       when others =>
  34.          TEXT_IO.PUT_LINE("I'm sorry.  I can't seem to create TUTOR.TXT.");
  35.          TEXT_IO.PUT_LINE("Perhaps that file already exists?");
  36.          OK := FALSE;
  37.    end;
  38.    if OK then
  39.       while not RANDOM_IO.END_OF_FILE(DATA_FILE) loop
  40.          RANDOM_IO.READ(DATA_FILE, ITEM => BLOCK);
  41.          TEXT_IO.PUT_LINE(FILE => TEXT_FILE, ITEM => BLOCK);
  42.       end loop;
  43.       RANDOM_IO.CLOSE(DATA_FILE);
  44.       TEXT_IO.CLOSE(TEXT_FILE);
  45.       TEXT_IO.PUT_LINE("TUTOR.TXT created.");
  46.    end if;
  47. end DAT2TXT;
  48.