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 ****************************************************************/
34 * Include needed headers
36 #include <sys/types.h> /* primitive system data types */
37 #include <sys/stat.h> /* file characteristics constants and functions */
38 #include <unistd.h> /* unix standard library */
39 #include <stdio.h> /* standard I/O library */
40 #include <stdlib.h> /* C standard library */
41 #include <string.h> /* C strings library */
42 #include <wait.h> /* process termination constants and functions */
43 #include <fcntl.h> /* file control functions */
44 #include <assert.h> /* C assertion functions */
45 #include <time.h> /* date and time constants, types and functions */
50 int main(int argc, char *argv[], char *envp[])
53 * Variables definition
59 "pnmmargin -white 10",
61 "gs -sDEVICE=ppmraw -sOutputFile=- -sNOPAUSE -q - -c showpage -c quit"
63 char content[]="Content-type: image/png\n\n";
65 /* write mime-type to stdout */
66 write(STDOUT_FILENO, content, strlen(content));
67 /* execute chain of command */
69 pipe[i] = popen(cmd_string[i], "w");
70 dup2(fileno(pipe[i]), STDOUT_FILENO);
72 /* create barcode (in PS) */
73 pipein = popen("barcode", "w");
74 /* send barcode string to barcode program */
75 write(fileno(pipein), argv[1], strlen(argv[1]));
77 /* close all pipes (in reverse order) */
78 for (i=4; i==0; i--) {