/*Copyright (c) 1994 by Matthew Belmonte. Rights and restrictions noted in the accompanying file scanepl.c apply to this file, too.*/ #include char *optarg; int optind=1, opterr; int getopt(argc, argv, optstring) int argc; char **argv; char *optstring; { static int arg_char_count = 1; register char *opt_ptr; if((optind >= argc) || ((arg_char_count == 1) && (argv[optind][0] != '-'))) return(-1); opt_ptr = strchr(optstring++, argv[optind][arg_char_count++]); if(opt_ptr == (char *)0) return(-1); if(opt_ptr[1] == ':') { if(argv[optind][arg_char_count] == '\0') optarg = (optind == argc-1? (char *)0: argv[++optind]); else optarg = argv[optind]+arg_char_count; optind++; arg_char_count = 1; } else { optarg = (char *)0; if(argv[optind][arg_char_count] == '\0') { optind++; arg_char_count = 1; } } return(*opt_ptr); }