home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c-kermit / ckmscr.pwp < prev    next >
Text File  |  2020-01-01  |  14KB  |  516 lines

  1. /* $Id: ckmscr.c,v 1.6 91/12/15 23:17:52 rick Exp $
  2.  * $Source: /uw/mackermit/RCS/ckmscr.c,v $
  3.  *------------------------------------------------------------------
  4.  * $Log:    ckmscr.c,v $
  5.  * Revision 1.6  91/12/15  23:17:52  rick
  6.  * ut9
  7.  * 
  8.  * Revision 1.5  91/10/13  13:43:38  rick
  9.  * UT(7)
  10.  * 
  11.  * Revision 1.4  91/09/25  12:17:34  rick
  12.  * Command window in TE. Multiple vt100 windows for command window.
  13.  * 
  14.  * Revision 1.3  91/09/12  21:50:53  rick
  15.  * UT(3). Install on watsun
  16.  * 
  17.  * Revision 1.2  1991/09/10  22:21:48  rick
  18.  * Update to UTexas(2)
  19.  *
  20.  * Revision 1.1  1991/09/10  19:18:05  rick
  21.  * Initial revision
  22.  *
  23.  *------------------------------------------------------------------
  24.  * $Endlog$
  25.  */
  26.  
  27. /* Version 0.8(35) - Jim Noble at Planning Research Corporation, June 1987. */
  28. /* Ported to Megamax native Macintosh C compiler. */
  29. /* Edit by Bill on Wed May 15, 15:53 */
  30. /* A K is 1024 not 512 */
  31.  
  32. /*
  33.  * file ckmscr.c
  34.  *
  35.  * Module of mackermit containing code for display of status dialog.
  36.  *
  37.  * Bill Schilit, May 1984
  38.  *
  39.   Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
  40.   York.  Permission is granted to any individual or institution to use this
  41.   software as long as it is not sold for profit.  This copyright notice must be
  42.   retained.  This software may not be included in commercial products without
  43.   written permission of Columbia University.
  44.  */
  45.  
  46. #include "ckcdeb.h"        /* C kermit debuggig */
  47. #include "ckcker.h"        /* general kermit defs */
  48.  
  49. #include "ckmdef.h"        /* General Mac defs */
  50. #include "ckmres.h"        /* Mac resource equates */
  51. #include "ckmptp.h"        /* ckm* Prototypes */
  52.  
  53. static int scrpkt, scrnak;        /* NAK, PKT counts */
  54. static long scrck;            /* char (K) count */
  55. static int scrpacln, scrcksum, scrwslots, scrbufnum;
  56.                 /* pkt len, checksum, win size */
  57. static long scrfsize, scrffc;
  58. static long saved_fsize;
  59. static DialogPtr scrdlg = (DialogPtr) NULL;    /* screen's dialog */
  60.  
  61. extern CHAR filnam[];
  62.  
  63. void update_scr_therm();
  64. static pascal void draw_screen_xfr_therm (WindowPtr win, short itemno);
  65.  
  66. /****************************************************************************/
  67. /* scrcreate - create the status display.  Called when a protocol
  68.  *               menu item is selected and a display is desired (I don't
  69.  *               think you'd want to see this for REMOTE command).
  70.  *
  71.  */
  72. /****************************************************************************/
  73. scrcreate ()
  74. {
  75.     Rect itemr;
  76.     short itype;
  77.     Handle itemhdl;
  78.  
  79.     if (scrdlg != NULL)
  80.     printerr ("scrcreate with active screen!", 0);
  81.  
  82.     scrdlg = GetNewDialog (SCRBOXID, NILPTR, (WindowPtr) -1);
  83.     scrck = -1;
  84.     scrnak = scrpkt = 0;
  85.     scrpacln = scrcksum = 0;
  86.     scrwslots = scrbufnum = -1;
  87.     scrfsize = scrffc = -1;
  88.     saved_fsize = -1;
  89.     ffc = 0;
  90.     
  91.     SetStrText (SRES_PTTXT,
  92.         "\pEmergency exit: hold down \021 and type a period.",
  93.             scrdlg);    /* yes, so set the text */
  94.  
  95.     SetStrText (SRES_DIR, (protocmd == SEND_REMO) ? "\p   Sending"
  96.                           : "\pReceiving",
  97.         scrdlg);
  98.  
  99.     GetDItem (scrdlg, SRES_THERM, &itype, &itemhdl, &itemr);
  100.     SetDItem (scrdlg, SRES_THERM, itype, (Handle) draw_screen_xfr_therm,
  101.           &itemr);
  102.     update_scr_therm();
  103.  
  104.     miniparser (TRUE);        /* keep things moving */
  105. }                /* scrcreate */
  106.  
  107.  
  108.  
  109. /****************************************************************************/
  110. /* scrdispose - called to finish up the status display, on a
  111.  *                  transaction complete screen() call.
  112.  */
  113. /****************************************************************************/
  114. scrdispose (wait)
  115. Boolean wait;
  116. {
  117.     EventRecord dummyEvt;
  118.  
  119.     if (scrdlg == NULL)
  120.     printerr ("scrdispose called with no screen active!", 0);
  121.  
  122.     SysBeep (3);
  123.  
  124.     if (wait) {            /* deactivate buttons */
  125.     HiliteControl (getctlhdl (SRES_CANF, scrdlg), 255);
  126.     HiliteControl (getctlhdl (SRES_CANG, scrdlg), 255);
  127.  
  128.     if (tlevel < 0)    {    /* if no takefile running */
  129.         SetStrText (SRES_PTTXT,
  130.             "\pType a key or click the mouse to continue.",
  131.             scrdlg);    /* yes, so set the text */
  132.  
  133.         /*
  134.          * wait for mouse or key down and discard the event when it
  135.          * happens
  136.          */
  137.         while (!GetNextEvent (keyDownMask + mDownMask, &dummyEvt))
  138.          /* do nothing */ ;
  139.     }
  140.     } else {
  141.     SetStrText (SRES_PTTXT, "\pNormal cleanupè",  scrdlg);
  142.     }
  143.  
  144.     DisposDialog (scrdlg);
  145.     scrdlg = NULL;
  146. }                /* scrdispose */
  147.  
  148. void
  149. update_scr_therm()
  150. {
  151.     GrafPtr savePort;
  152.     
  153.     GetPort (&savePort);    /* there just has to be a better way */
  154.     SetPort (scrdlg);
  155.  
  156.     draw_screen_xfr_therm (scrdlg, SRES_THERM);
  157.  
  158.     SetPort (savePort);        /* there just has to be a better way */    
  159. }
  160.  
  161. static pascal void
  162. draw_screen_xfr_therm (WindowPtr win, short itemno)
  163. {
  164.     Rect r, itemr;
  165.     short itype;
  166.     Handle itemhdl;
  167.     PenState oldpenstate;
  168.  
  169.     if (itemno != SRES_THERM)        /* Shouldn't ever happen */
  170.         return;
  171.  
  172.     GetPenState(&oldpenstate);        /* save so we can fuss with */
  173.     PenNormal();
  174.     
  175.     GetDItem (scrdlg, itemno, &itype, &itemhdl, &itemr);
  176.     
  177.     /* EraseRect(&itemr); */
  178.  
  179.     if (saved_fsize <= 0L) {
  180.  
  181.         /* Frame the thermometer in gray */
  182.     PenPat(qd.gray);
  183.     PenSize (2, 2);
  184.     FrameRect(&itemr);
  185.     InsetRect(&itemr, 2, 2);
  186.     
  187.     EraseRect(&itemr);
  188.     
  189.     } else {
  190.  
  191.         /* Frame the thermometer */
  192.     PenSize (2, 2);
  193.     FrameRect(&itemr);
  194.  
  195.     InsetRect(&itemr, 2, 2);
  196.     PenPat (qd.white);
  197.     FrameRect(&itemr);
  198.     
  199.     InsetRect(&itemr, 2, 2);
  200.         
  201.     /*
  202.      * We want to fill first (ffc / saved_fsize) of
  203.      * (itemr.right - itemr.left) 
  204.      * with black, and the rest with gray.
  205.      */
  206.     
  207.     r.top = itemr.top;
  208.     r.bottom = itemr.bottom;
  209.     r.left = itemr.left;
  210.     r.right = itemr.left
  211.           + (((long) (itemr.right - itemr.left) * (long) ffc)
  212.              / (long) saved_fsize);
  213.     if (r.right > itemr.right)        /* reality check */
  214.         r.right = itemr.right;
  215.     
  216.     if (r.left < r.right)            /* has any been transfered? */
  217.         FillRect (&r, qd.dkGray);
  218.     
  219.     if (r.right < itemr.right) {    /* any left to transfer? */
  220.         r.left = r.right;
  221.         r.right = itemr.right;
  222.         FillRect (&r, qd.ltGray);
  223.     }
  224.     }
  225.     
  226.     scrfsize = saved_fsize;
  227.     scrffc = ffc;
  228.     
  229.     SetPenState(&oldpenstate);        /* restore old pen state */
  230. }
  231.  
  232.  
  233. /* ststrings - translation of SCR_ST subfunctions to descriptive text */
  234.  
  235. char *ststrings[] = {
  236.     ": Transferred OK",        /* ST_OK */
  237.     ": Discarded",        /* ST_DISC */
  238.     ": Interrupted",        /* ST_INT */
  239.     ": Skipped ",        /* ST_SKIP */
  240.     ": Fatal error"        /* ST_ERR */
  241. };
  242.  
  243. /* scrtosresnum - table to translate from SCR_XXX values into resource
  244.  *                     item numbers.  Entries we aren't interested in are
  245.  *                  set to SRES_UNDEF.
  246.  */
  247.  
  248. int scrtoresnum[] = {
  249.     SRES_UNDEF,            /* 0 - nothing */
  250.     SRES_FILN,            /* SCR_FN - filename */
  251.     SRES_AFILN,            /* SCR_AN - as filename */
  252.     SRES_UNDEF,            /* SCR_FS - file size */
  253.     SRES_UNDEF,            /* SCR_XD - x-packet data */
  254.     SRES_PTEXT,            /* SCR_ST - status (goes in prev. text area) */
  255.     SRES_UNDEF,            /* SCR_PN - packet number */
  256.     SRES_UNDEF,            /* SCR_PT - packet type (special) */
  257.     SRES_BTEXT,            /* SCR_TC - transaction complete */
  258.     SRES_ITEXT,            /* SCR_EM - error msg (does alert) */
  259.     SRES_ITEXT,            /* SCR_WM - warning message */
  260.     SRES_BTEXT,            /* SCR_TU - arb text */
  261.     SRES_BTEXT,            /* SCR_TN - arb text */
  262.     SRES_BTEXT,            /* SCR_TZ - arb text */
  263.     SRES_BTEXT,            /* SCR_QE - arb text */
  264.     SRES_ITEXT            /* SCR_DT - date text */
  265. };
  266.  
  267. /****************************************************************************/
  268. /* screen - display status information on the screen during protocol.
  269.  *            Here we just set the items in their StatText dialog boxes,
  270.  *            updates occur through the miniparser, which we are nice
  271.  *            enough to call here to handle things.
  272.  *
  273.  */
  274. /****************************************************************************/
  275. VOID screen (f, c, n, s)
  276. int f;
  277. char c;
  278. char *s;
  279. long n;
  280. {
  281.     int rnum;
  282.     long i;
  283.     char buf[256];
  284.     extern int spktl, rln, bctu, wslots;
  285.     static char last_st = ST_OK;/* PWP: saves the most recent value of the
  286.                  * status indication */
  287.     static char got_err = 0; /* becomes true if we get an error message */
  288.  
  289.     miniparser (TRUE);        /* keep the mac going */
  290.  
  291. #ifdef COMMENT
  292.     if (f == SCR_EM) {        /* error message? (warnings go into dialog) */
  293.     printerr (s, 0);    /* display it */
  294.     return;            /* and return */
  295.     }
  296. #endif
  297.     
  298.     if ((scrdlg == NULL) || quiet)    /* not using it or silent? */
  299.     return;            /* but nothing for us to do */
  300.  
  301.     if (f == SCR_FN) {        /* seeing a file name? */
  302.     SetStrText (SRES_AFILN, "\p", scrdlg);    /* and the name also */
  303.     if (protocmd == RECV_REMO ||    /* seeing a file name from */
  304.         protocmd == GETS_REMO)            /* a receive command? */
  305.         dorecvdialog (s, &cmarg2);    /* yes, allow user to do dialog */
  306.     }
  307.     rnum = scrtoresnum[f];    /* load default DITL number */
  308.     /* where result will be posted */
  309.  
  310.     switch (f) {        /* according to function... */
  311.       case SCR_EM:        /* error message */
  312.       case SCR_WM:        /* warning message */
  313.     got_err = 1;
  314.     SysBeep(3);        /* get the user's attention */
  315.     Delay ((long) 10, &i);
  316.     SysBeep(3);
  317.     Delay ((long) 10, &i);
  318.     SysBeep(3);
  319.     if (n != 0L) {
  320.         strcpy (buf, s);
  321.         strcat (buf, " ");
  322.         s = &buf[strlen(buf)];
  323.         NumToString(n, s);
  324.         p2cstr(s);
  325.         s = buf;
  326.     }
  327.     break;
  328.       
  329.       case SCR_FN:
  330.     got_err = 0;    /* reset for this file */
  331.     SetStrText (SRES_BTEXT, "\p", scrdlg);    /* clear eg. remote size */
  332.     SetStrText (SRES_ITEXT, "\p", scrdlg);    /* clear eg. date */
  333.     break;
  334.  
  335.       case SCR_AN:        /* "AS" name is comming */
  336.     if ((filargs.filflg & (FIL_RSRC | FIL_DATA)) == (FIL_RSRC | FIL_DATA))
  337.     {
  338.         /* in MacBinary mode */
  339.         SetStrText (SRES_FFORK, "\p", scrdlg);
  340.         SetStrText (SRES_FMODE, "\pMacBinary Mode", scrdlg);
  341.     } else {
  342.         SetStrText (SRES_FFORK, (filargs.filflg & FIL_RSRC) ?
  343.             "\pRSRC Fork" : "\pData Fork", scrdlg);
  344.         SetStrText (SRES_FMODE, (filargs.filflg & FIL_BINA) ?
  345.             "\pBinary Mode" : "\pText Mode", scrdlg);
  346.     }
  347.     break;
  348.  
  349.       case SCR_FS:        /* File Size */
  350.         saved_fsize = n;    /* we put the stuff on the screen below */
  351.     break;
  352.  
  353.       case SCR_PT:        /* packet type? */
  354.     /* packet length */
  355.     if (protocmd == SEND_REMO) {  /* sent a packet -- ckcfn2.c, spack() */
  356.         i = spktl-bctu;
  357.         if (i+2 <= MAXPACK) i += 2;    /* short packet */
  358.     } else {        /* recieved a packet -- ckcfn2.c, rpack() */
  359.         i = rln + bctu;
  360.         if (rln <= MAXPACK)    /* if it was a short packet */
  361.         i += 2;        /* then add space for SEQ and TYPE */
  362.     }
  363.     if (i != scrpacln) {
  364.         scrpacln = i;
  365.         SetNumText (SRES_PACSZ, scrpacln, scrdlg);
  366.                 /* PWP: do xmit length */
  367.     }
  368.     /* checksum type */
  369.     if (bctu != scrcksum) {
  370.         scrcksum = bctu;
  371.         SetNumText (SRES_CKSUM, scrcksum, scrdlg);
  372.                 /* PWP: and rec length */
  373.     }
  374.     
  375.     /* window size */
  376.     if ((wslots != scrwslots)
  377.         || ((protocmd == SEND_REMO) && (sbufnum != scrbufnum))
  378.         || ((protocmd != SEND_REMO) && (rbufnum != scrbufnum)))
  379.     {
  380.         char *cp;
  381.  
  382.         scrwslots = wslots;
  383.         if (protocmd == SEND_REMO)
  384.         scrbufnum = sbufnum;
  385.         else
  386.         scrbufnum = rbufnum;
  387.  
  388.         NumToString ((wslots - scrbufnum), buf);    /* convert to number */
  389.         p2cstr(buf);
  390.         strcat (buf, "/");    /* make it be a fraction */
  391.         cp = (char *) buf + strlen (buf);
  392.         NumToString (scrwslots, cp);
  393.         p2cstr(cp);
  394.         c2pstr(buf);    /* convert whole buf back into string */
  395.         SetStrText (SRES_WINSZ, buf, scrdlg);    /* set new values */
  396.     }
  397.     
  398.     if (c == 'Y')
  399.         return;        /* don't do anything for yaks */
  400.  
  401.     if (c == 'N' || c == 'Q' ||    /* check for all types of */
  402.         c == 'T' || c == '%')    /* NAK */
  403.         i = ++scrnak, rnum = SRES_NRTY; /* increment nak counter */
  404.     else
  405.         i = ++scrpkt, rnum = SRES_NPKT; /* else increment pkt counter */
  406.  
  407.     NumToString (i, buf);    /* translate to number */
  408.     p2cstr(buf);
  409.     s = buf;        /* new buffer */
  410.     break;            /* all done */
  411.  
  412.       case SCR_ST:        /* status */
  413.     last_st = c;        /* PWP: save for later */
  414.     if (f == ST_SKIP)
  415.         strcpy(buf, s);
  416.     else
  417.         strcpy (buf, filnam);
  418.                  /* file name; should be same as filargs.fillcl */
  419.     strcat (buf, ststrings[c]);    /* add status */
  420.     s = buf;
  421. #ifdef COMMENT
  422.     SetStrText (SRES_BTEXT, "\p", scrdlg);    /* clear eg. remote size */
  423.     SetStrText (SRES_ITEXT, "\p", scrdlg);    /* clear eg. date */
  424. #endif
  425.     break;
  426.  
  427.       case SCR_TC:        /* transaction completed */
  428.     if (!server) {        /* are we a server? */
  429.         /* if not, dispose the screen */
  430.         scrdispose ((last_st != ST_OK) || got_err);
  431.         got_err = 0;    /* reset this */
  432.         return;        /* and we are done */
  433.     }
  434.     s = "Server transaction complete";
  435.     break;
  436.  
  437. #ifdef COMMENT
  438.       case SCR_DT:        /* file creation date */
  439.         strcpy (buf, "Creation date: __/__/__ ");
  440.     buf[15] = s[4];
  441.     buf[16] = s[5];
  442.     buf[18] = s[6];
  443.     buf[19] = s[7];
  444.     buf[21] = s[2];
  445.     buf[22] = s[3];
  446.     strcat (buf, &s[8]);
  447.     s = buf;
  448.     break;
  449. #endif /* COMMENT */
  450.  
  451.       case SCR_QE:        /* quantity equals */
  452.         strcpy (buf, s);
  453.     strcat (buf, " = ");
  454.     s = &buf[strlen(buf)];
  455.     NumToString(n, s);
  456.     p2cstr(s);
  457.     s = buf;
  458.     scrck = -1;    /* force update of # Ks transfered */
  459.     break;
  460.     }
  461.  
  462.     if (rnum != SRES_UNDEF)    /* have DITL number for this? */
  463.     SetStrText (rnum, c2p_tmp(s), scrdlg);    /* yes, so set the text */
  464.  
  465.     if ((scrfsize != saved_fsize) || (scrffc != ffc))
  466.         update_scr_therm();
  467.  
  468.     /* more K's xmitted (or new val)? */
  469.     if ((i = (ffc + 512) / 1024) != scrck) {
  470.     scrck = i;        /* remember new value */
  471.     NumToString (scrck, buf);    /* convert to number */
  472.     p2cstr(buf);
  473.     if (saved_fsize > 0) {    /* know the size? (only local or w/attrs) */
  474.         char *cp;
  475.         strcat (buf, "/");    /* make it be a fraction */
  476.         cp = (char *) buf + strlen (buf);
  477.         NumToString ((saved_fsize + 512) / 1024,    /* figure this out */
  478.              cp);
  479.         p2cstr(cp);
  480.  
  481.     }
  482.     c2pstr(buf);
  483.     SetStrText (SRES_KXFER, buf, scrdlg);    /* set new value */
  484.     }
  485. }                /* screen */
  486.  
  487.  
  488.  
  489. /****************************************************************************/
  490. /* scrmydlg - handle dialog events occuring in the screen (status)
  491.  *              dialog.  Called by the miniparser when a dialog event
  492.  *              occurs and we are supposed to handle it.
  493.  */
  494. /****************************************************************************/
  495. scrmydlg (item)
  496. int item;
  497. {
  498.     switch (item) {
  499.       case SRES_CANF:
  500.     cxseen = TRUE;
  501.     break;
  502.       case SRES_CANG:
  503.     czseen = TRUE;
  504.     break;
  505.     }
  506. }                /* scrmydlg */
  507.  
  508. /*
  509.  * Junk so Emacs will set local variables to be compatible with Mac/MPW.
  510.  * Should be at end of file.
  511.  * 
  512.  * Local Variables:
  513.  * tab-width: 4
  514.  * End:
  515.  */
  516.