]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/lpoptions.c
2 * "$Id: lpoptions.c 4906 2006-01-10 20:53:28Z 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
, NULL
,
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
, NULL
, _("lpoptions: No printers!?!\n"));
166 case 'o' : /* -o option[=value] */
168 num_options
= cupsParseOptions(argv
[i
] + 2, num_options
, &options
);
175 num_options
= cupsParseOptions(argv
[i
], num_options
, &options
);
181 case 'p' : /* -p printer */
183 printer
= argv
[i
] + 2;
193 if ((instance
= strrchr(printer
, '/')) != NULL
)
197 num_dests
= cupsGetDests(&dests
);
199 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) == NULL
)
201 num_dests
= cupsAddDest(printer
, instance
, num_dests
, &dests
);
202 dest
= cupsGetDest(printer
, instance
, num_dests
, dests
);
206 _cupsLangPrintf(stderr
, NULL
,
207 _("lpoptions: Unable to add printer or "
214 for (j
= 0; j
< dest
->num_options
; j
++)
215 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
216 num_options
= cupsAddOption(dest
->options
[j
].name
,
217 dest
->options
[j
].value
,
218 num_options
, &options
);
221 case 'r' : /* -r option (remove) */
223 option
= argv
[i
] + 2;
233 for (j
= 0; j
< num_options
; j
++)
234 if (strcasecmp(options
[j
].name
, option
) == 0)
237 * Remove this option...
243 memcpy(options
+ j
, options
+ j
+ 1,
244 sizeof(cups_option_t
) * (num_options
- j
));
251 case 'x' : /* -x printer */
253 printer
= argv
[i
] + 2;
263 if ((instance
= strrchr(printer
, '/')) != NULL
)
267 num_dests
= cupsGetDests(&dests
);
269 if ((dest
= cupsGetDest(printer
, instance
, num_dests
, dests
)) != NULL
)
271 cupsFreeOptions(dest
->num_options
, dest
->options
);
274 * If we are "deleting" the default printer, then just set the
275 * number of options to 0; if it is also the system default
276 * then cupsSetDests() will remove it for us...
279 if (dest
->is_default
)
281 dest
->num_options
= 0;
282 dest
->options
= NULL
;
290 memcpy(dest
, dest
+ 1, (num_dests
- j
) * sizeof(cups_dest_t
));
294 cupsSetDests(num_dests
, dests
);
307 num_dests
= cupsGetDests(&dests
);
311 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
313 for (j
= 0; j
< dest
->num_options
; j
++)
314 if (cupsGetOption(dest
->options
[j
].name
, num_options
, options
) == NULL
)
315 num_options
= cupsAddOption(dest
->options
[j
].name
,
316 dest
->options
[j
].value
,
317 num_options
, &options
);
327 * Set printer options...
330 cupsFreeOptions(dest
->num_options
, dest
->options
);
332 dest
->num_options
= num_options
;
333 dest
->options
= options
;
335 cupsSetDests(num_dests
, dests
);
337 else if (changes
== 0)
339 num_options
= dest
->num_options
;
340 options
= dest
->options
;
342 for (i
= 0; i
< num_options
; i
++)
345 _cupsLangPuts(stdout
, NULL
, " ");
347 if (!options
[i
].value
[0])
348 _cupsLangPrintf(stdout
, NULL
, "%s", options
[i
].name
);
349 else if (strchr(options
[i
].value
, ' ') != NULL
||
350 strchr(options
[i
].value
, '\t') != NULL
)
351 _cupsLangPrintf(stdout
, NULL
, "%s=\'%s\'", options
[i
].name
,
354 _cupsLangPrintf(stdout
, NULL
, "%s=%s", options
[i
].name
,
358 _cupsLangPuts(stdout
, NULL
, "\n");
365 * 'list_group()' - List printer-specific options from the PPD group.
369 list_group(ppd_group_t
*group
) /* I - Group to show */
371 int i
, j
; /* Looping vars */
372 ppd_option_t
*option
; /* Current option */
373 ppd_choice_t
*choice
; /* Current choice */
374 ppd_group_t
*subgroup
; /* Current subgroup */
377 for (i
= group
->num_options
, option
= group
->options
; i
> 0; i
--, option
++)
379 _cupsLangPrintf(stdout
, NULL
, "%s/%s:", option
->keyword
, option
->text
);
381 for (j
= option
->num_choices
, choice
= option
->choices
; j
> 0; j
--, choice
++)
383 _cupsLangPrintf(stdout
, NULL
, " *%s", choice
->choice
);
385 _cupsLangPrintf(stdout
, NULL
, " %s", choice
->choice
);
387 _cupsLangPuts(stdout
, NULL
, "\n");
390 for (i
= group
->num_subgroups
, subgroup
= group
->subgroups
; i
> 0; i
--, subgroup
++)
391 list_group(subgroup
);
396 * 'list_options()' - List printer-specific options from the PPD file.
400 list_options(cups_dest_t
*dest
) /* I - Destination to list */
402 int i
; /* Looping var */
403 const char *filename
; /* PPD filename */
404 ppd_file_t
*ppd
; /* PPD data */
405 ppd_group_t
*group
; /* Current group */
408 if ((filename
= cupsGetPPD(dest
->name
)) == NULL
)
410 _cupsLangPrintf(stderr
, NULL
,
411 _("lpoptions: Destination %s has no PPD file!\n"),
416 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
419 _cupsLangPrintf(stderr
, NULL
,
420 _("lpoptions: Unable to open PPD file for %s!\n"),
425 ppdMarkDefaults(ppd
);
426 cupsMarkOptions(ppd
, dest
->num_options
, dest
->options
);
428 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
437 * 'usage()' - Show program usage and exit.
443 _cupsLangPuts(stdout
, NULL
,
444 _("Usage: lpoptions [-h server] [-E] -d printer\n"
445 " lpoptions [-h server] [-E] [-p printer] -l\n"
446 " lpoptions [-h server] [-E] -p printer -o "
447 "option[=value] ...\n"
448 " lpoptions [-h server] [-E] -x printer\n"));
455 * End of "$Id: lpoptions.c 4906 2006-01-10 20:53:28Z mike $".