/* *options.c *Options for the cribserv * Copyright (C) 2005 Joseph Pingenot 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "options.h" void setup_opts(struct cribserv_options *opts, int argc, char* argv[]) { int c; int p; /*First, set up the defaults*/ opts->port = 32245; while((c = getopt(argc, argv, "hp:")) != -1) { switch(c) { case 'h': printf("ARGS:\n -h\t\tprints this help message\n -p \tPort number to listen to\n"); exit(1); case 'p': if(sscanf(optarg, "%d", &p) != 1) { fprintf(stderr, "ERROR: unable to get port from port argument (-d %s)\n", optarg); exit(2); } /*Set the option*/ opts->port = p; break; default: fprintf(stderr, "ERROR: unknown option -%c\n", c); exit(3); } } }