Next / Previous / Contents / Shipman's homepage

4.6. The main program

The only thing the main does is iterate over the list of files given as command line arguments, processing each one in turn by calling Section 4.7, “ processFile(): Process one input file ”.

litdocbook5
# - - - - -   m a i n

def main():
    '''Main program for litdocbook5.

      [ let
          argList == the set of command line INFILE arguments from
                     sys.argv[1:]
          valid-files == readable, valid XML files named in argList
          writeable-targets == output files named in lit-elts
              of valid-files
        in ->
          if argList is empty ->
            sys.stderr  +:=  usage message
          else ->
            writeable-targets  :=  lit-content of lit-elts in valid-files
            sys.stdout  +:=  reports on writeable-targets as
                specified by sys.argv[1:] switches
            sys.stderr  +:= (messages about names in argList that
              don't name readable, valid XML files) + (messages about
              output files named in valid-files that can't be
              opened new for writing) ]
    '''
    #-- 1
    # [ if sys.argv[1:] is a valid command line ->
    #     args  :=  an Args instance representing sys.argv[1:]
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution
    args = Args()

    #-- 2
    for inFileName in args.inFileList:
        #-- 2 body
        # [ if inFileName names a readable, valid DocBook XML file ->
        #     output files named in that file that can be opened
        #     new for writing  :=  code fragments from those XML files
        #         designated for those output files
        #     sys.stderr  +:=  messages about output files named in
        #         those XML files that can't be opened new for writing
        #   else ->
        #     sys.stderr  +:=  error message ]
        processFile(args, inFileName)