PAGER2

Section: User Commands (1)
Updated: 4 November 1987
Index Return to Main Contents
 

NAME

pager2 - page, unpage, and list paged files  

SYNOPSIS

pager2 {lpu filename}  

DESCRIPTION

Pager2 is used to create (page), disassemble (unpage), and list the contents of paged files, where a paged file is a concatenated source file as per the Ada Software Repository standard (see below).

Pager2 accepts a command from the command line or can be run interactively. The command pager2 with no arguments invokes interactive mode, where the user can issue one Pager2 command after another. Commands like

1) pager2 l filename
2) pager2 i filename output_include_file
3) pager2 p filename input_include_file
4) pager2 u filename

may be issued from the command line to (1) list the contents of a paged file to the console, (2) list the contents of a paged file into an include file, (3) create a new paged file from an include file, and (4) disassemble a paged file into its components. The L and U commands require only the name of a paged file; the I and P commands require the name of the paged file to be analyzed or created and the name of the include file to be created or used for input. Pager2 also runs in an interactive mode, invoked by simply giving its name:
pager2

Include Files are files which contain blank lines, comment lines (beginning with a dash "-"), the names of files to place into the paged file, and the names of other include files (beginning with an at-sign "@"). A sample include file follows:

        -- This is a sample include file

        -- Place the following files into the output paged file
        f1.txt
        f2.txt

        -- Places the files named in the following include file into the
        -- output paged file
        @filelist.include

        -- Place some more files into the output paged file
        f3.txt
        f4.txt


A Paged File is a file containing one or more component files. A paged file and its component files may only be text files. The standard for a paged file is established by the Ada Software Repository, and the layout of a paged file follows:
        --::::::::::
        --filename1
        --::::::::::
                < text of filename1 >
        --::::::::::
        --filename2
        --::::::::::
                < text of filename2 >
                        ...
        --::::::::::
        --filenameN
        --::::::::::
                < text of filenameN >

Pager2 creates, disassembles, and lists the contents of a paged file.  

SEE ALSO

N/A  

AUTHOR

Richard Conn  

BUGS

Each component file should be of "reasonable" size (less than 32,767 lines long). Running out of disk space during the creation of a paged file may pose a problem. --:::::::::: --pager2.ada --:::::::::: -- PROGRAM/CODE BODY NAME:      PAGER2
-- AUTHOR:                      Richard Conn
-- VERSION:                     1.0
-- DATE:                        8/28/87
-- REVISION HISTORY - -- Version      Date    Author          Comments
-- 1.0       8/28/87 Richard Conn    Initial
-- KEYWORDS - --      pager, pager2, paged files, page, unpage
-- CALLING SYNTAX - --      From the command line: pager2
-- EXTERNAL ROUTINES - --      TEXT_IO
-- DESCRIPTION - --      PAGER2 assembles, extracts elements from, and lists paged files.
-- Paged files are text files which contain one or more component files -- prefixed by a banner like: -- --      ::::::::::
--      filename
--      ::::::::::
-- -- or -- --      --::::::::::
--      --filename
--      --::::::::::
-- --      PAGER2 will extract elements from and list paged files whose components
-- are prefixed with either banner, but it assembles paged files with only -- the second banner (beginning with the Ada comment characters). -- --============================================================================== ---------------------------- PACKAGE LINE_DEFINITION --------------------------- --============================================================================== -- The following package defines an object of type LINE package LINE_DEFINITION is
   
   -- The maximum length of a line
   MAX_LINE_LENGTH : constant NATURAL := 200;
   
   -- Type definition for LINE
   type LINE is 
      record
         CONTENT : STRING (1 .. MAX_LINE_LENGTH);
         LAST    : NATURAL;
      end record;
   
   -- Banners
   COMMENT_BANNER : constant STRING := "--::::::::::";
   BANNER         : constant STRING := "::::::::::";
   
   -- Convert strings to LINEs and back
   function CONVERT (FROM : in STRING) return LINE;
   function CONVERT (FROM : in LINE) return STRING;
    end LINE_DEFINITION; package body LINE_DEFINITION is
   
   -- Convert strings to LINEs
   function CONVERT (FROM : in STRING) return LINE is
      TO : LINE_DEFINITION.LINE;
   begin
      TO.CONTENT (TO.CONTENT'FIRST .. TO.CONTENT'FIRST + FROM'LENGTH - 1) := 
         FROM;
      TO.LAST := FROM'LENGTH;
      return TO;
   end CONVERT;
   
   function CONVERT (FROM : in LINE) return STRING is
   begin
      return FROM.CONTENT (FROM.CONTENT'FIRST .. FROM.LAST);
   end CONVERT;
    end LINE_DEFINITION; -- --============================================================================== ---------------------------- PACKAGE INPUT_FILE ---------------------------- --============================================================================== -- The following package manipulates an object called an INPUT_FILE, -- which is a text file that is composed of objects of type LINE. -- LINEs can only be read from an INPUT_FILE. with LINE_DEFINITION; package INPUT_FILE is
   
   -- Open the input file
   -- Exceptions which may be raised: FILE_NOT_FOUND, FILE_ALREADY_OPEN
   procedure OPEN (FILE_NAME : in STRING);
   procedure OPEN (FILE_NAME : in LINE_DEFINITION.LINE);
   
   -- Close the input file
   -- Exceptions which may be raised: FILE_NOT_OPEN
   procedure CLOSE;
   
   -- Read a line from the input file
   -- Exceptions which may be raised: FILE_NOT_OPEN, READ_PAST_END_OF_FILE
   procedure READ (TO : out LINE_DEFINITION.LINE);
   
   -- Return TRUE if the input file is empty (no more lines remain)
   -- Exceptions which may be raised: FILE_NOT_OPEN
   function END_OF_FILE return BOOLEAN;
   
   -- Exceptional conditions
   FILE_NOT_FOUND        : exception;
   FILE_ALREADY_OPEN     : exception;
   FILE_NOT_OPEN         : exception;
   READ_PAST_END_OF_FILE : exception;
    end INPUT_FILE; with TEXT_IO; package body INPUT_FILE is
   
   -- The file descriptor for the input file
   FD : TEXT_IO.FILE_TYPE;
   
   -- Open the input file
   procedure OPEN (FILE_NAME : in STRING) is
   begin
      TEXT_IO.OPEN (FD, TEXT_IO.IN_FILE, FILE_NAME);
   exception
      when TEXT_IO.NAME_ERROR  =>
         raise FILE_NOT_FOUND;
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_ALREADY_OPEN;
   end OPEN;
   
   procedure OPEN (FILE_NAME : in LINE_DEFINITION.LINE) is
   begin
      OPEN (FILE_NAME.CONTENT (FILE_NAME.CONTENT'FIRST .. FILE_NAME.LAST));
   end OPEN;
   
   -- Close the input file
   procedure CLOSE is
   begin
      TEXT_IO.CLOSE (FD);
   exception
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_NOT_OPEN;
   end CLOSE;
   
   -- Read a line from the input file
   procedure READ (TO : out LINE_DEFINITION.LINE) is
   begin
      TEXT_IO.GET_LINE (FD, TO.CONTENT, TO.LAST);
   exception
      when TEXT_IO.END_ERROR   =>
         raise READ_PAST_END_OF_FILE;
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_NOT_OPEN;
   end READ;
   
   -- Return TRUE if the input file is empty (no more lines remain)
   function END_OF_FILE return BOOLEAN is
   begin
      return TEXT_IO.END_OF_FILE (FD);
   exception
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_NOT_OPEN;
   end END_OF_FILE;
    end INPUT_FILE; -- --============================================================================== ---------------------------- PACKAGE OUTPUT_FILE ---------------------------- --============================================================================== -- The following package manipulates an object called an OUTPUT_FILE, -- which is a text file that is composed of objects of type LINE. -- LINEs can only be written to an OUTPUT_FILE. with LINE_DEFINITION; package OUTPUT_FILE is
   
   -- Open the output file
   -- Exceptions which may be raised: CANNOT_CREATE_FILE, FILE_ALREADY_OPEN
   procedure OPEN (FILE_NAME : in STRING);
   procedure OPEN (FILE_NAME : in LINE_DEFINITION.LINE);
   
   -- Close the output file
   -- Exceptions which may be raised: FILE_NOT_OPEN
   procedure CLOSE;
   
   -- Write a line to the output file
   -- Exceptions which may be raised: FILE_NOT_OPEN, DISK_FULL
   procedure WRITE (FROM : in LINE_DEFINITION.LINE);
   procedure WRITE (FROM : in STRING);
   
   -- Exceptional conditions
   CANNOT_CREATE_FILE : exception;
   FILE_ALREADY_OPEN  : exception;
   FILE_NOT_OPEN      : exception;
   DISK_FULL          : exception;
    end OUTPUT_FILE; with TEXT_IO; package body OUTPUT_FILE is
   
   -- File descriptor for the output file
   FD : TEXT_IO.FILE_TYPE;
   
   -- Open the output file
   procedure OPEN (FILE_NAME : in STRING) is
      INLINE : STRING (1 .. 80);
      LAST   : NATURAL;
   begin
      TEXT_IO.CREATE (FD, TEXT_IO.OUT_FILE, FILE_NAME);
   exception
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_ALREADY_OPEN;
      when TEXT_IO.USE_ERROR   =>
         raise CANNOT_CREATE_FILE;
      when TEXT_IO.NAME_ERROR  =>
         TEXT_IO.PUT_LINE (" Cannot create " & FILE_NAME);
         loop
            begin
               TEXT_IO.PUT (" Enter New File Name: ");
               TEXT_IO.GET_LINE (INLINE, LAST);
               TEXT_IO.CREATE (FD, TEXT_IO.OUT_FILE, 
                               INLINE (INLINE'FIRST .. LAST));
               exit ;
            exception
               when TEXT_IO.NAME_ERROR   =>
                  TEXT_IO.PUT_LINE (" Cannot create " & 
                                    INLINE (INLINE'FIRST .. LAST));
               when others     =>
                  raise ;
            end;
         end loop;
   end OPEN;
   
   procedure OPEN (FILE_NAME : in LINE_DEFINITION.LINE) is
   begin
      OPEN (FILE_NAME.CONTENT (FILE_NAME.CONTENT'FIRST .. FILE_NAME.LAST));
   end OPEN;
   
   -- Close the output file
   procedure CLOSE is
   begin
      TEXT_IO.CLOSE (FD);
   exception
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_NOT_OPEN;
   end CLOSE;
   
   -- Write a line to the output file
   procedure WRITE (FROM : in LINE_DEFINITION.LINE) is
   begin
      TEXT_IO.PUT_LINE (FD, FROM.CONTENT (1 .. FROM.LAST));
   exception
      when TEXT_IO.STATUS_ERROR     =>
         raise FILE_NOT_OPEN;
      when others    =>
         raise DISK_FULL;
   end WRITE;
   
   procedure WRITE (FROM : in STRING) is
   begin
      WRITE (LINE_DEFINITION.CONVERT (FROM));
   end WRITE;
    end OUTPUT_FILE; -- --============================================================================== ---------------------------- PACKAGE INCLUDE_FILE ---------------------------- --============================================================================== -- The following package manipulates an object called an INCLUDE_FILE, -- which is a text file that is composed of objects of type LINE. -- LINEs can only be read from an INCLUDE_FILE. An INCLUDE_FILE contains -- the following types of LINE objects: --      blank lines
--      comment lines ('-' is the first character in the line)
--      file names (a string of non-blank characters which does not
--              begin with the character '-' or '@')
--      include file names (a string of non-blank characters which
--              begins with the character '@', where the '@' is used to
--              prefix the file name within the include file and is not
--              a part of the file name of the actual disk file)
-- Include files may be nested several levels (defined by the constant -- NESTING_DEPTH). with LINE_DEFINITION; package INCLUDE_FILE is
   
   -- Maximum number of levels include files may be nested
   NESTING_DEPTH     : constant NATURAL   := 40;
   
   -- Character which begins an include file name
   INCLUDE_CHARACTER : constant CHARACTER := '@';
   
   -- Character which begins a comment line
   COMMENT_CHARACTER : constant CHARACTER := '-';
   
   -- Open the include file (the LINE input string contains the leading '@')
   -- Exceptions which may be raised: FILE_NOT_FOUND, NESTING_LEVEL_EXCEEDED
   procedure OPEN (FILE_NAME : in LINE_DEFINITION.LINE);
   procedure OPEN (FILE_NAME : in STRING);
   
   -- Read a LINE containing a file name from the include file
   -- Exceptions which may be raised: FILE_NOT_OPEN, READ_PAST_END_OF_FILE
   procedure READ (TO : out LINE_DEFINITION.LINE);
   
   -- Abort processing the include file (close all open files)
   -- Exceptions which may be raised: FILE_NOT_OPEN
   procedure STOP;
   
   -- Exceptional conditions
   FILE_NOT_FOUND         : exception;
   NESTING_LEVEL_EXCEEDED : exception;
   FILE_NOT_OPEN          : exception;
   READ_PAST_END_OF_FILE  : exception;
   INCLUDE_FILE_EMPTY     : exception;
    end INCLUDE_FILE; with TEXT_IO; package body INCLUDE_FILE is
   
   -- File Descriptor for main include file
   FD              : array (1 .. NESTING_DEPTH) of TEXT_IO.FILE_TYPE;
   CURRENT_LEVEL   : NATURAL := 0;
   NEXT_LINE       : LINE_DEFINITION.LINE; -- next line to return by READ
   NEXT_LINE_READY : BOOLEAN := FALSE; -- indicates next line is available
   
   -- Open the include file (the LINE input string contains the leading '@')
   -- Exceptions which may be raised: FILE_NOT_FOUND, NESTING_LEVEL_EXCEEDED
   procedure OPEN (FILE_NAME : in LINE_DEFINITION.LINE) is
   begin
      if CURRENT_LEVEL = NESTING_DEPTH then
         raise NESTING_LEVEL_EXCEEDED;
      else
         CURRENT_LEVEL := CURRENT_LEVEL + 1;
         TEXT_IO.OPEN (FD (CURRENT_LEVEL), TEXT_IO.IN_FILE, 
                       FILE_NAME.CONTENT (FILE_NAME.CONTENT'FIRST + 1 .. 
                                          FILE_NAME.LAST));
      end if;
   exception
      when TEXT_IO.NAME_ERROR  =>
         TEXT_IO.PUT_LINE ("Include File " & 
                           FILE_NAME.CONTENT (FILE_NAME.CONTENT'FIRST + 1 .. 
                                              FILE_NAME.LAST) & " not Found");
         raise FILE_NOT_FOUND;
      when others    =>
         TEXT_IO.PUT_LINE ("Unexpected error with Include File " & 
                           FILE_NAME.CONTENT (FILE_NAME.CONTENT'FIRST + 1 .. 
                                              FILE_NAME.LAST));
         raise FILE_NOT_FOUND;
   end OPEN;
   
   procedure OPEN (FILE_NAME : in STRING) is
   begin
      OPEN (LINE_DEFINITION.CONVERT (FILE_NAME));
   end OPEN;
   
   -- Close the include file
   -- Exceptions which may be raised: FILE_NOT_OPEN
   procedure CLOSE is
   begin
      TEXT_IO.CLOSE (FD (CURRENT_LEVEL));
      CURRENT_LEVEL := CURRENT_LEVEL - 1;
      if CURRENT_LEVEL = 0 then
         raise INCLUDE_FILE_EMPTY;
      end if;
   end CLOSE;
   
   -- Abort processing the include file
   procedure STOP is
   begin
      while CURRENT_LEVEL > 0 loop
         TEXT_IO.CLOSE (FD (CURRENT_LEVEL));
         CURRENT_LEVEL := CURRENT_LEVEL - 1;
      end loop;
   end STOP;
   
   -- Read a LINE containing a file name from the include file
   -- Exceptions which may be raised: FILE_NOT_OPEN, READ_PAST_END_OF_FILE
   procedure READ (TO : out LINE_DEFINITION.LINE) is
      INLINE : LINE_DEFINITION.LINE;
   begin
      loop
         begin
            TEXT_IO.GET_LINE (FD (CURRENT_LEVEL), INLINE.CONTENT, INLINE.LAST);
            if INLINE.LAST > 0 and INLINE.CONTENT (1) = INCLUDE_CHARACTER then
               OPEN (INLINE);
            elsif (INLINE.LAST > 0 and INLINE.CONTENT (1) = COMMENT_CHARACTER)
                   or (INLINE.LAST = 0) then
               null; -- skip comment lines and empty lines
            else
               exit ;
            end if;
         exception
            when TEXT_IO.END_ERROR  =>
               CLOSE;
         end;
      end loop;
      TO := INLINE;
   end READ;
    end INCLUDE_FILE; -- --============================================================================== ------------------------------ PROCEDURE PARSER -------------------------------- --============================================================================== -- PARSER parses a LINE and returns the number of tokens in that LINE (0 to 4) -- and the first three tokens as COMMAND (converted to lower-case), ARG1, -- ARG2, and REMAINDER with LINE_DEFINITION; procedure PARSER (INLINE : in LINE_DEFINITION.LINE;
                  NARGS     : out NATURAL;
                  COMMAND   : out LINE_DEFINITION.LINE;
                  ARG1      : out LINE_DEFINITION.LINE;
                  ARG2      : out LINE_DEFINITION.LINE;
                  REMAINDER : out LINE_DEFINITION.LINE) is
   
   ROVER      : NATURAL;
   LCOMMAND   : LINE_DEFINITION.LINE;
   LREMAINDER : LINE_DEFINITION.LINE;
   
   procedure SKIP_SPACES is
   begin
      while INLINE.CONTENT (ROVER) <= ' ' and ROVER <= INLINE.LAST loop
         ROVER := ROVER + 1;
      end loop;
   end SKIP_SPACES;
   
   procedure EXTRACT (ITEM : out LINE_DEFINITION.LINE) is
      EXTRACT_ROVER : NATURAL := 0;
   begin
      while INLINE.CONTENT (ROVER) > ' ' and ROVER <= INLINE.LAST loop
         EXTRACT_ROVER := EXTRACT_ROVER + 1;
         ITEM.CONTENT (EXTRACT_ROVER) := INLINE.CONTENT (ROVER);
         ROVER         := ROVER + 1;
      end loop;
      ITEM.LAST := EXTRACT_ROVER;
   end EXTRACT;
   
   procedure TOLOWER (ITEM : in out LINE_DEFINITION.LINE) is
   begin
      for I in ITEM.CONTENT'FIRST .. ITEM.LAST loop
         if ITEM.CONTENT (I) in 'A' .. 'Z' then
            ITEM.CONTENT (I) := 
               CHARACTER'VAL (CHARACTER'POS (ITEM.CONTENT (I)) - 
                              CHARACTER'POS ('A') + CHARACTER'POS ('a'));
         end if;
      end loop;
   end TOLOWER;
    begin
   COMMAND.LAST   := 0;
   ARG1.LAST      := 0;
   ARG2.LAST      := 0;
   REMAINDER.LAST := 0;
   NARGS          := 0;
   ROVER          := INLINE.CONTENT'FIRST;
   SKIP_SPACES;
   if ROVER <= INLINE.LAST then
      EXTRACT (LCOMMAND);
      LCOMMAND.LAST                    := LCOMMAND.LAST + 1;
      LCOMMAND.CONTENT (LCOMMAND.LAST) := ' ';
      TOLOWER (LCOMMAND);
      COMMAND := LCOMMAND;
      NARGS := 1;
      if ROVER <= INLINE.LAST then
         SKIP_SPACES;
         if ROVER <= INLINE.LAST then
            EXTRACT (ARG1);
            NARGS := 2;
            if ROVER <= INLINE.LAST then
               SKIP_SPACES;
               if ROVER <= INLINE.LAST then
                  EXTRACT (ARG2);
                  NARGS := 3;
                  if ROVER <= INLINE.LAST then
                     SKIP_SPACES;
                     if ROVER <= INLINE.LAST then
                        for I in ROVER .. INLINE.LAST loop
                           LREMAINDER.CONTENT (I - ROVER + 
                                               LREMAINDER.CONTENT'FIRST) := 
                              INLINE.CONTENT (I);
                        end loop;
                        LREMAINDER.LAST := INLINE.LAST - ROVER + 
                                           LREMAINDER.CONTENT'FIRST;
                        REMAINDER       := LREMAINDER;
                        NARGS           := 4;
                     end if;
                  end if;
               end if;
            end if;
         end if;
      end if;
   end if; end PARSER; -- --============================================================================== ----------------------------------- MAINLINE ----------------------------------- --============================================================================== with LINE_DEFINITION, INCLUDE_FILE, INPUT_FILE, OUTPUT_FILE, PARSER; with TEXT_IO; procedure PAGER2 is
   
   TITLE           : constant STRING := "PAGER2, Ada Version 1.0";
   
   INLINE          : LINE_DEFINITION.LINE;
   
   NARGS           : NATURAL;
   COMMAND         : LINE_DEFINITION.LINE;
   ARG1            : LINE_DEFINITION.LINE;
   ARG2            : LINE_DEFINITION.LINE;
   REMAINDER       : LINE_DEFINITION.LINE;
   
   -- Command Verbs
   HELP_COMMAND    : constant STRING := "help ";
   H_COMMAND       : constant STRING := "h ";
   EXIT_COMMAND    : constant STRING := "exit ";
   X_COMMAND       : constant STRING := "x "; -- same as exit
   CHECK_COMMAND   : constant STRING := "check ";
   C_COMMAND       : constant STRING := "c "; -- same as check
   INCLUDE_COMMAND : constant STRING := "include ";
   I_COMMAND       : constant STRING := "i "; -- same as include
   LIST_COMMAND    : constant STRING := "list ";
   L_COMMAND       : constant STRING := "l "; -- same as list
   PAGE_COMMAND    : constant STRING := "page ";
   P_COMMAND       : constant STRING := "p "; -- same as page
   UNPAGE_COMMAND  : constant STRING := "unpage ";
   U_COMMAND       : constant STRING := "u "; -- same as unpage
   
   --=========================================================================
   -- PAGER2, Support Utilities
   --=========================================================================
   
   -- Determine if COMMAND contains one of the two target command strings
   function IS_COMMAND
       (TARGET1_COMMAND, TARGET2_COMMAND : in STRING) return BOOLEAN is
   begin
      if COMMAND.CONTENT (1 .. TARGET1_COMMAND'LENGTH) = TARGET1_COMMAND or 
         COMMAND.CONTENT (1 .. TARGET2_COMMAND'LENGTH) = TARGET2_COMMAND then
         return TRUE;
      else
         return FALSE;
      end if;
   end IS_COMMAND;
   
   -- Determine if ITEM contains a BANNER or COMMENT_BANNER
   function IS_BANNER (ITEM : in LINE_DEFINITION.LINE) return BOOLEAN is
      RESULT : BOOLEAN;
   begin
      if ITEM.LAST >= LINE_DEFINITION.BANNER'LENGTH and then 
         ITEM.CONTENT (1 .. LINE_DEFINITION.BANNER'LENGTH) = 
         LINE_DEFINITION.BANNER then
         RESULT := TRUE;
      elsif ITEM.LAST >= LINE_DEFINITION.COMMENT_BANNER'LENGTH and then 
            ITEM.CONTENT (1 .. LINE_DEFINITION.COMMENT_BANNER'LENGTH) = 
            LINE_DEFINITION.COMMENT_BANNER then
         RESULT := TRUE;
      else
         RESULT := FALSE;
      end if;
      return RESULT;
   end IS_BANNER;
   
   -- Package to handle line counting
   package COUNTER is
      
      -- Reset the Counter
      procedure SET;
      
      -- Increment the Counter
      procedure INCREMENT;
      
      -- Print the counter
      procedure PRINT;
      
   end COUNTER;
   
   package body COUNTER is
      
      type LINE_COUNT is  range 0 .. 1_000_001;
      package LINE_COUNT_IO is new TEXT_IO.INTEGER_IO (LINE_COUNT);
      
      LCOUNT : LINE_COUNT;
      
      -- Reset the LCOUNT variable
      procedure SET is
      begin
         LCOUNT := 0;
      end SET;
      
      -- Increment the LCOUNT variable
      procedure INCREMENT is
      begin
         if LCOUNT < LINE_COUNT'LAST then
            LCOUNT := LCOUNT + 1;
         end if;
      end INCREMENT;
      
      -- Print a count of the number of lines and reset the LCOUNT variable
      procedure PRINT is
      begin
         TEXT_IO.PUT (" -- ");
         if LCOUNT = LINE_COUNT'LAST then
            TEXT_IO.PUT ("More Than" & LINE_COUNT'IMAGE (LINE_COUNT'LAST - 1));
         else
            LINE_COUNT_IO.PUT (LCOUNT, 1);
         end if;
         TEXT_IO.PUT_LINE (" Lines");
         LCOUNT := 0;
      end PRINT;
      
   end COUNTER;
   
   --=========================================================================
   -- PAGER2, HELP Command
   --=========================================================================
   procedure HELP is
      procedure SPACER is
      begin
         TEXT_IO.PUT ("                  ");
      end SPACER;
   begin
      TEXT_IO.PUT_LINE (" Command Summary");
      TEXT_IO.PUT_LINE ("  help or h   - this summary");
      SPACER;
      TEXT_IO.PUT_LINE ("Syntax: help");
      TEXT_IO.PUT_LINE ("  exit or x   - exit from program");
      SPACER;
      TEXT_IO.PUT_LINE ("Syntax: exit");
      TEXT_IO.PUT_LINE ("  include or i- list components into an include file");
      SPACER;
      TEXT_IO.PUT_LINE ("Syntax: include paged_file_name output_include_file");
      TEXT_IO.PUT_LINE ("  list or l   - list components of paged file");
      SPACER;
      TEXT_IO.PUT_LINE ("Syntax: list paged_file_name");
      TEXT_IO.PUT_LINE ("  page or p   - create paged file from include file");
      SPACER;
      TEXT_IO.PUT_LINE ("Syntax: page paged_file_name include_file_name");
      TEXT_IO.PUT_LINE ("  unpage or u - extract components from paged file");
      SPACER;
      TEXT_IO.PUT_LINE ("Syntax: unpage paged_file_name");
   end HELP;
   
   --=========================================================================
   -- PAGER2, CHECK Command
   --=========================================================================
   procedure CHECK is
      CHECKSUM : INTEGER;
      package VALUE_IO is new TEXT_IO.INTEGER_IO (INTEGER);
   begin
      if NARGS = 1 then
         TEXT_IO.PUT_LINE (" CHECK Command requires the name of a file");
         TEXT_IO.PUT_LINE ("   Syntax: list file_name");
      else
         
         -- Step 1: Open the input file
         INPUT_FILE.OPEN (ARG1);
         
         -- Step 2: Compute the Hash (Checksum)
         CHECKSUM := 0;
         while not INPUT_FILE.END_OF_FILE loop
            INPUT_FILE.READ (INLINE);
            for I in 1 .. INLINE.LAST loop
               if INLINE.CONTENT (I) > ' ' then
                  CHECKSUM := CHECKSUM + CHARACTER'POS (INLINE.CONTENT (I));
                  if CHECKSUM >= 128 then
                     CHECKSUM := CHECKSUM - 128;
                  end if;
               end if;
            end loop;
         end loop;
         INPUT_FILE.CLOSE;
         
         -- Step 3: Print the result
         TEXT_IO.PUT (" Pager Checksum (Hash) of " & 
                      LINE_DEFINITION.CONVERT (ARG1) & " is ");
         VALUE_IO.PUT (CHECKSUM, 1);
         TEXT_IO.NEW_LINE;
         
      end if;
      
   exception
      when INPUT_FILE.FILE_NOT_FOUND     =>
         TEXT_IO.PUT_LINE (" File " & ARG1.CONTENT (1 .. ARG1.LAST) & 
                           " not Found");
      when INPUT_FILE.READ_PAST_END_OF_FILE   =>
         TEXT_IO.PUT_LINE
             (" Premature EOF on " & ARG1.CONTENT (1 .. ARG1.LAST));
         INPUT_FILE.CLOSE;
      when others    =>
         TEXT_IO.PUT_LINE (" Unexpected Error");
         INPUT_FILE.CLOSE;
         
   end CHECK;
   
   --=========================================================================
   -- PAGER2, INCLUDE Command
   --=========================================================================
   procedure INCLUDE is
      IN_FILE : BOOLEAN;
   begin
      if NARGS < 3 then
         TEXT_IO.PUT_LINE
             (" INCLUDE Command requires the name of a paged file");
         TEXT_IO.PUT_LINE
             ("   Syntax: include paged_file_name output_include_file");
      else
         
         -- Step 1: Open the input and output files
         COUNTER.SET;
         INPUT_FILE.OPEN (ARG1);
         OUTPUT_FILE.OPEN (ARG2);
         OUTPUT_FILE.WRITE ("-- Include file for " & 
                            LINE_DEFINITION.CONVERT (ARG1));
         
         -- Step 2: Look for the first banner in the paged file
         IN_FILE := TRUE;
         while not INPUT_FILE.END_OF_FILE loop
            INPUT_FILE.READ (INLINE);
            if IS_BANNER (INLINE) then
               IN_FILE := FALSE;
               exit ;
            end if;
         end loop;
         
         -- Step 3: If first banner not found, issue error message,
         --         else process component files
         if IN_FILE then
            TEXT_IO.PUT_LINE (" File " & LINE_DEFINITION.CONVERT (ARG1) & 
                              " does not contain any components");
         else
            
            -- Loop until the end of the input paged file
            while not INPUT_FILE.END_OF_FILE loop
               
               -- Read the next line from the input paged file
               INPUT_FILE.READ (INLINE);
               
               -- If we are not in the text of the file, the line just read
               -- contains the name of a new file, else it contains a line of
               -- the current component file
               if not IN_FILE then
                  
                  -- Remove leading comment character if any and print the
                  -- name of the component file
                  if INLINE.CONTENT (1 .. 2) = "--" then
                     TEXT_IO.PUT (" " & INLINE.CONTENT (3 .. INLINE.LAST));
                     OUTPUT_FILE.WRITE (INLINE.CONTENT (3 .. INLINE.LAST));
                  else
                     TEXT_IO.PUT (" " & INLINE.CONTENT (1 .. INLINE.LAST));
                     OUTPUT_FILE.WRITE (INLINE.CONTENT (1 .. INLINE.LAST));
                  end if;
                  
                  -- Flush the trailing banner line and note that we are now
                  -- within the text of a component file
                  INPUT_FILE.READ (INLINE);
                  COUNTER.SET;
                  IN_FILE := TRUE;
                  
               else
                  
                  -- We are within the text of a component file, so check for
                  -- a banner in order to determine if we are at the end of
                  -- the component file
                  if IS_BANNER (INLINE) then
                     IN_FILE := FALSE;
                     COUNTER.PRINT;
                  else
                     COUNTER.INCREMENT;
                  end if;
                  
               end if;
               
            end loop;
            
         end if;
         
         COUNTER.PRINT;
         INPUT_FILE.CLOSE;
         OUTPUT_FILE.CLOSE;
         
      end if;
      
   exception
      when OUTPUT_FILE.CANNOT_CREATE_FILE     =>
         TEXT_IO.PUT_LINE (" Cannot create " & ARG2.CONTENT (1 .. ARG2.LAST));
      when INPUT_FILE.FILE_NOT_FOUND     =>
         TEXT_IO.PUT_LINE (" File " & ARG1.CONTENT (1 .. ARG1.LAST) & 
                           " not Found");
      when INPUT_FILE.READ_PAST_END_OF_FILE   =>
         TEXT_IO.PUT_LINE
             (" Premature EOF on " & ARG1.CONTENT (1 .. ARG1.LAST));
         INPUT_FILE.CLOSE;
      when others    =>
         TEXT_IO.PUT_LINE (" Unexpected Error");
         INPUT_FILE.CLOSE;
         
   end INCLUDE;
   
   --=========================================================================
   -- PAGER2, LIST Command
   --=========================================================================
   procedure LIST is
      IN_FILE : BOOLEAN;
   begin
      if NARGS = 1 then
         TEXT_IO.PUT_LINE (" LIST Command requires the name of a paged file");
         TEXT_IO.PUT_LINE ("   Syntax: list paged_file_name");
      else
         
         -- Step 1: Open the input file
         COUNTER.SET;
         INPUT_FILE.OPEN (ARG1);
         
         -- Step 2: Look for the first banner in the paged file
         IN_FILE := TRUE;
         while not INPUT_FILE.END_OF_FILE loop
            INPUT_FILE.READ (INLINE);
            if IS_BANNER (INLINE) then
               IN_FILE := FALSE;
               exit ;
            end if;
         end loop;
         
         -- Step 3: If first banner not found, issue error message,
         --         else process component files
         if IN_FILE then
            TEXT_IO.PUT_LINE (" File " & LINE_DEFINITION.CONVERT (ARG1) & 
                              " does not contain any components");
         else
            
            -- Loop until the end of the input paged file
            while not INPUT_FILE.END_OF_FILE loop
               
               -- Read the next line from the input paged file
               INPUT_FILE.READ (INLINE);
               
               -- If we are not in the text of the file, the line just read
               -- contains the name of a new file, else it contains a line of
               -- the current component file
               if not IN_FILE then
                  
                  -- Remove leading comment character if any and print the
                  -- name of the component file
                  if INLINE.CONTENT (1 .. 2) = "--" then
                     TEXT_IO.PUT (" " & INLINE.CONTENT (3 .. INLINE.LAST));
                  else
                     TEXT_IO.PUT (" " & INLINE.CONTENT (1 .. INLINE.LAST));
                  end if;
                  
                  -- Flush the trailing banner line and note that we are now
                  -- within the text of a component file
                  INPUT_FILE.READ (INLINE);
                  COUNTER.SET;
                  IN_FILE := TRUE;
                  
               else
                  
                  -- We are within the text of a component file, so check for
                  -- a banner in order to determine if we are at the end of
                  -- the component file
                  if IS_BANNER (INLINE) then
                     IN_FILE := FALSE;
                     COUNTER.PRINT;
                  else
                     COUNTER.INCREMENT;
                  end if;
                  
               end if;
               
            end loop;
            
         end if;
         
         COUNTER.PRINT;
         INPUT_FILE.CLOSE;
         
      end if;
      
   exception
      when INPUT_FILE.FILE_NOT_FOUND     =>
         TEXT_IO.PUT_LINE (" File " & ARG1.CONTENT (1 .. ARG1.LAST) & 
                           " not Found");
      when INPUT_FILE.READ_PAST_END_OF_FILE   =>
         TEXT_IO.PUT_LINE
             (" Premature EOF on " & ARG1.CONTENT (1 .. ARG1.LAST));
         INPUT_FILE.CLOSE;
      when others    =>
         TEXT_IO.PUT_LINE (" Unexpected Error");
         INPUT_FILE.CLOSE;
         
   end LIST;
   
   --=========================================================================
   -- PAGER2, PAGE Command
   --=========================================================================
   procedure PAGE is
      COMPONENT_FILE_NAME : LINE_DEFINITION.LINE;
   begin
      if NARGS < 3 then
         TEXT_IO.PUT_LINE
             (
            " PAGE Command requires the name of the paged file and include file"
              );
         TEXT_IO.PUT_LINE ("   Syntax: page paged_file_name include_file_name");
      else
         INCLUDE_FILE.OPEN (INCLUDE_FILE.INCLUDE_CHARACTER & 
                            LINE_DEFINITION.CONVERT (ARG2));
         OUTPUT_FILE.OPEN (ARG1);
         begin
            loop
               INCLUDE_FILE.READ (COMPONENT_FILE_NAME);
               INPUT_FILE.OPEN (COMPONENT_FILE_NAME);
               OUTPUT_FILE.WRITE (LINE_DEFINITION.COMMENT_BANNER);
               OUTPUT_FILE.WRITE
                   ("--" & LINE_DEFINITION.CONVERT (COMPONENT_FILE_NAME));
               OUTPUT_FILE.WRITE (LINE_DEFINITION.COMMENT_BANNER);
               TEXT_IO.PUT (" Adding " & 
                            LINE_DEFINITION.CONVERT (COMPONENT_FILE_NAME));
               COUNTER.SET;
               while not INPUT_FILE.END_OF_FILE loop
                  INPUT_FILE.READ (INLINE);
                  OUTPUT_FILE.WRITE (INLINE);
                  COUNTER.INCREMENT;
               end loop;
               COUNTER.PRINT;
               INPUT_FILE.CLOSE;
            end loop;
         exception
            when INCLUDE_FILE.READ_PAST_END_OF_FILE |
                 INCLUDE_FILE.INCLUDE_FILE_EMPTY   =>
               OUTPUT_FILE.CLOSE;
            when INPUT_FILE.FILE_NOT_FOUND    =>
               TEXT_IO.PUT_LINE
                   (" File " & LINE_DEFINITION.CONVERT (COMPONENT_FILE_NAME) & 
                    " not Found");
               OUTPUT_FILE.CLOSE;
               INCLUDE_FILE.STOP;
            when others   =>
               TEXT_IO.PUT_LINE
                   (" Unexpected Error During Processing of Component File " & 
                    LINE_DEFINITION.CONVERT (COMPONENT_FILE_NAME));
               OUTPUT_FILE.CLOSE;
               INCLUDE_FILE.STOP;
         end;
      end if;
      
   exception
      when OUTPUT_FILE.CANNOT_CREATE_FILE     =>
         TEXT_IO.PUT_LINE (" Cannot create " & ARG1.CONTENT (1 .. ARG1.LAST));
      when INCLUDE_FILE.FILE_NOT_FOUND   =>
         TEXT_IO.PUT_LINE (" Cannot open include file " & 
                           ARG2.CONTENT (1 .. ARG2.LAST));
      when others    =>
         TEXT_IO.PUT_LINE (" Unexpected Error");
         INPUT_FILE.CLOSE;
         
   end PAGE;
   
   --=========================================================================
   -- PAGER2, UNPAGE Command
   --=========================================================================
   procedure UNPAGE is
      IN_FILE          : BOOLEAN;
      OUTPUT_FILE_NAME : LINE_DEFINITION.LINE;
   begin
      if NARGS = 1 then
         TEXT_IO.PUT_LINE (" UNPAGE Command requires the name of a paged file");
         TEXT_IO.PUT_LINE ("   Syntax: unpage paged_file_name");
      else
         
         -- Step 1: Open the input file
         COUNTER.SET;
         INPUT_FILE.OPEN (ARG1);
         
         -- Step 2: Look for the first banner in the paged file
         IN_FILE := TRUE;
         while not INPUT_FILE.END_OF_FILE loop
            INPUT_FILE.READ (INLINE);
            if IS_BANNER (INLINE) then
               IN_FILE := FALSE;
               exit ;
            end if;
         end loop;
         
         -- Step 3: If first banner not found, issue error message,
         --         else process component files
         if IN_FILE then
            TEXT_IO.PUT_LINE (" File " & LINE_DEFINITION.CONVERT (ARG1) & 
                              " does not contain any components");
         else
            
            -- Loop until the end of the input paged file
            while not INPUT_FILE.END_OF_FILE loop
               
               -- Read the next line from the input paged file
               INPUT_FILE.READ (INLINE);
               
               -- If we are not in the text of the file, the line just read
               -- contains the name of a new file, else it contains a line of
               -- the current component file
               if not IN_FILE then
                  
                  -- Remove leading comment character if any and store the
                  -- name of the component file
                  if INLINE.CONTENT (1 .. 2) = "--" then
                     OUTPUT_FILE_NAME := 
                        LINE_DEFINITION.CONVERT (INLINE.CONTENT (3 .. 
                                                                 INLINE.LAST));
                  else
                     OUTPUT_FILE_NAME := 
                        LINE_DEFINITION.CONVERT (INLINE.CONTENT (1 .. 
                                                                 INLINE.LAST));
                  end if;
                  
                  -- Open the new component file
                  OUTPUT_FILE.OPEN (OUTPUT_FILE_NAME);
                  TEXT_IO.PUT (" Extracting " & 
                               LINE_DEFINITION.CONVERT (OUTPUT_FILE_NAME));
                  
                  -- Flush the trailing banner line and note that we are now
                  -- within the text of a component file
                  INPUT_FILE.READ (INLINE);
                  IN_FILE := TRUE;
                  COUNTER.SET;
                  
               else
                  
                  -- We are within the text of a component file, so check for
                  -- a banner in order to determine if we are at the end of
                  -- the component file
                  if IS_BANNER (INLINE) then
                     OUTPUT_FILE.CLOSE;
                     IN_FILE := FALSE;
                     COUNTER.PRINT;
                  else
                     OUTPUT_FILE.WRITE (INLINE);
                     COUNTER.INCREMENT;
                  end if;
                  
               end if;
               
            end loop;
            
            OUTPUT_FILE.CLOSE;
            
         end if;
         
         COUNTER.PRINT;
         INPUT_FILE.CLOSE;
         
      end if;
      
   exception
      when OUTPUT_FILE.CANNOT_CREATE_FILE     =>
         TEXT_IO.PUT_LINE (" Cannot create " & 
                           LINE_DEFINITION.CONVERT (OUTPUT_FILE_NAME));
      when INPUT_FILE.FILE_NOT_FOUND     =>
         TEXT_IO.PUT_LINE (" File " & ARG1.CONTENT (1 .. ARG1.LAST) & 
                           " not Found");
      when INPUT_FILE.READ_PAST_END_OF_FILE   =>
         TEXT_IO.PUT_LINE
             (" Premature EOF on " & ARG1.CONTENT (1 .. ARG1.LAST));
         INPUT_FILE.CLOSE;
      when others    =>
         TEXT_IO.PUT_LINE (" Unexpected Error");
         INPUT_FILE.CLOSE;
         
   end UNPAGE;
   
   --=========================================================================
   -- PAGER2, Mainline
   --========================================================================= begin
   TEXT_IO.PUT_LINE (TITLE);
   TEXT_IO.PUT_LINE ("Type 'h' for Help");
   loop
      begin
         TEXT_IO.PUT ("PAGER2> ");
         TEXT_IO.GET_LINE (INLINE.CONTENT, INLINE.LAST);
         PARSER (INLINE, NARGS, COMMAND, ARG1, ARG2, REMAINDER);
         if NARGS > 0 then
            exit  when IS_COMMAND (EXIT_COMMAND, X_COMMAND);
            if IS_COMMAND (HELP_COMMAND, H_COMMAND) then
               HELP;
            elsif IS_COMMAND (CHECK_COMMAND, C_COMMAND) then
               CHECK;
            elsif IS_COMMAND (INCLUDE_COMMAND, I_COMMAND) then
               INCLUDE;
            elsif IS_COMMAND (LIST_COMMAND, L_COMMAND) then
               LIST;
            elsif IS_COMMAND (PAGE_COMMAND, P_COMMAND) then
               PAGE;
            elsif IS_COMMAND (UNPAGE_COMMAND, U_COMMAND) then
               UNPAGE;
            else
               TEXT_IO.PUT_LINE (" Invalid Command: " & 
                                 COMMAND.CONTENT (1 .. COMMAND.LAST));
            end if;
         end if;
      exception
         when others =>
            null;
      end;
   end loop;
    end PAGER2; --:::::::::: --pager2.c --:::::::::: /*
 * PROGRAM/CODE BODY NAME:      PAGER2.C 

 *
 * AUTHOR:                      Richard Conn 

 *
 * VERSION:                     1.0 

 *
 * DATE:                        10/30/87 

 *
 * REVISION HISTORY - 
 *
 * Version      Date            Author          Comments 

 *
 * 1.0  10/30/87        Richard Conn    Initial 

 *
 * KEYWORDS - 
 *
 * pager, pager2, paged files, page, unpage 
 *
 * CALLING SYNTAX - 
 *
 * From the command line: pager2 or pager2 command options 
 *
 * EXTERNAL ROUTINES - 
 *
 * <stdio.h>, <ctype.h
 *
 * DESCRIPTION - 
 *
 * PAGER2 is a simpler form of the PAGER program; PAGER2 performs three
 * of the functions of PAGER: (1) creates paged files, (2)
 * disassembles paged files, and (3) lists the contents of paged
 * files. 
 *
 */ #define TITLE "PAGER2, Version 1.1" #define INLEN 500               /* max length of lines in input file */
#define BANNER "::::::::::"     /* file banner in paged file */
#define BANLEN 10               /* number of chars in banner */
#define CBANNER "--::::::::::"  /* file comment banner in paged file */
#define CBANLEN 12              /* number of chars in comment banner */
#include <stdio.h> #include <ctype.h> main(argc, argv)
    int             argc;
    char          **argv; {
    char            inline[INLEN];
    char            command[INLEN], arg1[INLEN], arg2[INLEN], remainder[INLEN];
    int             nargs;
    int             i;
    /* Command Line Mode */
    if (argc > 1) {         if (argc > 2) {
         switch ((isupper(*argv[1])) ? tolower(*argv[1]) : *argv[1]) {
         case 'c':
                hash(argv[2]);
                break;
         case 'i':
                if (argc > 3)
                 include(argv[2], argv[3]);
                else
                 help();
                break;
         case 'l':
                list(argv[2]);
                break;
         case 'p':
                if (argc > 3)
                 page(argv[2], argv[3]);
                else
                 help();
                break;
         case 'u':
                unpage(argv[2]);
                break;
         default:
                help();
                break;
         }
         exit(0);
        } else {
         help();
         exit(0);
        }

    }
    /* Interactive Mode */
    printf("%s, TITLE);
    printf("Type 'h' for Help);
    while (1) {         printf("PAGER2> ");
        gets(inline);
        for (i = 0; inline[i] >= ' '; i++);
        inline[i] = ' ';
        parse(inline, &nargs, command, arg1, arg2, remainder);
        switch (*command) {
        case 'h':
         help();
         break;
        case 'c':
         if (nargs > 1)
                hash(arg1);
         break;
        case 'i':
         if (nargs > 2)
                include(arg1, arg2);
         break;
        case 'l':
         if (nargs > 1)
                list(arg1);
         break;
        case 'p':
         if (nargs > 2)
                page(arg1, arg2);
         break;
        case 'u':
         if (nargs > 1)
                unpage(arg1);
         break;
        case ' ':
        case '-':
         break;
        case 'x':
        case 'e':
         *command = 'x';
         break;
        default:
         printf("Invalid Command: %s, inline);
         break;
        }
        if (*command == 'x')
         break;

    }
    exit(0); } /*
 * Parse command line into a lower-case command character and a file
 * name 
 */ parse(line, nargs, command, arg1, arg2, remainder)
    char           *line, *command, *arg1, *arg2, *remainder;
    int            *nargs; {
    char           *chptr, *target;
    int             state, nextstate;
    chptr = line;
    *nargs = 0;
    state = 0;
    nextstate = 1;
    target = command;
    while (*chptr != ' ') {         switch (state) {
        case 0:
         if (*chptr > ' ')
                state = nextstate;
         else
                chptr++;
         break;
        case 1:         /* collecting characters for a
                                 * command */
         if (*chptr > ' ')
                *target++ = *chptr++;
         else {
                *target = ' ';
                nextstate = 2;
                target = arg1;
                state = 0;
         }
         break;
        case 2:         /* collecting characters for arg1 */
         if (*chptr > ' ')
                *target++ = *chptr++;
         else {
                *target = ' ';
                nextstate = 3;
                target = arg2;
                state = 0;
         }
         break;
        case 3:         /* collecting characters for arg2 */
         if (*chptr > ' ')
                *target++ = *chptr++;
         else {
                *target = ' ';
                nextstate = 4;
                target = remainder;
                state = 0;
         }
         break;
        case 4:         /* collecting characters for
                                 * remainder */
         *target++ = *chptr++;
         break;
        default:                /* should not happen */
         break;
        }

    }
    *target = ' ';
    if (state == 0)         *nargs = nextstate - 1;

    else         *nargs = state;

    *command = ((isupper(*command)) ? tolower(*command) : *command); } /* Print help message */ help() {
    printf(" Command Summary);
    printf("  help or h   - this summary);
    printf("                  Syntax: help);
    printf("  exit or x   - exit from program);
    printf("                  Syntax: exit);
    printf("  include or i- list components into an include file);
    printf("                  Syntax: include paged_file_name output_include_file);
    printf("  list or l   - list components of paged file);
    printf("                  Syntax: list paged_file_name);
    printf("  page or p   - create paged file from include file);
    printf("                  Syntax: page paged_file_name include_file_name);
    printf("  unpage or u - extract components from paged file);
    printf("                  Syntax: unpage paged_file_name); } /* Compute the hash code (checksum) of a file */ hash(filename)
    char           *filename; {
    FILE           *fopen(), *source;
    char            inline[INLEN];
    int             i, checksum;
    source = fopen(filename, "r");
    if (source == NULL) {         printf(" File %s not Found, filename);
        return;

    }
    checksum = 0;
    while (fgets(inline, INLEN, source) != (char *) NULL)         for (i = 0; inline[i] != ' '; i++)
         if ((inline[i] > ' ') && (inline[i] != 0x7f))
                checksum = (checksum + inline[i]) & 0x7f;

    fclose(source);
    printf(" Pager Checksum (Hash) of %s is %d, filename, checksum); } /* List the names of files in a paged file into an include file */ include(filename, ifname)
    char           *filename, *ifname; {
    FILE           *fopen(), *source, *dest;
    char            inline[INLEN], cfilename[INLEN];
    int             found, lcount;
    source = fopen(filename, "r");
    if (source == NULL) {         printf(" File %s not Found, filename);
        return;

    }
    dest = fopen(ifname, "w");
    if (dest == NULL) {         printf(" Cannot create %s, ifname);
        return;

    }
    fprintf(dest, "-- Include File for %s, filename);
    found = 0;                  /* first file has not yet been found */

    while (fgets(inline, INLEN, source) != (char *) NULL)         if ((strncmp(CBANNER, inline, CBANLEN) == 0) ||
         (strncmp(BANNER, inline, BANLEN) == 0)) {
         found = 1;
         break;
        }

    if (found == 0) {         printf(" File %s does not contain any components, filename);
        return;

    }
    while (found) {         found = 0;              /* next file has not yet been found */
        fgets(inline, INLEN, source);   /* get component file name */
        inline[strlen(inline) - 1] = ' ';       /* overwrite terminating
                                                 * */
        if (inline[0] != '-') {
         strcpy(cfilename, inline);
         fprintf(dest, "%s, inline);
        } else {
         strcpy(cfilename, &inline[2]);
         fprintf(dest, "%s, &inline[2]);
        }
        printf(" %s", cfilename);       /* print component file name */
        fgets(inline, INLEN, source);   /* flush line after component
                                         * file name */
        lcount = 0;
        while (fgets(inline, INLEN, source) != (char *) NULL)
         if ((strncmp(CBANNER, inline, CBANLEN) == 0) ||
                (strncmp(BANNER, inline, BANLEN) == 0)) {
                found = 1;
                break;
         } else
                lcount++;
        printf(" -- %d Lines, lcount);

    }
    fclose(source);
    fclose(dest); } /* List the names of files in a paged file */ list(filename)
    char           *filename; {
    FILE           *fopen(), *source;
    char            inline[INLEN], cfilename[INLEN];
    int             found, lcount;
    source = fopen(filename, "r");
    if (source == NULL) {         printf(" File %s not Found, filename);
        return;

    }
    found = 0;                  /* first file has not yet been found */

    while (fgets(inline, INLEN, source) != (char *) NULL)         if ((strncmp(CBANNER, inline, CBANLEN) == 0) ||
         (strncmp(BANNER, inline, BANLEN) == 0)) {
         found = 1;
         break;
        }

    if (found == 0) {         printf(" File %s does not contain any components, filename);
        return;

    }
    while (found) {         found = 0;              /* next file has not yet been found */
        fgets(inline, INLEN, source);   /* get component file name */
        inline[strlen(inline) - 1] = ' ';       /* overwrite terminating
                                                 * */
        if (inline[0] != '-')
         strcpy(cfilename, inline);
        else
         strcpy(cfilename, &inline[2]);
        printf(" %s", cfilename);       /* print component file name */
        fgets(inline, INLEN, source);   /* flush line after component
                                         * file name */
        lcount = 0;
        while (fgets(inline, INLEN, source) != (char *) NULL)
         if ((strncmp(CBANNER, inline, CBANLEN) == 0) ||
                (strncmp(BANNER, inline, BANLEN) == 0)) {
                found = 1;
                break;
         } else
                lcount++;
        printf(" -- %d Lines, lcount);

    }
    fclose(source); } /* Create a Paged File */ page(dest, include)
    char           *dest, *include; {
    FILE           *fopen(), *destination;
    destination = fopen(dest, "w");
    if (destination == NULL) {         printf(" Cannot create %s, dest);
        return;

    }
    page_include(include, destination);
    fclose(destination); } /* Page_Include processes the indicated file as an include file */ page_include(filename, destination)
    char           *filename;
    FILE           *destination; {
    FILE           *fopen(), *fd;
    char            inline[INLEN];
    fd = fopen(filename, "r");
    if (fd == NULL) {         printf(" Cannot open include file %s, filename);
        return;

    }
    while (fgets(inline, INLEN, fd) != (char *) NULL) {         inline[strlen(inline) - 1] = ' ';       /* overwrite ending */
        switch (inline[0]) {
        case ' ':
        case ' ':
        case '-':
         break;
        case '@':
         page_include(&inline[1], destination);
         break;
        default:
         copy(inline, destination);
        }

    }
    fclose(fd); } /* Copy the indicated file into the paged file being built */ copy(filename, destination)
    char           *filename;
    FILE           *destination; {
    FILE           *fopen(), *source;
    char            inline[INLEN], temp[INLEN];
    int             lcount;
    printf(" Adding %s", filename);
    lcount = 0;
    source = fopen(filename, "r");
    if (source == NULL) {         printf(" Component File %s not Found, filename);
        return;

    }
    fputs(CBANNER, destination);
    fputs(", destination);
    temp[0] = ' ';
    strcat(temp, "--");
    strcat(temp, filename);
    strcat(temp, ");
    fputs(temp, destination);
    fputs(CBANNER, destination);
    fputs(", destination);
    while (fgets(inline, INLEN, source) != (char *) NULL) {         fputs(inline, destination);
        lcount++;

    }
    printf(" -- %d Lines, lcount);
    fclose(source); } /* Unpage a Paged File */ unpage(filename)
    char           *filename; {
    FILE           *fopen(), *source, *destination;
    char            inline[INLEN], cfilename[INLEN];
    int             found, lcount;
    source = fopen(filename, "r");
    if (source == NULL) {         printf(" File %s not Found, filename);
        return;

    }
    found = 0;                  /* first file has not yet been found */

    while (fgets(inline, INLEN, source) != (char *) NULL)         if ((strncmp(CBANNER, inline, CBANLEN) == 0) ||
         (strncmp(BANNER, inline, BANLEN) == 0)) {
         found = 1;
         break;
        }

    if (found == 0) {         printf(" File %s does not contain any components, filename);
        return;

    }
    while (found) {         found = 0;              /* next file has not yet been found */
        fgets(inline, INLEN, source);   /* get component file name */
        inline[strlen(inline) - 1] = ' ';       /* overwrite terminating
                                                 * */
        if (inline[0] != '-')
         strcpy(cfilename, inline);
        else
         strcpy(cfilename, &inline[2]);
        printf(" Extracting %s", cfilename);    /* print component file
                                                 * name */
        fgets(inline, INLEN, source);   /* flush line after component
                                         * file name */
        destination = fopen(cfilename, "w");
        if (destination == NULL) {
         printf(" Cannot create %s, cfilename);
         return;
        }
        lcount = 0;
        while (fgets(inline, INLEN, source) != (char *) NULL)
         if ((strncmp(CBANNER, inline, CBANLEN) == 0) ||
                (strncmp(BANNER, inline, BANLEN) == 0)) {
                found = 1;
                break;
         } else {
                lcount++;
                fputs(inline, destination);
         }
        printf(" -- %d Lines, lcount);
        fclose(destination);

    }
    fclose(source); }


 

Index

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO
AUTHOR
BUGS

This document was created by man2html, using the manual pages.
Time: 14:06:54 GMT, November 26, 2024