home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / Telnet 2.5.src.ThinkC / source / maclook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-26  |  73.7 KB  |  3,003 lines  |  [TEXT/MPS ]

  1. #ifndef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. #define NEWSLC 
  5. /*
  6. *    maclook.c
  7. *    User interface code for NCSA Telnet for the Macintosh
  8. *     by Gaige B. Paulsen
  9. ****************************************************************************
  10. *                                                                          *
  11. *      Uses    :                                                               *
  12. *      TCP/IP kernel for NCSA Telnet                                       *
  13. *      by Tim Krauskopf                                                    *
  14. *       with Macintosh code by Gaige B. Paulsen                                *
  15. *                                                                          *
  16. *      National Center for Supercomputing Applications                     *
  17. *      152 Computing Applications Building                                 *
  18. *      605 E. Springfield Ave.                                             *
  19. *      Champaign, IL  61820                                                *
  20. *                                                                          *
  21. *                                                                          *
  22. ****************************************************************************
  23. *
  24. *   User interface for basic telnet with background file transfer
  25. *   capabilities via FTP calls from host.
  26. *
  27. *    This, the Macintosh version also gives each session its own window,
  28. *    provides advanced keyboard translation, Tek emulation, printing/copying
  29. *    of text and graphics and the pasting of text into the active session.
  30. *
  31. *        Requires:
  32. *    config.c- Aux. file for handling telnet documents
  33. *    menu.c    - Aux. file for handling menu calls
  34. *    event.c    - Aux. file for handling events
  35. *    switch.c- Aux. file for handling swithcher  (the J word is in Event and here )
  36. */
  37.  
  38. /*
  39.  *    Files for inclusion.
  40.  */
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <stdlib.h>
  44.  
  45. #include    <Appletalk.h>
  46. #include    <Controls.h>
  47. #include    <CType.h>
  48. #include    <Desk.h>
  49. #include     <Devices.h>
  50. #include    <Dialogs.h>
  51. #include    <Events.h>
  52. #include    <Fonts.h>
  53. #include    <FCntl.h>
  54. #include    <Memory.h>
  55. #include    <Menus.h>
  56. #include    <Packages.h>
  57. #include    <Files.h>
  58. #include    <OSUtils.h>
  59. #include    <Quickdraw.h>
  60. #include    <Resources.h>
  61. #include    <SegLoad.h>
  62. /*#include     <Strings.h>        /* BYU LSC */
  63. #include    <TextEdit.h>
  64. #include    <ToolUtils.h>
  65. #include    <Types.h>
  66. #include    <Windows.h>
  67. #include    <OSEvents.h>
  68.  
  69. #include    "wind.h"
  70. #include    "configrec.h"
  71. #include    "hostform.h"
  72. #include "event.h"
  73. #include "croft.h"
  74. #include "macutil.h"
  75. /*#include "atalk.h"            /* BYU 2.4.8 */
  76. #include "maclook.h"
  77. #define PREFMASTER
  78. #include    "prefs.h"
  79.  
  80. #include "whatami.h"
  81. #include "rsmac.h"
  82. #include "confile.h"
  83. #include    "vsdata.h"
  84. #include    "vskeys.h"
  85. #include "vsinterf.h"
  86. #include "vgtek.h"
  87. #include "tekrgmac.h"
  88. #include "rr.h"
  89. #include "vr.h"
  90. #include "vrrgmac.h" 
  91. #include "user.h"
  92. #include "util.h"
  93. #include "netevent.h"
  94. #include "config.h"
  95. #include "environ.h"
  96. #include "switch.h"
  97. #include "menu.h"
  98.  
  99. #ifdef MPW
  100. #include "mpw.h"
  101. #endif MPW
  102.  
  103. /*
  104.  *    Operation Governing Defines:
  105.  */
  106.  
  107. #define    MaxSess        20        /* The maximum number of sessions */
  108. #define    MaxGraph    30        /* Maximum number of graphics */
  109.  
  110.  
  111. /*
  112.  *    Emulation type defines
  113.  */
  114.  
  115. #define VTEKTYPE 1
  116. #define TEKTYPE 2
  117. #define DUMBTYPE 3
  118. #define RASTYPE 4
  119.  
  120.  
  121.     #define SLC 3 
  122.         #define SLC_NOSUPPORT    0
  123.         #define SLC_CANTCHANGE    1
  124.         #define SLC_VALUE        2
  125.         #define SLC_DEFAULT        3
  126.         #define SLC_LEVELBITS    3
  127.         #define SLC_AWK            128
  128.         #define SLC_SYNCH        1
  129.         #define SLC_BRK            2
  130.         #define SLC_IP            3
  131.         #define SLC_AO            4
  132.         #define SLC_AYT            5
  133.         #define SLC_EOR            6
  134.         #define SLC_ABORT        7
  135.         #define SLC_EOF            8
  136.         #define SLC_SUSP        9
  137.         #define SLC_EC            10
  138.         #define SLC_EL           11
  139.         #define SLC_EW           12
  140.         #define SLC_RP            13
  141.         #define SLC_LNEXT        14
  142.         #define SLC_XON            15
  143.         #define SLC_XOFF        16
  144.         #define SLC_FORW1        17
  145.         #define SLC_FORW2        18
  146.  
  147. /*
  148.  *    Font Height and width constants
  149.  */
  150. #define Fheight 11
  151. #define Fwidth 6
  152. #define Fright 480
  153.  
  154. #define DefFONT 4
  155. #define DefSIZE 9
  156. /*
  157.  *    Window constraints
  158.  */
  159.  
  160. #define MAXWINDOWHEIGHT 18+Fheight*24
  161. #define MAXWINDOWWIDTH  17+Fwidth*80+3
  162.  
  163. /*
  164.  *    Resource Defines
  165.  */
  166.  
  167.  
  168. #define    FirstDLOG    1023
  169. #define    AboutDLOG    256
  170. #define    ConnAttDLOG    258
  171. #define    ConnFalDLOG    303
  172. #define BadMaskDLOG    330
  173. #define BadIPDLOG    331
  174.  
  175. #define    GetParmDLOG    300
  176. #define GetDefDLOG 1300     /* Config net for MacTCP version */
  177. #define    GetParmIP    5        /* The IP number TE */
  178. #define GetParmHOST    10        /* The Default Host TE */
  179. #define    GetParmMASK    7        /* The Subnet Mask TE */
  180. #define    GetParmStat    3        /* The Static IP RB */
  181. #define    GetParmKDyn    4        /* The Dynamic IP RB */
  182. #define    GetParmUseM    6        /* The Use Mask CB */
  183.  
  184. #define    BadHostDLOG    301
  185. #define    BadHostQuit    3        /* The Quit Button */
  186. #define    BadHostCont    2        /* The Continue Button */
  187.  
  188.  
  189. #define RESOLVERERROR 128
  190. #define    GetDestDLOG    257
  191. #define    GDdest        3        /* The Destination filed in GetDest dialog */
  192.  
  193. #define    XferCURS    290
  194. #define    GINCURS        257
  195. #define    DbugCURS    268
  196. #define    POSCURS        256
  197.  
  198. #define    IPnumSTR    256
  199. #define    HostSTR        257
  200. #define    MaskSTR        258
  201.  
  202. #define    FTPlogWIND    257
  203.  
  204. /*
  205.  * Event Auxilliary Defines
  206.  */
  207.  
  208.  
  209.  
  210. /*
  211.  * ASCII character set defines
  212.  */
  213.  
  214. #define ESC            0x1b    /* the escape character */
  215. #define    BS            0x08    /* the backspace character */
  216. #define DEL            0x7f    /* the delete character */
  217. #define CR            0x0d    /* the carriage return character */
  218. #define LF            0x0a    /* the line feed character */
  219.  
  220.  
  221.  
  222. #define EDcopy        4        /* Edit Menu: Copy */
  223. #define EDpaste        5        /* Edit Menu: Paste */
  224. #define EDcopyt        7        /* Edit Menu: Copy Table */
  225. #define Edit    2
  226. #define    Emul        3        /*    Emulation Menu's position */
  227.  
  228. char *nospacemsg = "Can't get any space";    /* BYU LSC */
  229.  
  230. #ifdef OPTSDEBUG
  231. char *telstates[]={
  232.     "SE",
  233.     "NOP",
  234.     "DM",
  235.     "BREAK",
  236.     "IP",
  237.     "ABORT",
  238.     "AYT",
  239.     "ERASE CHAR",
  240.     "ERASE LINE",
  241.     "GO AHEAD",
  242.     "SB",
  243.     "WILL",
  244.     "WONT",
  245.     "DO",
  246.     "DONT"
  247. };
  248.  
  249. char *teloptions[256]={
  250.     "Binary",                /* 0 */
  251.     "Echo",
  252.     "Reconnection",
  253.     "Supress Go Ahead",
  254.     "Message Size Negotiation",
  255.     "Status",                /* 5 */
  256.     "Timing Mark",
  257.     "Remote Controlled Trans and Echo",
  258.     "Output Line Width",
  259.     "Output Page Size",
  260.     "Output Carriage-Return Disposition",    /* 10 */
  261.     "Output Horizontal Tab Stops",
  262.     "Output Horizontal Tab Disposition",
  263.     "Output Formfeed Disposition",
  264.     "Output Vertical Tabstops",
  265.     "Output Vertical Tab Disposition",        /* 15 */
  266.     "Output Linefeed Disposition",
  267.     "Extended ASCII",
  268.     "Logout",
  269.     "Byte Macro",
  270.     "Data Entry Terminal",                    /* 20 */
  271.     "SUPDUP",
  272.     "SUPDUP Output",
  273.     "Send Location",
  274.     "Terminal Type",
  275.     "End of Record",                        /* 25 */
  276.     "TACACS User Identification",
  277.     "Output Marking",
  278.     "Terminal Location Number",
  279.     "3270 Regime",
  280.     "X.3 PAD",                                /* 30 */
  281.     "Negotiate About Window Size",
  282.     "Terminal Speed",
  283.     "Toggle Flow Control",
  284.     "Linemode",
  285.     "X Display Location",                    /* 35 */
  286.     "36","37","38","39",
  287.     "40","41","42","43","44","45","46","47","48","49",
  288.     "50","51","52","53","54","55","56","57","58","59",
  289.     "60","61","62","63","64","65","66","67","68","69",
  290.     "70","71","72","73","74","75","76","77","78","79",
  291.     "80","81","82","83","84","85","86","87","88","89",
  292.     "90","91","92","93","94","95","96","97","98","99",
  293.     "100","101","102","103","104","105","106","107","108","109",
  294.     "110","111","112","113","114","115","116","117","118","119",
  295.     "120","121","122","123","124","125","126","127","128","129",
  296.     "130","131","132","133","134","135","136","137","138","139",
  297.     "140","141","142","143","144","145","146","147","148","149",
  298.     "150","151","152","153","154","155","156","157","158","159",
  299.     "160","161","162","163","164","165","166","167","168","169",
  300.     "170","171","172","173","174","175","176","177","178","179",
  301.     "180","181","182","183","184","185","186","187","188","189",
  302.     "190","191","192","193","194","195","196","197","198","199",
  303.     "200","201","202","203","204","205","206","207","208","209",
  304.     "210","211","212","213","214","215","216","217","218","219",
  305.     "220","221","222","223","224","225","226","227","228","229",
  306.     "230","231","232","233","234","235","236","237","238","239",
  307.     "240","241","242","243","244","245","246","247","248","249",
  308.     "250","251","252","253","254",
  309.     "Extended Options List"        /* 255 */
  310. };
  311.  
  312. char *LMoptions[]={
  313.     "None",
  314.     "SYNCH",
  315.     "BREAK",
  316.     "IP",
  317.     "ABORT OUTPUT",
  318.     "AYT",
  319.     "EOR",
  320.     "ABORT",
  321.     "EOF",
  322.     "SUSP",
  323.     "EC",
  324.     "EL",
  325.     "EW",
  326.     "RP",
  327.     "LNEXT",
  328.     "XON",
  329.     "XOFF",
  330.     "FORW1",
  331.     "FORW2",
  332.     "MCL",
  333.     "MCR",
  334.     "MCWL",
  335.     "MCWR",
  336.     "MCBOL",
  337.     "MCEOL",
  338.     "INSRT",
  339.     "OVER",
  340.     "ECR",
  341.     "EWR",
  342.     "EBOL",
  343.     "EEOL"
  344. };
  345.  
  346. char *LMflags[]={
  347.     "NOSUPPORT",
  348.     "CANTCHANGE",
  349.     "VALUE",
  350.     "DEFAULT"
  351. };
  352. #endif
  353.  
  354.  
  355.  
  356. #define MAXVG 20 /* maximum number of VG windows */
  357.  
  358. #ifdef SMTP            /* External Var for SMTP */
  359. extern int smnum;
  360. #endif
  361.  
  362. /*
  363.  *    Type declarations for Globals
  364.  */
  365. Cursor
  366.     *gincurs,        /* Cursor when in graphics input mode */
  367.     *xfercurs,        /* Cursor when in transfer mode */
  368.     *normcurs,        /* Cursor for non-transfer normal mode */
  369.     *textcurs,        /* Cursor for text mode */
  370.     *poscurs,        /* Cursor for positioning mode */
  371.     *watchcurs,        /* Cursor for time-taking operations */
  372.     *graphcurs;        /* Cursor for graphics windows */
  373. Rect
  374.     screenRect,        /* The whole screen */
  375.     dragRect,        /* Where it is legal to drag ourselves */
  376.     SizRect;        /* How big/small our windows can be */
  377. Str255
  378.     *defaultd,        /* Default host name */
  379.     *dvs;            /* Default Volume/directory specification */
  380.  
  381. WindRec
  382.     *screens,        /* Window Records (VS) for :    Current Sessions */
  383.     ftplog,            /*                                FTP Log             */
  384.     console;        /*                                console Window   */
  385.  
  386. int
  387.     SettingsFile=-1,/* The Resource Reference Number of the Settings file */
  388.     neton    = 0,    /* Has the network been set up right? */
  389.     ginon   = 0,    /* True if we are in GIN mode */
  390.     xferon  = 0,    /* Is a transfer in progress */
  391.     dynamic = 0,    /* not dynamic by default.... */
  392.     userlevel=0,    /* The user privelege level... 0 allows reconfig on fly */
  393.     numwindows=0,    /* Number of active window structures (note: not windows ) */
  394.     scrn=0,            /* Currently active screen */
  395.     graphs=0,        /* How many detached graphs do we have */
  396.     oldgraph[MaxGraph],    /* Storage for old Graph numbers */
  397.     debug=1,            /* Flag for debugging 1=active */
  398.     done=0,            /* Are we done yet 0=not */
  399.     net_okay,        /* BYU serial */
  400.     KIP=0,            /* is KIP gateway present */
  401.     ipn[4];            /* The real IP number */
  402.  
  403. long
  404.     defmask,        /* The network mask as per defaults contingent on the IP */
  405.     mynetmask;        /* The network mask as per user config */
  406.  
  407. unsigned char
  408.     TermType[32],    /* Termtype to send */
  409.     myipnum[4];        /* My IP number (internal) */
  410. AddrBlock
  411.     KIPserver;        /* KIP gateway address */
  412.  
  413. long *DirTree;        /* BYU LSC */
  414. char *mungbuf;
  415. int
  416.     cmask,            /* Are we using a custom mask */
  417.     err;            /* Error variable */
  418.  
  419. OSErr io;
  420.  
  421. extern int            /* BYU */
  422.     RGMalloc();        /* BYU */
  423.  
  424. extern void         /* BYU */
  425.     init_mb_files(),/* BYU */
  426.     AdjustMenus(),    /* BYU */
  427.     VGalloc();        /* BYU */
  428.  
  429. extern MenuHandle    myMenus[];
  430. #define COnext        1        /* Connection Menu: Next Session... */
  431. #define Conn        5        /*    Connection Menu's position */
  432.  
  433. extern VSscrn *VSIw;
  434.  
  435. void DoTheMenuChecks();
  436. /*
  437.  *    Type declarations for functions
  438.  */
  439.  
  440. int
  441.     getWDnum();
  442. char
  443. /*    *strncpy(),            /* BYU LSC */
  444.     *neterrstring();
  445. Str255
  446.     *getWDname();
  447. pascal void
  448.     VersionNumber(),
  449.     OutlineItem(),
  450.     ScrollProc();
  451. pascal int
  452.     modalProc();
  453.  
  454. GrafPtr
  455.     RSgetwindow();
  456.  
  457. extern short             /* BYU 2.4.15 */
  458.     slip_connection;    /* BYU 2.4.15 */
  459.  
  460. extern Boolean        /* BYU LSC */
  461.     HFSflag;        /* BYU LSC - True if HFS is active/ false if not */
  462.  
  463. extern int
  464.     whichMenus,        /* Are we commanded or not ?*/
  465.     EtherNet;        /* The all-powerful! */
  466. extern
  467. SysEnvRec
  468.     theWorld;        /* The state of the machine address */
  469. extern
  470. char
  471.     *VERSION;        /* Version Information */
  472.  
  473. #ifdef JOHN_DEERE
  474.     int jdp;
  475. #endif
  476.  
  477. void UItemAssign
  478.   (
  479.     DialogPtr dlog,
  480.     int item,
  481.     int (*proc)()
  482.   ) /* sets the handler for a user item to the specified procedure. */
  483. {
  484.     Rect ibox;
  485.     char **ihndl;
  486.     short typ;
  487.  
  488.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  489.     SetDItem( dlog, item,  typ, (Handle) proc, &ibox);
  490. }
  491.  
  492. void HostIsAppl
  493.   (
  494.     void
  495.   )
  496. {
  497.     Str255 fileName;
  498.     short dumint;
  499.     Handle dumlong;
  500.     char *nnmm, *from;
  501.     
  502.     GetAppParms( &fileName, &dumint, &dumlong);        /* BYU LSC */
  503.     nnmm = (char *) NewPtr( 64);
  504.     if (nnmm ==NULL) {
  505.         OtherError((char *) "\pCan't allocate space for",(char *) "\pdefault config.tel name");    /* BYU LSC */
  506.         quit();
  507.         }
  508.     from = (char *) &fileName;            /* BYU LSC - Convert to a real format... */
  509.  
  510.     from = strncpy( nnmm,from, 63);            /* Strcpy sort of ... */
  511.     nnmm[63]=0;
  512.     Shostfile(nnmm);
  513. }
  514.  
  515. /*
  516.  *            T h e        M  A  I  N            P r o g r a m
  517.  */
  518.  
  519. void initmac
  520.   (
  521.     void
  522.   )
  523. {
  524.     char **userstring;
  525.     EventRecord myEvent;
  526.     int i;
  527.  
  528.     InitGraf(&qd.thePort);
  529.     InitFonts();
  530.     InitWindows();
  531.     InitMenus();
  532.     TEInit();
  533.     InitDialogs(0L);
  534.     InitCursor();
  535.  
  536.     /* MaxApplZone(); */
  537.     MoreMasters();                    /* I want memory, */
  538.     MoreMasters();                    /* Lots of Memory, */
  539.     MoreMasters();                    /* I want ApplHeap, and SysHeap, and more */
  540.     MoreMasters();                    /* Give me handles, and pointers...... */
  541.     MoreMasters();
  542.     MoreMasters();
  543.     MoreMasters();
  544.  
  545. #if 0                                /* BYU LSC - was "#ifndef REAL" */
  546.     err=OpenResFile("\pncsa.rsrc");    /* BYU LSC - We don't want to RESedit too much */
  547. #endif
  548.  
  549.     InquireEnvironment();
  550.  
  551.     for (i=1;i<12;i++)
  552.         EventAvail( 0xffff, &myEvent);
  553.     setupmenu( 0);                /* Temporarily default to old menus.... */
  554.  
  555.     screenRect = qd.screenBits.bounds;            /* well, they have to be set */
  556.                                                 /* somewhere, where else ? */
  557.     SetRect(&dragRect, 4, 24, screenRect.right-4, screenRect.bottom-4);
  558.     SetRect(&SizRect,    10*Fwidth+18,  3 *Fheight+18,
  559.                         80*Fwidth+18, 24 *Fheight+18);
  560.  
  561.     userstring =GetResource('NCSA',1);
  562.  
  563.     if (userstring !=0L) {
  564.         userlevel= **userstring -'0';
  565.         if (userlevel<0) userlevel=32767;
  566.         if (userlevel>3) HostIsAppl();        /* Don't use config.tel <UAS> */
  567.         }
  568. }
  569.  
  570. /*
  571.  * checkdebug - check to see if they clicked on a debug file
  572.  */
  573.  
  574. int checkdebug
  575.   (
  576.     void
  577.   )
  578. {
  579.     short i,mess,count;
  580.     AppFile theFile;
  581.  
  582.     CountAppFiles(&mess,&count);
  583.     if (mess==1) return(FALSE);
  584.     if (count<1) return(FALSE);
  585.     for(i=1;i<=count;i++) {
  586.         GetAppFiles(i, &theFile);
  587.         if (theFile.fType=='DBUG') {
  588.             ClrAppFiles(i);
  589.             return(TRUE);
  590.             }
  591.         if (theFile.fType=='TEXT') {
  592.             char *nnmm, *from;
  593.             ClrAppFiles(i);
  594.             nnmm = (char *) NewPtr( 64);
  595.             if (nnmm ==NULL) {
  596.                 OtherError((char *) "\pCan't allocate space for",(char *) "\pdefault config.tel name");    /* BYU LSC */
  597.                 quit();
  598.                 }
  599.             from = (char *) &theFile.fName;            /* BYU LSC - Convert to a real format... */
  600.  
  601.             p2cstr(from);
  602.             from = strncpy( nnmm,from, 63);            /* Strcpy sort of ... */
  603.             nnmm[63]=0;
  604.             Shostfile(nnmm);
  605.             }
  606.         }
  607.     return(FALSE);
  608. }
  609.  
  610. void putln                                    /* Put a C string on the console */
  611.   (
  612.     char *cp
  613.   )
  614. {
  615.     int temp;
  616.  
  617.     if (!debug)
  618.         return;
  619.  
  620.     temp=strlen(cp);
  621.     if (temp>80) return;
  622.     VSwrite(console.vs,cp,temp);
  623.     VSwrite(console.vs,"\015\012",2);
  624. }
  625.  
  626. /*
  627.  *    initmcurs - Set up the mouse Cursors
  628.  *        NOTE: debug tells if the bug or the pointer is to be used as dflt.
  629.  */
  630.  
  631. void loadcursor
  632.   (
  633.     int CursorID,
  634.     CursPtr *result
  635.   )
  636.   /* copies a specified cursor from a resource into a nonrelocatable block
  637.     and returns a pointer to it in *result. */
  638.   {
  639.     CursHandle tempcurs;
  640.     OSErr Err;
  641.  
  642.     *result = nil;
  643.     do /* once */
  644.       {
  645.         tempcurs = GetCursor(CursorID);
  646.         Err = ResError();
  647.         if (Err != noErr)
  648.             break;
  649.         *result = (CursPtr) NewPtr(sizeof(Cursor));        /* BYU LSC */
  650.         Err = MemError();
  651.         if (Err != noErr)
  652.             break;
  653.         LoadResource((Handle) tempcurs); /* in case it was purged */
  654.         Err = ResError();
  655.         if (Err != noErr)
  656.             break;
  657.         BlockMove((Ptr) *tempcurs, (Ptr) *result, sizeof(Cursor));
  658.       }
  659.     while (false);
  660.     if (Err != noErr)
  661.       {
  662.         if (*result != nil)
  663.             DisposPtr((Ptr) *result);
  664.         *result = &qd.arrow;
  665.       }
  666.   } /* loadcursor */
  667.  
  668. void initmcurs
  669.   (
  670.     int debug
  671.   ) /* initializes all the mouse cursors for later use */
  672.   {
  673.     loadcursor(watchCursor, &watchcurs);
  674.     loadcursor(crossCursor, &graphcurs);
  675.     loadcursor(POSCURS, &poscurs);
  676.     loadcursor(iBeamCursor, &textcurs);
  677.     loadcursor(GINCURS, &gincurs);
  678.     loadcursor(XferCURS, &xfercurs);
  679.     if (debug)
  680.         loadcursor(DbugCURS, &normcurs);
  681.     else
  682.         normcurs = &qd.arrow;
  683.     SetCursor(normcurs);
  684.   }
  685.  
  686. /*
  687.  * initconsole - initialize the  console window
  688.  */
  689.  
  690. void initconsole
  691.   (
  692.     void
  693.   )
  694. {
  695.     Rect pRect;
  696.  
  697.     SetRect(&pRect,15,287,15+MAXWINDOWWIDTH /*495,335 */, 287+MAXWINDOWHEIGHT);
  698.     console.vs=RSnewwindow( &pRect, 50, 80, 24,
  699.                     (char *) "\p<console>", 1, DefFONT, DefSIZE, debug,0);    /* BYU LSC */
  700.     console.wind = RSgetwindow( console.vs);
  701.  
  702.     VSwrite(ftplog.vs,"\033[24;0H",1);        /* Move to bottom of screen */
  703.  
  704.     console.active=0;console.port=0;
  705.     console.termstate=VTEKTYPE;
  706.     console.name="<console>";
  707. }
  708.  
  709. /*
  710.  * initftplog - initialize the FTP log window
  711.  */
  712.  
  713. void initftplog
  714.   (
  715.     void
  716.   )
  717. {
  718.     Rect prect;
  719.  
  720.     SetRect(&prect, 300,256,512,384);
  721.  
  722.     ftplog.vs=RSnewwindow( &prect, 50, 80, 24,
  723.                     (char *) "\pFTP Log", 1, DefFONT, DefSIZE,0,0);    /* BYU LSC */
  724.     ftplog.wind = RSgetwindow( ftplog.vs);
  725.  
  726.     VSwrite(ftplog.vs,"\033[24;0H",7);        /* Move to bottom of screen */
  727.     ftplog.active=0;                         /* Meaningless */
  728.     ftplog.port=0;                            /* As is this */
  729.     ftplog.termstate=VTEKTYPE;
  730.     ftplog.name="FTP Log";                    /* And most of these */
  731.  
  732. }
  733.  
  734. /*
  735.  *    initwd - Initialize the working directory pointers
  736.  */
  737.  
  738. void initwd
  739.   (
  740.     void
  741.   )
  742. {
  743.     extern int defaultv;
  744.  
  745.     defaultv=getWDnum();
  746.     dvs=getWDname();
  747.     VSwrite(console.vs,(char *) &(*dvs)[1],(int) (*dvs)[0]);    /* BYU LSC */
  748. }
  749.  
  750. int ckhostfile
  751.   (
  752.     void
  753.   )
  754. {
  755.     DialogPtr dtemp;
  756.     char *from,*nnmm;
  757.     Point where;
  758.     SFReply sfr;
  759.     SFTypeList    sfl;
  760.     int temp=0;
  761.     short item=0;
  762.     Str255 *dir;
  763.  
  764.  
  765.     dtemp=GetNewDialog( BadHostDLOG,(Ptr) 0L,(WindowPtr) -1L);
  766.     while( item<1 || item>2 )
  767.         ModalDialog((ModalFilterProcPtr) modalProc ,&item);
  768.     DisposDialog(dtemp);
  769.  
  770.     if ( item==BadHostQuit ) return(-1);
  771.     if ( item==BadHostCont ) return(-1);        /* changed, continue not allowed */
  772.  
  773.     where.h=100; where.v=100;
  774.     sfl[0]='TEXT';                    /* All TEXT files are Game */
  775.  
  776.     SFGetFile( where, "\pSelect Host File:", 0L,1,sfl,0L,&sfr);    /* BYU LSC */
  777.  
  778.     if (!sfr.good) {
  779.         putln("got bad filename");    /* Possibly/Probably Cancel */
  780.         return(-1);
  781.         }
  782.  
  783.     SetVol( 0L, sfr.vRefNum);        /* BYU LSC - I like HFS, I like HFS, except when it is a pain */
  784.  
  785.     nnmm = (char *) NewPtr( 64);
  786.     if (nnmm ==NULL) {
  787.         OtherError((char *) "\pCan't allocate space for",(char *) "\pmodified config.tel name");    /* BYU LSC */
  788.         quit();
  789.         }
  790.     from = (char *) &sfr.fName;            /* BYU LSC - Convert to a real format... */
  791.  
  792.     p2cstr(from);
  793.     dir = getWDname();
  794.     (*dir)[++(*dir)[0]]='/';
  795.     VSwrite( console.vs, (char *) &(*dir)[1], (int) (*dir)[0]);    /* BYU LSC - Preview pathspec... */
  796.     putln(from );                        /* preview.... */
  797.  
  798.     from = strncpy( nnmm,from, 63);            /* Strcpy sort of ... */
  799.     nnmm[63]=0;
  800.  
  801.     Shostfile(nnmm);
  802.  
  803.     return(0);
  804. }
  805.  
  806. /*
  807.  * initnet - init all of the network stuff...
  808.  */
  809.  
  810. void initnet
  811.   (
  812.     int debug
  813.   )
  814. {
  815. #pragma unused(debug)
  816.     struct config conf;
  817.     int error;
  818.  
  819.     error=Snetinit();
  820.  
  821.     if (error!=0 && error!=-2) {            /* if cant find hosts file, give em another */
  822.         ShowAllErrors();
  823.         if (ckhostfile()) {            /* BYU */
  824.             quit();                    /* BYU - shot, if that fails.... */
  825.             return;                    /* BYU */
  826.             }                        /* BYU */
  827.         if (Snetinit()!=0)     {        /* Ok, but only one more chance or we'll.... */
  828.             HostIsAppl();
  829.             ShowAllErrors();
  830.     
  831.             error=Snetinit();
  832.             if (error!=0 && error!=-2) {
  833.                 ShowAllErrors();
  834.                 quit();                /* Squash 'em like a grape! */
  835.                 return;                /* BYU */
  836.                 }
  837.             }
  838.         }
  839.     if (error == -2)
  840.         reconfigNetwork(0);
  841.  
  842.     neton=1;
  843. /*    TickCount();                    /* BYU LSC */
  844.     Sgetconfig(&conf);
  845.     if (conf.comkeys)
  846.         whichMenus=1;
  847.     else
  848.         whichMenus=0;
  849.     strcpy((char *) TermType,(char *) conf.termtype);
  850.     switchMenus(whichMenus);
  851.  
  852.     if (conf.timesl>=0) JTime(conf.timesl);
  853.     if (conf.textblock > 0)  
  854.         setblocksize(conf.textblock);        /* network read-buffer size */
  855.     else 
  856.         setblocksize(120);
  857.  
  858. #ifdef SMTP
  859.     setSMTP();                        /* anyone wanna receive mail ? */
  860. #endif
  861.  
  862. }
  863.  
  864. main()
  865. {
  866.     DialogPtr dtemp;        /* Used for storage of the copyright dlog */
  867.  
  868.  
  869.     DirTree = (long *)NewPtr(256*sizeof(long));    /* BYU LSC */
  870.     mungbuf = (char *)NewPtr(1024);
  871.     
  872.     FlushEvents(everyEvent,0);
  873.     initmac();                /* initialize Macintosh stuff */
  874.  
  875.     debug=checkdebug();        /* must return TRUE or FALSE */
  876.  
  877.     initmcurs(debug);        /* init the mouse cursor */
  878.     SetCursor(watchcurs);
  879.  
  880.     if (RGMalloc()) {        /* BYU - save global space */
  881.         short item;
  882.         ParamText(0L, 0L, 0L, "\pInsufficient memory for TEK graphics");
  883.         dtemp = GetNewDialog(302, (Ptr) 0L, (WindowPtr) -1L);
  884.         ModalDialog(0L, &item);
  885.         DisposDialog(dtemp);
  886.         return;
  887.     }                        /* BYU */
  888.     VGalloc();                /* BYU - save global space */
  889.     VSinit(MaxSess+2);        /* initialize the Virtual Screen */
  890.     
  891.     screens = (WindRec *)NewPtr(MaxSess*sizeof(WindRec));
  892.  
  893.     initconsole();            /* allocate/initialize console screen */
  894.  
  895. /*    initEvents();            /* BYU 2.4.18 - Do Juggler stuff if necessary */
  896.  
  897.     dtemp=GetNewDialog(FirstDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* opening dialog */
  898.     UItemAssign( dtemp, 2, (int (*)()) VersionNumber);
  899.     putln("past version");
  900.     DrawDialog(dtemp);                /* while we init everything */
  901.  
  902.     initftplog();            /* allocate/initialize ftp log screen */
  903.     putln("past initftplog");
  904.     VGinit();                /* initialize Virtual Graphics after VS so that */
  905.                             /* init messages can come on console screen */
  906.     VRinit();
  907.     MacRGinit();
  908.     initwd();                /* init working/file transfer directory */
  909.  
  910.  
  911.     net_okay = TRUE;        /* BYU serial - assume okay (necessary for initnet()). */
  912.     initnet(debug);            /* initialize TK's network stuff */
  913.     if (done || !neton)        /* BYU serial */
  914.         net_okay = FALSE;    /* BYU serial */
  915.     else                    /* BYU serial */
  916.         net_okay = TRUE;    /* BYU serial */
  917.  
  918.     done = FALSE;            /* BYU serial */
  919.  
  920.     init_serial();            /* BYU serial */
  921.     initslip();                /* BYU 2.4.15 */
  922.  
  923.     init_mb_files();        /* BYU - initialize file id's to closed state */
  924.                     /* if initipnum() then FatalError("Can't run w/o IP number"); */
  925. /*    initipnum( Button() && (userlevel==1)); */
  926.  
  927.                                             /* get the IP number (w/reconfigure) */
  928.     SetCursor(normcurs);
  929.  
  930.     GetPrefs();                /* Load user preferences  (must be after initipnum) */
  931.     initEvents();            /* BYU 2.4.18 - Must be after GetPrefs() */
  932.     netgetip( myipnum);        /* Just in case it was RARPed */
  933.     initswitch();            /* initialize switcher stuff if necessary */
  934.  
  935.  
  936.     if (EtherNet == -99) {                            /* BYU 2.4.16 */
  937.         io = OpenResolver(NULL);                    /* BYU 2.4.16 */
  938.  
  939.         if (io) {                                    /* BYU 2.4.16 */
  940.             DialogPtr theErrDialog;                    /* BYU 2.4.16 */
  941.             short itemhit=0;                        /* BYU 2.4.16 */
  942.  
  943. /* BYU serial - "Unable to open resolver" message. */
  944.             theErrDialog = GetNewDialog(RESOLVERERROR,(Ptr)0L,(WindowPtr)-1L);    /* BYU 2.4.16 */
  945.             DrawDialog(theErrDialog);                                    /* BYU 2.4.16 */
  946.             while (!itemhit)                                             /* BYU 2.4.16 */
  947.                 ModalDialog((ModalFilterProcPtr) modalProc,&itemhit);    /* BYU 2.4.16 */
  948.             EtherNet = -100;                                            /* BYU 2.4.16 */
  949. /*            quit();                                    /* BYU 2.4.16 */
  950.         }                                            /* BYU 2.4.16 */
  951.     }                                                /* BYU 2.4.16 */
  952.  
  953. /*    Ssetgates();                    /* BYU serial - finishes IP inits */
  954.  
  955.     updateMenuChecks();
  956.     DoTheMenuChecks();
  957.     
  958.     if (!checkCONF())                 /* Configuration files? */
  959.         DrawDialog(dtemp);            /* while we init everything */
  960.  
  961.     DisposDialog(dtemp);            /* Take it off.....all off......*/
  962.  
  963. #ifdef JOHN_DEERE
  964.     jdp = netlisten( 2001,0);        /* BYU 2.4.15 */
  965. #endif
  966.  
  967.     do {                        /* BYU - Do this forever */
  968.                                             /* Getting a tad bit small..... */
  969.  
  970. #ifdef SMTP
  971.         rSMTPd();
  972. #endif
  973.         DoEvents();
  974.         if (!done) DoModem();                    /* BYU serial - watch serial port */
  975.         if (!done && net_okay) DoNetEvents();    /* BYU serial - act like the postman */
  976.  
  977.     } while (!done);            /* BYU mod */
  978. /*    quit();        /* BYU - TWIMC: this statement never used to execute */
  979. }
  980.  
  981. putstr(cp)                                    /* Put an STR255 on the console */
  982. char *cp;
  983. {
  984.     int temp;
  985.     temp = cp[0];
  986.     if (temp > 80)
  987.         return;
  988.     VSwrite(console.vs, &cp[1], temp);
  989.     VSwrite(console.vs, "\015\012", 2);
  990. }
  991.  
  992. vsput(c)                                    /* Put a single char on the console */
  993. char c;
  994. {
  995.     VSwrite(console.vs,&c,1);
  996. }
  997.  
  998. void ftpmess                                /* Put a C string on the console */
  999.   (
  1000.     char *cp
  1001.   )
  1002. {
  1003.     int temp;
  1004.     temp=strlen(cp);
  1005.     if (temp>80 || temp < 1) return;
  1006.     VSwrite(ftplog.vs,cp,temp);
  1007. }
  1008.  
  1009. int detachGraphics
  1010.   (
  1011.     int dnum
  1012.   )
  1013. {
  1014.     int i=0;
  1015.  
  1016.     while((i<numwindows) && (dnum!=screens[i].curgraph)) i++;
  1017.     if (i>=numwindows) return(-1);
  1018.     oldgraph[graphs++]=dnum;
  1019.     screens[i].curgraph=-1;
  1020.     screens[i].termstate=VTEKTYPE;
  1021.     screens[i].enabled=1;
  1022.     RGdetach(dnum);
  1023.     return(0);
  1024. }
  1025.  
  1026. int addport
  1027.   (
  1028.     ConfigRec *config
  1029.   )
  1030. {
  1031.     int i,cur,new, domlook=0,kk;
  1032.     char temp[43],*p,*rindex();
  1033.     long VSwhereis();
  1034.     struct machinfo *mp;
  1035.     DialogPtr dtemp;
  1036.     Str255 machinestring;                /* BYU LSC */
  1037.     struct machinfo *Sgethost();
  1038.  
  1039.     SetCursor( watchcurs);                    /* We may be here ARPTO seconds */
  1040.  
  1041.     strcpy ((char *) machinestring,config->machine);    /* BYU LSC */
  1042.     c2pstr((char *) machinestring);                        /* BYU LSC */
  1043.     ParamText(machinestring, 0L, 0L, 0L);                /* BYU LSC */
  1044.                                         /* No errors and this is the session */
  1045. /*    p2cstr(config->machine);            /* BYU LSC */
  1046. /*
  1047. *  check for port number tacked onto machine name.
  1048. */
  1049.     if (!config->ftpwind)                    /* is it an ftp window? */
  1050.         {
  1051.         p = rindex(config->machine, ' ');    /* look for space */
  1052.         if (p) {
  1053.             i = atoi(p);
  1054.             if (i > 0)
  1055.                 config->port = i;            /* new port to try for */
  1056.             p = strchr(config->machine, ' ');    /* BYU LSC - was "index()" */
  1057.             if (p)
  1058.                 *p = 0;                        /* terminate string at first space */
  1059.             }
  1060.         }
  1061. /*    else config->port = 21;                    /* BYU 2.4.20 - not needed, start at ftp port */
  1062.     
  1063.     new=0;                                /* Spot for new conn # */
  1064.  
  1065.     mp = Sgethost( config->machine );
  1066.  
  1067.                     /* Make the config record count for something..... */
  1068.  
  1069.     putln("before configrec");
  1070.     if (!mp && (config->connectionType == 0))  {    /* BYU serial */
  1071.         new = Sdomain( config->machine);
  1072.         domlook=1;
  1073.  
  1074.         mp = Slooknum(new);                /* get machine record */
  1075.         putln("after looknum");
  1076.         if (mp && config->port > 0) 
  1077.             mp->port = config->port;    /* save port to use later */
  1078.         }
  1079.     else {
  1080.  
  1081. /* 
  1082. *  When it comes to the port number to try for, if our user asked for
  1083. *  a specific port number, make sure he gets it.  Otherwise take the 
  1084. *  config file's word for it. 
  1085. */
  1086.         putln("inside else");
  1087.         if (config->ftpstate != 0)         /* BYU mod */
  1088.             config->port = 21;            /* BYU mod */
  1089.         else                            /* BYU mod */
  1090.         if (config->port == 23 && mp->port > 0)
  1091.             config->port = mp->port;        
  1092.  
  1093.         putln("before Snetopen");
  1094.         new = Snetopen( mp, config->port, config->connectionType);    /* BYU 2.4.15 */
  1095.  
  1096.         if (new < 0) {                                                 /* BYU 2.4.15 */
  1097.  
  1098.             if (config->connectionType == 0) {                                /* BYU 2.4.15 */
  1099.                 dtemp=GetNewDialog(ConnFalDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* BYU 2.4.15 */
  1100.                 DrawDialog( dtemp);                                            /* BYU 2.4.15 */
  1101.     
  1102.                 Wait4Mouse();
  1103.                 DisposDialog( dtemp);
  1104.             }
  1105.  
  1106.             updateCursor(1);                            
  1107.             return(-1);
  1108.             } 
  1109.  
  1110.         }
  1111.  
  1112.  
  1113.     cur=numwindows;            /* Adjust # of windows and get this window's number */
  1114.     numwindows++;
  1115.  
  1116.     DoTheMenuChecks();
  1117.  
  1118.     screens[cur].lineAllow = config->lineAllow;
  1119.     screens[cur].eightbit = config->eightbit;        /* BYU 2.4.9 */
  1120.     screens[cur].ftpwind = config->ftpwind;
  1121.     screens[cur].port=new;
  1122.     screens[cur].portNum = config->port;            /* NCSA */
  1123.     screens[cur].outlen=0;
  1124.  
  1125.     screens[cur].lmflag=0;
  1126.     for (kk=1; kk<19; kk++)
  1127.         (screens[cur]).slc[kk]=-1;
  1128.     screens[cur].slc[SLC_IP]=3;
  1129.     screens[cur].slc[SLC_EC]=127;
  1130.     screens[cur].slc[SLC_EL]=21;
  1131.     screens[cur].slc[SLC_EOF]=4;
  1132.     screens[cur].slc[SLC_ABORT]=3;
  1133.     screens[cur].slc[SLC_SUSP]=26; 
  1134.     
  1135.     c2pstr(config->name);            /* BYU LSC */
  1136.     screens[cur].vs=RSnewwindow( &config->window, config->scrollback, config->width, config->nlines,
  1137.                                   config->name, config->vtwrap, config->font, config->fsize,
  1138.                                   0, Prefs.dontclose); /* last two are No showit/Yes goaway */
  1139.     p2cstr(config->name);            /* BYU LSC */
  1140.     screens[cur].wind=RSgetwindow( screens[cur].vs);
  1141.  
  1142.     sprintf(temp,"VS -%d- %lx (%d)",screens[cur].vs, VSwhereis(screens[cur].vs),
  1143.                                     config->scrollback);
  1144.     putln(temp);
  1145.  
  1146.     if (screens[cur].vs<0) {
  1147.         putln( "Couldn't open Virtual Screen");
  1148.         updateCursor(1);                            /* Done stalling the user */
  1149.         return(-1);
  1150.         }
  1151.  
  1152.     screens[cur].maxscroll=config->scrollback;
  1153. #ifdef TESTING
  1154.     screens[cur].termstate=DUMBTYPE;
  1155. #else
  1156.     screens[cur].termstate=VTEKTYPE;
  1157. #endif TESTING
  1158.     screens[cur].naws =0;                    /* NCSA - set default NAWS to zero */
  1159.     screens[cur].rows =config->nlines;        /* BYU 2.4.16 */
  1160.     screens[cur].bsdel=config->bsdel;
  1161.     screens[cur].name=config->name;
  1162.     screens[cur].machine=config->machine;
  1163.     screens[cur].crmap = config->crmap;
  1164.     screens[cur].tekclear= config->tekclear;
  1165.     screens[cur].ESscroll= config->clearsave;
  1166.     screens[cur].ESclear= true;                /* BYU 2.4.8 - default Tek page clears screen */
  1167.     screens[cur].xfer=0;
  1168.     screens[cur].connectionType=config->connectionType;    /* BYU serial */
  1169.     screens[cur].ftpstate=config->ftpstate;    /* BYU */
  1170.     screens[cur].tektype = config->tektype;
  1171.     screens[cur].telstate=0;
  1172.     screens[cur].timing=0;
  1173.     screens[cur].curgraph=-1;            /* No graphics screen */
  1174.     screens[cur].echo=0;                /* I'm not echoing, are you? */
  1175.     screens[cur].ftpport = -1;            /* BYU - No additional FTP port opened yet */
  1176.     screens[cur].clientflags = 0;        /* BYU */
  1177.     if (config->ftpstate != 0) {        /* BYU */
  1178.       screens[cur].termstate=DUMBTYPE;    /* BYU */
  1179.       screens[cur].echo=1;                /* BYU - Echo for ftp */
  1180.       screens[cur].halfdup = 1;            /* BYU */
  1181.     } else {                            /* BYU */
  1182.       screens[cur].termstate=VTEKTYPE;    /* BYU */
  1183.       screens[cur].echo=0;                /* BYU - I'm not echoing, are you? */
  1184.       screens[cur].halfdup = config->halfdup;    /* BYU */
  1185.     }                                    /* BYU */
  1186.     screens[cur].wrap = config->vtwrap;    /* wrap mode anyone? */
  1187.     screens[cur].kblen=0;                /* nothing in the buffer */
  1188.     screens[cur].enabled=1;                /* Gotta be enabled to start with */
  1189.     screens[cur].Ittype=0;
  1190.     screens[cur].Isga=0;                /* I suppress go ahead = no */
  1191.     screens[cur].Usga=0;                /* U suppress go ahead = no */
  1192.     screens[cur].corpse=0;
  1193.     screens[cur].width= config->width;
  1194.     if (screens[cur].connectionType != 0) {        /* BYU serial - if serial connection ... */
  1195.         screens[cur].TELstop = -1;                /* BYU serial - no stopping */
  1196.         screens[cur].TELgo = -1;                /* BYU serial - no going */
  1197.         screens[cur].TELip = -1;                /* BYU serial - no Interrupting the Process */
  1198.     } else {
  1199.         screens[cur].TELstop = config->TELstop;    /* BYU serial - ^s stops */
  1200.         screens[cur].TELgo = config->TELgo;        /* BYU serial - ^q gos */
  1201.         screens[cur].TELip = config->TELip;        /* BYU serial - ^c Interrupts the Process */
  1202.     }
  1203.  
  1204.     for (i=0;i<4;i++)
  1205.         if (RSsetcolor( screens[cur].vs, i, config->red[i],
  1206.                                         config->green[i],
  1207.                                         config->blue[i]))
  1208.             putln("Trouble setting the color");
  1209.         else putln("Color set...");
  1210.  
  1211.     c2pstr(screens[cur].name);            /* BYU LSC */
  1212.     if ((screens[cur].connectionType == 1) && !slip_connection) {        /* BYU 2.4.15 */
  1213.         addinmenu(cur, (Str255 *) screens[cur].name, (char) 0x13);        /* BYU serial */
  1214.         screens[cur].active=0;                                            /* BYU serial */
  1215.         RSshow( screens[cur].vs);            /* BYU serial */
  1216.         SelectWindow(screens[cur].wind);    /* BYU serial */
  1217.         screens[cur].Usga=1;                /* BYU serial */
  1218.         changeport(scrn,cur);                /* BYU serial */
  1219.         liveport(scrn);                        /* BYU serial */
  1220.         }                                    /* BYU serial */
  1221.     else                                    /* BYU serial */
  1222.  
  1223.     if (domlook) {
  1224.         addinmenu(cur, (Str255 *) screens[cur].name, (char) 0x13);
  1225.         screens[cur].active = -1;
  1226.         }
  1227.     else {
  1228.         addinmenu(cur, (Str255 *) screens[cur].name, (char) 0xa5);
  1229.         screens[cur].active = 1;
  1230.         }
  1231.     p2cstr(screens[cur].name);            /* BYU LSC */
  1232.  
  1233.     VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  1234.     updateCursor(1);                            /* Done stalling the user */
  1235. /*    netgetip( myipnum);            /* BYU - For Driver version, we must get our number */
  1236.     return(cur);
  1237. } /* addport */
  1238.  
  1239. void destroyport
  1240.   (
  1241.     int wind
  1242.   )
  1243. {
  1244.     int i,
  1245.         callNoWindow=0;
  1246.  
  1247.  
  1248.     SetCursor( watchcurs);                    /* We may be here a while */
  1249.  
  1250.     if (!screens[wind].corpse) {
  1251.         if (screens[wind].curgraph>-1)
  1252.             detachGraphics( screens[wind].curgraph);    /* Detach the Tek screen */
  1253.         if (screens[wind].outlen>0) {
  1254.             screens[wind].outlen=0;                        /* Kill the remaining send*/
  1255.             HUnlock( screens[wind].outhand);            /*  buffer */
  1256.             HPurge ( screens[wind].outhand);
  1257.             }
  1258.         }
  1259.  
  1260.     /* Get rid of the names.  We don't need them anymore */
  1261.     
  1262.     DisposPtr(screens[wind].machine);
  1263.     DisposPtr(screens[wind].name);
  1264.  
  1265.  
  1266.  
  1267.     if (FrontWindow() == screens[wind].wind)
  1268.         callNoWindow=1;
  1269.  
  1270.     RSkillwindow( screens[wind].vs);
  1271.     screens[wind].active=-5;
  1272.     for (i=wind;i<numwindows-1;i++) {
  1273.         screens[i]=screens[i+1];        /* Bump all of the pointers */
  1274.         }
  1275.     if (scrn>wind) scrn--;                /* Adjust for deleting a lower #ered screen */
  1276.  
  1277.     numwindows--;                        /* There are now fewer windows */
  1278.     extractmenu( wind);                    /* remove from the menu bar */
  1279.  
  1280.     DoTheMenuChecks();
  1281.  
  1282. /* BYU 2.4.11 - the call to "NoWindow()" changes "myfrontwindow", 
  1283.                 which is used by "updateCursor()", so we reversed 
  1284.                 the order of the following two lines. */
  1285.     if (callNoWindow) NoWindow();        /* BYU 2.4.11 - Update cursor stuff if front window */
  1286.     updateCursor(1);                    /* BYU 2.4.11 - Done stalling the user */
  1287.  
  1288. } /* destroyport */
  1289.  
  1290. void removeport
  1291.   (
  1292.     int wind
  1293.   )
  1294. {
  1295.     SetCursor( watchcurs);                    /* We may be here a while */
  1296.  
  1297.     if (screens[wind].curgraph>-1)
  1298.         detachGraphics( screens[wind].curgraph);    /* Detach the Tek screen */
  1299.     if (screens[wind].outlen>0) {
  1300.                 screens[wind].outlen=0;                /* Kill the remaining send*/
  1301.                 HUnlock( screens[wind].outhand);    /*  buffer */
  1302.                 HPurge ( screens[wind].outhand);
  1303.                 }
  1304.     if (!Prefs.dontclose)
  1305.         destroyport(wind);
  1306.     else {
  1307.         char temp[255];
  1308.         sprintf(temp, "(%s)",screens[wind].name);
  1309.         c2pstr(temp);                            /* BYU LSC */
  1310.         SetWTitle( screens[wind].wind, temp);    /* BYU LSC */
  1311.  
  1312.         screens[wind].corpse=1;
  1313.         screens[wind].port = 32700;
  1314.         screens[wind].active=-5;
  1315.  
  1316.         }
  1317.     updateCursor(1);                            /* Done stalling the user */
  1318. } /* removeport */
  1319.  
  1320. int findbyWind                        /* Find screen index by Window */
  1321.   (
  1322.     GrafPtr wn
  1323.   )
  1324. {
  1325.     int i=0;
  1326.  
  1327.     while((i<numwindows) && (wn!=screens[i].wind)) i++;
  1328.     if (i>=numwindows) return(-1);
  1329.     return(i);
  1330. }
  1331.  
  1332. int findbyVS                        /* Find screen index by VS Number */
  1333.   (
  1334.     int vs
  1335.   )
  1336. {
  1337.     int i=0;
  1338.  
  1339.     while((i<numwindows) && (vs!=screens[i].vs)) i++;
  1340.     if (i>=numwindows) return(-1);
  1341.     return(i);
  1342. }
  1343.  
  1344. int isEightBit(int vs) {                            /* BYU 2.4.12 */
  1345.     int i = findbyVS(vs);                            /* BYU 2.4.12 */
  1346.     if (i>=numwindows) return(0);                    /* BYU 2.4.12 */
  1347.     return(screens[i].eightbit);                    /* BYU 2.4.12 */
  1348. }                                                    /* BYU 2.4.12 */
  1349.  
  1350. void ERR                /* Error routine for BKGR/ICMP/etc....*/
  1351.   (
  1352.     int num
  1353.   )
  1354. {
  1355.     char temp[80],*dummy;
  1356.  
  1357.     dummy=strncpy( &temp[1],neterrstring(num),78);
  1358.     temp[79]='\0';                        /* Compensate for error in strncopy */
  1359.     temp[0]= (unsigned char)strlen(&temp[1]);
  1360.     ParamText(0L,0L,0L,&temp[1]);            /* Load the error record field */
  1361.     putln( &temp[1]);
  1362. }
  1363.  
  1364. void xferstart                    /* Called at start of FTP */
  1365.   (
  1366.     void
  1367.   )
  1368. {
  1369.     xferon=1;
  1370.     updateCursor(1);
  1371. }
  1372.  
  1373. void xferdone                    /* Called at end of FTP */
  1374.   (
  1375.     void
  1376.   )
  1377. {
  1378.     xferon=0;
  1379.     updateCursor(1);
  1380. }
  1381.  
  1382. void setgraphcurs                    /* Called at start of gin */
  1383.   (
  1384.     void
  1385.   )
  1386. {
  1387.     putln("Graphics INput mode entered");
  1388.     ginon=1;
  1389.     updateCursor(1);
  1390. }
  1391.  
  1392. void unsetgraphcurs                    /* Called at start of gin */
  1393.   (
  1394.     void
  1395.   )
  1396. {
  1397.     ginon=0;
  1398.     updateCursor(1);
  1399. }
  1400.  
  1401. int decodeIPnum
  1402.   (
  1403.     char *s,
  1404.     unsigned char *myipnum
  1405.   )
  1406. {
  1407.     int i, node, hi, low;
  1408.     char temp[50];
  1409.  
  1410.     for (i=0; i<4; i++) myipnum[i]=0;
  1411.     i=0;
  1412.     
  1413.     if (!EtherNet)
  1414.         getATaddress( &hi, &low, &node);
  1415.  
  1416.     while((*s) && (i<4) ) {
  1417.         switch( *s) {
  1418.             case '0':
  1419.             case '1':
  1420.             case '2':
  1421.             case '3':
  1422.             case '4':
  1423.             case '5':
  1424.             case '6':
  1425.             case '7':
  1426.             case '8':
  1427.             case '9':
  1428.                 myipnum[i]= myipnum[i] *10 + (*s-'0');
  1429.                 break;
  1430.             case '.':
  1431.                 i++;
  1432.                 break;
  1433.             case 'H':
  1434.             case 'h':
  1435.                 myipnum[i]=hi;
  1436.                 break;
  1437.             case 'L':
  1438.             case 'l':
  1439.                 myipnum[i]=low;
  1440.                 break;
  1441.             case 'N':
  1442.             case 'n':
  1443.                 myipnum[i]=node;
  1444.                 break;
  1445.             default:
  1446.                 break;
  1447.             }
  1448.         s++;
  1449.         }
  1450.     
  1451.     sprintf( temp," IPNUM= %d.%d.%d.%d", (int) myipnum[0], (int) myipnum[1], (int) myipnum[2],
  1452.                                          (int) myipnum[3]);
  1453.     putln(temp);
  1454.     
  1455.     if (i<3) return( 1);
  1456.         else return( 0);
  1457. }
  1458.  
  1459. /*    CheckConfig (dynamic, dIP, useMask, dMask)
  1460.  *
  1461.  *        checks the configuration described by IP and Mask strings.  If it is OK,
  1462.  *            it returns (0).  If it is bad, it displays a message and returns (1)
  1463.  */
  1464. int CheckConfig
  1465.   (
  1466.     int dynamic,
  1467.     Handle dIP,
  1468.     int useMask,
  1469.     Handle dMask
  1470.   )
  1471. {
  1472.     DialogPtr dtemp;
  1473.     char temp[256];
  1474.     short item;
  1475.     int error=0;
  1476.     long ltemp;
  1477.  
  1478.     if (!dynamic) {                /* Check IP NUmber if appropriate */
  1479.         GetIText( dIP, temp);
  1480.         temp[temp[0] + 1]=0;            /* be safe for the wonderful sscanf */
  1481.     
  1482.         if (decodeIPnum(&temp[1], (unsigned char *) <emp)) {
  1483.             error=1;
  1484.  
  1485.             dtemp=GetNewDialog( BadIPDLOG,(Ptr) 0L,(WindowPtr) -1L);
  1486.             ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1487.             DisposDialog(dtemp);
  1488.             }
  1489.         }
  1490.  
  1491.     if (useMask) {                /* Check Subnet Mask if appropriate */
  1492.         GetIText( dMask, temp);
  1493.         temp[temp[0] + 1] = 0;            /* be safe for the wonderful sscanf */
  1494.  
  1495.         if (temp[0]!=8 || (sscanf(&temp[1], "%lx", <emp)!=1) ) {
  1496.             error=1;
  1497.  
  1498.             dtemp=GetNewDialog( BadMaskDLOG,(Ptr) 0L,(WindowPtr) -1L);
  1499.             ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1500.             DisposDialog(dtemp);
  1501.             }
  1502.         }
  1503.     return(error);
  1504. }
  1505.  
  1506. /*
  1507.  * PromptIP - this is one HUGE procedure, but I have not come up with an easy way
  1508.  *    to break it down.  It allows you to change all of the network parameters....
  1509.  */
  1510.  
  1511. int PromptIP
  1512.   (
  1513.     int dynam
  1514.   )
  1515. {
  1516.  
  1517. #define GetStrRes(x)    (Str255 **)GetResource('STR ',x);
  1518.  
  1519.     DialogPtr dtemp;
  1520.     Str255 *ptemp,nstring;
  1521.     Str255 **hostR,**ipR, **maskR;
  1522.     Rect dBox;
  1523.     Handle dynIP,statIP,useMask,dHand, dIP, dMask;
  1524.     int olddynam;
  1525.     int mask=0,terr,badconfig=1, enteredbad;
  1526.     short dItem;
  1527.     
  1528.     dtemp=GetNewDialog(GetParmDLOG,(void *) 0L,(WindowPtr) -1L); /* Get the dialog to use */
  1529.  
  1530.     UItemAssign( dtemp, 11, (int (*)()) OutlineItem);
  1531.  
  1532.     ipR=GetStrRes(IPnumSTR);                /* Was there an IP Number before */
  1533.  
  1534.     if (ipR!=0L) {                            /* If So...*/
  1535.         GetDItem(dtemp,GetParmIP,&dItem,&dHand,&dBox);    /* Get the dialog item */
  1536.         HLock((Handle) ipR);                            /* Lock the string in */
  1537.  
  1538.         SetIText(dHand, *ipR);                    /* BYU LSC - Set the item's text to the old 1*/
  1539.         SelIText(dtemp,GetParmIP,0,32767);                /* And select it */
  1540.         HUnlock((Handle) ipR);                            /* Unlock the string */
  1541. #ifdef OLDM
  1542.         RmveResource(ipR);                    /* Remove the old rotting number */
  1543. #endif
  1544.         putln("Reading previous IP Resource");
  1545.         }
  1546.     else if (KIP) dynam=1;                    /* Default to dynamic if KIP + no res */
  1547.  
  1548.     hostR=GetStrRes( HostSTR);        /* Was there a default host */
  1549.     if (hostR!=0L) {                            /* If So...*/
  1550.         GetDItem(dtemp,GetParmHOST,&dItem,&dHand,&dBox);    /* Get the dialog item */
  1551.         HLock((Handle) hostR);                    /* Lock the string in */
  1552.  
  1553.         SetIText(dHand, *hostR);        /* BYU LSC - Set the item's text to the old 1*/
  1554.  
  1555.         HUnlock((Handle) hostR);                /* Unlock the string */
  1556.         putln("Reading previous Default Dest. Resource");
  1557.         }
  1558.  
  1559.     maskR=GetStrRes( MaskSTR );
  1560.     if (maskR!=0L) {                            /* If So...*/
  1561.         GetDItem(dtemp,GetParmMASK,&dItem,&dHand,&dBox);    /* Get the dialog item */
  1562.         HLock((Handle) maskR);                        /* Lock the string in */
  1563.  
  1564.         SetIText(dHand, *maskR);            /* BYU LSC - Set the item's text to the old 1*/
  1565.  
  1566.         HUnlock((Handle) maskR);                    /* Unlock the string */
  1567.         if ( mynetmask!=defmask ) mask=1;        /* Is the mask custom? */
  1568.         putln("Reading previous Mask Resource");
  1569.         }
  1570.  
  1571.     olddynam = dynam;
  1572.  
  1573.     dItem=0;
  1574.     GetDItem(dtemp,GetParmStat,&dItem,&statIP,&dBox);    /* Get the IP # handle */
  1575.  
  1576.     dItem=0;
  1577.     GetDItem(dtemp,GetParmKDyn,&dItem,&dynIP,&dBox);    /* Get the Dynam Handle */
  1578.  
  1579.     dItem=0;
  1580.     GetDItem(dtemp,GetParmUseM,&dItem,&useMask,&dBox);    /* Get the Mask Handle */
  1581.  
  1582.     dItem=0;
  1583.     GetDItem(dtemp,GetParmIP,&dItem,&dIP,&dBox);        /* Get the IP TE Handle */
  1584.  
  1585.     dItem=0;
  1586.     GetDItem(dtemp,GetParmMASK,&dItem,&dMask,&dBox);    /* Get the Mask TE Handle */
  1587.  
  1588.     if (!(KIP || EtherNet)) {
  1589.         HiliteControl((ControlHandle) dynIP,255);    /* Dont even think of dynam */
  1590.         dynam = 0;
  1591.         }
  1592.  
  1593.     SetCtlValue((ControlHandle) dynIP,dynam);                /* Set up the controls */
  1594.  
  1595.     SetCtlValue((ControlHandle) statIP, !dynam);            /* Kip/RARP can have dynamic */
  1596.  
  1597.     SetCtlValue((ControlHandle) useMask, mask);                /* No Mask to start */
  1598. #ifdef MAYBELATER
  1599.     enteredbad = CheckConfig( dynam, dIP, mask, dMask);
  1600.                                             /* We can't cancel if we have a bad start */
  1601. #else
  1602. #pragma unused(enteredbad)
  1603. #endif
  1604.     while( badconfig) {
  1605.         dItem=0;
  1606.         while((dItem> 2) || (dItem==0)) {        /* loop till done */
  1607.             ModalDialog((ModalFilterProcPtr) modalProc ,&dItem); /* Get an event */
  1608.             if (dItem==GetParmIP)  
  1609.                     if (dynam) dItem = GetParmStat;
  1610.             if (dItem==GetParmStat) { dynam=0;                    /* They want to tell me */
  1611.                             SetCtlValue((ControlHandle) dynIP,dynam);
  1612.                             SetCtlValue((ControlHandle) statIP, !dynam);
  1613.                         }
  1614.             if (dItem==GetParmKDyn) { dynam=1;                    /* I should figure it out */
  1615.                             SetCtlValue((ControlHandle) dynIP,dynam);
  1616.                             SetCtlValue((ControlHandle) statIP, !dynam);
  1617.                         }
  1618.             if (dItem==GetParmMASK) 
  1619.                     if (!mask) dItem=GetParmUseM;
  1620.             if (dItem==GetParmUseM) {mask=!mask;
  1621.                             SetCtlValue((ControlHandle) useMask,mask);
  1622.                         }
  1623.             }
  1624.     
  1625.         if (dItem == 1) {
  1626.             DisposDialog(dtemp);                        /* Get rid of dialog */
  1627.             return(olddynam);
  1628.             }
  1629.         badconfig=CheckConfig( dynam, dIP, mask, dMask);
  1630.         }            /* End of While Badconfig */
  1631.  
  1632.     if (SettingsFile==-1) {
  1633.         DisposDialog(dtemp);
  1634.         return(dynam);
  1635.         }
  1636.  
  1637.  
  1638.     if (ipR ==0L) {
  1639.         putln("Making new IP number resource");
  1640.         ipR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  1641.         if (ipR==0L) putln(nospacemsg);                            /* BYU LSC */
  1642.         AddResource((Handle) ipR,'STR ',256,"\pIP Number");        /* BYU LSC */
  1643.         if ((terr=ResError())!=0) {
  1644.             sprintf((char *) &nstring,"Error in addresource. (%d)",terr);    /* BYU LSC */
  1645.             putln((char *) &nstring);        /* BYU LSC */
  1646.             }
  1647.         }
  1648.  
  1649.     HLock((Handle) ipR);                    /* Lock it down */
  1650.     ptemp=*ipR;                                /* a pointer for sanity*/
  1651.  
  1652.     GetIText(dIP, (Str255 *) ptemp);            /* BYU LSC - Get the IP Number fm the TE */
  1653.     (*ptemp)[(*ptemp)[0] + 1] = 0;                /* be on the scanf safe side */
  1654.  
  1655.     if (dynam) (*ptemp)[0]=0;
  1656.     else 
  1657.         if (0==decodeIPnum( (char *) &(*ptemp)[1], myipnum) )    /* BYU LSC */
  1658.                 putln("Got successful IP Number");
  1659.  
  1660.     HUnlock((Handle) ipR);
  1661.     ChangedResource((Handle) ipR);
  1662.     UpdateResFile(HomeResFile((Handle) ipR));    /* now it is saved, process it*/
  1663.  
  1664. /******/
  1665.  
  1666.     if (hostR ==0L) {
  1667.         putln("Making new Host resource");
  1668.         hostR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  1669.         if (hostR==0L) putln(nospacemsg);                            /* BYU LSC */
  1670.         AddResource((Handle) hostR,'STR ',257,"\pDefault Host");    /* BYU LSC */
  1671.         if ((terr=ResError())!=0) {
  1672.             sprintf((char *) &nstring,"Error in addresource. (%d)",terr);
  1673.             putln((char *) &nstring);
  1674.             }
  1675.         }
  1676.  
  1677.     HLock((Handle) hostR);                                /* Lock it down */
  1678.     ptemp=*hostR;                                /* a pointer for sanity*/
  1679.  
  1680.     GetDItem(dtemp,GetParmHOST,&dItem,&dHand,&dBox);        /* Get the Default Host */
  1681.     GetIText(dHand, (Str255 *) ptemp);            /* BYU LSC */
  1682.  
  1683.     memmove(defaultd, ptemp, (size_t) 256);        /* BYU LSC - Make a copy for later */
  1684.     p2cstr((StringPtr) defaultd);
  1685.  
  1686.     HUnlock((Handle) hostR);
  1687.     ChangedResource((Handle) hostR);
  1688.     UpdateResFile(HomeResFile((Handle) hostR));
  1689. /******/
  1690.  
  1691.     if (maskR ==0L) {
  1692.         maskR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  1693.         putln("Making new Mask resource");
  1694.         if (maskR==0L) putln(nospacemsg);                                    /* BYU LSC */
  1695.         AddResource((Handle) maskR, 'STR ', MaskSTR, "\pNetwork Mask");        /* BYU LSC */
  1696.         if ((terr=ResError())!=0) {
  1697.             sprintf((char *) &nstring, "Error in addresource. (%d)", terr);    /* BYU LSC */
  1698.             putln((char *) &nstring);        /* BYU LSC */
  1699.             }
  1700.         }
  1701.  
  1702.     HLock((Handle)maskR);                                /* Lock it down */
  1703.     ptemp=*maskR;                                /* a pointer for sanity*/
  1704.  
  1705.     GetIText(dMask, (Str255 *) ptemp);            /* BYU LSC - Get the Mask from the Dialog */
  1706.  
  1707.     if (mask) { putln("using custom mask");
  1708.                 cmask=1;
  1709.                 } else cmask=0;
  1710.     (*ptemp)[(*ptemp)[0] + 1] = '\0';            /* terminate for sscanf */
  1711.     
  1712.     if (( 1!=sscanf((char *) ptemp+1, "%lx", &mynetmask)) || (!mask)) {    /* BYU LSC */
  1713.         (*ptemp)[0] = 0;                    /* Make it remain default */
  1714.         (*ptemp)[1] = ' ';
  1715.         putln( "Default mask used, saved mask cleared....");
  1716.         }
  1717.  
  1718.     HUnlock((Handle) maskR);
  1719.     ChangedResource((Handle) maskR);
  1720.     UpdateResFile(HomeResFile((Handle) maskR));
  1721. /******/
  1722.  
  1723.     DisposDialog(dtemp);                        /* Get rid of dialog */
  1724.  
  1725.     return(dynam);                                /* Return with the status of */
  1726.                                                 /* Dynamic or Static IP */
  1727.   } /* PromptIP */
  1728.  
  1729. /*
  1730.  *    Get a dynamic IP Number..... this should be done only if you are Crofted
  1731.  */
  1732. int DynamIP
  1733.   (
  1734.     char *ipnum
  1735.   )
  1736. {
  1737.     if (!KIP) {
  1738.         putln("You can't use dynamic IP Numbers without Croft!!");
  1739.         return(-1);
  1740.         }
  1741.     putln("Obtaining a dynamic IP Number");
  1742.  
  1743.     if (KIPgetdynam(&KIPserver, (long *) ipnum) <0) {
  1744.         OtherError((char *) "\pError obtaining dynamic IP #.",(char *) "\pDynamic addressing not available");        /* BYU LSC */
  1745.         putln("dynamic IP get failed ");
  1746.         return(-1);
  1747.         }
  1748.  
  1749.     return(0);
  1750. }
  1751.  
  1752. /*
  1753.  *    Register your IP Number..... this need be done only if you are Crofted
  1754.  */
  1755. int RegIP
  1756.   (
  1757.     char *ipnum
  1758.   )
  1759. {
  1760. #if 1                                                            /* BYU 2.4.11 */
  1761.     if (EtherNet) {                                                /* BYU 2.4.11 */
  1762.         putln("You don't need to register on ethernet....");    /* BYU 2.4.11 */
  1763. #else                                                            /* BYU 2.4.11 */
  1764.     if (!KIP) {
  1765.         putln("You don't need to register if you aren't using Croft....");
  1766. #endif                                                            /* BYU 2.4.11 */
  1767.         return(0);
  1768.         }
  1769.     putln("Registering IP Number to the network");
  1770.     if (KIPregister((unsigned char *) ipnum) <0) {        /* BYU LSC */
  1771.         putln("Registration failed!!");
  1772.         return(-1);
  1773.         }
  1774.     return(0);
  1775. }
  1776.  
  1777. void setnetconfigs
  1778.   (
  1779.     char *ipnum,
  1780.     long *netmask
  1781.   )
  1782. {
  1783.     char sbuf[80];
  1784.     sprintf(sbuf,"%lx is mask",*netmask);
  1785.     putln(sbuf);
  1786.  
  1787.     netsetip((unsigned char *) ipnum);                /* BYU LSC - Here is your number */
  1788.  
  1789.     netsetmask((unsigned char *) netmask); /* And your network type */
  1790. }
  1791.  
  1792. /*
  1793.  *    initipnum - Initialize the IP number, and check it and the other wonderful
  1794.  *        things associated (mask,ip #, def host). Button forces the PromptIP dialog.
  1795.  *
  1796.  *  Thanks to Ric Anderson from the University of Arizona for the setvol patches to
  1797.  *  make the system folder work right.
  1798.  */
  1799.  
  1800. int initipnum
  1801.   (
  1802.     int button
  1803.   )
  1804. {
  1805.     Str255 *tempp,**temph;
  1806.     int error=0,dynam=0;
  1807.     short refnum;
  1808.     long ns;
  1809.     char *myDir;
  1810.     short myVRef;
  1811.     WDPBRec theWD;
  1812.     OSErr     err=0;
  1813.     
  1814. /*    strncpy (files_name, name, size);
  1815.     files_name[size] = 0; */
  1816.  
  1817.  
  1818.  
  1819.   /* look for an existing settings file. The usual search path
  1820.     for this will include the current folder and the system folder,
  1821.     unless they're on different volumes (see tech note 77). */
  1822.  
  1823.     myDir = (char *)NewPtr(255);
  1824.     setmydir(); /* first, try the application folder */
  1825.     SettingsFile=OpenRFPerm("\pNCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1826.     if (SettingsFile == - 1)
  1827.       {
  1828.         sysdir(); /* in case it's on a different volume */
  1829.         SettingsFile=OpenRFPerm("\pNCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1830.       } /* if */
  1831.  
  1832.     if (SettingsFile == - 1)
  1833.         {
  1834.  
  1835.         GetVol(myDir,&myVRef);    
  1836.         myDir[myDir[0]+2] = 0;        
  1837.         strcat(myDir,"System Folder:Preferences");
  1838.         myDir[myDir[0]+1] = ':';
  1839.         myDir[0] += (strlen("System Folder:Preferences")+1);
  1840.         
  1841.  
  1842.         putln("the dir is:");
  1843.         putln(myDir);
  1844.  
  1845.         theWD.ioCompletion = NULL;
  1846.         theWD.ioNamePtr = (unsigned char *) myDir;        /* BYU LSC */
  1847.         theWD.ioVRefNum = 0;
  1848.         theWD.ioWDDirID = 0;
  1849.         err = PBHSetVol (&theWD, false);
  1850.         SettingsFile=OpenRFPerm("\pNCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1851.         
  1852.         }
  1853.  
  1854.     DisposPtr(myDir);
  1855.     if (SettingsFile == -1 )
  1856.       {
  1857.       /* no settings file anywhere -- create one in the system folder. */
  1858.     /*    sysdir(); */
  1859.         Create("\pNCSA Telnet Settings", theWorld.sysVRefNum, 'NCSA', 'IPNO');    /* BYU LSC */
  1860.         CreateResFile("\pNCSA Telnet Settings");    /* BYU LSC - Make a new one if it is not there .... */
  1861.         SettingsFile=OpenRFPerm("\pNCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1862.       } /* if */
  1863.     setmydir();        /* set back to default dir */
  1864.     
  1865.   /* Initialize the default host */
  1866.     if ((defaultd=(Str255 *)NewPtr(256)) ==0L) {
  1867.         putln("Oops, no memory at all");
  1868.         quit();
  1869.         } else
  1870.             (*defaultd)[0]=0;                            /* Default to no host */
  1871.  
  1872.     temph=(Str255 **)GetResource('STR ',HostSTR);
  1873.     if (temph!=0L) {
  1874.         HLock((Handle) temph);                            /* This remains locked */
  1875.         memmove(defaultd, *temph, (size_t) 256);        /* BYU LSC */
  1876.         p2cstr((StringPtr) defaultd);
  1877.         HUnlock((Handle) temph);
  1878.         } else                                    /* BYU serial - Use it .... */
  1879.             strcpy((char *) defaultd,"");        /* BYU serial - Default to no host */
  1880.  
  1881.     if (EtherNet == -99)            /* Return on Driver TCP */
  1882.         return(1);
  1883.         
  1884.     if (!EtherNet)
  1885.       {
  1886.         OSErr err;
  1887.         err = OpenDriver("\p.MPP", &refnum);
  1888.         if (err == 0)
  1889.             putln("MPP AOk");
  1890.         else
  1891.           {
  1892.             DialogPtr dtemp;
  1893.             short item;
  1894.  
  1895.             putln("MPP Bad");
  1896.           /* following sequence is copied from atopen in atalk.c */
  1897.             if (err == -97 || err == -98)
  1898.                 ParamText(0L, 0L, 0L,
  1899.                     "\pYou forgot to turn on AppleTalk in the Chooser");
  1900.             else if (err == -192)
  1901.                 ParamText(0L, 0L, 0L, "\pCouldn’t find ‘atpl’ resource");
  1902.             else
  1903.                 ParamText(0L, 0L, 0L, "\pUnknown Error");
  1904.             dtemp = GetNewDialog(302, (Ptr) 0L, (WindowPtr) -1L);
  1905. #if 1                                                            /* BYU 2.4.15 */
  1906.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  1907.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  1908. #else                                                            /* BYU 2.4.15 */
  1909.             ModalDialog(0L,&item);
  1910. #endif                                                            /* BYU 2.4.15 */
  1911.             DisposDialog(dtemp);
  1912. /*            quit();                                                /* BYU 2.4.15 */
  1913.           }
  1914.       /* Check if KIP is the Gateway if so load number */
  1915.         if ( KIPfindgate(&KIPserver)>0)
  1916.           {
  1917.             putln("Croft Gateway is online!");        /* BYU */
  1918.             KIP=1;            /* we have a KIP Croft Gateway */
  1919.             KIPgetns(&KIPserver, &ns);
  1920.             if (ns !=0) Ssetns((unsigned char *) &ns);
  1921.           }
  1922.       }
  1923.     else
  1924.         KIP = 0;
  1925.   /* Initialize the IP Number */
  1926.     temph = (Str255 **)GetResource('STR ',IPnumSTR);
  1927.     if (temph!=0L) {
  1928.         HLock((Handle) temph);                            /* lock for string ref. */
  1929.         tempp=*temph;
  1930.  
  1931.         (*tempp)[(*tempp)[0] + 1]=0;
  1932.         error=decodeIPnum((char *) &(*tempp)[1], myipnum);    /* BYU LSC */
  1933.  
  1934.         if (error) {
  1935.             if (EtherNet) {                    /* Dynamic if Ether and no IP Number */
  1936.                 strncpy((char *) myipnum,"RARP",4);        /* BYU LSC */
  1937.                 dynam=1;
  1938.                 error=0;
  1939.                 }
  1940.             else if (KIP) {
  1941.                 DynamIP((char *) myipnum);        /* BYU LSC - Dynamic if KIP and no IP number */
  1942.                 dynam=1;
  1943.                 error=0;
  1944.                 }
  1945.             else  error=1;                /* Error  if !KIP and  "" ""       */
  1946.             }
  1947.         HUnlock((Handle) temph);            /* Get rid of old number */
  1948.         }
  1949.     else error=1;                            /* error set by lack of resource */
  1950.  
  1951.                         /* Set up our default masking, given the IP number */
  1952.  
  1953.     if (userlevel >2) {
  1954.         if (!dynam) {
  1955.             if (!KIP) error=1;
  1956.             else {
  1957.                 dynam=1;
  1958.                 DynamIP((char *) myipnum);        /* BYU LSC */
  1959.                 }
  1960.             }
  1961.         }
  1962.  
  1963.     if (!(myipnum[0] & 0x80))
  1964.             defmask=0xff000000;                        /* Class A */
  1965.         else if ( (myipnum[0] & 0xC0 )==0x80)
  1966.             defmask=0xffff0000;                        /* Class B */
  1967.         else if ( (myipnum[0] & 0xC0 )==0xC0)
  1968.             defmask=0xffffff00;                        /* Class C */
  1969.  
  1970.     temph=(Str255 **)GetResource('STR ',MaskSTR);    /* Get the current mask */
  1971.     if (temph!=0L) {
  1972.         HLock((Handle) temph);                        /* Lock for string ref. */
  1973.         tempp=*temph;
  1974.         (*tempp)[(*tempp)[0] + 1] = '\0';            /* terminate for scanf */
  1975.         }
  1976.     cmask=1;
  1977.     if (temph== 0L || *((char *) tempp) != 8 ||    /* BYU LSC */
  1978.         (1!=sscanf((char *) tempp+1, "%lx", (long) &mynetmask))) {    /* BYU LSC */
  1979.             mynetmask=defmask;                    /* Default masks... */
  1980.             cmask=0;
  1981.             }
  1982.  
  1983.     if (temph!=0L) HUnlock((Handle) temph);        /* Ok, I admit this seq. has to go */
  1984.  
  1985.     if (error) putln("error is set");
  1986.     if (button) putln("button is set");
  1987.  
  1988.     dynamic = dynam;
  1989.  
  1990.     if ( (error || button) && userlevel<2) {
  1991.         putln("Prompting for IP Number");
  1992.  
  1993.         /* if (ResError()!=-192)
  1994.             ERRWarn(800);        Can't Load Existing Resource, out of space */
  1995.  
  1996.         if ( PromptIP( dynam)) {
  1997.             if (EtherNet)
  1998.                 strncpy((char *) myipnum,"RARP",4);            /* BYU LSC */
  1999.             else 
  2000.                 DynamIP((char *) myipnum);                    /* BYU LSC */
  2001.             if (!(myipnum[0] & 0x80))
  2002.                     defmask=0xff000000;                        /* Class A */
  2003.                 else if ( (myipnum[0] & 0xC0 )==0x80)
  2004.                     defmask=0xffff0000;                        /* Class B */
  2005.                 else if ( (myipnum[0] & 0xC0 )==0xC0)
  2006.                     defmask=0xffffff00;                        /* Class C */
  2007.             if (!cmask) mynetmask=defmask;
  2008.             dynamic=1;
  2009.             }
  2010.         else dynamic=0;
  2011.         }
  2012.     else if (error) quit();
  2013.  
  2014.     setnetconfigs((char *) myipnum,  &mynetmask);    /* BYU LSC */
  2015.     if (RegIP((char *) myipnum))                    /* BYU LSC */
  2016.         reconfigNetwork(1);
  2017.     return(0);
  2018. } /* initipnum */
  2019.  
  2020. /*
  2021. *  special dialog for the driver version.
  2022. *  This one only prompts for default host and nothing else.
  2023. *  Much of the appearance of the dialog is retained so that the user can switch
  2024. *  versions easily.
  2025. */
  2026. int driverconf
  2027.   (
  2028.     void
  2029.   )
  2030. {
  2031. /*#define GetStrRes(x)    (Str255 **)GetResource('STR ',(x));        /* BYU LSC - defined above */
  2032.  
  2033.     DialogPtr dtemp;
  2034.     Str255 *ptemp;
  2035.     Str255 **hostR;
  2036.     Rect dBox;
  2037.     Handle dHand;
  2038.     int terr;
  2039.     short dItem;
  2040.  
  2041.  
  2042.     dtemp=GetNewDialog( GetDefDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  2043.  
  2044.  
  2045.     hostR=GetStrRes( HostSTR);        /* Was there a default host */
  2046.     if (hostR!=0L) {                            /* If So...*/
  2047.         GetDItem(dtemp,6,&dItem,&dHand,&dBox);    /* Get the dialog item */
  2048.         HLock((Handle) hostR);                    /* Lock the string in */
  2049.  
  2050.         SetIText(dHand, (Str255 *) *hostR);        /* BYU LSC - Set the item's text to the old 1*/
  2051.         SelIText(dtemp,6,0,1000);
  2052.         HUnlock((Handle) hostR);                /* Unlock the string */
  2053.         putln("Reading previous Default Dest. Resource");
  2054.         }
  2055.     
  2056.  
  2057.     UItemAssign( dtemp, 7, (int (*)()) OutlineItem);
  2058.         
  2059.     dItem = 3;
  2060.     while (dItem> 2)     /* cancel == 1, OK == 2 */
  2061.         ModalDialog((ModalFilterProcPtr) modalProc, &dItem);
  2062.  
  2063.     if (SettingsFile==-1 || dItem == 2) {
  2064.         DisposDialog(dtemp);
  2065.         return(0);
  2066.         }
  2067.         
  2068.     if (hostR ==0L) {
  2069.         putln("Making new Host resource");
  2070.         hostR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  2071.         if (hostR==0L) putln(nospacemsg);                            /* BYU LSC */
  2072.         AddResource((Handle) hostR,'STR ',257,"\pDefault Host");    /* BYU LSC */
  2073.         if ((terr=ResError())!=0) {
  2074.             putln("Error in addresource");
  2075.             }
  2076.         }
  2077.  
  2078.     HLock((Handle) hostR);                        /* Lock it down */
  2079.     ptemp=*hostR;                                /* a pointer for sanity*/
  2080.  
  2081.     GetDItem(dtemp,6,&dItem,&dHand,&dBox);        /* Get the Default Host */
  2082.     GetIText(dHand, (Str255 *) ptemp);            /* BYU LSC */
  2083.  
  2084.     memmove(defaultd, ptemp, (size_t) 256);        /* BYU LSC - Make a copy for later */
  2085.     p2cstr((char *) defaultd);
  2086.  
  2087.     HUnlock((Handle) hostR);
  2088.     ChangedResource((Handle) hostR);
  2089.     UpdateResFile(HomeResFile((Handle) hostR));
  2090.  
  2091.     DisposDialog( dtemp);
  2092.  
  2093.     return(1);
  2094. } /* driverconf */
  2095.  
  2096.  
  2097. /*********************************************************************/
  2098. /*  parse
  2099. *   look at the string which has just come in from outside and
  2100. *   check for special sequences that we are interested in.
  2101. *
  2102. *   Tries to pass through routine strings immediately, waiting for special
  2103. *   characters ESC and 255 to change modes.
  2104. */
  2105.  
  2106. #define STNORM    0
  2107. #define parseEOF        236        /* BYU LSC */
  2108. #define    SE        240
  2109. #define    NOP        241
  2110. #define DM        242
  2111. #define BREAK    243
  2112. #define IP        244
  2113. #define AO        245
  2114. #define    AYT        246
  2115. #define    EC        247
  2116. #define EL        248
  2117. #define GA        249
  2118. #define    SB        250
  2119. #define WILLTEL 251
  2120. #define WONTTEL 252
  2121. #define DOTEL    253
  2122. #define DONTTEL 254
  2123. #define    IAC        255
  2124. #define    SEXECUTE            200
  2125. #define    NEGOTIATE            1
  2126. #define ESCFOUND             5
  2127. #define IACFOUND             6
  2128.  
  2129. #define BINARY                 0
  2130. #define ECHO                1
  2131. #define SGA                    3
  2132. #define STATUS                5
  2133. #define TIMING                6
  2134. #define    TERMTYP                24
  2135. #define GS                    29
  2136. #define NAWS                31
  2137. #define    TERMSPEED            32
  2138. #define REMOTEFLOW            33
  2139. #define LINEMODE             34
  2140.     #define MODE 1
  2141.         #define EDIT     1
  2142.         #define TRAPSIG  2
  2143.         #define MODE_ACK 4
  2144.  
  2145.  
  2146. #define FORWARDMASK 2
  2147.  
  2148. #define    substate    tw->substat
  2149.  
  2150. void parse
  2151.   (
  2152.     struct WindRec *tw,
  2153.     unsigned char *st,
  2154.     int cnt
  2155.   )
  2156. {
  2157.     int i,temptw;
  2158.     unsigned char *mark,*orig;
  2159.     char parsedat[40];
  2160.     char mesg[50];
  2161. #ifdef OPTSDEBUG
  2162.     char munger[255]; 
  2163. #endif
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.     orig = st;                /* remember beginning point */
  2171.     mark = st + cnt;        /* set to end of input string */
  2172. /*
  2173. * raw mode for debugging, passes through escape sequences and other
  2174. * special characters as <27> symbols
  2175. */
  2176.     if (tw->termstate == DUMBTYPE) {
  2177.         for (i=0; i < cnt; i++,st++)            /* put on screen raw */
  2178.             if (*st == 27 || *st > 126) {
  2179.                 sprintf(parsedat,"<%d>",*st);
  2180.                 VSwrite(tw->vs,parsedat,strlen(parsedat));    /* send to virtual screen */
  2181.             }
  2182.             else
  2183.                 VSwrite(tw->vs,(char *) st,1);        /* BYU LSC */
  2184.     }
  2185.     else {
  2186.  
  2187. /*
  2188. *  traverse string, looking for any special characters which indicate that
  2189. *  we need to change modes.
  2190. */
  2191.     while (st < mark) {
  2192.  
  2193.         switch (tw->telstate) {
  2194.             case GS:
  2195.             case ESCFOUND:
  2196.                 if ((*st == 12) || (tw->telstate == GS))    /* esc-FF */
  2197.                 {
  2198.                     if ((tw->termstate == VTEKTYPE) || (!tw->tekclear))
  2199.                     {
  2200.                         if (tw->termstate == VTEKTYPE)
  2201.                             putln("Entering Tek mode");
  2202.                         else if (tw->curgraph > -1)
  2203.                             detachGraphics(tw->curgraph);
  2204.                         if (tw->curgraph <=  -1)
  2205.                         {
  2206.                             temptw = VGnewwin(1,tw->vs);
  2207.                             if (temptw > -1)
  2208.                             {
  2209.                                 tw->curgraph = temptw;
  2210.  
  2211.                                 VGgiveinfo(temptw);
  2212.                                 RGattach(temptw,tw->vs,tw->name);
  2213.                             }
  2214.                             else
  2215.                                 tw->telstate = STNORM;
  2216.                         }
  2217.                         if (tw->telstate != STNORM)
  2218.                             tw->termstate = TEKTYPE;
  2219.                     }
  2220.                     if (tw->telstate == GS)
  2221.                     {
  2222.                         st++;
  2223.                         VGwrite(tw->curgraph,"\035",1);
  2224.                     }
  2225.                     else if (tw->telstate != STNORM)
  2226.                         VGwrite(tw->curgraph,"\037\033\014",3);
  2227.                     tw->telstate = STNORM;
  2228.                     break;
  2229.                 }
  2230.     
  2231.                 if (*st == '^')                /* ESC- ^ */
  2232.                 {
  2233.                     tw->termstate = RASTYPE;
  2234.                     tw->telstate = STNORM;
  2235.                     VRwrite("\033^",2);        /* Put it through */
  2236.                     orig = ++st;
  2237.                     break;
  2238.                 }
  2239.                 
  2240.                 if (tw->termstate == TEKTYPE)
  2241.                     VGwrite(tw->curgraph,"\033",1);
  2242.                 else if (tw->termstate  == RASTYPE)
  2243.                     VRwrite("\033",1);
  2244.                 else
  2245.                     VSwrite(tw->vs,"\033",1);    /* send the missing ESC */
  2246.                 tw->telstate = STNORM;
  2247.                 break;
  2248.             case IACFOUND:         /* telnet option negotiation */
  2249.                 if (*st == 255) {        /* real data = 255 */
  2250.                     st++;                /* real 255 will get sent */
  2251.                     tw->telstate = STNORM;
  2252.                     break;
  2253.                 }
  2254.                 if ( 239 < *st ) {
  2255.                     tw->telstate = *st;        /* by what the option is */
  2256.                     st++;
  2257.                     break;
  2258.                 }
  2259.                 putln("Strange telnet option!");
  2260.                 tw->telstate = STNORM;
  2261.                 orig=st;
  2262.                 break;
  2263.  
  2264.             case parseEOF:        /* BYU LSC */
  2265. #ifdef OPTSDEBUG
  2266.                 sprintf(munger,"RECV: %s",telstates[tw->telstate - SE]);
  2267.                 putln(munger); 
  2268. #endif
  2269.                 orig=st;
  2270.                 tw->telstate=STNORM;
  2271.                 
  2272.                 break;
  2273.  
  2274.             case EL:                /* thanx Quincey!!! */
  2275.             case EC:
  2276.             case AYT:
  2277.             case AO:
  2278.             case IP:
  2279.             case BREAK:
  2280.             case DM:
  2281.             case NOP:
  2282.             case SE:
  2283. #ifdef OPTSDEBUG
  2284.                 sprintf(munger,"RECV: %s",telstates[tw->telstate - SE]);
  2285.                 putln(munger); 
  2286. #endif
  2287.                 tw->telstate = STNORM;
  2288.                 orig=st;
  2289.  
  2290.             case GA:
  2291.                 orig=st;
  2292.                 tw->telstate = STNORM;
  2293.                 break;
  2294.             case DOTEL:
  2295. #ifdef OPTSDEBUG
  2296.                 sprintf(munger,"RECV: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2297.                 putln(munger); 
  2298. #endif
  2299.  
  2300.                 switch( *st) {
  2301.                     case  SGA:        /* Sure we'll supress GA */
  2302.                         if (!tw->Isga)
  2303.                             {
  2304.                             tw->Isga=1;
  2305.                             sprintf(parsedat,"%c%c%c",255,WILLTEL,*st);
  2306.                             netpush(tw->port);
  2307.                             netwrite(tw->port,parsedat,3);
  2308.                             }
  2309.                         tw->telstate = STNORM;
  2310.                         orig = ++st;
  2311.                         break;
  2312.                     case TERMTYP:        /* And we'll even tell you about ourselves */
  2313.                         if (!tw->Ittype)
  2314.                             {
  2315.                             tw->Ittype=1;
  2316.                             sprintf(parsedat,"%c%c%c",255,WILLTEL,*st);
  2317.                             netpush(tw->port);
  2318.                             netwrite(tw->port,parsedat,3);
  2319.                             }
  2320.                         tw->telstate = STNORM;
  2321.                         orig = ++st;
  2322.                         break;
  2323.  
  2324.                     case  NAWS:            /* NCSA: sure, I like changing the window size! */
  2325.                         tw->naws =1;                                    /* NCSA: this session is now NAWS */
  2326.                         sprintf(parsedat,"%c%c%c",255,WILLTEL,*st);        /* NCSA: reply, we will to NAWS */
  2327.                         netpush(tw->port);                                /* NCSA */
  2328.                         netwrite(tw->port,parsedat,3);                    /* NCSA: send it out */
  2329. #if 1
  2330.                         sprintf(parsedat,"%c%c%c%c%c%c%c%c%c",IAC,SB,    /* BYU 2.4.16 */
  2331.                             NAWS,(char)0,(unsigned char)tw->width,        /* BYU 2.4.16 */
  2332.                             (char)0,(unsigned char)tw->rows,IAC,SE);    /* BYU 2.4.16 */
  2333.                         netpush(tw->port);                                /* BYU 2.4.16 */
  2334.                         netwrite(tw->port,parsedat,9);                    /* BYU 2.4.16 */
  2335. #endif
  2336.                         tw->telstate = STNORM;                            /* NCSA */
  2337.                         orig = ++st;                                    /* NCSA */
  2338.                         break;                                            /* NCSA */
  2339.  
  2340.                     case LINEMODE:  /* Sure I'll do line mode... */
  2341.                         if (tw->lineAllow) 
  2342.                             {
  2343.                             sprintf(parsedat,"%c%c%c",IAC,WILLTEL,*st++);
  2344.                             putln("*** using linemode");
  2345.                             
  2346.                             netwrite(tw->port,parsedat,3);
  2347.                             
  2348.                             sprintf(parsedat,"%c%c%c%c",IAC,SB,LINEMODE,SLC);
  2349.                             netwrite(tw->port,parsedat,4);
  2350.                             putln("SENT: IAC SB LINEMODE SLC");
  2351.     
  2352.                             for (i=1; i<19; i++){
  2353.                                 if (tw->slc[i]==-1)
  2354.                                     {
  2355.                                     sprintf(parsedat,"%c%c%c",i,SLC_NOSUPPORT,0);
  2356. #ifdef OPTSDEBUG
  2357.                                     sprintf(munger,"     %s NO_SUPPORT 0",LMoptions[i]);
  2358. #endif
  2359.                                     }
  2360.                                 else
  2361.                                     {
  2362.                                     sprintf(parsedat,"%c%c%c",i,SLC_CANTCHANGE,(char)tw->slc[i]);
  2363. #ifdef OPTSDEBUG
  2364.                                     sprintf(munger,"     %s CANTCHANGE %i",LMoptions[i],(int)tw->slc[i]);
  2365. #endif
  2366.                                     }
  2367. #ifdef OPTSDEBUG
  2368.                                 putln(munger);
  2369. #endif
  2370.                                 netwrite(tw->port,parsedat,3);
  2371.                                 }
  2372.     
  2373.                             putln("SENT: IAC SE");
  2374.                             sprintf(parsedat,"%c%c",IAC,SE);
  2375.                             netwrite(tw->port,parsedat,2);
  2376.                             }
  2377.                             
  2378.                         else 
  2379.                             {
  2380.                             sprintf(parsedat,"%c%c%c",IAC,WONTTEL,LINEMODE);
  2381.                             netwrite(tw->port,parsedat,3);
  2382.  
  2383.                             putln("*** linemode not allowed");
  2384.                             }
  2385.  
  2386.                         break;
  2387. #ifdef HAMMMMER
  2388.                     case NAWS:
  2389.                         sprintf(parsedat,"%c%c%c%c%c%c%c%c%c",IAC,SB,NAWS,(char)0,(char)tw->width,(char)0,(char)tw->rows,IAC,SE);
  2390.                         netwrite(tw->port,parsedat,9);                        
  2391.                         break;
  2392. #endif
  2393.                     default:                /* But, we won't do .... */
  2394.                         sprintf(parsedat,"%c%c%c",255,WONTTEL,*st++);
  2395.                         putln("didnt do option");
  2396.                         netwrite(tw->port,parsedat,3);  
  2397.                         break;
  2398.                     }
  2399.                 tw->telstate = STNORM;
  2400.                 orig = st;
  2401.                 break;
  2402.  
  2403.             case DONTTEL:
  2404. #ifdef NOTNEEDED
  2405.                 switch( *st) {
  2406.                     case  3:        /* Sure we'll supress GA */
  2407.                         if (!tw->Isga)
  2408.                             break;
  2409.                         tw->Isga=0;
  2410.                         sprintf(parsedat,"%c%c%c",255,WONTTEL,*st++);
  2411.                         netpush(tw->port);
  2412.                         netwrite(tw->port,parsedat,3);
  2413.                         break;
  2414.                     case 24:        /* And we'll even tell you about ourselves */
  2415.                         if (!tw->Ittype)
  2416.                             break;
  2417.                         tw->Ittype=0;
  2418.                         sprintf(parsedat,"%c%c%c",255,WONTTEL,*st++);
  2419.                         netpush(tw->port);
  2420.                         netwrite(tw->port,parsedat,3);
  2421.                         break;
  2422.                     
  2423.                     default: 
  2424.                         st++;     /* this data is garbage */
  2425.                         break;
  2426.                     }
  2427. #endif
  2428.  
  2429. #ifdef OPTSDEBUG
  2430.                     sprintf(munger,"RECV: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2431.                     putln(munger); 
  2432. #endif
  2433.                     tw->telstate = STNORM;
  2434.                     orig = ++st;
  2435.                 break;
  2436.  
  2437.             case WILLTEL:
  2438. #ifdef OPTSDEBUG
  2439.                 sprintf(munger,"SENT: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2440.                 putln(munger); 
  2441. #endif
  2442.  
  2443.                 tw->telstate = STNORM;
  2444.                 switch(*st++) {
  2445.                     case 1:             /* Echo on the other end*/
  2446.                         if (!tw->echo)
  2447.                             break;
  2448.                         tw->echo = 0;    /* Ok, in that case they can echo... */
  2449.                         changeport(scrn,scrn);
  2450.                         sprintf(parsedat,"%c%c%c",255,DOTEL,1);
  2451.                         netpush(tw->port);
  2452.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2453.                         break;
  2454.                     case 3:                /* Supress GA */
  2455.                         if (tw->Usga)
  2456.                             break;
  2457.                         tw->Usga = 1;    /* Go Ahead and supress GA */
  2458.                         sprintf(parsedat,"%c%c%c",255,DOTEL,3);
  2459.                         netpush(tw->port);
  2460.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2461.                         break;
  2462.                     case TIMING:                /* Timing Mark */
  2463.                         tw->timing = 0;
  2464.                         break;
  2465.                     default:
  2466.                         sprintf(parsedat,"%c%c%c",255,DONTTEL,*(st-1));
  2467.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2468.                 }
  2469.                 orig = st;
  2470.                 break;
  2471.  
  2472.             case WONTTEL:
  2473. #ifdef OPTSDEBUG
  2474.                 sprintf(munger,"SENT: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2475.                 putln(munger); 
  2476. #endif
  2477.                 tw->telstate = STNORM;
  2478.                 switch(*st++) {         /* which option? */
  2479.                     case ECHO:             /* echo */
  2480.                         if (tw->echo)
  2481.                             break;
  2482.                         tw->echo = 1;    /* Ok, I will echo if I have to... */
  2483.                         changeport(scrn,scrn);
  2484.                         sprintf(parsedat,"%c%c%c",IAC,DONTTEL,ECHO);
  2485.                         netpush(tw->port);
  2486.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2487.                         break;
  2488.                     case 3:
  2489.                         if (!tw->Usga)
  2490.                             break;
  2491.                         tw->Usga = 0;
  2492.                         sprintf(parsedat,"%c%c%c",255,DONTTEL,*(st-1));
  2493.                         netpush(tw->port);
  2494.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2495.                         break;
  2496.                     case TIMING:                /* Timing Mark */
  2497.                         tw->timing = 0;
  2498.                         break;
  2499.                     default:
  2500.                         break;
  2501.                 }
  2502.                 orig = st;
  2503.                 break;
  2504.  
  2505.             case SB:
  2506.                 tw->telstate = NEGOTIATE;
  2507.                 orig=st;
  2508.                 i = substate=0;                /* Defined for each */
  2509.                 break;
  2510.  
  2511.             case NEGOTIATE:
  2512.                 if (substate <200) {
  2513.                     switch( *st) {
  2514.                         case IAC:
  2515.                             if (*(st+1) ==IAC) 
  2516.                                 {
  2517.                                 parsedat[i++]=*st++;
  2518.                                 parsedat[i++]=*st++;
  2519.                                 }
  2520.                             else 
  2521.                                 {
  2522.                                 parsedat[i]='\0';
  2523.                                 substate=*st++;
  2524.                                 }                            
  2525.                             break;
  2526.                         default:
  2527.                             parsedat[i++]=*st++;
  2528.                             break;
  2529.                         }
  2530.                     } else {
  2531.                     switch( substate) {
  2532.                         case IAC:
  2533.                             substate=*st++;
  2534.                             if (substate==SE) {
  2535.                                 switch( parsedat[0]) {
  2536.                                 case TERMTYP:
  2537.                                     if (parsedat[1]==1) {
  2538.                                         char s[50];
  2539.  
  2540.  
  2541. #ifdef OPTSDEBUG
  2542.                                         sprintf(munger,"RECV: SB TERMINAL-TYPE SEND\r\nSEND: SB TERMINAL-TYPE IS %s\r\n",TermType);
  2543.                                         putln(munger); 
  2544. #endif
  2545.                                         netpush(tw->port);
  2546.                                         netwrite(tw->port,"\377\372\030\000",4);
  2547.                                         netpush(tw->port);
  2548.                                         sprintf(s,"%s\377\360",TermType);
  2549.                                         netwrite(tw->port, s, strlen(s));
  2550.                                         }
  2551.                                     break;
  2552. /* this is the new line-mode stuff */
  2553.  
  2554.                                 
  2555.                                         case LINEMODE:
  2556.                                             switch(parsedat[1]){
  2557.                                                 char s[50];
  2558.  
  2559.                                                 case MODE:
  2560.  
  2561.                                                     if ((parsedat[2] & EDIT) &&tw->lineAllow)
  2562.                                                         tw->lmflag=1;
  2563.                                                     /*else
  2564.                                                         tw->lmflag=0; */
  2565.                                                         
  2566.                                             
  2567.                                                     sprintf(mesg,"value of tw->lmflag: %i",(int)tw->lmflag);
  2568.                                                     putln(mesg);
  2569.                                                     putln("SENT: IAC SB LINEMODE MODE");
  2570.  
  2571.                                                     sprintf(s,"%c%c%c%c",IAC,SB,LINEMODE,MODE);
  2572.                                                     netwrite(tw->port,s,4);
  2573.                                                     sprintf(s,"%c%c%c",parsedat[2]|MODE_ACK,IAC,SE);
  2574.                                                     netwrite(tw->port,s,3); 
  2575. #ifdef OPTSDEBUG
  2576.                                                     sprintf(munger,"     %i IAC SE",(int)(parsedat[2]|MODE_ACK));
  2577.                                                     putln(munger); 
  2578. #endif
  2579.                                                     break;
  2580.                                                 case DOTEL:
  2581.                                                     netwrite(tw->port,"\377\372\042",3);
  2582.                                                     sprintf(s,"%c\002\377\360",WONTTEL);
  2583.                                                     netwrite(tw->port,s,strlen(s));
  2584.                                                     break;
  2585.  
  2586.                                                 case WILLTEL:
  2587.                                                     netwrite(tw->port,"\377\372\042",3);
  2588.                                                     sprintf(s,"%c\002\377\360",DONTTEL);
  2589.                                                     netwrite(tw->port,s,strlen(s));
  2590.                                                     break;
  2591.  
  2592.  
  2593.                                                 case SLC:
  2594. #ifdef OPTSDEBUG
  2595.                                                     sprintf(munger,"RECV: SB LINEMODE SLC");
  2596.                                                     putln(munger);
  2597. #endif
  2598.                                                     for(i=2;(parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3) 
  2599.                                                         {
  2600. #ifdef OPTSDEBUG
  2601.                                                         if(parsedat[i+1] & SLC_AWK)
  2602.                                                             sprintf(munger,"     %s %s|AWK %d",LMoptions[parsedat[i]],LMflags[parsedat[i+1] & SLC_LEVELBITS],parsedat[i+2]);
  2603.                                                         else
  2604.                                                             sprintf(munger,"     %s %s %d",LMoptions[parsedat[i]],LMflags[parsedat[i+1] & SLC_LEVELBITS],parsedat[i+2]);
  2605.                                                         putln(munger);
  2606. #endif
  2607.                                                         if ((unsigned char)(parsedat[i+2])==IAC) i++;
  2608.  
  2609.                                                         }    /* end for */
  2610.                     
  2611.                                                     /* First check to see if we need to reply */
  2612.                                                     for (i=2;(parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3)
  2613.                                                         {
  2614.                                                         if (!(parsedat[i+1] & SLC_AWK)) break;
  2615.                                                         if ((unsigned char)(parsedat[i+2])==IAC) i++;
  2616.                                                         }
  2617.     
  2618.                                                     /* if we do then send a reply */
  2619.                                                     if ((parsedat[i]!=IAC) && (parsedat[i]!='\0'))
  2620.                                                         {
  2621.                                                         sprintf(s,"%c%c%c%c",IAC,SB,LINEMODE,SLC);
  2622.                                                         netwrite(tw->port,s,4);
  2623.                                                         putln("SENT: IAC SB LINEMODE SLC");
  2624.         
  2625.  
  2626. #ifdef NEWSLC
  2627.                                                         for (i=2; (parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3)
  2628.                                                             {
  2629.                                                             if (!(parsedat[i+1] & SLC_AWK))        /* no response of ACK set */
  2630.                                                                 {
  2631.                                                                 if (parsedat[i+1] != SLC_NOSUPPORT)
  2632.                                                                     {
  2633.                                                                     sprintf(s,"%c%c%c",parsedat[i],SLC_NOSUPPORT,0);
  2634. #ifdef OPTSDEBUG
  2635.                                                                     sprintf(munger,"     %s NOSUPPORT 0",LMoptions[parsedat[i]]);
  2636. #endif
  2637.                                                                     }
  2638.                                                                 else        /* Acknowledge the No_Support case */
  2639.                                                                     {
  2640.                                                                     sprintf(s,"%c%c%c",parsedat[i],SLC_AWK|SLC_NOSUPPORT,(char)0);
  2641. #ifdef OPTSDEBUG
  2642.                                                                     sprintf(munger,"     %s NOSUPPORT|AWK 0",LMoptions[parsedat[i]]);
  2643. #endif
  2644.                                                                     }                                                                
  2645. #ifdef OPTSDEBUG
  2646.                                                                 putln(munger);
  2647. #endif
  2648.                                                                 netwrite(tw->port,s,3);
  2649.                                                                 }
  2650.                                                                 if ((unsigned char)(parsedat[i+2])==IAC) i++;
  2651.                                                             }
  2652.  
  2653. #else
  2654.                                                         for (i=2; (parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3)
  2655.                                                             {
  2656.                                                             if (!(parsedat[i+1] & SLC_AWK))
  2657.                                                                 {
  2658.                                                                 if (tw->slc[parsedat[i]]==-1)
  2659.                                                                     {
  2660.                                                                     sprintf(s,"%c%c%c",i,SLC_NOSUPPORT,0);
  2661. #ifdef OPTSDEBUG
  2662.                                                                     sprintf(munger,"     %s %s 0",LMoptions[i],LMflags[parsedat[i+1] & SLC_LEVELBITS]);
  2663. #endif
  2664.                                                                     }
  2665.                                                                 else
  2666.                                                                     {
  2667.                                                                     sprintf(s,"%c%c%c",i,SLC_CANTCHANGE,(char)tw->slc[parsedat[i]]);
  2668. #ifdef OPTSDEBUG
  2669.                                                                     sprintf(munger,"     %s %s 0",LMoptions[i],LMflags[parsedat[i+1] & SLC_LEVELBITS]);
  2670. #endif
  2671.                                                                     }                                                                
  2672. #ifdef OPTSDEBUG
  2673.                                                                 putln(munger);
  2674. #endif
  2675.                                                                 netwrite(tw->port,s,3);
  2676.                                                                 if (parsedat[i+2]==IAC) i++;
  2677.                                                                 }
  2678.                                                             }
  2679.                                                             
  2680. #endif
  2681.                                                         sprintf(s,"%c%c",IAC,SE);
  2682.                                                         netwrite(tw->port,s,2);
  2683.                                                         }
  2684.  
  2685.                                                 /* otherwise just exit */
  2686.                                                     break;
  2687.  
  2688.                                                 default:
  2689.                                                     break;
  2690.  
  2691.                                                 }
  2692.                                         break;
  2693.  
  2694. /* end of all the new line-mode shit */                                
  2695.                                 
  2696.                                 
  2697.                                 default:
  2698.                                     break;
  2699.                                 }
  2700.                             }
  2701.                             orig=st;
  2702.                             tw->telstate=STNORM;
  2703.                             break;
  2704.                         default:
  2705.                             orig=st;
  2706.                             tw->telstate=STNORM;
  2707.                             break;
  2708.                         }
  2709.                     }
  2710.  
  2711.                 break;
  2712.             default:
  2713.                 tw->telstate = STNORM;
  2714.                 break;
  2715.         }
  2716.  
  2717. /*
  2718. * quick scan of the remaining string, skip chars while they are
  2719. * uninteresting
  2720. */
  2721.         if (tw->telstate == STNORM) {
  2722. /*
  2723. *  skip along as fast as possible until an interesting character is found
  2724. */
  2725.  
  2726.             if (!tw->eightbit) {                                            /* BYU 2.4.10 */
  2727.                 while (st < mark) {                                            /* BYU 2.4.10 */
  2728.                     if (*st == IAC)                                         /* BYU 2.4.10 */
  2729.                         break;                                                /* BYU 2.4.10 */
  2730.                     else {                                                    /* BYU 2.4.10 */
  2731.                         *st &= 0x7f;                                         /* BYU 2.4.10 */
  2732.                         if (*st == ESC  || *st == GS)                         /* BYU 2.4.10 */
  2733.                             break;                                            /* BYU 2.4.10 */
  2734.                         st++;                                                /* BYU 2.4.10 */
  2735.                 }    }                                                        /* BYU 2.4.10 */
  2736.             } else                                                             /* BYU 2.4.10 */
  2737.                 while (st < mark && *st != ESC  && *st < 128 && *st != GS)     /* BYU 2.4.10 */
  2738.                     st++;                                                     /* BYU 2.4.10 */
  2739. /*
  2740. *  send the string where it belongs
  2741. */
  2742.             if (!tw->timing) {
  2743.                 if (tw->termstate == TEKTYPE) {
  2744.                     int i;
  2745.                     
  2746.                     i = VGwrite( tw->curgraph,(char *) orig,  st-orig);    /* BYU LSC */
  2747.                     if (i < (st - orig)) {
  2748.                         detachGraphics(tw->curgraph);
  2749.                         st = orig + i;
  2750.                         putln("From Tek to VS");
  2751.                         }
  2752.                     }
  2753.                 else if (tw->termstate == RASTYPE) {
  2754.                     int i;
  2755.                     
  2756.                     i= VRwrite((char *) orig, st-orig);        /* BYU LSC */
  2757.                     if (i <(st-orig)) {
  2758.                         tw->termstate = VTEKTYPE;
  2759.                         st = orig +i;                /* Next char to parse */
  2760.                         putln("From VR to VS");
  2761.                         }
  2762.                     }
  2763.                 else 
  2764.                     VSwrite( tw->vs,(char *) orig,st-orig);    /* BYU LSC - send to virtual VT102 */
  2765.                 }
  2766.  
  2767.             orig = st;                /* forget what we have sent already */
  2768.  
  2769.             if (st < mark)
  2770.             switch (*st) {
  2771.                 case 255:            /* telnet IAC */
  2772.                     tw->telstate = IACFOUND;
  2773.                     st++;
  2774.                     break;
  2775.                 case GS:
  2776.                     if (tw->telstate != GS)
  2777.                     {
  2778. #if 0    /* BYU */
  2779.                         putln("Hey, were here @ GS!!!");
  2780. #endif
  2781.                         tw->telstate = GS;
  2782.                     }
  2783.                     else
  2784.                         tw->telstate = STNORM;
  2785.                     st++;
  2786.                     break;
  2787.                     
  2788.                 case ESC:            /* ESCape code */
  2789.                     if (st == mark-1 || *(st+1) == 12 || *(st+1) == '^' ) {
  2790.                         tw->telstate = ESCFOUND;
  2791.                     }
  2792.                     st++;            /* strip or accept ESC char */
  2793.  
  2794.                     break;
  2795. #ifdef WORKSOLD
  2796.                 default:
  2797.                     if (*st > 127) {
  2798.                         putln("Strange char > 128!");
  2799.                         (*st++)&=0x7f;    /* NVT Ascii says I can... */
  2800.                       if (st==mark)     /*new addition */
  2801.                           VSwrite(tw->vs,(char *) orig,1);        /* BYU LSC */
  2802. #endif
  2803.                 default:
  2804.                     if (*st++ > 127) {
  2805. /*                        putln("Strange char > 128!");            /* BYU 2.4.10 */
  2806.                     /*    (*st++)&=0x7f;*/    /* NVT Ascii says I can... */
  2807.                       if (st==mark)     /*new addition */
  2808.                           VSwrite(tw->vs,(char *) orig,1);        /* BYU LSC */
  2809.  
  2810.  
  2811.                     }
  2812.                     break;
  2813.             }
  2814.  
  2815.         }
  2816.  
  2817.     }  /* end while */
  2818.     }
  2819. } /* parse */
  2820.  
  2821. int VGalive
  2822.   (
  2823.     int dnum
  2824.   )
  2825. {
  2826.     int i;
  2827.  
  2828.     i=0;
  2829.     while((i<numwindows) && (dnum!=screens[i].curgraph)) i++;
  2830.     if (i<numwindows) {
  2831.         return(1);
  2832.         }
  2833.     else {
  2834.         i=0;
  2835.         while ((i<graphs) && (dnum!=oldgraph[i])) i++;
  2836.         if (i<graphs)
  2837.             return(1);
  2838.         }
  2839.     return(0);
  2840. }
  2841.  
  2842. void destroyGraphics
  2843.   (
  2844.     int dnum
  2845.   )
  2846. {
  2847.     int i;
  2848.  
  2849.     i=0;
  2850.     while((i<numwindows) && (dnum!=screens[i].curgraph)) i++;
  2851.     if (i<numwindows) {
  2852.         screens[i].curgraph=-1;
  2853.         screens[i].termstate=VTEKTYPE;
  2854.         screens[i].enabled=1;
  2855.         }
  2856.     else {
  2857.         i=0;
  2858.         while ((i<graphs) && (dnum!=oldgraph[i])) i++;
  2859.         while (i<(MaxGraph-1))
  2860.             oldgraph[i]=oldgraph[++i];            /* Bump everyone down one slot */
  2861.         graphs--;                                /* One less graph to feed */
  2862.         }
  2863.     VGclose( dnum);
  2864. }
  2865.  
  2866. int isHFS
  2867.   (
  2868.     void
  2869.   )
  2870. {
  2871.     return
  2872.         HFSflag;        /* BYU LSC */
  2873. }
  2874.  
  2875. FindByVG(vg)
  2876. int vg;
  2877. {
  2878.     int i=0;
  2879.  
  2880.     while((i<numwindows) && (vg!=screens[i].curgraph)) i++;
  2881.     if (i>=numwindows) return(-1);
  2882.     return(i);
  2883. }
  2884.  
  2885. void TekEnable
  2886.   (
  2887.     int vg
  2888.   )
  2889. {
  2890.     int change;
  2891.  
  2892.     change=FindByVG( vg);
  2893.     if (change>=0)
  2894.         screens[change].enabled=1;
  2895. }
  2896.  
  2897. void TekDisable
  2898.   (
  2899.     int vg
  2900.   )
  2901. {
  2902.     int change;
  2903.  
  2904.     change=FindByVG( vg);
  2905.     if (change>=0)
  2906.         screens[change].enabled=0;
  2907. }
  2908.  
  2909. pascal void OutlineItem( dlog, itm)
  2910. DialogPtr dlog;
  2911. short itm;
  2912. {
  2913.     Rect ibox;
  2914.     char **ihndl;
  2915.     short typ;
  2916.     int item=itm;
  2917.     
  2918.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  2919.     PenSize( 3,3);
  2920.     InsetRect( &ibox, -4,-4);
  2921.     FrameRoundRect( &ibox, 16,16);
  2922. }
  2923.  
  2924. pascal void VersionNumber( dlog, itm)
  2925. DialogPtr dlog;
  2926. short itm;
  2927. {
  2928.     Rect ibox;
  2929.     char **ihndl;
  2930.     short typ;
  2931.     int item=itm;
  2932.  
  2933.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  2934.     TextFont( 3);
  2935.     TextSize( 9);
  2936.     MoveTo( ibox.left+((ibox.right-ibox.left)/2)-(StringWidth( VERSION)/2), ibox.bottom-2);        /* BYU LSC */
  2937.     DrawString( VERSION );        /* BYU LSC */
  2938. }
  2939.  
  2940.  
  2941. char *rindex(s,c)
  2942.     char *s,c;
  2943.     {
  2944.     char *p;
  2945.     
  2946.     p = NULL;
  2947.     
  2948.     while (*s) {
  2949.         if (*s == c)
  2950.             p = s;
  2951.         s++;
  2952.         }
  2953.  
  2954.     return(p);
  2955.  
  2956. }
  2957.  
  2958.  
  2959.  
  2960. void DoTheMenuChecks()
  2961. {
  2962.     short    active;
  2963.     short    windownum;
  2964.  
  2965.     if (numwindows>0)
  2966.         {
  2967.         EnableItem( myMenus[Conn],0);
  2968.         DrawMenuBar();
  2969.         }
  2970.  
  2971.     else 
  2972.         {
  2973.         DisableItem(myMenus[Conn],0);
  2974.         DrawMenuBar();
  2975.         }
  2976. #if 0
  2977.     active =0;
  2978.     
  2979.     for (windownum=0;windownum<numwindows;windownum++)
  2980.         if (!screens[windownum].active) active++;
  2981.         
  2982.     if (active<2)    
  2983.         DisableItem(myMenus[Conn],COnext);
  2984.     else EnableItem(myMenus[Conn],COnext);
  2985.  
  2986.     if (!active)
  2987.         {
  2988. /*        DisableItem(myMenus[Edit],EDcopy);
  2989.         DisableItem(myMenus[Edit],EDcopyt); */
  2990.         DisableItem(myMenus[Edit],EDpaste);
  2991.         DisableItem(myMenus[Emul],0);
  2992.         DrawMenuBar();
  2993.         }
  2994.     else 
  2995.         {
  2996. /*        EnableItem(myMenus[Edit],EDcopy);
  2997.         EnableItem(myMenus[Edit],EDcopyt); */
  2998.         EnableItem(myMenus[Edit],EDpaste);
  2999.         EnableItem( myMenus[Emul],0);
  3000.         DrawMenuBar();
  3001.         }
  3002. #endif
  3003. }