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

  1.  
  2. -------- SIMTEL20 Ada Software Repository Prologue ------------
  3. --                                                           -*
  4. -- Unit name    : UNPAGE
  5. -- Version      : 1.0
  6. -- Author       : Mitre Corp.
  7. -- DDN Address  : wis_ada at mitre
  8. -- Date created : 21 JAN 85
  9. -- Release date : 29 JAN 85
  10. -- Last update  : 21 JAN 85
  11. -- Machine/System Compiled/Run on : Intellimac 7000M
  12. --                                  UNIX
  13. --                                  Telesoft unvalidated
  14. --                                                           -*
  15. ---------------------------------------------------------------
  16. --                                                           -*
  17. -- Keywords     :  Table builder, Text formatter
  18. --
  19. ----------------:
  20. --
  21. -- Abstract     :  
  22. --      UNPAGE is a simple little program which complements the
  23. -- UNIX page command.  The UNIX page command can be used to combine
  24. -- several source files, interspersing file headers of the form:
  25. --
  26. --                    ::::::::::
  27. --                    FILENAME
  28. --                    ::::::::::
  29. --
  30. --    UNPAGE reads such a file breaking the subfiles into separate
  31. -- files as indicated by the filename headers.  UNPAGE has been
  32. -- enhanced to also recognize file headers which have the format of
  33. -- an Ada comment:
  34. --
  35. --                    --::::::::::
  36. --                    --FILENAME
  37. --                    --::::::::::
  38. ----------------:  
  39. --                                                           -*
  40. ------------------ Revision history ---------------------------
  41. --                                                           -*
  42. -- DATE         VERSION    AUTHOR           HISTORY
  43. -- 12/15/84    1.0    Mitre Corp      Initial Release
  44. -- 01/21/85     1.0     Mitre Corp       Add recognition of
  45. --                                       --:::::::::::
  46. --                                                           -*
  47. ------------------ Distribution and Copyright -----------------
  48. --                                                           -*
  49. -- This prologue must be included in all copies of this software.
  50. --
  51. -- This software is released to the Public Domain (note:
  52. --   software released to the Public Domain is not subject
  53. --   to copyright protection).
  54. --
  55. -- Restrictions on use or distribution:  Although there are
  56. --      no current plans to provide maintenance for UNPAGE,
  57. --      we would appreciate your reporting problems and
  58. --      experiences to:
  59. --              
  60. --                wis_ada at mitre (net address)
  61. --
  62. --      or call at:
  63. --
  64. --                (703)  883-7697
  65. --                                                           -*
  66. ------------------ Disclaimer ---------------------------------
  67. --                                                           -*
  68. -- This software and its documentation are provided "AS IS" and
  69. -- without any expressed or implied warranties whatsoever.
  70. -- No warranties as to performance, merchantability, or fitness
  71. -- for a particular purpose exist.
  72. --
  73. -- Because of the diversity of conditions and hardware under
  74. -- which this software may be used, no warranty of fitness for
  75. -- a particular purpose is offered.  The user is advised to
  76. -- test the software thoroughly before relying on it.  The user
  77. -- must assume the entire risk and liability of using this
  78. -- software.
  79. --
  80. -- In no event shall any person or organization of people be
  81. -- held responsible for any direct, indirect, consequential
  82. -- or inconsequential damages or lost profits.
  83. --                                                           -*
  84. -------------------END-PROLOGUE--------------------------------
  85. with TEXT_IO; use TEXT_IO;
  86. procedure UNPAGE is
  87.   MAX_STRING   : constant INTEGER := 255;
  88.   NEW_FILE     : FILE_TYPE;
  89.   PAGED_FILE   : FILE_TYPE;
  90.   LINE         : STRING(1..MAX_STRING);
  91.   LAST         : INTEGER;
  92.  
  93.   procedure WRITE_ERROR
  94.     (PART1 : in STRING;
  95.      PART2 : in STRING) is
  96.   begin
  97.     NEW_LINE;
  98.     PUT("**ERROR**");
  99.     PUT(PART1);
  100.     PUT(PART2);
  101.     NEW_LINE;
  102.   end WRITE_ERROR;
  103.  
  104.  
  105.  
  106.   procedure OPEN_INPUT is
  107.     TAB_NAME  : STRING(1..MAX_STRING);
  108.   begin
  109.     NEW_LINE;
  110.     PUT("ENTER NAME OF PAGE-CATENATED FILE =>");
  111.     GET_LINE(TAB_NAME, LAST);
  112.     OPEN(PAGED_FILE, IN_FILE, TAB_NAME(1..LAST));
  113.   end;
  114.  
  115.  
  116.   function FILE_NAME_LINE return BOOLEAN is
  117.   begin
  118.     if LAST >= 10 and then (LINE(1..10) = "::::::::::" or
  119.                             LINE(1..10) = "--::::::::")then
  120.       return TRUE;
  121.     else
  122.       return FALSE;
  123.     end if;
  124.   end FILE_NAME_LINE;
  125.  
  126.  
  127.   procedure OPEN_NEW_FILE is
  128.     NAME_START : integer;
  129.   begin
  130.     GET_LINE(PAGED_FILE, LINE, LAST);
  131.     PUT_LINE(LINE(1..LAST));
  132.  
  133.     if LINE(1..2) = "--" then
  134.       NAME_START := 3;
  135.     else
  136.       NAME_START := 1;
  137.     end if;
  138.     CREATE (NEW_FILE, OUT_FILE, LINE(NAME_START..LAST));
  139.  
  140.     --Skip over the trailing ":::::::::::::" line
  141.     GET_LINE(PAGED_FILE, LINE, LAST);
  142.   end OPEN_NEW_FILE;
  143.  
  144.  
  145.  
  146. begin
  147.  
  148.   --Prompt user for paged file name. Then get name of first file to be processed
  149.   OPEN_INPUT;
  150.  
  151.   GET_LINE(PAGED_FILE, LINE, LAST);
  152.   if FILE_NAME_LINE then
  153.     OPEN_NEW_FILE;
  154.     loop
  155.         GET_LINE(PAGED_FILE, LINE, LAST);
  156.         if FILE_NAME_LINE then
  157.           CLOSE(NEW_FILE);
  158.           OPEN_NEW_FILE;
  159.         else
  160.           PUT_LINE(NEW_FILE, LINE(1..LAST));
  161.         end if;
  162.     end loop;
  163.   else
  164.     WRITE_ERROR("FILE IS NOT IN PAGED FORMAT, EXECUTION ABORTED", ".");
  165.   end if;
  166.  
  167. exception
  168.   when END_ERROR => CLOSE(NEW_FILE);
  169.                     CLOSE(PAGED_FILE);
  170. end UNPAGE;
  171.  
  172.