home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / programi / adaed.lzh / Ada / Examples / UnPage.ada < prev    next >
Encoding:
Text File  |  1992-03-03  |  5.4 KB  |  173 lines

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