3 * Copyright (C) 2002 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
22 * CGI for barcode generation
24 * Author: Simone Piccardi
27 * Usage: cgi-bin for apache.
28 * Called by downloading something like:
29 * http://localhost/cgi-bin/barcode?string
30 * where string is the code to be converted
32 * $Id: BarCode.c,v 1.9 2003/05/02 09:55:13 piccardi Exp $
34 ****************************************************************/
36 * Include needed headers
38 #include <sys/types.h> /* predefined types */
39 #include <sys/stat.h> /* stat deinitiions */
40 #include <unistd.h> /* include unix standard library */
42 #include <stdio.h> /* include standard I/O library */
43 #include <stdlib.h> /* include standard library */
44 #include <string.h> /* include string library */
45 #include <wait.h> /* include wait call */
53 int main(int argc, char *argv[], char *envp[])
56 * Variables definition
62 "pnmmargin -white 10",
64 "gs -sDEVICE=ppmraw -sOutputFile=- -sNOPAUSE -q - -c showpage -c quit"
66 char content[]="Content-type: image/png\n\n";
68 /* write mime-type to stdout */
69 write(STDOUT_FILENO, content, strlen(content));
70 /* execute chain of command */
72 pipe[i] = popen(cmd_string[i], "w");
73 dup2(fileno(pipe[i]), STDOUT_FILENO);
75 /* create barcode (in PS) */
76 pipein = popen("barcode", "w");
77 /* send barcode string to barcode program */
78 write(fileno(pipein), argv[1], strlen(argv[1]));
80 /* close all pipes (in reverse order) */
81 for (i=4; i==0; i--) {