X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FFortuneServer.c;fp=sources%2FFortuneServer.c;h=c00b3fedf5a80ca33d6de56dbb3652bd97b8132c;hp=0000000000000000000000000000000000000000;hb=198add70c8604fe7ffb05689aa693d782102917e;hpb=5099573b0239402d8860e2c0af07c8eb3378b865 diff --git a/sources/FortuneServer.c b/sources/FortuneServer.c new file mode 100644 index 0000000..c00b3fe --- /dev/null +++ b/sources/FortuneServer.c @@ -0,0 +1,140 @@ +/* FortuneServer.c + * + * Copyright (C) 2002 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/**************************************************************** + * + * Program fortuned + * Fortune server + * + * Author: Simone Piccardi + * Aug. 2002 + * + * 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 "macros.h" + +/* Subroutines declaration */ +void usage(void); +int FortuneParse(char *file, char **fortune, int n); + +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"; + char **fortune; + char line[80]; + int fifo_server, fifo_client; + int nread; + /* + * Input section: decode parameters passed in the calling + * Use getopt function + */ + int i; + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "hn:f:")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': + printf("Wrong -h option use\n"); + usage(); + return(0); + break; + case 'f': + fortunefilename = optarg; + break; + case 'n': + n = strtol(optarg, NULL, 10); + fortune = (char **) calloc(sizeof(*fortune), n); + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + if (n==0) { /* if no pool depth exit */ + usage(); /* print usage info */ + } + i = FortuneParse(fortunefilename, fortune, n); + for (n=0; n