]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpoptions.c
2 * "$Id: lpoptions.c 5833 2006-08-16 20:05:58Z mike $"
4 * Printer option program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry.
27 * list_group() - List printer-specific options from the PPD group.
28 * list_options() - List printer-specific options from the PPD file.
29 * usage() - Show program usage and exit.
33 * Include necessary headers...
36 #include <cups/string.h>
37 #include <cups/cups.h>
38 #include <cups/i18n.h>
47 void list_group(ppd_group_t
*group
);
48 void list_options(cups_dest_t
*dest
);
53 * 'main()' - Main entry.
56 int /* O - Exit status */
57 main(int argc
, /* I - Number of command-line arguments */
58 char *argv
[]) /* I - Command-line arguments */
60 int i
, j
; /* Looping vars */
61 int changes
; /* Did we make changes? */
62 int num_options
; /* Number of options */
63 cups_option_t
*options
; /* Options */
64 int num_dests
; /* Number of destinations */
65 cups_dest_t
*dests
; /* Destinations */
66 cups_dest_t
*dest
; /* Current destination */
67 char *printer
, /* Printer name */
68 *instance
, /* Instance name */
69 *option
; /* Current option */
75 * Loop through the command-line arguments...
85 for (i
= 1; i
< argc
; i
++)
86 if (argv
[i
][0] == '-')
90 case 'd' : /* -d printer */
92 printer
= argv
[i
] + 2;
102 if ((instance
= strrchr(printer
, '/')) != NULL
)
106 num_dests
= cupsGetDests(&dests
);
108 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) == NULL
)
110 _cupsLangPuts(stderr
,
111 _("lpoptions: Unknown printer or class!\n"));
116 * Set the default destination...
119 for (j
= 0; j
< num_dests
; j
++)
120 dests
[j
].is_default
= 0;
122 dest
->is_default
= 1;
124 cupsSetDests(num_dests
, dests
);
126 for (j
= 0; j
< dest
->num_options
; j
++)
127 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
128 num_options
= cupsAddOption(dest
->options
[j
].name
,
129 dest
->options
[j
].value
,
130 num_options
, &options
);
133 case 'h' : /* -h server */
135 cupsSetServer(argv
[i
] + 2);
142 cupsSetServer(argv
[i
]);
146 case 'E' : /* Encrypt connection */
147 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
150 case 'l' : /* -l (list options) */
154 num_dests
= cupsGetDests(&dests
);
156 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
161 _cupsLangPuts(stderr
, _("lpoptions: No printers!?!\n"));
168 case 'o' : /* -o option[=value] */
172 num_dests
= cupsGetDests(&dests
);
174 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
177 for (j
= 0; j
< dest
->num_options
; j
++)
178 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
179 num_options
= cupsAddOption(dest
->options
[j
].name
,
180 dest
->options
[j
].value
,
181 num_options
, &options
);
185 num_options
= cupsParseOptions(argv
[i
] + 2, num_options
, &options
);
192 num_options
= cupsParseOptions(argv
[i
], num_options
, &options
);
198 case 'p' : /* -p printer */
200 printer
= argv
[i
] + 2;
210 if ((instance
= strrchr(printer
, '/')) != NULL
)
214 num_dests
= cupsGetDests(&dests
);
216 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) == NULL
)
218 num_dests
= cupsAddDest(printer
, instance
, num_dests
, &dests
);
219 dest
= cupsGetDest(printer
, instance
, num_dests
, dests
);
223 _cupsLangPrintf(stderr
,
224 _("lpoptions: Unable to add printer or "
231 for (j
= 0; j
< dest
->num_options
; j
++)
232 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
233 num_options
= cupsAddOption(dest
->options
[j
].name
,
234 dest
->options
[j
].value
,
235 num_options
, &options
);
238 case 'r' : /* -r option (remove) */
242 num_dests
= cupsGetDests(&dests
);
244 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
247 for (j
= 0; j
< dest
->num_options
; j
++)
248 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
249 num_options
= cupsAddOption(dest
->options
[j
].name
,
250 dest
->options
[j
].value
,
251 num_options
, &options
);
255 option
= argv
[i
] + 2;
265 for (j
= 0; j
< num_options
; j
++)
266 if (!strcasecmp(options
[j
].name
, option
))
269 * Remove this option...
275 memcpy(options
+ j
, options
+ j
+ 1,
276 sizeof(cups_option_t
) * (num_options
- j
));
283 case 'x' : /* -x printer */
285 printer
= argv
[i
] + 2;
295 if ((instance
= strrchr(printer
, '/')) != NULL
)
299 num_dests
= cupsGetDests(&dests
);
301 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) != NULL
)
303 cupsFreeOptions(dest
->num_options
, dest
->options
);
306 * If we are "deleting" the default printer, then just set the
307 * number of options to 0; if it is also the system default
308 * then cupsSetDests() will remove it for us...
311 if (dest
->is_default
)
313 dest
->num_options
= 0;
314 dest
->options
= NULL
;
322 memcpy(dest
, dest
+ 1, (num_dests
- j
) * sizeof(cups_dest_t
));
326 cupsSetDests(num_dests
, dests
);
339 num_dests
= cupsGetDests(&dests
);
343 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
345 for (j
= 0; j
< dest
->num_options
; j
++)
346 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
347 num_options
= cupsAddOption(dest
->options
[j
].name
,
348 dest
->options
[j
].value
,
349 num_options
, &options
);
359 * Set printer options...
362 cupsFreeOptions(dest
->num_options
, dest
->options
);
364 dest
->num_options
= num_options
;
365 dest
->options
= options
;
367 cupsSetDests(num_dests
, dests
);
369 else if (changes
== 0)
371 num_options
= dest
->num_options
;
372 options
= dest
->options
;
374 for (i
= 0; i
< num_options
; i
++)
377 _cupsLangPuts(stdout
, " ");
379 if (!options
[i
].value
[0])
380 _cupsLangPrintf(stdout
, "%s", options
[i
].name
);
381 else if (strchr(options
[i
].value
, ' ') != NULL
||
382 strchr(options
[i
].value
, '\t') != NULL
)
383 _cupsLangPrintf(stdout
, "%s=\'%s\'", options
[i
].name
,
386 _cupsLangPrintf(stdout
, "%s=%s", options
[i
].name
,
390 _cupsLangPuts(stdout
, "\n");
397 * 'list_group()' - List printer-specific options from the PPD group.
401 list_group(ppd_group_t
*group
) /* I - Group to show */
403 int i
, j
; /* Looping vars */
404 ppd_option_t
*option
; /* Current option */
405 ppd_choice_t
*choice
; /* Current choice */
406 ppd_group_t
*subgroup
; /* Current subgroup */
409 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
411 _cupsLangPrintf(stdout
, "%s/%s:", option
->keyword
, option
->text
);
413 for (j
= option
->num_choices
, choice
= option
->choices
; j
> 0; j
--, choice
++)
415 _cupsLangPrintf(stdout
, " *%s", choice
->choice
);
417 _cupsLangPrintf(stdout
, " %s", choice
->choice
);
419 _cupsLangPuts(stdout
, "\n");
422 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
; i
> 0; i
--, subgroup
++)
423 list_group(subgroup
);
428 * 'list_options()' - List printer-specific options from the PPD file.
432 list_options(cups_dest_t
*dest
) /* I - Destination to list */
434 int i
; /* Looping var */
435 const char *filename
; /* PPD filename */
436 ppd_file_t
*ppd
; /* PPD data */
437 ppd_group_t
*group
; /* Current group */
440 if ((filename
= cupsGetPPD(dest
->name
)) == NULL
)
442 _cupsLangPrintf(stderr
,
443 _("lpoptions: Destination %s has no PPD file!\n"),
448 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
451 _cupsLangPrintf(stderr
,
452 _("lpoptions: Unable to open PPD file for %s!\n"),
457 ppdMarkDefaults(ppd
);
458 cupsMarkOptions(ppd
, dest
->num_options
, dest
->options
);
460 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
469 * 'usage()' - Show program usage and exit.
475 _cupsLangPuts(stdout
,
476 _("Usage: lpoptions [-h server] [-E] -d printer\n"
477 " lpoptions [-h server] [-E] [-p printer] -l\n"
478 " lpoptions [-h server] [-E] -p printer -o "
479 "option[=value] ...\n"
480 " lpoptions [-h server] [-E] -x printer\n"));
487 * End of "$Id: lpoptions.c 5833 2006-08-16 20:05:58Z mike $".