home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Virtual Screen Kernel Interface
- * (vsinterf.c)
- *
- * by Gaige B. Paulsen
- *
- * This file contains the control and interface calls for the NCSA
- * Virtual Screen Kernal.
- *
- * VSinit(maxwidth) - Initialize the VSK
- * VSnewscreen(maxlines,scrnsave) - Initialize a new screen.
- * VSdetach(w) - Detach screen w
- * VSredraw(w,x1,y1,x2,y2) - redraw region for window w
- * VSwrite(w,ptr,len) - write text @ptr, length len
- * VSclear(w) - clear w's real screen
- * VSkbsend(w,k,echo) - send keycode k's rep. out window w (w/echo if req.)
- * VSclearall(w) - clear w's real and saved screen
- * VSreset(w) - reset w's emulator (as per TERM)
- * VSgetline(w,y) - get a ptr to w's line y
- * VSsetrgn(w,x1,y1,x2,y2) - set local display region
- * VSscrolback(w,n) - scrolls window w back n lines
- * VSscrolforward(w,n) - scrolls window w forward n lines
- * VSscrolleft(w,n) - scrolls window w left n columns
- * VSscrolright(w,n) - scrolls window w right n columns
- * VSscrolcontrol(w,scrlon,offtop) - sets scroll vars for w
- * VSgetrgn(w,&x1,&y1,&x2,&y2) - returns set region
- * VSsnapshot(w) - takes a snapshot of w
- * VSgetlines(w) - Returns current # of lines
- * VSsetlines(w, lines) - Sets the current # of lines to lines
- *
- * Version Date Notes
- * ------- ------ ---------------------------------------------------
- * 0.01 861102 Initial coding -GBP
- * 0.10 861113 Added some actual program to this file -GBP
- * 0.15 861114 Initiated Kludge Operation-GBP
- * 0.50 8611VSPBOTTOM Parameters added to VSnewscreen -GBP
- * 0.90 870203 Added the kbsend routine -GBP
- * 2.1 871130 NCSA Telnet 2.1 -GBP
- * 2.2 880715 NCSA Telnet 2.2 -GBP
- *
- */
-
- #ifdef MPW
- #pragma segment VS
- #endif
-
- #define VSMASTER
-
-
- #include "rsinterf.proto.h"
- #include "rsmac.proto.h"
- #include "vsem.proto.h"
- #include "vsdata.h"
- #include "vskeys.h"
- #include "vsinit.h"
- #include "vsintern.proto.h"
- #include "Wind.h"
- #include "DlogUtils.proto.h"
- #include "maclook.proto.h"
- #include "errors.proto.h"
- #define DEBUGMAC
-
- #include "vsinterf.proto.h"
-
- extern TelInfoRec *TelInfo;
- extern WindRec *screens;
- extern long TempItemsDirID;
- extern short TempItemsVRefNum;
-
- short
- /* Internal variables for use in managing windows */
- VSmax = 0, /* max nr screens allowed */
- VSinuse = 0; /* nr screens actually in existence */
- VSscrndata *VSscreens;
-
- short VSinit
- (
- short max /* max nr screens to allow */
- )
- /* initializes virtual screen and window handling. */
- {
- short i;
-
- RSinitall(max);
- VSmax = max;
- VSIwn = 0;
- if ((VSscreens = (VSscrndata *) myNewPtr(max * sizeof(VSscrndata))) == 0L)
- return(-2);
- for (i = 0; i < max; i++)
- {
- VSscreens[i].loc = 0L;
- VSscreens[i].stat = 0;
- } /* for */
- return(0);
- } /* VSinit */
-
-
- short VSiscapturing(short w) { /* BYU 2.4.18 */
- return(VSscreens[w].captureRN); /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
-
- Boolean VSopencapture(short scrn_num, short w)
- {
- UNUSED_ARG(scrn_num)
- static short captNumber = 1;
- short VRefNum;
- long DirID;
- Str255 filename, tempString;
- Str32 numstring;
- Point where = {100,100};
- SFReply sfr;
- long junk = 0;
- OSErr err;
-
- NumToString(captNumber++, numstring);
- GetIndString(filename, MISC_STRINGS, CAPTFILENAME);
- filename[++(filename[0])] = ' ';
- pstrcat(filename, numstring);
-
- GetIndString(tempString,MISC_STRINGS,SAVE_CAPTURED_TEXT_STRING);
- SFPutFile(where,tempString, filename, NULL, &sfr);
- if (sfr.good) {
- (void) GetWDInfo(sfr.vRefNum, &VRefNum, &DirID, &junk);
-
- err = HCreate(VRefNum, DirID, sfr.fName,
- gApplicationPrefs->CaptureFileCreator, 'TEXT');
- if (err == dupFNErr) {
- HDelete(VRefNum, DirID, sfr.fName);
- err = HCreate(VRefNum, DirID, sfr.fName,
- gApplicationPrefs->CaptureFileCreator, 'TEXT');
- }
-
- if (err != noErr)
- OperationFailedAlert(CANT_CREATE_FILE, 500, err);
- else {
- err = HOpen(VRefNum, DirID, sfr.fName, fsRdWrPerm,
- &VSscreens[w].captureRN);
- if (err != noErr) OperationFailedAlert(CANT_OPEN_FILE, 501, err);
- else {
- SetEOF(VSscreens[w].captureRN, (long) 0);
- return(TRUE);
- }
- }
- }
-
- return(FALSE);
- }
-
- void VSclosecapture(short w) { /* BYU 2.4.18 */
- FSClose(VSscreens[w].captureRN); /* BYU 2.4.18 */
- VSscreens[w].captureRN = 0; /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
-
- void VScapture(unsigned char *ptr, short len) { /* BYU 2.4.18 */
- long ln = len; /* BYU 2.4.18 */
- if (VSscreens[VSIwn].captureRN) { /* BYU 2.4.18 */
- unsigned char captbuf[512]; /* BYU 2.4.18 */
- unsigned char *ptr2,*ptr3; /* BYU 2.4.18 */
- ptr2 = ptr; /* BYU 2.4.18 */
- ptr3 = &captbuf[0]; /* BYU 2.4.18 */
- for (len = 0; len < ln; len++) { /* BYU 2.4.18 */
- if (*ptr2 >= 32 || /* BYU 2.4.18 */
- *ptr2 == 13 || /* BYU 2.4.18 */
- *ptr2 == 9) /* BYU 2.4.18 */
- *(ptr3++) = *(ptr2++); /* BYU 2.4.18 */
- else { /* BYU 2.4.18 */
- ptr2++; /* BYU 2.4.18 */
- ln--; /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
- if (ln > 0) { /* BYU 2.4.18 */
- if (FSWrite(VSscreens[VSIwn].captureRN, &ln, captbuf)) { /* BYU 2.4.18 */
- FSClose(VSscreens[VSIwn].captureRN); /* BYU 2.4.18 */
- VSscreens[VSIwn].captureRN = 0; /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
- } /* BYU 2.4.18 */
-
- short VSisprinting(short w)
- {
- return((VSscreens[w].loc)->prredirect);
- }
-
- void ClosePrintingFile(short w)
- {
- OSErr sts;
- char tmp[80];
-
- putln("Attempting to remove print file");
-
- if ((sts=FSClose ((VSscreens[w].loc)->refNum)) != noErr) {
- SysBeep(1);
- sprintf(tmp,"FSClose: ERROR %d",sts); putln(tmp);
- }
- if ((sts=HDelete(TempItemsVRefNum, TempItemsDirID, (StringPtr)VSIw->fname)) != noErr) {
- SysBeep(1);
- sprintf(tmp,"HDelete: ERROR %d",sts); putln(tmp);
- }
- }
-
- short VSvalids
- (
- short w
- )
- /* validates a virtual screen number and sets it as the
- current screen for subsequent operations if success.
- Returns 0 iff success. */
- {
- if (VSinuse == 0)
- return(-5); /* -5=no ports in use */
- if (VSIwn == w)
- return(0); /* Currently set to that window */
- if ((w > VSmax) || (w < 0))
- return(-6); /* blown out the top of the stuff */
- VSIwn = w;
- if (VSscreens[w].stat != 1)
- return(-3);/* not currently active */
- VSIw = VSscreens[w].loc;
- if (VSIw == 0L)
- return(-3); /* no space allocated */
- return(0);
- } /* VSvalids */
-
- VSscrn *VSwhereis(short i) /* screen number */
- /* returns a pointer to the structure for the specified screen. */
- {
- VSvalids(i);
- return(VSIw);
- } /* VSwhereis */
-
- void VSIclrbuf
- (
- void
- )
- /* clears out the text and attribute buffers for the current screen.
- All text characters are set to blanks, and all attribute bytes
- are set to zero. Doesn't update the display. */
- {
- register short j, i;
- register char *tx;
- register unsigned short *ta;
- for (i = 0; i <= VSIw->lines; i++)
- {
- ta = &VSIw->attrst[i]->text[0];
- tx = &VSIw->linest[i]->text[0];
- for (j = 0; j <= VSIw->allwidth; j++)
- {
- *ta++ = 0;
- *tx++ = ' ';
- } /* for */
- } /* for */
- } /* VSIclrbuf */
-
- short VSnewscreen
- (
- short maxlines, /* max lines to save in scrollback buffer */
- short screensave, /* whether to have a scrollback buffer */
- short numLines, //numLines initially on screen (CCP 2.7)
- short maxwid, /* number of columns on screen */
- short forcesave /* NCSA 2.5: force lines to be saved */
- )
- /* creates a new virtual screen, and returns its number. */
- {
-
- if (maxlines < VSDEFLINES)
- maxlines = VSDEFLINES;
-
- if (VSinuse >= VSmax)
- /* too many screens in existence */
- return(-1);
- VSIwn = 0;
- while ((VSIwn < VSmax) && (VSscreens[VSIwn].stat == 1))
- VSIwn++;
- if (VSIwn >= VSmax)
- /* shouldn't occur? */
- return(-1);
- numLines -= 1; //correct for internal use
-
- /*
- * Fill initial scrollback buffer and screen storage space.
- *
- * Memory allocation rules:
- * line->mem == 0 if not a memory allocation, line->mem == 1 if it is the first
- * VSline in a block (indeterminate size, may be size == 1)
- *
- * attributes array is ALWAYS allocated as one block. Internally represented and
- * manipulated as a linked list of lines, but only one of the lines will have
- * line->mem == 1. This list is always supposed to be circular (it is never
- * extended, as attributes are never scrolled back).
- *
- * scrollback and screen line buffer space is allocated in large blocks. Each
- * block will have line->mem == 1 if the pointer to that VSline is "free"able.
- * This list will either be circular (which means it has reached its full size),
- * or it will have a NULL next field at the end. During scrolling, the end may
- * be augmented until VSIw->numlines > VSIw->maxlines or we run out of memory.
- * Typically allocate memory 100 lines at a time in two blocks, one is the VSline
- * list, the other is the mem for the character storage.
- *
- */
-
- /* All memory allocation for this function is done at once, to help damage control in
- low memory situations */
-
- if ((VSscreens[VSIwn].loc = VSIw = (VSscrn *) myNewPtr(sizeof(VSscrn))) == 0L)
- return(-2);
-
- VSIw->lines = numLines;
- //VSIw->lines = 23; CCP 2.7 set this from the start
-
- VSIw->linest = VSInewlinearray(VSIw->lines + 1);
- if (VSIw->linest == NULL)
- {
- DisposePtr((Ptr)VSIw);
- VSscreens[VSIwn].loc = VSIw = NULL;
- return (-2);
- }
-
- VSIw->attrst = VSInewattrlinearray(VSIw->lines + 1);
- if (VSIw->attrst == NULL)
- {
- DisposePtr((Ptr)VSIw->linest);
- DisposePtr((Ptr)VSIw);
- VSscreens[VSIwn].loc = VSIw = NULL;
- return (-2);
- }
-
- VSIw->tabs = (char *) myNewPtr(132); /* NCSA: SB - allow 132 column mode */
- if (VSIw->tabs == NULL) /* CCP: Hey? Why not check if we got it?! */
- {
- DisposePtr((Ptr)VSIw->attrst);
- DisposePtr((Ptr)VSIw->linest);
- DisposePtr((Ptr)VSIw);
- VSscreens[VSIwn].loc = VSIw = NULL;
- return (-2);
- }
-
- VSIw->allwidth = 131; /* NCSA: SB - always allocate max lines */
-
- if (screensave)
- VSIw->buftop = VSInewlines(VSIw->lines + 1 + VSDEFLINES,1); /* screen lines plus some initial preallocated scrollback space */
- else
- VSIw->buftop = VSInewlines(VSIw->lines + 1,1); /* screen lines, no scrollback */
- if (VSIw->buftop == NULL)
- {
- DisposePtr((Ptr)VSIw->tabs);
- DisposePtr((Ptr)VSIw->attrst);
- DisposePtr((Ptr)VSIw->linest);
- DisposePtr((Ptr)VSIw);
- VSscreens[VSIwn].loc = VSIw = NULL;
- return(-2);
- }
- VSIw->linest[0] = VSIw->buftop;
- VSIw->attrst[0] = (VSattrlinePtr)VSInewlines(VSIw->lines + 1,2); /* new space for attributes (these are never scrolled back) */
- if (VSIw->attrst[0] == NULL)
- {
- VSIfreelinelist(VSIw->buftop);
- DisposePtr((Ptr)VSIw->tabs);
- DisposePtr((Ptr)VSIw->attrst);
- DisposePtr((Ptr)VSIw->linest);
- DisposePtr((Ptr)VSIw);
- VSscreens[VSIwn].loc = VSIw = NULL;
- return(-2);
- }
-
- VSIw->vistop = VSIw->scrntop = VSIw->buftop; /* initial view = screen */
-
- VSIlistndx(VSIw->scrntop, VSIw->attrst[0]); /* Set up screen arrays */
-
- VSIw->attrst[0]->prev = VSIw->attrst[VSIw->lines]; /* make attribute list circular, since it is never extended */
- VSIw->attrst[VSIw->lines]->next = VSIw->attrst[0];
-
- if (!screensave)
- { /* make text line list circular to indi