    ! Program to view an EDWIN PDF on any device.

    external string(31) Version   = "5",
                          Release   = "2",
                          Revision  = "0",
                          Fname     = "VIEWPDF",
                       Product Code = "VIEWPDF"

    from Imp include Cliparse
    from LL  include Common
    from Edwin include Consts
    from Edwin include Specs
    const integer EMAS=1, VMS=2
    const integer MACHINE = VMS

    begin
       string(127) OUTPUT, INPUT
       integer TYPE, I, SIZE, XOFF, YOFF, DEVICE
       long real UPCM
       const integer array VX ('1':'5') = 20 * 4, 28 * 2, 20 * 2, 28, 20
       const integer array VY ('1':'5') = 28 * 2, 20 * 2, 28, 20, 14

       on event 9,14 start
           TERMINATE EDWIN
           if EVENT_EVENT=14 start
               NEWLINE
               Fatal Error ("EDWIN error".ItoS(EVENT_SUB,1)."  : ".EDWIN ERROR(EVENT_SUB))
           finish
           return
       finish

       if Qualifier Present("IDENTIFY") start
          Print Identification
          return unless Qualifier Present("FILE")
       finish

       Type = default device
       Type = Qualifier I ("DEVICE") if Qualifier Present ("DEVICE")
       Output = Qualifier S ("OUTPUT")
       Input = Qualifier S ("FILE")

       begin { Open input stream }
          on event 9 start
              Fatal Error ("Cannot open input stream")
          finish
          OPEN LL INPUT (1, LL EDWIN PDF File, 0, INPUT, "")
       end
       SELECT INPUT (0)
       if OUTPUT#"" or TYPE=300 c
                     or TYPE=2686 or TYPE=2686300 c
                     or TYPE=30072 or TYPE=300144 c
                     or TYPE=7500  or TYPE=-7220 or 563<=TYPE<=1051 start
           OUTPUT = INPUT if OUTPUT = ""
           if MACHINE=EMAS start
               if OUTPUT -> OUTPUT.("#") start; finish
               if OUTPUT -> (".").OUTPUT start; finish
               if OUTPUT -> ("_").OUTPUT start; finish
           else
               if OUTPUT -> (":").OUTPUT start; finish
               if OUTPUT -> ("]").OUTPUT start; finish
               if OUTPUT -> (">").OUTPUT start; finish
               if OUTPUT -> OUTPUT.(".") start; finish
               if OUTPUT -> OUTPUT.(";") start; finish
           finish
           if TYPE=300 or TYPE=2686 or TYPE=2686300 or TYPE=30072 or TYPE=300144 start
               I = LL Listing File
           finish else if TYPE=-7220 or TYPE=7500 start
               I = LL HP Plotter File
           else
               I = LL Calcomp Plotter File
           finish
           begin { Open input stream }
              on event 9 start
                  Fatal Error ("Cannot open output stream")
              finish
              OPEN LL OUTPUT (2, I, 0, OUTPUT, "")
              VIEW ON (2)
           end
       finish
       INITIALISE FOR (TYPE)
       DEVICE = DEVICE DATA_DEV NO
       UPCM = DEVICE DATA_UNITS PER CM
       if UPCM > 1 start
           PROMPT ("Size (cms):")
           SKIP SYMBOL while NEXT SYMBOL <=' '
           if NEXT SYMBOL & 95 = 'A' start
               SKIP SYMBOL
               READ SYMBOL (SIZE)
               unless '1' <= SIZE <= '5' start
                   Fatal Error ("Paper size must be A5, A4, A3, A2 or A1")
               finish
               VIEWPORT (0, Round(VX(SIZE)*UPCM), 0, Round(VY(SIZE)*UPCM))
               READ SYMBOL (SIZE) until SIZE = NL
           else
               begin
                  on 3,4 start
                      SKIP SYMBOL while NEXT SYMBOL # NL
                      Fatal Error ("Invalid size specified")
                  finish
                  READ (SIZE)
                  SKIP SYMBOL while NEXT SYMBOL = ' ' or NEXT SYMBOL = ','
                  if '0'<= NEXT SYMBOL <= '9' then READ (TYPE) else TYPE=SIZE
                  XOFF = 0;   YOFF = 0
                  SKIP SYMBOL while NEXT SYMBOL = ' ' or NEXT SYMBOL = ','
                  if '0'<= NEXT SYMBOL <= '9' then READ (XOFF)
                  SKIP SYMBOL while NEXT SYMBOL = ' ' or NEXT SYMBOL = ','
                  if '0'<= NEXT SYMBOL <= '9' then READ (YOFF)
                  VIEWPORT (Round(XOFF*UPCM), Round((XOFF+SIZE)*UPCM),
                            Round(YOFF*UPCM), Round((YOFF+TYPE)*UPCM))
               end
           finish
       finish
    !   %if DEVICE = Printronix %start
    !       SELECT OUTPUT (0)
    !       PRINT STRING ("Is this for a Printronix with narrow or wide paper?")
    !       NEWLINE
    !       PROMPT ("Narrow or Wide? ")
    !       READ SYMBOL (SIZE) %and SIZE=SIZE&95 %until SIZE='N' %or SIZE='W'
    !       READ SYMBOL (TYPE) %until TYPE=NL
    !       VIEWPORT (0, 460, 0, 791) %if SIZE='N'; ! W = default.
    !   %finish

       cycle
          NEWFRAME
          SELECT INPUT (1)
          REVIEW
          DRIVE DEVICE (4, 0, 22) if DEVICE = VT100
          DRIVE DEVICE (4, 0, 760) if DEVICE = Tektronix or DEVICE=X5A
          UPDATE
          if Qualifier Present ("MULTIPLE") or Device Data_Devno = BBC Micro start
              SELECT INPUT (0)
              if Device Data_Devno = BBC Micro start
                  Prompt ("More?")
              else
                  Prompt (" Another?")
              finish
              READ SYMBOL (I) and I=I&95 until I='Y' or I='N'
              SKIP SYMBOL while NEXT SYMBOL # NL
              exit if I='N'
          else
              exit
          finish
       repeat

    TERMINATE EDWIN
    end

    endoffile