#include #include extern char *optarg; extern int optind,opterr; static char theString[256]; char *optarg=(char*) theString; int optind=1,opterr=1; char getopt( int argc, char *argv[], char *format ) { char theOption; char *p; if ( argv[optind]==NULL ) return EOF; if ( argv[optind][0]=='-' ) { if ( argv[optind][1]==0x00 ) return '?'; if ( (p=strchr( format, ( int )argv[optind][1]))==NULL ) { if( opterr != 0 ) fprintf(stderr,"%s:\tillegal option -- %c\n",argv[0],argv[optind][1]); fflush(stderr); optind++; return '?'; } if ( *(p+1) == ':' ) { optind++; if (argv[optind]==NULL) { if( opterr != 0 ) fprintf(stderr,"%s:\toption requires an argument -- %c\n", argv[0],argv[optind-1][1]); fflush(stderr); return EOF; } else { strcpy(optarg,argv[optind]); } } optind++; return(*p); } else return EOF; }