home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff304.lzh
/
Gears
/
doargs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-10
|
3KB
|
145 lines
/*
*
* do_args.c - Argument processing - WB or CLI
*
*/
#include <exec/types.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>
#include <workbench/startup.h>
#include <stdio.h>
#define DIAMETERMAX 1000
#define DIAMETERDEF 27
#define STRINGMAX 100
extern struct WBStartup *WBenchMsg;
extern struct Gadget inmm_Gad;
extern char title[];
extern long diameter;
char filename[STRINGMAX];
char title[STRINGMAX]; /* Window title */
char *myname;
void *OpenLibrary();
struct IconBase *IconBase;
long atol();
/*
* General purpose Workbench argument processing subroutine.
* It retrieves arguments from the icon ToolTypes array.
*/
getWBargs()
{
struct WBArg *wbArg;
char **toolArray;
char *string;
struct DiskObject *diskObj;
if(IconBase = (struct IconBase *) OpenLibrary("icon.library",0L))
{
wbArg = WBenchMsg->sm_ArgList;
diskObj = (struct DiskObject *)GetDiskObject(wbArg->wa_Name);
if(diskObj)
{
toolArray = diskObj->do_ToolTypes;
if(string = FindToolType(toolArray,"DIAMETER"))
{
diameter = atol(string);
if (diameter <0 || diameter >DIAMETERMAX) diameter = DIAMETERDEF;
}
if(string = FindToolType(toolArray,"TITLE"))
{
if (*string != '\0')
{
strncpy(title, string,STRINGMAX-1);
title[STRINGMAX-1] = '\0';
}
}
if(string = FindToolType(toolArray,"FILE"))
{
if (*string != '\0')
{
strncpy(filename, string,STRINGMAX-1);
filename[STRINGMAX-1] = '\0';
}
}
if(string = FindToolType(toolArray,"MM"))
{
inmm_Gad.Flags |= SELECTED;
}
if(string = FindToolType(toolArray,"INCHES"))
{
inmm_Gad.Flags &= ~SELECTED;
}
FreeDiskObject(diskObj);
}
CloseLibrary(IconBase);
}
}
getCLIargs(argc,argv)
int argc;
char *argv[];
{
register char *p;
/* get command name */
myname = (argc-- < 1) ? "skel" : *argv++;
while (argc > 0)
{
argc--; /* One fewer to process */
p = *argv++; /* Get arg pointer and bump to next */
if (*p != '-') /* If no '-' it is the filename */
{
strncpy(filename, p,STRINGMAX-1);
filename[STRINGMAX-1] = '\0';
continue;
}
p++;
switch (*p) {
case 't': /* Title */
strncpy(title, ++p,STRINGMAX-1);
title[sizeof(title)-1] = '\0';
break;
case 'd': /* wheel diameter in . */
diameter = atoi(++p);
if (diameter <0 || diameter >DIAMETERMAX) diameter = DIAMETERDEF;
break;
case 'm':
inmm_Gad.Flags |= SELECTED;
break;
case 'i':
inmm_Gad.Flags &= ~SELECTED;
break;
default: /* Wrong option */
usage();
done(14);
}
}
}
usage()
{
fprintf(stderr,"Bicycle Gear Calculator\n");
fprintf(stderr,"Usage:%s: -d# -i -m filename file\n",myname);
fprintf(stderr,"-d# wheel diameter in inches or milimeters\n");
fprintf(stderr,"-i inches\n");
fprintf(stderr,"-m millimeters\n");
fprintf(stderr,"filename gearset file to load\n");
}
#ifdef AZTEC_C
_wb_parse() /* keep aztec's paws off it */
{
}
#endif