home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char *SCCSid = "%W% (NCSA) %G%";
- #endif
- /*
- * config.c
- * User interface code for NCSA Telnet for the Macintosh
- * by Gaige B. Paulsen
- ****************************************************************************
- * *
- * Uses : *
- * TCP/IP kernel for NCSA Telnet *
- * by Tim Krauskopf *
- * with Macintosh code by Gaige B. Paulsen *
- * *
- * National Center for Supercomputing Applications *
- * 152 Computing Applications Building *
- * 605 E. Springfield Ave. *
- * Champaign, IL 61820 *
- * *
- * *
- ****************************************************************************
- *
- * Configuration structure and Set file functions.
- *
- * Called by:
- * menu.c
- * maclook.c
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #include <Dialogs.h>
- #include <Files.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <SegLoad.h>
- #include <Strings.h>
- #include <prefs.h>
- #include "configrec.h"
- #include "confile.h"
- #include "event.h"
- #include "hostform.h"
- #include "maclook.h"
- #include "menu.h"
- #include "netevent.h"
-
- #ifdef MPW
- #include "mpw.h"
- #endif
-
- extern int numwindows, whichMenus;
-
- char *Cspace;
-
- char *Ckeyw[] = {
- "", /* Skip so we start at one */
- "name", /* Name of session ** 1 **/
- "host", /* Name of host to use ** 2 **/
- "size", /* Window size (user) ** 3 **/
- "scrollback", /* Amount of scrollback ** 4 **/
- "backspace", /* set to backspace ** 5 **/
- "delete", /* set to delete ** 6 **/
- "key0", /* Macro definition key 0 ** 7 **/
- "key1", /* Macro definition key 1 ** 8 **/
- "key2", /* Macro definition key 2 ** 9 **/
- "key3", /* Macro definition key 3 ** 10 **/
- "key4", /* Macro definition key 4 ** 11 **/
- "key5", /* Macro definition key 5 ** 12 **/
- "key6", /* Macro definition key 6 ** 13 **/
- "key7", /* Macro definition key 7 ** 14 **/
- "key8", /* Macro definition key 8 ** 15 **/
- "key9", /* Macro definition key 9 ** 16 **/
- "commandkeys", /* Command keys active? ** 17 **/
- "erase", /* Erase mode (as in bs/del ) ** 18 **/
- "width", /* Width of the current session ** 19 **/
- "tekclear", /* Clear Tek for each drawing ** 20 **/
- "vtwidth", /* Tim, I am going to hit you ** 21 **/
- "rgb0", /* RGB Color #0 ** 22 **/
- "rgb1", /* RGB Color #1 ** 23 **/
- "rgb2", /* RGB Color #2 ** 24 **/
- "rgb3", /* RGB Color #3 ** 25 **/
- "font", /* Font for your window ** 26 **/
- "fsize", /* Size for mr. font ** 27 **/
- "nlines", /* number of active lines ** 28 **/
- "keystop", /* XOFF key ** 29 **/
- "keygo", /* XON key ** 30 **/
- "keyip", /* interrupt process key ** 31 **/
- "crmap", /* the CR mapping ** 32 **/
- "linemode", /* allow line mode ** 33 **/ /* BYU 2.4.9 */
- "eightbit", /* allow 8 bit font ** 34 **/ /* BYU 2.4.9 */
- "ftp", /* ftp session ** 35 **/ /* BYU */
- "serial", /* serial port connection ** 36 **/ /* BYU serial */
- "port", /* port number ** 37 **/ /* NCSA */
- "" /* END OF LIST */
- };
- char *AffWords[]= {
- "yes",
- "y",
- "on",
- "active",
- "true",
- "alive",
- "yup",
- "yep",
- "yessir",
- "affirmative",
- "ja",
- ""
- };
-
-
- #define PORTNUM 37 /* NCSA 2.5: the port variable */
-
- int CONFstate=0,CONFactive=0;
- int position, inquote, lineno ; /* state vars */
- FILE *fp;
-
- ConfigRec config;
-
- int affirmative( s)
- char *s;
- {
- int i;
-
- for (i=0; i<position; i++)
- s[i] = tolower( s[i] );
-
- for (i=0; *AffWords[i] && strcmp(AffWords[i],s); i++) ;
- if (*AffWords[i])
- return(1);
- else
- return(0);
- }
-
- /* Prime the Configuration with Default Data (Capital D) */
- void configdefault
- (
- ConfigRec *config
- )
- {
- config->tektype =0;
- config->bsdel=1; /* Default to Delete */
- config->ftpwind =0; /* not an ftp window */
- config->width=80; /* " " " " */
- config->ftpstate = 0; /* BYU - not at ftp session */
- config->connectionType = 0; /* BYU serial - not a serial port connection */
- config->nlines=24;
- config->tekclear=0;
- config->clearsave=0;
- config->halfdup=0;
- config->crmap=0x0a;
- config->vtwrap=0;
- config->scrollback=120; /* Should be user defined */
- config->machine="newton"; /* and host name pointer */
- config->name="newton"; /* and real name pointer */
- config->port = 23; /* default is to use telnet port */
- config->window.top = config->stdwindow.top = 40 +( numwindows *(5+Prefs.stag*15));
- config->window.left = config->stdwindow.left = 5 +( numwindows *(5+Prefs.stag*15));
- config->window.bottom= config->stdwindow.bottom=30000 +( numwindows *(5+Prefs.stag*15));
- config->window.right = config->stdwindow.right =30000 +( numwindows *(5+Prefs.stag*15));
- config->red[0] = 0;
- config->green[0] = 0;
- config->blue[0] = 0;
- config->red[1] = 65535;
- config->green[1] = 65535;
- config->blue[1] = 65535;
- config->red[2] = 0;
- config->green[2] = 61183;
- config->blue[2] = 11060;
- config->red[3] = 61183;
- config->green[3] = 2079;
- config->blue[3] = 4938;
- config->font = 4;
- config->fsize = 9;
- config->eightbit = 1; /* BYU 2.4.9 */
- config->forcesave = 0; /* NCSA 2.5 */
- config->TELstop = 19;
- config->TELgo = 17;
- config->TELip = 3;
- config->lineAllow = 1;
- }
-
- /* Prime the Configuration with real data.... */
- void primeConfig
- (
- ConfigRec *config
- )
- {
- struct machinfo *mp;
- char s[255];
-
- mp = Shostlook( config->machine);
- if (mp==NULL)
- mp = Shostlook("default");
- if (mp!= NULL) {
- config->bsdel = mp->bksp == 127;
- config->connectionType = 0; /* BYU serial - not a serial port connection */
- config->ftpstate = 0; /* BYU - not at ftp session */
- config->lineAllow = mp->linemode; /* BYU 2.4.9 */
- config->eightbit = mp->eightbit; /* BYU 2.4.9 */
- config->forcesave = mp->forcesave; /* NCSA 2.5 */
- config->width = mp->vtwidth;
- config->tektype = mp->tektype;
- config->nlines = mp->nlines;
- config->tekclear=1;
- config->clearsave = mp->clearsave;
- config->halfdup = mp->halfdup;
- config->crmap = mp->crmap;
- config->scrollback = mp->bkscroll;
- config->vtwrap = mp->vtwrap;
- config->port = mp->port;
- strcpy( s, mp->font);
- getfnum( s, &config->font);
- config->red[0] = mp->nfcolor[0];
- config->green[0] = mp->nfcolor[1];
- config->blue[0] = mp->nfcolor[2];
- config->red[1] = mp->nbcolor[0];
- config->green[1] = mp->nbcolor[1];
- config->blue[1] = mp->nbcolor[2];
- config->red[2] = mp->bfcolor[0];
- config->green[2] = mp->bfcolor[1];
- config->blue[2] = mp->bfcolor[2];
- config->red[3] = mp->bbcolor[0];
- config->green[3] = mp->bbcolor[1];
- config->blue[3] = mp->bbcolor[2];
- config->fsize = mp->fsize;
- config->TELstop = mp->skey;
- config->TELgo = mp->qkey;
- config->TELip = mp->ckey;
- config->window.top = config->stdwindow.top = 40 +( numwindows *(5+Prefs.stag*15));
- config->window.left = config->stdwindow.left = 5 +( numwindows *(5+Prefs.stag*15));
- config->window.bottom= config->stdwindow.bottom= 30000 +( numwindows *(5+Prefs.stag*15));
- config->window.right = config->stdwindow.right = 30000 +( numwindows *(5+Prefs.stag*15));
- }
- else {
- config->bsdel = 1;
- config->width = 80;
- config->nlines = 24;
- config->tekclear=1;
- config->clearsave=1;
- config->connectionType = 0; /* BYU serial - not a serial port connection */
- config->ftpstate = 0; /* BYU - not at ftp session */
- config->halfdup = 0;
- config->crmap = 0x0a;
- config->scrollback = 120;
- config->vtwrap = 0;
- config->tektype = 0;
- }
-
- if (config->width <2)
- if (config->width ==0)
- config->width=80;
- else config->width=132;
-
- if (config->TELip <= 0)
- config->TELip = -1; /* disable it */
- if (config->TELstop <= 0)
- config->TELstop = -1; /* disable it */
- if (config->TELgo <= 0)
- config->TELgo = -1; /* disable it */
- }
-
- int confile
- (
- char *s
- )
- {
- int i,scrn;
- unsigned int a,b,c,d;
-
- putln(s);
- if (!(*s) )
- return(0);
-
- switch( CONFstate) {
- case 0: /* No keyword yet! */
- for (i=0; i<position; i++)
- s[i] = tolower( s[i] );
-
- for (i=1; *Ckeyw[i] && strcmp(Ckeyw[i],s); i++) ;
-
- if ( !(*Ckeyw[i]) ) {
- putln("ERROR IN KEYWORD!");
- putln(s);
- return(1);
- }
-
- CONFstate=i;
-
- if (CONFstate==5) {
- config.bsdel=0;
- CONFstate=0;
- }
- if (CONFstate==6) {
- config.bsdel=1;
- CONFstate=0;
- }
- break;
-
- case 1: /* NAME */
- putln("NAME");
- { char *p;
- if (NULL == ((Ptr) p = NewPtr(40000))) {
- #ifndef MPW
- OtherError("\PLoad Set Error:","\PNo space for machine name");
- #else
- OtherError("Load Set Error:","Not enough memory to open");
- #endif MPW
- return(-1);
- }
- else
- DisposPtr(p);
- }
- if (CONFactive) {
- putln("Open attempt....");
- scrn=addport( &config ); /* Make our user window */
- if (scrn<0) {
- putln("ERROR IN OPENING!! ");
- return(42);
- }
- }
-
- configdefault( &config ); /* Set up the defaults */
- (Ptr) config.name = NewPtr( strlen( s) +2); /* Allocate namespace */
- strcpy(config.name, s); /* Move name in */
- config.name= config.name;
- CONFstate=0;
- CONFactive=1;
- break;
-
- case 2:
- putln("HOST");
- (Ptr) config.machine = NewPtr( strlen( s) +2); /* Allocate namespace */
- if (config.machine==NULL) {
- #ifndef MPW
- OtherError("\PLoad Set Error:","\PNo space for machine name");
- #else
- OtherError("Load Set Error:","No space for machine name");
- #endif MPW
- return(-1);
- }
- strcpy(config.machine, s); /* Move name in */
- primeConfig(&config);
- CONFstate=0;
- break;
-
- case 3: /* SIZE */
- putln("SIZE");
- if ( 4 != sscanf(s, "{%d,%d,%d,%d}", &a, &b, &c,&d) ) {
- putln("Error in window size");
- return(2);
- }
-
- config.window.top=a;
- config.window.left=b;
- config.window.bottom=c;
- config.window.right=d;
- CONFstate=0;
- break;
-
- case 4:
- if ( 1 != sscanf(s,"%d", &a) ) {
- putln(" You need a parameter after Scrollback ");
- return(1);
- }
- config.scrollback=a;
- CONFstate=0;
- break;
-
- case 5:
- config.bsdel=0;
- CONFstate=0;
- break;
-
- case 6:
- config.bsdel=1;
- CONFstate=0;
- break;
-
- case 7:
- setmacro( 0, s);
- CONFstate=0;
- break;
- case 8:
- setmacro( 1, s);
- CONFstate=0;
- break;
- case 9:
- setmacro( 2, s);
- CONFstate=0;
- break;
- case 10:
- setmacro( 3, s);
- CONFstate=0;
- break;
- case 11:
- setmacro( 4, s);
- CONFstate=0;
- break;
- case 12:
- setmacro( 5, s);
- CONFstate=0;
- break;
- case 13:
- setmacro( 6, s);
- CONFstate=0;
- break;
- case 14:
- setmacro( 7, s);
- CONFstate=0;
- break;
- case 15:
- setmacro( 8, s);
- CONFstate=0;
- break;
- case 16:
- setmacro( 9, s);
- CONFstate=0;
- break;
- case 17:
- if (affirmative(s))
- whichMenus=1;
- else
- whichMenus=0;
- switchMenus(whichMenus);
- CONFstate=0;
- break;
- case 18:
- if (strcmp(s,"backspace") )
- config.bsdel=1;
- else
- config.bsdel=0;
- CONFstate=0;
- break;
- case 19:
- case 21:
- if ( 1 != sscanf(s,"%d", &a) ) {
- config.width=80;
- }
- config.width=a;
- CONFstate=0;
- break;
- case 20:
- if (affirmative(s))
- config.tekclear = 1;
- else
- config.tekclear = 0;
- CONFstate = 0;
- break;
- case 22:
- case 23:
- case 24:
- case 25:
- if ( 3 != sscanf(s, "{%d,%d,%d}", &a, &b, &c)) {
- putln("Bad Parms to rgb");
- return(2);
- }
- config.red[ CONFstate-22] =a;
- config.green[CONFstate-22] =b;
- config.blue[ CONFstate-22] =c;
- CONFstate = 0;
- break;
- case 26: /* Font Name */
- #ifndef MPW
- ctop(s);
- #endif MPW
- getfnum( s, &config.font);
- CONFstate = 0;
- break;
- case 27: /* Font Size */
- if (1 == sscanf( s, "%d", &a))
- config.fsize=a;
- CONFstate = 0;
- break;
- case 28: /* number of lines to use for window's editable region */
- if (1 == sscanf( s, "%d", &a))
- config.nlines=a;
- CONFstate = 0;
- break;
- case 29: /* keystop, XOFF key */
- if (1 == sscanf( s, "%d", &a))
- config.TELstop=a;
- CONFstate = 0;
- break;
- case 30: /* keygo, XON key */
- if (1 == sscanf( s, "%d", &a))
- config.TELgo=a;
- CONFstate = 0;
- break;
- case 31: /* keyip, kill key */
- if (1 == sscanf( s, "%d", &a))
- config.TELip=a;
- CONFstate = 0;
- break;
- case 32: /* cr-map */
- putln("got crmap");
- if (1 == sscanf( s, "%d", &a))
- config.crmap=a;
- CONFstate = 0;
- break;
- case 33: /* BYU 2.4.9 */
- if (affirmative(s)) /* BYU 2.4.9 */
- config.lineAllow=1; /* BYU 2.4.9 */
- else /* BYU 2.4.9 */
- config.lineAllow=0; /* BYU 2.4.9 */
- CONFstate=0; /* BYU 2.4.9 */
- break; /* BYU 2.4.9 */
- case 34: /* BYU 2.4.9 */
- if (affirmative(s)) /* BYU 2.4.9 */
- config.eightbit=1; /* BYU 2.4.9 */
- else /* BYU 2.4.9 */
- config.eightbit=0; /* BYU 2.4.9 */
- CONFstate=0; /* BYU 2.4.9 */
- break; /* BYU 2.4.9 */
- case 35: /* BYU */
- config.ftpstate=1; /* BYU */
- CONFstate=0; /* BYU */
- break; /* BYU */
- case 36: /* BYU serial */
- config.connectionType=1;/* BYU serial */
- CONFstate=0; /* BYU serial */
- break; /* BYU serial */
- case PORTNUM: /* NCSA 2.5: get the real port # */
- if (1 == sscanf( s, "%d", &a)) /* NCSA */
- config.port=a; /* NCSA */
- CONFstate = 0; /* NCSA */
- break; /* NCSA */
- default:
- putln("I'm so stateless....");
- CONFstate=0;
- }
- return(0);
- } /* confile */
-
- /************************************************************************/
- /* Scontoken
- * tokenize the strings which get passed to Sconfile.
- * Handles quotes and uses separators: <33, ;:=
- */
- int contoken
- (
- int c
- )
- {
- int retval,scrn;
-
- if (c == EOF) {
- Cspace[position++] = '\0';
- putln("Eof handler called");
- confile(Cspace);
- if (CONFactive) {
- putln("attempting open");
- scrn=addport( &config ); /* Make our user window */
- if (scrn<0) {
- putln("ERROR IN OPENING!! ");
- return(42);
- }
- }
- return(-1);
- }
-
- if (!position && !inquote && Sissep(c))
- /*if (!position && Sissep(c)) */ /* old_skip over junk before keyword */
- return(0);
-
- if (inquote || !Sissep(c)) {
-
- if (position > 200) {
- putln("Out of bounds error!");
- return(1);
- }
- /*
- * check for quotes, a little mixed up here, could be reorganized
- */
- if (c == '"' ) {
- if (!inquote) { /* beginning of quotes */
- inquote = 1;
- return(0);
- }
- Cspace[position++] =c;
- return(0);
- }
- else
- { /* include in current string */
- if (c != '\n')
- {
- Cspace[position++] = c;
- return(0);
- }
- }
-
- }
-
- if (Cspace[position-1] == '"') position--;
- Cspace[position++] = '\0';
-
- retval = confile(Cspace); /* pass the token along */
-
- position = 0;
- inquote = 0;
- Cspace[0] = '\0';
-
- return(retval);
- }
-
- /************************************************************************/
- /* Sreadhosts
- * read in the hosts file into our in-memory data structure.
- * Handle everything by keyword, see docs for specifications about file.
- */
- int readconfig
- (
- char *Cfile
- )
- {
- int c,retval;
-
- (Ptr) Cspace = NewPtr(256); /* get room for gathering stuff */
-
- configdefault(&config);
-
- if (NULL == Cspace) {
- #ifndef MPW
- OtherError("\PNo space for set to load","\P ");
- #else
- OtherError("No space for set to load"," ");
- #endif MPW
- return(1);
- }
-
- position = CONFstate = CONFactive = inquote = lineno = 0; /* state vars */
-
- if (NULL == (fp = fopen(Cfile,"r"))) {
- putln("Couldn't open Configuration file:");
- putln( Cfile);
- return(1);
- }
-
- retval = 0;
- while (!retval) {
- c = fgetc(fp);
- if (c == '#' && !inquote) {
- while (c != EOF && c != '\n') /* skip to EOL */
- c = fgetc(fp);
- }
- if (c == '\n')
- lineno++;
- retval = contoken(c);
- }
-
- fclose(fp);
- DisposPtr((Ptr) Cspace);
-
- if (retval == EOF) { /* EOF is normal end */
- putln("EOF termination");
- return(0);
- }
- else {
- putln("NON-EOF termination");
- return(retval);
- }
- }
-
- /*
- * checkCONF - check if the user clicked on a configuration file
- */
-
- int checkCONF
- (
- void
- )
- {
- short i,mess,count,retcode=0;
- AppFile theFile;
-
- CountAppFiles(&mess,&count);
- if (mess==1) { putln("PRINTING...."); return(FALSE); }
- if (count<1) { putln("No files (<1)"); return(FALSE); }
- for(i=1;i<=count;i++) {
- GetAppFiles(i, &theFile);
- if (theFile.fType=='CONF') {
- ClrAppFiles(i);
- setvol( 0L, theFile.vRefNum);
- p2cstr( &theFile.fName);
- readconfig( &theFile.fName);
- putln("file has been read");
- retcode=1;
- }
- }
- return(retcode);
- }
-
-
-