Category : C Source Code
Archive   : E_C_STR.ZIP
Filename : GETOPT.C

 
Output of file : GETOPT.C contained in archive : E_C_STR.ZIP
/* File : getopt.c
Author : Henry Spencer, University of Toronto
Updated: 28 April 1984
Purpose: get option letter from argv.
*/

#include
#include "strings.h"

char *optarg; /* Global argument pointer. */
int optind = 0; /* Global argv index. */

int getopt(argc, argv, optstring)
int argc;
char *argv[];
char *optstring;
{
register int c;
register char *place;
static char *scan = NullS; /* Private scan pointer. */

optarg = NullS;

if (scan == NullS || *scan == '\0') {
if (optind == 0) optind++;
if (optind >= argc) return EOF;
place = argv[optind];
if (place[0] != '-' || place[1] == '\0') return EOF;
optind++;
if (place[1] == '-' && place[2] == '\0') return EOF;
scan = place+1;
}

c = *scan++;
place = index(optstring, c);
if (place == NullS || c == ':') {
fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
return '?';
}
if (*++place == ':') {
if (*scan != '\0') {
optarg = scan, scan = NullS;
} else {
optarg = argv[optind], optind++;
}
}
return c;
}



  3 Responses to “Category : C Source Code
Archive   : E_C_STR.ZIP
Filename : GETOPT.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/