* 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 $
- *
****************************************************************/
/*
* Include needed headers
*/
-#include <sys/types.h> /* predefined types */
-#include <sys/stat.h> /* stat deinitiions */
-#include <unistd.h> /* include unix standard library */
-/* */
-#include <stdio.h> /* include standard I/O library */
-#include <stdlib.h> /* include standard library */
-#include <string.h> /* include string library */
-#include <wait.h> /* include wait call */
-#include <fcntl.h>
-#include <assert.h>
-#include <time.h>
+#include <sys/types.h> /* primitive system data types */
+#include <sys/stat.h> /* file characteristics constants and functions */
+#include <unistd.h> /* unix standard library */
+#include <stdio.h> /* standard I/O library */
+#include <stdlib.h> /* C standard library */
+#include <string.h> /* C strings library */
+#include <wait.h> /* process termination constants and functions */
+#include <fcntl.h> /* file control functions */
+#include <assert.h> /* C assertion functions */
+#include <time.h> /* date and time constants, types and functions */
#include"macros.h"
-void WriteMess(char *mess);
-
/* Program begin */
int main(int argc, char *argv[], char *envp[])
/*
* Variables definition
*/
- FILE *file1, *file2, *file3;
- char content[]="Content-type: image/jpeg\n\n";
- /*
- * Begin
- */
- /* write mime-type to stout */
+ 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));
- /* 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 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);
}
-/*
- * Routine to produce an HTML error message on output
- */
-void WriteMess(char *mess)
-{
- printf("Content-type: text/html\n\n");
- perror(mess);
- printf("<br>\n");
-}