]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpoptions.c
30d57aa48f24af954c642c637df0003aa3768bb0
2 * "$Id: lpoptions.c 5753 2006-07-18 19:53:24Z 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 */
73 * Loop through the command-line arguments...
83 for (i
= 1; i
< argc
; i
++)
84 if (argv
[i
][0] == '-')
88 case 'd' : /* -d printer */
90 printer
= argv
[i
] + 2;
100 if ((instance
= strrchr(printer
, '/')) != NULL
)
104 num_dests
= cupsGetDests(&dests
);
106 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) == NULL
)
108 _cupsLangPuts(stderr
,
109 _("lpoptions: Unknown printer or class!\n"));
114 * Set the default destination...
117 for (j
= 0; j
< num_dests
; j
++)
118 dests
[j
].is_default
= 0;
120 dest
->is_default
= 1;
122 cupsSetDests(num_dests
, dests
);
124 for (j
= 0; j
< dest
->num_options
; j
++)
125 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
126 num_options
= cupsAddOption(dest
->options
[j
].name
,
127 dest
->options
[j
].value
,
128 num_options
, &options
);
131 case 'h' : /* -h server */
133 cupsSetServer(argv
[i
] + 2);
140 cupsSetServer(argv
[i
]);
144 case 'E' : /* Encrypt connection */
145 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
148 case 'l' : /* -l (list options) */
152 num_dests
= cupsGetDests(&dests
);
154 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
159 _cupsLangPuts(stderr
, _("lpoptions: No printers!?!\n"));
166 case 'o' : /* -o option[=value] */
170 num_dests
= cupsGetDests(&dests
);
172 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
175 for (j
= 0; j
< dest
->num_options
; j
++)
176 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
177 num_options
= cupsAddOption(dest
->options
[j
].name
,
178 dest
->options
[j
].value
,
179 num_options
, &options
);
183 num_options
= cupsParseOptions(argv
[i
] + 2, num_options
, &options
);
190 num_options
= cupsParseOptions(argv
[i
], num_options
, &options
);
196 case 'p' : /* -p printer */
198 printer
= argv
[i
] + 2;
208 if ((instance
= strrchr(printer
, '/')) != NULL
)
212 num_dests
= cupsGetDests(&dests
);
214 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) == NULL
)
216 num_dests
= cupsAddDest(printer
, instance
, num_dests
, &dests
);
217 dest
= cupsGetDest(printer
, instance
, num_dests
, dests
);
221 _cupsLangPrintf(stderr
,
222 _("lpoptions: Unable to add printer or "
229 for (j
= 0; j
< dest
->num_options
; j
++)
230 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
231 num_options
= cupsAddOption(dest
->options
[j
].name
,
232 dest
->options
[j
].value
,
233 num_options
, &options
);
236 case 'r' : /* -r option (remove) */
240 num_dests
= cupsGetDests(&dests
);
242 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
245 for (j
= 0; j
< dest
->num_options
; j
++)
246 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
247 num_options
= cupsAddOption(dest
->options
[j
].name
,
248 dest
->options
[j
].value
,
249 num_options
, &options
);
253 option
= argv
[i
] + 2;
263 for (j
= 0; j
< num_options
; j
++)
264 if (!strcasecmp(options
[j
].name
, option
))
267 * Remove this option...
273 memcpy(options
+ j
, options
+ j
+ 1,
274 sizeof(cups_option_t
) * (num_options
- j
));
281 case 'x' : /* -x printer */
283 printer
= argv
[i
] + 2;
293 if ((instance
= strrchr(printer
, '/')) != NULL
)
297 num_dests
= cupsGetDests(&dests
);
299 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) != NULL
)
301 cupsFreeOptions(dest
->num_options
, dest
->options
);
304 * If we are "deleting" the default printer, then just set the
305 * number of options to 0; if it is also the system default
306 * then cupsSetDests() will remove it for us...
309 if (dest
->is_default
)
311 dest
->num_options
= 0;
312 dest
->options
= NULL
;
320 memcpy(dest
, dest
+ 1, (num_dests
- j
) * sizeof(cups_dest_t
));
324 cupsSetDests(num_dests
, dests
);
337 num_dests
= cupsGetDests(&dests
);
341 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
343 for (j
= 0; j
< dest
->num_options
; j
++)
344 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
345 num_options
= cupsAddOption(dest
->options
[j
].name
,
346 dest
->options
[j
].value
,
347 num_options
, &options
);
357 * Set printer options...
360 cupsFreeOptions(dest
->num_options
, dest
->options
);
362 dest
->num_options
= num_options
;
363 dest
->options
= options
;
365 cupsSetDests(num_dests
, dests
);
367 else if (changes
== 0)
369 num_options
= dest
->num_options
;
370 options
= dest
->options
;
372 for (i
= 0; i
< num_options
; i
++)
375 _cupsLangPuts(stdout
, " ");
377 if (!options
[i
].value
[0])
378 _cupsLangPrintf(stdout
, "%s", options
[i
].name
);
379 else if (strchr(options
[i
].value
, ' ') != NULL
||
380 strchr(options
[i
].value
, '\t') != NULL
)
381 _cupsLangPrintf(stdout
, "%s=\'%s\'", options
[i
].name
,
384 _cupsLangPrintf(stdout
, "%s=%s", options
[i
].name
,
388 _cupsLangPuts(stdout
, "\n");
395 * 'list_group()' - List printer-specific options from the PPD group.
399 list_group(ppd_group_t
*group
) /* I - Group to show */
401 int i
, j
; /* Looping vars */
402 ppd_option_t
*option
; /* Current option */
403 ppd_choice_t
*choice
; /* Current choice */
404 ppd_group_t
*subgroup
; /* Current subgroup */
407 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
409 _cupsLangPrintf(stdout
, "%s/%s:", option
->keyword
, option
->text
);
411 for (j
= option
->num_choices
, choice
= option
->choices
; j
> 0; j
--, choice
++)
413 _cupsLangPrintf(stdout
, " *%s", choice
->choice
);
415 _cupsLangPrintf(stdout
, " %s", choice
->choice
);
417 _cupsLangPuts(stdout
, "\n");
420 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
; i
> 0; i
--, subgroup
++)
421 list_group(subgroup
);
426 * 'list_options()' - List printer-specific options from the PPD file.
430 list_options(cups_dest_t
*dest
) /* I - Destination to list */
432 int i
; /* Looping var */
433 const char *filename
; /* PPD filename */
434 ppd_file_t
*ppd
; /* PPD data */
435 ppd_group_t
*group
; /* Current group */
438 if ((filename
= cupsGetPPD(dest
->name
)) == NULL
)
440 _cupsLangPrintf(stderr
,
441 _("lpoptions: Destination %s has no PPD file!\n"),
446 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
449 _cupsLangPrintf(stderr
,
450 _("lpoptions: Unable to open PPD file for %s!\n"),
455 ppdMarkDefaults(ppd
);
456 cupsMarkOptions(ppd
, dest
->num_options
, dest
->options
);
458 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
467 * 'usage()' - Show program usage and exit.
473 _cupsLangPuts(stdout
,
474 _("Usage: lpoptions [-h server] [-E] -d printer\n"
475 " lpoptions [-h server] [-E] [-p printer] -l\n"
476 " lpoptions [-h server] [-E] -p printer -o "
477 "option[=value] ...\n"
478 " lpoptions [-h server] [-E] -x printer\n"));
485 * End of "$Id: lpoptions.c 5753 2006-07-18 19:53:24Z mike $".