diff options
author | msweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2009-01-29 18:07:00 +0000 |
---|---|---|
committer | msweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2009-01-29 18:07:00 +0000 |
commit | dfd5680b8770f4dd462a90a7a6579aa9523e484f (patch) | |
tree | 7b73e21339610b1c0be8f975244256bd39b41263 /cups/testcups.c | |
parent | d1c13e168660dfc384ead2efe29eb20a7abc5950 (diff) | |
download | cups-dfd5680b8770f4dd462a90a7a6579aa9523e484f.tar.gz |
Merge changes from CUPS 1.4svn-r8305.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@1166 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups/testcups.c')
-rw-r--r-- | cups/testcups.c | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/cups/testcups.c b/cups/testcups.c index 834e08a90..555df69a5 100644 --- a/cups/testcups.c +++ b/cups/testcups.c @@ -3,7 +3,7 @@ * * CUPS API test program for the Common UNIX Printing System (CUPS). * - * Copyright 2007-2008 by Apple Inc. + * Copyright 2007-2009 by Apple Inc. * Copyright 2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -27,6 +27,8 @@ #include <stdio.h> #include <stdlib.h> #include "cups.h" +#include "string.h" +#include <errno.h> /* @@ -57,6 +59,74 @@ main(int argc, /* I - Number of command-line arguments */ cups_job_t *jobs; /* Jobs for queue */ + if (argc > 1) + { + /* + * ./testcups printer file interval + */ + + int interval, /* Interval between writes */ + job_id; /* Job ID */ + cups_file_t *fp; /* Print file */ + char buffer[16384]; /* Read/write buffer */ + ssize_t bytes; /* Bytes read/written */ + + + if (argc != 4) + { + puts("Usage: ./testcups"); + puts(" ./testcups printer file interval"); + return (1); + } + + if ((fp = cupsFileOpen(argv[2], "r")) == NULL) + { + printf("Unable to open \"%s\": %s\n", argv[2], strerror(errno)); + return (1); + } + + if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, argv[1], "testcups", 0, + NULL)) <= 0) + { + printf("Unable to create print job on %s: %s\n", argv[1], + cupsLastErrorString()); + return (1); + } + + interval = atoi(argv[3]); + + if (cupsStartDocument(CUPS_HTTP_DEFAULT, argv[1], job_id, argv[2], + CUPS_FORMAT_AUTO, 1) != HTTP_CONTINUE) + { + puts("Unable to start document!"); + return (1); + } + + while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0) + { + printf("Writing %d bytes...\n", (int)bytes); + + if (cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, + bytes) != HTTP_CONTINUE) + { + puts("Unable to write bytes!"); + return (1); + } + + sleep(interval); + } + + cupsFileClose(fp); + + if (cupsFinishDocument(CUPS_HTTP_DEFAULT, argv[1]) != HTTP_OK) + { + puts("Unable to finish document!"); + return (1); + } + + return (0); + } + /* * cupsGetDests() */ |