home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc072.zip / ckmscr.c < prev    next >
C/C++ Source or Header  |  1988-08-16  |  9KB  |  267 lines

  1. /* Version 0.8(35) - Jim Noble at Planning Research Corporation, June 1987. */
  2. /* Ported to Megamax native Macintosh C compiler. */
  3. /* Edit by Bill on Wed May 15, 15:53 */
  4. /* A K is 1024 not 512 */
  5.  
  6. /*
  7.  * file ckmscr.c
  8.  *
  9.  * Module of mackermit containing code for display of status dialog.
  10.  *
  11.  * Bill Schilit, May 1984
  12.  *
  13.  * Copyright (C) 1985, Trustees of Columbia University in the City of
  14.  * New York.  Permission is granted to any individual or institution to
  15.  * use, copy, or redistribute this software so long as it is not sold
  16.  * for profit, provided this copyright notice is retained.
  17.  *
  18.  */
  19.  
  20. #include "ckcdeb.h"        /* C kermit debuggig */
  21. #include "ckcker.h"        /* general kermit defs */
  22.  
  23. #define    __SEG__ ckmscr
  24. #include <controls.h>
  25. #include <dialogs.h>
  26. #include <osutils.h>
  27. #include <events.h>
  28.  
  29. #include "ckmdef.h"        /* General Mac defs */
  30. #include "ckmres.h"        /* Mac resource equates */
  31.  
  32. int scrpkt, scrnak;        /* NAK, PKT counts */
  33. long scrck;            /* char (K) count */
  34. int scrpacln, scrcksum, scrwinsz;    /* pkt len, checksum, win size */
  35. DialogPtr scrdlg = (DialogPtr) NULL;    /* screen's dialog */
  36.  
  37.  
  38.  
  39. /****************************************************************************/
  40. /* scrcreate - create the status display.  Called when a protocol
  41.  *               menu item is selected and a display is desired (I don't
  42.  *               think you'd want to see this for REMOTE command).
  43.  *
  44.  */
  45. /****************************************************************************/
  46. scrcreate ()
  47. {
  48.     char *s;
  49.  
  50.     if (scrdlg != NULL)
  51.     printerr ("scrcreate with active screen!", 0);
  52.  
  53.     scrdlg = GetNewDialog (SCRBOXID, NILPTR, (WindowPtr) - 1);
  54.     scrck = scrnak = scrpkt = 0;
  55.     SetStrText (SRES_DIR, (protocmd == SEND_FIL) ? "   Sending" : "Receiving",
  56.         scrdlg);
  57.     miniparser (TRUE);        /* keep things moving */
  58. }                /* scrcreate */
  59.  
  60.  
  61.  
  62. /****************************************************************************/
  63. /* scrdispose - called to finish up the status display, on a
  64.  *                  transaction complete screen() call.
  65.  */
  66. /****************************************************************************/
  67. scrdispose (wait)
  68. Boolean wait;
  69. {
  70.     int i;
  71.     EventRecord dummyEvt;
  72.  
  73.     if (scrdlg == NULL)
  74.     printerr ("scrdispose called with no screen active!", 0);
  75.  
  76.     SysBeep (1);
  77.  
  78.     if (wait) {            /* deactivate buttons */
  79.     HiliteControl (getctlhdl (SRES_CANF, scrdlg), 255);
  80.     HiliteControl (getctlhdl (SRES_CANG, scrdlg), 255);
  81.  
  82.     if (tlevel < 0)        /* if no takefile running */
  83.  
  84.         /*
  85.          * wait for mouse or key down and discard the event when it
  86.          * happens
  87.          */
  88.         while (!GetNextEvent (keyDownMask + mDownMask, &dummyEvt))
  89.          /* do nothing */ ;
  90.     }
  91.     DisposDialog (scrdlg);
  92.     scrdlg = NULL;
  93. }                /* scrdispose */
  94.  
  95.  
  96.  
  97. /* ststrings - translation of SCR_ST subfunctions to descriptive text */
  98.  
  99. char *ststrings[] = {
  100.     "Transferred OK",        /* ST_OK */
  101.     "Discarded",        /* ST_DISC */
  102.     "Interrupted",        /* ST_INT */
  103.     "Skipped ",            /* ST_SKIP */
  104.     "Fatal error"        /* ST_ERR */
  105. };
  106.  
  107. /* scrtosresnum - table to translate from SCR_XXX values into resource
  108.  *                     item numbers.  Entries we aren't interested in are
  109.  *                  set to SRES_UNDEF.
  110.  */
  111.  
  112. int scrtoresnum[] = {
  113.     SRES_UNDEF,            /* 0 - nothing */
  114.     SRES_FILN,            /* SCR_FN - filename */
  115.     SRES_AFILN,            /* SCR_AN - as filename */
  116.     SRES_UNDEF,            /* SCR_FS - file size */
  117.     SRES_UNDEF,            /* SCR_XD - x-packet data */
  118.     SRES_BTEXT,            /* SCR_ST - status */
  119.     SRES_UNDEF,            /* SCR_PN - packet number */
  120.     SRES_UNDEF,            /* SCR_PT - packet type (special) */
  121.     SRES_BTEXT,            /* SCR_TC - transaction complete */
  122.     SRES_UNDEF,            /* SCR_EM - error msg (does alert) */
  123.     SRES_UNDEF,            /* SCR_WM - warning message */
  124.     SRES_BTEXT,            /* SCR_TU - arb text */
  125.     SRES_BTEXT,            /* SCR_TN - arb text */
  126.     SRES_BTEXT,            /* SCR_TZ - arb text */
  127.     SRES_BTEXT            /* SCR_QE - arb text */
  128. };
  129.  
  130. /****************************************************************************/
  131. /* screen - display status information on the screen during protocol.
  132.  *            Here we just set the items in their StatText dialog boxes,
  133.  *            updates occur through the miniparser, which we are nice
  134.  *            enough to call here to handle things.
  135.  *
  136.  */
  137. /****************************************************************************/
  138. screen (f, c, n, s)
  139. int f;
  140. char c;
  141. char *s;
  142. long n;
  143. {
  144.     int rnum;
  145.     long i;
  146.     int itype;
  147.     Handle ihdl;
  148.     Rect ibox;
  149.     char buf[256];
  150.     extern int spktl, rln, bctu, wsize;
  151.     static char last_st = ST_OK;/* PWP: saves the most recent value of the
  152.                  * status indication */
  153.  
  154.     miniparser (TRUE);        /* keep the mac going */
  155.  
  156.     if (f == SCR_EM || f == SCR_WM) {    /* error/warning message? */
  157.     printerr (s, 0);    /* display it */
  158.     return;            /* and return */
  159.     }
  160.     if ((scrdlg == NULL) || quiet)    /* not using it or silent? */
  161.     return;            /* but nothing for us to do */
  162.  
  163.     if (f == SCR_FN) {        /* seeing a file name? */
  164.     SetStrText (SRES_AFILN, "", scrdlg);    /* and the name also */
  165.     if (protocmd == RECV_FIL ||    /* seeing a file name from */
  166.         protocmd == GETS_FIL)    /* a receive command? */
  167.         dorecvdialog (s, &cmarg2);    /* yes, allow user to do dialog */
  168.     }
  169.     rnum = scrtoresnum[f];    /* load default DITL number */
  170.     /* where result will be posted */
  171.  
  172.     switch (f) {        /* according to function... */
  173.       case SCR_AN:        /* "AS" name is comming */
  174.     SetStrText (SRES_FFORK, (filargs.filflg & FIL_RSRC) ?
  175.             "RSRC Fork" : "Data Fork", scrdlg);
  176.     SetStrText (SRES_FMODE, (filargs.filflg & FIL_BINA) ?
  177.             "Binary Mode" : "Text Mode", scrdlg);
  178.     break;
  179.  
  180.       case SCR_PT:        /* packet type? */
  181.     /* packet length */
  182.     i = (spktl > rln) ? spktl : rln;
  183.     if (i != scrpacln) {
  184.         scrpacln = i;
  185.         NumToString (scrpacln, buf);    /* PWP: do xmit length */
  186.         SetStrText (SRES_PACSZ, buf, scrdlg);
  187.     }
  188.     /* checksum type */
  189.     if (bctu != scrcksum) {
  190.         scrcksum = bctu;
  191.         NumToString (scrcksum, buf);    /* PWP: and rec length */
  192.         SetStrText (SRES_CKSUM, buf, scrdlg);
  193.     }
  194.     /* window size */
  195.     if (wsize != scrwinsz) {
  196.         scrwinsz = wsize;
  197.         NumToString (scrwinsz, buf);    /* PWP: and rec length */
  198.         SetStrText (SRES_WINSZ, buf, scrdlg);
  199.     }
  200.     if (c == 'Y')
  201.         return;        /* don't do anything for yaks */
  202.  
  203.     if (c == 'N' || c == 'Q' ||    /* check for all types of */
  204.         c == 'T' || c == '%')    /* NAK */
  205.         i = ++scrnak, rnum = SRES_NRTY; /* increment nak counter */
  206.     else
  207.         i = ++scrpkt, rnum = SRES_NPKT; /* else increment pkt counter */
  208.  
  209.     NumToString (i, buf);    /* translate to number */
  210.     s = buf;        /* new buffer */
  211.     break;            /* all done */
  212.  
  213.       case SCR_ST:        /* status */
  214.     last_st = c;        /* PWP: save for later */
  215.     if (c == ST_SKIP) {    /* if skipped... */
  216.         strcpy (buf, ststrings[c]);    /* there is something else */
  217.         strcat (buf, s);    /* add in filename */
  218.         s = buf;
  219.     } else
  220.         s = ststrings[c];    /* use subfunction description */
  221.     break;
  222.  
  223.       case SCR_TC:        /* transaction completed */
  224.     if (!server) {        /* are we a server? */
  225.         scrdispose (last_st != ST_OK); /* if not, dispose the screen */
  226.         return;        /* and we are done */
  227.     }
  228.     s = "Server transaction complete";
  229.     break;
  230.     }
  231.  
  232.     if (rnum != SRES_UNDEF)    /* have DITL number for this? */
  233.     SetStrText (rnum, s, scrdlg);    /* yes, so set the text */
  234.  
  235.     if ((i = ffc / 1024) != scrck) {    /* more K's xmitted (or new val)? */
  236.     scrck = i;        /* remember new value */
  237.     NumToString (scrck, buf);    /* convert to number */
  238.     if (filargs.filsiz != 0) {    /* know the size? (only local) */
  239.         strcat (buf, "/");    /* make it be a fraction */
  240.         NumToString (filargs.filsiz / 1024,    /* figure this one out */
  241.              (char *) buf + strlen (buf));
  242.     }
  243.     SetStrText (SRES_KXFER, buf, scrdlg);    /* set new value */
  244.     }
  245. }                /* screen */
  246.  
  247.  
  248.  
  249. /****************************************************************************/
  250. /* scrmydlg - handle dialog events occuring in the screen (status)
  251.  *              dialog.  Called by the miniparser when a dialog event
  252.  *              occurs and we are supposed to handle it.
  253.  */
  254. /****************************************************************************/
  255. scrmydlg (item)
  256. int item;
  257. {
  258.     switch (item) {
  259.       case SRES_CANF:
  260.     cxseen = TRUE;
  261.     break;
  262.       case SRES_CANG:
  263.     czseen = TRUE;
  264.     break;
  265.     }
  266. }                /* scrmydlg */
  267.