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 >
Text File  |  1979-12-31  |  16KB  |  824 lines

  1. /*
  2. $title ('yam1.c: Main program,command sequencer')
  3. $date (17 nov 85)
  4. */
  5.  
  6. #include "yam.h"
  7. #include <ctype.h>
  8. #define MAXARGS 20
  9.  
  10. /****************************************************************************
  11. FUNCTION:
  12.     main program and command line parser.
  13.  
  14. CALLING PARAMETERS:
  15.     argc:
  16.         count of command line arguments.
  17.     argv:
  18.         pointer to string of command line arguments.
  19. ===========================================================================*/
  20. main(argc, argv)
  21. char *argv[];
  22. int argc;
  23. {
  24.     int c;
  25.     char *args[MAXARGS],
  26.          **argp,
  27.          *nextcmd;
  28.  
  29.         /* initialization */
  30.     nextcmd=NULL;
  31.     onceonly();
  32.  
  33.         /* init parmams and signon */
  34.     init();
  35.  
  36.         /* read command line arguments */
  37.     if(argc>MAXARGS)
  38.         goto usage;
  39.  
  40.         /* copy given arguments to our own array */
  41.     for (c = 0; c < argc; c++)
  42.         args[c] = argv[c];
  43.  
  44.     for(;;)
  45.     {
  46.         if(argc < 2)
  47.         {
  48.             if(nextcmd)
  49.                 cp=nextcmd;
  50.             else
  51.             {
  52. #ifdef XMODEM
  53.                 printf("\nxYAM(%c)", defdisk+'A');
  54. #else
  55.                 printf("\n>>>%c:", defdisk+'a');
  56. #endif
  57.                 gets(cmdbuf);
  58.                 cp=cmdbuf;
  59. #ifdef SYSFUNC
  60.                 if(*cp=='!')
  61.                 {
  62.                     system(++cp);
  63.                     continue;
  64.                 }
  65. #endif
  66.             }
  67.             if(nextcmd=index(';', cp))
  68.                 *nextcmd++ =0;    /*  ; separates commands */
  69.  
  70.                 /* init arg pointer, arg count */
  71.             argp = &args[1];
  72.             argc = 1;
  73.             while(1)
  74.             {
  75.                     /* printable char means vaild argument */
  76.                 if(isgraph(*cp))
  77.                 {
  78.                     *argp++ = cp;
  79.                     argc++;
  80.  
  81.                         /* skip to next arg */
  82.                     while(isgraph(*cp))
  83.                         cp++;
  84.                 }
  85.                     /* skip white space and change to string terminator */
  86.                 while(*cp==' ' || *cp=='\t')
  87.                     *cp++ =0;
  88.  
  89.                     /* found another printable, get next arg */
  90.                 if(isgraph(*cp))
  91.                     continue;
  92.  
  93.                     /* end of argument list */
  94.                 *cp=0;
  95.                 break;
  96.             }
  97.         }
  98.  
  99.             /* loop thru all parmaters */
  100.         for(argp = &args[1]; --argc>0; )
  101.         {
  102.             uncaps(*argp);
  103.             cp = *argp++;
  104.  
  105.                 /* reset mode flags to default. They may have been set
  106.                    by parms in s or r command */
  107.             Gototerm=Batch=Crcflg=Creamfile=Echo=
  108.                 Ctlview=Chat=View=Quiet=FALSE;
  109.  
  110.             blklen=SECSIZ;
  111. #ifdef DEFBYTL
  112.             Bytesleft=DEFBYTL;
  113. #endif
  114.  
  115.                 /* change disk drive */
  116.             if(index(':', cp))
  117.             {
  118.                 chdsk(cp);
  119.                 continue;
  120.             }
  121.  
  122.                 /* evaluate arguments */
  123.             switch(*cp++)
  124.             {
  125.                 /* b [baudrate] */
  126.             case 'b':
  127.  
  128.                     /* bye = exit */
  129.                 if (cmdeq(cp, "ye"))
  130.                     doexit();
  131.  
  132.                     /* break=send break to modem */
  133.                 if(*cp == 'r')
  134.                 {
  135.                     sendbrk();
  136.                     continue;
  137.                 }
  138.  
  139.                     /* set baud rate */
  140.                 else
  141.                 {
  142.                     setbaud(atoi(*argp++));
  143.                     --argc;
  144.                 }
  145.                 continue;
  146.  
  147.             case 'c':
  148. #ifndef RESTRICTED
  149.                 if(cmdeq(cp, "all") && --argc >=1)
  150.                 {
  151.                     uncaps(*argp);    /* make name lcase */
  152.                     if(getphone(*argp,Phone)!=ERROR)
  153.                         dial(Phone);
  154.                     else if (isdigit(**argp))
  155.                         dial_number(*argp);
  156.                     else
  157.                     {
  158.                         printf("Can't find data for %s\n", *argp++);
  159.                         goto usage;
  160.                     }
  161.                     argp++;
  162.                     term();
  163.                     continue;
  164.                 }
  165. #endif
  166.                     /* ch=change config(parity,etc) */
  167.                 else if(cmdeq(cp, "h"))
  168.                 {
  169.                     changecnfg();
  170.                     continue;
  171.                 }
  172.                     /* chat mode */
  173.                 else if(cmdeq(cp, "hat"))
  174.                 {
  175.                     dochat();
  176.                     continue;
  177.                 }
  178.                     /* cd=change directory */
  179.                 else if(cmdeq(cp, "d"))
  180.                 {
  181.                     chgdir(argp);
  182.                     argc=0;
  183.                     continue;
  184.                 }
  185. #ifdef BIGYAM
  186.                     /* crck */
  187.                 else if(cmdeq(cp, "rck"))
  188.                 {
  189.                     docrck( --argc, argp);
  190.                     argc=0;
  191.                     continue;
  192.                 }
  193.  
  194.                     /* crc */
  195.                 else if(cmdeq(cp, "rc"))
  196.                 {
  197.                     docrc( --argc, argp);
  198.                     argc=0;
  199.                     continue;
  200.                 }
  201. #endif
  202.                 else if(cmdeq(cp, "lose"))
  203.                 {
  204.                     dumprxbuff();
  205.                     closerx(TRUE);
  206.                     closetx(TRUE);
  207.                     continue;
  208.                 }
  209.                 goto usage;
  210.  
  211.             case 'd':
  212.                     /* delete file */
  213.                 if(cmdeq(cp, "el"))
  214.                 {
  215. #ifdef RESTRICTED
  216.                     goto nono;
  217. #else
  218.                     doerase( --argc, argp);
  219.                     argc=0;
  220.                     continue;
  221. #endif
  222.                 }
  223.  
  224.                     /* dir */
  225.                 if(cmdeq(cp, "ir"))
  226.                 {
  227.                     dodir(--argc, argp);
  228.                     argc=0;
  229.                     continue;
  230.                 }
  231. #ifdef IBMPC
  232.                     /* debug=cause int 3 */
  233.                 else if(cmdeq(cp, "ebug"))
  234.                 {
  235.                     dbgint();
  236.                     continue;
  237.                 }
  238. #endif
  239.                     /* dump */
  240.                 if(cmdeq(cp, "ump"))
  241.                 {
  242.                     dodump(--argc, argp);
  243.                     argc=0;
  244.                     continue;
  245.                 }
  246.                     /* d.. = set paramter requested false */
  247.                 else if(setval(0)==ERROR)
  248.                     goto usage;
  249.                 continue;
  250.  
  251.             case '-':
  252.             case 'e':
  253.  
  254.                     /* e.. = set paramter requested true */
  255.                 if(setval(~0)==ERROR)
  256.                     goto usage;
  257.                 continue;
  258.  
  259.             case 'f':
  260.                     /* close any already open files */
  261.                 closetx(TRUE);
  262.                     /* set parmaters if any */
  263.                 if(setval(~0)==ERROR)
  264.                     goto usage;
  265.                     /* open file.  open will compute file size */
  266.                 if(--argc<=0 || opentx(1,0,*argp++)==ERROR)
  267.                     goto usage;
  268.                 /* frame file with ^R ^T if Squelch */
  269.                 if(Squelch)
  270.                     sendbyte(022);
  271.                 term();
  272.                 if(Squelch)
  273.                     sendbyte(024);
  274.                 continue;
  275.  
  276.             case 'i':
  277.                 if(cmdeq(cp, "nit"))
  278.                 {
  279.                     init();
  280.                     argc=0;
  281.                     nextcmd=0;    
  282.                     continue;
  283.                 }
  284.                 else
  285.                     goto usage;
  286.  
  287.             case '?':
  288.             case 'h':
  289.                 searchpath(HELPFILE,Utility.ubuf);
  290.                 listfile(NULL,Utility.ubuf);
  291.                 continue;
  292.  
  293.             case 'k':
  294.                 if(cmdeq(cp, "ill"))
  295.                 {
  296.                     clearbuff();
  297.                     continue;
  298.                 }
  299.                 else
  300.                     goto usage;
  301.  
  302. #ifndef RESTRICTED
  303.                     /* change modem port */
  304.             case 'm':
  305.                 closetx(TRUE);
  306.                 if (chngport(atoi(cp))==ERROR)
  307.                     goto usage;
  308.                 continue;
  309. #endif
  310.  
  311.             case 'o':
  312.                     /* turn on DTR to modem */
  313.                 if(cmdeq(cp, "n"))
  314.                 {
  315.                     offhook();
  316.                     continue;
  317.                 }
  318.                     /* hang up phone */
  319.                 onhook();
  320.                 continue;
  321.  
  322.             case 'p':
  323.                     /* pwd=print working directory */
  324.                 if(cmdeq(cp, "wd"))
  325.                     dopwd();
  326.  
  327.                     /* set parmamters */
  328.                 else if(setparm(cp)==ERROR)
  329.                     goto usage;
  330.                 continue;
  331.  
  332.             case 'q':
  333.                 /* quit.  go to DOS, don't hangup */
  334.                 if(cmdeq(cp, "u"))
  335.                 {
  336.                     dumprxbuff();
  337.                     closerx(TRUE);
  338.                     closetx(TRUE);
  339.                     userexit();
  340.                     exit(0);
  341.                 }
  342.                 goto usage;
  343.  
  344.             case 'r':
  345.                 if(cmdeq(cp, "eset"))
  346.                 {
  347.                     terminit();
  348.                         /* close and flush capture buffer */
  349.                     closetx(TRUE);
  350.                     dumprxbuff();
  351.                     closerx(TRUE);
  352.                         /* reset modem port */
  353.                     userinit(TRUE);
  354.  
  355.                     /* change buffer size for debugging */
  356.                     if(--argc>0)
  357.                     {
  358.                         bufend= bufst + atoi(*argp++);
  359.                         clearbuff();
  360.                         dostat();
  361.                     }
  362.                     continue;
  363.                 }
  364.                     /* replot */
  365.                 if(cmdeq(cp, "ep"))
  366.                 {
  367.                     replot(argc>1 ? (--argc,atoi(*argp++)) : 0);
  368.                     continue;
  369.                 }
  370.                     /* rewind */
  371.                 if(cmdeq(cp, "ew"))
  372.                 {
  373.                     rewindcb();
  374.                     continue;
  375.                 }
  376.                     /* set flags for receive */
  377.                 if(chkbvq()==ERROR)
  378.                     goto usage;
  379.                 if(argc<2)
  380.                     Batch=TRUE;
  381.                 psxfer(wcreceive(--argc, argp));
  382.                 if(Gototerm)
  383.                     term();
  384.                 argc=0;
  385.                 continue;
  386.  
  387.             case 's':
  388. #ifdef BIGYAM
  389.                     /* sum */
  390.                 if (cmdeq(cp, "um"))
  391.                 {
  392.                     dosum( --argc, argp);
  393.                     argc=0;
  394.                     continue;
  395.                 }
  396. #endif
  397.  
  398.                     /* s=status */
  399.                 if(*cp==0 && argc==1)
  400.                 {
  401.                     dostat();
  402.                     continue;
  403.                 }
  404.                     /* illegal */
  405.                 if(argc<2 || chkbvq()==ERROR)
  406.                     goto usage;
  407.  
  408.                     /* s *.?= wild card send */
  409.                 if( argc > 2
  410.                   || index('?',*argp) || index('*',*argp))
  411.                     Batch=TRUE;
  412. #ifdef XMODEM
  413.                 /* tell 'em how long it will take! */
  414.                 if(Batch)
  415.                     docomp(argc-1, argp);
  416. #endif
  417.                 /* s filename */
  418.                 psxfer(wcsend(--argc, argp));
  419.                 if(Gototerm)
  420.                     term();
  421.                 argc=0;
  422.                 continue;
  423.  
  424.             case 't':
  425.                     /* type */
  426.                 if(cmdeq(cp, "ype"))
  427.                 {
  428.                     dolist( --argc, argp);
  429.                     argc=0;
  430.                     continue;
  431.                 }
  432.  
  433.                     /* tab = set tab expansion */
  434.                 if(cmdeq(cp, "ab"))
  435.                 {
  436.                     tabstop = (char)(atoi(*argp++));
  437.                     argc=0;
  438.                         /* tab of 0 is illegal.  Also resets
  439.                            tab back to default if tab only entered */
  440.                     if (!tabstop)
  441.                         tabstop=TABS;
  442.                     continue;
  443.                 }
  444.  
  445.                     /* t [filename] */
  446.                 if(--argc > 0)
  447.                 {
  448.                     if(opencapt(*argp++)==ERROR)
  449.                         goto usage;
  450.                 }
  451.                     /* t.. */
  452.