X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=trunk%2Fsrc%2Fmy_getopt.c;fp=trunk%2Fsrc%2Fmy_getopt.c;h=0000000000000000000000000000000000000000;hb=4a2a65ece88edbfdfda338e263370f292e311228;hp=d0a9fd75714350f99da6302d4f9738b511f49a8f;hpb=85718e4dcaf5f34496f629e45a47ec91145c6f9e;p=iptables.git diff --git a/trunk/src/my_getopt.c b/trunk/src/my_getopt.c deleted file mode 100644 index d0a9fd7..0000000 --- a/trunk/src/my_getopt.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - Copyright (C) Slava Astashonok - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License. - - $Id: my_getopt.c,v 1.2.2.3 2004/02/02 08:06:24 sla Exp $ -*/ - -#include - -/* getopt() */ -#include - -/* fprintf() */ -#include - -#include - -extern char *optarg; -extern int optind, opterr, optopt; - -int my_getopt(int argc, char * const argv[], - struct getopt_parms parms[]) -{ - int c, i, p; - static int flag = 0, my_opterr = 1; - static char optstring[MY_GETOPT_MAX_OPTSTR]; - - if (flag++ == 0) { - p = 0; i = 0; - while ((parms[i].name != 0) && (p < (MY_GETOPT_MAX_OPTSTR - 1))) { - optstring[p++] = parms[i].name; - if (parms[i].flag & MY_GETOPT_ARG_REQUIRED) optstring[p++] = ':'; - optstring[p] = 0; - i++; - } - flag = 1; - } - - c = getopt(argc, argv, optstring); - switch (c) { - case '?': - if (my_opterr) fprintf(stderr, "Wrong parameters\n"); - break; - - case -1: - flag = 0; - i = 0; - while (parms[i].name != 0) { - if ((parms[i].flag & MY_GETOPT_REQUIRED) && (parms[i].count == 0)) { - if (my_opterr) fprintf(stderr, "Missing required option\n"); - return '?'; - } - i++; - } - break; - - default: - i = 0; - while ((parms[i].name != 0) && (parms[i].name != c)) { - i++; - } - if (parms[i].flag & MY_GETOPT_ARG_REQUIRED) { - if (optarg == 0) { - if (my_opterr) fprintf(stderr, "Option `-%c': %s\n", - c, "require parameter"); - return '?'; - } else parms[i].arg = optarg; - } - if ((++parms[i].count > 1) && !(parms[i].flag & MY_GETOPT_ALLOW_REPEAT)) { - if (my_opterr) fprintf(stderr, "Option `-%c': %s\n", - c, "repeat not allowed"); - return '?'; - } - break; - } - return c; -}