home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / files / Sets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-22  |  20.0 KB  |  758 lines

  1. /*
  2. *    Sets.c
  3. *    All code relating to loading, parsing, and saving of sets
  4. *
  5. *****************************************************************
  6. *    NCSA Telnet for the Macintosh                                *
  7. *                                                                *
  8. *    National Center for Supercomputing Applications                *
  9. *    Software Development Group                                    *
  10. *    152 Computing Applications Building                            *
  11. *    605 E. Springfield Ave.                                        *
  12. *    Champaign, IL  61820                                        *
  13. *                                                                *
  14. *    Copyright (c) 1986-1993,                                    *
  15. *    Board of Trustees of the University of Illinois                *
  16. *****************************************************************
  17. *  Revisions:
  18. *  7/92        Telnet 2.6:    Code moved here from config.c and maclook.c...  Jim Browne
  19. */
  20.  
  21. #ifdef MPW
  22. #pragma segment Files
  23. #endif
  24.  
  25. #include <stdio.h>            /* So sprintfs have protos... */
  26. #include <string.h>
  27. #include <ctype.h>
  28.  
  29. #include "TelnetHeader.h"
  30. #include "menu_resrcdefs.h"
  31. #include "string_resrcdefs.h"
  32. #include "general_resrcdefs.h"
  33. #include "macros.proto.h"
  34. #include "wind.h"            /* For WindRec definition */
  35. #include "Sets.proto.h"
  36. #include "telneterrors.h"
  37. #include "prefs.proto.h"
  38. #include "debug.h"
  39. #include "Connections.proto.h"
  40. #include "rsinterf.proto.h"
  41. #include "vsdata.h"
  42. #include "vsinterf.proto.h"
  43.  
  44. //#define    DEBUG_SETS
  45. #ifdef    DEBUG_SETS
  46. #define    sets_debug_print(x) putln(x)
  47. #else
  48. #define sets_debug_print(x)
  49. #endif
  50.  
  51. ConnInitParams    **SetParams;
  52. SessionPrefs    *SetSessionPtr;
  53. TerminalPrefs    *SetTerminalPtr;
  54.  
  55. char            *Cspace;
  56.  
  57. extern WindRec
  58.     *screens;        /* Window Records (VS) for :    Current Sessions */
  59.  
  60. extern SysEnvRec theWorld;                        /* System Environment record */
  61.  
  62. extern MenuHandle
  63.     myMenus[NMENUS];        /* Menu Handles .... */
  64.  
  65. #define PORTNUM 37            /* NCSA 2.5: the port variable */
  66.  
  67. void    SETSunload(void)    {}
  68.  
  69. /* affirmative() checks a token to see if it is a valid Affirmation string.
  70.     We now get the affirmative strings from the resource */
  71.     
  72. Boolean    affirmative( char *s)
  73. {
  74.     short    i;
  75.     Str255    AffWords;        /* Telnet 2.6: get string resources */
  76.  
  77.     for (i=0; i<TelInfo->position; i++)
  78.         s[i] = tolower( s[i] );
  79.  
  80.     for (i=1; i<= AFF_WORDS_COUNT ;i++) 
  81.         {
  82.         GetIndString(AffWords,AFF_WORDS_ID,i);
  83.         p2cstr(AffWords);
  84.         if (!ncstrcmp((char *)AffWords,s))                
  85.         break;                                        
  86.         }
  87.         
  88.     if (i <= AFF_WORDS_COUNT)
  89.         return(TRUE);
  90.     else
  91.         return(FALSE);
  92. }
  93.  
  94. /**************************************************************************/
  95. /*  Sissep
  96. *   is the character a valid separator for the hosts file?
  97. *   separators are white space, special chars and :;=
  98. *
  99. */
  100. Boolean Sissep( char c)
  101. {
  102.     if (c < 33)
  103.         return(1);
  104.     if (c == ':' || c == ';' || c == '=')
  105.         return(TRUE);
  106.     return(FALSE);
  107. }
  108.  
  109. /************************************************************************/
  110. /*  ncstrcmp
  111. *   No case string compare.
  112. *   Only returns 0=match, 1=no match, does not compare greater or less
  113. *   There is a tiny bit of overlap with the | 32 trick, but shouldn't be
  114. *   a problem.  It causes some different symbols to match.
  115. */
  116. short ncstrcmp(char *sa, char *sb)
  117. {
  118.     while (*sa && *sa < 33)        /* don't compare leading spaces */
  119.         sa++;
  120.     while (*sb && *sb < 33)
  121.         sb++;
  122.  
  123.     while (*sa && *sb) {
  124.         if ((*sa != *sb) && ((*sa | 32) != (*sb | 32)))
  125.             return(1);
  126.         sa++;sb++;
  127.     }
  128.     if (!*sa && !*sb)        /* if both at end of string */
  129.         return(0);
  130.     else
  131.         return(1);
  132. }
  133.  
  134. /* confile() now gets all of its keywords from the string resources, for greater
  135.     ease, flexibility, and overall coolness.  */
  136. short confile( char *s)
  137. {
  138.     short        i, port;
  139.     Boolean        success;
  140.     unsigned    int a,b,c,d;
  141.     int            signedint;
  142.     Str255        Ckeyw;
  143.     char        tempCstring[256];
  144.     
  145.     sets_debug_print(s);
  146.     if (!(*s) )
  147.         return(0);
  148.  
  149.     switch( TelInfo->CONFstate) {
  150.         case 0:                /* No keyword yet! */
  151.             for (i=0; i<TelInfo->position; i++)
  152.                 s[i] = tolower( s[i] );
  153.  
  154.             for (i=1; i<= SAVE_SET_STRINGS_COUNT ;i++) 
  155.                 {
  156.                 GetIndString(Ckeyw,SAVE_SET_STRINGS_ID,i);
  157.                 p2cstr(Ckeyw);
  158.                 if (!ncstrcmp((char *)Ckeyw,s))                
  159.                 break;                                        
  160.                 }
  161.  
  162.             if ( i > SAVE_SET_STRINGS_COUNT ) 
  163.                 {
  164.                 OperationFailedAlert(BAD_SET_ERR, 0, 0);
  165.                 return(1);
  166.                 }
  167.  
  168.             TelInfo->CONFstate=i;
  169.  
  170.             if (TelInfo->CONFstate==5) {
  171.                 SetSessionPtr->bksp = 0;
  172.                 TelInfo->CONFstate=0;
  173.                 }
  174.             if (TelInfo->CONFstate==6) {
  175.                 SetSessionPtr->bksp = 1;
  176.                 TelInfo->CONFstate=0;
  177.                 }
  178.             break;
  179.  
  180.         case 1:                /* NAME */
  181.             { char *p;
  182.             if (NULL == (p = NewPtr(40000)))         /* is there enough memory? */
  183.                 {                    /* NOT enough memory for the set! */
  184.                 DoError(107 | MEMORY_ERRORCLASS, LEVEL2, NULL);    /* register the error */
  185.                 return(-1);
  186.                 }
  187.             else
  188.                 DisposPtr(p);
  189.             }
  190.             if (TelInfo->CONFactive) {
  191.                 success = CreateConnectionFromParams(SetParams);
  192.                 SetParams = NULL;
  193.                 if (!success) {
  194.                     sets_debug_print("ERROR IN OPENING!! ");
  195.                     return(42);
  196.                     }
  197.                 }
  198.  
  199.             if (SetParams == NULL) {
  200.                 SetParams = ReturnDefaultConnInitParams();
  201.                 HLockHi((Handle)SetParams);
  202.                 HLockHi((Handle)(**SetParams).session);
  203.                 SetSessionPtr = *(**SetParams).session;
  204.                 HLockHi((Handle)(**SetParams).terminal);
  205.                 SetTerminalPtr = *(**SetParams).terminal;
  206.                 }
  207.                 
  208.             strncpy(tempCstring, s, 255);            /* Move name in */
  209.             CtoPstr(tempCstring);
  210.             BlockMove(tempCstring, (**SetParams).WindowName, tempCstring[0]+1);
  211.             TelInfo->CONFstate=0;
  212.             TelInfo->CONFactive=1;
  213.             break;
  214.  
  215.         case 2:                /* HOST */
  216.             strncpy(tempCstring, s, 63);            /* Move name in */
  217.             CtoPstr(tempCstring);
  218.  
  219.             //    Process the hosname string.
  220.             if (ProcessHostnameString((StringPtr)tempCstring, &port))
  221.                 SetSessionPtr->port = port;
  222.             
  223.             BlockMove(tempCstring, SetSessionPtr->hostname, tempCstring[0]+1);
  224.  
  225.             TelInfo->CONFstate=0;
  226.             break;
  227.  
  228.         case 3:                /* SIZE */
  229.             if ( 4 != sscanf(s, "{%d,%d,%d,%d}", &a, &b, &c,&d) ) {
  230.                 sets_debug_print("Error in window size");
  231.                 return(2);
  232.                 }
  233.             
  234.             (**SetParams).WindowLocation.top=a;
  235.             (**SetParams).WindowLocation.left=b;
  236.             (**SetParams).WindowLocation.bottom=c;
  237.             (**SetParams).WindowLocation.right=d;
  238.             TelInfo->CONFstate=0;
  239.             break;
  240.  
  241.         case 4:
  242.             if ( 1 != sscanf(s,"%d", &a) ) {
  243.                 sets_debug_print("Scrollback needs parameter");
  244.                 return(1);
  245.                 }
  246.             SetTerminalPtr->numbkscroll = a;
  247.             TelInfo->CONFstate=0;
  248.             break;
  249.  
  250.         case 5:
  251.             SetSessionPtr->bksp = 0;            
  252.             TelInfo->CONFstate=0;
  253.             break;
  254.  
  255.         case 6:
  256.             SetSessionPtr->bksp = 1;
  257.             TelInfo->CONFstate=0;
  258.             break;
  259.  
  260.         case 7:
  261.             setmacro( 0, s);
  262.             TelInfo->CONFstate=0;
  263.             break;
  264.         case 8:
  265.             setmacro( 1, s);
  266.             TelInfo->CONFstate=0;
  267.             break;
  268.         case 9:
  269.             setmacro( 2, s);
  270.             TelInfo->CONFstate=0;
  271.             break;
  272.         case 10:
  273.             setmacro( 3, s);
  274.             TelInfo->CONFstate=0;
  275.             break;
  276.         case 11:
  277.             setmacro( 4, s);
  278.             TelInfo->CONFstate=0;
  279.             break;
  280.         case 12:
  281.             setmacro( 5, s);
  282.             TelInfo->CONFstate=0;
  283.             break;
  284.         case 13:
  285.             setmacro( 6, s);
  286.             TelInfo->CONFstate=0;
  287.             break;
  288.         case 14:
  289.             setmacro( 7, s);
  290.             TelInfo->CONFstate=0;
  291.             break;
  292.         case 15:
  293.             setmacro( 8, s);
  294.             TelInfo->CONFstate=0;
  295.             break;
  296.         case 16:
  297.             setmacro( 9, s);
  298.             TelInfo->CONFstate=0;
  299.             break;
  300.         case 17:
  301.             TelInfo->CONFstate=0;        // Now ignored (was commandkeys)
  302.             break;
  303.         case 18:
  304.             if (!strcmp(s,"backspace") )
  305.                 SetSessionPtr->bksp = 0;
  306.             else
  307.                 SetSessionPtr->bksp = 1;
  308.             TelInfo->CONFstate=0;
  309.             break;
  310.         case 19:
  311.         case 21:
  312.             if ( 1 == sscanf(s,"%d", &a) ) 
  313.                 SetTerminalPtr->vtwidth = a;
  314.             TelInfo->CONFstate=0;
  315.             break;
  316.         case 20:
  317.             if (affirmative(s))
  318.                 SetSessionPtr->tekclear = 1;
  319.             else
  320.                 SetSessionPtr->tekclear = 0;
  321.             TelInfo->CONFstate = 0;
  322.             break;
  323.         case 22:
  324.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  325.                 sets_debug_print("Bad Parms to rgb");
  326.                 return(2);
  327.                 }
  328.             SetTerminalPtr->nfcolor.red = a;
  329.             SetTerminalPtr->nfcolor.green = b;
  330.             SetTerminalPtr->nfcolor.blue = c;
  331.             TelInfo->CONFstate = 0;
  332.             break;            
  333.         case 23:
  334.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  335.                 sets_debug_print("Bad Parms to rgb");
  336.                 return(2);
  337.                 }
  338.             SetTerminalPtr->nbcolor.red = a;
  339.             SetTerminalPtr->nbcolor.green = b;
  340.             SetTerminalPtr->nbcolor.blue = c;
  341.             TelInfo->CONFstate = 0;
  342.             break;            
  343.         case 24:
  344.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  345.                 sets_debug_print("Bad Parms to rgb");
  346.                 return(2);
  347.                 }
  348.             SetTerminalPtr->bfcolor.red = a;
  349.             SetTerminalPtr->bfcolor.green = b;
  350.             SetTerminalPtr->bfcolor.blue = c;
  351.             TelInfo->CONFstate = 0;
  352.             break;            
  353.         case 25:
  354.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  355.                 sets_debug_print("Bad Parms to rgb");
  356.                 return(2);
  357.                 }
  358.             SetTerminalPtr->bbcolor.red = a;
  359.             SetTerminalPtr->bbcolor.green = b;
  360.             SetTerminalPtr->bbcolor.blue = c;
  361.             TelInfo->CONFstate = 0;
  362.             break;
  363.         case 26:        /* Font Name */
  364.             strncpy(tempCstring, s, 63);            /* Move name in */
  365.             CtoPstr(tempCstring);
  366.             BlockMove(tempCstring, &(SetTerminalPtr->DisplayFont[0]), tempCstring[0]+1);
  367.             TelInfo->CONFstate = 0;
  368.             break;
  369.         case 27:        /* Font Size */
  370.             if (1 == sscanf( s, "%d", &a))
  371.                 SetTerminalPtr->fontsize = a;
  372.             TelInfo->CONFstate = 0;
  373.             break;
  374.         case 28:        /* number of lines to use for window's editable region */
  375.             if (1 == sscanf( s, "%d", &a))
  376.                 SetTerminalPtr->vtheight = a;
  377.             TelInfo->CONFstate = 0;
  378.             break;
  379.         case 29:        /* keystop, XOFF key */
  380.             if (1 == sscanf( s, "%d", &a))
  381.                 SetSessionPtr->skey = a;
  382.             TelInfo->CONFstate = 0;
  383.             break;
  384.         case 30:        /* keygo, XON key */
  385.             if (1 == sscanf( s, "%d", &a))
  386.                 SetSessionPtr->qkey = a;
  387.             TelInfo->CONFstate = 0;
  388.             break;
  389.         case 31:        /* keyip, kill key */
  390.             if (1 == sscanf( s, "%d", &a))
  391.                 SetSessionPtr->ckey = a;
  392.             TelInfo->CONFstate = 0;
  393.             break;
  394.         case 32:        /* cr-map */
  395.             if ((1 == sscanf( s, "%d", &a)) && (a !=0))
  396.                 SetSessionPtr->crmap = TRUE;
  397.             else
  398.                 SetSessionPtr->crmap = FALSE;
  399.             TelInfo->CONFstate = 0;
  400.             break;
  401.         case 33:                    /* BYU 2.4.9 */
  402.             if (affirmative(s))        /* BYU 2.4.9 */
  403.                 SetSessionPtr->linemode = TRUE;    /* BYU 2.4.9 */
  404.             else                    /* BYU 2.4.9 */
  405.                 SetSessionPtr->linemode = FALSE;    /* BYU 2.4.9 */
  406.             TelInfo->CONFstate=0;            /* BYU 2.4.9 */
  407.             break;                    /* BYU 2.4.9 */
  408.         case 34:                    /* BYU 2.4.9 */
  409.             if (affirmative(s))        /* BYU 2.4.9 */
  410.                 SetTerminalPtr->eightbit = TRUE;    /* BYU 2.4.9 */
  411.             else                    /* BYU 2.4.9 */
  412.                 SetTerminalPtr->eightbit = FALSE;    /* BYU 2.4.9 */
  413.             TelInfo->CONFstate=0;            /* BYU 2.4.9 */
  414.             break;                    /* BYU 2.4.9 */
  415.         case 35:                    /* BYU */
  416. //            (**SetParams).ftpstate = 1;        /* BYU */
  417.             TelInfo->CONFstate=0;            /* BYU */
  418.             break;                    /* BYU */
  419.         case 36:    // ignored
  420.             TelInfo->CONFstate=0;
  421.             break;
  422.         case PORTNUM:                            /* NCSA 2.5: get the real port # */
  423.             if (1 == sscanf( s, "%d", &a))        /* NCSA */
  424.                 SetSessionPtr->port = a;                /* NCSA */
  425.             TelInfo->CONFstate = 0;                /* NCSA */
  426.             break;                                /* NCSA */
  427.         case 38:    // translation
  428.             strncpy((char *) SetSessionPtr->TranslationTable, s, 32);
  429.             CtoPstr((char *) SetSessionPtr->TranslationTable);
  430.             TelInfo->CONFstate=0;
  431.             break;
  432.         case 39:    // tekem
  433.             if (1 == sscanf(s, "%d", &signedint))
  434.                 SetSessionPtr->tektype = signedint;
  435.             TelInfo->CONFstate=0;
  436.             break;
  437.         case 40:    // answerback
  438.             strncpy((char *) SetTerminalPtr->AnswerBackMessage, s, 32);
  439.             CtoPstr((char *) SetTerminalPtr->AnswerBackMessage);
  440.             TelInfo->CONFstate=0;
  441.             break;
  442.         default:
  443.             TelInfo->CONFstate=0;
  444.         }
  445.     return(0);
  446.   } /* confile */
  447.  
  448. /************************************************************************/
  449. /* contoken
  450. *  tokenize the strings which get passed to confile.
  451. *  Handles quotes and uses separators:  <33, ;:=
  452. */ 
  453. short contoken( char c)
  454. {
  455.     short        retval;
  456.     Boolean        success;
  457.  
  458.     if (c == EOF) {
  459.         Cspace[TelInfo->position++] = '\0';
  460.         sets_debug_print("Eof handler called");
  461.         confile(Cspace);
  462.         if (TelInfo->CONFactive) {
  463.                 success = CreateConnectionFromParams(SetParams);
  464.                 if (!success) {
  465.                     sets_debug_print("ERROR IN OPENING!! ");
  466.                     return(42);
  467.                     }
  468.                 }
  469.         return(-1);
  470.     }
  471.     
  472.     if (!TelInfo->position && !TelInfo->inquote && Sissep(c))
  473.     /*if (!TelInfo->position && Sissep(c))    */    /* old_skip over junk before keyword */
  474.         return(0);
  475.  
  476.     if (TelInfo->inquote || !Sissep(c)) {
  477.  
  478.         if (TelInfo->position > 200) {
  479.             sets_debug_print("Out of bounds error!");
  480.             return(1);
  481.         }
  482. /*
  483. *  check for quotes, a little mixed up here, could be reorganized
  484. */
  485.         if (c == '"' ) {
  486.             if (!TelInfo->inquote) {            /* beginning of quotes */
  487.                 TelInfo->inquote = 1;
  488.                 return(0);
  489.             }
  490.              Cspace[TelInfo->position++] =c;
  491.             return(0);
  492.         }
  493.         else 
  494.             {                        /* include in current string */
  495.             if (c != '\012' && c != '\015')        /* BYU 2.4.18 - changed \n to \015 and added \012 */
  496.                 {
  497.                 Cspace[TelInfo->position++] = c;
  498.                 return(0);
  499.                 }
  500.             }
  501.                 
  502.         }
  503.  
  504.     if (Cspace[TelInfo->position-1] == '"') TelInfo->position--;
  505.     Cspace[TelInfo->position++] = '\0';
  506.  
  507.     retval = confile(Cspace);            /* pass the token along */
  508.  
  509.     TelInfo->position = 0;
  510.     TelInfo->inquote = 0;
  511.     Cspace[0] = '\0';
  512.  
  513.     return(retval);
  514. }
  515.  
  516. /************************************************************************/
  517. /*  readconfig
  518. *   read the saved set file into our in-memory data structure.
  519. *   Handle everything by keyword (stored in resources).
  520. */
  521. void readconfig(FSSpec theSet)
  522. {
  523.     short c,retval;
  524.     short fn;
  525.     OSErr err;
  526.  
  527.     Cspace = NewPtr(256);                /* BYU LSC - get room for gathering stuff */
  528.  
  529.     SetParams = ReturnDefaultConnInitParams();
  530.     HLockHi((Handle)SetParams);
  531.     HLockHi((Handle)(**SetParams).session);
  532.     SetSessionPtr = *(**SetParams).session;
  533.     HLockHi((Handle)(**SetParams).terminal);
  534.     SetTerminalPtr = *(**SetParams).terminal;
  535.  
  536.     if (NULL == Cspace)                 /* no memory left for the set to load in */
  537.         {                                /* we're out of memory */
  538.         DoError(107 | MEMORY_ERRORCLASS, LEVEL2, NULL);    
  539.         return;
  540.         }
  541.     
  542.     TelInfo->position = TelInfo->CONFstate = TelInfo->CONFactive = TelInfo->inquote = TelInfo->lineno = 0;   /* state vars */    
  543.  
  544.     err = HOpen(theSet.vRefNum, theSet.parID, theSet.name, fsRdPerm, &fn);
  545.  
  546.     retval = 0;
  547.     while (!retval) {
  548.         c = Myfgetc(fn);
  549.         if (c == '#' && !TelInfo->inquote) {
  550.             while (c != EOF && c != '\012' && c != '\015')        /* skip to EOL */    /* BYU 2.4.18 - changed \n to \015 and added \012*/
  551.                 c = Myfgetc(fn);
  552.         }
  553.         if (c == '\012' || c == '\015')            /* BYU 2.4.18 - changed \n to \015 and added \012 */
  554.             TelInfo->lineno++;
  555.         retval = contoken(c);
  556.     }
  557.  
  558.     FSClose(fn);
  559.     DisposPtr((Ptr) Cspace);
  560.  
  561.     if (retval == EOF) {                /* EOF is normal end */
  562.         sets_debug_print("EOF termination");
  563.         }
  564.     else {
  565.         sets_debug_print("NON-EOF termination");
  566.         }
  567.         
  568.     return;
  569. }
  570.  
  571. void LoadSet( void)
  572. {
  573.     SFReply        sfr;
  574.     long        junk;
  575.     SFTypeList    typesok = {'CONF'};
  576.     Point        where;
  577.     FSSpec        set;
  578.  
  579.     where.h=100;where.v=100;
  580.  
  581.     SFGetFile( where, "\pSet to load:", 0L, 1, typesok, 0L, &sfr);
  582.  
  583.     if (! sfr.good) return;
  584.  
  585.     BlockMove(&sfr.fName, set.name, (*sfr.fName)+1); // pstring copy sfr.fName -> set.name
  586.     GetWDInfo(sfr.vRefNum, &set.vRefNum, &set.parID, &junk);
  587.     readconfig(set);
  588. }
  589.  
  590. char Myfgetc(short myfile)
  591. {
  592.     OSErr err;
  593.     long count;
  594.     unsigned char buffer;
  595.     
  596.     count = 1;
  597.     if ((err = FSRead(myfile, &count, &buffer)) == eofErr)
  598.         buffer = EOF;
  599.     
  600.     return (buffer);
  601. }
  602.  
  603. void CStringToFile(short myfile, unsigned char *mystring) 
  604. {    
  605.     long mycount;                                        /* BYU LSC */
  606.     short fstatus;                                        /* BYU LSC */
  607.   
  608.   mycount = strlen((char *) mystring);                /* BYU LSC */
  609.   fstatus = FSWrite(myfile,&mycount,mystring);        /* BYU LSC */
  610. }
  611.  
  612.  
  613. void SaveSet( void)
  614. {
  615.     SFReply        sfr;
  616.     short        fn, truncate;
  617.     WindowPeek    wpeek;
  618.     Rect        rect;
  619.     Point        where;
  620.     long        junk;
  621.     char        temp[256], temp2[256];            /* BYU LSC */
  622.     unsigned short    red, green, blue;
  623.     short            fnum,fsiz;
  624.     short            i;
  625.     FSSpec        set;
  626.     OSErr        err;
  627.     Str255        scratchPstring;
  628.     
  629.     where.h = 100; where.v = 100;
  630.  
  631.     SFPutFile( where, "\pSave Set to:", "\pTelnet Set", 0L, &sfr);    /* BYU LSC */
  632.  
  633.     if (!sfr.good)
  634.         return;
  635.  
  636.     BlockMoveData(&sfr.fName, set.name, (*sfr.fName)+1); // pstring copy sfr.fName -> set.name
  637.     GetWDInfo(sfr.vRefNum, &set.vRefNum, &set.parID, &junk);
  638.  
  639.     if ((err = HCreate(set.vRefNum, set.parID, set.name, kNCSACreatorSignature, kNCSASetFileType)) == dupFNErr)
  640.         truncate = 1;
  641.         
  642.     err = HOpen(set.vRefNum, set.parID, set.name, fsWrPerm, &fn);
  643.  
  644.     if (truncate) 
  645.         SetEOF(fn, 0L);
  646.  
  647.     if (gApplicationPrefs->CommandKeys)
  648.         CStringToFile(fn,(unsigned char *) "commandkeys = yes\015");    /* BYU LSC */
  649.     else
  650.         CStringToFile(fn,(unsigned char *) "commandkeys = no\015");        /* BYU LSC */
  651.  
  652.     for (i = 0; i < 10; i++)
  653.       {
  654.         getmacro(i, temp, sizeof(temp));            /* BYU LSC */
  655.         if (*temp) {                                    /* BYU LSC */
  656.             sprintf(temp2, "key%d = \"", i);            /* BYU 2.4.16 */
  657.             CStringToFile(fn,(unsigned char *) temp2);    /* BYU LSC */
  658.             CStringToFile(fn,(unsigned char *) temp);    /* BYU LSC */
  659.             strcpy(temp2,"\"\015");                        /* BYU LSC */
  660.             CStringToFile(fn,(unsigned char *) temp2);    /* BYU LSC */
  661.         }                                                /* BYU LSC */
  662.       } /* for */
  663.  
  664. #if 0                                                    /* BYU LSC */
  665.     for (i = 0; i < TelInfo->numwindows; i++)
  666.       {
  667.         short j;
  668.         j = RSgetfont(screens[i].vs, &fnum, &fsiz);
  669.       } /* for */
  670. #endif                                                    /* BYU LSC */
  671.  
  672.     for (i = 0; i < TelInfo->numwindows; i++)
  673.       {
  674.           GetWTitle(screens[i].wind, scratchPstring);
  675.           PtoCstr(scratchPstring);
  676.         sprintf(temp2, "name= \"%s\"\015", scratchPstring);
  677.         CStringToFile(fn,(unsigned char *) temp2);                /* BYU LSC */
  678.  
  679.         BlockMove((Ptr)screens[i].machine, (Ptr)scratchPstring, Length(screens[i].machine)+1);
  680.         PtoCstr(scratchPstring);
  681.         sprintf(temp2, "host= \"%s\"\015", scratchPstring);
  682.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  683.  
  684.         sprintf (temp2,"port= %d\015",screens[i].portNum);    /* NCSA: save port # */
  685.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  686.  
  687.         sprintf(temp2, "scrollback= %d\015", (screens[i].maxscroll));    /* BYU LSC */
  688.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  689.  
  690.         if (screens[i].bsdel)
  691.             CStringToFile(fn,(unsigned char *)  "erase = delete\015");        /* BYU LSC */
  692.         else
  693.             CStringToFile(fn,(unsigned char *)  "erase = backspace\015");    /* BYU LSC */
  694.  
  695.         wpeek = (WindowPeek) screens[i].wind;
  696.         rect = (*wpeek->contRgn)->rgnBBox;
  697.  
  698.         sprintf(temp2, "size = {%d,%d,%d,%d}\015", rect.top, rect.left,    /* BYU LSC */
  699.                     rect.bottom, rect.right);
  700.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  701.  
  702.         sprintf(temp2, "vtwidth = %d\015", VSmaxwidth(screens[i].vs) + 1);            /* BYU LSC */
  703.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  704.  
  705.         if (screens[i].tekclear)
  706.             CStringToFile(fn,(unsigned char *) "tekclear = yes\015");    /* BYU LSC */
  707.         else
  708.             CStringToFile(fn,(unsigned char *) "tekclear = no\015");    /* BYU LSC */
  709.  
  710.         if (theWorld.hasColorQD)
  711.           {
  712.             short j;
  713.             for (j = 0; j < 4; j++)
  714.               {
  715.                 RSgetcolor( screens[i].vs, j, &red, &green, &blue);
  716.                 sprintf(temp2, "rgb%d = {%u,%u,%u}\015",
  717.                     j, red, green, blue);
  718.                 CStringToFile(fn,(unsigned char *) temp2);
  719.               } /* for j */
  720.           } /* if */
  721.         RSgetfont( screens[i].vs, &fnum, &fsiz);
  722.         GetFontName( fnum, (StringPtr)temp);                                    /* BYU LSC */
  723. #ifndef MPW
  724.         p2cstr((unsigned char *) temp);                                /* BYU LSC */
  725. #endif
  726.  
  727.         sprintf( temp2, "font = \"%s\"\015", temp);                    /* BYU LSC */
  728.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  729.         sprintf( temp2, "fsize= %d\015", fsiz);                        /* BYU LSC */
  730.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  731.         
  732.         sprintf( temp2, "nlines= %d\015", VSgetlines(screens[i].vs));/* BYU LSC */
  733.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  734.         sprintf( temp2, "keystop= %d\015", screens[i].TELstop);        /* BYU LSC */
  735.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  736.         sprintf( temp2, "keygo= %d\015", screens[i].TELgo);            /* BYU LSC */
  737.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  738.         sprintf( temp2, "keyip= %d\015", screens[i].TELip);            /* BYU LSC */
  739.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  740.         sprintf( temp2, "crmap= %d\015", screens[i].crmap);        /* BYU LSC */
  741.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  742.         sprintf( temp2, "tekem= %d\015", screens[i].tektype);
  743.         CStringToFile(fn,(unsigned char *) temp2);
  744.         if (screens[i].national) {                        // Don't do this if using default translation table
  745.             GetItem(myMenus[National], screens[i].national+1, scratchPstring);
  746.             PtoCstr(scratchPstring);
  747.             sprintf(temp2, "translation= \"%s\"\015", scratchPstring);
  748.             CStringToFile(fn, (unsigned char *)temp2);
  749.             }
  750.         BlockMove(screens[i].answerback, scratchPstring, *(screens[i].answerback)+1);
  751.         PtoCstr(scratchPstring);
  752.         sprintf(temp2, "answerback= \"%s\"\015", scratchPstring);
  753.         CStringToFile(fn, (unsigned char *)temp2);
  754.       } /* for i */
  755.  
  756.     FSClose(fn);                        /* BYU LSC */
  757. }
  758.