home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 91 / af091a.adf / af91a3.lzx / prgs / IO / print.b < prev    next >
Encoding:
Text File  |  1996-09-15  |  1.3 KB  |  75 lines

  1. { ** Send a file to the printer **
  2.  
  3.   If the program is started from the shell,
  4.   the file name is taken to be the first
  5.   argument. Likewise if the program is
  6.   WorkBench launched. Otherwise the 
  7.   program invokes a file requester. 
  8.  
  9.   If the requested file doesn't exist 
  10.   the program quits with a beep.
  11.  
  12.   Page size can also be specified.
  13.  
  14.   Compile thus: bas -O print ACE:SUBmods/WBarg/WBarg.o
  15. }
  16.  
  17. #include <SUBmods/WBarg.h>
  18.  
  19. DEFINT a-z
  20.  
  21. page_size=0
  22.  
  23. SUB usage
  24.   print "usage: ";arg$(0);" ? | [<filename>][page-size]"
  25. END SUB
  26.  
  27. '..get the filename
  28. if WBargcount=1 then
  29.   '..Workbench args
  30.   x$ = WBargPath$(1) + WBarg$(1)
  31. else
  32.   if argcount > 0 then
  33.     '..CLI/shell args
  34.     if argcount = 1 then
  35.        x$ = arg$(1)
  36.        if x$ = "?" then 
  37.           usage
  38.           stop
  39.        end if
  40.     else
  41.       if argcount = 2 then 
  42.      x$ = arg$(1)
  43.      page_size = val(arg$(2)) 
  44.       else
  45.      '..too many args
  46.          usage
  47.      stop
  48.       end if
  49.     end if
  50.   else
  51.     '..no args
  52.     x$ = FileBox$("Select file to print")
  53.   end if
  54. end if
  55.  
  56. '..print the file
  57. open "I",1,x$
  58.  
  59. if handle(1)=0 then beep:stop  '..doesn't exist.
  60.  
  61. open "O",2,"PRT:"
  62. ln$=""
  63. count=0
  64. while not eof(1)
  65.  line input #1,ln$
  66.  print #2,ln$
  67.  ++count
  68.  if page_size > 0 and count = page_size then 
  69.     count=0
  70.     print #2,chr$(12)  '..form feed
  71.  end if
  72. wend
  73.  
  74. close 1,2
  75.