137
155
static void pqp_buildqueuelist(struct pqprivate *pp)
157
/* FIXME - should use libcups here, if available... */
162
const char *old_lang=getenv("LC_ALL");
163
setenv("LC_ALL","C",1);
142
165
pqp_identifyprintsystem(pp);
143
166
if ((pfile = popen(printsystems[pp->printsystem].scan_command, "r")))
155
178
printernode_create(pp,buf);
182
printernode_create(pp,PRINTERQUEUE_CUSTOMCOMMAND);
183
printernode_create(pp,PRINTERQUEUE_SAVETOFILE);
186
setenv("LC_ALL",old_lang,1);
222
254
free(pq->priv->currentqueue);
223
255
pq->priv->currentqueue=strdup(queue);
257
if(strcmp(queue,PRINTERQUEUE_CUSTOMCOMMAND)==0)
258
pq->priv->mode=PQMODE_CUSTOMCOMMAND;
259
else if(strcmp(queue,PRINTERQUEUE_SAVETOFILE)==0)
260
pq->priv->mode=PQMODE_FILE;
262
pq->priv->mode=PQMODE_COMMAND;
266
static const char *getprinterqueue(struct pqinfo *pq)
268
return(pq->priv->currentqueue);
272
static void setcustomcommand(struct pqinfo *pq,const char *command)
274
if(pq->priv->customcommand)
275
free(pq->priv->customcommand);
277
pq->priv->customcommand=strdup(command);
279
pq->priv->customcommand=NULL;
283
static const char *getcustomcommand(struct pqinfo *pq)
285
return(pq->priv->customcommand);
289
static void setgetfilenamecallback(struct pqinfo *pq,char *(*func)(void *userdata),void *userdata)
291
pq->priv->getfilecallback=func;
292
pq->priv->userdata=userdata;
228
296
static char *getdriver(struct pqinfo *pq)
298
if(strcmp(pq->priv->currentqueue,PRINTERQUEUE_SAVETOFILE)==0)
300
if(strcmp(pq->priv->currentqueue,PRINTERQUEUE_CUSTOMCOMMAND)==0)
230
302
#ifdef HAVE_LIBCUPS
303
fprintf(stderr,"Querying cups for printer driver...\n");
231
304
char *result=NULL;
232
305
const char *ppdname=cupsGetPPD(pq->priv->currentqueue);
300
377
static char *buildprintcommand(struct pqinfo *pq)
302
/* FIXME - need to deduce whether or not to use the RAW flag */
305
380
int len=strlen(printsystems[pq->priv->printsystem].print_command);
306
381
len+=strlen(printsystems[pq->priv->printsystem].queue_select);
328
403
static int initialisejob(struct pqinfo *pq)
405
if(pq->priv->mode==PQMODE_FILE)
409
pq->priv->cancelled=0;
411
if(pq->priv->getfilecallback)
412
fn=pq->priv->getfilecallback(pq->priv->userdata);
417
pq->priv->outputfd=-1;
419
pq->priv->outputfd=open(fn,O_CREAT|O_RDWR,0644);
422
if(pq->priv->outputfd<0)
427
// FIXME - bail out if the customcommand isn't set.
428
if(pq->priv->mode==PQMODE_CUSTOMCOMMAND)
430
if(pq->priv->customcommand)
431
pq->priv->printcommand=strdup(pq->priv->customcommand);
436
pq->priv->printcommand=buildprintcommand(pq);
330
438
fprintf(stderr,"In initialisejob()\n");
331
439
signal(SIGPIPE,&sighandler);
336
444
// Workaroud for now - clear aborted and cancelled flags in the InitialisePage function.
337
445
// Race condition, though - not a permanent fix.
339
pq->priv->printcommand=buildprintcommand(pq);
340
447
fprintf(stderr,"Print command: %s\n",pq->priv->printcommand);
342
449
if(pipe(pq->priv->pipefd))
451
pq->priv->outputfd=pq->priv->pipefd[1];
345
453
pq->priv->childpid=fork();
346
454
if(pq->priv->childpid==-1)
368
477
pq->priv->cancelled=0;
371
481
static void endpage(struct pqinfo *pq)
373
483
fprintf(stderr,"In endpage()\n");
376
487
static void endjob(struct pqinfo *pq)
378
fprintf(stderr,"In endjob()\n");
379
if(pq->priv->cancelled)
381
kill(pq->priv->childpid,SIGTERM);
383
close(pq->priv->pipefd[0]);
384
close(pq->priv->pipefd[1]);
385
free(pq->priv->printcommand);
386
pq->priv->printcommand=NULL;
489
if(pq->priv->mode==PQMODE_FILE)
491
close(pq->priv->outputfd);
495
fprintf(stderr,"In endjob()\n");
496
if(pq->priv->cancelled)
498
kill(pq->priv->childpid,SIGTERM);
500
close(pq->priv->pipefd[0]);
501
close(pq->priv->pipefd[1]);
502
free(pq->priv->printcommand);
503
pq->priv->printcommand=NULL;
397
516
static int writedata(struct pqinfo *pq,const char *data,int bytecount)
399
write(pq->priv->pipefd[1],data,bytecount);
518
write(pq->priv->outputfd,data,bytecount);
400
519
return(1-aborted);
410
529
pq->GetPrinterCount=getprintercount;
411
530
pq->GetPrinterName=getprintername;
412
531
pq->SetPrinterQueue=setprinterqueue;
532
pq->GetPrinterQueue=getprinterqueue;
413
533
pq->GetDriver=getdriver;
414
534
pq->GetPPD=getppd;
415
535
pq->InitialiseJob=initialisejob;