I have just started on an interface to CUPS, only four functions so far
but already two ways to get a list of printers:
CUPS_GETPRINTERS( array_to_be_filled ) // based on the deprecated
function cupsGetPrinters()
CUPS_GETDESTS( array_to_be_filled ) // based on cupsGetDests()
c source code is as follows:
// CUPS4HFunctions.c
#include
#include
HB_FUNC( CUPS_GETDEFAULT )
{
const char *default_printer;
default_printer = cupsGetDefault();
if ( default_printer != NULL )
{
hb_retc( default_printer );
}
else
{
hb_ret();
}
}
HB_FUNC( CUPS_GETPRINTERS )
{
int num_printers;
int c_index;
int h_index;
char **printer_list;
PHB_ITEM pArray;
pArray = hb_param( 1, HB_IT_ARRAY );
num_printers = cupsGetPrinters(
hb_arraySize( pArray, ( ULONG ) num_printers );
if ( num_printers > 0 )
{
for ( c_index = 0, h_index = 1; c_index < num_printers;
c_index++, h_index++ )
{
hb_storc( printer_list[c_index], 1, h_index );
}
for ( c_index = 0; c_index < num_printers; c_index++ )
{
free( printer_list[c_index] );
}
free( printer_list );
}
hb_retni( num_printers );
}
HB_FUNC( CUPS_GETDESTS )
{
int num_dests;
int c_index;
int h_index;
ULONG length_of_name;
cups_dest_t *dest_list, *dest;
PHB_ITEM pArray;
pArray = hb_param( 1, HB_IT_ARRAY );
num_dests = cupsGetDests(
hb_arraySize( pArray, ( ULONG ) num_dests );
if ( num_dests > 0 )
{
for (c_index = 0, h_index = 1, dest = dest_list; c_index <
num_dests; c_index++, h_index++, dest ++)
{
hb_storc( dest->name, 1, h_index );
}
cupsFreeDests( num_dests, dest_list );
}
hb_retni( num_dests );
}
HB_FUNC( CUPS_PRINTFILE )
{
int jobID;
jobID = cupsPrintFile( hb_parc( 1 ), hb_parc( 2 ), hb_parc( 3 ), 0,
NULL );
hb_retni( jobID );
}
To illustrate usage here is my first test program:
// testcups4h.prg
FUNCTION Main()
LOCAL arr_Printers
LOCAL int_PrinterCount
? CUPS_GetDefault()
?
InKey( 0 )
arr_Printers := Array( 0 )
int_PrinterCount := CUPS_GetPrinters( arr_Printers )
? int_PrinterCount
?
FOR i = 1 TO int_PrinterCount
? arr_Printers[i]
NEXT
?
? "End of list"
?
InKey( 0 )
arr_Printers := Array( 0 )
int_PrinterCount := CUPS_GetDests( arr_Printers )
? int_PrinterCount
?
FOR i = 1 TO int_PrinterCount
? arr_Printers[i]
NEXT
?
? "End of list"
?
InKey( 0 )
? "About to print"
int_JobID := CUPS_PrintFile( CUPS_GetDefault(),
"/home/bwana/sixthsense/templates_safety/Consult1.ps", "TestCUPS4H" )
? "Job ID is:", int_JobID
?
InKey( 0 )
QUIT
You need to:
compile CUPS4HFunctions.c with something like:
gcc CUPS4HFunctions.c -c -I./../../include -I./../../../harbour/include
then I created a library from it with something like:
ar rc ./../../lib/libcups4h.a ./CUPS4HFunctions
then when you link your program (or my test program) you need to include
the following libraries:
-lcups -lcups4h
Good luck! If I can be of further help let me know.
By the way CUPS_GETDEFAULT() will return the name of the default printer.
CUPS_PRINTFILE( cPrinterName, cFileToPrint, cNameForPrintQueue ) will
print a file. I will add support for options some time.
This code is an experiment I only did last night!
Regards
Doug
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour