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

 
Output of file : GETOPT.C contained in archive : MNDL.ZIP
/*
getopt.c -- Turbo C --

Copyright (c) 1986,1987 by Borland International Inc.
All Rights Reserved.
*/
/*
Modified for MS C 3.00 by R. G. Jones, Washington, DC
*/


/* RGJ: Duplicates main file #includes
#include
#include
#include
#include
*/

int optind = 1; /* index of which argument is next */
char *optarg; /* pointer to argument of current option */
int opterr = 1; /* allow error message */

static char *letP = NULL; /* remember next option char's location */
static char SW = 0; /* DOS switch character, either '-' or '/' */



int getopt(int, char **, char *);

int getopt(argc, argv, optionS)
int argc;
char *argv[];
char *optionS;
{
unsigned char ch;
char *optP;

/* get SW using dos call 0x37 */
/*
if (SW == 0) {
_AX = 0x3700;
geninterrupt(0x21);
SW = _DL;
}
*/

if (SW == 0) SW = '/'; /* RGJ: Quick Fix, avoid the problem */

if (argc > optind) {
if (letP == NULL) {
if ((letP = argv[optind]) == NULL ||
*(letP++) != SW) goto gopEOF;
if (*letP == SW) {
optind++; goto gopEOF;
}
}
if (0 == (ch = *(letP++))) {
optind++; goto gopEOF;
}
if (':' == ch || (optP = strchr(optionS, ch)) == NULL)
goto gopError;
if (':' == *(++optP)) {
optind++;
if (0 == *letP) {
if (argc <= optind) goto gopError;
letP = argv[optind++];
}
optarg = letP;
letP = NULL;
} else {
if (0 == *letP) {
optind++;
letP = NULL;
}
optarg = NULL;
}
return ch;
}
gopEOF:
optarg = letP = NULL;
return EOF;

gopError:
optarg = NULL;
errno = EINVAL;
if (opterr)
perror ("get command line option");
return ('?');
}


  3 Responses to “Category : C Source Code
Archive   : MNDL.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/