From de47eb59bb829423b1d0f47ba13099073999b3cb Mon Sep 17 00:00:00 2001 From: Nicolas Planel Date: Wed, 29 Oct 2003 16:07:11 +0000 Subject: Corporate Server 2.1.1 release --- mdk-stage1/dietlibc/lib/getopt.c | 155 +++++++++++++-------------------------- 1 file changed, 50 insertions(+), 105 deletions(-) (limited to 'mdk-stage1/dietlibc/lib/getopt.c') diff --git a/mdk-stage1/dietlibc/lib/getopt.c b/mdk-stage1/dietlibc/lib/getopt.c index 93097122f..aa1988f8d 100644 --- a/mdk-stage1/dietlibc/lib/getopt.c +++ b/mdk-stage1/dietlibc/lib/getopt.c @@ -1,118 +1,63 @@ -#include "getopt.h" #include - -/* - * by Olaf Dreesen - */ - -int opterr; - -int optind=1; -char *optarg; - -static int opt_unknown=1,opt_unknown_len; - -static int getopt_check(int c,char*o,int ol) -{ - int i; - if (c==':') return 2; - for (i=0;i + +static void getopterror(int which) { + static char error1[]="Unknown option `-x'.\n"; + static char error2[]="Missing argument for `-x'.\n"; + if (opterr) { + if (which) { + error2[23]=optopt; + write(2,error2,28); + } else { + error1[17]=optopt; + write(2,error1,22); } } - return 2; } -static void getopt_sort(char*v[],int oi) -{ - int i; - char *tmp, *tmp2=0; - - if (opt_unknown_len) - { - tmp=v[optind-(1+oi)]; - if (oi) tmp2=v[optind-1]; - - for (i=opt_unknown+opt_unknown_len;i>opt_unknown;i--) v[i+oi]=v[i-1]; - - v[opt_unknown++]=tmp; - if (oi) v[opt_unknown++]=tmp2; +int getopt(int argc, char * const argv[], const char *optstring) { + static int lastidx=0,lastofs=0; + char *tmp; + if (optind==0) optind=1; /* whoever started setting optind to 0 should be shot */ +again: + if (optind>argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0) + return -1; + if (argv[optind][1]=='-' && argv[optind][2]==0) { + ++optind; + return -1; } -} - -static char* nextchar; -int getopt(int c,char*v[],char*o) -{ - int ol=strlen(o); - int ret=0; - int oi=0; - - optarg=0; - - while (nextchar || (optind