Un po' di materiale su {{{splice}}} e inizio della ripulitura degli
[gapil.git] / sources / FortuneClient.c
index 9d5c54624aa6f223c442eaa0b80a75f32b738654..caf3002d7ee7c06532418e21a2cc57068395af50 100644 (file)
  *
  * Usage: fortune -h give all info
  *
- * $Id: FortuneClient.c,v 1.1 2002/08/18 10:34:09 piccardi Exp $
- *
  ****************************************************************/
 /* 
  * Include needed headers
  */
-#include <sys/types.h>   /* predefined types */
-#include <unistd.h>      /* include unix standard library */
+#include <sys/types.h>   /* primitive system data types */
+#include <unistd.h>      /* unix standard library */
 #include <arpa/inet.h>   /* IP addresses conversion utiliites */
-#include <stdio.h>      /* include standard I/O library */
-#include <errno.h>
-#include <fcntl.h>
+#include <stdio.h>      /* standard I/O library */
+#include <errno.h>>      /* error definitions and routines */
+#include <fcntl.h>       /* file control functions */
 
 #include "macros.h"
 
@@ -87,31 +85,30 @@ int main(int argc, char *argv[])
      *               Main code beginning
      * 
      * ***********************************************************/
-    snprintf(fifoname, 80, "/tmp/fortune.%d", getpid());
-    if (mkfifo(fifoname, 0622)) {
+    snprintf(fifoname, 80, "/tmp/fortune.%d", getpid());     /* compose name */
+    if (mkfifo(fifoname, 0622)) {                        /* open client fifo */
        if (errno!=EEXIST) {
            perror("Cannot create well known fifo");
            exit(-1);
        }
     }
-    fifo_server = open(fortunefilename, O_WRONLY);
+    fifo_server = open(fortunefilename, O_WRONLY);       /* open server fifo */
     if (fifo_server < 0) {
        perror("Cannot open well known fifo");
        exit(-1);
     }
     debug("%s\n", fifoname);
-    nread = write(fifo_server, fifoname, strlen(fifoname)+1);
-    close(fifo_server);
-    fifo_client = open(fifoname, O_RDONLY);
+    nread = write(fifo_server, fifoname, strlen(fifoname)+1);  /* write name */
+    close(fifo_server);                                 /* close server fifo */
+    fifo_client = open(fifoname, O_RDONLY);              /* open client fifo */
     if (fifo_client < 0) {
        perror("Cannot open well known fifo");
        exit(-1);
     }
-    nread = read(fifo_client, buffer, sizeof(buffer));
-    printf("%s", buffer);
-    close(fifo_client);
-    close(fifo_server);
-    unlink(fifoname);
+    nread = read(fifo_client, buffer, sizeof(buffer));        /* read answer */
+    printf("%s", buffer);                                   /* print fortune */
+    close(fifo_client);                                      /* close client */
+    unlink(fifoname);                                  /* remove client fifo */
 }
 /*
  * routine to print usage info and exit