From: Simone Piccardi Date: Sat, 10 Aug 2002 14:22:53 +0000 (+0000) Subject: Correzioni alla citazione del codice X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=commitdiff_plain;h=af52f000f3956b58885a317c51faaa57aa543472;p=gapil.git Correzioni alla citazione del codice --- diff --git a/ipc.tex b/ipc.tex index 9d537d4..536d096 100644 --- a/ipc.tex +++ b/ipc.tex @@ -184,7 +184,7 @@ nel file \file{BarCodePage.c} che si trova nella directory dei sorgenti. int main(int argc, char *argv[], char *envp[]) { ... - /* create two pipes to handle process communication */ + /* create two pipes, pipein and pipeout, to handle communication */ if ( (retval = pipe(pipein)) ) { WriteMess("input pipe creation error"); exit(0); @@ -204,14 +204,14 @@ int main(int argc, char *argv[], char *envp[]) dup2(pipein[0], STDIN_FILENO); /* remap stdin to pipe read end */ close(pipeout[0]); dup2(pipeout[1], STDOUT_FILENO); /* remap stdout in pipe output */ - execlp("barcode", "barcode", size, NULL); //"-o", "-", NULL); + execlp("barcode", "barcode", size, NULL); } close(pipein[0]); /* close input side of input pipe */ write(pipein[1], argv[1], strlen(argv[1])); /* write parameter to pipe */ close(pipein[1]); /* closing write end */ waitpid(pid, NULL, 0); /* wait child completion */ /* Second fork: use child to run ghostscript */ - if ( (pid = fork()) == -1) { /* on error exit */ + if ( (pid = fork()) == -1) { WriteMess("child creation error"); exit(0); } @@ -240,7 +240,7 @@ La prima operazione del programma (\texttt{\small 4--12}) le due pipe che serviranno per la comunicazione fra i due comandi utilizzati per produrre il codice a barre; si ha cura di controllare la riuscita della chiamata, inviando in caso di errore un messaggio invece dell'immagine -richiesta.\footnote{la funzione \func{WriteMess}, non è riportata in +richiesta.\footnote{la funzione \func{WriteMess} non è riportata in \secref{fig:ipc_barcodepage_code}; essa si incarica semplicemente di formattare l'uscita alla maniera dei CGI, aggiungendo l'opportuno \textit{mime type}, e formattando il messaggio in HTML, in modo che diff --git a/sources/BarCodePage.c b/sources/BarCodePage.c index ef48ce7..419e9c0 100644 --- a/sources/BarCodePage.c +++ b/sources/BarCodePage.c @@ -1,4 +1,4 @@ -/* BarCodeOld.c +/* BarCodePage.c * * Copyright (C) 2002 Simone Piccardi * @@ -29,7 +29,7 @@ * http://localhost/cgi-bin/barcode?string * where string is the code to be converted * - * $Id: BarCodePage.c,v 1.1 2002/06/30 13:26:17 piccardi Exp $ + * $Id: BarCodePage.c,v 1.2 2002/08/10 14:22:53 piccardi Exp $ * ****************************************************************/ /* @@ -38,7 +38,6 @@ #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 */ @@ -50,7 +49,6 @@ #include"macros.h" void WriteMess(char *mess); - /* Program begin */ int main(int argc, char *argv[], char *envp[]) { @@ -66,7 +64,7 @@ int main(int argc, char *argv[], char *envp[]) /* * Begin */ - /* create two pipes to handle process communication */ + /* create two pipes, pipein and pipeout, to handle communication */ if ( (retval = pipe(pipein)) ) { WriteMess("input pipe creation error"); exit(0); @@ -75,11 +73,10 @@ int main(int argc, char *argv[], char *envp[]) WriteMess("output pipe creation error"); exit(0); } - /* fork child to run barcode program */ - pid = fork(); - if (pid == -1) { + /* First fork: use child to run barcode program */ + if ( (pid = fork()) == -1 ) { WriteMess("child creation error"); - exit(0); + exit(0); } /* if child */ if (pid == 0) { @@ -92,7 +89,7 @@ int main(int argc, char *argv[], char *envp[]) dup2(pipein[0], STDIN_FILENO); /* remap stdin in pipe input */ close(pipeout[0]); dup2(pipeout[1], STDOUT_FILENO); /* remap stdout in pipe output */ - execlp("barcode", "barcode", size, NULL); //"-o", "-", NULL); + execlp("barcode", "barcode", size, NULL); } /* * Parent write string to pipe input and close it, @@ -103,9 +100,8 @@ int main(int argc, char *argv[], char *envp[]) write(pipein[1], argv[1], strlen(argv[1])); close(pipein[1]); waitpid(pid, NULL, 0); - /* Second fork use child to run ghostscript*/ - pid = fork(); - if (pid == -1) { + /* Second fork: use child to run ghostscript*/ + if ( (pid = fork()) == -1) { WriteMess("child creation error"); exit(0); }