prout

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

commit d850021c09eca08676c06c0ec5ec9b977b546671
parent 29e9c5ae17148c2569f3a5c7119157df2819a17d
Author: Willy Goiffon <willy@mailoo.org>
Date:   Wed, 18 Dec 2013 08:42:45 +0100

Made the printing non-blocking

Diffstat:
Msrc/prout.c | 78++++++++++++++++++++++++++++++++++--------------------------------------------
1 file changed, 34 insertions(+), 44 deletions(-)

diff --git a/src/prout.c b/src/prout.c @@ -94,52 +94,42 @@ static void check_job (cups_dest_t *dest, int job_id) ipp_jstate_t state = IPP_JOB_PENDING; - while (state < IPP_JOB_STOPPED) { - /* GET ALL THE JOBS "\_(°D°)/ */ - num_jobs = cupsGetJobs(&jobs, dest->name, 1, CUPS_WHICHJOBS_ALL); - - /* Find MY job id */ - for (i = 0; i < num_jobs; i++) { - if (jobs[i].id == job_id) { - state = jobs[i].state; - break; - } + /* GET ALL THE JOBS "\_(°D°)/ */ + num_jobs = cupsGetJobs(&jobs, dest->name, 1, CUPS_WHICHJOBS_ALL); + + /* Find MY job id */ + for (i = 0; i < num_jobs; i++) { + if (jobs[i].id == job_id) { + state = jobs[i].state; + break; } + } - /* Free the job array */ - cupsFreeJobs(num_jobs, jobs); - - switch (state) { - case IPP_JOB_PENDING : - fprintf(stdout, "\rjob %d pending.", job_id); - break; - case IPP_JOB_HELD : - fprintf(stdout, "\rjob %d held.", job_id); - break; - case IPP_JOB_PROCESSING : - fprintf(stdout, "\rjob %d processing.", job_id); - break; - case IPP_JOB_STOPPED : - fprintf(stdout, "\rjob %d stopped.", job_id); - break; - case IPP_JOB_CANCELED : - fprintf(stdout, "\rjob %d canceled.", job_id); - break; - case IPP_JOB_ABORTED : - fprintf(stdout, "\rjob %d aborted.", job_id); - break; - case IPP_JOB_COMPLETED : - fprintf(stdout, "\rjob %d completed.\n", job_id); - break; - } - - /* Actually print text to stdout */ - fflush(stdout); - - /* Wait just a second if the job is not finished */ - if (state < IPP_JOB_STOPPED) { - sleep(1); - } + /* Free the job array */ + cupsFreeJobs(num_jobs, jobs); + + switch (state) { + case IPP_JOB_PENDING : + fprintf(stdout, "job %d pending.\n", job_id); + break; + case IPP_JOB_HELD : + fprintf(stdout, "job %d held.\n", job_id); + break; + case IPP_JOB_PROCESSING : + fprintf(stdout, "job %d processing.\n", job_id); + break; + case IPP_JOB_STOPPED : + fprintf(stdout, "job %d stopped.\n", job_id); + break; + case IPP_JOB_CANCELED : + fprintf(stdout, "job %d canceled.\n", job_id); + break; + case IPP_JOB_ABORTED : + fprintf(stdout, "job %d aborted.\n", job_id); + break; + case IPP_JOB_COMPLETED : + fprintf(stdout, "job %d completed.\n", job_id); + break; } return;