home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / researchmachines.zip / rmlmai.c < prev    next >
Text File  |  1985-07-11  |  9KB  |  398 lines

  1.  
  2. /***********************************************************************/
  3.  
  4. /*  File KMAIN.C  -  RML Kermit  -  main() & associated routines.
  5.         Chris Kennington,    3rd July 1985.    */
  6.  
  7. #define     DEFS1    1
  8. #define     DEFS2    1        
  9. #define  DEFS3    1
  10. #define  DEFS4    1
  11.  
  12. #include "stdio.h"
  13. #include "b:kext.h"
  14.  
  15. char  verdate[]    = "Version 1.22,  10th July 1985.";
  16. /* max 32 chars:   12345678901234567890123456789012        */
  17.  
  18. extern    CHAR    menu();
  19.  
  20. static  char  cmdmenu[]      = "C O M M A N D S  to  S E R V E R";
  21. static  char  *copyrite[] = {head1,head3,head2,0};
  22. static  char  mainmenu[]  = "K E R M I T   M A I N   M E N U";
  23. static  char  *mainhelp[]  = {
  24. "        Use up \136 & down \036 arrows to select next Kermit activity;",
  25. "          (or F1/PGUP & F3/PGDN for top & bottom of list).",
  26. "        Hit ? for help on selected parameter, RETURN to take action,",kqhelp,
  27. "        Kermit will prompt for file-names etc. as needed.",0};
  28.  
  29.  
  30.  
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char **argv;
  35. {
  36.     int        i, mod, rsc;
  37.     char    c, rcmd, **txt;
  38.     struct    mode    *md;
  39.  
  40.     keyinit();
  41.     netcool();
  42.     s4go();
  43.     s4set(commode,comctrl);
  44.     dynamic();
  45.  
  46.     cursor(0);
  47.     vtline(0x0000,head1);    
  48.     vtline(0x0100,head4);
  49.     vtline(0x0200,head5);
  50.     vtline(0x0300,head6);
  51.     vtline(0x0400,divisor);
  52.     vtline(LOCVER,verdate);
  53.  
  54.     setbaud();            /* set initial speed (300baud)    */
  55.     i = head2;                /* prolink restriction    */
  56.     env = s4env();
  57.     strcop(locations[env],i+64);    /* source of comms    */
  58.  
  59. /* main Kermit loop - go on until exits surreptitiously        */
  60.  
  61.     mod = rsc = 1;        /* top lines of menus    */
  62.     kmode = KERM;
  63.     forever {
  64.   /* at this point "break" leads to "Hit any key..", "continue" skips it */
  65.  
  66.       nakflag = abtflag = 0;
  67.       rptflg = TRUE;         /* attempt repeat-counting    */
  68.       flushinput();        /* avoid trouble    */
  69.       screen(5,23);
  70.  
  71.       switch (kmode) {
  72.  
  73.       case KERM:        /* command-mode        */
  74.     md = &modker;        /* Prolink restriction    */
  75.     vtline(LOCMODE,md->m_text);
  76.     i = menu(kmodes,MODMAX,mainmenu,&mod);
  77.     md = kmodes[i];
  78.     vtline(LOCMODE,md->m_text); /* next action */
  79.     kmode = md->m_value;
  80.     clrscrn();
  81.     continue;
  82.  
  83.  
  84.       case LOGO:        /* kill mainframe Kermit */
  85.     md = &rclogo;
  86.     printmsg(md->m_text);
  87.     servsend(kmode);
  88.   /* fall through into connect                */
  89.       case CONN:        /* connect-mode        */
  90.     s4set(commode,comctrl);
  91.     cursor(0x09);
  92.     connect();
  93.     continue;
  94.  
  95.       case SEND:
  96.     vtline(LOCMODE,sendf);
  97.     s4set(commode,comctrl);
  98.     s4sleep();
  99.     cursor(0x1d);
  100.     printmsg("%sEnter filename(s) > ",sendf);
  101.     if (keyline(cmdline) == 0)
  102.         goto Out2;
  103.     cursor(0);
  104.     upper(cmdline);
  105.     filecount = decol8(cmdline,cmdparm,8);
  106.     filelist = cmdparm;        /* Set up file list    */
  107.     if ( (gnxtfl() == FALSE) || (sendsw('S') == FALSE) ) /* Send file(s) */
  108.         printmsg("** SEND failure. ");
  109.     goto Out1;
  110.  
  111.       case RECV:        /* Receive-mode            */
  112.     vtline(LOCMODE,filblank);
  113.     vtline(LOCMODE,rcvng);
  114.     state = 'R';
  115.       case GET:            /* from Server-Command mode    */
  116.     s4set(commode,comctrl);
  117.     s4sleep();
  118.     cursor(0x1d);
  119.     vtline(LOCFILE,filblank);
  120.     printmsg("%sStore under own names",rcvng);
  121.     if (confirm() != TRUE) {    /* if overriding    */
  122.         if (abtflag != 0)
  123.         goto Out2;
  124.         printmsg("New filenames &/or disk-letter > ");
  125.         keyline(cmdline);
  126.         upper(cmdline);
  127.         if ( (filecount = decol8(cmdline,cmdparm,8)) == 0 )
  128.         goto Out2;
  129.         filelist = cmdparm;        /* Set up file list    */
  130.         printmsg("%sas requested%s",rcvng,dots);
  131.         vtline(LOCFILE,*filelist);
  132.      }
  133.     else {
  134.         filelist = filecount = 0;
  135.         printmsg("%s%s",rcvng,dots);
  136.     }
  137.     cursor(0);
  138.     kmode = RECV;            /* makes ESCs valid    */
  139.     if (recsw(state,'R') == FALSE)
  140.         printmsg("** RECEIVE failure. ");
  141.     else
  142.         printmsg("** Files received OK. ");
  143.     goto Out1;
  144.  
  145.       case PARM:        /* Set parameters        */
  146.     setshow();
  147.     goto Out2;
  148.  
  149.       case CMND:        /* Commands to server        */
  150.     if ( (i = menu(rcmds,CMDMAX,cmdmenu,&rsc)) == 0 ) {
  151.         kmode = KERM;
  152.         continue;
  153.     }
  154.     md = rcmds[i];
  155.     if ( (rcmd = md->m_value) != MAIN )
  156.         printmsg(md->m_text);
  157.     outc(SP);
  158.     cursor(0x1d);
  159.     servsend(rcmd);
  160.     continue;
  161.  
  162.       case DISK:            /* process BDOS commands    */
  163.     cursor(9);
  164.     md = &modisk;            /* Prolink restriction    */
  165.     printmsg(md->m_text);
  166.     outc(CR);
  167.     txt = md->m_help;
  168.     while (*txt != 0) {
  169.         outc(CR);
  170.         txtout(*txt++);
  171.     }
  172.     s4sleep();
  173.     outc(CR);
  174.     forever
  175.         if (osaction() == 0)
  176.         break;
  177.     netcool();
  178. Out2:
  179.     kmode = KERM;
  180.     continue;
  181.  
  182.       case QUIT:        /* exit from prog        */
  183.     printmsg(null);
  184.     kermkill(1);
  185.  
  186.       default:            /* unknown mode            */
  187. Out1:
  188.     cursor(0x1d);
  189.     kmode = KERM;
  190.     break;
  191.     }            /* end switch                */
  192.  
  193.     if ( (kmode == KERM) || (kmode == CMND) ) {
  194.     printmsg("Hit any key to continue ... ");
  195.     while (keyget(&c) == 0)
  196.         ;            /* pause            */
  197.   } }            /* end if, forever            */
  198.  
  199. /* we never come out of this loop                */
  200.     printmsg("%sExit!",interr);
  201.     kermkill(1);
  202.  
  203. }        /* End of main()                */
  204.  
  205.  
  206. static dynamic()        /* set up dynamic storage    */
  207. {
  208.     cmdline = getram(85);
  209.     osline = getram(85);
  210.     work = getram(MAXPACKSIZE+10);
  211.     packet = getram(MAXPACKSIZE+2);
  212.     recpkt = getram(MAXPACKSIZE+2);
  213.     oldpkt = getram(MAXPACKSIZE+2);
  214.     ownfcb = getram(42);
  215.     fname = getram(50);
  216.     filblank = blanx;
  217.     filblank += 60;        /* PROLINK restriction    */
  218.     return;
  219. }            /* end of dynamic()        */
  220.  
  221.  
  222.  
  223. errdisp()        /* display error-counts        */
  224. /*  Display counts of naks in, bad crcs, duplicate blocks
  225.     and timouts in header.                */
  226. {
  227.     static  char  buff[20];
  228.     static  int  old1=0, old2 =0, old3=0, old4=0;
  229.  
  230.     if (dupes != old1) {
  231.     old1 = dupes;
  232.     sprintf(buff,"%d Dupes,",dupes);
  233.     vtline(LOCDUPES,buff);
  234.     }
  235.     if (badcrcs != old2) {
  236.     old2 = badcrcs;
  237.     sprintf(buff,"%d Cksm,",badcrcs);
  238.     vtline(LOCCRCS,buff);
  239.     }
  240.     if (timouts != old3) {
  241.     old3 = timouts;
  242.     sprintf(buff,"%d Timeouts,",timouts);
  243.     vtline(LOCTIMOS,buff);
  244.     }
  245.     if (naxin != old4) {
  246.     old4 = naxin;
  247.     sprintf(buff,"%d NAKs.",naxin);
  248.     vtline(LOCNAKS,buff);
  249.     }
  250.     return;
  251. }        /* end of errdisp()            */
  252.  
  253.  
  254.  
  255. kermkill(code)        /* close down Kermit        */
  256. /* confirms with user if code = 0            */
  257. char    code;
  258. {
  259.     char  c, *msg;
  260.  
  261.     if (code == 0) {
  262.     printmsg("Quit Kermit");
  263.     if (confirm() != TRUE)
  264.         return;
  265.     }
  266.     keyrest();
  267.     s4stop();
  268. #ifdef MPUZ80
  269.     txtout(" End of Kermit.");
  270. #else
  271.     msg = "\n Kermit cancelled - You may have to reload MSDOS.\n";
  272.     while ( (c = *msg++) != 0 )
  273.     putchar(c);
  274. #endif
  275.     cpmgo();
  276. }        /* end of kermkill()                */
  277.  
  278.  
  279.  
  280.  
  281. CHAR menu(modes,max,title,iline)    /* display menu        */
  282. struct  mode  *modes[];
  283. int    max,  *iline;
  284. char    *title;
  285. {
  286.     CHAR    c;
  287.     int     i,  mod;
  288.     struct    mode    *md;
  289.  
  290.     scrdiv();
  291.     screen(19,24);
  292.     vtline((SCRTOP-1)*256+MENUCOL,title);
  293.     i = SCRTOP*256+MENUCOL;
  294.     c = strlen(title);
  295.     while (c-- > 0)        /* underline            */
  296.     vtout(i++,0x1f);
  297.     for (i=1; i<max; ++i) {
  298.     md = modes[i];
  299.     vtline((SCRTOP+i)*256+PNMCOL,md->m_text);
  300.     }
  301.     show5( (title == mainmenu) ? copyrite : mainhelp );
  302.     curset(23,0);
  303.     mod = *iline;
  304.     md = modes[mod];
  305.  
  306.     forever {            /* control arrow-selection    */
  307.     vtout((SCRTOP+mod)*256+PVCOL,LARROW);
  308.     while (keyget(&c) == 0)
  309.         ;
  310.     vtout((SCRTOP+mod)*256+PVCOL,SP); /*  & old arrow    */
  311.  
  312.     c &= (char)0x5f;    /* u.c. 7-bit            */
  313.     switch (c) {
  314.  
  315.       case CR:            /* action        */
  316.       case LF:
  317.         *iline = mod;        /* remember line-#    */
  318.         screen(5,23);
  319.         clrscrn();
  320.         return(mod);        /* exit with index-#    */
  321.  
  322.       case 0:            /* SP&0x5f - cycle    */
  323.         if (++mod > (max-1))
  324.         mod = 1;
  325.         break;
  326.  
  327.       case 'B':            /* back to top        */
  328.         mod = 1;
  329.         break;
  330.  
  331.       case 'D':            /* down            */
  332.         if (++mod > (max-1)) {
  333.         bell();
  334.         --mod;
  335.         }
  336.         break;
  337.  
  338.       case 'H':            /* general help        */
  339.         show5(mainhelp);
  340.         continue;
  341.  
  342.       case 'N':            /* on to bottom        */
  343.         mod = max-1;
  344.         break;
  345.  
  346.       case 'Q':            /* quit            */
  347.         kermkill(0);
  348.   /* if not confirmed, fall through                */
  349.       case 'K':
  350.         return(0);            /* no-op exit        */
  351.  
  352.       case 'U':            /* up            */
  353.         if (--mod == 0) {
  354.         bell();
  355.         ++mod;
  356.         }
  357.         break;
  358.  
  359.       case '?':            /* specific help    */
  360.       case 0x1f:
  361.       case 0x0f:
  362.         break;
  363.  
  364.       default:
  365.         continue;
  366.     }            /* end switch            */
  367.     md = modes[mod];
  368.     show5(md->m_help);
  369.     }                /* end forever            */
  370. }            /* End of menu()            */
  371.  
  372.  
  373.  
  374. prerrpkt(msg)
  375. /*  Print contents of error packet received from remote host. */
  376. char *msg;
  377. {
  378.     printmsg("Aborting; %s\r  \"%s\". ",mainsays,msg);
  379.     return;
  380. }        /* end of prerrpkt()            */
  381.  
  382.  
  383.  
  384. printmsg(fmt, a1,a2,a3,a4,a5)
  385. char *fmt;
  386. {
  387.     txtout(prompt);
  388.     outc(':');
  389.     outc(SP);
  390.     printf(fmt,a1,a2,a3,a4,a5);
  391.     outc(DEOL);            /* Delete to EoL    */
  392. }            /* end of printmsg()        */
  393.  
  394.  
  395. /****************  END of file KMAIN.C  ***********************/
  396.  
  397.  
  398.