home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / paged / page.ada next >
Encoding:
Text File  |  1988-05-03  |  5.9 KB  |  160 lines

  1.  
  2.  
  3.  
  4.  
  5. -------- SIMTEL20 Ada Software Repository Prologue ------------
  6. --                                                           -*
  7. -- Unit name    : PAGE
  8. -- Version      : 1.0
  9. -- Author       : Richard Conn
  10. --              : Texas Instruments, Ada Technology Branch
  11. --              : PO Box 801, MS 8007
  12. --              : McKinney, TX  75069
  13. -- DDN Address  : RCONN at SIMTEL20
  14. -- Copyright    : (c) 1985 Richard Conn
  15. -- Date created : 15 Feb 85
  16. -- Release date : 15 Feb 85
  17. -- Last update  : 15 Feb 85
  18. -- Machine/System Compiled/Run on : DG MV 10000, ROLM ADE
  19. --                                                           -*
  20. ---------------------------------------------------------------
  21. --                                                           -*
  22. -- Keywords     : Text file concatenation, text formatter
  23. --
  24. -- Abstract     :
  25. ----------------: PAGE creates a text file containing several
  26. -- other text files separated by the lines:
  27. --              ::::::::::
  28. --              filename
  29. --              ::::::::::
  30. -- where 'filename' is the name of the file which follows.
  31. -- It accepts as input the name of an output file (file to be
  32. -- generated) and the names of the input files, where striking
  33. -- a RETURN to the input file name prompt terminates the input
  34. -- of the list of names.
  35. --
  36. --      UNPAGE is the complement of PAGE, which extracts the component
  37. -- files from the combined file.
  38. --
  39. --                                                           -*
  40. ------------------ Revision history ---------------------------
  41. --                                                           -*
  42. -- DATE         VERSION AUTHOR                  HISTORY
  43. -- 2/15/85      1.0     Richard Conn            Initial Release
  44. --                                                           -*
  45. ------------------ Distribution and Copyright -----------------
  46. --                                                           -*
  47. -- This prologue must be included in all copies of this software.
  48. --
  49. -- This software is copyright by the author.
  50. --
  51. -- This software is released to the Ada community.
  52. -- This software is released to the Public Domain (note:
  53. --   software released to the Public Domain is not subject
  54. --   to copyright protection).
  55. -- Restrictions on use or distribution:  NONE
  56. --                                                           -*
  57. ------------------ Disclaimer ---------------------------------
  58. --                                                           -*
  59. -- This software and its documentation are provided "AS IS" and
  60. -- without any expressed or implied warranties whatsoever.
  61. -- No warranties as to performance, merchantability, or fitness
  62. -- for a particular purpose exist.
  63. --
  64. -- Because of the diversity of conditions and hardware under
  65. -- which this software may be used, no warranty of fitness for
  66. -- a particular purpose is offered.  The user is advised to
  67. -- test the software thoroughly before relying on it.  The user
  68. -- must assume the entire risk and liability of using this
  69. -- software.
  70. --
  71. -- In no event shall any person or organization of people be
  72. -- held responsible for any direct, indirect, consequential
  73. -- or inconsequential damages or lost profits.
  74. --                                                           -*
  75. -------------------END-PROLOGUE--------------------------------
  76. --
  77. --  PAGE, Version 1.0
  78. --  by Richard Conn, TI Ada Technology Branch
  79. --  Date: 14 Feb 1985
  80. --
  81. --  PAGE accepts a number of file names and generates a paged file
  82. --  containing each of the indicated files prefixed by the form:
  83. --     ::::::::::
  84. --     filename
  85. --     ::::::::::
  86. --
  87. with TEXT_IO,
  88.      GENERIC_LIST;
  89. procedure PAGE is
  90.     VERSION : constant STRING := "PAGE, Version 1.0";
  91.  
  92. --
  93. --  A doubly-linked list of file names
  94. --
  95.     FILE_NAME_LENGTH : constant := 80;
  96.     type FILE_NAME_STRING is
  97.         record
  98.             NAME   : STRING (1 .. FILE_NAME_LENGTH);
  99.             LENGTH : NATURAL;
  100.         end record;
  101.     package FN_LIST is new GENERIC_LIST (FILE_NAME_STRING);
  102.  
  103. --
  104. --  Variables
  105. --
  106.     OUTPUT_FILE     : TEXT_IO.FILE_TYPE;
  107.     FILE_NAME_ENTRY : FILE_NAME_STRING;
  108.     FILE_NAME       : STRING (1 .. FILE_NAME_LENGTH);
  109.     LENGTH          : NATURAL;
  110.  
  111. --
  112. -- Append indicated file to end of output file
  113. --
  114.     procedure APPEND_FILE (FILE_NAME : STRING) is
  115.         INPUT_FILE : TEXT_IO.FILE_TYPE;
  116.         INLINE     : STRING (1 .. 1024);
  117.         LENGTH     : NATURAL;
  118.     begin
  119.         TEXT_IO.OPEN (INPUT_FILE, TEXT_IO.IN_FILE, FILE_NAME);
  120.         TEXT_IO.PUT_LINE (OUTPUT_FILE, "::::::::::");
  121.         TEXT_IO.PUT_LINE (OUTPUT_FILE, FILE_NAME);
  122.         TEXT_IO.PUT_LINE (OUTPUT_FILE, "::::::::::");
  123.         while not TEXT_IO.END_OF_FILE (INPUT_FILE) loop
  124.             TEXT_IO.GET_LINE (INPUT_FILE, INLINE, LENGTH);
  125.             TEXT_IO.PUT_LINE (OUTPUT_FILE, INLINE (1 .. LENGTH));
  126.         end loop;
  127.         TEXT_IO.CLOSE (INPUT_FILE);
  128.     end APPEND_FILE;
  129.  
  130.  
  131. --
  132. --  Mainline
  133. --
  134. begin
  135.     TEXT_IO.PUT_LINE (VERSION);
  136.     TEXT_IO.PUT ("Output File Name > ");
  137.     TEXT_IO.GET_LINE (FILE_NAME, LENGTH);
  138.     TEXT_IO.CREATE (OUTPUT_FILE, TEXT_IO.OUT_FILE, FILE_NAME (1 .. LENGTH));
  139.     FN_LIST.INITIALIZE_LIST;
  140.     loop
  141.         TEXT_IO.PUT (" Input File Name > ");
  142.         TEXT_IO.GET_LINE (FILE_NAME, LENGTH);
  143.         exit when LENGTH = 0;
  144.         FILE_NAME_ENTRY.NAME := FILE_NAME;
  145.         FILE_NAME_ENTRY.LENGTH := LENGTH;
  146.         FN_LIST.APPEND_ELEMENT (FILE_NAME_ENTRY);
  147.     end loop;
  148.     TEXT_IO.NEW_LINE;
  149.     FN_LIST.SET_FIRST;
  150.     loop
  151.         FILE_NAME_ENTRY := FN_LIST.RETURN_CURRENT_ELEMENT;
  152.         APPEND_FILE (FILE_NAME_ENTRY.NAME (1 .. FILE_NAME_ENTRY.LENGTH));
  153.         TEXT_IO.PUT_LINE (FILE_NAME_ENTRY.NAME (1 .. FILE_NAME_ENTRY.LENGTH));
  154.         exit when not FN_LIST.CURRENT_NEXT;
  155.     end loop;
  156.     TEXT_IO.CLOSE (OUTPUT_FILE);
  157. exception
  158.     when others =>
  159.         TEXT_IO.PUT_LINE ("Unknown EXCEPTION Trapped");
  160. end PAGE;