Varie correzioni, completata revisione capitolo sull'I/O su file
[gapil.git] / listati / BarCode.c
1 int main(int argc, char *argv[], char *envp[])
2 {
3     FILE *pipe[4];
4     FILE *pipein;
5     char *cmd_string[4]={
6         "pnmtopng",
7         "pnmmargin -white 10",
8         "pnmcrop",
9         "gs -sDEVICE=ppmraw -sOutputFile=- -sNOPAUSE -q - -c showpage -c quit"
10     };  
11     char content[]="Content-type: image/png\n\n";
12     int i;
13     /* write mime-type to stdout */ 
14     write(STDOUT_FILENO, content, strlen(content));
15     /* execute chain of command */
16     for (i=0; i<4; i++) {
17         pipe[i] = popen(cmd_string[i], "w");
18         dup2(fileno(pipe[i]), STDOUT_FILENO); 
19     }
20     /* create barcode (in PS) */
21     pipein = popen("barcode", "w");
22     /* send barcode string to barcode program */
23     write(fileno(pipein), argv[1], strlen(argv[1]));
24     /* close all pipes (in reverse order) */
25     for (i=4; i==0; i--) {
26         pclose((pipe[i]));
27     }
28     exit(0);
29 }