home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
203_01
/
yam1.c
< prev
next >
Wrap
Text File
|
1979-12-31
|
16KB
|
824 lines
/*
$title ('yam1.c: Main program,command sequencer')
$date (17 nov 85)
*/
#include "yam.h"
#include <ctype.h>
#define MAXARGS 20
/****************************************************************************
FUNCTION:
main program and command line parser.
CALLING PARAMETERS:
argc:
count of command line arguments.
argv:
pointer to string of command line arguments.
===========================================================================*/
main(argc, argv)
char *argv[];
int argc;
{
int c;
char *args[MAXARGS],
**argp,
*nextcmd;
/* initialization */
nextcmd=NULL;
onceonly();
/* init parmams and signon */
init();
/* read command line arguments */
if(argc>MAXARGS)
goto usage;
/* copy given arguments to our own array */
for (c = 0; c < argc; c++)
args[c] = argv[c];
for(;;)
{
if(argc < 2)
{
if(nextcmd)
cp=nextcmd;
else
{
#ifdef XMODEM
printf("\nxYAM(%c)", defdisk+'A');
#else
printf("\n>>>%c:", defdisk+'a');
#endif
gets(cmdbuf);
cp=cmdbuf;
#ifdef SYSFUNC
if(*cp=='!')
{
system(++cp);
continue;
}
#endif
}
if(nextcmd=index(';', cp))
*nextcmd++ =0; /* ; separates commands */
/* init arg pointer, arg count */
argp = &args[1];
argc = 1;
while(1)
{
/* printable char means vaild argument */
if(isgraph(*cp))
{
*argp++ = cp;
argc++;
/* skip to next arg */
while(isgraph(*cp))
cp++;
}
/* skip white space and change to string terminator */
while(*cp==' ' || *cp=='\t')
*cp++ =0;
/* found another printable, get next arg */
if(isgraph(*cp))
continue;
/* end of argument list */
*cp=0;
break;
}
}
/* loop thru all parmaters */
for(argp = &args[1]; --argc>0; )
{
uncaps(*argp);
cp = *argp++;
/* reset mode flags to default. They may have been set
by parms in s or r command */
Gototerm=Batch=Crcflg=Creamfile=Echo=
Ctlview=Chat=View=Quiet=FALSE;
blklen=SECSIZ;
#ifdef DEFBYTL
Bytesleft=DEFBYTL;
#endif
/* change disk drive */
if(index(':', cp))
{
chdsk(cp);
continue;
}
/* evaluate arguments */
switch(*cp++)
{
/* b [baudrate] */
case 'b':
/* bye = exit */
if (cmdeq(cp, "ye"))
doexit();
/* break=send break to modem */
if(*cp == 'r')
{
sendbrk();
continue;
}
/* set baud rate */
else
{
setbaud(atoi(*argp++));
--argc;
}
continue;
case 'c':
#ifndef RESTRICTED
if(cmdeq(cp, "all") && --argc >=1)
{
uncaps(*argp); /* make name lcase */
if(getphone(*argp,Phone)!=ERROR)
dial(Phone);
else if (isdigit(**argp))
dial_number(*argp);
else
{
printf("Can't find data for %s\n", *argp++);
goto usage;
}
argp++;
term();
continue;
}
#endif
/* ch=change config(parity,etc) */
else if(cmdeq(cp, "h"))
{
changecnfg();
continue;
}
/* chat mode */
else if(cmdeq(cp, "hat"))
{
dochat();
continue;
}
/* cd=change directory */
else if(cmdeq(cp, "d"))
{
chgdir(argp);
argc=0;
continue;
}
#ifdef BIGYAM
/* crck */
else if(cmdeq(cp, "rck"))
{
docrck( --argc, argp);
argc=0;
continue;
}
/* crc */
else if(cmdeq(cp, "rc"))
{
docrc( --argc, argp);
argc=0;
continue;
}
#endif
else if(cmdeq(cp, "lose"))
{
dumprxbuff();
closerx(TRUE);
closetx(TRUE);
continue;
}
goto usage;
case 'd':
/* delete file */
if(cmdeq(cp, "el"))
{
#ifdef RESTRICTED
goto nono;
#else
doerase( --argc, argp);
argc=0;
continue;
#endif
}
/* dir */
if(cmdeq(cp, "ir"))
{
dodir(--argc, argp);
argc=0;
continue;
}
#ifdef IBMPC
/* debug=cause int 3 */
else if(cmdeq(cp, "ebug"))
{
dbgint();
continue;
}
#endif
/* dump */
if(cmdeq(cp, "ump"))
{
dodump(--argc, argp);
argc=0;
continue;
}
/* d.. = set paramter requested false */
else if(setval(0)==ERROR)
goto usage;
continue;
case '-':
case 'e':
/* e.. = set paramter requested true */
if(setval(~0)==ERROR)
goto usage;
continue;
case 'f':
/* close any already open files */
closetx(TRUE);
/* set parmaters if any */
if(setval(~0)==ERROR)
goto usage;
/* open file. open will compute file size */
if(--argc<=0 || opentx(1,0,*argp++)==ERROR)
goto usage;
/* frame file with ^R ^T if Squelch */
if(Squelch)
sendbyte(022);
term();
if(Squelch)
sendbyte(024);
continue;
case 'i':
if(cmdeq(cp, "nit"))
{
init();
argc=0;
nextcmd=0;
continue;
}
else
goto usage;
case '?':
case 'h':
searchpath(HELPFILE,Utility.ubuf);
listfile(NULL,Utility.ubuf);
continue;
case 'k':
if(cmdeq(cp, "ill"))
{
clearbuff();
continue;
}
else
goto usage;
#ifndef RESTRICTED
/* change modem port */
case 'm':
closetx(TRUE);
if (chngport(atoi(cp))==ERROR)
goto usage;
continue;
#endif
case 'o':
/* turn on DTR to modem */
if(cmdeq(cp, "n"))
{
offhook();
continue;
}
/* hang up phone */
onhook();
continue;
case 'p':
/* pwd=print working directory */
if(cmdeq(cp, "wd"))
dopwd();
/* set parmamters */
else if(setparm(cp)==ERROR)
goto usage;
continue;
case 'q':
/* quit. go to DOS, don't hangup */
if(cmdeq(cp, "u"))
{
dumprxbuff();
closerx(TRUE);
closetx(TRUE);
userexit();
exit(0);
}
goto usage;
case 'r':
if(cmdeq(cp, "eset"))
{
terminit();
/* close and flush capture buffer */
closetx(TRUE);
dumprxbuff();
closerx(TRUE);
/* reset modem port */
userinit(TRUE);
/* change buffer size for debugging */
if(--argc>0)
{
bufend= bufst + atoi(*argp++);
clearbuff();
dostat();
}
continue;
}
/* replot */
if(cmdeq(cp, "ep"))
{
replot(argc>1 ? (--argc,atoi(*argp++)) : 0);
continue;
}
/* rewind */
if(cmdeq(cp, "ew"))
{
rewindcb();
continue;
}
/* set flags for receive */
if(chkbvq()==ERROR)
goto usage;
if(argc<2)
Batch=TRUE;
psxfer(wcreceive(--argc, argp));
if(Gototerm)
term();
argc=0;
continue;
case 's':
#ifdef BIGYAM
/* sum */
if (cmdeq(cp, "um"))
{
dosum( --argc, argp);
argc=0;
continue;
}
#endif
/* s=status */
if(*cp==0 && argc==1)
{
dostat();
continue;
}
/* illegal */
if(argc<2 || chkbvq()==ERROR)
goto usage;
/* s *.?= wild card send */
if( argc > 2
|| index('?',*argp) || index('*',*argp))
Batch=TRUE;
#ifdef XMODEM
/* tell 'em how long it will take! */
if(Batch)
docomp(argc-1, argp);
#endif
/* s filename */
psxfer(wcsend(--argc, argp));
if(Gototerm)
term();
argc=0;
continue;
case 't':
/* type */
if(cmdeq(cp, "ype"))
{
dolist( --argc, argp);
argc=0;
continue;
}
/* tab = set tab expansion */
if(cmdeq(cp, "ab"))
{
tabstop = (char)(atoi(*argp++));
argc=0;
/* tab of 0 is illegal. Also resets
tab back to default if tab only entered */
if (!tabstop)
tabstop=TABS;
continue;
}
/* t [filename] */
if(--argc > 0)
{
if(opencapt(*argp++)==ERROR)
goto usage;
}
/* t.. */