X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FFortuneServer.c;h=4cb65cac20e3fea98cff688b0b0e5e9ab0f3ce86;hp=c00b3fedf5a80ca33d6de56dbb3652bd97b8132c;hb=fa15a3f1ecd64efd8440e46d398fd9976abc3d25;hpb=198add70c8604fe7ffb05689aa693d782102917e diff --git a/sources/FortuneServer.c b/sources/FortuneServer.c index c00b3fe..4cb65ca 100644 --- a/sources/FortuneServer.c +++ b/sources/FortuneServer.c @@ -26,34 +26,35 @@ * * Usage: fortuned -h give all info * - * $Id: FortuneServer.c,v 1.1 2002/08/18 10:34:10 piccardi Exp $ - * ****************************************************************/ /* * Include needed headers */ -#include /* predefined types */ -#include /* */ -#include /* include unix standard library */ -#include /* include standard I/O library */ -#include /* standard library */ -#include /* ANSI C standard string */ -#include /* errorstring */ -#include /* */ +#include /* primitive system data types */ +#include /* file characteristics constants and functions */ +#include /* unix standard library */ +#include /* standard I/O library */ +#include /* C standard library */ +#include /* C strings library */ +#include /* error definitions and routines */ +#include /* signal constants, types and functions */ +#include /* file control functions */ #include "macros.h" +#include "Gapil.h" /* Subroutines declaration */ void usage(void); +void HandSIGTERM(int signo); int FortuneParse(char *file, char **fortune, int n); +/* name of well known fifo */ +char *fifoname = "/tmp/fortune.fifo"; int main(int argc, char *argv[]) { /* Variables definition */ - int n = 0; - FILE *fortunefile; - char *fortunefilename = "/usr/share/misc/fortune/fortune.it"; - char *fifoname = "/tmp/fortune.fifo"; + int i, n = 0; + char *fortunefilename = "/usr/share/games/fortunes/linux"; char **fortune; char line[80]; int fifo_server, fifo_client; @@ -62,8 +63,7 @@ int main(int argc, char *argv[]) * Input section: decode parameters passed in the calling * Use getopt function */ - int i; - opterr = 0; /* don't want writing to stderr */ + opterr = 0; /* don't want writing to stderr */ while ( (i = getopt(argc, argv, "hn:f:")) != -1) { switch (i) { /* @@ -81,10 +81,10 @@ int main(int argc, char *argv[]) n = strtol(optarg, NULL, 10); fortune = (char **) calloc(sizeof(*fortune), n); break; - case '?': /* unrecognized options */ + case '?': /* unrecognized options */ printf("Unrecognized options -%c\n",optopt); usage(); - default: /* should not reached */ + default: /* should not reached */ usage(); } } @@ -95,36 +95,54 @@ int main(int argc, char *argv[]) * Main code beginning * * ***********************************************************/ - if (n==0) { /* if no pool depth exit */ - usage(); /* print usage info */ - } - i = FortuneParse(fortunefilename, fortune, n); - for (n=0; n