! 3up4up.bas
! a program to print lables either 3 or 4 wide from andi
! by rc & ske on 8-21-82

map1 the'matrix
       map2 line'one(4),s,28
       map2 line'two(4),s,28
       map2 line'three(4),s,28
       map2 line'four(4),s,28
       map2 line'five(4),s,28

map1 matrix'zapper
       map2 next'to'nothing,s,560,"",@the'matrix

map1 input'file
       map2 lname,s,15
       map2 fname,s,15
       map2 company,s,28
       map2 add1,s,28
       map2 add2,s,28
       map2 city,s,15
       map2 state,s,2
       map2 zip,s,10

map1 file'zapper
       map2 nothing,s,141,"",@input'file

map1 dummy,s,1
map1 threeup4up,f
map1 output'line,s,120
map1 input'file'name,s,10
map1 output'file'name,s,10
map1 z,s,1
map1 extension,s,4

top:
       call get'file'name
       lookup input'file'name,x
       if x <= 0 &
           then &
               call no'such'file :&
               goto quit
       call threeup'or'4up
       call open'files

format:
       the'matrix = matrix'zapper
       call load'matrix
       if file'empty # "Y"
          then &
               call shift'lines :&
               call write'to'file :&
               goto format

tidy'up:
       call close'files
       ? tab(23,1); "that's all folks!"
quit:
       end

get'file'name:
       ? tab (-1,0)
       ? tab (10,10);
       input "enter file name (default = .LST)     ",input'file'name
       input'file'name=ucs(input'file'name)
       x=instr(1, input'file'name,".")
       if x=0 &
         then &
           input'file'name=input'file'name+".LST"
       return






no'such'file:
       ? "there isn't anything like "input'file'name" in this account"
       return

open'files:
       z=threeup4up
       extension ="."+z+"UP"
       x=instr(1,input'file'name,".")
       output'file'name=input'file'name[1;x-1]+extension
       open #1, input'file'name, input
       open #2, output'file'name, output
       return

threeup'or'4up:
       ? "how many lables across do you desire to print?"
       input "(3 or 4) ",threeup4up
       if threeup4up < 3 or threeup4up > 4 &
               then &
                       goto threeup'or'4up
       return

load'matrix:
       for n = 1 to threeup4up
           input'file = file'zapper
           input line #1, lname
           if eof(1) = 1 &
              then &
                   n = threeup4up : &
                   goto out'of'names
           input line #1, fname
           input line #1, company
           input line #1, add1
           input line #1, add2
           input line #1, city
           input line #1, state
           input line #1, zip
           call file'to'matrix
           call matrix'to'output'line
       out'of'names:
       next n
       return

shift'lines:
           for n = 1 to threeup4up
               if len(line'one(n)) = 0 &
                   then &
                       line'one(n) = line'two(n) :&
                       line'two(n) = ""
               if len(line'two(n)) = 0 &
                   then &
                       line'two(n) = line'three(n) :&
                       line'three(n) = ""
               if len(line'three(n)) = 0 &
                   then &
                       line'three(n) = line'four(n) :&
                       line'four(n) = ""
               if len(line'four(n)) = 0
                   then &
                       line'four(n) = line'five(n) :&
                       line'five(n) = ""
           next n
       return

write'to'file:







close'files:
       close #1
       close #2
       return

file'to'matrix:
       line'one(n) = fname + " " + lname
       line'two(n) = company
       line'three(n) = add1
       line'four(n) = add2
       line'five(n) = city + ", " + state + "  " + zip
       return

matrix'to'output'line:
       for n = 1 to threeup4up
           ? #2 tab(35 * (n-1));line'one(n);
       next n
       ? #2
       for n = 1 to threeup4up
           ? #2 tab(35 * (n-1); line'two(n);
       next n
       ? #2
       for n = 1 to threeup4up
           ? #2 tab(35 * (n-1); line'three(n);
       next n
       ? #2
       for n = 1 to threeup4up
           ? #2 tab(35 * (n-1); line'four(n);
       next n
       ? #2
       for n = 1 to threeup4up
           ? #2 tab(35 * (n-1); line'five(n);
       next n
       ? #2
       return



n = 1 to