X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FBarCode.c;fp=sources%2FBarCode.c;h=a6d1519d35dbf58389a47159ab8e00b1e9c58f08;hp=0000000000000000000000000000000000000000;hb=b1ead1b930038e4f7cd6ee7f737d7ee4699a068c;hpb=d12bc3e1e4b3ee762036d1c226c3b2ba1a720fb9 diff --git a/sources/BarCode.c b/sources/BarCode.c new file mode 100644 index 0000000..a6d1519 --- /dev/null +++ b/sources/BarCode.c @@ -0,0 +1,85 @@ +/* BarCode.c + * + * Copyright (C) 2002 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/**************************************************************** + * + * Program barcode + * CGI for barcode generation + * + * Author: Simone Piccardi + * Jun. 2002 + * + * Usage: cgi-bin for apache. + * Called by downloading something like: + * http://localhost/cgi-bin/barcode?string + * where string is the code to be converted + * + * $Id: BarCode.c,v 1.9 2003/05/02 09:55:13 piccardi Exp $ + * + ****************************************************************/ +/* + * Include needed headers + */ +#include /* predefined types */ +#include /* stat deinitiions */ +#include /* include unix standard library */ +/* */ +#include /* include standard I/O library */ +#include /* include standard library */ +#include /* include string library */ +#include /* include wait call */ +#include +#include +#include + +#include"macros.h" + +/* Program begin */ +int main(int argc, char *argv[], char *envp[]) +{ +/* + * Variables definition + */ + 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 stdout */ + write(STDOUT_FILENO, content, strlen(content)); + /* 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 to barcode program */ + write(fileno(pipein), argv[1], strlen(argv[1])); + pclose(pipein); + /* close all pipes (in reverse order) */ + for (i=4; i==0; i--) { + pclose((pipe[i])); + } + exit(0); +}