Next / Previous / Contents / Shipman's homepage

20.2. InputFile.__init__(): Constructor

listext2
# - - -   I n p u t F i l e . _ _ i n i t _ _

    def __init__(self, inFile, bodyLayout):
        '''Constructor.
        '''
        #-- 1
        self.bodyLayout = bodyLayout
        self.__blockList = []
        self.nOutCols = 0
        self.nInLines = self.nOverflows = self.nOutLines = 0

Section 20.3, “InputFile.__readFile(): Slice up the input lines” reads the input file and slices the lines into OutBlock instances that will fit into a column. In each FirstBlock instance, the .goodBreak flag is set if the corresponding input line starts with the break string.

listext2
        #-- 2
        # [ self.__blockList  +:=  OutBlock instances representing
        #       the lines from inFile with tabs expanded, with each
        #       line represented as a FirstBlock
        #       followed by zero or more OverflowBlock
        #       instances ]
        self.__readFile(inFile)

If the --break option was specified on the command line, Section 20.7, “InputFile.__findBreaks(): Implement --break implements this option by marking a break at each line where a new column must start. See Section 20.7, “InputFile.__findBreaks(): Implement --break.

listext2
        #-- 3
        # [ self.__blockList  :=  self.__blockList with column
        #       breaks as specified by Args() marked as breaks ]
        self.__findBreaks()

For the logic that removes completely blank columns, see Section 20.10, “InputFile.__delBlankCols(): Suppress entirely blank columns”.

listext2
        #-- 4
        # [ self.__blockList  :=  self.__blockList minus any columns
        #       that contain only empty or entirely blank lines
        #   self.nOutLines  +:=  number of output lines remaining
        #       after removal of blank columns
        #   self.nOverflows  +:=  number of overflow lines remaining
        #       after removal of blank columns
        #   self.nOutCols  +:=  number of columns remaining
        #       after removal of blank columns ]
        self.__delBlankCols()

The number of pages is the ceiling of the number of columns divided by the number of columns per page.

listext2
        #-- 5
        # [ self.nOutPages  :=  ceiling(self.nOutCols/Args().nCols) ]
        colsPerPage = Args().nCols
        self.nOutPages = (self.nOutCols + colsPerPage - 1) / colsPerPage