From: Simone Piccardi Date: Fri, 28 Jun 2002 17:59:24 +0000 (+0000) Subject: Versione funzionante di un CGI che produce PNG di codici a barre. X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=commitdiff_plain;h=da8455a295d5e2e237711cd930b7052f1b30ea38;p=gapil.git Versione funzionante di un CGI che produce PNG di codici a barre. --- diff --git a/sources/BarCode.c b/sources/BarCode.c index 44a08da..fbea4ae 100644 --- a/sources/BarCode.c +++ b/sources/BarCode.c @@ -29,7 +29,7 @@ * http://localhost/cgi-bin/barcode?string * where string is the code to be converted * - * $Id: BarCode.c,v 1.3 2002/06/23 22:03:28 piccardi Exp $ + * $Id: BarCode.c,v 1.4 2002/06/28 17:59:24 piccardi Exp $ * ****************************************************************/ /* @@ -57,23 +57,32 @@ int main(int argc, char *argv[], char *envp[]) /* * Variables definition */ - FILE *file1, *file2, *file3; - char content[]="Content-type: image/jpeg\n\n"; - /* - * Begin - */ + FILE *pipe[4]; + FILE *pipein; + char *cmd_string[4]={ + "pnmtopng", + "pnmmargin -white 10", + "pnmcrop", + "gs -sDEVICE=ppmraw -sOutputFile=- -sNOPAUSE -q - -c showpage -c quit" + }; + char content[]="Content-type: image/png\n\n"; + int i; /* 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])); + + /* execute chain of command */ + for (i=0; i<4; i++) { + pipe[i] = popen(cmd_string[i], "w"); + dup2(fileno(pipe[i]), STDOUT_FILENO); + } + /* create barcode (in PS) */ + pipein = popen("barcode", "w"); + /* send barcode string */ + write(fileno(pipein), argv[1], strlen(argv[1])); + /* close all pipes */ + for (i=4; i==0; i--) { + pclose((pipe[i])); + } exit(0); } /*