X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FBarCode.c;h=44a08dab1a0924c7296cf20bbcf9bd686353b80b;hp=138e23ab5d3908538afeccfaea03d2018d13211b;hb=9790ea16d447835b894169fa997314fd5fb0ebd5;hpb=1f3175061ada629be8bf1a8aa819ed0ed5f9cd3f diff --git a/sources/BarCode.c b/sources/BarCode.c index 138e23a..44a08da 100644 --- a/sources/BarCode.c +++ b/sources/BarCode.c @@ -18,7 +18,7 @@ */ /**************************************************************** * - * Program echod + * Program barcode * CGI for barcode generation * * Author: Simone Piccardi @@ -29,7 +29,7 @@ * http://localhost/cgi-bin/barcode?string * where string is the code to be converted * - * $Id: BarCode.c,v 1.1 2002/06/18 22:11:06 piccardi Exp $ + * $Id: BarCode.c,v 1.3 2002/06/23 22:03:28 piccardi Exp $ * ****************************************************************/ /* @@ -57,81 +57,23 @@ int main(int argc, char *argv[], char *envp[]) /* * Variables definition */ - char buffer[8192]; - pid_t pid; - size_t n; - int retval; - int pipein[2]; - int pipeout[2]; - char size[]="-pA9"; - char psize[]="-sPAPERSIZE=a9"; + FILE *file1, *file2, *file3; char content[]="Content-type: image/jpeg\n\n"; /* * Begin */ - /* create two pipes to handle process communication */ - if ( (retval = pipe(pipein)) ) { - WriteMess("input pipe creation error"); - exit(0); - } - if ( (retval = pipe(pipeout)) ) { - WriteMess("output pipe creation error"); - exit(0); - } - /* fork child to run barcode program */ - pid = fork(); - if (pid == -1) { - WriteMess("child creation error"); - exit(0); - } - /* if child */ - if (pid == 0) { - /* - * Child exec barcode program, that take input (string to encode) - * from pipein, remapped to stdin, and write the output (a ppm - * image) to stdout, remapped to pipeout - */ - close(pipein[1]); /* close output side of input pipe */ - dup2(pipein[0], STDIN_FILENO); /* remap stdin in pipe input */ - close(pipeout[0]); - dup2(pipeout[1], STDOUT_FILENO); /* remap stdout in pipe output */ - execlp("barcode", "barcode", size, NULL); //"-o", "-", NULL); - } - /* - * Parent write string to pipe input and close it, - * then wait child execution and results form pipeout, - * then fork to convert ppm to gif using ppmtogif - */ - close(pipein[0]); /* close input side of input pipe */ - n=write(pipein[1], argv[1], strlen(argv[1])); - close(pipein[1]); - waitpid(pid, NULL, 0); - /* - * refork to use ppmtogif - */ - pid = fork(); - if (pid == -1) { - WriteMess("child creation error"); - exit(0); - } - /* - * second child, convert ppm to gif - */ - if (pid == 0) { - /* send mime type */ - close(pipeout[1]); - dup2(pipeout[0], STDIN_FILENO); - write(STDOUT_FILENO, content, strlen(content)); - n=read(pipeout[0], buffer, sizeof(buffer)); - printf("Letti %n di %n, %s\n", n, sizeof(buffer), buffer); - exit(0); - execlp("gs", "gs", "-q", "-sDEVICE=jpeg", "-sOutputFile=-", "-", NULL); - } - /* - * still parent - */ - close(pipeout[1]); - waitpid(pid, NULL, 0); + /* write mime-type to stout */ + write(STDOUT_FILENO, content, strlen(content)); + /* convert PDF to JPEG */ + file1 = popen("gs -q -sDEVICE=jpeg -sOutputFile=- -", "w"); + /* convert EPS to PDF*/ + dup2(fileno(file1), STDOUT_FILENO); /* set epstopdf stdout to file1 */ + file2 = popen("epstopdf --filter", "w"); +// file2 = popen("eps2eps", "w"); + /* create barcode */ + dup2(fileno(file2), STDOUT_FILENO); /* set barcode stdout to file2 */ + file3 = popen("barcode -E", "w"); + write(fileno(file3), argv[1], strlen(argv[1])); exit(0); } /*