home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 110_01 / yam1.c < prev    next >
Text File  |  1984-03-03  |  9KB  |  443 lines

  1. /*
  2. >>:yam1.c
  3.  * Mainline for yam 9-6-81
  4.  */
  5. #include "yam.h"
  6. #define MAXARGS 20
  7.  
  8. main(argc, argv)
  9. char **argv;
  10. {
  11.     int c;
  12.     char *args[MAXARGS], **argp, **argq, *nextcmd, *p;
  13.  
  14.     nextcmd=NULL;
  15.     printf("Yet Another Modem by Chuck Forsberg\n");
  16.     printf(VERSION);
  17.     init();
  18.     if(argc>MAXARGS)
  19.         goto usage;
  20.     /* copy given arguments to our own array */
  21.     for(argp=argv,argq=args,c=argc; --c>=0;)
  22.         *argq++ = *argp++;
  23.     for(;;) {
  24. #ifdef TERMRESET
  25.         lprintf(TERMRESET);
  26. #endif
  27.         if(argc < 2) {
  28.             if(nextcmd)
  29.                 cp=nextcmd;
  30.             else {
  31. #ifdef CPM
  32.                 printf("\n>>>%c%d: ",defdisk+'A', user);
  33. #else
  34.                 printf("\nCommand: ");
  35. #endif
  36.                 gets(cmdbuf);
  37.                 cp=cmdbuf;
  38.             }
  39.             if(nextcmd=index(';', cp))
  40.                 *nextcmd++ =0;    /*  ; separates commands */
  41.             else if(nextcmd=index('\\', cp))
  42.                 *nextcmd++ =0;    /*  \ separates commands */
  43.  
  44.             argp= &args[1]; argc=1;
  45.             for(;;) {
  46.                 if(isgraphic(*cp)) {
  47.                     *argp++ = cp;
  48.                     argc++;
  49.                     while(isgraphic(*cp))
  50.                         cp++;
  51.                 }
  52.                 while(*cp==' ' || *cp=='\t')
  53.                     *cp++ =0;
  54.                 if(*cp > ' ')
  55.                     continue;
  56.                 *cp=0;
  57.                 break;
  58.             }
  59.         }
  60.         for(argp= &args[1]; --argc>0; ) {
  61.             uncaps(*argp);
  62.             cp= *argp++;
  63.  
  64.             Gototerm=Batch=Creamfile=Echo=View=Quiet=FALSE;
  65. #ifdef CPM
  66.             if(index(':', cp)) {
  67.                 chdir(cp);
  68.                 continue;
  69.             }
  70. #endif
  71.             switch(*cp++) {
  72.             case 'b':
  73.                 if(cmdeq(cp, "ye")) {
  74.                     bye();
  75.                     continue;
  76.                 }
  77.                 else if(setbaud(atoi(cp)))
  78.                     goto usage;
  79.                 continue;
  80.             case 'c':
  81. #ifndef RESTRICTED
  82.                 if(cmdeq(cp, "all") && --argc ==1) {
  83.                     uncaps(*argp);    /* make name lcase */
  84.                     if(getphone(*argp++,Phone)==ERROR)
  85.                         goto usage;
  86.                     else if(dial(Phone)==ERROR)
  87.                         goto usage;
  88.                     continue;
  89.                 }
  90. #endif
  91. #ifdef XMODEM
  92.                 if(cmdeq(cp, "hat")) {
  93.                     chat();
  94.                     continue;
  95.                 }
  96. #endif
  97.                 if(cmdeq(cp, "lose")) {
  98.                     dumprxbuff();
  99.                     closerx(TRUE); closetx();
  100.                     continue;
  101.                 }
  102.                 else
  103.                     goto usage;
  104.             case 'd':
  105.                 if(cmdeq(cp, "ir")) {
  106. #ifndef CDOS
  107.                     if(cp[2])
  108.                         docomp(--argc, argp);
  109.                     else
  110. #endif
  111.                         dodir(--argc, argp);
  112.                     argc=0;
  113.                 }
  114.                 else if(setval(0)==ERROR)
  115.                     goto usage;
  116.                 continue;
  117.             case 'e':
  118.                 if(setval(~0)==ERROR)
  119.                     goto usage;
  120.                 continue;
  121.             case 'f':
  122.                 closetx();
  123.                 if(setval(~0)==ERROR)
  124.                     goto usage;
  125.                 if(--argc<=0 || opentx(*argp++)==ERROR)
  126.                     goto usage;
  127.                 if(Squelch)        /* frame file with ^R and ^T if Squelch */
  128.                     outp(Dport, 022);
  129.                 term(0);
  130.                 if(Squelch)
  131.                     outp(Dport, 024);
  132.                 continue;
  133.             case 'i':
  134.                 if(cmdeq(cp, "nit")) {
  135.                     init(); argc=nextcmd=0; continue;
  136.                 }
  137.                 else
  138.                     goto usage;
  139.             case '?':
  140.             case 'h':
  141.                 listfile(HELPFILE); continue;
  142.             case 'k':
  143.                 if(cmdeq(cp, "ill")) {
  144.                     clearbuf();
  145.                     continue;
  146.                 }
  147.                 else
  148.                     goto usage;
  149.             case 'l':
  150.                 if(cmdeq(cp, "ist")) {
  151. listit:
  152.                     dolist( --argc, argp); argc=0; continue;
  153.                 }
  154.                 else
  155.                     goto usage;
  156. #ifndef RESTRICTED
  157.             case 'm':
  158.                 Sport=(Dport=atoi(cp))+SPORT-DPORT;
  159.                 readbaud(); continue;
  160. #endif
  161.             case 'o':
  162.                 onhook(); printf("On Hook");
  163.                 if(cmdeq(cp, "ff"))
  164.                     exit(0);
  165.                 continue;
  166.             case 'p':
  167.                 if(setparm(cp)==ERROR)
  168.                     goto usage;
  169.                 continue;
  170.             case 'r':
  171.                 if(cmdeq(cp, "eset")) {
  172.                     closetx();
  173.                     dumprxbuff(); closerx(TRUE);
  174. #ifdef CPM
  175.                     bdos(13,0);bdos(14,defdisk);
  176. #endif
  177.                     /* change buffer size for debugging */
  178.                     if(--argc>0) {
  179.                         bufend= bufst + atoi(*argp++);
  180.                         clearbuf();
  181.                         dostat();
  182.                     }
  183.                     continue;
  184.                 }
  185.                 if(cmdeq(cp, "ep")) {
  186.                     replot(argc>1 ? (--argc,atoi(*argp++)) : 0);
  187.                     continue;
  188.                 }
  189.                 if(cmdeq(cp, "ew")) {
  190.                     rewindcb(); continue;
  191.                 }
  192.                 if(chkbvq()==ERROR)
  193.                     goto usage;
  194.                 if(argc<2)
  195.                     Batch=TRUE;
  196.                 psxfer(wcreceive(--argc, argp));
  197.                 if(Gototerm)
  198.                     term();
  199.                 argc=0; continue;
  200.             case 's':
  201.                 if(*cp == 0 && argc==1) {
  202.                     dostat();
  203.                     continue;
  204.                 }
  205.                 if(argc<2 || chkbvq()==ERROR)
  206.                     goto usage;
  207. #ifdef XMODEM
  208.                 /* tell 'em how long it will take! */
  209.                 if(Baudrate<=1200)
  210.                     docomp(argc-1, argp);
  211. #endif
  212.                 psxfer(wcsend(--argc, argp));
  213.                 if(Gototerm)
  214.                     term();
  215.                 argc=0; continue;
  216.             case 't':
  217.                 if(cmdeq(cp, "ype"))
  218.                     goto listit;
  219.                 if(--argc > 0) {
  220.                     dumprxbuff(); closerx(TRUE);
  221.                     if(opencapt(*argp++)==ERROR)
  222.                         goto usage;
  223.                 }
  224.                 switch(setval(~0)) {
  225.                 case ERROR:
  226.                     goto usage;
  227.                 case OK:
  228.                     term();
  229.                 case TRUE:        /* remain in command mode if t..c  */
  230.                     break;
  231.                 }
  232.                 continue;
  233.             case 'w':
  234.                 dumprxbuff(); continue;
  235.             case 'x':
  236.                 continue;    /* in case you said "XMODEM" */
  237.             case 0:
  238.             default:
  239.                 goto usage;
  240.             }
  241.             continue;
  242.         }
  243.         continue;
  244. usage:
  245.         printf("\nType HELP for instructions");
  246.         nextcmd=argc=0; continue;
  247.     }
  248. }
  249.  
  250. chkbvq()
  251. {
  252.     while(*cp)
  253.         switch(*cp++) {
  254.         case 'b':
  255.             Batch=TRUE; break;
  256.         case 'q':
  257.             Quiet=TRUE; break;
  258. #ifndef RESTRICTED
  259.         case 't':
  260.             Gototerm=TRUE; break;
  261.         case 'v':
  262.             View=TRUE; break;
  263.         case 'y':
  264.             Creamfile=TRUE; break;
  265. #endif
  266.         default:
  267.             return ERROR;
  268.         }
  269.     return FALSE;
  270. }
  271. setval(value)
  272. unsigned value;
  273. {
  274.     FLAG dumped;
  275.     dumped=FALSE;
  276.     while(*cp)
  277.         switch(*cp++) {
  278.         case 'b':
  279.             Txeoln= value&TX_BINARY; Txmoname="BINARY"; break;
  280.         case 'c':
  281.             dumprxbuff(); closerx(dumped=TRUE); break;
  282.         case 'e':
  283.             Echo=value; break;
  284.         case 'f':
  285.             Hdx= !value; break;
  286.         case 'g':
  287.             Txgo= value; break;
  288.         case 'h':
  289.             Hdx=value; break;
  290.         case 'i':
  291.             Image=value; break;
  292.         case 'l':
  293.             Pflag=value; break;
  294.         case 'n':
  295.             Txeoln =value&EOL_NL; Txmoname="NL ONLY"; break;
  296.         case 'p':
  297.             Txeoln =value&EOL_CRPROMPT; Txmoname="WAIT FOR PROMPT"; break;
  298.         case 'r':
  299.             Txeoln =value&EOL_CR; Txmoname="CR ONLY"; break;
  300.         case 's':
  301.             Squelch=value; break;
  302.         case 't':
  303.             Waitbunch=value; break;
  304.         case 'v':
  305.             Ctlview=value; break;
  306.         case 'w':
  307.             Txeoln= value&EOL_CRWAIT; Txmoname="CR WAIT FOR NL"; break;
  308.         case 'x':
  309.             Exoneof=value; break;
  310.         case 'z':
  311.             Zeof=value; break;
  312.         default:
  313.             return ERROR;
  314.         }
  315.     return dumped;
  316. }
  317.  
  318. init()
  319. {
  320. #ifdef BDSC
  321.     char *endext(), *topofmem(), *codend(), *externs();
  322.     if(codend() > externs()) {    /* check for bad -e value! */
  323.         printf("urk"); exit();
  324.     }
  325. #endif
  326.     initdd();        /* fetch default disk and user number */
  327.     bufst=endext();
  328.     bufend=topofmem()-1024;    /* fudge so we don't crash ... */
  329.     Dport=DPORT; Sport=SPORT;
  330.     readbaud();
  331. #ifndef XMODEM
  332.     setbaud(Baudrate);
  333. #endif
  334.     Ctlview=Rfile=Tfile=Pflag=FALSE;
  335.     Image=Waitbunch=Exoneof=Hdx=Zeof=Squelch=FALSE;
  336.     Txgo=TRUE;
  337.     Parity= NORMAL;
  338.     Originate= TRUE;
  339.     Txeoln= EOL_NOTHING;
  340.     Low= 400;
  341.     Tpause=1500*CLKMHZ; Throttle=80*CLKMHZ; T1pause=311*CLKMHZ;
  342.     Waitnum=1;
  343.     clearbuf();
  344. }
  345. clearbuf()
  346. {
  347.     Wrapped= 0;
  348.     buffcdq=bufcq=bufcdq=bufpcdq=bufmark= bufst;
  349.     Bufsize=Free= bufend-bufst;
  350.     setmem(bufst, Bufsize, 0);
  351. }
  352.  
  353.  
  354. cmdeq(s,p)
  355. char *s, *p;
  356. {
  357.     while(*p)
  358.         if(*s++ != *p++)
  359.             return 0;
  360.     return 1;
  361. }
  362.  
  363. dostat()
  364. {
  365.  
  366.         printf("Capture %s Receiving %s ",
  367.          Dumping?"ON":"SQUELCHED", Rfile?Rname:"<nil>");
  368.         if(Image)
  369.             printf("Transparency mode ");
  370.         if(Squelch)
  371.             printf("^R ^T Squelch ");
  372.         if(Zeof)
  373.             printf("EOF on ^Z");
  374.         printf("\n");
  375.  
  376.     if(Txeoln==EOL_NOTHING)
  377.         Txmoname="IMAGE";
  378.  
  379.     printf("%sSending %s in %s mode\n",
  380.      Txgo? "" : "Pausing in ", Tfile?Tname:"<nil>", Txmoname);
  381.     printf("%sWaiting %d loops every %u chars  Pause=%u\n",
  382.      Waitbunch?"":"NOT ",Throttle, Waitnum, Tpause);
  383.  
  384.     printf("Printer %s  ", Pflag?"ON":"OFF");
  385.     if(Hdx)
  386.         printf("Half Duplex ");
  387.     printf("At %u baud data port %d.\n", Baudrate, Dport);
  388.     printf("%u of %u chars used %u free%s\n",
  389.       Bufsize-Free, Bufsize, Free, Wrapped?" POINTERS WRAPPED":"");
  390.     printf("bufst=%x bufcq=%x bufcdq=%x buffcdq=%x bufpcdq=%x bufend=%x\n",
  391.      bufst, bufcq, bufcdq, buffcdq, bufpcdq, bufend);
  392. }
  393.  
  394. isgraphic(c)
  395. {
  396.     if(c>' ' && c<0177)
  397.         return TRUE;
  398.     else
  399.         return FALSE;
  400. }
  401.  
  402. /*
  403.  * index returns a pointer to the first occurrence of c in s,
  404.  * NULL otherwise.
  405.  */
  406. char *index(c, s)
  407. char c,*s;
  408. {
  409.     for(; *s; s++)
  410.         if(c== *s)
  411.             return s;
  412.     return NULL;
  413. }
  414. psxfer(status)
  415. {
  416.     lpstat("File transfer(s) %s",
  417.      status==ERROR?"ABORTED BY ERROR" : "successful");
  418. }
  419.  
  420. setparm(p)
  421. char *p;
  422. {
  423.     if(*p)
  424.         switch(*p++) {
  425.         case 'p':
  426.             Tpause=atoi(p); break;
  427.         case 't':
  428.             Throttle=atoi(p); break;
  429.         case 'w':
  430.             Waitnum=atoi(p); break;
  431.         default:
  432.             return ERROR;
  433.      }
  434.     return 0;
  435. }
  436. /* make strings lower case */
  437. uncaps(s)
  438. char *s;
  439. {
  440.     while(*s)
  441.         *s = tolower(*s++);
  442. }
  443. pr