mark_h
4th May 2004, 21:59
I was wondering if there was a function that would allow me to print a file. I am using the select.file function of tgbrg0019 to get file names. I know I can create a report and attach it to the session to do this, but was wondering if there was some function lurking out there that I can use. Currently I am just shelling out an executing a lp command. Thought maybe if there was a function out there I could clean it up and post it in the code and utilities forum. It does not need to print nicely, but just enough to make it kind of useful to a user. Or maybe someone has a better thought.

Mark

günther
5th May 2004, 09:52
I also had some textfiles (logfiles). Some keyusers were allowed to view and print them.

Btw. The function for viewing only works for the gui, but should work on unix and windows. All other parts are unix ;-)


...

if printer = "d" then
if <running in ascii mode> then
SHELL("view " & filename, 6)
else
view.file( filename)
endif
else
SHELL("lp -d" & printer & " -onb " & filename, 1)
endif

...

function view.file(const string filename)
{
long mw.o, mw.n, child, size

file.stat(filename, size)
if (size <= 0) then
return
endif

mw.o = current.mwindow()
mw.n = create.mwindow("ttstpdisplay: " & filename, CHARBASED, DSNORMALSTATE)

if mw.n then
change.mwindow(mw.n)
child = activate("ttstpdisplay", filename, "80", "22")
if child then
set.pgrp(child, child)
grab.mwindow(mw.n, child)
wait(child, WTHANG)
destroy.mwindow(mw.n)
mw.n = 0
change.mwindow(mw.o)
endif
endif

return
}

mark_h
5th May 2004, 15:54
Thats basically what I do - see the code below. I am going to play around a bit and see how I can improve it.

Mark


function print.files()
{
long i
string sh.cmd(1024)
| For printing only a max of 30 files can be selected. 1 is multi-file select on and 30
| is max files to be selected.
ret = EXEC_DLL_FUNCTION ("otgbrg0019", "select.file", ret1, start.dir, 1, work, nr, 30)
if nr>0 then
if ask.enum("tdilc40079",tcyesno.no,ret) = tcyesno.yes then
| See what device they want to print to.
ret = spool.open("",spool.device,1)
if not ret then
spool.close()
choice.again()
endif
spool.close()

for i = 1 to nr
sh.cmd = strip$(sprintf$("lp -d%s %s",tolower$(spool.device),work(1,i)))
shell(sh.cmd,1)
endfor
endif
endif
set.mem(work,"")
}