prout

smaller "lp" command
git clone git://git.2f30.org/prout
Log | Files | Refs | README | LICENSE

commit 015aa305a486ae3a0878e7ba753227b6143fc9d7
parent b4d2e996413139a66e94aa25b1713510abbf6de1
Author: Willy Goiffon <w.goiffon@gmail.com>
Date:   Sun, 20 Oct 2013 22:33:20 +0200

Added a meant to pass options when printing files

Diffstat:
Msrc/prout.c | 37+++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/prout.c b/src/prout.c @@ -22,7 +22,7 @@ /* Usage function */ static void usage() { - fputs("usage: prout [-o opt=value,...] <file>\n", stdout); + fputs("usage: prout [-h] [-o key=val,..] <file>\n", stdout); } /* Return the file name if the file is opennable. exit instead */ @@ -145,20 +145,49 @@ static void check_job (cups_dest_t *dest, int job_id) return; } +/* Parse a string and add options to a cups_dest_t */ +static int get_options(cups_option_t **opt, char *line) +{ + int i, num; + char *token = NULL; + char *key = NULL; + char *val = NULL; + + /* Cut the string with ','. For every match .. */ + for (i=0; (token = strtok(line, ",")) != NULL; i++) { + /* Store the key and the value in a cups_option_t */ + sscanf(token, "%s=%s", key, val); + num = cupsAddOption(key, val, num, opt); + } + + return num; +} + int main(int argc, char **argv) { + int i = 0; int job_id = -1; - - cups_dest_t *dest; + int num_options = 0; char *file; - /* check the input file */ + cups_dest_t *dest; + cups_option_t *opt; + + /* check the given arguments */ if (argc < 2 ) { usage(); exit (1); } + for (i=0; (i+1 < argc) && (argv[i][0] == '-'); i++) { + switch (argv[i][1]) { + case 'o': num_options = get_options(&opt, argv[++i]); break; + case 'h': usage(); exit(0); + default: usage(); exit(1); + } + } + /* check if the file is correct */ file = check_file(argv[1]);