home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
350.lha
/
IRA
/
doargs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-04
|
4KB
|
188 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>
#include "limits.h"
/* The input data */
extern double apr ; /* Anual percentage rate (-a) */
extern double bb ; /* Beginning balence (-b) */
extern double ad ; /* Annual Deposit (-d) */
extern long yrs ; /* Years till retirement (-y) */
extern int batch;
char *name;
double atof();
long atol();
extern struct WBStartup *WBenchMsg;
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;
int any = 0;
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,"FILE"))
{
if (*string != '\0')
{
strncpy(filename, string,STRINGMAX-1);
filename[STRINGMAX-1] = '\0';
}
}
if(string = FindToolType(toolArray,"BALANCE"))
{
if (get_float(string,&bb)) any = 1;
}
if(string = FindToolType(toolArray,"INTEREST"))
{
if (get_float(string,&apr)) any = 1;
}
if(string = FindToolType(toolArray,"DEPOSIT"))
{
if (get_float(string,&ad)) any = 1;
}
if(string = FindToolType(toolArray,"YEARS"))
{
yrs = atol(string);
any = 1;
}
FreeDiskObject(diskObj);
}
CloseLibrary(IconBase);
if (any) put_values();
}
}
/*
* scan the CLI arg array for options
*/
getCLIargs(argc,argv)
int argc;
char *argv[];
{
int len,cnt;
int any = 0;
batch = 1;
for (cnt=1; cnt < argc; cnt++)
{
if (argv[cnt][0] != '-') /* If no '-' it is the filename */
{
strncpy(filename, argv[cnt],STRINGMAX-1);
filename[STRINGMAX-1] = '\0';
continue;
}
else
{ switch(argv[cnt][1])
{
case 'a':
apr = atof(&argv[cnt][2]) ;
if ( apr < MINAPR ||
apr > MAXAPR)
fatal("Bad -a value: %s", argv[cnt]) ;
any++;
break ;
case 'b':
bb = atof(&argv[cnt][2]) ;
if (bb < MINBB)
fatal("Bad -b value: %s", argv[cnt]) ;
any++;
break ;
case 'w':
batch = 0;
break ;
case 'd':
ad = atof(&argv[cnt][2]) ;
if (ad < MINAD)
fatal("Bad -d value: %s", argv[cnt]) ;
any++;
break ;
case 'y':
yrs = atol(&argv[cnt][2]) ;
if (yrs < MINYRS)
fatal("Bad -y value: %s", argv[cnt]) ;
any++;
break ;
case '?': /* help option */
printf(" ira [-options]\n");
printf(" IRA Version 2.0 - Calculate Nest-Egg\n");
printf(" Options:\n");
printf(" -ann.n : Anual percentage rate\n");
printf(" -bnnnn.nn : Beginning balence\n");
printf(" -dnnnn.nn : Yearly deposit\n");
printf(" -ynn : Years till retirement\n");
printf(" -w : Put up the window\n");
printf(" -? : display this list.\n");
exit(0);
default:
usage();
}
}
}
if (any) put_values();
}
usage()
{
printf("%s -? for help\n",name);
exit(10);
}
fatal(arg1,arg2)
char * arg1,arg2;
{
fprintf(stderr,arg1,arg2);
usage();
}
#ifdef AZTEC_C
_wb_parse() /* keep aztec's paws off it */
{
}
#endif