home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / main / maclook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-01  |  8.6 KB  |  341 lines  |  [TEXT/CWIE]

  1. /*
  2. *    maclook.c
  3. *    User interface code for NCSA Telnet for the Macintosh
  4. *     by Gaige B. Paulsen
  5. *****************************************************************
  6. *    NCSA Telnet for the Macintosh                                *
  7. *                                                                *
  8. *    National Center for Supercomputing Applications                *
  9. *    Software Development Group                                    *
  10. *    152 Computing Applications Building                            *
  11. *    605 E. Springfield Ave.                                        *
  12. *    Champaign, IL  61820                                        *
  13. *                                                                *
  14. *    Copyright (c) 1986-1992,                                    *
  15. *    Board of Trustees of the University of Illinois                *
  16. *****************************************************************
  17. *
  18. *   User interface for basic telnet with background file transfer
  19. *   capabilities via FTP calls from host.
  20. *
  21. *    This, the Macintosh version also gives each session its own window,
  22. *    provides advanced keyboard translation, Tek emulation, printing/copying
  23. *    of text and graphics and the pasting of text into the active session.
  24. *
  25. *        Requires:
  26. *    menu.c    - Aux. file for handling menu calls
  27. *    event.c    - Aux. file for handling events
  28. *    switch.c- Aux. file for handling swithcher  (the J word is in Event and here )
  29. *
  30. *
  31. *    Revisions:
  32. *    7/92 Telnet 2.6: added support for the 2 global structs, and put all the 
  33. *                    cursors into one array.  Cleaned up defines            Scott Bulmahn
  34. */
  35.  
  36. #ifdef MPW
  37. #pragma segment 4
  38. #endif
  39.  
  40.  
  41. #define PREFMASTER                    /* So pref structure gets defined Scott! */
  42.  
  43.  
  44. #include "netevent.proto.h"
  45. #include "wind.h"
  46. #include "event.proto.h"
  47. #include "macutil.proto.h"
  48. #include "popup.h"
  49. #include "popup.proto.h"
  50.  
  51. #include "rsinterf.proto.h"
  52. #include "vsdata.h"
  53. #include "vskeys.h"
  54. #include "vsinterf.proto.h"
  55. #include "vgtek.proto.h"
  56. #include "tekrgmac.proto.h"
  57. #include "vr.h"
  58. #include "vrrgmac.proto.h" 
  59. #include "network.proto.h"
  60. #include "mydnr.proto.h"
  61. #include "menuseg.proto.h"
  62. #include "prefs.proto.h"
  63. #include "maclook.proto.h"
  64. #include "DlogUtils.proto.h"
  65. #include "telneterrors.h"
  66.  
  67. extern    Cursor *theCursors[];
  68. extern    WindRec
  69.     *screens;        /* Window Records (VS) for :    Current Sessions */
  70.  
  71. extern    short    scrn;
  72. //extern    char    *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  73.  
  74. void MiscUnload(void) {}
  75.  
  76. short detachGraphics( short dnum)
  77. {
  78.     short i=0;
  79.  
  80.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  81.     if (i>=TelInfo->numwindows) return(-1);
  82.     TelInfo->oldgraph[TelInfo->graphs++]=dnum;
  83.     screens[i].curgraph=-1;
  84.     screens[i].termstate=VTEKTYPE;
  85.     screens[i].enabled=1;
  86.     RGdetach(dnum);
  87.     return(0);
  88. }
  89.  
  90. /* Find screen index by Window */
  91. short    WindowPtr2ScreenIndex(WindowPtr wn)
  92. {
  93.     short    i=0;
  94.  
  95.     while((i<TelInfo->numwindows) && (wn!= (WindowPtr)screens[i].wind)) i++;
  96.     if (i>=TelInfo->numwindows) return(-1);
  97.     return(i);
  98. }
  99.  
  100. WindRecPtr    WindowPtr2WindRecPtr(WindowPtr wn)
  101. {
  102.     short    winNum;
  103.     
  104.     winNum = WindowPtr2ScreenIndex(wn);
  105.     
  106.     if (winNum == -1) {
  107.         return nil;
  108.         }
  109.         
  110.     return &screens[winNum];
  111. }
  112.  
  113. /* Find screen index by VS Number */
  114. short findbyVS( short vs)
  115. {
  116.     short i=0;
  117.  
  118.     while((i<TelInfo->numwindows) && (vs!=screens[i].vs)) i++;
  119.     if (i>=TelInfo->numwindows) return(-1);
  120.     return(i);
  121. }
  122.  
  123. void setgraphcurs( void)                /* Called at start of gin */
  124. {
  125.     TelInfo->ginon=1;
  126.     updateCursor(1);
  127. }
  128.  
  129. void unsetgraphcurs( void)                /* Called at start of gin */
  130. {
  131.     TelInfo->ginon=0;
  132.     updateCursor(1);
  133. }
  134.  
  135. short VGalive( short dnum)
  136. {
  137.     short i;
  138.  
  139.     i=0;
  140.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  141.     if (i<TelInfo->numwindows) {
  142.         return(1);
  143.         }
  144.     else {
  145.         i=0;
  146.         while ((i<TelInfo->graphs) && (dnum!=TelInfo->oldgraph[i])) i++;
  147.         if (i<TelInfo->graphs)
  148.             return(1);
  149.         }
  150.     return(0);
  151. }
  152.  
  153. void destroyGraphics( short dnum)
  154. {
  155.     short i;
  156.  
  157.     i=0;
  158.     while((i<TelInfo->numwindows) && (dnum!=screens[i].curgraph)) i++;
  159.     if (i<TelInfo->numwindows) {
  160.         screens[i].curgraph=-1;
  161.         screens[i].termstate=VTEKTYPE;
  162.         screens[i].enabled=1;
  163.         }
  164.     else {
  165.         i=0;
  166.         while ((i<TelInfo->graphs) && (dnum!=TelInfo->oldgraph[i])) i++;
  167.         while (i<(MaxGraph-1))
  168.             TelInfo->oldgraph[i]=TelInfo->oldgraph[++i];            /* Bump everyone down one slot */
  169.         TelInfo->graphs--;                                /* One less graph to feed */
  170.         }
  171.     VGclose( dnum);
  172. }
  173.  
  174. short FindByVG(short vg)
  175. {
  176.     short i=0;
  177.  
  178.     while((i<TelInfo->numwindows) && (vg!=screens[i].curgraph)) i++;
  179.     if (i>=TelInfo->numwindows) return(-1);
  180.     return(i);
  181. }
  182.  
  183. void TekEnable( short vg)
  184. {
  185.     short change;
  186.  
  187.     change=FindByVG( vg);
  188.     if (change>=0)
  189.         screens[change].enabled=1;
  190. }
  191.  
  192. void    TekDisable( short vg)
  193. {
  194.     short change;
  195.  
  196.     change=FindByVG( vg);
  197.     if (change>=0)
  198.         screens[change].enabled=0;
  199. }
  200.  
  201. /* showNetNumbers    - Show the current network numbers. */
  202. void showNetNumbers( void)
  203. {
  204.     char        tmpout[30];            /* IP Number */
  205.  
  206.     DialogPtr    dptr;                /* dialog box pointer */
  207.     short        scratchshort;
  208.     int            tmp[4];                /* Integer copy of IP Number */
  209.     unsigned char tmp2[4];
  210.     
  211.     netgetip(tmp2);
  212.     for(scratchshort=0; scratchshort<4; scratchshort++)
  213.             tmp[scratchshort] = (int)tmp2[scratchshort];        /* Get integer numbers */
  214.  
  215.     sprintf(&tmpout[0],"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  216.                                         /* create Human-readable numbers */
  217.  
  218.  
  219.     c2pstr(tmpout);                                    /* BYU LSC */
  220.  
  221.     ParamText(0L, (StringPtr)tmpout,0L,0L);                /* BYU LSC - Put Parms in Dlog */
  222.     
  223.     dptr = GetNewMyDialog(MyIPDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  224.     DrawDialog(dptr);                            /* Display Dialog */
  225.  
  226.     ModalDialog(NULL, &scratchshort);            /* Wait for a click */
  227.  
  228.     DisposDialog(dptr);
  229. }
  230.  
  231. /*******************************************************************/
  232. /*  setupkeys
  233. *   Prompt the user for which keys to use for kill, stop and start.
  234. */
  235.  
  236. void setupkeys( void)
  237. {
  238.     DialogPtr dtemp;
  239.     Rect dBox;
  240.     short dItem,kItem,sItem,eItem;
  241.     Handle kbox,sbox,ebox;
  242.     
  243.     char *tempspot;
  244.     
  245.     tempspot = (char *) myNewPtr(256);
  246.     if (tempspot == NULL)
  247.         return; //BUGG signal error here
  248.         
  249.     dtemp=GetNewMyDialog( SetupDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  250.  
  251.     SetCursor(theCursors[normcurs]);
  252.     
  253.     GetDItem( dtemp, killbox, &kItem, &kbox, &dBox);    
  254.     GetDItem( dtemp, stopbox, &eItem, &ebox, &dBox);    
  255.     GetDItem( dtemp, startbox, &sItem, &sbox, &dBox);    
  256.  
  257.     *tempspot = 0;
  258.     if (screens[scrn].TELstop > 0) {
  259.         sprintf(tempspot,"^%c",screens[scrn].TELstop^64);
  260.         c2pstr(tempspot);                                    /* BYU LSC */
  261.         SetIText( ebox , (StringPtr)tempspot);
  262.         SelIText( dtemp, stopbox, 0, 32767);
  263.         }
  264.     if (screens[scrn].TELgo > 0) {
  265.         sprintf(tempspot,"^%c",screens[scrn].TELgo^64);
  266.         c2pstr(tempspot);                                    /* BYU LSC */
  267.         SetIText( sbox , (StringPtr)tempspot);
  268.         SelIText( dtemp, startbox, 0, 32767);
  269.         }
  270.     if (screens[scrn].TELip > 0) {
  271.         sprintf(tempspot,"^%c",screens[scrn].TELip^64);
  272.         c2pstr(tempspot);                                    /* BYU LSC */
  273.         SetIText( kbox , (StringPtr)tempspot);
  274.         SelIText( dtemp, killbox, 0, 32767);
  275.         }
  276.     
  277.         dItem=0;                                /* initially no hits */
  278.         while((dItem>3) || (dItem==0)) {        /* While we are in the loop */
  279.             ModalDialog(DLOGwOK_CancelUPP,&dItem);
  280.  
  281. /*
  282. *  intermediate check.  If they hit a key, put its number in the box.
  283. */
  284.             GetIText( kbox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  285.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  286.             if (*tempspot < 32 && *tempspot > 0) {
  287.                 sprintf(tempspot,"^%c",*tempspot^64);
  288.                 c2pstr(tempspot);                        /* BYU LSC */
  289.                 SetIText( kbox , (StringPtr)tempspot);                /* BYU LSC */
  290.                 SelIText( dtemp, killbox, 0, 32767 );
  291.                 }
  292.             GetIText( ebox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  293.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  294.             if (*tempspot < 32 && *tempspot > 0) {
  295.                 sprintf(tempspot,"^%c",*tempspot^64);
  296.                 c2pstr(tempspot);                        /* BYU LSC */
  297.                 SetIText( ebox , (StringPtr)tempspot);                /* BYU LSC */
  298.                 SelIText( dtemp, stopbox, 0, 32767);
  299.                 }
  300.             GetIText( sbox, (StringPtr)tempspot);                    /* BYU LSC - Get the string */
  301.             p2cstr((StringPtr)tempspot);                            /* BYU LSC */
  302.             if (*tempspot < 32 && *tempspot > 0) {
  303.                 sprintf(tempspot,"^%c",*tempspot^64);
  304.                 c2pstr(tempspot);                        /* BYU LSC */
  305.                 SetIText( sbox , (StringPtr)tempspot);                /* BYU LSC */
  306.                 SelIText( dtemp, startbox, 0, 32767);
  307.                 }
  308.                 
  309.             }
  310.                 
  311.     
  312.         if (dItem==DLOGCancel) {
  313.             DisposDialog( dtemp);
  314.             return;
  315.             }
  316.             
  317.         GetIText( kbox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  318.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  319.         if (*tempspot != '^') 
  320.             screens[scrn].TELip = -1;
  321.         else
  322.             screens[scrn].TELip = toupper(*(tempspot+1)) ^ 64;
  323.             
  324.         GetIText( ebox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  325.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  326.         if (*tempspot != '^') 
  327.             screens[scrn].TELstop = -1;
  328.         else
  329.             screens[scrn].TELstop = toupper(*(tempspot+1)) ^ 64;
  330.  
  331.         GetIText( sbox, (StringPtr)tempspot);            /* BYU LSC - Get the string */
  332.         p2cstr((StringPtr)tempspot);                    /* BYU LSC */
  333.         if (*tempspot != '^') 
  334.             screens[scrn].TELgo = -1;
  335.         else
  336.             screens[scrn].TELgo = toupper(*(tempspot+1)) ^ 64;
  337.             
  338.     DisposDialog( dtemp);
  339.     updateCursor(1);
  340. }
  341.