CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Functions | Variables
lpr.c File Reference

"Line PRinter" tool frontend to libcapsclient More...

Data Structures

struct  lpr_exchange
 

Functions

static void printer_job_unref (struct lpr_exchange *job)
 
static int get_first_available_printer (struct caps_cl_handle *instance, caps_identifier *id)
 
static caps_identifier printer_by_name_get (struct caps_cl_handle *clh, const char *name)
 
static int commit_document (struct lpr_exchange *lpr)
 
static int copies_set_from_string (struct lpr_exchange *lpr, const char *string)
 
static int port_set_from_string (struct lpr_exchange *lpr, const char *string)
 
static int host_name_and_port_set_from_string (struct lpr_exchange *lpr, const char *string)
 
static int document_set_from_name (struct lpr_exchange *lpr, const char *document_name)
 
static void document_params_set_from_string (struct lpr_exchange *lpr, const char *string)
 
static void copies_parameter_on_demand (struct lpr_exchange *lpr)
 
static void handle_nls (void)
 
static void caps_lpr_print_help_message (void)
 
int main (int argc, char *argv[])
 

Variables

static struct lpr_exchange print_job
 
static const struct option caps_lpr_long_options []
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

Function Documentation

◆ printer_job_unref()

static void printer_job_unref ( struct lpr_exchange job)
static

◆ get_first_available_printer()

static int get_first_available_printer ( struct caps_cl_handle instance,
caps_identifier id 
)
static

Retrieve ID of first available printer

Parameters
[in]instanceThe library instance handle
[in]idPointer where to store the printer's ID
Return values
0On success (*id is valid),
-ENODEVNo printer found
negativeFailed to retrieve the printer list from the coordinator

Used if no printer was specified on the command line.

◆ printer_by_name_get()

static caps_identifier printer_by_name_get ( struct caps_cl_handle clh,
const char *  name 
)
static

Try harder to get the printer ID

Parameters
[in]clhCAPS client library handle to communicate with the printing coordinator
[in]nameThe printer name to search for
Return values
CAPS_INVALID_IDENTIFIERIf no printer was found
PositivePrinter's ID

The CUPS world tends to combine the printer's name¹ and its instance¹ into one printer name. E.g. with name="foo" and instance="bar" the used printer name is something like "foo/bar". But in the CAPS universe only "foo" is used to identify the printer.

Note
Call this only, if the naive approach using caps_cl_printer_name_to_id() already failed.
This is a copy of the caps_cl_printer_name_to_id() function

¹) From their 'cups_dest_t' structure.

◆ commit_document()

static int commit_document ( struct lpr_exchange lpr)
static

Print document from file handle

Parameters
[in]lprAll available information about the printing job
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREElse

◆ copies_set_from_string()

static int copies_set_from_string ( struct lpr_exchange lpr,
const char *  string 
)
static

Set the printing copy count from a string

Parameters
[in,out]lprThe instance to work on
[in]stringThe copy number string
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREIf the format wasn't usable

◆ port_set_from_string()

static int port_set_from_string ( struct lpr_exchange lpr,
const char *  string 
)
static

Set the port from a string

Parameters
[in,out]lprThe instance to work on
[in]stringThe port number string
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREIf the format wasn't usable
Note
Value ignored

◆ host_name_and_port_set_from_string()

static int host_name_and_port_set_from_string ( struct lpr_exchange lpr,
const char *  string 
)
static

Extract server name and port from the string

Parameters
[in,out]lprThe instance to work on
[in]stringThe string in the format the -H parameter expects (e.g. <server>[:<port>])
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREIf the format wasn't usable
Note
Value ignored

◆ document_set_from_name()

static int document_set_from_name ( struct lpr_exchange lpr,
const char *  document_name 
)
static

Open the to be printerd document file for reading

Parameters
[in,out]lprThe instance to work on
[in]document_nameThe name of the document to print
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREIf the format wasn't usable

◆ document_params_set_from_string()

static void document_params_set_from_string ( struct lpr_exchange lpr,
const char *  string 
)
static

Concatenate a string as the document's print parameters for this print transaction

Parameters
[in]lprThe instance to work on
[in]stringThe print parameters
Note
Does not return in case of memory error

◆ copies_parameter_on_demand()

static void copies_parameter_on_demand ( struct lpr_exchange lpr)
static

Add the copies printing parameter on demand

Parameters
[in]lprThe instance to work on

"On demand" means: add this printing parameter only, if not already done or more copies than 1 should be printed. Since the user can add this parameter manually via the -o option, we should not overwrite it.

Precondition
The lpr_exchange::copies member is valid (e.g. >= 1)

◆ handle_nls()

static void handle_nls ( void  )
static

◆ caps_lpr_print_help_message()

static void caps_lpr_print_help_message ( void  )
static

◆ main()

int main ( int  argc,
char *  argv[] 
)

Variable Documentation

◆ print_job

struct lpr_exchange print_job
static
Initial value:
= {
.copies = 1,
.fd = -1,
}

◆ caps_lpr_long_options

const struct option caps_lpr_long_options[]
static
Initial value:
= {
{ .name = "encryption", .has_arg = no_argument, .flag = NULL, .val = 'E', },
{ .name = "host", .has_arg = required_argument, .flag = NULL, .val = 'H', },
{ .name = "title", .has_arg = required_argument, .flag = NULL, .val = 'T', },
{ .name = "name", .has_arg = required_argument, .flag = NULL, .val = 'J', },
{ .name = "printer", .has_arg = required_argument, .flag = NULL, .val = 'P', },
{ .name = "option", .has_arg = required_argument, .flag = NULL, .val = 'o', },
{ .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'i', },
{ .name = "version", .has_arg = no_argument, .flag = NULL, .val = 19,},
}

this parser uses a free argument: the number of copies to print. This isn't currently supported by the capscmdparser. Thus, we stay with getopt_long() for now.