Category : C Source Code
Archive   : OPTIONS.ZIP
Filename : OPTDEMO.C

 
Output of file : OPTDEMO.C contained in archive : OPTIONS.ZIP
#include
#include
#define void int

/*********************************************************
*
* demo program
*
* defines 3 options:
* -x, -q and -r
*
* -r takes a command line argument, ie. -r file
*
*********************************************************/


/* declare the functions used in the table */

void func_x();
void func_q();
void func_r();
void usage();

#define NOPTS 3

static OPT demo_table[NOPTS] =
{ {'x', 0, func_x},
{'q', 0, func_q},
{'r', 1, func_r }};

/*
* the program does nothing but call options
*/


main(argc, argv)
int argc;
char *argv[];
{
int i;

options(&argc, &argv, NOPTS, demo_table, usage, "demo");

/* display remaining args */
for(i=1; i printf("arg: %s\n", argv[i]);

exit(0);
}

/*
* this is called to print a "Usage..." message
* the options table is passed as an arg so can print options
* if desired
*/

static usage(n, table, name)
int n;
OPT table[];
char *name;
{
int i;
OPT *t;

printf("Usage: %s -", name);
for(i=0, t=table; i putchar(t->optchar);
if(t->takesarg) putchar('*');
}

putchar('\n');
}


/*
* these are the individual option functions
* ie. what gets called when "-x" is found
*/

static func_x()
{
printf("func X\n");
}

static func_q()
{
printf("func Q\n");
}

static func_r( s )
char *s;
{
printf("func R <%s>\n", s);
}




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