[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Learning C
Ick. I would have assumed there would be a decent library for printing by
now. One more reason I stick to networking code rather than printing (or
anything GUI for that matter).
Christopher Bibbs
-----Original Message-----
From: Adam Tauno Williams [mailto:adam@morrison-ind.com]
Sent: Thursday, July 27, 2000 9:58 AM
To: members@kalamazoolinux.org
Subject: RE: Learning C
>As a general rule, I try to avoid executing system commands from within C
>code. Bad form, IMHO. I'm sure there is a better API available.
I'm afraid their isn't. Interfacing directly to LPD (the printer daemon) is
NOT something you want to do, trust me, it is very easy to really screw
things
up, and the lpd code is hideous. Also you'd possibly loose portability to
systems that replace LPD with CUPS, LPRnq, etc... The "libprint" project to
create a distro-nuetral print API is dead. If you want something sexy I'd
suggest looking at gnome-print, which provides an API for drawing things on
pages and then sending it to the system queue (itself then invokes
"/usr/bin/lpr" on a temporary file). Qt I think also offer a printing API.
http://www.levien.com/gnome/print-arch.html
>>I must admit, stdprn and stdaux are new to me. A quick check with my
>>co-workers (all of us are C or C++ programmers) and no one knows about
>>stdprn or stdaux. It may be that we're all terribly ignorant *OR* it
>could
>>be one of those "standards" that really isn't. Off the top of my head I
>>can't tell you how to print to a printer. I guess you'd want to interface
>>with lpd, but that wouldn't be as non-trivial as a stdprn.
>You would use the popen to create a sub-process ala:
> command_string = sprintf("/usr/bin/lpr -P%s", $queue_name);
> FILE *printer = popen(command_string, "w");
> fwrite(pointer_to_stuff, size_of_stuff, 1, printer);
> pclose(printer);
>(Note: the above syntax is a rough idea and in no way will compile).
>Since the pclose function does not return until the subprocess
>closes it's stdin (i.e. dies) you really should perform such
>operations as printing in thier own thread so as not to block
>over-all program execution. pclose returns the exit status of
>the subprocess.
Systems and Network Administrator
Morrison Industries
1825 Monroe Ave NW.
Grand Rapids, MI. 49505