home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1992
/
04
/
app.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-05
|
3KB
|
142 lines
// app.cpp RHS 6/7/91
#include<string.h>
#include<dos.h>
#include"app.h"
Application::Application(int argc, char **argv)
{
argcount = argc;
arglist = argv;
SetDefaults();
}
Application::Application(void)
{
argcount = _argc;
arglist = _argv;
SetDefaults();
}
char *Application::GetAppName(void)
{
return arglist[0];
}
void Application::GetAppName(char *buf)
{
strcpy(buf,GetAppName());
}
BOOL Application::GetSwitchArg(char c)
{
if(GetSwitchArg(c,NULL) != NULL)
return TRUE;
return FALSE;
}
char *Application::GetSwitchArg(char c, char *buf)
{
nextarg = 1; // set to search first time
oldc = c; // set char to search for
return _GetSwitchArg(buf); // call search Engine
}
char *Application::GetNextSwitchArg(char *buf)
{
// NOTE: oldc set from previous search call
return _GetSwitchArg(buf); // call search Engine for more of previous
}
char *Application::_GetSwitchArg(char *buf)
{
int i;
register char *s = &switches[0];
register char *s2 = &switches[1];
if(oldc)
{
for( i = nextarg; i < argcount; i++)
if( (*s && (*s == arglist[i][0])) || (*s2 && (*s2 == arglist[i][0])) )
if(arglist[i][1] == oldc)
{
if(buf)
strcpy(buf,&arglist[i][2]);
nextarg = i+1;
return &arglist[i][2];
}
if(buf)
*buf = '\0';
return NULL;
}
else
{
for(i = nextarg; i < argcount; i++)
if( (*s && (*s != arglist[i][0])) && (*s2 && (*s2 != arglist[i][0])) )
{
nextarg = i+1;
return arglist[i];
}
return NULL;
}
}
char *Application::Arg(void)
{
static char count;
oldc = 0;
if(!count)
{
nextarg = 1;
count++;
}
return _GetSwitchArg(NULL);
}
char *Application::GetArg(void)
{
oldc = 0; // no switch search
nextarg = 1; // set for initial search
return _GetSwitchArg(NULL); // call search engine
}
char *Application::GetNextArg(void)
{
oldc = 0; // no switch search
return _GetSwitchArg(NULL); // call search engine
}
void Application::SetSwitchChar(char c)
{
switches[0] = c;
}
void Application::AddSwitchChar(char c)
{
switches[1] = c;
}
char *Application::GetArg(int argno)
{
return arglist[argno+1];
}
int Application::GetArgCount(void)
{
return argcount-1;
}
int Application::GetParamCount(void)
{
return argcount;
}
char *Application::operator[](int argno)
{
return arglist[argno];
}