home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc095.zip / ckmscr.c < prev    next >
C/C++ Source or Header  |  1989-08-22  |  10KB  |  331 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. extern CHAR filnam[];
  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 = -1;
  55.     scrnak = scrpkt = 0;
  56.     scrpacln = scrcksum = scrwinsz = 0;
  57.     SetStrText (SRES_DIR, (protocmd == SEND_FIL) ? "   Sending" : "Receiving",
  58.         scrdlg);
  59.     miniparser (TRUE);        /* keep things moving */
  60. }                /* scrcreate */
  61.  
  62.  
  63.  
  64. /****************************************************************************/
  65. /* scrdispose - called to finish up the status display, on a
  66.  *                  transaction complete screen() call.
  67.  */
  68. /****************************************************************************/
  69. scrdispose (wait)
  70. Boolean wait;
  71. {
  72.     int i;
  73.     EventRecord dummyEvt;
  74.  
  75.     if (scrdlg == NULL)
  76.     printerr ("scrdispose called with no screen active!", 0);
  77.  
  78.     SysBeep (1);
  79.  
  80.     if (wait) {            /* deactivate buttons */
  81.     HiliteControl (getctlhdl (SRES_CANF, scrdlg), 255);
  82.     HiliteControl (getctlhdl (SRES_CANG, scrdlg), 255);
  83.  
  84.     if (tlevel < 0)    {    /* if no takefile running */
  85.  
  86.         SetStrText (SRES_ITEXT, "Type a key or click the mouse to continue.",
  87.             scrdlg);    /* yes, so set the text */
  88.         /*
  89.          * wait for mouse or key down and discard the event when it
  90.          * happens
  91.          */
  92.         while (!GetNextEvent (keyDownMask + mDownMask, &dummyEvt))
  93.          /* do nothing */ ;
  94.     }
  95.     }
  96.     DisposDialog (scrdlg);
  97.     scrdlg = NULL;
  98. }                /* scrdispose */
  99.  
  100.  
  101.  
  102. /* ststrings - translation of SCR_ST subfunctions to descriptive text */
  103.  
  104. char *ststrings[] = {
  105.     ": Transferred OK",        /* ST_OK */
  106.     ": Discarded",        /* ST_DISC */
  107.     ": Interrupted",        /* ST_INT */
  108.     ": Skipped ",        /* ST_SKIP */
  109.     ": Fatal error"        /* ST_ERR */
  110. };
  111.  
  112. /* scrtosresnum - table to translate from SCR_XXX values into resource
  113.  *                     item numbers.  Entries we aren't interested in are
  114.  *                  set to SRES_UNDEF.
  115.  */
  116.  
  117. int scrtoresnum[] = {
  118.     SRES_UNDEF,            /* 0 - nothing */
  119.     SRES_FILN,            /* SCR_FN - filename */
  120.     SRES_AFILN,            /* SCR_AN - as filename */
  121.     SRES_UNDEF,            /* SCR_FS - file size */
  122.     SRES_UNDEF,            /* SCR_XD - x-packet data */
  123.     SRES_PTEXT,            /* SCR_ST - status (goes in prev. text area) */
  124.     SRES_UNDEF,            /* SCR_PN - packet number */
  125.     SRES_UNDEF,            /* SCR_PT - packet type (special) */
  126.     SRES_BTEXT,            /* SCR_TC - transaction complete */
  127.     SRES_ITEXT,            /* SCR_EM - error msg (does alert) */
  128.     SRES_ITEXT,            /* SCR_WM - warning message */
  129.     SRES_BTEXT,            /* SCR_TU - arb text */
  130.     SRES_BTEXT,            /* SCR_TN - arb text */
  131.     SRES_BTEXT,            /* SCR_TZ - arb text */
  132.     SRES_BTEXT,            /* SCR_QE - arb text */
  133.     SRES_ITEXT            /* SCR_DT - date text */
  134. };
  135.  
  136. /****************************************************************************/
  137. /* screen - display status information on the screen during protocol.
  138.  *            Here we just set the items in their StatText dialog boxes,
  139.  *            updates occur through the miniparser, which we are nice
  140.  *            enough to call here to handle things.
  141.  *
  142.  */
  143. /****************************************************************************/
  144. screen (f, c, n, s)
  145. int f;
  146. char c;
  147. char *s;
  148. long n;
  149. {
  150.     int rnum;
  151.     long i;
  152.     int itype;
  153.     Handle ihdl;
  154.     Rect ibox;
  155.     char buf[256];
  156.     extern int spktl, rln, bctu, wslots;
  157.     static char last_st = ST_OK;/* PWP: saves the most recent value of the
  158.                  * status indication */
  159.  
  160.     miniparser (TRUE);        /* keep the mac going */
  161.  
  162. #ifdef COMMENT
  163.     if (f == SCR_EM) {        /* error message? (warnings go into dialog) */
  164.     printerr (s, 0);    /* display it */
  165.     return;            /* and return */
  166.     }
  167. #endif
  168.     
  169.     if ((scrdlg == NULL) || quiet)    /* not using it or silent? */
  170.     return;            /* but nothing for us to do */
  171.  
  172.     if (f == SCR_FN) {        /* seeing a file name? */
  173.     SetStrText (SRES_AFILN, "", scrdlg);    /* and the name also */
  174.     if (protocmd == RECV_FIL ||    /* seeing a file name from */
  175.         protocmd == GETS_FIL)    /* a receive command? */
  176.         dorecvdialog (s, &cmarg2);    /* yes, allow user to do dialog */
  177.     }
  178.     rnum = scrtoresnum[f];    /* load default DITL number */
  179.     /* where result will be posted */
  180.  
  181.     switch (f) {        /* according to function... */
  182.       case SCR_WM:        /* warning message */
  183.       case SCR_EM:
  184.     SysBeep(3);        /* get the user's attention */
  185.     Delay ((long) 10, &i);
  186.     SysBeep(3);
  187.     Delay ((long) 10, &i);
  188.     SysBeep(3);
  189.     if (n != 0L) {
  190.         strcpy (buf, s);
  191.         strcat (buf, " ");
  192.         s = &buf[strlen(buf)];
  193.         NumToString(n, s);
  194.         s = buf;
  195.     }
  196.     break;
  197.       
  198.       case SCR_AN:        /* "AS" name is comming */
  199.     if ((filargs.filflg & (FIL_RSRC | FIL_DATA)) == (FIL_RSRC | FIL_DATA)) {
  200.         /* in MacBinary mode */
  201.         SetStrText (SRES_FFORK, "", scrdlg);
  202.         SetStrText (SRES_FMODE, "MacBinary Mode", scrdlg);
  203.     } else {
  204.         SetStrText (SRES_FFORK, (filargs.filflg & FIL_RSRC) ?
  205.             "RSRC Fork" : "Data Fork", scrdlg);
  206.         SetStrText (SRES_FMODE, (filargs.filflg & FIL_BINA) ?
  207.             "Binary Mode" : "Text Mode", scrdlg);
  208.     }
  209.     break;
  210.  
  211.       case SCR_PT:        /* packet type? */
  212.     /* packet length */
  213.     if (protocmd == SEND_FIL) {    /* sent a packet, see ckcfn2.c, spack() */
  214.         i = spktl-bctu;
  215.         if (i+2 <= MAXPACK) i += 2;    /* short packet */
  216.     } else {        /* recieved a packet -- see ckcfn2.c, rpack() */
  217.         i = rln + bctu;
  218.         if (rln <= MAXPACK)    /* if it was a short packet */
  219.         i += 2;        /* then add space for SEQ and TYPE */
  220.     }
  221.     if (i != scrpacln) {
  222.         scrpacln = i;
  223.         NumToString (scrpacln, buf);    /* PWP: do xmit length */
  224.         SetStrText (SRES_PACSZ, buf, scrdlg);
  225.     }
  226.     /* checksum type */
  227.     if (bctu != scrcksum) {
  228.         scrcksum = bctu;
  229.         NumToString (scrcksum, buf);    /* PWP: and rec length */
  230.         SetStrText (SRES_CKSUM, buf, scrdlg);
  231.     }
  232.     /* window size */
  233.     if (wslots != scrwinsz) {
  234.         scrwinsz = wslots;
  235.         NumToString (scrwinsz, buf);    /* PWP: and rec length */
  236.         SetStrText (SRES_WINSZ, buf, scrdlg);
  237.     }
  238.     if (c == 'Y')
  239.         return;        /* don't do anything for yaks */
  240.  
  241.     if (c == 'N' || c == 'Q' ||    /* check for all types of */
  242.         c == 'T' || c == '%')    /* NAK */
  243.         i = ++scrnak, rnum = SRES_NRTY; /* increment nak counter */
  244.     else
  245.         i = ++scrpkt, rnum = SRES_NPKT; /* else increment pkt counter */
  246.  
  247.     NumToString (i, buf);    /* translate to number */
  248.     s = buf;        /* new buffer */
  249.     break;            /* all done */
  250.  
  251.       case SCR_ST:        /* status */
  252.     last_st = c;        /* PWP: save for later */
  253.     if (f == ST_SKIP)
  254.         strcpy(buf, s);
  255.     else
  256.         strcpy (buf, filnam);    /* file name; should be same as filargs.fillcl */
  257.     strcat (buf, ststrings[c]);    /* add status */
  258.     s = buf;
  259.     SetStrText (SRES_BTEXT, "", scrdlg);    /* clear eg. remote size */
  260.     SetStrText (SRES_ITEXT, "", scrdlg);    /* clear eg. date */
  261.     break;
  262.  
  263.       case SCR_TC:        /* transaction completed */
  264.     if (!server) {        /* are we a server? */
  265.         scrdispose (last_st != ST_OK); /* if not, dispose the screen */
  266.         return;        /* and we are done */
  267.     }
  268.     s = "Server transaction complete";
  269.     break;
  270.  
  271. #ifdef COMMENT
  272.       case SCR_DT:        /* file creation date */
  273.         strcpy (buf, "Creation date: __/__/__ ");
  274.     buf[15] = s[4];
  275.     buf[16] = s[5];
  276.     buf[18] = s[6];
  277.     buf[19] = s[7];
  278.     buf[21] = s[2];
  279.     buf[22] = s[3];
  280.     strcat (buf, &s[8]);
  281.     s = buf;
  282.     break;
  283. #endif /* COMMENT */
  284.  
  285.       case SCR_QE:        /* quantity equals */
  286.         strcpy (buf, s);
  287.     strcat (buf, " = ");
  288.     s = &buf[strlen(buf)];
  289.     NumToString(n, s);
  290.     /* p2cstr(s); */
  291.     s = buf;
  292.     scrck = -1;    /* force update of # Ks transfered */
  293.     break;
  294.     }
  295.  
  296.     if (rnum != SRES_UNDEF)    /* have DITL number for this? */
  297.     SetStrText (rnum, s, scrdlg);    /* yes, so set the text */
  298.  
  299.     if ((i = ffc / 1024) != scrck) {    /* more K's xmitted (or new val)? */
  300.     scrck = i;        /* remember new value */
  301.     NumToString (scrck, buf);    /* convert to number */
  302.     if (fsize != 0) {    /* know the size? (only local or w/attrs) */
  303.         strcat (buf, "/");    /* make it be a fraction */
  304.         NumToString (fsize / 1024,    /* figure this one out (was filargs.filsiz) */
  305.              (char *) buf + strlen (buf));
  306.     }
  307.     SetStrText (SRES_KXFER, buf, scrdlg);    /* set new value */
  308.     }
  309. }                /* screen */
  310.  
  311.  
  312.  
  313. /****************************************************************************/
  314. /* scrmydlg - handle dialog events occuring in the screen (status)
  315.  *              dialog.  Called by the miniparser when a dialog event
  316.  *              occurs and we are supposed to handle it.
  317.  */
  318. /****************************************************************************/
  319. scrmydlg (item)
  320. int item;
  321. {
  322.     switch (item) {
  323.       case SRES_CANF:
  324.     cxseen = TRUE;
  325.     break;
  326.       case SRES_CANG:
  327.     czseen = TRUE;
  328.     break;
  329.     }
  330. }                /* scrmydlg */
  331.