Corretti i commenti ai listati in una forma piu' leggibile (spero).
[gapil.git] / listati / MQFortuneServer.c
index cd0dd1ee430bc203193ec9a3bdfa15cfd77e9f0f..aec0e1eb713d6bf40d555e01ea9966909c0096e8 100644 (file)
@@ -1,26 +1,26 @@
-int msgid;                                       /* Message queue identifier */
+int msgid;          /* Message queue identifier */
 int main(int argc, char *argv[])
 {
 /* Variables definition */
     int i, n = 0;
 int main(int argc, char *argv[])
 {
 /* Variables definition */
     int i, n = 0;
-    char **fortune;                       /* array of fortune message string */
-    char *fortunefilename = "/usr/share/games/fortunes/linux";  /* file name */
-    struct msgbuf_read {      /* message struct to read request from clients */
-        long mtype;                               /* message type, must be 1 */
-        long pid;             /* message data, must be the pid of the client */
+    char **fortune;       /* array of fortune message string */
+    char *fortunefilename = "/usr/share/games/fortunes/linux"; /* file name */
+    struct msgbuf_read {  /* message struct to read request from clients */
+        long mtype;       /* message type, must be 1 */
+        long pid;         /* message data, must be the pid of the client */
     } msg_read;
     } msg_read;
-    struct msgbuf_write {       /* message struct to write result to clients */
-        long mtype;            /* message type, will be the pid of the client*/
-        char mtext[MSGMAX];             /* message data, will be the fortune */
+    struct msgbuf_write { /* message struct to write result to clients */
+        long mtype;       /* message type, will be the pid of the client*/
+        char mtext[MSGMAX]; /* message data, will be the fortune */
     } msg_write;
     } msg_write;
-    key_t key;                                          /* Message queue key */
-    int size;                                                /* message size */
+    key_t key;            /* Message queue key */
+    int size;             /* message size */
     ...
     ...
-    Signal(SIGTERM, HandSIGTERM);            /* set handlers for termination */
+    Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */
     Signal(SIGINT, HandSIGTERM);
     Signal(SIGQUIT, HandSIGTERM);
     Signal(SIGINT, HandSIGTERM);
     Signal(SIGQUIT, HandSIGTERM);
-    if (n==0) usage();          /* if no pool depth exit printing usage info */
-    i = FortuneParse(fortunefilename, fortune, n);          /* parse phrases */
+    if (n==0) usage();    /* if no pool depth exit printing usage info */
+    i = FortuneParse(fortunefilename, fortune, n); /* parse phrases */
     /* Create the queue */
     key = ftok("./MQFortuneServer.c", 1); 
     msgid = msgget(key, IPC_CREAT|0666);
     /* Create the queue */
     key = ftok("./MQFortuneServer.c", 1); 
     msgid = msgget(key, IPC_CREAT|0666);
@@ -32,10 +32,10 @@ int main(int argc, char *argv[])
     daemon(0, 0);
     while (1) {
         msgrcv(msgid, &msg_read, sizeof(int), 1, MSG_NOERROR);
     daemon(0, 0);
     while (1) {
         msgrcv(msgid, &msg_read, sizeof(int), 1, MSG_NOERROR);
-        n = random() % i;                             /* select random value */
+        n = random() % i;             /* select random value */
         strncpy(msg_write.mtext, fortune[n], MSGMAX);
         size = min(strlen(fortune[n])+1, MSGMAX);  
         strncpy(msg_write.mtext, fortune[n], MSGMAX);
         size = min(strlen(fortune[n])+1, MSGMAX);  
-        msg_write.mtype=msg_read.pid;             /* use request pid as type */
+        msg_write.mtype=msg_read.pid; /* use request pid as type */
         msgsnd(msgid, &msg_write, size, 0);
     }
 }
         msgsnd(msgid, &msg_write, size, 0);
     }
 }
@@ -43,6 +43,6 @@ int main(int argc, char *argv[])
  * Signal Handler to manage termination
  */
 void HandSIGTERM(int signo) {
  * Signal Handler to manage termination
  */
 void HandSIGTERM(int signo) {
-    msgctl(msgid, IPC_RMID, NULL);                   /* remove message queue */
+    msgctl(msgid, IPC_RMID, NULL);    /* remove message queue */
     exit(0);
 }
     exit(0);
 }