Clean up of Windows telnet source
authorKeith Vetter <keithv@fusion.com>
Thu, 27 Apr 1995 20:14:25 +0000 (20:14 +0000)
committerKeith Vetter <keithv@fusion.com>
Thu, 27 Apr 1995 20:14:25 +0000 (20:14 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5569 dc483132-0cff-0310-8789-dd5450dbe970

12 files changed:
src/windows/wintel/changelo
src/windows/wintel/edit.c
src/windows/wintel/emul.c
src/windows/wintel/font.c
src/windows/wintel/intern.c
src/windows/wintel/screen.c
src/windows/wintel/screen.h
src/windows/wintel/struct.h
src/windows/wintel/telnet.c
src/windows/wintel/telnet.def
src/windows/wintel/telnet.h
src/windows/wintel/wt-proto.h

index 2afd4f0550030f915d3a466603afed8b92b3f930..59c0eeb76d07ce49f34d967b3decb6f9b44dfc71 100644 (file)
@@ -1,3 +1,26 @@
+Thu Apr 27 12:00:00 1995  John Rivlin  <jrvlin@fusion.com>
+
+       * edit.c, emul.c, font.c, intern.c, screen.c, telnet.c, screen.h
+       struct.h, telnet.h, wt-proto.h
+       Clean up code extensively:
+               Change memory management to use calloc rather than locking
+               and unlocking handles everywhere.  This makes the code
+               much easier to understand and maintain.
+
+               Add assertions
+
+               Remove unused global values and scope global values
+               appropriately to remove accidental overlays of liked
+               name values (like hInst)
+
+               Make code formatting uniform and remove dead code.
+
+       * screen.c (InitNewScreen, ScreenWndProc): Rearranged window
+       creation order to so that SCREEN_HANDLE gets set up at the 
+       beginning of the window creation.  Thus we can create the 
+       window in the correct size and shape prior to showing it,
+       eliminating a resize after the window is shown.
+
 Tue Apr 18 17:11:56 1995 Keith Vetter (keithv@fusion.com)
 
        * telnet.c: bug fix with saving/restoring delete versus backspace.
index 16ac28c2485eb96cc47e38389141f5b497cc2298..02de7bea1dd2fbde8ba1e67f00a2b2e6868e6935 100644 (file)
+/* edit.c */
+
 #include <windows.h>
 #include <commdlg.h>
 #include <ctype.h>
+#include <assert.h>
 #include "screen.h"
 
 char *cInvertedArray;
-int bMouseDown=FALSE;
-int iLocStart,iLocEnd,bSelection;
-
-void Edit_LbuttonDown(HWND hWnd,LPARAM lParam) {
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    HMENU hMenu;
-    int iTmp,iXlocStart,iYlocStart;
-    HDC hDC;
-    
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-    
-    hDC=GetDC(hWnd);
-    for (iTmp=0; iTmp < fpScr->width*fpScr->height; iTmp++) {        
-        if (cInvertedArray[iTmp]) {
-            PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-            cInvertedArray[iTmp]=0;                    
-        }    
-    }
-    bSelection=FALSE;
-    hMenu=GetMenu(hWnd);
-    EnableMenuItem(hMenu,IDM_COPY,MF_GRAYED);
-    ReleaseDC(hWnd,hDC);
-    iXlocStart=(int)LOWORD(lParam)/fpScr->cxChar;
-       if (iXlocStart >= fpScr->width)
-               iXlocStart = fpScr->width - 1;
-    iYlocStart=(int)HIWORD(lParam)/fpScr->cyChar;
-       if (iYlocStart >= fpScr->height)
-               iYlocStart = fpScr->height - 1;
-    iLocStart=iXlocStart+(iYlocStart*fpScr->width);
-    bMouseDown=TRUE;
-    GlobalUnlock(hgScr);
-}
-
-void Edit_LbuttonUp(HWND hWnd, LPARAM lParam) {
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    int iTmp,iTmp2;
-    HMENU hMenu;
-    
-    bMouseDown=FALSE;
-    if (bSelection) return;
-    bSelection=TRUE;
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");        
-    iTmp=(int)LOWORD(lParam)/fpScr->cxChar;
-       if (iTmp >= fpScr->width)
-               iTmp = fpScr->width - 1;
-    iTmp2=(int)HIWORD(lParam)/fpScr->cyChar;
-       if (iTmp2 >= fpScr->height)
-               iTmp2 = fpScr->height - 1;
-    GlobalUnlock(hgScr);
-    iLocEnd=iTmp+(iTmp2*fpScr->width);
-    if (iLocEnd==iLocStart) {
-        bSelection=FALSE;
-    } else {
-        hMenu=GetMenu(hWnd);
-        EnableMenuItem(hMenu,IDM_COPY,MF_ENABLED);
-    }    
-}    
-    
+int bMouseDown = FALSE;
+int bSelection;
+
+static int iLocStart;
+static int iLocEnd;
+
+void Edit_LbuttonDown(
+       HWND hWnd,
+       LPARAM lParam)
+{
+       SCREEN *pScr;
+       HMENU hMenu;
+       int iTmp;
+       int iXlocStart;
+       int iYlocStart;
+       HDC hDC;
+       
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+       
+       hDC = GetDC(hWnd);
+       for (iTmp = 0; iTmp < pScr->width * pScr->height; iTmp++) {        
+               if (cInvertedArray[iTmp]) {
+                       PatBlt(hDC, iTmp % pScr->width * pScr->cxChar,
+                               (int) (iTmp / pScr->width) * pScr->cyChar,
+                               pScr->cxChar, pScr->cyChar, DSTINVERT);                
+                       cInvertedArray[iTmp] = 0;
+                       }
+       }
+       bSelection = FALSE;
+       hMenu = GetMenu(hWnd);
+       EnableMenuItem(hMenu, IDM_COPY, MF_GRAYED);
+       ReleaseDC(hWnd, hDC);
+       iXlocStart = (int) LOWORD(lParam) / pScr->cxChar;
+       if (iXlocStart >= pScr->width)
+               iXlocStart = pScr->width - 1;
+       iYlocStart = (int) HIWORD(lParam) / pScr->cyChar;
+       if (iYlocStart >= pScr->height)
+               iYlocStart = pScr->height - 1;
+       iLocStart = iXlocStart + iYlocStart * pScr->width;
+       bMouseDown = TRUE;
+
+} /* Edit_LbuttonDown */
+
+
+void Edit_LbuttonUp(
+       HWND hWnd,
+       LPARAM lParam)
+{
+       SCREEN *pScr;
+       int iTmp;
+       int iTmp2;
+       HMENU hMenu;
+       
+       bMouseDown = FALSE;
+       if (bSelection)
+               return;
+       bSelection = TRUE;
+
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+
+       iTmp = (int) LOWORD(lParam) / pScr->cxChar;
+       if (iTmp >= pScr->width)
+               iTmp = pScr->width - 1;
+       iTmp2 = (int) HIWORD(lParam) / pScr->cyChar;
+       if (iTmp2 >= pScr->height)
+               iTmp2 = pScr->height - 1;
+       iLocEnd = iTmp + iTmp2 * pScr->width;
+       if (iLocEnd == iLocStart) {
+               bSelection = FALSE;
+       }
+       else {
+               hMenu = GetMenu(hWnd);
+               EnableMenuItem(hMenu, IDM_COPY, MF_ENABLED);
+       }    
+
+} /* Edit_LbuttonUp */
+
+
 void Edit_MouseMove(HWND hWnd, LPARAM lParam){
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    int iTmp,iTmp2,iXlocCurr,iYlocCurr,iLocCurr,iX,iX2,iY,iY2;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    HDC hDC;
-    
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-    hDC = GetDC(hWnd);
-    iXlocCurr=(int)LOWORD(lParam)/fpScr->cxChar;
-       if (iXlocCurr >= fpScr->width)
-               iXlocCurr = fpScr->width - 1;
-    iYlocCurr=(int)HIWORD(lParam)/fpScr->cyChar;
-       if (iYlocCurr >= fpScr->height)
-               iYlocCurr = fpScr->height - 1;
-    iLocCurr=iXlocCurr+(iYlocCurr*fpScr->width);
-    if (iLocCurr > iLocStart) {    
-        for (iTmp=0; iTmp < iLocStart; iTmp++) {        
-            if (cInvertedArray[iTmp]) {
-                PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                    fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-                cInvertedArray[iTmp]=0;                    
-            }    
-        }
-        iX=(iLocStart%fpScr->width);
-        iY=(int)(iLocStart/fpScr->width);
-        iX2=(iLocCurr%fpScr->width);
-        iY2=(int)(iLocCurr/fpScr->width);
-        if (iY==iY2) {
-            hgScrLine=GetScreenLineFromY(fpScr,iY);
-            fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-            for (iTmp2= iX; iTmp2 < iX2; iTmp2++) {
-                if ((!cInvertedArray[iTmp2+(fpScr->width*iY)])&& fpScrLine->text[iTmp2]) {
-                    PatBlt(hDC,(iTmp2)*fpScr->cxChar,iY*fpScr->cyChar,
-                        fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                    cInvertedArray[iTmp2+(fpScr->width*iY)]=fpScrLine->text[iTmp2];
-                }    
-            }    
-            LINE_MEM_UNLOCK(hgScrLine);
-        }            
-        else {
-            hgScrLine=GetScreenLineFromY(fpScr,iY);
-            fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-            for (iTmp2= iX; iTmp2 < fpScr->width; iTmp2++) {
-                if ((!cInvertedArray[iTmp2+(fpScr->width*iY)])&& fpScrLine->text[iTmp2]) {
-                    PatBlt(hDC,(iTmp2)*fpScr->cxChar,iY*fpScr->cyChar,
-                        fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                    cInvertedArray[iTmp2+(fpScr->width*iY)]=fpScrLine->text[iTmp2];
-                }    
-            }                
-            for (iTmp=iY+1; iTmp < iY2; iTmp++) {
-                hgScrLine=GetScreenLineFromY(fpScr,iTmp);
-                fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-                for (iTmp2= 0; iTmp2 < fpScr->width; iTmp2++) {
-                    if ((!cInvertedArray[iTmp2+(fpScr->width*iTmp)])&& fpScrLine->text[iTmp2]) {
-                        PatBlt(hDC,(iTmp2)*fpScr->cxChar,iTmp*fpScr->cyChar,
-                            fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                        cInvertedArray[iTmp2+(fpScr->width*iTmp)]=fpScrLine->text[iTmp2];
-                    }    
-                }    
-                LINE_MEM_UNLOCK(hgScrLine);
-            }
-            if (!(iY2==iY)) {
-                hgScrLine=GetScreenLineFromY(fpScr,iY2);
-                fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-                for (iTmp2= 0; iTmp2 < iX2; iTmp2++) {
-                    if ((!cInvertedArray[iTmp2+(fpScr->width*iY2)])&& fpScrLine->text[iTmp2]) {
-                        PatBlt(hDC,(iTmp2)*fpScr->cxChar,iY2*fpScr->cyChar,
-                            fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                        cInvertedArray[iTmp2+(fpScr->width*iY2)]=fpScrLine->text[iTmp2];
-                    }    
-                }    
-                LINE_MEM_UNLOCK(hgScrLine);                
-            }                
-
-        }    
-        for (iTmp=iLocCurr; iTmp < fpScr->width*fpScr->height; iTmp++) {        
-            if (cInvertedArray[iTmp]) {
-                PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                    fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-                cInvertedArray[iTmp]=0;                    
-            }    
-        }
-    } else { /* going backwards */
-        for (iTmp=0; iTmp < iLocCurr; iTmp++) {        
-            if (cInvertedArray[iTmp]) {
-                PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                    fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-                cInvertedArray[iTmp]=0;                    
-            }    
-        }
-        iX=(iLocCurr%fpScr->width);
-        iY=(int)(iLocCurr/fpScr->width);
-        iX2=(iLocStart%fpScr->width);
-        iY2=(int)(iLocStart/fpScr->width);
-        if (iY==iY2) {
-            hgScrLine=GetScreenLineFromY(fpScr,iY);
-            fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-            for (iTmp2= iX; iTmp2 < iX2; iTmp2++) {
-                if ((!cInvertedArray[iTmp2+(fpScr->width*iY)])&& fpScrLine->text[iTmp2]) {
-                    PatBlt(hDC,(iTmp2)*fpScr->cxChar,iY*fpScr->cyChar,
-                        fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                    cInvertedArray[iTmp2+(fpScr->width*iY)]=fpScrLine->text[iTmp2];
-                }    
-            }    
-            LINE_MEM_UNLOCK(hgScrLine);
-        }            
-        else {
-            hgScrLine=GetScreenLineFromY(fpScr,iY);
-            fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-            for (iTmp2= iX; iTmp2 < fpScr->width; iTmp2++) {
-                if ((!cInvertedArray[iTmp2+(fpScr->width*iY)])&& fpScrLine->text[iTmp2]) {
-                    PatBlt(hDC,(iTmp2)*fpScr->cxChar,iY*fpScr->cyChar,
-                        fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                    cInvertedArray[iTmp2+(fpScr->width*iY)]=fpScrLine->text[iTmp2];
-                }    
-            }                
-            for (iTmp=iY+1; iTmp < iY2; iTmp++) {
-                hgScrLine=GetScreenLineFromY(fpScr,iTmp);
-                fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-                for (iTmp2= 0; iTmp2 < fpScr->width; iTmp2++) {
-                    if ((!cInvertedArray[iTmp2+(fpScr->width*iTmp)])&& fpScrLine->text[iTmp2]) {
-                        PatBlt(hDC,(iTmp2)*fpScr->cxChar,iTmp*fpScr->cyChar,
-                            fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                        cInvertedArray[iTmp2+(fpScr->width*iTmp)]=fpScrLine->text[iTmp2];
-                    }    
-                }    
-                LINE_MEM_UNLOCK(hgScrLine);
-            }
-            if (!(iY2==iY)) {
-                hgScrLine=GetScreenLineFromY(fpScr,iY2);
-                fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-                for (iTmp2= 0; iTmp2 < iX2; iTmp2++) {
-                    if ((!cInvertedArray[iTmp2+(fpScr->width*iY2)])&& fpScrLine->text[iTmp2]) {
-                        PatBlt(hDC,(iTmp2)*fpScr->cxChar,iY2*fpScr->cyChar,
-                            fpScr->cxChar,fpScr->cyChar,DSTINVERT);
-                        cInvertedArray[iTmp2+(fpScr->width*iY2)]=fpScrLine->text[iTmp2];
-                    }    
-                }    
-                LINE_MEM_UNLOCK(hgScrLine);                
-            }                
-
-        }    
-        for (iTmp=iLocStart; iTmp < fpScr->width*fpScr->height; iTmp++) {        
-            if (cInvertedArray[iTmp]) {
-                PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                    fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-                cInvertedArray[iTmp]=0;                    
-            }    
-        }
-        
-    }            
-    ReleaseDC(hWnd,hDC);
-    GlobalUnlock(hgScr);
-}
-
-void Edit_ClearSelection(SCREEN *fpScr) {
-    int iTmp;
-    HDC hDC;
-    HMENU hMenu;
-
-    hDC=GetDC(fpScr->hWnd);
-    for (iTmp=0; iTmp < fpScr->width*fpScr->height; iTmp++) {        
-        if (cInvertedArray[iTmp]) {
-            PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-            cInvertedArray[iTmp]=0;                    
-        }    
-    }
-    bSelection=FALSE;
-    hMenu=GetMenu(fpScr->hWnd);
-    EnableMenuItem(hMenu,IDM_COPY,MF_GRAYED);    
-    ReleaseDC(fpScr->hWnd,hDC);
-}    
-
-void Edit_Copy(HWND hWnd) {
-    int iTmp,iIdx;
-    HGLOBAL hCutBuffer;
-    LPSTR lpCutBuffer;
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-
-    hCutBuffer= GlobalAlloc(GHND,(DWORD)(fpScr->width*fpScr->height+1));
-    lpCutBuffer= GlobalLock(hCutBuffer);
-
-    if (iLocStart > iLocEnd) { /* swap variables */
-        iTmp=iLocStart;
-        iLocStart=iLocEnd;
-        iLocEnd=iLocStart;
-    }        
-    iTmp=iLocStart;
-    iIdx=0;
-    while (iTmp < iLocEnd) {
-        if (!cInvertedArray[iTmp]) {
-            lpCutBuffer[iIdx++]='\r';
-            lpCutBuffer[iIdx++]='\n';
-            iTmp= (((int)(iTmp/fpScr->width))+1)*fpScr->width;            
-            continue;
-        }
-        lpCutBuffer[iIdx++]=cInvertedArray[iTmp++];
-    }
-    lpCutBuffer[iIdx]=0;
-    GlobalUnlock(hCutBuffer);
-    OpenClipboard(hWnd);
-    EmptyClipboard();
-    SetClipboardData(CF_TEXT,hCutBuffer);
-    CloseClipboard();
-}
-
-void Edit_Paste(HWND hWnd) {
-    HGLOBAL hClipMemory;
-    static HGLOBAL hMyClipBuffer;
-    LPSTR lpClipMemory,lpMyClipBuffer;
-    HGLOBAL hgScr;
-       SCREEN *fpScr;                              
-    
-    if (hMyClipBuffer) GlobalFree(hMyClipBuffer);
-    OpenClipboard(hWnd);
-    hClipMemory = GetClipboardData(CF_TEXT);
-    hMyClipBuffer = GlobalAlloc(GHND,GlobalSize(hClipMemory));
-    lpMyClipBuffer= GlobalLock(hMyClipBuffer);
-    lpClipMemory= GlobalLock(hClipMemory);
-    
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-       fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-
-    lstrcpy(lpMyClipBuffer,lpClipMemory);
+       SCREEN *pScr;
+       int iTmp;
+       int iTmp2;
+       int iXlocCurr;
+       int iYlocCurr;
+       int iLocCurr;
+       int iX;
+       int iX2;
+       int iY;
+       int iY2;
+       SCREENLINE *pScrLine;
+       HDC hDC;
+
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+
+       hDC = GetDC(hWnd);
+       iXlocCurr = (int) LOWORD(lParam) / pScr->cxChar;
+       if (iXlocCurr >= pScr->width)
+               iXlocCurr = pScr->width - 1;
+       iYlocCurr = (int) HIWORD(lParam) / pScr->cyChar;
+       if (iYlocCurr >= pScr->height)
+               iYlocCurr = pScr->height - 1;
+       iLocCurr = iXlocCurr + (iYlocCurr * pScr->width);
+       if (iLocCurr > iLocStart) {
+               for (iTmp=0; iTmp < iLocStart; iTmp++) {        
+                       if (cInvertedArray[iTmp]) {
+                               PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar,
+                                       (int) (iTmp / pScr->width) * pScr->cyChar,
+                                       pScr->cxChar, pScr->cyChar, DSTINVERT);
+                               cInvertedArray[iTmp] = 0;
+                       }
+               }
+               iX = iLocStart % pScr->width;
+               iY = (int) (iLocStart / pScr->width);
+               iX2 = iLocCurr % pScr->width;
+               iY2 = (int) (iLocCurr / pScr->width);
+               if (iY == iY2) {
+                       pScrLine = GetScreenLineFromY(pScr, iY);
+                       for (iTmp2 = iX; iTmp2 < iX2; iTmp2++) {
+                               if ((!cInvertedArray[iTmp2 + (pScr->width * iY)]) && pScrLine->text[iTmp2]) {
+                                       PatBlt(hDC, iTmp2 * pScr->cxChar, iY * pScr->cyChar,
+                                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                       cInvertedArray[iTmp2 + (pScr->width * iY)] = pScrLine->text[iTmp2];
+                               }
+                       }
+               }            
+               else {
+                       pScrLine = GetScreenLineFromY(pScr, iY);
+
+                       for (iTmp2 = iX; iTmp2 < pScr->width; iTmp2++) {
+                               if ((!cInvertedArray[iTmp2 + (pScr->width * iY)]) && pScrLine->text[iTmp2]) {
+                                       PatBlt(hDC, iTmp2 * pScr->cxChar, iY * pScr->cyChar,
+                                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                       cInvertedArray[iTmp2 + (pScr->width * iY)] = pScrLine->text[iTmp2];
+                               }
+                       }
+
+                       for (iTmp = iY + 1; iTmp < iY2; iTmp++) {
+                               pScrLine = GetScreenLineFromY(pScr, iTmp);
+                               for (iTmp2 = 0; iTmp2 < pScr->width; iTmp2++) {
+                                       if ((!cInvertedArray[iTmp2 + (pScr->width * iTmp)]) && pScrLine->text[iTmp2]) {
+                                               PatBlt(hDC, iTmp2 * pScr->cxChar, iTmp * pScr->cyChar,
+                                                       pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                               cInvertedArray[iTmp2 + (pScr->width * iTmp)] = pScrLine->text[iTmp2];
+                                       }
+                               }
+                       }
+
+                       if (iY2 != iY) {
+                               pScrLine = GetScreenLineFromY(pScr, iY2);
+                               for (iTmp2 = 0; iTmp2 < iX2; iTmp2++) {
+                                       if ((!cInvertedArray[iTmp2 + (pScr->width * iY2)]) && pScrLine->text[iTmp2]) {
+                                               PatBlt(hDC, iTmp2 * pScr->cxChar, iY2 * pScr->cyChar,
+                                                       pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                               cInvertedArray[iTmp2 + (pScr->width * iY2)] = pScrLine->text[iTmp2];
+                                       }    
+                               }    
+                       }                
+               }
+
+               for (iTmp = iLocCurr; iTmp < pScr->width * pScr->height; iTmp++) {        
+                       if (cInvertedArray[iTmp]) {
+                               PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar, (int) (iTmp / pScr->width) * pScr->cyChar,
+                                       pScr->cxChar, pScr->cyChar, DSTINVERT);                
+                               cInvertedArray[iTmp] = 0;
+                       }
+               }
+       }
+       else { /* going backwards */
+               for (iTmp = 0; iTmp < iLocCurr; iTmp++) {        
+                       if (cInvertedArray[iTmp]) {
+                               PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar, (int) (iTmp / pScr->width) * pScr->cyChar,
+                                       pScr->cxChar, pScr->cyChar, DSTINVERT);                
+                               cInvertedArray[iTmp] = 0;
+                       }
+               }
+               iX = iLocCurr % pScr->width;
+               iY = (int) (iLocCurr / pScr->width);
+               iX2 = (iLocStart % pScr->width);
+               iY2 = (int) (iLocStart / pScr->width);
+               if (iY == iY2) {
+                       pScrLine = GetScreenLineFromY(pScr, iY);
+                       for (iTmp2= iX; iTmp2 < iX2; iTmp2++) {
+                               if ((!cInvertedArray[iTmp2 + (pScr->width * iY)]) && pScrLine->text[iTmp2]) {
+                                       PatBlt(hDC, iTmp2 * pScr->cxChar, iY * pScr->cyChar,
+                                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                       cInvertedArray[iTmp2 + (pScr->width * iY)] = pScrLine->text[iTmp2];
+                               }
+                       }
+               }            
+               else {
+                       pScrLine = GetScreenLineFromY(pScr, iY);
+                       for (iTmp2 = iX; iTmp2 < pScr->width; iTmp2++) {
+                               if ((!cInvertedArray[iTmp2 + (pScr->width * iY)]) && pScrLine->text[iTmp2]) {
+                                       PatBlt(hDC, iTmp2 * pScr->cxChar, iY * pScr->cyChar,
+                                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                       cInvertedArray[iTmp2 + (pScr->width * iY)] = pScrLine->text[iTmp2];
+                               }    
+                       }                
+                       for (iTmp = iY + 1; iTmp < iY2; iTmp++) {
+                               pScrLine = GetScreenLineFromY(pScr, iTmp);
+                               for (iTmp2 = 0; iTmp2 < pScr->width; iTmp2++) {
+                                       if ((!cInvertedArray[iTmp2 + (pScr->width * iTmp)]) && pScrLine->text[iTmp2]) {
+                                               PatBlt(hDC, iTmp2 * pScr->cxChar, iTmp * pScr->cyChar,
+                                                       pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                               cInvertedArray[iTmp2 + (pScr->width * iTmp)] = pScrLine->text[iTmp2];
+                                       }
+                               }
+                       }
+                       if (iY2 != iY) {
+                               pScrLine = GetScreenLineFromY(pScr, iY2);
+                               for (iTmp2 = 0; iTmp2 < iX2; iTmp2++) {
+                                       if ((!cInvertedArray[iTmp2 + (pScr->width * iY2)]) && pScrLine->text[iTmp2]) {
+                                               PatBlt(hDC, iTmp2 * pScr->cxChar, iY2 * pScr->cyChar,
+                                                       pScr->cxChar, pScr->cyChar, DSTINVERT);
+                                               cInvertedArray[iTmp2 + (pScr->width * iY2)] = pScrLine->text[iTmp2];
+                                       }    
+                               }    
+                       }                
+               }    
+               for (iTmp = iLocStart; iTmp < pScr->width * pScr->height; iTmp++) {        
+                       if (cInvertedArray[iTmp]) {
+                               PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar, (int) (iTmp / pScr->width) * pScr->cyChar,
+                                       pScr->cxChar, pScr->cyChar, DSTINVERT);
+                               cInvertedArray[iTmp] = 0;
+                       }    
+               }
+       }            
+       ReleaseDC(hWnd, hDC);
+} /* Edit_MouseMove */
+
+
+void Edit_ClearSelection(
+       SCREEN *pScr)
+{
+       int iTmp;
+       HDC hDC;
+       HMENU hMenu;
+
+       hDC = GetDC(pScr->hWnd);
+       for (iTmp = 0; iTmp < pScr->width * pScr->height; iTmp++) {
+               if (cInvertedArray[iTmp]) {
+                       PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar,
+                               (int) (iTmp / pScr->width) * pScr->cyChar,
+                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                       cInvertedArray[iTmp] = 0;
+               }
+       }
+       bSelection = FALSE;
+       hMenu=GetMenu(pScr->hWnd);
+       EnableMenuItem(hMenu, IDM_COPY, MF_GRAYED);    
+       ReleaseDC(pScr->hWnd, hDC);
+} /* Edit_ClearSelection */
+
+
+void Edit_Copy(
+       HWND hWnd)
+{
+       int iTmp,iIdx;
+       HGLOBAL hCutBuffer;
+       LPSTR lpCutBuffer;
+       SCREEN *pScr;
+       
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+
+       hCutBuffer= GlobalAlloc(GHND, (DWORD) (pScr->width * pScr->height + 1));
+       lpCutBuffer= GlobalLock(hCutBuffer);
+
+       if (iLocStart > iLocEnd) { /* swap variables */
+               iTmp = iLocStart;
+               iLocStart = iLocEnd;
+               iLocEnd = iLocStart;
+       }
+       iTmp = iLocStart;
+       iIdx = 0;
+       while (iTmp < iLocEnd) {
+               if (!cInvertedArray[iTmp]) {
+                       lpCutBuffer[iIdx++] = '\r';
+                       lpCutBuffer[iIdx++] = '\n';
+                       iTmp = (((int) (iTmp / pScr->width)) + 1) * pScr->width;
+                       continue;
+               }
+               lpCutBuffer[iIdx++] = cInvertedArray[iTmp++];
+       }
+       lpCutBuffer[iIdx] = 0;
+       GlobalUnlock(hCutBuffer);
+       OpenClipboard(hWnd);
+       EmptyClipboard();
+       SetClipboardData(CF_TEXT, hCutBuffer);
+       CloseClipboard();
+
+} /* Edit_Copy */
+
+
+void Edit_Paste(
+       HWND hWnd)
+{
+       HGLOBAL hClipMemory;
+       static HGLOBAL hMyClipBuffer;
+       LPSTR lpClipMemory;
+       LPSTR lpMyClipBuffer;
+       SCREEN *pScr;                              
+       
+       if (hMyClipBuffer)
+               GlobalFree(hMyClipBuffer);
+       OpenClipboard(hWnd);
+       hClipMemory = GetClipboardData(CF_TEXT);
+       hMyClipBuffer = GlobalAlloc(GHND, GlobalSize(hClipMemory));
+       lpMyClipBuffer = GlobalLock(hMyClipBuffer);
+       lpClipMemory= GlobalLock(hClipMemory);
+       
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+
+       lstrcpy(lpMyClipBuffer, lpClipMemory);
 //    OutputDebugString(lpMyClipBuffer);
-    PostMessage(fpScr->hwndTel,WM_MYSCREENBLOCK,(WPARAM)hMyClipBuffer,
-                    (HSCREEN)hgScr);                
-    CloseClipboard();                    
-    GlobalUnlock(hClipMemory);
-    GlobalUnlock(hMyClipBuffer);    
-}
-
-void Edit_LbuttonDblclk(HWND hWnd,LPARAM lParam) {
-    HDC hDC;
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    int iTmp,iTmp2,iXlocStart,iYloc;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-        
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-    
-    hDC=GetDC(hWnd);
-    for (iTmp=0; iTmp < fpScr->width*fpScr->height; iTmp++) {        
-        if (cInvertedArray[iTmp]) {
-            PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-            cInvertedArray[iTmp]=0;                    
-        }    
-    }
-    bSelection=FALSE;
-    iXlocStart=(int)LOWORD(lParam)/fpScr->cxChar;
-       if (iXlocStart >= fpScr->width)
-               iXlocStart = fpScr->width - 1;
-    iYloc=(int)HIWORD(lParam)/fpScr->cyChar;
-       if (iYloc >= fpScr->height)
-               iYloc = fpScr->height - 1;
-    iLocStart=iXlocStart+(iYloc*fpScr->width);
-    
-    hgScrLine=GetScreenLineFromY(fpScr,iYloc);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    
-    iTmp=iXlocStart;
-    while (isalnum((int)fpScrLine->text[iTmp])) {
-        PatBlt(hDC,iTmp*fpScr->cxChar,iYloc*fpScr->cyChar,
-             fpScr->cxChar,fpScr->cyChar,DSTINVERT);                    
-        cInvertedArray[iTmp+(iYloc*fpScr->width)]=fpScrLine->text[iTmp];
-        iTmp++;
-    }
-    iTmp2=iXlocStart-1;
-    while (isalnum((int)fpScrLine->text[iTmp2])) {
-        PatBlt(hDC,iTmp2*fpScr->cxChar,iYloc*fpScr->cyChar,
-             fpScr->cxChar,fpScr->cyChar,DSTINVERT);                        
-        cInvertedArray[iTmp2+(iYloc*fpScr->width)]=fpScrLine->text[iTmp2];
-        iTmp2--;
-    }    
-    iLocStart=(iTmp2+1)+(iYloc*fpScr->width);
-    iLocEnd=(iTmp)+(iYloc*fpScr->width);        
-
-    bSelection=TRUE;
-    ReleaseDC(hWnd,hDC);
-    LINE_MEM_UNLOCK(hgScrLine);        
-    GlobalUnlock(hgScr);
-}
-
-void Edit_TripleClick(HWND hWnd,LPARAM lParam) {
-    HDC hDC;
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    int iTmp,iYloc;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-        
+       PostMessage(pScr->hwndTel, WM_MYSCREENBLOCK, (WPARAM) hMyClipBuffer, (LPARAM) pScr);
+       CloseClipboard();                    
+       GlobalUnlock(hClipMemory);
+       GlobalUnlock(hMyClipBuffer);    
+
+} /* Edit_Paste */
+
+
+void Edit_LbuttonDblclk(
+       HWND hWnd,
+       LPARAM lParam)
+{
+       HDC hDC;
+       SCREEN *pScr;
+       int iTmp;
+       int iTmp2;
+       int iXlocStart;
+       int iYloc;
+       SCREENLINE *pScrLine;
+               
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+       
+       hDC = GetDC(hWnd);
+       for (iTmp = 0; iTmp < pScr->width * pScr->height; iTmp++) {        
+               if (cInvertedArray[iTmp]) {
+                       PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar,
+                               (int) (iTmp / pScr->width) * pScr->cyChar,
+                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                       cInvertedArray[iTmp] = 0;
+               }
+       }
+       bSelection = FALSE;
+       iXlocStart = (int) LOWORD(lParam) / pScr->cxChar;
+       if (iXlocStart >= pScr->width)
+               iXlocStart = pScr->width - 1;
+       iYloc = (int) HIWORD(lParam) / pScr->cyChar;
+       if (iYloc >= pScr->height)
+               iYloc = pScr->height - 1;
+       iLocStart = iXlocStart + (iYloc * pScr->width);
+
+       pScrLine = GetScreenLineFromY(pScr, iYloc);
+
+       iTmp = iXlocStart;
+       while (isalnum((int) pScrLine->text[iTmp])) {
+               PatBlt(hDC, iTmp * pScr->cxChar, iYloc * pScr->cyChar,
+                        pScr->cxChar, pScr->cyChar, DSTINVERT);
+               cInvertedArray[iTmp + (iYloc * pScr->width)] = pScrLine->text[iTmp];
+               iTmp++;
+       }
+       iTmp2 = iXlocStart - 1;
+       while (isalnum((int) pScrLine->text[iTmp2])) {
+               PatBlt(hDC, iTmp2 * pScr->cxChar, iYloc * pScr->cyChar,
+                        pScr->cxChar, pScr->cyChar, DSTINVERT);
+               cInvertedArray[iTmp2 + (iYloc * pScr->width)] = pScrLine->text[iTmp2];
+               iTmp2--;
+       }
+       iLocStart = (iTmp2 + 1) + (iYloc * pScr->width);
+       iLocEnd = iTmp + (iYloc * pScr->width);
+
+       bSelection = TRUE;
+       ReleaseDC(hWnd, hDC);
+
+} /* Edit_LbuttonDblclk */
+
+
+void Edit_TripleClick(
+       HWND hWnd,
+       LPARAM lParam)
+{
+       HDC hDC;
+       SCREEN *pScr;
+       int iTmp;
+       int iYloc;
+       SCREENLINE *pScrLine;
+               
 //    OutputDebugString("Triple Click \r\n");
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-    
-    hDC=GetDC(hWnd);
-    for (iTmp=0; iTmp < fpScr->width*fpScr->height; iTmp++) {        
-        if (cInvertedArray[iTmp]) {
-            PatBlt(hDC,(iTmp%fpScr->width)*fpScr->cxChar,(int)(iTmp/fpScr->width)*fpScr->cyChar,
-                fpScr->cxChar,fpScr->cyChar,DSTINVERT);                
-            cInvertedArray[iTmp]=0;                    
-        }    
-    }
-    bSelection=FALSE;
-    iYloc=(int)HIWORD(lParam)/fpScr->cyChar;
-       if (iYloc >= fpScr->height)
-               iYloc = fpScr->height - 1;
-    iLocStart=(iYloc*fpScr->width);
-    
-    hgScrLine=GetScreenLineFromY(fpScr,iYloc);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    
-    for (iTmp=0; iTmp<fpScr->width; iTmp++) {
-        if (fpScrLine->text[iTmp]) {
-            PatBlt(hDC,iTmp*fpScr->cxChar,iYloc*fpScr->cyChar,
-                 fpScr->cxChar,fpScr->cyChar,DSTINVERT);                    
-            cInvertedArray[iTmp+(iYloc*fpScr->width)]=fpScrLine->text[iTmp];
-        } else break;    
-    }
-    iLocEnd=(iTmp+(iYloc*fpScr->width));
-
-    bSelection=TRUE;
-    ReleaseDC(hWnd,hDC);
-    LINE_MEM_UNLOCK(hgScrLine);        
-    GlobalUnlock(hgScr);
-}
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+       
+       hDC = GetDC(hWnd);
+       for (iTmp = 0; iTmp < pScr->width * pScr->height; iTmp++) {        
+               if (cInvertedArray[iTmp]) {
+                       PatBlt(hDC, (iTmp % pScr->width) * pScr->cxChar,
+                               (int) (iTmp / pScr->width) * pScr->cyChar,
+                               pScr->cxChar, pScr->cyChar, DSTINVERT);
+                       cInvertedArray[iTmp] = 0;
+               }    
+       }
+       bSelection = FALSE;
+       iYloc = (int) HIWORD(lParam) / pScr->cyChar;
+       if (iYloc >= pScr->height)
+               iYloc = pScr->height - 1;
+       iLocStart = iYloc * pScr->width;
+       
+       pScrLine = GetScreenLineFromY(pScr, iYloc);
+       
+       for (iTmp = 0; iTmp < pScr->width; iTmp++) {
+               if (pScrLine->text[iTmp]) {
+                       PatBlt(hDC, iTmp * pScr->cxChar, iYloc * pScr->cyChar,
+                                pScr->cxChar, pScr->cyChar, DSTINVERT);
+                       cInvertedArray[iTmp + (iYloc * pScr->width)] = pScrLine->text[iTmp];
+               }
+               else
+                       break;
+       }
+       iLocEnd = iTmp + (iYloc * pScr->width);
+
+       bSelection = TRUE;
+       ReleaseDC(hWnd, hDC);
+
+} /* Edit_TripleClick */
index 027089ebe2f85b9c957a40cf9c446b73b5598494..0282866c33d88b4d2f94a8b387e7de1856bb90b9 100644 (file)
+/* emul.c */
+
 #include "windows.h"
 #include "screen.h"
 
-/**********************************************************************
-*  Function :   ScreenEmChar
-*  Purpose  :   Send a character to the virtual screen with no translantion
-*  Parameters   :
-            fpScr - pointer top screen
-*           c - character to send to the virtual screen
-*  Returns  :   none
-*  Calls    :
-*  Called by    :   ScreenEm()
-**********************************************************************/
-static int ScreenEmChar(SCREEN *fpScr,unsigned char c)
+static int ScreenEmChar(
+       SCREEN *pScr,
+       unsigned char c)
 {
-    int sx;
-    int insert,
-        ocount,
-        attrib,
-        extra,
-        offend;
-    char *acurrent,         /* pointer to the attributes for characters drawn */
-        *current,           /* pointer to the place to put characters */
-        *start;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine==NULL) return (-1);
-
-    current=start=&fpScrLine->text[fpScr->x];
-    acurrent=&fpScrLine->attrib[fpScr->x];
-
-    attrib=fpScr->attrib;
-    insert=fpScr->IRM;          /* boolean */
-    ocount=fpScr->x;
-    offend=0;
-    extra=0;
-    sx=fpScr->x;
-    if(fpScr->x>fpScr->width) {
-        if(fpScr->DECAWM) {  /* check for line wrapping on */
-            fpScr->x=0;
-            ScreenIndex(fpScr);
-        } /* end if */
-        else                /* no line wrapping */
-            fpScr->x=fpScr->width;
-        current=start=&fpScrLine->text[fpScr->x];
-        acurrent=&fpScrLine->attrib[fpScr->x];
-        ocount=fpScr->x;
-        sx=fpScr->x;
-    } /* end if */
-    if(insert)
-        ScreenInsChar(fpScr,1);
-    *current=c;
-    *acurrent=(char)attrib;
-    if(fpScr->x<fpScr->width) {
-        acurrent++;
-        current++;
-        fpScr->x++;
-    } /* end if */
-    else {
-        if(fpScr->DECAWM) {
-            fpScr->x++;
-            offend=1;
-        } /* end if */
-        else {
-            fpScr->x=fpScr->width;
-            extra=1;
-        } /* end else */
-    } /* end else */
-    if(insert)
-        ScreenInsString(fpScr,fpScr->x-ocount+offend+extra,start);        /* actually just decides which RS to use */
-    else
-        ScreenDraw(fpScr,sx,fpScr->y,fpScr->attrib,fpScr->x-ocount+offend+extra,start);
-    LINE_MEM_UNLOCK(hgScrLine);        
-}   /* end ScreenEmChar() */
-
-void ScreenEm(LPSTR c,int len,HSCREEN hsScr)
+       /*
+       Function: Send a character to the virtual screen with no translation.
+       */
+       int sx;
+       int insert;
+       int ocount;
+       int attrib;
+       int extra;
+       int offend;
+       char *acurrent;                                         /* pointer to the attributes for characters drawn */
+       char *current;                                          /* pointer to the place to put characters */
+       char *start;
+       SCREENLINE *pScrLine;
+
+       pScrLine = GetScreenLineFromY(pScr, pScr->y);
+       if (pScrLine == NULL)
+               return(-1);
+
+       current = start = &pScrLine->text[pScr->x];
+       acurrent = &pScrLine->attrib[pScr->x];
+
+       attrib = pScr->attrib;
+       insert = pScr->IRM;
+       ocount = pScr->x;
+       offend = 0;
+       extra = 0;
+       sx = pScr->x;
+       if (pScr->x > pScr->width) {
+               if (pScr->DECAWM) {                             /* check for line wrapping on */
+                       pScr->x = 0;
+                       ScreenIndex(pScr);
+               }
+               else                                                    /* no line wrapping */
+                       pScr->x = pScr->width;
+               current = start = &pScrLine->text[pScr->x];
+               acurrent = &pScrLine->attrib[pScr->x];
+               ocount = pScr->x;
+               sx = pScr->x;
+       }
+       if (insert)
+               ScreenInsChar(pScr, 1);
+       *current = c;
+       *acurrent = (char) attrib;
+       if (pScr->x < pScr->width) {
+               acurrent++;
+               current++;
+               pScr->x++;
+       }
+       else {
+               if(pScr->DECAWM) {
+                       pScr->x++;
+                       offend = 1;
+               }
+               else {
+                       pScr->x = pScr->width;
+                       extra = 1;
+               }
+       }
+       if (insert)
+               ScreenInsString(pScr, pScr->x - ocount + offend + extra, start); /* actually just decides which RS to use */
+       else
+               ScreenDraw(pScr, sx, pScr->y, pScr->attrib, pScr->x - ocount + offend + extra, start);
+
+} /* ScreenEmChar */
+
+void ScreenEm(
+       LPSTR c,
+       int len,
+       SCREEN *pScr)
 {
-    HSCREENLINE hgScrLine;
-    SCREEN *fpScr;
-    SCREENLINE *fpScrLine;    
-    int escflg;             /* vt100 escape level */
-    RECT rc;
+       SCREENLINE *pScrLine;    
+       int escflg;             /* vt100 escape level */
+       RECT rc;
        unsigned int ic;
        char stat[20];
        int i;
-    
-    fpScr=(SCREEN *) GlobalLock(hsScr);
-    if (fpScr==NULL) {
-        OutputDebugString("Screen is hosed.\r\n");
-        return;
-    }
-
-    if (fpScr->screen_bottom != fpScr->buffer_bottom) {
-               ScreenUnscroll(fpScr);
-        InvalidateRect(fpScr->hWnd,NULL,TRUE);
-        SetScrollPos(fpScr->hWnd,SB_VERT,fpScr->numlines,TRUE);
+       
+       if (pScr->screen_bottom != pScr->buffer_bottom) {
+               ScreenUnscroll(pScr);
+               InvalidateRect(pScr->hWnd, NULL, TRUE);
+               SetScrollPos(pScr->hWnd, SB_VERT, pScr->numlines, TRUE);
        }
 
-    ScreenCursorOff(fpScr);
-    escflg=fpScr->escflg;
-
-#ifdef UM
-/* @UM */
-    if(fpScr->localprint && (len>0)) {    /* see if printer needs anything */
-        pcount=send_localprint(c,len);
-        len-=pcount;
-        c+=pcount;
-      } /* end if */
-/* @UM */
-#endif
-
-    while(len>0) {
-        while((*c<32) && (escflg==0) && (len>0)) {      /* look at first character in the vt100 string, if it is a non-printable ascii code */
-            switch(*c) {
-            
-                case 0x1b:      /* ESC found (begin vt100 control sequence) */
-                    escflg++;
-                    break;
-
-                               case -1:                /* IAC from telnet session */
-                                       escflg=6;
+       ScreenCursorOff(pScr);
+       escflg = pScr->escflg;
+
+       #ifdef UM
+               if (pScr->localprint && len > 0) {    /* see if printer needs anything */
+                       pcount = send_localprint(c, len);
+                       len -= pcount;
+                       c += pcount;
+               }
+       #endif
+
+       while (len > 0) {
+               while((*c < 32) && (escflg == 0) && (len > 0)) {  /* look at first character in the vt100 string, if it is a non-printable ascii code */
+                       switch(*c) {
+                       
+                       case 0x1b:              /* ESC found (begin vt100 control sequence) */
+                               escflg++;
+                               break;
+
+                       case -1:                /* IAC from telnet session */
+                               escflg = 6;
+                               break;
+
+                       #ifdef CISB
+                               case 0x05:      /* CTRL-E found (answerback) */
+                                       bp_ENQ();
+                                       break;
+                       #endif
+
+                       case 0x07:              /* CTRL-G found (bell) */
+                               ScreenBell(pScr);
+                               break;
+
+                       case 0x08:              /* CTRL-H found (backspace) */
+                               ScreenBackspace(pScr);
+                               break;
+
+                       case 0x09:              /* CTRL-I found (tab) */
+                               ScreenTab(pScr);       /* Later change for versatile tabbing */
+                               break;
+
+                       case 0x0a:              /* CTRL-J found (line feed) */
+                       case 0x0b:              /* CTRL-K found (treat as line feed) */
+                       case 0x0c:              /* CTRL-L found (treat as line feed) */
+                               ScreenIndex(pScr);
+                               break;
+
+                       case 0x0d:              /* CTRL-M found (carriage feed) */
+                               ScreenCarriageFeed(pScr);
+                               break;
+
+                       #if 0
+                               case 0x0e:      /* CTRL-N found (invoke Graphics (G1) character set) */
+                                       if (pScr->G1)
+                                               pScr->attrib = VSgraph(pScr->attrib);
+                                       else
+                                               pScr->attrib = VSnotgraph(pScr->attrib);
+                                       pScr->charset = 1;
+                                       break;
+
+                               case 0x0f:      /* CTRL-O found (invoke 'normal' (G0) character set) */
+                                       if(pScr->G0)
+                                               pScr->attrib = VSgraph(pScr->attrib);
+                                       else
+                                               pScr->attrib = VSnotgraph(pScr->attrib);
+                                       pScr->charset = 0;
+                                       break;
+                       #endif
+
+                       #ifdef CISB
+                               case 0x10:      /* CTRL-P found (undocumented in vt100) */
+                                       bp_DLE(c, len);
+                                       len = 0;
+                                       break;
+                       #endif
+
+                       #if 0
+                               case 0x11:      /* CTRL-Q found (XON) (unused presently) */
+                               case 0x13:      /* CTRL-S found (XOFF) (unused presently) */
+                               case 0x18:      /* CTRL-X found (CAN) (unused presently) */
+                               case 0x1a:      /* CTRL-Z found (SUB) (unused presently) */
+                                       break;
+                       #endif
+
+                       } /* end switch */
+
+                       c++;        /* advance to the next character in the string */
+                       len--;      /* decrement the counter */
+
+                 } /* end while */
+
+               if (escflg == 0) {              /* check for normal character to print */
+                       while ((len > 0) && (*c >= 32)) {     /* print out printable ascii chars, if we haven't found an ESCAPE char */
+                               int sx;
+                               int insert;
+                               int ocount;
+                               int attrib;
+                               int extra;
+                               int offend;
+                               char *acurrent;         /* pointer to the attributes for characters drawn */
+                               char *current;          /* pointer to the place to put characters */
+                               char *start;
+
+                               pScrLine = GetScreenLineFromY(pScr, pScr->y);
+                               if (pScrLine == NULL)
+                                       return;
+
+                               current = start = &pScrLine->text[pScr->x];
+                               acurrent = &pScrLine->attrib[pScr->x];
+                               attrib = pScr->attrib;
+                               insert = pScr->IRM;
+                               ocount = pScr->x;
+                               offend = 0;
+                               extra = 0;
+                               sx = pScr->x;
+                               if (pScr->x > pScr->width) {
+                                       if (pScr->DECAWM) {  /* check for line wrapping on */
+                                               pScr->x = 0;
+                                               ScreenIndex(pScr);
+                                       }
+                                       else                /* no line wrapping */
+                                               pScr->x = pScr->width;
+                                       current = start = &pScrLine->text[pScr->x];
+                                       acurrent = &pScrLine->attrib[pScr->x];
+                                       ocount = pScr->x;
+                                       sx = pScr->x;
+                               }
+                               while ((len > 0) && (*c >= 32) && (offend == 0)) {
+                                       if (insert)
+                                               ScreenInsChar(pScr, 1);
+                                       *current = *c;
+                                       *acurrent = (char) attrib;
+                                       c++;
+                                       len--;
+                                       if (pScr->x < pScr->width) {
+                                               acurrent++;
+                                               current++;
+                                               pScr->x++;
+                                       }
+                                       else {
+                                               if (pScr->DECAWM) {
+                                                       pScr->x++;
+                                                       offend = 1;
+                                               }
+                                               else {
+                                                       pScr->x = pScr->width;
+                                                       extra = 1;
+                                               }
+                                       }
+                               }
+                               if (insert)
+                                       ScreenInsString(pScr, pScr->x - ocount + offend + extra, start);  /* actually just decides which RS to use */
+                               else 
+                                       ScreenDraw(pScr, sx, pScr->y, pScr->attrib, pScr->x - ocount + offend + extra, start);
+                       }
+               }
+                 
+               while ((len > 0) && (escflg == 1)) {     /* ESC character was found */
+                       switch(*c) {
+                       
+                       case 0x08:      /* CTRL-H found (backspace) */
+                               ScreenBackspace(pScr);
+                               break;
+
+                       case '[':               /* mostly cursor movement options, and DEC private stuff following */
+                               ScreenApClear(pScr);
+                               escflg = 2;
+                               break;
+
+                       case '#':               /* various screen adjustments */
+                               escflg = 3;
+                               break;
+
+                       case '(':               /* G0 character set options */
+                               escflg = 4;
+                               break;
+
+                       case ')':               /* G1 character set options */
+                               escflg = 5;
+                               break;
+
+                       case '>':               /* keypad numeric mode (DECKPAM) */
+                               pScr->DECPAM = 0;
+                               escflg = 0;
+                               break;
+
+                       case '=':               /* keypad application mode (DECKPAM) */
+                               pScr->DECPAM = 1;
+                               escflg = 0;
+                               break;
+
+                       case '7':               /* save cursor (DECSC) */
+                               ScreenSaveCursor(pScr);
+                               escflg = 0;
+                               break;
+
+                       case '8':               /* restore cursor (DECRC) */
+                               ScreenRestoreCursor(pScr);
+                               escflg = 0;
+                               break;
+
+                       #if 0
+                               case 'c':                       /* reset to initial state (RIS) */
+                                       ScreenReset(pScr);
+                                       escflg = 0;
+                                       break;
+                       #endif
+
+                       case 'D':                               /* index (move down one line) (IND) */
+                               ScreenIndex(pScr);
+                               escflg = 0;
+                               break;
+
+                       case 'E':                               /*  next line (move down one line and to first column) (NEL) */
+                               pScr->x = 0;
+                               ScreenIndex(pScr);
+                               escflg = 0;
+                               break;
+
+                       case 'H':                               /* horizontal tab set (HTS) */
+                               pScr->tabs[pScr->x] = 'x';
+                               escflg = 0;
+                               break;
+
+                       #ifdef CISB
+                               case 'I':                       /* undoumented in vt100 */
+                                       bp_ESC_I();
+                                       break;
+                       #endif
+
+                       case 'M':               /* reverse index (move up one line) (RI) */
+                               ScreenRevIndex(pScr);
+                               escflg = 0;
+                               break;
+
+                       case 'Z':               /* identify terminal (DECID) */
+                               escflg = 0;
+                               break;
+
+                       default:
+                               ScreenEmChar(pScr, 0x1b); /* put the ESC character into the Screen */
+                               ScreenEmChar(pScr, *c);   /* put the next character into the Screen */
+                               escflg = 0;
+                               break;
+
+                       } /* end switch */
+
+                       c++;
+                       len--;
+               }
+
+               while((escflg == 2) && (len > 0)) {     /* '[' handling */            
+                       switch(*c) {
+
+                       case 0x08:      /* backspace */
+                               ScreenBackspace(pScr);
+                               break;
+
+                       case '0':
+                       case '1':
+                       case '2':
+                       case '3':
+                       case '4':
+                       case '5':
+                       case '6':
+                       case '7':
+                       case '8':
+                       case '9':               /* numeric parameters */
+                               if (pScr->parms[pScr->parmptr] < 0)
+                                       pScr->parms[pScr->parmptr] = 0;
+                               pScr->parms[pScr->parmptr] *= 10;
+                               pScr->parms[pScr->parmptr] += *c - '0';
+                               break;
+
+                       case '?':               /* vt100 mode change */
+                               pScr->parms[pScr->parmptr++] = -2;
+                               break;
+
+                       case ';':               /* parameter divider */
+                               pScr->parmptr++;
+                               break;
+
+                       case 'A':               /* cursor up (CUU) */
+                               rc.left = pScr->x * pScr->cxChar;
+                               rc.right = (pScr->x + 1) * pScr->cxChar;
+                               rc.top = pScr->cyChar * pScr->y;
+                               rc.bottom = pScr->cyChar * (pScr->y + 1);
+                               InvalidateRect(pScr->hWnd, &rc, TRUE);
+                               if (pScr->parms[0] < 1)
+                                       pScr->y--;
+                               else
+                                       pScr->y -= pScr->parms[0];
+                               if(pScr->y < pScr->top)
+                                       pScr->y = pScr->top;
+                               ScreenRange(pScr);
+                               escflg = 0;
+                               SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+                               break;
+
+                       case 'B':               /* cursor down (CUD) */
+                               rc.left = pScr->x * pScr->cxChar;
+                               rc.right = (pScr->x + 1) * pScr->cxChar;
+                               rc.top = pScr->cyChar * pScr->y;
+                               rc.bottom = pScr->cyChar * (pScr->y + 1);
+                               InvalidateRect(pScr->hWnd, &rc, TRUE);
+                               if (pScr->parms[0] < 1)
+                                       pScr->y++;
+                               else
+                                       pScr->y += pScr->parms[0];
+                               if (pScr->y > pScr->bottom)
+                                       pScr->y = pScr->bottom;
+                               ScreenRange(pScr);
+                               escflg = 0;
+                               SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+                               break;
+
+                       case 'C':                       /* cursor forward (right) (CUF) */
+                               rc.left = pScr->x * pScr->cxChar;
+                               rc.right = (pScr->x + 1) * pScr->cxChar;
+                               rc.top = pScr->cyChar * pScr->y;
+                               rc.bottom = pScr->cyChar * (pScr->y +1);
+                               InvalidateRect(pScr->hWnd, &rc, TRUE);
+                               if(pScr->parms[0] < 1)
+                                       pScr->x++;
+                               else
+                                       pScr->x += pScr->parms[0];
+                               ScreenRange(pScr);
+                               if (pScr->x > pScr->width)
+                                       pScr->x = pScr->width;
+                               escflg = 0;
+                               SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+                               break;
+
+                       case 'D':                       /* cursor backward (left) (CUB) */
+                               rc.left = pScr->x * pScr->cxChar;
+                               rc.right = (pScr->x + 1) * pScr->cxChar;
+                               rc.top = pScr->cyChar * pScr->y;
+                               rc.bottom = pScr->cyChar * (pScr->y + 1);
+                               InvalidateRect(pScr->hWnd, &rc, TRUE);
+                               if(pScr->parms[0] < 1)
+                                       pScr->x--;
+                               else
+                                       pScr->x -= pScr->parms[0];
+                               ScreenRange(pScr);
+                               escflg = 0;
+                               SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+                               break;
+
+                       case 'f':               /* horizontal & vertical position (HVP) */
+                       case 'H':               /* cursor position (CUP) */
+                               rc.left = pScr->x * pScr->cxChar;
+                               rc.right = (pScr->x + 1) * pScr->cxChar;
+                               rc.top = pScr->cyChar * pScr->y;
+                               rc.bottom = pScr->cyChar * (pScr->y + 1);
+                               InvalidateRect(pScr->hWnd, &rc, TRUE);
+                               pScr->x = pScr->parms[1] - 1;
+                               pScr->y = pScr->parms[0] - 1;
+                               ScreenRange(pScr);      /* make certain the cursor position is valid */
+                               escflg = 0;
+                               SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+                               break;
+
+                       case 'J':               /* erase in display (ED) */
+                               switch(pScr->parms[0]) {
+
+                               case -1:
+                               case 0:                 /* erase from active position to end of screen */
+                                       ScreenEraseToEndOfScreen(pScr);
+                                       break;
+                               case 1:                 /* erase from start of screen to active position */
+                                       #if 0
+                                               ScreenEraseToPosition(pScr);
+                                       #endif
+                                       break;
+
+                               case 2:                 /* erase whole screen */
+                                       ScreenEraseScreen(pScr);
+                                       break;
+
+                               default:
+                                       break;
+                               }
+
+                               escflg = 0;
+                               break;
+
+                       case 'K':                       /* erase in line (EL) */
+                               switch(pScr->parms[0]) {
+                               case -1:
+                               case 0:         /* erase to end of line */
+                                       ScreenEraseToEOL(pScr);
+                                       break;
+
+                               case 1:         /* erase to beginning of line */
+                                       ScreenEraseToBOL(pScr);
+                                       break;
+
+                               case 2:         /* erase whole line */
+                                       ScreenEraseLine(pScr, -1);
+                                       break;
+
+                               default:
+                                       break;
+                               }
+
+                               escflg = 0;
+                               break;
+
+                       case 'L':               /* insert n lines preceding current line (IL) */
+                               if (pScr->parms[0] < 1)
+                                       pScr->parms[0] = 1;
+                               ScreenInsLines(pScr, pScr->parms[0], -1);
+                               escflg = 0;
+                               break;
+
+                       case 'M':               /* delete n lines from current position downward (DL) */
+                               if (pScr->parms[0] < 1)
+                                       pScr->parms[0] = 1;
+                               ScreenDelLines(pScr, pScr->parms[0], -1);
+                               escflg = 0;
+                               break;
+
+                       case 'P':               /* delete n chars from cursor to the left (DCH) */
+                               if (pScr->parms[0] < 1)
+                                       pScr->parms[0] = 1;
+                               ScreenDelChars(pScr, pScr->parms[0]);
+                               escflg = 0;
+                               break;
+
+                       #if 0
+                               case 'R':                       /* receive cursor position status from host */
+                                       break;
+                       #endif
+
+                       #if 0
+                               case 'c':                       /* device attributes (DA) */
+                                       ScreenSendIdent();
+                                       escflg = 0;
+                                       break;
+                       #endif
+
+                       case 'g':               /* tabulation clear (TBC) */
+                               if (pScr->parms[0] == 3)                /* clear all tabs */
+                                       ScreenTabClear(pScr);
+                               else
+                                       if (pScr->parms[0] <= 0)        /* clear tab stop at active position */
+                                               pScr->tabs[pScr->x] = ' ';
+                               escflg = 0;
+                               break;
+
+                       case 'h':               /* set mode (SM) */
+//                  ScreenSetOption(pScr,1);
+                               escflg = 0;
+                               break;
+
+                       case 'i':               /* toggle printer */
+                               #if 0
+                                       if(pScr->parms[pScr->parmptr] == 5)
+                                       pScr->localprint = 1;
+                                       else if (pScr->parms[pScr->parmptr] == 4)
+                                       pScr->localprint = 0;
+                               #endif
+                               escflg = 0;
+                               break;
+
+                       case 'l':                               /* reset mode (RM) */
+//                    ScreenSetOption(pScr,0);
+                               escflg = 0;
+                               break;
+
+                       case 'm':                               /* select graphics rendition (SGR) */
+                               {
+                               int temp = 0;
+
+                               while (temp <= pScr->parmptr) {
+                                       if (pScr->parms[temp] < 1)
+                                               pScr->attrib &= 128;
+                                       else
+                                               pScr->attrib |= 1 << (pScr->parms[temp] - 1);
+                                       temp++;
+                                       }
+                               }
+                               escflg = 0;
+                               break;
+
+                       case 'n':               /* device status report (DSR) */
+                               switch (pScr->parms[0]) {
+                               #if 0
+                                       case 0: /* response from vt100; ready, no malfunctions */
+                                       case 3: /* response from vt100; malfunction, retry */
+                               #endif
+                               case 5: /* send status */
+                               case 6: /* send active position */
+                                       wsprintf(stat, "\033[%d;%dR", pScr->y, pScr->x);
+                                       for (i = 0; stat[i]; i++)
+                                               SendMessage(pScr->hwndTel, WM_MYSCREENCHAR, stat[i], (LPARAM) pScr);
                                        break;
+                               } /* end switch */
+                               escflg = 0;
+                               break;
+
+                       case 'q':                               /* load LEDs (unsupported) (DECLL) */
+                               escflg = 0;
+                               break;
 
-#ifdef CISB
-                case 0x05:      /* CTRL-E found (answerback) */
-                    bp_ENQ();
-                    break;
-
-#endif
-                case 0x07:      /* CTRL-G found (bell) */
-                    ScreenBell(fpScr);
-                    break;
-
-                case 0x08:      /* CTRL-H found (backspace) */
-                    ScreenBackspace(fpScr);
-                    break;
-
-                case 0x09:          /* CTRL-I found (tab) */
-                    ScreenTab(fpScr);       /* Later change for versatile tabbing */
-                    break;
-
-                case 0x0a:          /* CTRL-J found (line feed) */
-                case 0x0b:          /* CTRL-K found (treat as line feed) */
-                case 0x0c:          /* CTRL-L found (treat as line feed) */
-                    ScreenIndex(fpScr);
-                    break;
-                case 0x0d:      /* CTRL-M found (carriage feed) */
-                    ScreenCarriageFeed(fpScr);
-                    break;
-
-#ifdef LATER
-                case 0x0e:      /* CTRL-N found (invoke Graphics (G1) character set) */
-                    if(fpScr->G1)
-                        fpScr->attrib=VSgraph(fpScr->attrib);
-                    else
-                        fpScr->attrib=VSnotgraph(fpScr->attrib);
-                    fpScr->charset=1;
-                    break;
-
-                case 0x0f:      /* CTRL-O found (invoke 'normal' (G0) character set) */
-                    if(fpScr->G0)
-                        fpScr->attrib=VSgraph(fpScr->attrib);
-                    else
-                        fpScr->attrib=VSnotgraph(fpScr->attrib);
-                    fpScr->charset=0;
-                    break;
-#endif
-#ifdef CISB
-                case 0x10:      /* CTRL-P found (undocumented in vt100) */
-                    bp_DLE( c, len);
-                    len=0;
-                    break;
-#endif
-
-#ifdef NOT_USED
-                case 0x11:      /* CTRL-Q found (XON) (unused presently) */
-                case 0x13:      /* CTRL-S found (XOFF) (unused presently) */
-                case 0x18:      /* CTRL-X found (CAN) (unused presently) */
-                case 0x1a:      /* CTRL-Z found (SUB) (unused presently) */
-                    break;
-#endif
-              } /* end switch */
-            c++;        /* advance to the next character in the string */
-            len--;      /* decrement the counter */
-          } /* end while */
-
-        if(escflg==0) {  /* check for normal character to print */
-            while((len>0) && (*c>=32)) {     /* print out printable ascii chars, if we haven't found an ESCAPE char */
-                int sx;
-                int insert,
-                    ocount,
-                    attrib,
-                    extra,
-                    offend;
-                char *acurrent,         /* pointer to the attributes for characters drawn */
-                    *current,           /* pointer to the place to put characters */
-                    *start;
-
-                hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-                fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-                if (fpScrLine==NULL) return;
-
-                current=start=&fpScrLine->text[fpScr->x];
-                acurrent=&fpScrLine->attrib[fpScr->x];
-                attrib=fpScr->attrib;
-                insert=fpScr->IRM;          /* boolean */
-                ocount=fpScr->x;
-                offend=0;
-                extra=0;
-                sx=fpScr->x;
-                if(fpScr->x>fpScr->width) {
-                    if(fpScr->DECAWM) {  /* check for line wrapping on */
-                        fpScr->x=0;
-                        ScreenIndex(fpScr);
-                      } /* end if */
-                    else                /* no line wrapping */
-                        fpScr->x=fpScr->width;
-                    current=start=&fpScrLine->text[fpScr->x];
-                    acurrent=&fpScrLine->attrib[fpScr->x];
-                    ocount=fpScr->x;
-                    sx=fpScr->x;
-                } /* end if */
-                while((len>0) && (*c>=32) && (offend==0)) {
-                    if(insert)
-                        ScreenInsChar(fpScr,1);
-                    *current=*c;
-                    *acurrent=(char)attrib;
-                    c++;
-                    len--;
-                    if(fpScr->x<fpScr->width) {
-                        acurrent++;
-                        current++;
-                        fpScr->x++;
-                      } /* end if */
-                    else {
-                        if(fpScr->DECAWM) {
-                            fpScr->x++;
-                            offend=1;
-                          } /* end if */
-                        else {
-                            fpScr->x=fpScr->width;
-                            extra=1;
-                          } /* end else */
-                      } /* end else */
-                  } /* end while */
-                if (insert)
-                    ScreenInsString(fpScr,fpScr->x-ocount+offend+extra,start);        /* actually just decides which RS to use */
-                else 
-                    ScreenDraw(fpScr,sx,fpScr->y,fpScr->attrib,fpScr->x-ocount+offend+extra,start);
-              } /* end while */
-          } /* end if */
-          
-        while((len>0) && (escflg==1)) {     /* ESC character was found */
-            switch(*c) {
-                case 0x08:      /* CTRL-H found (backspace) */
-                    ScreenBackspace(fpScr);
-                    break;
-
-                case '[':               /* mostly cursor movement options, and DEC private stuff following */
-//                    OutputDebugString("[");
-                    ScreenApClear(fpScr);
-                    escflg=2;
-                    break;
-
-                case '#':               /* various screen adjustments */
-//                    OutputDebugString("#");
-                    escflg=3;
-                    break;
-
-                case '(':               /* G0 character set options */
-//                    OutputDebugString("(");
-                    escflg=4;
-                    break;
-
-                case ')':               /* G1 character set options */
-//                    OutputDebugString(")");
-                    escflg=5;
-                    break;
-
-                case '>':               /* keypad numeric mode (DECKPAM) */
-//                    OutputDebugString(">");
-                    fpScr->DECPAM=0;
-                    escflg=0;
-                    break;
-
-                case '=':               /* keypad application mode (DECKPAM) */
-//                    OutputDebugString("=");
-                    fpScr->DECPAM=1;
-                    escflg=0;
-                    break;
-
-                case '7':               /* save cursor (DECSC) */
-//                    OutputDebugString("7!");
-                    ScreenSaveCursor(fpScr);
-                    escflg=0;
-                    break;
-
-                case '8':               /* restore cursor (DECRC) */
-//                    OutputDebugString("8!");
-                    ScreenRestoreCursor(fpScr);
-                    escflg=0;
-                    break;
-#ifdef LATER
-                case 'c':               /* reset to initial state (RIS) */
-                    ScreenReset(fpScr);
-                    escflg=0;
-                    break;
-#endif
-                case 'D':               /* index (move down one line) (IND) */
-                    ScreenIndex(fpScr);
-                    escflg=0;
-                    break;
-
-                case 'E':               /*  next line (move down one line and to first column) (NEL) */
-//                    OutputDebugString("E!");
-                    fpScr->x=0;
-                    ScreenIndex(fpScr);
-                    escflg=0;
-                    break;
-
-                case 'H':               /* horizontal tab set (HTS) */
-//                    OutputDebugString("H!");
-                    fpScr->tabs[fpScr->x]='x';
-                    escflg=0;
-                    break;
-
-#ifdef CISB
-                case 'I':               /* undoumented in vt100 */
-                    bp_ESC_I();
-                    break;
-
-#endif
-
-                case 'M':               /* reverse index (move up one line) (RI) */
-//                    OutputDebugString("M!");
-                    ScreenRevIndex(fpScr);
-                    escflg=0;
-                    break;
-
-                case 'Z':               /* identify terminal (DECID) */
-                    OutputDebugString("Screen Send Ident- Not implemented! \r\n");
-//                    ScreenSendIdent(fpScr);
-
-                    escflg=0;
-                    break;
-
-                default:
-                    ScreenEmChar(fpScr,0x1b); /* put the ESC character into the Screen */
-                    ScreenEmChar(fpScr,*c);   /* put the next character into the Screen */
-                    escflg=0;
-                    break;
-
-              } /* end switch */
-            c++;
-            len--;
-          } /* end while */
-        while((escflg==2) && (len>0)) {     /* '[' handling */            
-            switch(*c) {
-                case 0x08:      /* backspace */
-                    ScreenBackspace(fpScr);
-                    break;
-
-                case '0':
-                case '1':
-                case '2':
-                case '3':
-                case '4':
-                case '5':
-                case '6':
-                case '7':
-                case '8':
-                case '9':               /* numeric parameters */
-                    if(fpScr->parms[fpScr->parmptr]<0)
-                        fpScr->parms[fpScr->parmptr]=0;
-                    fpScr->parms[fpScr->parmptr]*=10;
-                    fpScr->parms[fpScr->parmptr]+=*c-'0';
-                    break;
-
-                case '?':               /* vt100 mode change */
-                    fpScr->parms[fpScr->parmptr++]=(-2);
-                    break;
-
-                case ';':               /* parameter divider */
-                    fpScr->parmptr++;
-                    break;
-
-                case 'A':               /* cursor up (CUU) */
-//                    OutputDebugString("A");
-                    rc.left=((fpScr->x)*(fpScr->cxChar));
-                    rc.right=(((fpScr->x)+1)*(fpScr->cxChar));
-                    rc.top=((fpScr->cyChar)*(fpScr->y));    
-                    rc.bottom=((fpScr->cyChar)*((fpScr->y)+1));
-                    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-//                    OutputDebugString("[2A]");
-                    if(fpScr->parms[0]<1)
-                        fpScr->y--;
-                    else
-                        fpScr->y-=fpScr->parms[0];
-                    if(fpScr->y<fpScr->top)
-                        fpScr->y=fpScr->top;
-                    ScreenRange(fpScr);
-                    escflg=0;
-                    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-                    break;
-
-                case 'B':               /* cursor down (CUD) */
-//                    OutputDebugString("B");
-                    rc.left=((fpScr->x)*(fpScr->cxChar));
-                    rc.right=(((fpScr->x)+1)*(fpScr->cxChar));
-                    rc.top=((fpScr->cyChar)*(fpScr->y));    
-                    rc.bottom=((fpScr->cyChar)*((fpScr->y)+1));
-                    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-//                    OutputDebugString("[2B]");
-                    if(fpScr->parms[0]<1)
-                        fpScr->y++;
-                    else
-                        fpScr->y+=fpScr->parms[0];
-                    if(fpScr->y>fpScr->bottom)
-                        fpScr->y=fpScr->bottom;
-                    ScreenRange(fpScr);
-                    escflg=0;
-                    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-                    break;
-
-                case 'C':               /* cursor forward (right) (CUF) */
-//                    OutputDebugString("C");
-                    rc.left=((fpScr->x)*(fpScr->cxChar));
-                    rc.right=(((fpScr->x)+1)*(fpScr->cxChar));
-                    rc.top=((fpScr->cyChar)*(fpScr->y));    
-                    rc.bottom=((fpScr->cyChar)*((fpScr->y)+1));
-                    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-//                    OutputDebugString("[2C]");
-                    if(fpScr->parms[0]<1)
-                        fpScr->x++;
-                    else
-                        fpScr->x+=fpScr->parms[0];
-                    ScreenRange(fpScr);
-                    if(fpScr->x>fpScr->width)
-                        fpScr->x=fpScr->width;
-                    escflg=0;
-                    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-                    break;
-
-                case 'D':               /* cursor backward (left) (CUB) */
-//                    OutputDebugString("D");
-                    rc.left=((fpScr->x)*(fpScr->cxChar));
-                    rc.right=(((fpScr->x)+1)*(fpScr->cxChar));
-                    rc.top=((fpScr->cyChar)*(fpScr->y));    
-                    rc.bottom=((fpScr->cyChar)*((fpScr->y)+1));
-                    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-//                    OutputDebugString("[2D]");
-                    if(fpScr->parms[0]<1)
-                        fpScr->x--;
-                    else
-                        fpScr->x-=fpScr->parms[0];
-                    ScreenRange(fpScr);
-                    escflg=0;
-                    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-                    break;
-
-                case 'f':               /* horizontal & vertical position (HVP) */
-                case 'H':               /* cursor position (CUP) */
-//                    OutputDebugString("fH");
-                    rc.left=((fpScr->x)*(fpScr->cxChar));
-                    rc.right=(((fpScr->x)+1)*(fpScr->cxChar));
-                    rc.top=((fpScr->cyChar)*(fpScr->y));    
-                    rc.bottom=((fpScr->cyChar)*((fpScr->y)+1));
-                    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-//                    OutputDebugString("[2H]");
-                    fpScr->x=fpScr->parms[1]-1;
-                    fpScr->y=fpScr->parms[0]-1;
-                    ScreenRange(fpScr);         /* make certain the cursor position is valid */
-                    escflg=0;
-                    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-                    break;
-
-                case 'J':               /* erase in display (ED) */
-//                    OutputDebugString("J");
-                    switch(fpScr->parms[0]) {
-                        case -1:
-                        case 0:     /* erase from active position to end of screen */
-                            ScreenEraseToEndOfScreen(fpScr);
-                            break;
-                        case 1:     /* erase from start of screen to active position */
-                            OutputDebugString("[Screen Erase to Position- Not Implemented!]\r\n");
-//                            ScreenEraseToPosition(fpScr);
-                            break;
-
-                        case 2:     /* erase whole screen */
-//                            OutputDebugString("2");
-                            ScreenEraseScreen(fpScr);
-                            break;
-
-                        default:
-                            break;
-                      } /* end switch */
-                    escflg=0;
-                    break;
-
-                case 'K':               /* erase in line (EL) */
-//                    OutputDebugString("K");
-                    switch(fpScr->parms[0]) {
-                        case -1:
-                        case 0:     /* erase to end of line */
-//                            OutputDebugString("0");
-                            ScreenEraseToEOL(fpScr);
-                            break;
-
-                        case 1:     /* erase to beginning of line */
-//                            OutputDebugString("1");
-                            ScreenEraseToBOL(fpScr);
-                            break;
-
-                        case 2:     /* erase whole line */
-//                            OutputDebugString("2");
-                            ScreenEraseLine(fpScr,-1);
-                            break;
-
-                        default:
-                            break;
-                      } /* end switch */
-                    escflg=0;
-                    break;
-
-                case 'L':               /* insert n lines preceding current line (IL) */
-//                    OutputDebugString("L");
-                    if(fpScr->parms[0]<1)
-                        fpScr->parms[0]=1;
-                    ScreenInsLines(fpScr,fpScr->parms[0],-1);
-                    escflg=0;
-                    break;
-
-                case 'M':               /* delete n lines from current position downward (DL) */
-//                    OutputDebugString("M");
-                    if(fpScr->parms[0]<1)
-                        fpScr->parms[0]=1;
-                    ScreenDelLines(fpScr,fpScr->parms[0],-1);
-                    escflg=0;
-                    break;
-
-                case 'P':               /* delete n chars from cursor to the left (DCH) */
-//                    OutputDebugString("P");
-                    if(fpScr->parms[0]<1)
-                        fpScr->parms[0]=1;
-                    ScreenDelChars(fpScr,fpScr->parms[0]);
-                    escflg=0;
-                    break;
-
-#ifdef NOT_NEEDED
-                case 'R':               /* receive cursor position status from host */
-                    break;
-#endif
-#ifdef LATER
-                case 'c':               /* device attributes (DA) */
-                    ScreenSendIdent();
-                    escflg=0;
-                    break;
-#endif
-                case 'g':               /* tabulation clear (TBC) */
-//                    OutputDebugString("g");
-                    if(fpScr->parms[0]==3)   /* clear all tabs */
-                        ScreenTabClear(fpScr);
-                    else
-                        if(fpScr->parms[0]<=0)   /* clear tab stop at active position */
-                            fpScr->tabs[fpScr->x]=' ';
-                    escflg=0;
-                    break;
-
-                case 'h':               /* set mode (SM) */
-//                    OutputDebugString("h");
-//                  ScreenSetOption(fpScr,1);
-                    escflg=0;
-                    break;
-
-
-                case 'i':               /* toggle printer */
-//                    if(fpScr->parms[fpScr->parmptr]==5)
-//                        fpScr->localprint=1;
-//                    else if(fpScr->parms[fpScr->parmptr]==4)
-//                        fpScr->localprint=0;
-                    escflg=0;
-                    break;
-
-                case 'l':               /* reset mode (RM) */
-//                    OutputDebugString("l");
-//                    ScreenSetOption(fpScr,0);
-                    escflg=0;
-                    break;
-
-                case 'm':               /* select graphics rendition (SGR) */
-//                    OutputDebugString("m");
-                    {
-                        int temp=0;
-
-                        while(temp<=fpScr->parmptr) {
-                            if(fpScr->parms[temp]<1)
-                                fpScr->attrib&=128;
-                            else
-                                fpScr->attrib|=(1<<(fpScr->parms[temp]-1));
-                            temp++;
-                          } /* end while */
-                      } /* end case */
-                    escflg=0;
-                    break;
-
-                case 'n':               /* device status report (DSR) */
-                    switch(fpScr->parms[0]) {
-#ifdef NOT_SUPPORTED
-                    case 0: /* response from vt100; ready, no malfunctions */
-                    case 3: /* response from vt100; malfunction, retry */
-#endif
-                    case 5: /* send status */
-                    case 6: /* send active position */
-                                               wsprintf(stat, "\033[%d;%dR", fpScr->y, fpScr->x);
-                                               for (i = 0; stat[i]; i++)
-                                                       SendMessage(fpScr->hwndTel,WM_MYSCREENCHAR,stat[i],hsScr);
-                        break;
-                    } /* end switch */
-                    escflg=0;
-                    break;
-
-                case 'q':               /* load LEDs (unsupported) (DECLL) */
-                    escflg=0;
-                    break;
-
-                case 'r':               /* set top & bottom margins (DECSTBM) */
-                    if(fpScr->parms[0]<0)
-                        fpScr->top=0;
-                    else
-                        fpScr->top=fpScr->parms[0]-1;
-                    if(fpScr->parms[1]<0)
-                        fpScr->bottom=fpScr->height-1;
-                    else
-                        fpScr->bottom=fpScr->parms[1]-1;
-                    if(fpScr->top<0)
-                        fpScr->top=0;
-                    if(fpScr->top>fpScr->height-1)
-                        fpScr->top=fpScr->height-1;
-                    if(fpScr->bottom<1)
-                        fpScr->bottom=fpScr->height;
-                    if(fpScr->bottom>=fpScr->height)
-                        fpScr->bottom=fpScr->height-1;
-                    if(fpScr->top>=fpScr->bottom) {   /* check for valid scrolling region */
-                        if(fpScr->bottom>=1)     /* assume the bottom value has precedence, unless it is as the top of the screen */
-                            fpScr->top=fpScr->bottom-1;
-                        else                /* totally psychotic case, bottom of screen set to the very top line, move the bottom to below the top */
-                            fpScr->bottom=fpScr->top+1;
-                      } /* end if */
-                    fpScr->x=0;
-                    fpScr->y=0;
-#ifdef NOT_SUPPORTED
-                    if (fpScr->DECORG)
-                        fpScr->y=fpScr->top;  /* origin mode relative */
-#endif
-                    escflg=0;
-                    break;
-
-#ifdef NOT_SUPPORTED
-                case 'x':                       /* request/report terminal parameters (DECREQTPARM/DECREPTPARM) */
-                case 'y':                       /* invoke confidence test (DECTST) */
-                    break;
-#endif
-                default:            /* Dag blasted strays... */
-                    escflg=0;
-                    break;
-
-              } /* end switch */
-            c++;
-            len--;
-
-#ifdef NOT
-/* @UM */
-            if(fpScr->localprint && (len>0)) {    /* see if printer needs anything */
-                pcount=send_localprint(c,len);
-                len-=pcount;
-                c+=pcount;
-              } /* end if */
-/* @UM */
-#endif
-          } /* end while */
-        while((escflg==3) && (len>0)) { /* #  Handling */
-            switch(*c) {
-                case 0x08:      /* backspace */
-                    ScreenBackspace(fpScr);
-                    break;
-
-#ifdef NOT_SUPPORTED
-                case '3':               /* top half of double line (DECDHL) */
-                case '4':               /* bottom half of double line (DECDHL) */
-                case '5':               /* single width line (DECSWL) */
-                case '6':               /* double width line (DECDWL) */
-                    break;
-#endif
-                case '8':               /* screen alignment display (DECALN) */
-                    ScreenAlign(fpScr);
-//                    OutputDebugString("8");
-                    escflg=0;
-                    break;
-                default:
-                    escflg=0;
-                    break;
-
-              } /* end switch */
-            c++;
-            len--;
-          } /* end while */
-        while((escflg==4) && (len>0)) { /* ( Handling (GO character set) */
-            switch(*c) {
-                case 0x08:      /* backspace */
-                    ScreenBackspace(fpScr);
-                    break;
-
-#ifdef LATER
-                case 'A':               /* united kingdom character set (unsupported) */
-                case 'B':               /* ASCII character set */
-                case '1':               /* choose standard graphics (same as ASCII) */
-                    fpScr->G0=0;
-                    if(!fpScr->charset)
-                        fpScr->attrib=ScreenNotGraph(fpScr->attrib);
-                    escflg=0;
-                    break;
-
-                case '0':               /* choose special graphics set */
-                case '2':               /* alternate character set (special graphics) */
-                    fpScr->G0=1;
-                    if(!fpScr->charset)
-                        fpScr->attrib=ScreenGraph(fpScr->attrib);
-                    escflg=0;
-                    break;
-#endif
-                default:
-                    escflg=0;
-                    break;
-              } /* end switch */
-            c++;
-            len--;
-          } /* end while */
-        while((escflg==5) && (len>0)) { /* ) Handling (G1 handling) */
-            switch(*c) {
-                case 0x08:      /* backspace */
-                    ScreenBackspace(fpScr);
-                    break;
-
-#ifdef LATER
-                case 'A':               /* united kingdom character set (unsupported) */
-                case 'B':               /* ASCII character set */
-                case '1':               /* choose standard graphics (same as ASCII) */
-                    fpScr->G1=0;
-                    if(fpScr->charset)
-                        fpScr->attrib=ScreenNotGraph(fpScr->attrib);
-                    escflg=0;
-                    break;
-
-                case '0':               /* choose special graphics set */
-                case '2':               /* alternate character set (special graphics) */
-                    fpScr->G1=1;
-                    if(fpScr->charset)
-                        fpScr->attrib=ScreenGraph(fpScr->attrib);
-                    escflg=0;
-                    break;
-#endif
-                default:
-                    escflg=0;
-                    break;
-              } /* end switch */
-            c++;
-            len--;
-          } /* end while */
-
-        while((escflg>=6) && (escflg<=10) && (len>0)) { /* Handling IAC */
+                       case 'r':                               /* set top & bottom margins (DECSTBM) */
+                               if (pScr->parms[0] < 0)
+                                       pScr->top = 0;
+                               else
+                                       pScr->top = pScr->parms[0] - 1;
+                               if (pScr->parms[1] < 0)
+                                       pScr->bottom = pScr->height - 1;
+                               else
+                                       pScr->bottom = pScr->parms[1] - 1;
+                               if (pScr->top < 0)
+                                       pScr->top = 0;
+                               if (pScr->top > pScr->height-1)
+                                       pScr->top = pScr->height-1;
+                               if (pScr->bottom < 1)
+                                       pScr->bottom = pScr->height;
+                               if (pScr->bottom >= pScr->height)
+                                       pScr->bottom = pScr->height - 1;
+                               if (pScr->top >= pScr->bottom) {/* check for valid scrolling region */
+                                       if (pScr->bottom >= 1)          /* assume the bottom value has precedence, unless it is as the top of the screen */
+                                               pScr->top = pScr->bottom - 1;
+                                       else                /* totally psychotic case, bottom of screen set to the very top line, move the bottom to below the top */
+                                               pScr->bottom = pScr->top + 1;
+                               }
+                               pScr->x = 0;
+                               pScr->y = 0;
+                               #if 0
+                                       if (pScr->DECORG)
+                                               pScr->y = pScr->top;  /* origin mode relative */
+                               #endif
+                               escflg = 0;
+                               break;
+
+                       #if 0 
+                               case 'x':                       /* request/report terminal parameters (DECREQTPARM/DECREPTPARM) */
+                               case 'y':                       /* invoke confidence test (DECTST) */
+                                       break;
+                       #endif
+
+                       default:
+                               escflg = 0;
+                               break;
+
+                       }
+
+                       c++;
+                       len--;
+
+                       #if 0
+                               if (pScr->localprint && (len > 0)) {    /* see if printer needs anything */
+                                       pcount = send_localprint(c, len);
+                                       len -= pcount;
+                                       c += pcount;
+                               }
+                       #endif
+               }
+
+               while ((escflg == 3) && (len > 0)) { /* #  Handling */
+                       switch (*c) {
+                       case 0x08:      /* backspace */
+                               ScreenBackspace(pScr);
+                               break;
+
+                       #if 0
+                               case '3':                       /* top half of double line (DECDHL) */
+                               case '4':                       /* bottom half of double line (DECDHL) */
+                               case '5':                       /* single width line (DECSWL) */
+                               case '6':                       /* double width line (DECDWL) */
+                                       break;
+                       #endif
+
+                       case '8':               /* screen alignment display (DECALN) */
+                               ScreenAlign(pScr);
+                               escflg = 0;
+                               break;
+
+                       default:
+                               escflg = 0;
+                               break;
+
+                       }
+
+                       c++;
+                       len--;
+               }
+
+               while ((escflg == 4) && (len > 0)) { /* ( Handling (GO character set) */
+                       switch (*c) {
+
+                       case 0x08:      /* backspace */
+                               ScreenBackspace(pScr);
+                               break;
+
+                       #if 0
+                               case 'A':               /* united kingdom character set (unsupported) */
+                               case 'B':               /* ASCII character set */
+                               case '1':               /* choose standard graphics (same as ASCII) */
+                                       pScr->G0 = 0;
+                                       if (!pScr->charset)
+                                               pScr->attrib = ScreenNotGraph(pScr->attrib);
+                                       escflg = 0;
+                                       break;
+
+                               case '0':               /* choose special graphics set */
+                               case '2':               /* alternate character set (special graphics) */
+                                       pScr->G0 = 1;
+                                       if(!pScr->charset)
+                                               pScr->attrib = ScreenGraph(pScr->attrib);
+                                       escflg = 0;
+                                       break;
+                       #endif
+
+                       default:
+                               escflg = 0;
+                               break;
+                       }
+
+                       c++;
+                       len--;
+
+               } /* end while */
+
+               while((escflg == 5) && (len > 0)) { /* ) Handling (G1 handling) */
+                       switch (*c) {
+
+                       case 0x08:                              /* backspace */
+                               ScreenBackspace(pScr);
+                               break;
+
+                       #if 0
+                               case 'A':               /* united kingdom character set (unsupported) */
+                               case 'B':               /* ASCII character set */
+                               case '1':               /* choose standard graphics (same as ASCII) */
+                                       pScr->G1 = 0;
+                                       if (pScr->charset)
+                                               pScr->attrib = ScreenNotGraph(pScr->attrib);
+                                       escflg = 0;
+                                       break;
+
+                               case '0':               /* choose special graphics set */
+                               case '2':               /* alternate character set (special graphics) */
+                                       pScr->G1 = 1;
+                                       if(pScr->charset)
+                                               pScr->attrib = ScreenGraph(pScr->attrib);
+                                       escflg = 0;
+                                       break;
+                       #endif
+
+                       default:
+                               escflg = 0;
+                               break;
+                       } /* end switch */
+
+                       c++;
+                       len--;
+               } /* end while */
+
+               while ((escflg >= 6) && (escflg <= 10) && (len > 0)) { /* Handling IAC */
                        ic = (unsigned char) *c;
                        switch (escflg) {
 
                        case 6:     /* Handling IAC xx */
                                if (ic == 255) /* if IAC */
-                                       escflg=0;
-                else if (ic == 250) /* if SB */
-                                       escflg=7;
+                                       escflg = 0;
+                               else if (ic == 250) /* if SB */
+                                       escflg = 7;
                                else
-                                       escflg=9;
+                                       escflg = 9;
                                break;
 
                        case 7:     /* Handling IAC SB xx */
                                if (ic == 255) /* if IAC */
-                    escflg=8;
+                                       escflg = 8;
                                break;
 
                        case 8:     /* Handling IAC SB IAC xx */
                                if (ic == 255) /* if IAC IAC */
-                   escflg=7;
+                                  escflg = 7;
                                else if (ic == 240) /* if IAC SE */
-                   escflg=0;
+                                  escflg = 0;
                                break;
 
                        case 9:    /* IAC xx xx */
-                               escflg=0;
+                               escflg = 0;
                                break;
                        }
-            c++;        /* advance to the next character in the string */
-            len--;      /* decrement the counter */
+                       c++;        /* advance to the next character in the string */
+                       len--;      /* decrement the counter */
                }
 
-        if((escflg>2 && escflg<6) && (len>0)) {
-            escflg=0;
-            c++;
-            len--;
-          } /* end if */
-      } /* end while */
-    fpScr->escflg=escflg;
-    ScreenCursorOn(fpScr);
-    GlobalUnlock(hsScr);
-}   /* end ScreenEm() */
+               if (escflg > 2 && escflg < 6 && len > 0) {
+                       escflg = 0;
+                       c++;
+                       len--;
+               }
+       }
+       pScr->escflg = escflg;
+       ScreenCursorOn(pScr);
+
+} /* ScreenEm */
index 9bdb00ec0d8a8962c8d5302b63821f5615dc13f3..ce670832507b5ab810375080928f82e510b162ef 100644 (file)
+/* font.c */
+
 #include <windows.h>
 #include <commdlg.h>
+#include <assert.h>
 #include "screen.h"
 #include "ini.h"
 
-LOGFONT lf;
-HFONT hFont;
-char szStyle[LF_FACESIZE];
-
-void ProcessFontChange(HWND hWnd) {
-    static DWORD dwFontColor;  /* Color of font if one has been selected */
-    CHOOSEFONT cf;
-    HDC hDC;
-    SCREEN *fpScr;
-    HGLOBAL hgScr;
-    TEXTMETRIC tm;
-    char buf[16];
-        
-    hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-    if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-    fpScr=(SCREEN *)GlobalLock(hgScr);
-    if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-
-    cf.lStructSize = sizeof(cf);
-    cf.hwndOwner = hWnd;
-    cf.lpLogFont = (LPLOGFONT)&(fpScr->lf);
-    cf.lpszStyle = szStyle;
-    cf.Flags = CF_INITTOLOGFONTSTRUCT; // | CF_USESTYLE;
-    cf.Flags |= CF_SCREENFONTS;
-//    cf.Flags |= CF_ANSIONLY;
-    cf.Flags |= CF_FORCEFONTEXIST;
-    cf.Flags |= CF_FIXEDPITCHONLY;
-    cf.Flags |= CF_NOSIMULATIONS;
+void ProcessFontChange(
+       HWND hWnd)
+{
+       static DWORD dwFontColor;  /* Color of font if one has been selected */
+       CHOOSEFONT cf;
+       HDC hDC;
+       SCREEN *pScr;
+       TEXTMETRIC tm;
+       char buf[16];
+       char szStyle[LF_FACESIZE];
+               
+       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+       assert(pScr != NULL);
+
+       cf.lStructSize = sizeof(cf);
+       cf.hwndOwner = hWnd;
+       cf.lpLogFont = (LPLOGFONT) &(pScr->lf);
+       cf.lpszStyle = szStyle;
+       cf.Flags = CF_INITTOLOGFONTSTRUCT; // | CF_USESTYLE;
+       cf.Flags |= CF_SCREENFONTS;
+//  cf.Flags |= CF_ANSIONLY;
+       cf.Flags |= CF_FORCEFONTEXIST;
+       cf.Flags |= CF_FIXEDPITCHONLY;
+       cf.Flags |= CF_NOSIMULATIONS;
  
-    if (ChooseFont(&cf)) {
-      if (fpScr->ghSelectedFont) DeleteObject(fpScr->ghSelectedFont);
-
-      fpScr->ghSelectedFont = CreateFontIndirect((LPLOGFONT)&(fpScr->lf));
-      fpScr->lf.lfUnderline=TRUE;
-      fpScr->ghSelectedULFont= CreateFontIndirect((LPLOGFONT)&(fpScr->lf));
-      fpScr->lf.lfUnderline=FALSE;
-      hDC=GetDC(hWnd);
-      SelectObject(hDC,fpScr->ghSelectedFont);
-      GetTextMetrics(hDC,(LPTEXTMETRIC)&tm);
-
-      fpScr->cxChar = tm.tmAveCharWidth;
-      fpScr->cyChar = tm.tmHeight+ tm.tmExternalLeading;
-      ReleaseDC(hWnd,hDC);
-      SetWindowPos(hWnd,NULL,0,0, fpScr->cxChar * fpScr->width + 
-                    FRAME_WIDTH, fpScr->cyChar * fpScr->height +
-                    FRAME_HEIGHT, SWP_NOMOVE|SWP_NOZORDER);
-
-      dwFontColor=RGB(255, 255, 255);
-      InvalidateRect(hWnd, NULL, TRUE);
-    }
-
-    WritePrivateProfileString(INI_FONT,"FaceName",fpScr->lf.lfFaceName,TELNET_INI);
-    wsprintf(buf,"%d",(int)fpScr->lf.lfHeight);
-    WritePrivateProfileString(INI_FONT,"Height",buf,TELNET_INI);
-    wsprintf(buf,"%d",(int)fpScr->lf.lfWidth);
-    WritePrivateProfileString(INI_FONT,"Width",buf,TELNET_INI);
-    wsprintf(buf,"%d",(int)fpScr->lf.lfEscapement);
-    WritePrivateProfileString(INI_FONT,"Escapement",buf,TELNET_INI);
-    wsprintf(buf,"%d",(int)fpScr->lf.lfCharSet);
-    WritePrivateProfileString(INI_FONT,"CharSet",buf,TELNET_INI);
-    wsprintf(buf,"%d",(int)fpScr->lf.lfPitchAndFamily);
-    WritePrivateProfileString(INI_FONT,"PitchAndFamily",buf,TELNET_INI);
-    
-    GlobalUnlock(hgScr);
-    return;
-}
-
-void NEAR InitializeStruct(WORD wCommDlgType, LPSTR lpStruct, HWND hWnd)
+       if (ChooseFont(&cf)) {
+               if (pScr->hSelectedFont)
+                       DeleteObject(pScr->hSelectedFont);
+
+               pScr->hSelectedFont = CreateFontIndirect(&(pScr->lf));
+               pScr->lf.lfUnderline = TRUE;
+               pScr->hSelectedULFont = CreateFontIndirect(&(pScr->lf));
+               pScr->lf.lfUnderline = FALSE;
+               hDC = GetDC(hWnd);
+               SelectObject(hDC, pScr->hSelectedFont);
+               GetTextMetrics(hDC, &tm);
+               pScr->cxChar = tm.tmAveCharWidth;
+               pScr->cyChar = tm.tmHeight + tm.tmExternalLeading;
+               ReleaseDC(hWnd, hDC);
+               SetWindowPos(hWnd, NULL, 0, 0, pScr->cxChar * pScr->width + 
+                       FRAME_WIDTH, pScr->cyChar * pScr->height +
+                       FRAME_HEIGHT, SWP_NOMOVE | SWP_NOZORDER);
+
+               dwFontColor = RGB(255, 255, 255);
+               InvalidateRect(hWnd, NULL, TRUE);
+       }
+
+       WritePrivateProfileString(INI_FONT, "FaceName", pScr->lf.lfFaceName, TELNET_INI);
+       wsprintf(buf, "%d", (int) pScr->lf.lfHeight);
+       WritePrivateProfileString(INI_FONT, "Height", buf, TELNET_INI);
+       wsprintf(buf, "%d", (int) pScr->lf.lfWidth);
+       WritePrivateProfileString(INI_FONT, "Width", buf, TELNET_INI);
+       wsprintf(buf, "%d", (int) pScr->lf.lfEscapement);
+       WritePrivateProfileString(INI_FONT, "Escapement", buf, TELNET_INI);
+       wsprintf(buf, "%d", (int) pScr->lf.lfCharSet);
+       WritePrivateProfileString(INI_FONT, "CharSet", buf, TELNET_INI);
+       wsprintf(buf, "%d", (int) pScr->lf.lfPitchAndFamily);
+       WritePrivateProfileString(INI_FONT, "PitchAndFamily", buf, TELNET_INI);
+
+       return;
+
+} /* ProcessFontChange */
+
+
+void NEAR InitializeStruct(
+       WORD wCommDlgType,
+       LPSTR lpStruct,
+       HWND hWnd)
 {
-   LPCHOOSEFONT        lpFontChunk;
+       LPCHOOSEFONT lpFontChunk;
    
-   switch (wCommDlgType)
-      {      
-      case IDC_FONT:
-
-         lpFontChunk = (LPCHOOSEFONT)lpStruct;
-
-         lpFontChunk->lStructSize    = sizeof(CHOOSEFONT);
-         lpFontChunk->hwndOwner      = hWnd;
-
-//The hDC field will be initialized when we return--this avoids passing
-//the hDC in or getting the DC twice.
-//The LOGFONT field will also be initialized when we get back.
-//            lpFontChunk->hDC            = hDC;
-//            lpFontChunk->lpLogFont      = &lf;
-
-         lpFontChunk->Flags          = CF_SCREENFONTS | CF_FIXEDPITCHONLY |
-                                       CF_INITTOLOGFONTSTRUCT | CF_APPLY;
-         lpFontChunk->rgbColors      = RGB(0, 0, 255);
-         lpFontChunk->lCustData      = 0L;
-         lpFontChunk->lpfnHook       = NULL;
-         lpFontChunk->lpTemplateName = (LPSTR)NULL;
-         lpFontChunk->hInstance      = (HANDLE)NULL;
-         lpFontChunk->lpszStyle      = (LPSTR)NULL;
-         lpFontChunk->nFontType      = SCREEN_FONTTYPE;
-         lpFontChunk->nSizeMin       = 0;
-         lpFontChunk->nSizeMax       = 0;
-         break;
-      default:
-         break;
-      }
-   return;
-}
-
-LPSTR NEAR AllocAndLockMem(HANDLE *hChunk, WORD wSize) {
-   LPSTR lpChunk;
-
-   *hChunk = GlobalAlloc(GMEM_FIXED, wSize);
-   if (*hChunk) {
-       lpChunk = GlobalLock(*hChunk);
-       if (!lpChunk) {
-           GlobalFree(*hChunk);
-           ReportError(IDC_LOCKFAIL);
-           lpChunk=NULL;
-       }
-   } else {
-       ReportError(IDC_ALLOCFAIL);
-       lpChunk=NULL;
-   }
-   return(lpChunk);
-}
-
-
+       if (wCommDlgType == IDC_FONT) {
+               lpFontChunk = (LPCHOOSEFONT) lpStruct;
+
+               lpFontChunk->lStructSize = sizeof(CHOOSEFONT);
+               lpFontChunk->hwndOwner = hWnd;
+               lpFontChunk->Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT | CF_APPLY;
+               lpFontChunk->rgbColors = RGB(0, 0, 255);
+               lpFontChunk->lCustData = 0L;
+               lpFontChunk->lpfnHook = NULL;
+               lpFontChunk->lpTemplateName = NULL;
+               lpFontChunk->hInstance = NULL;
+               lpFontChunk->lpszStyle = NULL;
+               lpFontChunk->nFontType = SCREEN_FONTTYPE;
+               lpFontChunk->nSizeMin = 0;
+               lpFontChunk->nSizeMax = 0;
+       }
+
+} /* InitialiseStruct */
index d2ec5fc37b6275bd5afa40ea6ea98c8d183acf14..ab01cb3808cc8c6e38055a416cec13c1ccea6dd8 100644 (file)
+/* intern.c */
+
 #include <windows.h>
 #include <string.h>
+#include <assert.h>
 #include "screen.h"
+
 #define ScreenClearAttrib 0
 
-HSCREENLINE GetScreenLineFromY(SCREEN *fpScr,int y)
+SCREENLINE *GetScreenLineFromY(
+       SCREEN *pScr,
+       int y)
 {
-    HSCREENLINE hgScrLine,hgScrLineTmp;
-    SCREENLINE *fpScrLine;
-    int idx;
-
-    hgScrLine=fpScr->screen_top;
-    for (idx=0; idx<fpScr->height; idx++) {
-        if (idx==y) return(hgScrLine);
-        fpScrLine=LINE_MEM_LOCK(hgScrLine);
-        if (fpScrLine==NULL) return (NULL);    
-        hgScrLineTmp=fpScrLine->next;        
-        LINE_MEM_UNLOCK(hgScrLine);
-        hgScrLine=hgScrLineTmp;
-    }
-    return(NULL);
-}    
-
-HSCREENLINE ScreenClearLine(SCREEN *fpScr,HSCREENLINE hgScrLine)
+       SCREENLINE *pScrLine;
+       int idx;
+
+       pScrLine = pScr->screen_top;
+       for (idx = 0; idx < pScr->height; idx++) {
+               if (idx == y)
+                       return(pScrLine);
+               if (pScrLine == NULL)
+                       return(NULL);
+               pScrLine = pScrLine->next;
+       }
+
+       return(NULL);
+
+} /* GetScreenLineFromY */
+
+
+SCREENLINE *ScreenClearLine(
+       SCREEN *pScr,
+       SCREENLINE *pScrLine)
 {
-    SCREENLINE *fpScrLine;
-      
-    fpScrLine=LINE_MEM_LOCK(hgScrLine);
-       memset(fpScrLine->attrib, ScreenClearAttrib, fpScr->width);
-       memset(fpScrLine->text, ' ', fpScr->width);
-    LINE_MEM_UNLOCK(hgScrLine);
-    return(hgScrLine);
-}
-
-void ScreenUnscroll(SCREEN *fpScr)
+       memset(pScrLine->attrib, ScreenClearAttrib, pScr->width);
+       memset(pScrLine->text, ' ', pScr->width);
+       return(pScrLine);
+
+} /* ScreenClearLine */
+
+
+void ScreenUnscroll(
+       SCREEN *pScr)
 {
        int idx;
-    HSCREENLINE hgScrLine,hgScrLineTmp;
-    SCREENLINE *fpScrLine;
+       SCREENLINE *pScrLine;
 
-    if (fpScr->screen_bottom == fpScr->buffer_bottom)
+       if (pScr->screen_bottom == pScr->buffer_bottom)
                return;
 
-    fpScr->screen_bottom=fpScr->buffer_bottom;
-    hgScrLine=fpScr->screen_bottom;
-    for (idx = 1; idx < fpScr->height; idx++) {
-        fpScrLine=LINE_MEM_LOCK(hgScrLine);
-        if (fpScrLine==NULL)
-            return;
-        hgScrLineTmp=fpScrLine->prev;
-        LINE_MEM_UNLOCK(hgScrLine);
-        hgScrLine=hgScrLineTmp;
-    }
-    fpScr->screen_top=hgScrLine;
-}
-
-void ScreenCursorOn(SCREEN *fpScr)
+       pScr->screen_bottom = pScr->buffer_bottom;
+       pScrLine = pScr->screen_bottom;
+       for (idx = 1; idx < pScr->height; idx++) {
+               if (pScrLine == NULL)
+                       return;
+               pScrLine = pScrLine->prev;
+       }
+       pScr->screen_top = pScrLine;
+
+} /* ScreenUnscroll */
+
+
+void ScreenCursorOn(
+       SCREEN *pScr)
 {
        int y;
        int nlines;
 
-       if (fpScr->screen_bottom != fpScr->buffer_bottom)
-       nlines = fpScr->numlines - GetScrollPos(fpScr->hWnd, SB_VERT);
+       if (pScr->screen_bottom != pScr->buffer_bottom)
+               nlines = pScr->numlines - GetScrollPos(pScr->hWnd, SB_VERT);
        else
                nlines = 0;
 
-       y = fpScr->y + nlines;
-       SetCaretPos(fpScr->x * fpScr->cxChar, (y+1) * fpScr->cyChar);
-       ShowCaret(fpScr->hWnd);
-}
+       y = pScr->y + nlines;
+       SetCaretPos(pScr->x * pScr->cxChar, (y+1) * pScr->cyChar);
+       ShowCaret(pScr->hWnd);
+
+} /* ScreenCursorOn */
 
-void ScreenCursorOff(SCREEN *fpScr)
+
+void ScreenCursorOff(
+       SCREEN *pScr)
 {
-       HideCaret(fpScr->hWnd);
-}
+       HideCaret(pScr->hWnd);
+
+} /* ScreenCursorOff */
 
-void ScreenELO(SCREEN *fpScr,int s)
+
+void ScreenELO(
+       SCREEN *pScr,
+       int s)
 {
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    RECT rc;
-            
-/*  fpScrrapnow(&i,&j); */
-    if(s<0) 
-        s=fpScr->y;
-    
-    hgScrLine=GetScreenLineFromY(fpScr,s);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-       memset(fpScrLine->attrib, ScreenClearAttrib, fpScr->width);
-       memset(fpScrLine->text, ' ', fpScr->width);
-    LINE_MEM_UNLOCK(hgScrLine);
-    rc.left=0;
-    rc.right=(fpScr->width*fpScr->cxChar);
-    rc.top=(fpScr->cyChar*s);    
-    rc.bottom=(fpScr->cyChar*(s+1));
-    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-}
-
-void ScreenEraseScreen(SCREEN *fpScr) 
+       SCREENLINE *pScrLine;
+       RECT rc;
+                       
+       if (s < 0) 
+               s = pScr->y;
+       
+       pScrLine = GetScreenLineFromY(pScr,s);
+       memset(pScrLine->attrib, ScreenClearAttrib, pScr->width);
+       memset(pScrLine->text, ' ', pScr->width);
+       rc.left = 0;
+       rc.right = pScr->width * pScr->cxChar;
+       rc.top = pScr->cyChar * s;    
+       rc.bottom = pScr->cyChar * (s+1);
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+
+} /* ScreenELO */
+
+void ScreenEraseScreen(
+       SCREEN *pScr)
 {
-    int i;
-    int x1=0,y1=0;
-    int x2=fpScr->width,y2=fpScr->height;
-    int n=(-1);
-            
-    for(i=0; i<fpScr->height; i++)
-        ScreenELO(fpScr,i);
-    InvalidateRect(fpScr->hWnd,NULL,TRUE);
-    UpdateWindow(fpScr->hWnd);
-}
-
-void ScreenTabClear(SCREEN *fpScr)
+       int i;
+       int x1 = 0;
+       int y1 = 0;
+       int x2 = pScr->width;
+       int y2 = pScr->height;
+       int n = -1;
+                       
+       for(i = 0; i < pScr->height; i++)
+               ScreenELO(pScr,i);
+
+       InvalidateRect(pScr->hWnd, NULL, TRUE);
+       UpdateWindow(pScr->hWnd);
+
+} /* ScreenEraseScreen */
+
+
+void ScreenTabClear(
+       SCREEN *pScr)
 {
-    int x=0;
+       int x = 0;
+
+       while(x <= pScr->width) {
+               pScr->tabs[x] = ' ';
+               x++;
+       }
+
+} /* ScreenTabClear */
 
-    while(x<=fpScr->width) {
-        fpScr->tabs[x]=' ';
-        x++;
-      } /* end while */
-}
 
-void ScreenTabInit(SCREEN *fpScr)
+void ScreenTabInit(
+       SCREEN *pScr)
 {
-    int x=0;
+       int x = 0;
 
-    ScreenTabClear(fpScr);
+       ScreenTabClear(pScr);
+
+       while(x <= pScr->width) { 
+               pScr->tabs[x] = 'x';
+               x += 8;
+       }
+       pScr->tabs[pScr->width] = 'x';
+
+} /* ScreenTabInit */
 
-    while(x<=fpScr->width) { 
-        fpScr->tabs[x]='x';
-        x+=8;
-    } /* end while */
-    fpScr->tabs[fpScr->width]='x';
-}
 
-void ScreenReset(SCREEN *fpScr)
+void ScreenReset(
+       SCREEN *pScr)
 {
-    fpScr->top=0;
-    fpScr->bottom=fpScr->height-1;
-    fpScr->parmptr=0;
-    fpScr->escflg=0;
-    fpScr->DECAWM=1;
-    fpScr->DECCKM=0;
-    fpScr->DECPAM=0;
-/*  fpScr->DECORG=0;     */
-/*  fpScr->Pattrib=-1;   */
-    fpScr->IRM=0;
-    fpScr->attrib=0;
-    fpScr->x=0;
-    fpScr->y=0;
-//    fpScr->charset=0;
-    ScreenEraseScreen(fpScr);
-    ScreenTabInit(fpScr);
-//    set_vtwrap(fpScrn,fpScr->DECAWM);     /* QAK - 7/27/90: added because resetting the virtual screen's wrapping flag doesn't reset telnet window's wrapping */
-}
-
-
-void ScreenListMove(HSCREENLINE hTD,HSCREENLINE hBD,HSCREENLINE hTI,HSCREENLINE hBI)
+       pScr->top = 0;
+       pScr->bottom = pScr->height-1;
+       pScr->parmptr = 0;
+       pScr->escflg = 0;
+       pScr->DECAWM = 1;
+       pScr->DECCKM = 0;
+       pScr->DECPAM = 0;
+/*  pScr->DECORG = 0;     */
+/*  pScr->Pattrib = -1;   */
+       pScr->IRM = 0;
+       pScr->attrib = 0;
+       pScr->x = 0;
+       pScr->y = 0;
+//    pScr->charset = 0;
+       ScreenEraseScreen(pScr);
+       ScreenTabInit(pScr);
+//    set_vtwrap(pScrn, pScr->DECAWM);     /* QAK - 7/27/90: added because resetting the virtual screen's wrapping flag doesn't reset telnet window's wrapping */
+
+} /* ScreenReset */
+
+
+void ScreenListMove(
+       SCREENLINE *TD,
+       SCREENLINE *BD,
+       SCREENLINE *TI,
+       SCREENLINE *BI)
 {
-    HSCREENLINE hTmpLine;
-    SCREENLINE *TD,*BD,*TI,*BI,*tmpLine;
-    
-//    OutputDebugString("ScreenListMove");
-    TD= (SCREENLINE *)GlobalLock(hTD);
-    BD= (SCREENLINE *)GlobalLock(hBD);
-    TI= (SCREENLINE *)GlobalLock(hTI);
-    BI= (SCREENLINE *)GlobalLock(hBI);
-    
-    if(TD->prev!=NULL) {
-        hTmpLine=TD->prev;
-        tmpLine=(SCREENLINE *)GlobalLock(hTmpLine);
-        tmpLine->next=BD->next;    /* Maintain circularity */
-        GlobalUnlock(hTmpLine);
-    }        
-    if(BD->next!=NULL) {
-        hTmpLine=BD->next;
-        tmpLine=(SCREENLINE *)GlobalLock(hTmpLine);
-        tmpLine->prev=TD->prev;
-        GlobalUnlock(hTmpLine);
-    }
-    TD->prev=hTI;                    /* Place the node in its new home */
-    BD->next=hBI;
-    if(TI!=NULL) 
-        TI->next=hTD;                /* Ditto prev->prev */
-    if(BI!=NULL) 
-        BI->prev=hBD;
-        
-    GlobalUnlock(hTD);
-    GlobalUnlock(hBD);
-    GlobalUnlock(hTI);
-    GlobalUnlock(hBI);            
-}
-
-
-void ScreenDelLines(SCREEN *fpScr, int n, int s)
+       if (TD->prev != NULL)
+               TD->prev->next = BD->next;    /* Maintain circularity */
+
+       if (BD->next != NULL)
+               BD->next->prev = TD->prev;
+
+       TD->prev = TI;                    /* Place the node in its new home */
+       BD->next = BI;
+
+       if (TI != NULL) 
+               TI->next = TD;                /* Ditto prev->prev */
+
+       if (BI != NULL) 
+               BI->prev = BD;
+
+} /* ScreenListMove */
+
+
+void ScreenDelLines(
+       SCREEN *pScr,
+       int n,
+       int s)
 {
-    HSCREENLINE hBI,hTI,hTD,hBD;
-    SCREENLINE *TI;
-    SCREENLINE *BD;
-    HSCREENLINE hLine;
-    SCREENLINE *fpLine;
-    HSCREENLINE hTemp;
+       SCREENLINE *BI;
+       SCREENLINE *TI;
+       SCREENLINE *TD;
+       SCREENLINE *BD;
+       SCREENLINE *pLine;
        int idx;
        RECT rc;
        HDC hDC;
-    
-    if (s < 0) 
-        s = fpScr->y;
+       
+       if (s < 0) 
+               s = pScr->y;
 
-    if (s + n - 1 > fpScr->bottom)
-        n = fpScr->bottom - s + 1;
+       if (s + n - 1 > pScr->bottom)
+               n = pScr->bottom - s + 1;
 
-    hTD = GetScreenLineFromY(fpScr, s);
-    hBD = GetScreenLineFromY(fpScr, s + n - 1);
-    hTI = GetScreenLineFromY(fpScr, fpScr->bottom);
-    TI= LINE_MEM_LOCK(hTI);
-    hBI = TI->next;
-    LINE_MEM_UNLOCK(hTI);
+       TD = GetScreenLineFromY(pScr, s);
+       BD = GetScreenLineFromY(pScr, s + n - 1);
+       TI = GetScreenLineFromY(pScr, pScr->bottom);
+       BI = TI->next;
 
        /*
        Adjust the top of the screen and buffer if they will move.
        */
-       if (hTD == fpScr->screen_top) {
-           BD = LINE_MEM_LOCK(hBD);
-               if (fpScr->screen_top == fpScr->buffer_top)
-                       fpScr->buffer_top = BD->next;
-               fpScr->screen_top = BD->next;
-           LINE_MEM_UNLOCK(hBD);
+       if (TD == pScr->screen_top) {
+               if (pScr->screen_top == pScr->buffer_top)
+                       pScr->buffer_top = BD->next;
+               pScr->screen_top = BD->next;
        }
 
        /*
        Adjust the bottom of the screen and buffer if they will move.
        */
-       if (hTI == fpScr->screen_bottom) {
-               if (fpScr->screen_bottom == fpScr->buffer_bottom)
-                       fpScr->buffer_bottom = hBD;
-               fpScr->screen_bottom = hBD;
+       if (TI == pScr->screen_bottom) {
+               if (pScr->screen_bottom == pScr->buffer_bottom)
+                       pScr->buffer_bottom = BD;
+               pScr->screen_bottom = BD;
        }
 
-    if (hTI != hBD)
-        ScreenListMove(hTD, hBD, hTI, hBI);
+       if (TI != BD)
+               ScreenListMove(TD, BD, TI, BI);
 
        /*
        Clear the lines moved from the deleted area to the
        bottom of the scrolling area.
        */
-       hLine = hTI;
+       pLine = TI;
 
        for (idx = 0; idx < n; idx++) {
-               fpLine = LINE_MEM_LOCK(hLine);
-               hTemp = fpLine->next;
-               LINE_MEM_UNLOCK(hLine);
-               hLine = hTemp;
-               ScreenClearLine(fpScr, hLine);
+               pLine = pLine->next;
+               ScreenClearLine(pScr, pLine);
        }
 
-//     CheckScreen(fpScr);
+//     CheckScreen(pScr);
 
        /*
        Scroll the affected area on the screen.
        */
-    rc.left = 0;
-    rc.right = fpScr->width * fpScr->cxChar;
-    rc.top = s * fpScr->cyChar;
-    rc.bottom = (fpScr->bottom + 1) * fpScr->cyChar;
+       rc.left = 0;
+       rc.right = pScr->width * pScr->cxChar;
+       rc.top = s * pScr->cyChar;
+       rc.bottom = (pScr->bottom + 1) * pScr->cyChar;
 
-    hDC = GetDC(fpScr->hWnd);
+       hDC = GetDC(pScr->hWnd);
 
-    ScrollDC(hDC, 0, -fpScr->cyChar * n, &rc, &rc, NULL, NULL);
+       ScrollDC(hDC, 0, -pScr->cyChar * n, &rc, &rc, NULL, NULL);
 
-    PatBlt(hDC, 0, (fpScr->bottom - n + 1) * fpScr->cyChar,
-               fpScr->width * fpScr->cxChar, n * fpScr->cyChar, WHITENESS);
+       PatBlt(hDC, 0, (pScr->bottom - n + 1) * pScr->cyChar,
+               pScr->width * pScr->cxChar, n * pScr->cyChar, WHITENESS);
 
-    ReleaseDC(fpScr->hWnd, hDC);
+       ReleaseDC(pScr->hWnd, hDC);
 
 } /* ScreenDelLines */
 
 
-void ScreenInsertLine(SCREEN *fpScr, int s)
+void ScreenInsertLine(
+       SCREEN *pScr,
+       int s)
 {
-       ScreenInsLines(fpScr, 1, s);
+       ScreenInsLines(pScr, 1, s);
+
 } /* ScreenInsertLine */
 
 
-void ScreenInsLines(SCREEN *fpScr, int n, int s)
+void ScreenInsLines(
+       SCREEN *pScr,
+       int n,
+       int s)
 {
-    HSCREENLINE hLine;
-    HSCREENLINE hTemp;
-    HSCREENLINE hTI;
-    HSCREENLINE hBI;
-    HSCREENLINE hTD;
-    HSCREENLINE hBD;
-    SCREENLINE *fpLine;
-    SCREENLINE *BI;
+       SCREENLINE *TI;
+       SCREENLINE *BI;
        SCREENLINE *TD;
-    int idx;
-    RECT rc;
-    HDC hDC;
+       SCREENLINE *BD;
+       SCREENLINE *pLine;
+       int idx;
+       RECT rc;
+       HDC hDC;
  
 //    wsprintf(strTmp, "ScreenInsLine (n=%d s=%d)", n, s);
 //    OutputDebugString(strTmp);
 
-    if (s < 0)
-               s = fpScr->y;
+       if (s < 0)
+               s = pScr->y;
 
-    if (s + n - 1 > fpScr->bottom) 
-        n = fpScr->bottom - s + 1;
+       if (s + n - 1 > pScr->bottom) 
+               n = pScr->bottom - s + 1;
 
        /*
        Determine the top and bottom of the insert area.  Also determine
        the top and bottom of the area to be deleted and moved to the
        insert area.
        */
-    hBI = GetScreenLineFromY(fpScr, s);
-    BI = LINE_MEM_LOCK(hBI);
-    hTI = BI->prev;
-    hTD = GetScreenLineFromY(fpScr, fpScr->bottom - n + 1);
-    hBD = GetScreenLineFromY(fpScr, fpScr->bottom);
-    
+       BI = GetScreenLineFromY(pScr, s);
+       TI = BI->prev;
+       TD = GetScreenLineFromY(pScr, pScr->bottom - n + 1);
+       BD = GetScreenLineFromY(pScr, pScr->bottom);
+
        /*
        Adjust the top of the screen and buffer if they will move.
        */
-       if (hBI == fpScr->screen_top) {
-               if (fpScr->screen_top == fpScr->buffer_top)
-                       fpScr->buffer_top = hTD;
-               fpScr->screen_top = hTD;
+       if (BI == pScr->screen_top) {
+               if (pScr->screen_top == pScr->buffer_top)
+                       pScr->buffer_top = TD;
+               pScr->screen_top = TD;
        }
 
        /*
        Adjust the bottom of the screen and buffer if they will move.
        */
-       if (hBD == fpScr->screen_bottom) {
-           TD = LINE_MEM_LOCK(hTD);
-               if (fpScr->screen_bottom == fpScr->buffer_bottom)
-                       fpScr->buffer_bottom = TD->prev;
-               fpScr->screen_bottom = TD->prev;
-           LINE_MEM_UNLOCK(hTD);
+       if (BD == pScr->screen_bottom) {
+               if (pScr->screen_bottom == pScr->buffer_bottom)
+                       pScr->buffer_bottom = TD->prev;
+               pScr->screen_bottom = TD->prev;
        }
 
        /*
        Move lines from the bottom of the scrolling region to the insert area.
        */
-    if (hTD != hBI)
-        ScreenListMove(hTD,hBD,hTI,hBI);
+       if (TD != BI)
+               ScreenListMove(TD,BD,TI,BI);
 
        /*
        Clear the inserted lines
        */
-    hLine = GetScreenLineFromY(fpScr, s);
+       pLine = GetScreenLineFromY(pScr, s);
 
-    for (idx = 0; idx < n; idx++) {
-               ScreenClearLine(fpScr, hLine);
-        fpLine = LINE_MEM_LOCK(hLine);
-               hTemp = fpLine->next;
-        LINE_MEM_UNLOCK(hLine);
-               hLine = hTemp;
-    }
+       for (idx = 0; idx < n; idx++) {
+               ScreenClearLine(pScr, pLine);
+               pLine = pLine->next;
+       }
 
-//     CheckScreen(fpScr);
+//     CheckScreen(pScr);
 
        /*
        Scroll the affected area on the screen.
        */
-    rc.left = 0;
-    rc.right = fpScr->width * fpScr->cxChar;
-    rc.top = s * fpScr->cyChar;
-    rc.bottom = (fpScr->bottom + 1) * fpScr->cyChar;
+       rc.left = 0;
+       rc.right = pScr->width * pScr->cxChar;
+       rc.top = s * pScr->cyChar;
+       rc.bottom = (pScr->bottom + 1) * pScr->cyChar;
 
-    hDC = GetDC(fpScr->hWnd);
+       hDC = GetDC(pScr->hWnd);
 
-    ScrollDC(hDC, 0, fpScr->cyChar * n, &rc, &rc, NULL, NULL);
+       ScrollDC(hDC, 0, pScr->cyChar * n, &rc, &rc, NULL, NULL);
 
-    PatBlt(hDC, 0, s * fpScr->cyChar,
-               fpScr->width * fpScr->cxChar, n * fpScr->cyChar, WHITENESS);
+       PatBlt(hDC, 0, s * pScr->cyChar,
+               pScr->width * pScr->cxChar, n * pScr->cyChar, WHITENESS);
 
-    ReleaseDC(fpScr->hWnd, hDC);
+       ReleaseDC(pScr->hWnd, hDC);
 
 } /* ScreenInsLines */
 
 
-void ScreenIndex(SCREEN * fpScr)
+void ScreenIndex(
+       SCREEN * pScr)
 {
-    if(fpScr->y>=fpScr->bottom)
-        ScreenScroll(fpScr);
-    else
-        fpScr->y++;    
-}
+       if (pScr->y >= pScr->bottom)
+               ScreenScroll(pScr);
+       else
+               pScr->y++;    
+
+} /* ScreenIndex */
+
 
-void ScreenWrapNow(SCREEN *fpScr,int *xp,int *yp)
+void ScreenWrapNow(
+       SCREEN *pScr,
+       int *xp,
+       int *yp)
 {
-    if(fpScr->x > fpScr->width) {
-        fpScr->x=0;
-        ScreenIndex(fpScr);
-      } /* end if */
-    *xp=fpScr->x;
-    *yp=fpScr->y;
-}
-
-void ScreenEraseToEOL(SCREEN *fpScr)
+       if (pScr->x > pScr->width) {
+               pScr->x = 0;
+               ScreenIndex(pScr);
+       }
+
+       *xp = pScr->x;
+       *yp = pScr->y;
+
+} /* ScreenWrapNow */
+
+
+void ScreenEraseToEOL(
+       SCREEN *pScr)
 {
-    int x1=fpScr->x,y1=fpScr->y;
-    int x2=fpScr->width,y2=fpScr->y;
-    int n=(-1);
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    RECT rc;
-        
-    ScreenWrapNow(fpScr,&x1,&y1);
-    y2=y1;
+       int x1 = pScr->x;
+       int y1 = pScr->y;
+       int x2 = pScr->width;
+       int y2 = pScr->y;
+       int n = -1;
+       SCREENLINE *pScrLine;
+       RECT rc;
+               
+       ScreenWrapNow(pScr, &x1, &y1);
+
+       y2 = y1;
 //    wsprintf(strTmp,"[EraseEOL:%d]",y2);
 //    OutputDebugString(strTmp);
-    hgScrLine=GetScreenLineFromY(fpScr,y2);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-       memset(&fpScrLine->attrib[x1], ScreenClearAttrib, fpScr->width-x1+1);
-       memset(&fpScrLine->text[x1], ' ', fpScr->width-x1+1);
-    LINE_MEM_UNLOCK(hgScrLine);      
-    rc.left=x1*fpScr->cxChar;
-    rc.right=(fpScr->width*fpScr->cxChar);
-    rc.top=(fpScr->cyChar*y1);    
-    rc.bottom=(fpScr->cyChar*(y1+1));
-    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-    UpdateWindow(fpScr->hWnd);
-}
-
-void ScreenDelChars(SCREEN *fpScr, int n)
+       pScrLine = GetScreenLineFromY(pScr,y2);
+       memset(&pScrLine->attrib[x1], ScreenClearAttrib, pScr->width-x1+1);
+       memset(&pScrLine->text[x1], ' ', pScr->width - x1 + 1);
+       rc.left = x1 * pScr->cxChar;
+       rc.right = pScr->width * pScr->cxChar;
+       rc.top = pScr->cyChar * y1;
+       rc.bottom = pScr->cyChar * (y1 + 1);
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+       UpdateWindow(pScr->hWnd);
+
+} /* ScreenEraseToEOL */
+
+
+void ScreenDelChars(
+       SCREEN *pScr,
+       int n)
 {
-    int x = fpScr->x;
-       int y = fpScr->y;
-    int width;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    RECT rc;
+       int x = pScr->x;
+       int y = pScr->y;
+       int width;
+       SCREENLINE *pScrLine;
+       RECT rc;
        
-    hgScrLine = GetScreenLineFromY(fpScr, y);
-    fpScrLine = LINE_MEM_LOCK(hgScrLine);
+       pScrLine = GetScreenLineFromY(pScr, y);
 
-       width = fpScr->width - x - n;
+       width = pScr->width - x - n;
 
        if (width > 0) {
-               memmove(&fpScrLine->attrib[x], &fpScrLine->attrib[x + n], width);
-               memmove(&fpScrLine->text[x], &fpScrLine->text[x + n], width);
+               memmove(&pScrLine->attrib[x], &pScrLine->attrib[x + n], width);
+               memmove(&pScrLine->text[x], &pScrLine->text[x + n], width);
        }
 
-       memset(&fpScrLine->attrib[fpScr->width - n], ScreenClearAttrib, n);
-    memset(&fpScrLine->text[fpScr->width - n], ' ', n);
+       memset(&pScrLine->attrib[pScr->width - n], ScreenClearAttrib, n);
+       memset(&pScrLine->text[pScr->width - n], ' ', n);
        
-    LINE_MEM_UNLOCK(hgScrLine);
+       rc.left = x * pScr->cxChar;
+       rc.right = pScr->width * pScr->cxChar;
+       rc.top = pScr->cyChar * y;
+       rc.bottom = pScr->cyChar * (y + 1);
+
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
 
-    rc.left = x * fpScr->cxChar;
-    rc.right = fpScr->width * fpScr->cxChar;
-    rc.top = fpScr->cyChar * y;
-    rc.bottom = fpScr->cyChar * (y + 1);
+       UpdateWindow(pScr->hWnd);
 
-    InvalidateRect(fpScr->hWnd, &rc, TRUE);
+} /* ScreenDelChars */
 
-    UpdateWindow(fpScr->hWnd);
-}
 
-void ScreenRevIndex(SCREEN *fpScr)
+void ScreenRevIndex(
+       SCREEN *pScr)
 {
-    HSCREENLINE hgScrLine,hTopLine;
-    
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-    hTopLine=GetScreenLineFromY(fpScr,fpScr->top);
-    
-    if(hgScrLine==hTopLine) 
-        ScreenInsertLine(fpScr,fpScr->y);
-    else
-        fpScr->y--;
-}
-
-void ScreenEraseToBOL(SCREEN *fpScr)
+       SCREENLINE *pScrLine;
+       SCREENLINE *pTopLine;
+       
+       pScrLine = GetScreenLineFromY(pScr, pScr->y);
+       pTopLine = GetScreenLineFromY(pScr, pScr->top);
+
+       if(pScrLine == pTopLine) 
+               ScreenInsertLine(pScr, pScr->y);
+       else
+               pScr->y--;
+
+} /* ScreenRevIndex */
+
+
+void ScreenEraseToBOL(
+       SCREEN *pScr)
 {
-    int x1=0,y1=fpScr->y;
-    int x2=fpScr->x,y2=fpScr->y;
-    int n=(-1);
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-
-    ScreenWrapNow(fpScr,&x2,&y1);
-    y2=y1;
-       memset(fpScrLine->attrib, ScreenClearAttrib, x2);
-       memset(fpScrLine->text, ' ', x2);
-    LINE_MEM_UNLOCK(hgScrLine);      
-}
-
-void ScreenEraseLine(SCREEN *fpScr,int s)
+       int x1 = 0;
+       int y1 = pScr->y;
+       int x2 = pScr->x;
+       int y2 = pScr->y;
+       int n = -1;
+       SCREENLINE *pScrLine;
+
+       pScrLine = GetScreenLineFromY(pScr, pScr->y);
+
+       ScreenWrapNow(pScr, &x2, &y1);
+       y2 = y1;
+       memset(pScrLine->attrib, ScreenClearAttrib, x2);
+       memset(pScrLine->text, ' ', x2);
+
+} /* ScreenEraseToBOL */
+
+
+void ScreenEraseLine(
+       SCREEN *pScr,
+       int s)
 {
-    int x1=0,y1=s;
-    int x2=fpScr->width,y2=s;
-    int n=(-1);
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    RECT rc;
-    
-    if(s<0) {
-        ScreenWrapNow(fpScr,&x1,&y1);
-        s=y2=y1;
-        x1=0;
-      } /* end if */
-
-    hgScrLine=GetScreenLineFromY(fpScr,y1);
-    fpScrLine=LINE_MEM_LOCK(hgScrLine);
-       memset(fpScrLine->attrib, ScreenClearAttrib, fpScr->width);
-       memset(fpScrLine->text, ' ', fpScr->width);
-    LINE_MEM_UNLOCK(hgScrLine);      
-    rc.left=0;
-    rc.right=(fpScr->width*fpScr->cxChar);
-    rc.top=(fpScr->cyChar*y1);    
-    rc.bottom=(fpScr->cyChar*(y1+1));
-    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-}
-
-void ScreenEraseToEndOfScreen(SCREEN *fpScr)
+       int x1 = 0;
+       int y1 = s;
+       int x2 = pScr->width;
+       int y2 = s;
+       int n = -1;
+       SCREENLINE *pScrLine;
+       RECT rc;
+       
+       if (s < 0) {
+               ScreenWrapNow(pScr, &x1, &y1);
+               s = y2 = y1;
+               x1 = 0;
+       }
+
+       pScrLine = GetScreenLineFromY(pScr,y1);
+       memset(pScrLine->attrib, ScreenClearAttrib, pScr->width);
+       memset(pScrLine->text, ' ', pScr->width);
+       rc.left = 0;
+       rc.right = pScr->width * pScr->cxChar;
+       rc.top = pScr->cyChar * y1;
+       rc.bottom = pScr->cyChar * (y1+1);
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+       SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+
+} /* ScreenEraseLine */
+
+
+void ScreenEraseToEndOfScreen(
+       SCREEN *pScr)
 {
-    register int i;
-    int x1=0,y1=fpScr->y+1;
-    int x2=fpScr->width,y2=fpScr->height;
-    int n=(-1);
-
-    ScreenWrapNow(fpScr,&x1,&y1);
-    y1++;
-    x1=0;
-    i=y1;
-    ScreenEraseToEOL(fpScr);
-    while(i<fpScr->height) {
-        ScreenELO(fpScr,i);
-        ScreenEraseLine(fpScr,i);
-        i++;
-    } /* end while */
-}
-
-void ScreenRange(SCREEN *fpScr)               /* check and resolve range errors on x and y */
+       int i;
+       int x1 = 0;
+       int y1 = pScr->y+1;
+       int x2 = pScr->width;
+       int y2 = pScr->height;
+       int n = -1;
+
+       ScreenWrapNow(pScr, &x1, &y1);
+       y1++;
+       x1 = 0;
+       i = y1;
+       ScreenEraseToEOL(pScr);
+       while (i < pScr->height) {
+               ScreenELO(pScr, i);
+               ScreenEraseLine(pScr, i);
+               i++;
+       }
+
+} /* ScreenEraseToEndOfScreen */
+
+
+void ScreenRange(
+       SCREEN *pScr)
 {
-    int wrap=0;
-
-    if(fpScr->DECAWM)
-        wrap=1;
-    if(fpScr->x<0)
-        fpScr->x=0;
-    if(fpScr->x>(fpScr->width+wrap))
-        fpScr->x=fpScr->width+wrap;
-    if(fpScr->y<0)
-        fpScr->y=0;
-    if(fpScr->y>=fpScr->height)
-        fpScr->y=fpScr->height-1;
-}
-
-void ScreenAlign(SCREEN *fpScr)  /* vt100 alignment, fill screen with 'E's */
+       int wrap = 0;
+
+       if (pScr->DECAWM)
+               wrap = 1;
+
+       if (pScr->x < 0)
+               pScr->x = 0;
+
+       if (pScr->x > pScr->width + wrap)
+               pScr->x = pScr->width + wrap;
+
+       if (pScr->y < 0)
+               pScr->y = 0;
+
+       if (pScr->y >= pScr->height)
+               pScr->y = pScr->height - 1;
+
+} /* ScreenRange */
+
+
+void ScreenAlign(
+       SCREEN *pScr)  /* vt100 alignment, fill screen with 'E's */
 {
-    char *tt;
-    register int i,j;
-    HSCREENLINE hgScrLine,hgScrLineTmp;
-    SCREENLINE *fpScrLine;
-    
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->top);
-    ScreenEraseScreen(fpScr);        /* erase the screen */
-
-    for(j=0; j<fpScr->height; j++) {
-        fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-        tt=&fpScrLine->text[0];
-        for(i=0; i<=fpScr->width; i++)
-            *tt++='E';
-        hgScrLineTmp=fpScrLine->next;            
-        LINE_MEM_UNLOCK(hgScrLine);
-        hgScrLine=hgScrLineTmp;    
-        
-      } /* end for */
-    LINE_MEM_UNLOCK(hgScrLine);      
-}
-
-/* reset all the ANSI parameters back to the default state */
-void ScreenApClear(SCREEN *fpScr)
+       char *tt;
+       int i;
+       int j;
+       SCREENLINE *pScrLine;
+       
+       pScrLine = GetScreenLineFromY(pScr, pScr->top);
+       ScreenEraseScreen(pScr);
+
+       for(j = 0; j < pScr->height; j++) {
+               tt = &pScrLine->text[0];
+               for(i = 0; i <= pScr->width; i++)
+                       *tt++ = 'E';
+               pScrLine = pScrLine->next;
+       }
+
+} /* ScreenAlign */
+
+
+void ScreenApClear(
+       SCREEN *pScr)
 {
-    for(fpScr->parmptr=5; fpScr->parmptr>=0; fpScr->parmptr--)
-        fpScr->parms[fpScr->parmptr]=-1;
-    fpScr->parmptr=0;
-}
+       /*
+       reset all the ANSI parameters back to the default state
+       */
+       for(pScr->parmptr=5; pScr->parmptr>=0; pScr->parmptr--)
+               pScr->parms[pScr->parmptr] = -1;
 
-void ScreenSetOption(SCREEN *fpScr,int toggle) {
-//    int WindWidth=(fpScr->width - 1);
+       pScr->parmptr = 0;
 
-    switch(fpScr->parms[0]) {
-        case -2:
-            switch(fpScr->parms[1]) {
-                case 1:     /* set/reset cursor key mode */
-                    fpScr->DECCKM=toggle;
-                    break;
+} /* ScreenApClear */
 
-#ifdef NOT_SUPPORTED
-                case 2:     /* set/reset ANSI/vt52 mode */
-                    break;
-#endif
 
-                case 3:     /* set/reset column mode */
-                    fpScr->x=fpScr->y=0;      /* Clear the screen, mama! */
-                    ScreenEraseScreen(fpScr);
-                                       #if 0   /* removed for variable screen size */
-                           if(toggle)      /* 132 column mode */
-                           fpScr->width=fpScr->allwidth;
-                           else
-                           fpScr->width=79;
-                                       #endif
-                    break;
+void ScreenSetOption(
+       SCREEN *pScr,
+       int toggle)
+{
 
-#ifdef NOT_SUPPORTED
-                case 4:     /* set/reset scrolling mode */
-                case 5:     /* set/reset screen mode */
-                case 6:     /* set/rest origin mode */
-                    fpScr->DECORG = toggle;
-                    break;
-#endif
+       switch(pScr->parms[0]) {
 
-                case 7:     /* set/reset wrap mode */
-                    fpScr->DECAWM=toggle;
-//                    set_vtwrap(fpScrn,fpScr->DECAWM);     /* QAK - 7/27/90: added because resetting the virtual screen's wrapping flag doesn't reset telnet window's wrapping */
-                    break;
+       case -2:
+               switch(pScr->parms[1]) {
 
-#ifdef NOT_SUPPORTED
-                case 8:     /* set/reset autorepeat mode */
-                case 9:     /* set/reset interlace mode */
-                    break;
-#endif
+               case 1:     /* set/reset cursor key mode */
+                       pScr->DECCKM = toggle;
+                       break;
+
+               #ifdef NOT_SUPPORTED
+                       case 2:     /* set/reset ANSI/vt52 mode */
+                               break;
+               #endif
+
+               case 3:     /* set/reset column mode */
+                       pScr->x = pScr->y = 0;      /* Clear the screen, mama! */
+                       ScreenEraseScreen(pScr);
+                       #if 0   /* removed for variable screen size */
+                               if (toggle)      /* 132 column mode */
+                                       pScr->width = pScr->allwidth;
+                   else
+                           pScr->width = 79;
+                       #endif
+                       break;
+
+               #ifdef NOT_SUPPORTED
+                       case 4:     /* set/reset scrolling mode */
+                       case 5:     /* set/reset screen mode */
+                       case 6:     /* set/rest origin mode */
+                               pScr->DECORG = toggle;
+                               break;
+               #endif
+
+               case 7:         /* set/reset wrap mode */
+                       pScr->DECAWM = toggle;
+//          set_vtwrap(pScrn, fpScr->DECAWM);     /* QAK - 7/27/90: added because resetting the virtual screen's wrapping flag doesn't reset telnet window's wrapping */
+                       break;
+
+               #ifdef NOT_SUPPORTED
+                       case 8:     /* set/reset autorepeat mode */
+                       case 9:     /* set/reset interlace mode */
+                               break;
+               #endif
+
+               default:
+                       break;
+               } /* end switch */
+               break;
+
+       case 4:
+               pScr->IRM=toggle;
+               break;
 
-                default:
-                    break;
-            } /* end switch */
-            break;
+       default:
+               break;
 
-        case 4:
-            fpScr->IRM=toggle;
-            break;
+       } /* end switch */
 
-        default:
-            break;
+} /* ScreenSetOption */
 
-    } /* end switch */
-}
 
 #ifdef NOT_SUPPORTED
-void ScreenTab(SCREEN *fpScr)
-{
-    if(fpScr->x>=fpScr->width)
-        fpScr->x=fpScr->width;
-    fpScr->x++;
-    while((fpScr->tabs[fpScr->x] != 'x') && (fpScr->x < fpScr->width)) 
-        fpScr->x++;
-}
+       void ScreenTab(
+               SCREEN *pScr)
+       {
+               if (pScr->x> = pScr->width)
+                       pScr->x = pScr->width;
+               pScr->x++;
+               while (pScr->tabs[fpScr->x] != 'x' && pScr->x < pScr->width)
+                       pScr->x++;
+       } /* ScreenTab */
 #endif
 
-int ScreenInsChar(SCREEN *fpScr,int x)
+
+int ScreenInsChar(
+       SCREEN *pScr,
+       int x)
 {
-    int i;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    RECT rc;
-        
+       int i;
+       SCREENLINE *pScrLine;
+       RECT rc;
+               
 //    ScreenWrapNow(&i,&j);  /* JEM- Why is this here? comment out for now */
 
 //    OutputDebugString("OOPS-InsChar!");
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine==NULL) return (-1);
-
-    for(i=fpScr->width-x; i>=fpScr->x; i--) {
-        fpScrLine->text[x+i]=fpScrLine->text[i];
-        fpScrLine->attrib[x+i]=fpScrLine->attrib[i];
-    } /* end for */
-
-       memset(&fpScrLine->attrib[fpScr->x], ScreenClearAttrib, x);
-       memset(&fpScrLine->text[fpScr->x], ' ', x);
-
-    for(i=fpScr->x; i<fpScr->x+x; i++) {
-        fpScrLine->text[i]=' ';
-        fpScrLine->attrib[i]=ScreenClearAttrib;
-    } /* end for */
-    LINE_MEM_UNLOCK(hgScrLine);  
-    rc.left= (fpScr->cxChar*x);
-    rc.right= ((fpScr->cxChar*x)+(fpScr->cxChar*(x+fpScr->x)));
-    rc.top=(fpScr->cyChar*((fpScr->y)-1));    
-    rc.bottom=(fpScr->cyChar*(fpScr->y));
-    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-}
-
-void ScreenInsString(SCREEN *fpScr,int len,char *start)
+       pScrLine = GetScreenLineFromY(pScr, pScr->y);
+       if (pScrLine == NULL)
+               return(-1);
+
+       for(i = pScr->width - x; i >= pScr->x; i--) {
+               pScrLine->text[x+i] = pScrLine->text[i];
+               pScrLine->attrib[x+i] = pScrLine->attrib[i];
+       }
+
+       memset(&pScrLine->attrib[pScr->x], ScreenClearAttrib, x);
+       memset(&pScrLine->text[pScr->x], ' ', x);
+
+       for(i = pScr->x; i < pScr->x + x; i++) {
+               pScrLine->text[i] = ' ';
+               pScrLine->attrib[i] = ScreenClearAttrib;
+       }
+       rc.left = pScr->cxChar * x;
+       rc.right = (pScr->cxChar * x) + (pScr->cxChar * (x + pScr->x));
+       rc.top = pScr->cyChar * (pScr->y - 1);
+       rc.bottom = pScr->cyChar * pScr->y;
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+       SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+
+} /* ScreenInsChar */
+
+
+void ScreenInsString(
+       SCREEN *pScr,
+       int len,
+       char *start)
 {
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    int idx;
-    RECT rc;
-    
-    if(fpScr->VSIDC) return;  /* Call RSinsstring which does nothing? */
-    
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine==NULL) return;
-
-    for(idx=fpScr->x; idx<fpScr->x+len; idx++) {
-        fpScrLine->text[idx]=start[idx];
-        fpScrLine->attrib[idx]=fpScr->attrib;
-    } /* end for */
-    LINE_MEM_UNLOCK(hgScrLine);
-    rc.left= (fpScr->cxChar*fpScr->x);
-    rc.right= ((fpScr->cxChar*fpScr->x)+(fpScr->cxChar*(fpScr->x+len)));
-    rc.top=(fpScr->cyChar*(fpScr->y));    
-    rc.bottom=(fpScr->cyChar*(fpScr->y+1));    
-    
-    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-}
-
-void ScreenSaveCursor(SCREEN *fpScr)
+       SCREENLINE *pScrLine;
+       int idx;
+       RECT rc;
+       
+       if (pScr->VSIDC)
+               return;
+       
+       pScrLine = GetScreenLineFromY(pScr, pScr->y);
+       if (pScrLine == NULL)
+               return;
+
+       for(idx = pScr->x; idx < pScr->x + len; idx++) {
+               pScrLine->text[idx] = start[idx];
+               pScrLine->attrib[idx] = pScr->attrib;
+       }
+       rc.left = pScr->cxChar * pScr->x;
+       rc.right = pScr->cxChar * pScr->x + pScr->cxChar * (pScr->x + len);
+       rc.top = pScr->cyChar * pScr->y;
+       rc.bottom = pScr->cyChar * (pScr->y + 1);
+
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+       SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+
+} /* ScreenInsString */
+
+
+void ScreenSaveCursor(
+       SCREEN *pScr)
 {
-    fpScr->Px=fpScr->x;
-    fpScr->Py=fpScr->y;
-    fpScr->Pattrib=fpScr->attrib;
-}
+       pScr->Px = pScr->x;
+       pScr->Py = pScr->y;
+       pScr->Pattrib = pScr->attrib;
 
-void ScreenRestoreCursor(SCREEN *fpScr)
+} /* ScreenSaveCursor */
+
+
+void ScreenRestoreCursor(
+       SCREEN *pScr)
 {
-    fpScr->x=fpScr->Px;
-    fpScr->y=fpScr->Py;
-    ScreenRange(fpScr);
-}
+       pScr->x = pScr->Px;
+       pScr->y = pScr->Py;
+       ScreenRange(pScr);
+
+} /* ScreenRestoreCursor */
+
 
-void ScreenDraw(SCREEN *fpScr,int x,int y,int a,int len,char *c)
+void ScreenDraw(
+       SCREEN *pScr,
+       int x,
+       int y,
+       int a,
+       int len,
+       char *c)
 {
        int idx;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    RECT rc;
-
-    hgScrLine=GetScreenLineFromY(fpScr,y);  
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine==NULL) {
-        OutputDebugString("fpScrLine==NULL");
-        return;
-    }
-    
-    for(idx=x; idx<(x+len); idx++) {
-        fpScrLine->text[idx]=c[idx-x];
-        fpScrLine->attrib[idx-x]=a;
-    } 
-    LINE_MEM_UNLOCK(hgScrLine);
-
-       rc.left= (fpScr->cxChar*x);
-    rc.right= (fpScr->cxChar*(x+len));
-       rc.top=(fpScr->cyChar*(fpScr->y));    
-    rc.bottom=(fpScr->cyChar*((fpScr->y)+1));
-       InvalidateRect(fpScr->hWnd,&rc,TRUE);    
-    SendMessage(fpScr->hWnd,WM_PAINT,NULL,NULL);
-}
+       SCREENLINE *pScrLine;
+       RECT rc;
+
+       pScrLine = GetScreenLineFromY(pScr, y);  
+       assert(pScrLine != NULL);
+       
+       for(idx = x; idx < x + len; idx++) {
+               pScrLine->text[idx] = c[idx - x];
+               pScrLine->attrib[idx - x] = a;
+       }
+
+       rc.left = pScr->cxChar * x;
+       rc.right = pScr->cxChar * (x + len);
+       rc.top = pScr->cyChar * pScr->y;
+       rc.bottom = pScr->cyChar * (pScr->y + 1);
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+       SendMessage(pScr->hWnd, WM_PAINT, NULL, NULL);
+
+} /* ScreenDraw */
+
 
 #ifdef _DEBUG
 
-       BOOL CheckScreen(SCREEN *fpScr)
+       BOOL CheckScreen(
+               SCREEN *pScr)
        {
-               HSCREENLINE hLine;
-               HSCREENLINE hLinePrev;
-               SCREENLINE *fpLine;
+               SCREENLINE *pLinePrev;
+               SCREENLINE *pLine;
                int nscreen = 0;
                int nbuffer = 0;
                int topline = 0;
@@ -769,9 +831,9 @@ void ScreenDraw(SCREEN *fpScr,int x,int y,int a,int len,char *c)
                BOOL bBottom;
                BOOL bOK;
 
-               hLine = fpScr->buffer_top;
+               pLine = pScr->buffer_top;
 
-               if (hLine == NULL) {
+               if (pLine == NULL) {
                        OutputDebugString("CheckScreen: buffer_top invalid");
                        MessageBox(NULL, "buffer_top invalid", "CheckScreen", MB_OK);
                        return(FALSE);
@@ -779,32 +841,28 @@ void ScreenDraw(SCREEN *fpScr,int x,int y,int a,int len,char *c)
 
                bBottom = FALSE;
                while (TRUE) {
-                       hLinePrev = hLine;
-                       if (nscreen > 0 || hLine == fpScr->screen_top)
+                       pLinePrev = pLine;
+                       if (nscreen > 0 || pLine == pScr->screen_top)
                                if (!bBottom)
                                        nscreen++;
                        nbuffer++;
-                       if (hLine == fpScr->screen_top)
+                       if (pLine == pScr->screen_top)
                                topline = nbuffer - 1;
-                       if (hLine == fpScr->screen_bottom)
+                       if (pLine == pScr->screen_bottom)
                                bBottom = TRUE;
-                       fpLine = LINE_MEM_LOCK(hLine);
-                       hLine = fpLine->next;
-                       LINE_MEM_UNLOCK(hLine);
-                       if (hLine == NULL)
+                       pLine = pLine->next;
+                       if (pLine == NULL)
                                break;
-                       fpLine = LINE_MEM_LOCK(hLine);
-                       if (fpLine->prev != hLinePrev) {
+                       if (pLine->prev != pLinePrev) {
                                wsprintf(buf,
                                        "Previous ptr of line %d does not match next ptr of line %d",
                                        nbuffer, nbuffer - 1);
                                OutputDebugString(buf);
                                MessageBox(NULL, buf, "CheckScreen", MB_OK);
                        }
-                       LINE_MEM_UNLOCK(hLine);
                }
 
-               if (hLinePrev == fpScr->buffer_bottom && nscreen == fpScr->height)
+               if (pLinePrev == pScr->buffer_bottom && nscreen == pScr->height)
                        bOK = TRUE;
                else {
                        OutputDebugString("CheckScreen: Invalid number of lines on screen");
@@ -824,14 +882,15 @@ void ScreenDraw(SCREEN *fpScr,int x,int y,int a,int len,char *c)
                        "Actual buffer lines = %d\n"
                        "Actual screen lines = %d\n"
                        "Bottom of buffer is %s",
-                       fpScr->width, fpScr->height, fpScr->maxlines, fpScr->numlines,
-                       fpScr->x, fpScr->y, fpScr->top, fpScr->bottom,
+                       pScr->width, pScr->height, pScr->maxlines, pScr->numlines,
+                       pScr->x, pScr->y, pScr->top, pScr->bottom,
                        topline, nbuffer, nscreen,
-                       (hLinePrev == fpScr->buffer_bottom) ? "valid" : "invalid");
+                       (pLinePrev == pScr->buffer_bottom) ? "valid" : "invalid");
 
                MessageBox(NULL, buf, "CheckScreen", MB_OK);
 
                return(bOK);
-       }
+
+       } /* CheckScreen */
 
 #endif
index 6842b75c9e219433690952b4255eff6fec1e19f7..75d90d3a7ca27d0fe85e64680789718475029c88 100644 (file)
+/* screen.c */
+
 #include <windows.h>
 #include <commdlg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 #include "telnet.h"
 #include "ini.h"
 
 extern char *cInvertedArray;
-HSCREEN ScreenList;
-HINSTANCE hInst;
-HDC hDC;
-char gszAllocErrorMsg[]="Error Allocating Memory!";
-char gszLockErrorMsg[]="Error Locking Memory!";
-char gszLoadStrFail[]="LoadString failed!";
-
-int bDoubleClick=FALSE;
-extern LOGFONT lf;
-extern HFONT hFont;
 extern int bMouseDown;
 extern int bSelection;
 
-char szScreenClass[]="ScreenWClass";
-char szScreenMenu[]="ScreenMenu";
-
-OFSTRUCT ofFile;
-HFILE fh;
-
-#ifdef WINMEM
-CATCHBUF EndRtn;              /* error return buffer (required by WinMem)*/
-#endif
-
-//#define FILE_DEBUG
-
-void ScreenInit(HANDLE hInstance) {
-
-    WNDCLASS    wc;
-
-    hInst=hInstance;
-    
-//    wsprintf(strTmp,"hInst= %d \r\n",hInst);
-//    OutputDebugString(strTmp);
-    
-    ScreenList=NULL;
-
-    wc.style = CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_GLOBALCLASS;       /* Class style(s).                    */
-    wc.lpfnWndProc = ScreenWndProc;         /* Function to retrieve messages for  */
-                                            /* windows of this class.             */
-    wc.cbClsExtra = 0;                      /* No per-class extra data.           */
-    wc.cbWndExtra = sizeof(HGLOBAL);        /* Only extra data is handle to screen*/
-    wc.hInstance = hInstance;               /* Application that owns the class.   */
-    wc.hIcon = LoadIcon(hInstance, "TERMINAL");
-    wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
-    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
-    wc.lpszMenuName =  szScreenMenu;        /* Name of menu resource in .RC file. */
-    wc.lpszClassName = szScreenClass;      /* Name used in call to CreateWindow. */
-
-    /* Register the window class and return success/failure code. */
-    if (!RegisterClass(&wc))
-       MessageBox(NULL,"Couldn't register Class!",NULL,MB_OK);
-}
-
-int GetNewScreen(void) {
-    HGLOBAL ghScr;
-    SCREEN *fpScr, *fpTmp, *fpTmp2;
-    static int id=0;
-
-    if (ScreenList==NULL) {
-        ghScr = GlobalAlloc(GHND,sizeof(SCREEN));
-        if (ghScr==NULL) return -1;
-        fpScr = (SCREEN *)GlobalLock(ghScr);
-        if (fpScr==NULL) return -1;
-        fpScr->next=NULL;
-        fpScr->prev=NULL;
-        GlobalUnlock(ghScr);
-        ScreenList=ghScr;
-        return(id++);
-    }
-       else {
-        ghScr = GlobalAlloc(GHND,sizeof(SCREEN));
-        if (ghScr==NULL) return -1;
-        fpScr = (SCREEN *)GlobalLock(ghScr);
-        if (fpScr==NULL) return -1;
-        fpScr->next=ScreenList;
-        fpTmp = (SCREEN *)GlobalLock(ScreenList);
-               if (fpTmp != NULL) {
-            if (fpTmp->next==NULL) {
-                fpScr->next=ScreenList;
-                fpScr->prev=ScreenList;
-                fpTmp->next=ghScr;
-                fpTmp->prev=ghScr;
-            } else {
-                fpScr->prev=fpTmp->prev;
-                   fpTmp2 = (SCREEN *)GlobalLock(fpTmp->prev);
-                           if (fpTmp2 != NULL)
-                       fpTmp2->next=ghScr;
-                GlobalUnlock(fpTmp->prev);
-                   fpTmp->prev=ghScr;
-            }
-        }
-        GlobalUnlock(fpScr->next);
-        GlobalUnlock(ghScr);
-        ScreenList=ghScr;
-        return(id++);
-    }
-}
-
-HSCREENLINE ScreenNewLine(void) 
+static SCREEN *ScreenList;
+static HINSTANCE hInst;
+static char szScreenClass[] = "ScreenWClass";
+static char szScreenMenu[] = "ScreenMenu";
+
+void ScreenInit(
+       HINSTANCE hInstance)
 {
+       BOOL b;
+       WNDCLASS wc;
 
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
+       hInst = hInstance;
+       
+       ScreenList = NULL;
 
-    hgScrLine=LINE_MEM_ALLOC(sizeof(SCREENLINE)+2*MAX_LINE_WIDTH);
-    if (hgScrLine==NULL)
-               return (NULL);
-    fpScrLine=LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine==NULL)
+       wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; /* Class style(s) */
+       wc.lpfnWndProc = ScreenWndProc;
+       wc.cbClsExtra = 0;
+       wc.cbWndExtra = sizeof(long);
+       wc.hInstance = hInstance;
+       wc.hIcon = LoadIcon(hInstance, "TERMINAL");
+       wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
+       wc.hbrBackground = GetStockObject(WHITE_BRUSH);
+       wc.lpszMenuName =  szScreenMenu;
+       wc.lpszClassName = szScreenClass;
+
+       b = RegisterClass(&wc);
+       assert(b);
+
+} /* ScreenInit */
+
+
+void SetScreenInstance(
+       HINSTANCE hInstance)
+{
+       hInst = hInstance;
+
+} /* SetScreenInstance */
+
+
+int GetNewScreen(void)
+{
+       SCREEN *pScr;
+       static int id = 0;
+
+       pScr = (SCREEN *) calloc(sizeof(SCREEN), 1);
+       if (pScr == NULL)
+               return(-1);
+
+       if (ScreenList == NULL) {
+               pScr->next = NULL;
+               pScr->prev = NULL;
+       }
+       else {
+               if (ScreenList->next == NULL) {
+                       ScreenList->next = ScreenList;
+                       ScreenList->prev = ScreenList;
+               }
+               pScr->next = ScreenList;
+               pScr->prev = ScreenList->prev;
+               ScreenList->prev->next = pScr;
+               ScreenList->prev = pScr;
+       }
+
+       ScreenList = pScr;
+       return(id++);
+
+} /* GetNewScreen */
+
+
+SCREENLINE *ScreenNewLine(void) 
+{
+       SCREENLINE *pScrLine;
+
+       pScrLine = calloc(sizeof(SCREENLINE) + 2*MAX_LINE_WIDTH, 1);
+       if (pScrLine == NULL)
                return (NULL);
-       memset(fpScrLine,0,sizeof(SCREENLINE)+2*MAX_LINE_WIDTH);
-       fpScrLine->text=&fpScrLine->buffer[0];
-       fpScrLine->attrib=&fpScrLine->buffer[MAX_LINE_WIDTH];
-    LINE_MEM_UNLOCK(hgScrLine);
-    return(hgScrLine);
-}  
-
-static void MakeWindowTitle(char *host, int width, int height, char *title, int nchars)
+       pScrLine->text = &pScrLine->buffer[0];
+       pScrLine->attrib = &pScrLine->buffer[MAX_LINE_WIDTH];
+       return(pScrLine);
+
+} /* ScreenNewLine */
+
+
+static void MakeWindowTitle(
+       char *host,
+       int width,
+       int height,
+       char *title,
+       int nchars)
 {
        char buf[128];
        int hlen;
@@ -143,463 +121,414 @@ static void MakeWindowTitle(char *host, int width, int height, char *title, int
                return;
 
        strcat(title, buf);
-}
-
-HSCREEN InitNewScreen(CONFIG *Config) {
-    TEXTMETRIC  tm;
-    HMENU hMenu=NULL;
-    SCREEN *scr=NULL;
-    HSCREENLINE hgScrLine;
-    HSCREENLINE hgScrLineLast;
-    SCREENLINE *fpScrLine;
-    SCREENLINE *fpScrLineLast;
-    int id,idx=0;
-       HGLOBAL h;
+
+} /* MakeWindowTitle */
+
+
+SCREEN *InitNewScreen(
+       CONFIG *Config)
+{
+       TEXTMETRIC tm;
+       HMENU hMenu = NULL;
+       SCREEN *scr = NULL;
+       SCREENLINE *pScrLine;
+       SCREENLINE *pScrLineLast;
+       int id;
+       int idx = 0;
        char title[128];
+       HDC hDC;
+       HFONT hFont;
 
-    id=GetNewScreen();
-    if (id == -1) return(0);
-    scr=(SCREEN *) GlobalLock(ScreenList);
-    if (scr==NULL) OutputDebugString("Scr is NULL!\r\n");
-               
-    hMenu = LoadMenu(hInst,szScreenMenu);
-    if (hMenu==NULL) OutputDebugString("hMenu is NULL! \r\n");
-    
-       scr->title=Config->title;
-       MakeWindowTitle(Config->title,Config->width,Config->height,title,sizeof(title));
-
-    scr->hWnd = CreateWindow((char *)szScreenClass,title,WS_OVERLAPPEDWINDOW|WS_VSCROLL,
-        CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,hInst,NULL);
-    
-       if (!(scr->hWnd)) {
-               OutputDebugString("Couldn't Create Window!! \r\n");
-               return(0); 
-       }
-    scr->hwndTel=Config->hwndTel;  /* save HWND of calling window */
-       
-       if (Config->backspace) {
-        CheckMenuItem(hMenu,IDM_BACKSPACE,MF_CHECKED);
-        CheckMenuItem(hMenu,IDM_DELETE,MF_UNCHECKED);
-    }
-       else {
-        CheckMenuItem(hMenu,IDM_BACKSPACE,MF_UNCHECKED);
-        CheckMenuItem(hMenu,IDM_DELETE,MF_CHECKED);
-    }    
-    SetWindowWord(scr->hWnd,SCREEN_HANDLE,(WORD)ScreenList);
-    hDC = GetDC(scr->hWnd);
-
-    scr->lf.lfPitchAndFamily=FIXED_PITCH;
-    GetPrivateProfileString(INI_FONT,"FaceName","Courier",scr->lf.lfFaceName,
-        LF_FACESIZE,TELNET_INI);
-    scr->lf.lfHeight=(int)GetPrivateProfileInt(INI_FONT,"Height",0,TELNET_INI);
-    scr->lf.lfWidth=(int)GetPrivateProfileInt(INI_FONT,"Width",0,TELNET_INI);
-    scr->lf.lfPitchAndFamily=(BYTE)GetPrivateProfileInt(INI_FONT,"PitchAndFamily",0,TELNET_INI);
-    scr->lf.lfCharSet=(BYTE)GetPrivateProfileInt(INI_FONT,"CharSet",0,TELNET_INI);
-    scr->lf.lfEscapement=(BYTE)GetPrivateProfileInt(INI_FONT,"Escapement",0,TELNET_INI);
-    scr->lf.lfQuality=PROOF_QUALITY;
-    scr->ghSelectedFont = CreateFontIndirect((LPLOGFONT)&(scr->lf));
-    
-    SelectObject(hDC,scr->ghSelectedFont);
-                
-    GetTextMetrics(hDC,(LPTEXTMETRIC)&tm);
-    scr->cxChar = tm.tmAveCharWidth;
-    scr->cyChar = tm.tmHeight + tm.tmExternalLeading;
-
-    ReleaseDC(scr->hWnd,hDC);
-    scr->width=Config->width;
-    scr->height=Config->height;
-    scr->ID=id;
-    scr->x=0;    
-    scr->y=0;
-    scr->Oldx=0;
-    scr->Oldy=0;
-    scr->attrib=0;
-    scr->DECAWM=1;
-    scr->top=0;
-    scr->bottom=scr->height-1;
-    scr->parmptr=0;
-    scr->escflg=0;
-    scr->bAlert=FALSE;
-    scr->numlines=0;
-    scr->maxlines=150;
-
-       h=GlobalAlloc(GHND,scr->width*scr->height);
-       if (h==NULL)
+       id = GetNewScreen();
+       if (id == -1)
                return(0);
-       cInvertedArray=GlobalLock(h);
 
-    hgScrLineLast=ScreenNewLine();
-    scr->screen_top=scr->buffer_top=hgScrLineLast;
-       hgScrLine=hgScrLineLast;
+       scr = ScreenList;
+       assert(scr != NULL);
 
-    for (idx=0; idx<scr->height-1; idx++) {
-        hgScrLine=ScreenNewLine();
-        fpScrLine=LINE_MEM_LOCK(hgScrLine);
-               if (fpScrLine == NULL)
-                       return(NULL);
-        fpScrLine->prev=hgScrLineLast;
-        LINE_MEM_UNLOCK(hgScrLine);
+       hMenu = LoadMenu(hInst, szScreenMenu);
+       assert(hMenu != NULL);
 
-        fpScrLineLast=LINE_MEM_LOCK(hgScrLineLast);
-               if (fpScrLineLast == NULL)
-                       return(NULL);
-        fpScrLineLast->next=hgScrLine;
-        LINE_MEM_UNLOCK(hgScrLineLast);
+       scr->title = Config->title;
+       MakeWindowTitle(Config->title, Config->width, Config->height, title, sizeof(title));
 
-        hgScrLineLast=hgScrLine;
-    }
+       scr->hwndTel = Config->hwndTel;  /* save HWND of calling window */
+       
+       if (Config->backspace) {
+               CheckMenuItem(hMenu, IDM_BACKSPACE, MF_CHECKED);
+               CheckMenuItem(hMenu, IDM_DELETE, MF_UNCHECKED);
+       }
+       else {
+               CheckMenuItem(hMenu, IDM_BACKSPACE, MF_UNCHECKED);
+               CheckMenuItem(hMenu, IDM_DELETE, MF_CHECKED);
+       }
 
-    scr->screen_bottom=scr->buffer_bottom=hgScrLine;
+       hDC = GetDC(NULL);
+       assert(hDC != NULL);
+
+       scr->lf.lfPitchAndFamily = FIXED_PITCH;
+       GetPrivateProfileString(INI_FONT, "FaceName", "Courier", scr->lf.
+               lfFaceName,     LF_FACESIZE, TELNET_INI);
+       scr->lf.lfHeight = (int) GetPrivateProfileInt(INI_FONT, "Height", 0, TELNET_INI);
+       scr->lf.lfWidth = (int) GetPrivateProfileInt(INI_FONT, "Width", 0, TELNET_INI);
+       scr->lf.lfPitchAndFamily = (BYTE) GetPrivateProfileInt(INI_FONT, "PitchAndFamily", 0, TELNET_INI);
+       scr->lf.lfCharSet = (BYTE) GetPrivateProfileInt(INI_FONT, "CharSet", 0, TELNET_INI);
+       scr->lf.lfEscapement = (BYTE) GetPrivateProfileInt(INI_FONT, "Escapement", 0, TELNET_INI);
+       scr->lf.lfQuality = PROOF_QUALITY;
+       scr->hSelectedFont = CreateFontIndirect((LPLOGFONT) &(scr->lf));
+       hFont = SelectObject(hDC, scr->hSelectedFont);
+       GetTextMetrics(hDC, (LPTEXTMETRIC) &tm);
+       SelectObject(hDC, hFont);
+       scr->cxChar = tm.tmAveCharWidth;
+       scr->cyChar = tm.tmHeight + tm.tmExternalLeading;
+
+       ReleaseDC(NULL, hDC);
+
+       scr->width = Config->width;
+       scr->height = Config->height;
+       scr->ID = id;
+       scr->x = 0;    
+       scr->y = 0;
+       scr->Oldx = 0;
+       scr->Oldy = 0;
+       scr->attrib = 0;
+       scr->DECAWM = 1;
+       scr->top = 0;
+       scr->bottom = scr->height-1;
+       scr->parmptr = 0;
+       scr->escflg = 0;
+       scr->bAlert = FALSE;
+       scr->numlines = 0;
+       scr->maxlines = 150;
+
+       cInvertedArray = calloc(scr->width * scr->height, 1);
+
+       pScrLineLast = ScreenNewLine();
+       if (pScrLineLast == NULL)
+               return(NULL);
+       scr->screen_top = scr->buffer_top = pScrLineLast;
+
+       for (idx = 0; idx < scr->height - 1; idx++) {
+               pScrLine = ScreenNewLine();
+               if (pScrLine == NULL)
+                       return(NULL);
+               pScrLine->prev = pScrLineLast;
+               pScrLineLast->next = pScrLine;
+               pScrLineLast = pScrLine;
+       }
+
+       scr->screen_bottom = scr->buffer_bottom = pScrLine;
 
-    SetWindowPos(scr->hWnd,NULL,0,0,scr->cxChar * scr->width + FRAME_WIDTH,
-         scr->cyChar * scr->height + FRAME_HEIGHT, SWP_NOMOVE|SWP_NOZORDER);
+       scr->hWnd = CreateWindow(szScreenClass, title, WS_OVERLAPPEDWINDOW | WS_VSCROLL,
+               CW_USEDEFAULT, CW_USEDEFAULT,
+               scr->cxChar * scr->width + FRAME_WIDTH,
+               scr->cyChar * scr->height + FRAME_HEIGHT,
+               NULL, hMenu, hInst, scr);
+       assert(scr->hWnd != NULL);
+       
+       ShowWindow(scr->hWnd, SW_SHOW);
 
        CreateCaret(scr->hWnd, NULL, scr->cxChar, 2);
-       SetCaretPos(scr->x*scr->cxChar, (scr->y+1)*scr->cyChar);
+       SetCaretPos(scr->x*scr->cxChar, (scr->y+1) * scr->cyChar);
        ShowCaret(scr->hWnd);
 
-    GlobalUnlock(ScreenList);
-    return(ScreenList);
-}
-
-void DeleteTopLine(SCREEN *fpScr) {
-    HSCREENLINE hsTop;
-    SCREENLINE *fpScrLine;
-    
-    fpScrLine=(SCREENLINE *) LINE_MEM_LOCK(fpScr->buffer_top);
-    if (fpScrLine==NULL) OutputDebugString("Hosed in DeleteTopLine.\r\n");
-    hsTop=fpScrLine->next;
-    LINE_MEM_FREE(fpScr->buffer_top);
-    fpScr->buffer_top=hsTop;
-    fpScrLine=(SCREENLINE *) LINE_MEM_LOCK(fpScr->buffer_top);
-    if (fpScrLine==NULL) OutputDebugString("Hosed in DeleteTopLine.\r\n");
-    fpScrLine->prev=NULL;
-    LINE_MEM_UNLOCK(fpScr->buffer_top);
-    fpScr->numlines--;
-}
-
-
-static void SetScreenScrollBar(SCREEN *fpScr)
+       return(ScreenList);
+
+} /* InitNewScreen */
+
+
+void DeleteTopLine(
+       SCREEN *pScr)
 {
-       if (fpScr->numlines <= 0) {
-               SetScrollRange(fpScr->hWnd, SB_VERT, 0, 100, FALSE);
-               SetScrollPos(fpScr->hWnd, SB_VERT, 0, TRUE);
-               EnableScrollBar(fpScr->hWnd, SB_VERT, ESB_DISABLE_BOTH);
+       assert(pScr->buffer_top != NULL);
+
+       pScr->buffer_top = pScr->buffer_top->next;
+       assert(pScr->buffer_top != NULL);
+
+       pScr->buffer_top->prev = NULL;
+
+       pScr->numlines--;
+
+} /* DeleteTopLine */
+
+
+static void SetScreenScrollBar(
+       SCREEN *pScr)
+{
+       if (pScr->numlines <= 0) {
+               SetScrollRange(pScr->hWnd, SB_VERT, 0, 100, FALSE);
+               SetScrollPos(pScr->hWnd, SB_VERT, 0, TRUE);
+               EnableScrollBar(pScr->hWnd, SB_VERT, ESB_DISABLE_BOTH);
        }
        else {
-               SetScrollRange(fpScr->hWnd, SB_VERT, 0, fpScr->numlines, FALSE);
-               SetScrollPos(fpScr->hWnd, SB_VERT, fpScr->numlines, TRUE);
-               EnableScrollBar(fpScr->hWnd, SB_VERT, ESB_ENABLE_BOTH);
+               SetScrollRange(pScr->hWnd, SB_VERT, 0, pScr->numlines, FALSE);
+               SetScrollPos(pScr->hWnd, SB_VERT, pScr->numlines, TRUE);
+               EnableScrollBar(pScr->hWnd, SB_VERT, ESB_ENABLE_BOTH);
        }
+
 } /* SetScreenScrollBar */
 
 
-int ScreenScroll(SCREEN *fpScr)
+int ScreenScroll(
+       SCREEN *pScr)
 {
-    HSCREENLINE hgScrLine;
-    HSCREENLINE hScrollTop;
-    HSCREENLINE hScrollBottom;
-    HSCREENLINE hPrev;
-    HSCREENLINE hNext;
-    SCREENLINE *fpScrLine;
-    SCREENLINE *fpPrev;
-    SCREENLINE *fpNext;
-    SCREENLINE *fpScrollTop;
-    SCREENLINE *fpScrollBottom;
-    BOOL bFullScreen = TRUE;
-    HDC hDC;
-    RECT rc;
-
-    Edit_ClearSelection(fpScr);
-
-    hScrollTop = (HSCREENLINE) GetScreenLineFromY(fpScr, fpScr->top);
-
-    hScrollBottom = (HSCREENLINE) GetScreenLineFromY(fpScr, fpScr->bottom);
-
-    if (hScrollTop != fpScr->screen_top) {
+       SCREENLINE *pScrLine;
+       SCREENLINE *pPrev;
+       SCREENLINE *pNext;
+       SCREENLINE *pScrollTop;
+       SCREENLINE *pScrollBottom;
+       BOOL bFullScreen = TRUE;
+       HDC hDC;
+       RECT rc;
+
+       Edit_ClearSelection(pScr);
+
+       pScrollTop = GetScreenLineFromY(pScr, pScr->top);
+
+       pScrollBottom = GetScreenLineFromY(pScr, pScr->bottom);
+
+       if (pScrollTop != pScr->screen_top) {
                bFullScreen = FALSE;
-        rc.left = 0;
-        rc.right = fpScr->cxChar * fpScr->width;
-        rc.top = fpScr->cyChar * (fpScr->top);
-        rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-
-           fpScrollTop = LINE_MEM_LOCK(hScrollTop);
-        hNext = fpScrollTop->next;
-        hPrev = fpScrollTop->prev;
-               LINE_MEM_UNLOCK(hScrollTop);
-
-        fpPrev = LINE_MEM_LOCK(hPrev);
-        fpPrev->next = hNext;        
-        fpNext = LINE_MEM_LOCK(hNext);
-        fpNext->prev = hPrev;
-        LINE_MEM_UNLOCK(hPrev);
-               LINE_MEM_UNLOCK(hNext);
-
-               hgScrLine = hScrollTop;
-               ScreenClearLine(fpScr, hgScrLine);
-    }
+               rc.left = 0;
+               rc.right = pScr->cxChar * pScr->width;
+               rc.top = pScr->cyChar * (pScr->top);
+               rc.bottom = pScr->cyChar * (pScr->bottom+1);
+
+               pNext = pScrollTop->next;
+               pPrev = pScrollTop->prev;
+
+               pPrev->next = pNext;        
+               pNext->prev = pPrev;
+
+               pScrLine = pScrollTop;
+               ScreenClearLine(pScr, pScrLine);
+       }
        else {
-               fpScr->numlines++;                
-               hgScrLine = ScreenNewLine(); 
-               if (hgScrLine == NULL)
+               pScr->numlines++;                
+               pScrLine = ScreenNewLine(); 
+               if (pScrLine == NULL)
                        return(0);
-               fpScrollTop = LINE_MEM_LOCK(hScrollTop);
-               fpScr->screen_top = fpScrollTop->next;
-               LINE_MEM_UNLOCK(hScrollTop);
-    }    
+               pScr->screen_top = pScrollTop->next;
+       }    
 
-    fpScrLine= LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine == NULL)
+       if (pScrLine == NULL)
                return(0);
 
-       fpScrollBottom = LINE_MEM_LOCK(hScrollBottom);
-    hNext = fpScrollBottom->next;
-       fpScrollBottom->next = hgScrLine;
-       LINE_MEM_UNLOCK(hScrollBottom);
-       fpScrLine->next = hNext;
-       fpScrLine->prev = hScrollBottom;
-       if (hNext != NULL) {
-           fpNext = LINE_MEM_LOCK(hNext);
-           fpNext->prev = hgScrLine;
-               LINE_MEM_UNLOCK(hNext);
-       }
-
-       LINE_MEM_UNLOCK(hgScrLine);
+       pNext = pScrollBottom->next;
+       pScrollBottom->next = pScrLine;
+       pScrLine->next = pNext;
+       pScrLine->prev = pScrollBottom;
+       if (pNext != NULL)
+           pNext->prev = pScrLine;
 
-    if (hScrollBottom != fpScr->screen_bottom) {
+       if (pScrollBottom != pScr->screen_bottom) {
                bFullScreen = FALSE;
-        rc.left = 0;
-        rc.right = fpScr->cxChar * fpScr->width;
-        rc.top = fpScr->cyChar * fpScr->top;
-        rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-    }
+               rc.left = 0;
+               rc.right = pScr->cxChar * pScr->width;
+               rc.top = pScr->cyChar * pScr->top;
+               rc.bottom = pScr->cyChar * (pScr->bottom+1);
+       }
        else {
-               if (fpScr->screen_bottom == fpScr->buffer_bottom)
-                       fpScr->buffer_bottom = hgScrLine;
-               fpScr->screen_bottom = hgScrLine;
+               if (pScr->screen_bottom == pScr->buffer_bottom)
+                       pScr->buffer_bottom = pScrLine;
+               pScr->screen_bottom = pScrLine;
        }
 
 //     CheckScreen(fpScr);
 
-       fpScr->y++;
+       pScr->y++;
+
+       if (pScr->y > pScr->bottom)
+               pScr->y = pScr->bottom;
 
-       if (fpScr->y > fpScr->bottom)
-               fpScr->y = fpScr->bottom;
+       hDC = GetDC(pScr->hWnd);
+       assert(hDC != NULL);
 
-       hDC = GetDC(fpScr->hWnd);
        if (bFullScreen)
-               ScrollDC(hDC, 0, -fpScr->cyChar, NULL, NULL, NULL, NULL);
+               ScrollDC(hDC, 0, -pScr->cyChar, NULL, NULL, NULL, NULL);
        else 
-               ScrollDC(hDC, 0, -fpScr->cyChar, &rc, &rc, NULL, NULL);
+               ScrollDC(hDC, 0, -pScr->cyChar, &rc, &rc, NULL, NULL);
 
-       PatBlt(hDC, 0, fpScr->bottom * fpScr->cyChar,
-               fpScr->width * fpScr->cxChar, fpScr->cyChar, WHITENESS);
-        
-       ReleaseDC(fpScr->hWnd, hDC);
+       PatBlt(hDC, 0, pScr->bottom * pScr->cyChar,
+               pScr->width * pScr->cxChar, pScr->cyChar, WHITENESS);
+               
+       ReleaseDC(pScr->hWnd, hDC);
 
-       if (fpScr->numlines == fpScr->maxlines)
-               DeleteTopLine(fpScr);
+       if (pScr->numlines == pScr->maxlines)
+               DeleteTopLine(pScr);
        else
-               SetScreenScrollBar(fpScr);
+               SetScreenScrollBar(pScr);
 
        return(1);
-}
-
-
-void DrawCursor(SCREEN *fpScr) {
-#ifdef NOT
-    HDC hDC;
-    char ch=95;
-
-    hDC=GetDC(fpScr->hWnd);
-    SelectObject(hDC,fpScr->ghSelectedFont);
-    SetTextColor(hDC,RGB(255,255,255));
-    TextOut(hDC,fpScr->Oldx*fpScr->cxChar,fpScr->Oldy*fpScr->cyChar,&ch,1);
-    fpScr->Oldx=fpScr->x;
-    fpScr->Oldy=fpScr->y;
-    SetTextColor(hDC,RGB(0,0,0));
-    TextOut(hDC,fpScr->x*fpScr->cxChar,fpScr->y*fpScr->cyChar,&ch,1);
-    ReleaseDC(fpScr->hWnd,hDC);                
-#endif    
-}
-
-int DrawTextScreen(RECT rcInvalid, SCREEN * fpScr, HDC hDC)
+
+} /* ScreenScroll */
+
+
+int DrawTextScreen(
+       RECT rcInvalid,
+       SCREEN *pScr,
+       HDC hDC)
 {
-       HSCREENLINE hgScrLine, hgScrLineTmp;
-       SCREENLINE *fpScrLine;
-       int x=0, y=0;
-       int left=0, right=0;
+       SCREENLINE *pScrLineTmp;
+       SCREENLINE *pScrLine;
+       int x = 0;
+       int y = 0;
+       int left = 0;
+       int right = 0;
        int i;
        int len;
        char attrib;
-       #define YPOS (y*fpScr->cyChar)
+       #define YPOS (y*pScr->cyChar)
 
-    hgScrLine=fpScr->screen_top;
-//    hgScrLine=GetScreenLineFromY(fpScr,0);
-//    wsprintf(strTmp,"{DTS: (%d)=%X }",fpScr->top,hgScrLine);
-//    OutputDebugString(strTmp);
+       pScrLine = pScr->screen_top;
 
-       for (y = 0; y < fpScr->height; y++) {
-               fpScrLine = LINE_MEM_LOCK(hgScrLine);
-
-               if (!fpScrLine)
+       for (y = 0; y < pScr->height; y++) {
+               if (!pScrLine)
                        continue;
 
-               if (YPOS >= rcInvalid.top - fpScr->cyChar && 
-                       YPOS <= rcInvalid.bottom + fpScr->cyChar) {
+               if (YPOS >= rcInvalid.top - pScr->cyChar && 
+                       YPOS <= rcInvalid.bottom + pScr->cyChar) {
 
                        if (y < 0)
                                y = 0;
 
-                       if (y >= fpScr->height)
-                               y = fpScr->height - 1;
+                       if (y >= pScr->height)
+                               y = pScr->height - 1;
 
-                       left = (rcInvalid.left / fpScr->cxChar) - 1;
+                       left = (rcInvalid.left / pScr->cxChar) - 1;
 
-                       right = (rcInvalid.right / fpScr->cxChar) + 1;
+                       right = (rcInvalid.right / pScr->cxChar) + 1;
 
                        if (left < 0)
                                left = 0;
 
-                       if (right > fpScr->width - 1)
-                               right = fpScr->width - 1;
+                       if (right > pScr->width - 1)
+                               right = pScr->width - 1;
 
                        x = left;
 
                        while (x <= right) {
-                               if (!fpScrLine->text[x]) {
+                               if (!pScrLine->text[x]) {
                                        x++;
                                        continue;
                                }
 
-                               if (SCR_isrev(fpScrLine->attrib[x])) {
-                                       SelectObject(hDC, fpScr->ghSelectedFont);                
+                               if (SCR_isrev(pScrLine->attrib[x])) {
+                                       SelectObject(hDC, pScr->hSelectedFont);                
                                        SetTextColor(hDC, RGB(255, 255, 255));
                                        SetBkColor(hDC, RGB(0, 0, 0));
                                }
-                               else if (SCR_isblnk(fpScrLine->attrib[x])) {
-                                       SelectObject(hDC, fpScr->ghSelectedFont);                
+                               else if (SCR_isblnk(pScrLine->attrib[x])) {
+                                       SelectObject(hDC, pScr->hSelectedFont);                
                                        SetTextColor(hDC, RGB(255, 0, 0));
                                        SetBkColor(hDC, RGB(255, 255, 255));
                                }
-                               else if (SCR_isundl(fpScrLine->attrib[x])) {
+                               else if (SCR_isundl(pScrLine->attrib[x])) {
                                        SetTextColor(hDC, RGB(255, 0, 0));
                                        SetBkColor(hDC, RGB(255, 255, 255));
-                                       SelectObject(hDC, fpScr->ghSelectedULFont);
+                                       SelectObject(hDC, pScr->hSelectedULFont);
                                }
                                else {
-                                       SelectObject(hDC,fpScr->ghSelectedFont);
-                                       SetTextColor(hDC,RGB(0, 0, 0));
-                                       SetBkColor(hDC,RGB(255, 255, 255));
+                                       SelectObject(hDC,pScr->hSelectedFont);
+                                       SetTextColor(hDC, RGB(0, 0, 0));
+                                       SetBkColor(hDC, RGB(255, 255, 255));
                                }
 
                                len = 1;
-                               attrib = fpScrLine->attrib[x];
+                               attrib = pScrLine->attrib[x];
                                for (i = x + 1; i <= right; i++) {
-                                       if (fpScrLine->attrib[i] != attrib || !fpScrLine->text[i])
+                                       if (pScrLine->attrib[i] != attrib || !pScrLine->text[i])
                                                break;
                                        len++;
                                }
 
-                               TextOut(hDC, x*fpScr->cxChar, y*fpScr->cyChar, &fpScrLine->text[x], len);
+                               TextOut(hDC, x*pScr->cxChar, y*pScr->cyChar, &pScrLine->text[x], len);
                                x += len;
                        }
                }                
-               hgScrLineTmp = fpScrLine->next;
-               LINE_MEM_UNLOCK(hgScrLine);
-               hgScrLine = hgScrLineTmp;
-       }            
+               pScrLineTmp = pScrLine->next;
+               pScrLine = pScrLineTmp;
+       }
+
        return(0);
-}
 
-static BOOL SetInternalScreenSize(SCREEN *fpScr, int width, int height)
+} /* DrawTextScreen */
+
+
+static BOOL SetInternalScreenSize(
+       SCREEN *pScr,
+       int width,
+       int height)
 {
        RECT rc;
        char *p;
-       HGLOBAL h;
        int idx;
        int n;
        int newlines;
-       HSCREENLINE hgNewLine;
-       SCREENLINE *fpNewLine;
-       HSCREENLINE hgTopLine;
-       SCREENLINE *fpTopLine;
-       HSCREENLINE hgBottomLine;
-       SCREENLINE *fpBottomLine;
+       SCREENLINE *pNewLine;
+       SCREENLINE *pTopLine;
+       SCREENLINE *pBottomLine;
        #if 0
                int col;
                int row;
                int dydestbottom;
        #endif
 
-       GetClientRect(fpScr->hWnd, &rc);
+       GetClientRect(pScr->hWnd, &rc);
 
-       width = (rc.right - rc.left) / fpScr->cxChar;
-       height = (rc.bottom - rc.top) / fpScr->cyChar;
+       width = (rc.right - rc.left) / pScr->cxChar;
+       height = (rc.bottom - rc.top) / pScr->cyChar;
 
-       if (fpScr->height == height && fpScr->width == width)
+       if (pScr->height == height && pScr->width == width)
                return(FALSE);
 
-    fpScr->Oldx = 0;
-    fpScr->Oldy = 0;
-    fpScr->attrib = 0;
+       pScr->Oldx = 0;
+       pScr->Oldy = 0;
+       pScr->attrib = 0;
 
        /*
        Reallocate the inverted array of bytes and copy the values
        from the old screen to the new screen.
        */
-       h = GlobalAlloc(GHND, width * height);
-       if (h == NULL)
-               return(0);
+       p = calloc(width * height, 1);
 
-       ScreenCursorOff(fpScr);
-
-       p = GlobalLock(h);
+       ScreenCursorOff(pScr);
 
        #if 0   /* Copy inversion array to desitination */
                for (col = 0; col < width; col++) {
                        for (row = 0; row < height; row++) {
                                dydestbottom = height - 1 - row;
-                               if (col < fpScr->width && dydestbottom < fpScr->height - 1)
+                               if (col < pScr->width && dydestbottom < pScr->height - 1)
                                        p[row * width + col] =
-                                               cInvertedArray[(fpScr->height - 1 - dydestbottom) * fpScr->width + col];
+                                               cInvertedArray[(pScr->height - 1 - dydestbottom) * pScr->width + col];
                        }
                }
        #endif
 
-       h = LOWORD(GlobalHandle(SELECTOROF(cInvertedArray)));
-       GlobalUnlock(h);
-       GlobalFree(h);
+       free(cInvertedArray);
        cInvertedArray = p;
 
        /*
        Append any new lines which need to be added to accomodate the new
        screen size.
        */
-       hgBottomLine = fpScr->buffer_bottom;
-       newlines = height - (fpScr->height + fpScr->numlines);
+       pBottomLine = pScr->buffer_bottom;
+       newlines = height - (pScr->height + pScr->numlines);
 
        if (newlines > 0) {
-               fpScr->y += fpScr->numlines;
-               fpScr->numlines = 0;
+               pScr->y += pScr->numlines;
+               pScr->numlines = 0;
 
-       for (idx = 0; idx < newlines; idx++) {
-               hgNewLine = ScreenNewLine();
-               fpNewLine = LINE_MEM_LOCK(hgNewLine);
-                       if (fpNewLine == NULL)
+               for (idx = 0; idx < newlines; idx++) {
+                       pNewLine = ScreenNewLine();
+                       if (pNewLine == NULL)
                                return(FALSE);
-               fpNewLine->prev = hgBottomLine;
-
-                       fpBottomLine = LINE_MEM_LOCK(hgBottomLine);
-                       if (fpBottomLine == NULL)
+                       pNewLine->prev = pBottomLine;
+                       if (pBottomLine == NULL)
                                return(FALSE);
-                       fpBottomLine->next = hgNewLine;
-                       LINE_MEM_UNLOCK(hgBottomLine);
-
-                       LINE_MEM_UNLOCK(hgNewLine);
-
-                       hgBottomLine = hgNewLine;
-       }
+                       pBottomLine->next = pNewLine;
+                       pBottomLine = pNewLine;
+               }
        }
 
        /*
@@ -609,686 +538,586 @@ static BOOL SetInternalScreenSize(SCREEN *fpScr, int width, int height)
        in this instance.
        */
        if (newlines < 0) {
-               fpScr->y = (height - 1) - (fpScr->bottom - fpScr->y);
-               if (fpScr->y < 0)
-                       fpScr->y = 0;
-               fpScr->numlines = -newlines;
-               n = fpScr->numlines - fpScr->maxlines;
+               pScr->y = (height - 1) - (pScr->bottom - pScr->y);
+               if (pScr->y < 0)
+                       pScr->y = 0;
+               pScr->numlines = -newlines;
+               n = pScr->numlines - pScr->maxlines;
                for (idx = 0; idx < n; idx++)
-                       DeleteTopLine(fpScr);
+                       DeleteTopLine(pScr);
        }
                
        /*
        Calculate the position of the buffer relative to the screen.
        */
-    fpScr->screen_bottom = hgBottomLine;
-       fpScr->buffer_bottom = hgBottomLine;
+       pScr->screen_bottom = pBottomLine;
+       pScr->buffer_bottom = pBottomLine;
 
-       hgTopLine = hgBottomLine;
+       pTopLine = pBottomLine;
 
        for (idx = 1; idx < height; idx++) {
-               fpTopLine = LINE_MEM_LOCK(hgTopLine);
-               hgTopLine = fpTopLine->prev;
-               LINE_MEM_UNLOCK(hgTopLine);
+               pTopLine = pTopLine->prev;
        }
 
-       fpScr->screen_top = hgTopLine;
-    fpScr->width = width;
-    fpScr->height = height;
-    fpScr->top = 0;
-    fpScr->bottom = height - 1;
+       pScr->screen_top = pTopLine;
+       pScr->width = width;
+       pScr->height = height;
+       pScr->top = 0;
+       pScr->bottom = height - 1;
 
-       if (fpScr->x >= width)
-               fpScr->x = width - 1;
+       if (pScr->x >= width)
+               pScr->x = width - 1;
 
-       if (fpScr->y >= height)
-               fpScr->y = height - 1;
+       if (pScr->y >= height)
+               pScr->y = height - 1;
 
-       SetScreenScrollBar(fpScr);
-       ScreenCursorOn(fpScr);
+       SetScreenScrollBar(pScr);
+       ScreenCursorOn(pScr);
        return(TRUE);
-}
 
-static int ScreenAdjustUp(SCREEN *fpScr, int n)
+} /* SetInternalScreenSize */
+
+
+static int ScreenAdjustUp(
+       SCREEN *pScr,
+       int n)
 {
        int idx;
-       HSCREENLINE hslLine1;
-       HSCREENLINE hslLine2;
-       SCREENLINE *fpScrLine1;
-       SCREENLINE *fpScrLine2;
+       SCREENLINE *pLine1;
+       SCREENLINE *pLine2;
 
        for (idx = 0; idx < n; idx++) {
-           if (fpScr->screen_top == fpScr->buffer_top)
+           if (pScr->screen_top == pScr->buffer_top)
                        return(-idx);
-               fpScrLine1 = LINE_MEM_LOCK(fpScr->screen_top);
-       hslLine1 = fpScrLine1->prev;
-       LINE_MEM_UNLOCK(fpScr->screen_top);
-       if (hslLine1 == NULL)
+               pLine1 = pScr->screen_top->prev;
+               if (pLine1 == NULL)
                        return(-idx);
-       fpScrLine2 = LINE_MEM_LOCK(fpScr->screen_bottom);
-       hslLine2 = fpScrLine2->prev;
-       LINE_MEM_UNLOCK(fpScr->screen_bottom);
-       if (hslLine2 == NULL)
+               pLine2 = pScr->screen_bottom->prev;
+               if (pLine2 == NULL)
                        return(-idx);
-       fpScr->screen_top = hslLine1;
-       fpScr->screen_bottom = hslLine2;                    
+               pScr->screen_top = pLine1;
+               pScr->screen_bottom = pLine2;
        }
+
        return(idx);
-}
 
-static int ScreenAdjustDown(SCREEN *fpScr, int n)
+} /* ScreenAdjustUp */
+
+
+static int ScreenAdjustDown(
+       SCREEN *pScr,
+       int n)
 {
        int idx;
-       HSCREENLINE hslLine1;
-       HSCREENLINE hslLine2;
-       SCREENLINE *fpScrLine1;
-       SCREENLINE *fpScrLine2;
+       SCREENLINE *pLine1;
+       SCREENLINE *pLine2;
 
        for (idx = 0; idx < n; idx++) {
-       if (fpScr->screen_bottom == fpScr->buffer_bottom)
+               if (pScr->screen_bottom == pScr->buffer_bottom)
                        return(-idx);
-       fpScrLine1 = LINE_MEM_LOCK(fpScr->screen_top);
-       hslLine1 = fpScrLine1->next;
-       LINE_MEM_UNLOCK(fpScr->screen_top);
-       if (hslLine1 == NULL)
+               pLine1 = pScr->screen_top->next;
+               if (pLine1 == NULL)
                        return(-idx);
-       fpScrLine2 = LINE_MEM_LOCK(fpScr->screen_bottom);
-       hslLine2 = fpScrLine2->next;
-       LINE_MEM_UNLOCK(fpScr->screen_bottom);
-       if (hslLine2 == NULL)
+               pLine2 = pScr->screen_bottom->next;
+               if (pLine2 == NULL)
                        return(-idx);
-       fpScr->screen_top = hslLine1;
-       fpScr->screen_bottom = hslLine2;
+               pScr->screen_top = pLine1;
+               pScr->screen_bottom = pLine2;
        }
+
        return(idx);
-}
 
-long FAR PASCAL ScreenWndProc(hWnd, message, wParam, lParam)
-HWND hWnd;                /* window handle           */
-UINT message;                 /* type of message         */
-WPARAM wParam;                  /* additional information          */
-LPARAM lParam;                  /* additional information          */
+} /* ScreenAdjustDown */
+
+
+long FAR PASCAL ScreenWndProc(
+       HWND hWnd,
+       UINT message,
+       WPARAM wParam,
+       LPARAM lParam)
 {
        MINMAXINFO *lpmmi;
-    SCREEN *fpScr;                              
-    HGLOBAL hgScr;
-    HMENU hMenu;
-    PAINTSTRUCT ps;    
-    int x=0,
-        y=0,
-        ScrollPos,tmpScroll=0,
-        idx;
-    HSCREENLINE hslLine;
+       SCREEN *pScr;                              
+       HMENU hMenu;
+       PAINTSTRUCT ps;    
+       int x = 0;
+       int y = 0;
+       int ScrollPos;
+       int tmpScroll = 0;
+       int idx;
        HDC hDC;
        RECT rc;
        char title[128];
-         
-    switch (message) {
-
-    case WM_COMMAND:
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-           fpScr=(SCREEN *)GlobalLock(hgScr);
-           if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-
-        switch (wParam) {               
-
-        case IDM_BACKSPACE:
-            hMenu=GetMenu(hWnd);
-            CheckMenuItem(hMenu,IDM_BACKSPACE,MF_CHECKED);
-            CheckMenuItem(hMenu,IDM_DELETE,MF_UNCHECKED);
-            SendMessage(fpScr->hwndTel,WM_MYSCREENCHANGEBKSP,VK_BACK,(HSCREEN)hgScr);                                
-            break;
-        case IDM_DELETE:
-            hMenu=GetMenu(hWnd);
-            CheckMenuItem(hMenu,IDM_BACKSPACE,MF_UNCHECKED);
-            CheckMenuItem(hMenu,IDM_DELETE,MF_CHECKED);
-            SendMessage(fpScr->hwndTel,WM_MYSCREENCHANGEBKSP,0x7f,(HSCREEN)hgScr);                                
-            break;    
-        case IDM_FONT:
-                       ScreenCursorOff(fpScr);
-            ProcessFontChange(hWnd);
-                       ScreenCursorOn(fpScr);
-            break;
-        case IDM_COPY:
-            Edit_Copy(hWnd);
-            hMenu=GetMenu(hWnd);
-            Edit_ClearSelection(fpScr);                
-            GlobalUnlock(hgScr);
-            break;
-        case IDM_PASTE:
-            Edit_Paste(hWnd);
-            break;
-       case IDM_ABOUT:
+       static int bDoubleClick = FALSE;
+                
+       switch (message) {
+
+       case WM_COMMAND:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+
+               switch (wParam) {               
+
+               case IDM_BACKSPACE:
+                       hMenu = GetMenu(hWnd);
+                       CheckMenuItem(hMenu, IDM_BACKSPACE, MF_CHECKED);
+                       CheckMenuItem(hMenu, IDM_DELETE, MF_UNCHECKED);
+                       SendMessage(pScr->hwndTel, WM_MYSCREENCHANGEBKSP, VK_BACK, (LPARAM) pScr);
+                       break;
+
+               case IDM_DELETE:
+                       hMenu = GetMenu(hWnd);
+                       CheckMenuItem(hMenu, IDM_BACKSPACE, MF_UNCHECKED);
+                       CheckMenuItem(hMenu, IDM_DELETE, MF_CHECKED);
+                       SendMessage(pScr->hwndTel, WM_MYSCREENCHANGEBKSP, 0x7f, (LPARAM) pScr);
+                       break;
+
+               case IDM_FONT:
+                       ScreenCursorOff(pScr);
+                       ProcessFontChange(hWnd);
+                       ScreenCursorOn(pScr);
+                       break;
+
+               case IDM_COPY:
+                       Edit_Copy(hWnd);
+                       hMenu=GetMenu(hWnd);
+                       Edit_ClearSelection(pScr);                
+                       break;
+
+               case IDM_PASTE:
+                       Edit_Paste(hWnd);
+                       break;
+
+               case IDM_ABOUT:
                #ifdef KRB4
-                       strcpy(strTmp, "        Kerberos 4 for Windows\n");
-            #endif
-            #ifdef KRB5
-                strcpy(strTmp, "        Kerberos 5 for Windows\n");
-            #endif
-            strcat(strTmp, "\n                Version 1.00\n\n");
-            strcat(strTmp, "          For support, contact:\n");
-            strcat(strTmp, "Cygnus Support");
-            strcat(strTmp, " - (415) 903-1400");
-            MessageBox(NULL, strTmp, "Kerberos", MB_OK);
-            break;
-#ifdef _DEBUG
-               case IDM_DEBUG:
-                       CheckScreen(fpScr);
+                               strcpy(strTmp, "        Kerberos 4 for Windows\n");
+                       #endif
+                       #ifdef KRB5
+                               strcpy(strTmp, "        Kerberos 5 for Windows\n");
+                       #endif
+                       strcat(strTmp, "\n                Version 1.00\n\n");
+                       strcat(strTmp, "          For support, contact:\n");
+                       strcat(strTmp, "Cygnus Support");
+                       strcat(strTmp, " - (415) 903-1400");
+                       MessageBox(NULL, strTmp, "Kerberos", MB_OK);
                        break;
-#endif
-        }        
-
-               GlobalUnlock(hgScr);
-        break;
-
-    case WM_CREATE:
-//        OutputDebugString("WM_CREATE\r\n");
-        SetWindowWord(hWnd,SCREEN_HANDLE,NULL);
-        SetScrollRange(hWnd,SB_VERT,0,100,FALSE);
-               SetScrollPos(hWnd,SB_VERT,0,TRUE);
-               EnableScrollBar(hWnd,SB_VERT,ESB_DISABLE_BOTH);
-        ShowWindow(hWnd,SW_SHOW);
-#ifdef FILE_DEBUG
-        fh=OpenFile("d:\\debug.txt",&ofFile,OF_CREATE|OF_WRITE);
-#endif
-        break;
-        
-    case WM_VSCROLL:
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-        if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-
-               ScreenCursorOff(fpScr);
-
-        switch(wParam) {
-        case SB_LINEDOWN:
-                       if (ScreenAdjustDown(fpScr, 1) <= 0)
+
+               #ifdef _DEBUG
+                       case IDM_DEBUG:
+                               CheckScreen(pScr);
+                               break;
+               #endif
+               }        
+
+               break;
+
+       case WM_NCCREATE:
+               pScr = (SCREEN *) ((LPCREATESTRUCT) lParam)->lpCreateParams;
+               pScr->hWnd = hWnd;
+               SetWindowLong(hWnd, SCREEN_HANDLE, (LONG) pScr);
+               SetScrollRange(hWnd, SB_VERT, 0, 100, FALSE);
+               SetScrollPos(hWnd, SB_VERT, 0, TRUE);
+               EnableScrollBar(hWnd, SB_VERT, ESB_DISABLE_BOTH);
+               return(TRUE);
+               
+       case WM_VSCROLL:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+
+               ScreenCursorOff(pScr);
+
+               switch(wParam) {
+
+               case SB_LINEDOWN:
+                       if (ScreenAdjustDown(pScr, 1) <= 0)
                                break;
                        hDC = GetDC(hWnd);
+                       assert(hDC != NULL);
                        rc.left = 0;
-                       rc.right = fpScr->cxChar * fpScr->width;
+                       rc.right = pScr->cxChar * pScr->width;
                        rc.top = 0;
-                       rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-                       ScrollDC(hDC, 0, -fpScr->cyChar, &rc, &rc, NULL, NULL);
+                       rc.bottom = pScr->cyChar * (pScr->bottom + 1);
+                       ScrollDC(hDC, 0, -pScr->cyChar, &rc, &rc, NULL, NULL);
                        ReleaseDC(hWnd, hDC);
-                       rc.top = fpScr->cyChar * fpScr->bottom;
+                       rc.top = pScr->cyChar * pScr->bottom;
                        InvalidateRect(hWnd, &rc, TRUE);
-            ScrollPos=GetScrollPos(hWnd,SB_VERT);
-            SetScrollPos(hWnd,SB_VERT,ScrollPos+1,TRUE);
+                       ScrollPos = GetScrollPos(hWnd, SB_VERT);
+                       SetScrollPos(hWnd, SB_VERT, ScrollPos + 1, TRUE);
                        UpdateWindow(hWnd);
-            break;
+                       break;
 
-        case SB_LINEUP:
-                       if (ScreenAdjustUp(fpScr, 1) <= 0)
+               case SB_LINEUP:
+                       if (ScreenAdjustUp(pScr, 1) <= 0)
                                break;
                        hDC = GetDC(hWnd);
+                       assert(hDC != NULL);
                        rc.left = 0;
-                       rc.right = fpScr->cxChar * fpScr->width;
+                       rc.right = pScr->cxChar * pScr->width;
                        rc.top = 0;
-                       rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-                       ScrollDC(hDC, 0, fpScr->cyChar, &rc, &rc, NULL, NULL);
+                       rc.bottom = pScr->cyChar * (pScr->bottom + 1);
+                       ScrollDC(hDC, 0, pScr->cyChar, &rc, &rc, NULL, NULL);
                        ReleaseDC(hWnd, hDC);
-                       rc.bottom = fpScr->cyChar;
+                       rc.bottom = pScr->cyChar;
                        InvalidateRect(hWnd, &rc, TRUE);
-            ScrollPos=GetScrollPos(fpScr->hWnd,SB_VERT);
-            SetScrollPos(hWnd,SB_VERT,ScrollPos-1,TRUE);
+                       ScrollPos = GetScrollPos(pScr->hWnd, SB_VERT);
+                       SetScrollPos(hWnd,SB_VERT, ScrollPos - 1, TRUE);
                        UpdateWindow(hWnd);
-            break;
+                       break;
 
-        case SB_PAGEDOWN:
-                       idx = abs(ScreenAdjustDown(fpScr, fpScr->height));
+               case SB_PAGEDOWN:
+                       idx = abs(ScreenAdjustDown(pScr, pScr->height));
                        hDC = GetDC(hWnd);
+                       assert(hDC != NULL);
                        rc.left = 0;
-                       rc.right = fpScr->cxChar * fpScr->width;
+                       rc.right = pScr->cxChar * pScr->width;
                        rc.top = 0;
-                       rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-                       ScrollDC(hDC, 0, -idx * fpScr->cyChar, &rc, &rc, NULL, NULL);
+                       rc.bottom = pScr->cyChar * (pScr->bottom+1);
+                       ScrollDC(hDC, 0, -idx * pScr->cyChar, &rc, &rc, NULL, NULL);
                        ReleaseDC(hWnd, hDC);
-                       rc.top = fpScr->cyChar * (fpScr->bottom - idx + 1);
+                       rc.top = pScr->cyChar * (pScr->bottom - idx + 1);
                        InvalidateRect(hWnd, &rc, TRUE);
-            ScrollPos=GetScrollPos(hWnd,SB_VERT);
-            SetScrollPos(hWnd,SB_VERT,ScrollPos+idx,TRUE);
-            break;
+                       ScrollPos=GetScrollPos(hWnd, SB_VERT);
+                       SetScrollPos(hWnd, SB_VERT, ScrollPos + idx, TRUE);
+                       break;
 
-        case SB_PAGEUP:
-                       idx = abs(ScreenAdjustUp(fpScr, fpScr->height));
+               case SB_PAGEUP:
+                       idx = abs(ScreenAdjustUp(pScr, pScr->height));
                        hDC = GetDC(hWnd);
+                       assert(hDC != NULL);
                        rc.left = 0;
-                       rc.right = fpScr->cxChar * fpScr->width;
+                       rc.right = pScr->cxChar * pScr->width;
                        rc.top = 0;
-                       rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-                       ScrollDC(hDC, 0, idx * fpScr->cyChar, &rc, &rc, NULL, NULL);
+                       rc.bottom = pScr->cyChar * (pScr->bottom + 1);
+                       ScrollDC(hDC, 0, idx * pScr->cyChar, &rc, &rc, NULL, NULL);
                        ReleaseDC(hWnd, hDC);
-                       rc.bottom = idx * fpScr->cyChar;
+                       rc.bottom = idx * pScr->cyChar;
                        InvalidateRect(hWnd, &rc, TRUE);
-            ScrollPos=GetScrollPos(hWnd,SB_VERT);
-            SetScrollPos(hWnd,SB_VERT,ScrollPos-idx,TRUE);
-            break;
-
-        case SB_THUMBPOSITION:
-        case SB_THUMBTRACK:
-            ScrollPos = GetScrollPos(hWnd,SB_VERT);
-            tmpScroll = ScrollPos - LOWORD(lParam);
+                       ScrollPos=GetScrollPos(hWnd, SB_VERT);
+                       SetScrollPos(hWnd, SB_VERT, ScrollPos - idx, TRUE);
+                       break;
+
+               case SB_THUMBPOSITION:
+               case SB_THUMBTRACK:
+                       ScrollPos = GetScrollPos(hWnd, SB_VERT);
+                       tmpScroll = ScrollPos - LOWORD(lParam);
                        if (tmpScroll == 0)
                                break;
                        if (tmpScroll > 0)
-                               ScreenAdjustUp(fpScr, tmpScroll);
+                               ScreenAdjustUp(pScr, tmpScroll);
                        else
-                               ScreenAdjustDown(fpScr, -tmpScroll);
-                       if (abs(tmpScroll) < fpScr->height) {
-                               hDC=GetDC(hWnd);
+                               ScreenAdjustDown(pScr, -tmpScroll);
+                       if (abs(tmpScroll) < pScr->height) {
+                               hDC = GetDC(hWnd);
+                               assert(hDC != NULL);
                                rc.left = 0;
-                               rc.right = fpScr->cxChar * fpScr->width;
+                               rc.right = pScr->cxChar * pScr->width;
                                rc.top = 0;
-                               rc.bottom = fpScr->cyChar * (fpScr->bottom+1);
-                               ScrollDC(hDC,0,tmpScroll*fpScr->cyChar,&rc,&rc,NULL,NULL);
+                               rc.bottom = pScr->cyChar * (pScr->bottom + 1);
+                               ScrollDC(hDC, 0, tmpScroll * pScr->cyChar, &rc, &rc, NULL, NULL);
                                ReleaseDC(hWnd, hDC);
                                if (tmpScroll > 0) {
-                                       rc.bottom = tmpScroll * fpScr->cyChar;
+                                       rc.bottom = tmpScroll * pScr->cyChar;
                                        InvalidateRect(hWnd, &rc, TRUE);
                                }
                                else {
-                                       rc.top = (fpScr->bottom + tmpScroll + 1) * fpScr->cyChar;
+                                       rc.top = (pScr->bottom + tmpScroll + 1) * pScr->cyChar;
                                        InvalidateRect(hWnd, &rc, TRUE);
                                }
                        }
                        else
                                InvalidateRect(hWnd, NULL, TRUE);
 
-            SetScrollPos(hWnd,SB_VERT,LOWORD(lParam),TRUE);
+                       SetScrollPos(hWnd, SB_VERT, LOWORD(lParam), TRUE);
                        UpdateWindow(hWnd);
-            break;
-        }
-               ScreenCursorOn(fpScr);
-        GlobalUnlock(hgScr);
-        break;
-    
-    case WM_KEYDOWN:
-        if (wParam==VK_INSERT) {
-            if (GetKeyState(VK_SHIFT)<0) 
-                PostMessage(hWnd,WM_COMMAND,IDM_PASTE,NULL);
-            else if (GetKeyState(VK_CONTROL)<0)
-                PostMessage(hWnd,WM_COMMAND,IDM_COPY,NULL);
-            break;
-        }        
-        if ((wParam < VK_PRIOR)||(wParam > VK_DOWN)) break;
-        switch (wParam) {
-        case VK_PRIOR: /* Page up   */
-            SendMessage(hWnd,WM_VSCROLL,SB_PAGEUP,NULL);               
-            break;
-        case VK_NEXT:  /* Page down */
-            SendMessage(hWnd,WM_VSCROLL,SB_PAGEDOWN,NULL);
-            break;
-        case VK_UP:            /* Line up   */
-            SendMessage(hWnd,WM_VSCROLL,SB_LINEUP,NULL);
-            break;
-        case VK_DOWN:  /* Line down */
-            SendMessage(hWnd,WM_VSCROLL,SB_LINEDOWN,NULL);
-            break;
-        }
-        UpdateWindow(hWnd);
-        break;
-        
-    case WM_CHAR:
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) {
-               OutputDebugString("Hosed #1.\r\n");
-               break;
-        }      
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-        if (fpScr == NULL) {
-               OutputDebugString("Hosed #2.\r\n");
-               break;
-        }      
-        SendMessage(fpScr->hwndTel,WM_MYSCREENCHAR,wParam,(HSCREEN)hgScr);
-        GlobalUnlock(hgScr);
-        break;
-
-    case WM_SYSCHAR:
-        if ((wParam=='c')||(wParam=='e'))
-            return (DefWindowProc(hWnd, message, wParam, lParam));
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) {
-               OutputDebugString("Hosed #1.\r\n");
-               break;
-        }      
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-        if (fpScr == NULL) {
-               OutputDebugString("Hosed #2.\r\n");
-               break;
-        }
-        SendMessage(fpScr->hwndTel,WM_MYSYSCHAR,wParam,(HSCREEN)hgScr);
-        GlobalUnlock(hgScr);
-        break;
-
-    case WM_INITMENU:
-        if (IsClipboardFormatAvailable(CF_TEXT))
-            EnableMenuItem((HMENU) wParam,IDM_PASTE,MF_ENABLED);
-        else EnableMenuItem((HMENU) wParam,IDM_PASTE,MF_GRAYED);
-        if (bSelection) EnableMenuItem((HMENU) wParam,IDM_COPY,MF_ENABLED);
-        else EnableMenuItem((HMENU) wParam,IDM_COPY,MF_GRAYED);
-        break;
-                              
-    case WM_GETMINMAXINFO:
-//        OutputDebugString("WM_GETMINMAX_INFO\r\n");
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) break;
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-//        if (fpScr == NULL) OutputDebugString("Hosed in GetMinMaxInfo.\r\n");
-//        wsprintf(strTmp,"cx=%d cy=%d width=%d height=%d",fpScr->cxChar,fpScr->cyChar,fpScr->width,fpScr->height);
-//        OutputDebugString(strTmp);
-           lpmmi = (MINMAXINFO *) lParam;
-               if (FRAME_WIDTH + MAX_LINE_WIDTH * fpScr->cxChar < lpmmi->ptMaxSize.x)
-                       lpmmi->ptMaxSize.x = FRAME_WIDTH + MAX_LINE_WIDTH * fpScr->cxChar;
-               lpmmi->ptMaxTrackSize.x = lpmmi->ptMaxSize.x;
-               lpmmi->ptMinTrackSize.x = FRAME_WIDTH + 20 * fpScr->cxChar;
-               lpmmi->ptMinTrackSize.y = FRAME_HEIGHT + 4 * fpScr->cyChar;
-           GlobalUnlock(hgScr);
-        break;
-    
-    case WM_LBUTTONDOWN: 
-        if (bDoubleClick) Edit_TripleClick(hWnd,lParam);
-        else Edit_LbuttonDown(hWnd,lParam);
-        break;
-    
-    case WM_LBUTTONUP:
-        Edit_LbuttonUp(hWnd,lParam);
-        break;
-
-    case WM_LBUTTONDBLCLK:
-        bDoubleClick=TRUE;
-        SetTimer(hWnd,TIMER_TRIPLECLICK,GetDoubleClickTime(),NULL);
-        Edit_LbuttonDblclk(hWnd,lParam);
-        break;
-
-    case WM_TIMER:
-        if (wParam==TIMER_TRIPLECLICK) bDoubleClick=FALSE;
-        break;
-
-    case WM_RBUTTONUP:
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) {
-               OutputDebugString("Hosed #1.\r\n");
-               break;
-        }      
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-        if (fpScr == NULL) {
-               OutputDebugString("Hosed #2.\r\n");
-               break;
-        }
-        Edit_Copy(hWnd);
-        Edit_ClearSelection(fpScr);                
-        Edit_Paste(hWnd);
-        GlobalUnlock(hgScr);
-        break;
-                            
-    case WM_MOUSEMOVE:
-        if (bMouseDown) Edit_MouseMove(hWnd,lParam);
-        break;
-        
-    case WM_RBUTTONDOWN: {
-        HSCREENLINE hgScrLine;
-        SCREENLINE *fpScrLine;
-        
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) {
-               OutputDebugString("Hosed #1.\r\n");
-               break;
-        }      
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-        if (fpScr == NULL) {
-               OutputDebugString("Hosed #2.\r\n");
-               break;
-        }
-        hgScrLine=fpScr->screen_top;
-        fpScrLine=LINE_MEM_LOCK(hgScrLine);
-
-//        wsprintf(strTmp,"fp->x=%d fp->y=%d text=%s \r\n",fpScr->x,fpScr->y,fpScrLine->text);
-//        OutputDebugString(strTmp);
-        LINE_MEM_LOCK(hgScrLine);
-        }        
-        break;
-            
-    case WM_PAINT:        
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr == NULL) {
-               OutputDebugString("Hosed #1.\r\n");
-               break;
-        }      
-        fpScr=(SCREEN *)GlobalLock(hgScr);
-        if (fpScr == NULL) {
-               OutputDebugString("Hosed #2.\r\n");
-               break;
-        }
-        BeginPaint (hWnd,&ps);
-        SelectObject(ps.hdc,fpScr->ghSelectedFont);
-        hslLine=fpScr->screen_bottom;
-        if (hslLine==NULL) {
-            OutputDebugString("screen_bottom is NULL.\r\n");
-            EndPaint(hWnd,&ps);                
-            GlobalUnlock(hgScr);
-            break;
-        }
-        DrawTextScreen(ps.rcPaint, fpScr, ps.hdc);
-        EndPaint(hWnd,&ps);                
-        DrawCursor(fpScr);
-        GlobalUnlock(hgScr);
-        break;         
-
-    case WM_CLOSE:
-#ifdef FILE_DEBUG
-        _lclose(fh);
-#endif
-        if (MessageBox(hWnd,"Terminate this connection?","Telnet",MB_OKCANCEL) == IDOK) {
-            hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-            if (hgScr == NULL) OutputDebugString("Hosed #1.\r\n");
-            fpScr=(SCREEN *)GlobalLock(hgScr);
-            if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-            SendMessage(fpScr->hwndTel,WM_MYSCREENCLOSE,NULL,(HSCREEN)hgScr);
-            return (DefWindowProc(hWnd, message, wParam, lParam));
-        }    
-        break;
-
-    case WM_DESTROY:
-        hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-        if (hgScr != NULL) {
-               fpScr=(SCREEN *)GlobalLock(hgScr);
-               if (fpScr != NULL)
-                DeleteObject(fpScr->ghSelectedFont);
+                       break;
                }
-        return (DefWindowProc(hWnd, message, wParam, lParam));
-
-    case WM_ACTIVATE:
-       if (wParam!=WA_INACTIVE) {
-            hgScr=(HGLOBAL)GetWindowWord(hWnd,SCREEN_HANDLE);
-            if (hgScr == NULL) return (DefWindowProc(hWnd, message, wParam, lParam));
-            fpScr=(SCREEN *)GlobalLock(hgScr);
-            if (fpScr == NULL) OutputDebugString("Hosed #2.\r\n");
-            if (fpScr->bAlert) {
-                char strTitle[128];
-                int idx;
-
-                GetWindowText(hWnd,strTitle,sizeof(strTitle));
-                if (strTitle[0] == ALERT) {
-                    idx=lstrlen(strTitle);
-                    strTitle[idx-2]=0;
-                    SetWindowText(hWnd,&strTitle[2]);
-                    fpScr->bAlert=FALSE;
-                }
-            }
-            GlobalUnlock(hgScr);
-        }  /* Allow control to drop down to DefWindowProc() */
-        return (DefWindowProc(hWnd, message, wParam, lParam));
-        break;
 
-       case WM_SIZE:
-               if (wParam == SIZE_MINIMIZED)
+               ScreenCursorOn(pScr);
+               break;
+       
+       case WM_KEYDOWN:
+               if (wParam == VK_INSERT) {
+                       if (GetKeyState(VK_SHIFT) < 0) 
+                               PostMessage(hWnd, WM_COMMAND, IDM_PASTE, NULL);
+                       else if (GetKeyState(VK_CONTROL) < 0)
+                               PostMessage(hWnd, WM_COMMAND, IDM_COPY, NULL);
+                       break;
+               }        
+               if (wParam < VK_PRIOR || wParam > VK_DOWN)
                        break;
 
-               hgScr = (HGLOBAL) GetWindowWord(hWnd, SCREEN_HANDLE);
-               if (hgScr == NULL)
+               switch (wParam) {
+
+               case VK_PRIOR:  /* Page up   */
+                       SendMessage(hWnd, WM_VSCROLL, SB_PAGEUP, NULL);
                        break;
-               fpScr = (SCREEN *) GlobalLock(hgScr);
-               if (fpScr == NULL)
+
+               case VK_NEXT:   /* Page down */
+                       SendMessage(hWnd, WM_VSCROLL, SB_PAGEDOWN, NULL);
                        break;
 
-               if (SetInternalScreenSize(fpScr, LOWORD(lParam), HIWORD(lParam))) {
-                       SendMessage(fpScr->hwndTel, WM_MYSCREENSIZE, 0,
-                               MAKELONG(fpScr->width, fpScr->height));
-                       MakeWindowTitle(fpScr->title,fpScr->width,fpScr->height,title,sizeof(title));
-            SetWindowText(hWnd,title);
+               case VK_UP:             /* Line up   */
+                       SendMessage(hWnd, WM_VSCROLL, SB_LINEUP, NULL);
+                       break;
+
+               case VK_DOWN:   /* Line down */
+                       SendMessage(hWnd, WM_VSCROLL, SB_LINEDOWN, NULL);
+                       break;
                }
 
-               GlobalUnlock(hgScr);
+               UpdateWindow(hWnd);
+               break;
+               
+       case WM_CHAR:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+               SendMessage(pScr->hwndTel, WM_MYSCREENCHAR, wParam, (LPARAM) pScr);
                break;
 
-       case WM_SETFOCUS:
-               hgScr = (HGLOBAL) GetWindowWord(hWnd, SCREEN_HANDLE);
-               if (hgScr == NULL)
-                       break;
-               fpScr = (SCREEN *) GlobalLock(hgScr);
-               if (fpScr == NULL)
+       case WM_SYSCHAR:
+               if (wParam == 'c' || wParam == 'e')
+                       return (DefWindowProc(hWnd, message, wParam, lParam));
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+               SendMessage(pScr->hwndTel, WM_MYSYSCHAR, wParam, (LPARAM) pScr);
+               break;
+
+       case WM_INITMENU:
+               if (IsClipboardFormatAvailable(CF_TEXT))
+                       EnableMenuItem((HMENU) wParam, IDM_PASTE, MF_ENABLED);
+               else
+                       EnableMenuItem((HMENU) wParam, IDM_PASTE, MF_GRAYED);
+               if (bSelection)
+                       EnableMenuItem((HMENU) wParam, IDM_COPY, MF_ENABLED);
+               else
+                       EnableMenuItem((HMENU) wParam, IDM_COPY, MF_GRAYED);
+               break;
+                                                         
+       case WM_GETMINMAXINFO:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               if (pScr == NULL) // Used on creation when window word not set
+                       pScr = ScreenList;
+           lpmmi = (MINMAXINFO *) lParam;
+               if (FRAME_WIDTH + MAX_LINE_WIDTH * pScr->cxChar < lpmmi->ptMaxSize.x)
+                       lpmmi->ptMaxSize.x = FRAME_WIDTH + MAX_LINE_WIDTH * pScr->cxChar;
+               lpmmi->ptMaxTrackSize.x = lpmmi->ptMaxSize.x;
+               lpmmi->ptMinTrackSize.x = FRAME_WIDTH + 20 * pScr->cxChar;
+               lpmmi->ptMinTrackSize.y = FRAME_HEIGHT + 4 * pScr->cyChar;
+               break;
+       
+       case WM_LBUTTONDOWN: 
+               if (bDoubleClick)
+                       Edit_TripleClick(hWnd, lParam);
+               else
+                       Edit_LbuttonDown(hWnd, lParam);
+               break;
+       
+       case WM_LBUTTONUP:
+               Edit_LbuttonUp(hWnd, lParam);
+               break;
+
+       case WM_LBUTTONDBLCLK:
+               bDoubleClick = TRUE;
+               SetTimer(hWnd, TIMER_TRIPLECLICK, GetDoubleClickTime(), NULL);
+               Edit_LbuttonDblclk(hWnd, lParam);
+               break;
+
+       case WM_TIMER:
+               if (wParam == TIMER_TRIPLECLICK)
+                       bDoubleClick = FALSE;
+               break;
+
+       case WM_RBUTTONUP:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+               Edit_Copy(hWnd);
+               Edit_ClearSelection(pScr);
+               Edit_Paste(hWnd);
+               break;
+                                                       
+       case WM_MOUSEMOVE:
+               if (bMouseDown)
+                       Edit_MouseMove(hWnd, lParam);
+               break;
+
+       case WM_RBUTTONDOWN:
+               #if 0
+                       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+                       assert (pScr != NULL);
+                       wsprintf(strTmp,"fp->x=%d fp->y=%d text=%s \r\n", 
+                               pScr->screen_top->x, pScr->screen_top->y, pScr->screen_top->text);
+                       OutputDebugString(strTmp);
+               #endif
+               break;
+                       
+       case WM_PAINT:        
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+               BeginPaint (hWnd, &ps);
+               SelectObject(ps.hdc, pScr->hSelectedFont);
+               if (pScr->screen_bottom != NULL)
+                       DrawTextScreen(ps.rcPaint, pScr, ps.hdc);
+               else
+                       OutputDebugString("screen_bottom is NULL.\r\n");
+               EndPaint(hWnd, &ps);
+               break;         
+
+       case WM_CLOSE:
+               if (MessageBox(hWnd, "Terminate this connection?", "Telnet", MB_OKCANCEL) == IDOK) {
+                       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+                       assert (pScr != NULL);
+                       SendMessage(pScr->hwndTel, WM_MYSCREENCLOSE, NULL, (LPARAM) pScr);
+                       return (DefWindowProc(hWnd, message, wParam, lParam));
+               }    
+               break;
+
+       case WM_DESTROY:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               if (pScr != NULL)
+                       DeleteObject(pScr->hSelectedFont);
+               return (DefWindowProc(hWnd, message, wParam, lParam));
+
+       case WM_ACTIVATE:
+               if (wParam != WA_INACTIVE) {
+                       pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+                       assert (pScr != NULL);
+                       if (pScr->bAlert) {
+                               char strTitle[128];
+                               int idx;
+
+                               GetWindowText(hWnd, strTitle, sizeof(strTitle));
+                               if (strTitle[0] == ALERT) {
+                                       idx = lstrlen(strTitle);
+                                       strTitle[idx - 2] = 0;
+                                       SetWindowText(hWnd, &strTitle[2]);
+                                       pScr->bAlert = FALSE;
+                               }
+                       }
+               }
+               return (DefWindowProc(hWnd, message, wParam, lParam));
+
+       case WM_SIZE:
+               if (wParam == SIZE_MINIMIZED)
                        break;
 
-               CreateCaret(hWnd, NULL, fpScr->cxChar, 2);
-               ScreenCursorOn(fpScr);
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+
+               if (SetInternalScreenSize(pScr, LOWORD(lParam), HIWORD(lParam))) {
+                       SendMessage(pScr->hwndTel, WM_MYSCREENSIZE, 0,
+                               MAKELONG(pScr->width, pScr->height));
+               }
+               MakeWindowTitle(pScr->title, pScr->width, pScr->height, title, sizeof(title));
+               SetWindowText(hWnd, title);
+               break;
+
+       case WM_SETFOCUS:
+               pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
+               assert (pScr != NULL);
+               CreateCaret(hWnd, NULL, pScr->cxChar, 2);
+               ScreenCursorOn(pScr);
                break;
 
        case WM_KILLFOCUS:
                DestroyCaret();
                break;
 
-    default:              /* Passes it on if unproccessed    */
-        return (DefWindowProc(hWnd, message, wParam, lParam));
-    }
-
-    return (NULL);
-}
-
-/**************************************************************************
-*                                                                         *
-*  Function:  ReportError(WORD)                                           *
-*                                                                         *
-*   Purpose:  To report an error that has occurred while allocating       *
-*             memory for the CD struct, locking the memory or while       *
-*             trying to load a resource string.                           *
-*                                                                         *
-*   Returns:  void                                                        *
-*                                                                         *
-*  Comments:                                                              *
-*                                                                         *
-*   History:  Date      Reason                                            *
-*             --------  -----------------------------------               *
-*                                                                         *
-*             10/01/91  Created                                           *
-*                                                                         *
-**************************************************************************/
-void ReportError(WORD wErrorType){
-   LPSTR lpszErrorMsg;
-
-   switch( wErrorType )
-      {
-         case IDC_ALLOCFAIL:
-
-            lpszErrorMsg=gszAllocErrorMsg;
-            break;
-
-         case IDC_LOCKFAIL:
-
-            lpszErrorMsg=gszLockErrorMsg;
-            break;
-
-         case IDC_LOADSTRINGFAIL:
-
-            lpszErrorMsg=gszLoadStrFail;
-            break;
-
-         default:    //let's hope we never get here!
-            return;
-      }
-
-   MessageBox(NULL, (LPSTR)lpszErrorMsg, NULL, MB_OK);
-
-   return;
-}
-
-void ScreenBell(SCREEN *fpScr) {
-    MessageBeep(MB_ICONEXCLAMATION);
-    if (fpScr->hWnd != GetActiveWindow()) {
-        char strTitle[128];
-        int idx;
-
-        FlashWindow(fpScr->hWnd,TRUE);
-        if (!fpScr->bAlert) {
-            strTitle[0]=ALERT;
-            strTitle[1]=SPACE;
-            GetWindowText(fpScr->hWnd,&strTitle[2],sizeof(strTitle)-2);
-            idx=lstrlen(strTitle);
-            strTitle[idx]=SPACE;
-            strTitle[idx+1]=ALERT;
-            strTitle[idx+2]=0;
-            SetWindowText(fpScr->hWnd,strTitle);
-        }
-        FlashWindow(fpScr->hWnd,FALSE);
-        fpScr->bAlert=TRUE;
-    }
-}
-
-void ScreenBackspace(SCREEN * fpScr) {
-    RECT rc;
-    
-//    hDC=GetDC(fpScr->hWnd);
-//    SelectObject(hDC,fpScr->ghSelectedFont);
-//    TextOut(hDC,fpScr->x*fpScr->cxChar,fpScr->y*fpScr->cyChar," ",1);
-//    ReleaseDC(fpScr->hWnd,hDC);
-    rc.left=fpScr->x*fpScr->cxChar;
-    rc.right=((fpScr->x+1)*fpScr->cxChar);
-    rc.top=(fpScr->cyChar*fpScr->y);    
-    rc.bottom=(fpScr->cyChar*fpScr->y+1);
-    InvalidateRect(fpScr->hWnd,&rc,TRUE);
-    fpScr->x--;
-    if (fpScr->x < 0) fpScr->x=0;
-//    DrawCursor(fpScr);
-    UpdateWindow(fpScr->hWnd);
-    
-}
-
-void ScreenTab(SCREEN *fpScr) {
-    int num_spaces,idx;
-    HSCREENLINE hgScrLine;
-    SCREENLINE *fpScrLine;
-    int iTest=0;
-    
-    num_spaces = TAB_SPACES - (fpScr->x % TAB_SPACES);
-    if ((fpScr->x + num_spaces) >= fpScr->width) {
-       ScreenScroll(fpScr);
-       num_spaces -= fpScr->width - fpScr->x;
-       fpScr->x=0;
-    }
-//    hgScrLine=fpScr->buffer_bottom;
-    hgScrLine=GetScreenLineFromY(fpScr,fpScr->y);
-    if (hgScrLine==NULL) return;
-    fpScrLine=(SCREENLINE *)LINE_MEM_LOCK(hgScrLine);
-    if (fpScrLine==NULL) return;
-    for (idx=0; idx<num_spaces; idx++,fpScr->x++) {
-        if (!fpScrLine->text[fpScr->x])
-            iTest=1;
-        if (iTest)
-            fpScrLine->text[fpScr->x]=SPACE;
-    }
-//    fpScrLine->text[fpScr->x]=0;
-    hDC=GetDC(fpScr->hWnd);
-    SelectObject(hDC,fpScr->ghSelectedFont);
-    TextOut(hDC,(fpScr->x-num_spaces)*fpScr->cxChar,fpScr->y*fpScr->cyChar,
-        fpScrLine->text+fpScr->x-num_spaces,num_spaces);
-    ReleaseDC(fpScr->hWnd,hDC);                
-    LINE_MEM_UNLOCK(hgScrLine);
-    DrawCursor(fpScr);
-}
-
-void ScreenCarriageFeed(SCREEN *fpScr) {
-    DrawCursor(fpScr);
-    fpScr->x=0;    
-}
+       default:
+               return(DefWindowProc(hWnd, message, wParam, lParam));
+       }
+
+       return(NULL);
+
+} /* ScreenWndProc */
+
+
+void ScreenBell(
+       SCREEN *pScr)
+{
+       char strTitle[128];
+       int idx;
+
+       MessageBeep(MB_ICONEXCLAMATION);
+       if (pScr->hWnd != GetActiveWindow()) {
+               FlashWindow(pScr->hWnd, TRUE);
+               if (!pScr->bAlert) {
+                       strTitle[0] = ALERT;
+                       strTitle[1] = SPACE;
+                       GetWindowText(pScr->hWnd, &strTitle[2], sizeof(strTitle) - 2);
+                       idx = lstrlen(strTitle);
+                       strTitle[idx] = SPACE;
+                       strTitle[idx+1] = ALERT;
+                       strTitle[idx+2] = 0;
+                       SetWindowText(pScr->hWnd, strTitle);
+               }
+               FlashWindow(pScr->hWnd, FALSE);
+               pScr->bAlert = TRUE;
+       }
+
+} /* ScreenBell */
+
+
+void ScreenBackspace(SCREEN *pScr)
+{
+       RECT rc;
+       
+       #if 0
+               hDC = GetDC(fpScr->hWnd);
+               assert(hDC != NULL);
+               SelectObject(hDC, fpScr->ghSelectedFont);
+               TextOut(hDC, pScr->x * pScr->cxChar, pScr->y * pScr->cyChar, " ", 1);
+               ReleaseDC(pScr->hWnd, hDC);
+       #endif
+       rc.left = pScr->x * pScr->cxChar;
+       rc.right = (pScr->x + 1) * pScr->cxChar;
+       rc.top = pScr->cyChar * pScr->y;
+       rc.bottom = pScr->cyChar * (pScr->y + 1);
+       InvalidateRect(pScr->hWnd, &rc, TRUE);
+       pScr->x--;
+       if (pScr->x < 0)
+               pScr->x = 0;
+       UpdateWindow(pScr->hWnd);
+
+} /* ScreenBackspace */
+
+
+void ScreenTab(
+       SCREEN *pScr)
+{
+       int num_spaces;
+       int idx;
+       SCREENLINE *pScrLine;
+       int iTest = 0;
+       HDC hDC;
+
+       num_spaces = TAB_SPACES - (pScr->x % TAB_SPACES);
+       if (pScr->x + num_spaces >= pScr->width) {
+          ScreenScroll(pScr);
+          num_spaces -= pScr->width - pScr->x;
+          pScr->x = 0;
+       }
+       pScrLine = GetScreenLineFromY(pScr, pScr->y);
+       if (pScrLine == NULL)
+               return;
+       for (idx = 0; idx<num_spaces; idx++, pScr->x++) {
+               if (!pScrLine->text[pScr->x])
+                       iTest=1;
+               if (iTest)
+                       pScrLine->text[pScr->x] = SPACE;
+       }
+       hDC = GetDC(pScr->hWnd);
+       assert(hDC != NULL);
+       SelectObject(hDC, pScr->hSelectedFont);
+       TextOut(hDC, (pScr->x - num_spaces) * pScr->cxChar, pScr->y * pScr->cyChar,
+               pScrLine->text + pScr->x - num_spaces, num_spaces);
+       ReleaseDC(pScr->hWnd, hDC);                
+
+} /* ScreenTab */
+
+
+void ScreenCarriageFeed(
+       SCREEN *pScr)
+{
+       pScr->x = 0;
+
+} /* ScreenCarriageFeed */
index 7a472436f241f26cde6c1aacdbb5d474eb4e94c3..a8599cf14016416d2e351e1d6702e85d87eec959 100644 (file)
@@ -1,7 +1,5 @@
 extern long FAR PASCAL ScreenWndProc(HWND,UINT,WPARAM,LPARAM);
 
-//#define WINMEM
-
 /*
 *          Definition of attribute bits in the Virtual Screen
 *
@@ -43,25 +41,9 @@ extern long FAR PASCAL ScreenWndProc(HWND,UINT,WPARAM,LPARAM);
 #define ALERT 0x21
 #define MAX_LINE_WIDTH 256 /* not restricted to 1 byte */
 
-#ifdef WINMEM
-#define HSCREENLINE DWORD
-#define LINE_MEM_ALLOC(x) sAlloc(x)
-#define LINE_MEM_LOCK(x) (SCREENLINE *)sLock(x)
-#define LINE_MEM_UNLOCK(x) sUnlock(x)
-#define LINE_MEM_FREE(x) sFree(x)
-#else
-#define HSCREENLINE HGLOBAL
-#define LINE_MEM_ALLOC(x) GlobalAlloc(GHND,x)
-#define LINE_MEM_LOCK(x) (SCREENLINE *) GlobalLock(x)
-#define LINE_MEM_UNLOCK(x) GlobalUnlock(x)
-#define LINE_MEM_FREE(x) GlobalFree(x)
-#endif
-
-#define HSCREEN HGLOBAL
-
 typedef struct SCREENLINE {
-       HSCREENLINE next;
-       HSCREENLINE prev;
+       struct SCREENLINE *next;
+       struct SCREENLINE *prev;
        int width;
        char *text;
        char *attrib;
@@ -69,56 +51,63 @@ typedef struct SCREENLINE {
 } SCREENLINE;
 
 typedef struct SCREEN {
-    LPSTR title;
-    HWND hWnd;
-    HWND hwndTel;
-    HSCREENLINE screen_top,
-                screen_bottom,
-                buffer_top,
-                buffer_bottom;
-       int ID,
-        type,
-        width,
-        height,
-        maxlines,       //Maximum number of scrollback lines
-        numlines,       //Current number of scrollback lines
-        savelines,      //Save lines off top?
-        ESscroll,       //Scroll screen when ES received
-        attrib,         //current attribute
-        x,y,            //current cursor position
-        Oldx,Oldy,      // internally used to redraw cursor
-        Px,Py,Pattrib,  //saved cursor pos and attribute
-        VSIDC,          // Insert/Delete character mode 0=draw line
-        DECAWM,         // AutoWrap mode 0=off
-        DECCKM,         // Cursor key mode
-        DECPAM,         // keyPad Application mode
-        IRM,            // Insert/Replace mode
-        escflg,         // Current Escape level        
-        top,bottom,     // Vertical bounds of screen
-        parmptr,
-        cxChar,         /* Width of the current font */
-        cyChar;         /* Height of the current font */
-    BOOL bAlert;
-    int parms[6];       //Ansi Params
-    LOGFONT lf;
-    HFONT ghSelectedFont,ghSelectedULFont;
-    char tabs[MAX_LINE_WIDTH];
-    HSCREEN next, prev;
+       LPSTR title;
+       HWND hWnd;
+       HWND hwndTel;
+       SCREENLINE *screen_top;
+       SCREENLINE *screen_bottom;
+       SCREENLINE *buffer_top;
+       SCREENLINE *buffer_bottom;
+       int ID;
+       int type;
+       int width;
+       int height;
+       int maxlines;       // Maximum number of scrollback lines
+       int numlines;       // Current number of scrollback lines
+       int savelines;      // Save lines off top?
+       int ESscroll;       // Scroll screen when ES received
+       int attrib;         // current attribute
+       int x;              // current cursor position
+       int y;              // current cursor position
+       int Oldx;           // internally used to redraw cursor
+       int Oldy;
+       int Px;             // saved cursor pos and attribute
+       int Py;
+       int Pattrib;
+       int VSIDC;          // Insert/Delete character mode 0=draw line
+       int DECAWM;         // AutoWrap mode 0=off
+       int DECCKM;         // Cursor key mode
+       int DECPAM;         // keyPad Application mode
+       int IRM;            // Insert/Replace mode
+       int escflg;         // Current Escape level        
+       int top;            // Vertical bounds of screen
+       int bottom;
+       int parmptr;
+       int cxChar;         // Width of the current font
+       int cyChar;         // Height of the current font
+       BOOL bAlert;
+       int parms[6];       // Ansi Params
+       LOGFONT lf;
+       HFONT hSelectedFont;
+       HFONT hSelectedULFont;
+       char tabs[MAX_LINE_WIDTH];
+       struct SCREEN *next;
+       struct SCREEN *prev;
 } SCREEN;
 
 typedef struct CONFIG {
-    LPSTR title;
-    HWND hwndTel;
-    int ID,
-        type,
-        height,
-        width,
-        maxlines,       //Maximum number of scrollback lines
-        backspace,
-        ESscroll,       //Scroll screen when ES received
-        VSIDC,          // Insert/Delete character mode 0=draw line
-        DECAWM,         // AutoWrap mode 0=off
-        IRM;            // Insert/Replace mode
+       LPSTR title;
+       HWND hwndTel;
+       int ID;
+       int type;
+       int height;
+       int width;
+       int maxlines;       // Maximum number of scrollback lines
+       int backspace;
+       int ESscroll;       // Scroll screen when ES received
+       int VSIDC;          // Insert/Delete character mode 0=draw line
+       int DECAWM;         // AutoWrap mode 0=off
+       int IRM;            // Insert/Replace mode
 } CONFIG;
 
 #define TELNET_SCREEN   0
@@ -142,66 +131,190 @@ typedef struct CONFIG {
 
 #define DESIREDPOINTSIZE 12
 
+/*
+Prototypes
+*/
+       void NEAR InitializeStruct(
+               WORD wCommDlgType,
+               LPSTR lpStruct,
+               HWND hWnd);
+
+       void ScreenInit(
+               HANDLE hInstance);
+
+       void SetScreenInstance(
+               HINSTANCE hInstance);
+
+       SCREENLINE *ScreenNewLine();
+
+       void ScreenBell(
+               SCREEN *pScr);
+
+       void ScreenBackspace(
+               SCREEN *pScr);
+
+       void ScreenTab(
+               SCREEN *pScr);
+
+       void ScreenCarriageFeed(
+               SCREEN *pScr);
+
+       int ScreenScroll(
+               SCREEN *pScr);
+
+       void DeleteTopLine(
+               SCREEN *pScr);
+
+/*
+emul.c
+*/
+       void ScreenEm(
+               LPSTR c,
+               int len,
+               SCREEN *pScr);
+
+/*
+intern.c
+*/
+       SCREENLINE *GetScreenLineFromY(
+               SCREEN *pScr,
+               int y);
+
+       SCREENLINE *ScreenClearLine(
+               SCREEN *pScr,
+               SCREENLINE *pScrLine);
+
+       void ScreenUnscroll(
+               SCREEN *pScr);
+
+       void ScreenELO(
+               SCREEN *pScr,
+               int s);
+
+       void ScreenEraseScreen(
+               SCREEN *pScr);
+
+       void ScreenTabClear(
+               SCREEN *pScr);
+
+       void ScreenTabInit(
+               SCREEN *pScr);
+
+       void ScreenReset(
+               SCREEN *pScr);
+
+       void ScreenIndex(
+               SCREEN *pScr);
+
+       void ScreenWrapNow(
+               SCREEN *pScr,
+               int *xp,
+               int *yp);
+
+       void ScreenEraseToEOL(
+               SCREEN *pScr);
+
+       void ScreenEraseToBOL(
+               SCREEN *pScr);
+
+       void ScreenEraseLine(
+               SCREEN *pScr,
+               int s);
+
+       void ScreenEraseToEndOfScreen(
+               SCREEN *pScr);
+
+       void ScreenRange(
+               SCREEN *pScr);
+
+       void ScreenAlign(
+               SCREEN *pScr);
+
+       void ScreenApClear(
+               SCREEN *pScr);
+
+       int ScreenInsChar(
+               SCREEN *pScr,
+               int x);
+
+       void ScreenInsString(
+               SCREEN *pScr,
+               int len,
+               char *start);
+
+       void ScreenSaveCursor(
+               SCREEN *pScr);
+
+       void ScreenRestoreCursor(
+               SCREEN *pScr);
+
+       void ScreenDraw(
+               SCREEN *pScr,
+               int x,
+               int y,
+               int a,
+               int len,
+               char *c);
+
+       void ScreenCursorOff(
+               SCREEN *pScr);
+
+       void ScreenCursorOn(
+               SCREEN *pScr);
+
+       void ScreenDelChars(
+               SCREEN *pScr,
+               int n);
+
+       void ScreenRevIndex(
+               SCREEN *pScr);
+
+       void ScreenDelLines(
+               SCREEN *pScr,
+               int n,
+               int s);
+
+       void ScreenInsLines(
+               SCREEN *pScr,
+               int n,
+               int s);
+
+       #ifdef _DEBUG
+               BOOL CheckScreen(
+                       SCREEN *pScr);
+       #endif
+
+       void ProcessFontChange(
+               HWND hWnd);
+
+       void Edit_LbuttonDown(
+               HWND hWnd,
+               LPARAM lParam);
+
+       void Edit_LbuttonDblclk(
+               HWND hWnd,
+               LPARAM lParam);
+
+       void Edit_LbuttonUp(
+               HWND hWnd,
+               LPARAM lParam);
+
+       void Edit_TripleClick(
+               HWND hWnd,
+               LPARAM lParam);
+
+       void Edit_MouseMove(
+               HWND hWnd,
+               LPARAM lParam);
+
+       void Edit_ClearSelection(
+               SCREEN *pScr);
 
-void        ReportError(WORD);
-LPSTR NEAR AllocAndLockMem(HANDLE *hChunk, WORD wSize);
-void NEAR InitializeStruct(WORD wCommDlgType, LPSTR lpStruct, HWND hWnd);
-
-void ScreenInit(HANDLE hInstance);
-HSCREENLINE ScreenNewLine();
-void ScreenBell(SCREEN *fpScr);
-void ScreenBackspace(SCREEN * fpScr);
-void ScreenTab(SCREEN *fpScr);
-void ScreenCarriageFeed(SCREEN *fpScr);
-int ScreenScroll(SCREEN *fpScr);
-void DeleteTopLine(SCREEN *fpScr);
-/* emul.c */
-void ScreenEm(LPSTR c,int len,HSCREEN hsScr);
-
-
-/* intern.c */
-HSCREENLINE GetScreenLineFromY(SCREEN *fpScr,int y);
-HSCREENLINE ScreenClearLine(SCREEN *fpScr,HSCREENLINE hgScrLine);
-void ScreenUnscroll(SCREEN *fpScr);
-void ScreenELO(SCREEN *fpScr,int s);
-void ScreenEraseScreen(SCREEN *fpScr);
-void ScreenTabClear(SCREEN *fpScr);
-void ScreenTabInit(SCREEN *fpScr);
-void ScreenReset(SCREEN *fpScr);
-void ScreenIndex(SCREEN * fpScr);
-void ScreenWrapNow(SCREEN *fpScr,int *xp,int *yp);
-void ScreenEraseToEOL(SCREEN *fpScr);
-void ScreenEraseToBOL(SCREEN *fpScr);
-void ScreenEraseLine(SCREEN *fpScr,int s);
-void ScreenEraseToEndOfScreen(SCREEN *fpScr);
-void ScreenRange(SCREEN *fpScr);
-void ScreenAlign(SCREEN *fpScr);
-void ScreenApClear(SCREEN *fpScr);
-int ScreenInsChar(SCREEN *fpScr,int x);
-void ScreenInsString(SCREEN *fpScr,int len,char *start);
-void ScreenSaveCursor(SCREEN *fpScr);
-void ScreenRestoreCursor(SCREEN *fpScr);
-void ScreenDraw(SCREEN *fpScr,int x,int y,int a,int len,char *c);
-void ScreenCursorOff(SCREEN *fpScr);
-void ScreenCursorOn(SCREEN *fpScr);
-void ScreenDelChars(SCREEN *fpScr, int n);
-void ScreenRevIndex(SCREEN *fpScr);
-void ScreenDelLines(SCREEN *fpScr, int n, int s);
-void ScreenInsLines(SCREEN *fpScr, int n, int s);
-#ifdef _DEBUG
-       BOOL CheckScreen(SCREEN *fpScr);
-#endif
-
-void ProcessFontChange(HWND hWnd);
-void Edit_LbuttonDown(HWND hWnd,LPARAM lParam);
-void Edit_LbuttonDblclk(HWND hWnd,LPARAM lParam);
-void Edit_LbuttonUp(HWND hWnd, LPARAM lParam);
-void Edit_TripleClick(HWND hWnd, LPARAM lParam);
-void Edit_MouseMove(HWND hWnd, LPARAM lParam);
-void Edit_ClearSelection(SCREEN *fpScr);
-void Edit_Copy(HWND hWnd);
-void Edit_Paste(HWND hWnd);
-
-HSCREEN InitNewScreen(CONFIG *Config);
+       void Edit_Copy(
+               HWND hWnd);
 
+       void Edit_Paste(
+               HWND hWnd);
 
+       SCREEN *InitNewScreen(
+               CONFIG *Config);
index b31fa9a7c43b5000ec6963fa63acb5818b5fcdb9..cbea7850b85b2eb4acb48b8d86b9ca976dca1207 100644 (file)
@@ -9,12 +9,12 @@
 #define HCONNECTION HGLOBAL
 
 typedef struct CONNECTION {
-       HSCREEN hScreen; // handle to screen associated with connection
+       SCREEN *pScreen;        // handle to screen associated with connection
        kstream ks;
        SOCKET socket;
-       int pnum;       // port number associated with connection
-       int telstate;   // telnet state for this connection
-       int substate;   // telnet subnegotiation state
+       int pnum;                       // port number associated with connection
+       int telstate;           // telnet state for this connection
+       int substate;           // telnet subnegotiation state
        int termsent;
        int echo;
        int ugoahead;
@@ -22,9 +22,8 @@ typedef struct CONNECTION {
        int timing;
        int backspace;
        int ctrl_backspace;
-       int termstate;  // terminal type for this connection
+       int termstate;          // terminal type for this connection
        int width;
        int height;
        BOOL bResizeable;
 } CONNECTION;
-
index b69bca6fe82e3d00c95698350abab6ac35ee356f..ee4683e5846e2a2cef1e0a11b48656c145b30ef6 100644 (file)
@@ -1,46 +1,44 @@
 /****************************************************************************
 
-    PROGRAM: telnet.c
+       PROGRAM: telnet.c
 
-    PURPOSE: Windows networking kernel - Telnet
+       PURPOSE: Windows networking kernel - Telnet
 
-    FUNCTIONS:
+       FUNCTIONS:
 
-    WinMain() - calls initialization function, processes message loop
-    InitApplication() - initializes window data and registers window
-    InitInstance() - saves instance handle and creates main window
-    MainWndProc() - processes messages
-    About() - processes messages for "About" dialog box
+       WinMain() - calls initialization function, processes message loop
+       InitApplication() - initializes window data and registers window
+       InitInstance() - saves instance handle and creates main window
+       MainWndProc() - processes messages
+       About() - processes messages for "About" dialog box
 
-    COMMENTS:
+       COMMENTS:
 
-        Windows can have several copies of your application running at the
-        same time.  The variable hInst keeps track of which instance this
-        application is so that processing will be to the correct window.
+               Windows can have several copies of your application running at the
+               same time.  The variable hInst keeps track of which instance this
+               application is so that processing will be to the correct window.
 
 ****************************************************************************/
 
 #include <windows.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 #include "telnet.h"
 #include "auth.h"
 
-HANDLE hInst;                                   /* current instance      */
-HWND hWnd;                                      /* Main window handle.   */
-CONFIG *tmpConfig;
-GLOBALHANDLE hGlobalMem, hTitleMem;
-CONNECTION *con = NULL;
-char hostdata[MAXGETHOSTSTRUCT];
-HGLOBAL ghCon;
-SCREEN *fpScr;
-int debug = 1;
-
-char __near strTmp[1024];                       // Scratch buffer 
+static HANDLE hInst;
+static HWND hWnd;
+static CONFIG *tmpConfig;
+static CONNECTION *con = NULL;
+static char hostdata[MAXGETHOSTSTRUCT];
+static SCREEN *pScr;
+static int debug = 1;
 
+char __near strTmp[1024];                              // Scratch buffer
 BOOL bAutoConnection = FALSE; 
 int port_no = 23;
-char szUserName[64];                            // Used in auth.c
+char szUserName[64];                                   // Used in auth.c
 char szHostName[64];
 
 #ifdef KRB4
@@ -49,229 +47,238 @@ char szHostName[64];
 
 #ifdef KRB5
        krb5_context k5_context;
-    #define WINDOW_CLASS   "K5_telnetWClass"
+       #define WINDOW_CLASS   "K5_telnetWClass"
 #endif
 
 /*+**************************************************************************
 
-    FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
+       FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
 
-    PURPOSE: calls initialization function, processes message loop
+       PURPOSE: calls initialization function, processes message loop
 
-    COMMENTS:
+       COMMENTS:
 
-        Windows recognizes this function by name as the initial entry point 
-        for the program.  This function calls the application initialization 
-        routine, if no other instance of the program is running, and always 
-        calls the instance initialization routine.  It then executes a message 
-        retrieval and dispatch loop that is the top-level control structure 
-        for the remainder of execution.  The loop is terminated when a WM_QUIT 
-        message is received, at which time this function exits the application 
-        instance by returning the value passed by PostQuitMessage(). 
+               Windows recognizes this function by name as the initial entry point 
+               for the program.  This function calls the application initialization 
+               routine, if no other instance of the program is running, and always 
+               calls the instance initialization routine.  It then executes a message 
+               retrieval and dispatch loop that is the top-level control structure 
+               for the remainder of execution.  The loop is terminated when a WM_QUIT 
+               message is received, at which time this function exits the application 
+               instance by returning the value passed by PostQuitMessage(). 
 
-        If this function must abort before entering the message loop, it 
-        returns the conventional value NULL.  
+               If this function must abort before entering the message loop, it 
+               returns the conventional value NULL.  
 
 ****************************************************************************/
 
-int PASCAL
-WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
-HANDLE hInstance;                /* current instance             */
-HANDLE hPrevInstance;            /* previous instance            */
-LPSTR lpCmdLine;                 /* command line                 */
-int nCmdShow;                    /* show-window type (open/icon) */
+int PASCAL WinMain(
+       HANDLE hInstance,                                       // current instance
+       HANDLE hPrevInstance,                           // previous instance
+       LPSTR lpCmdLine,                                        // command line
+       int nCmdShow)                                           // show-window type (open/icon)
 {
-    MSG msg;                     /* message                      */
+       MSG msg;
 
-    if (!hPrevInstance)
-       if (!InitApplication(hInstance)) /* Initialize shared things */
-               return (FALSE);      /* Exits if unable to initialize    */
+       if (!hPrevInstance)
+               if (!InitApplication(hInstance))
+                       return(FALSE);
 
-    /* Perform initializations that apply to a specific instance */
+       /*
+       Perform initializations that apply to a specific instance
+       */
+       bAutoConnection = parse_cmdline(lpCmdLine);
 
-    bAutoConnection = parse_cmdline (lpCmdLine);
-       
-    if (!InitInstance(hInstance, nCmdShow))
-        return (FALSE);
+       if (!InitInstance(hInstance, nCmdShow))
+               return(FALSE);
 
-    /* Acquire and dispatch messages until a WM_QUIT message is received. */
+       /*
+       Acquire and dispatch messages until a WM_QUIT message is received.
+       */
+       while (GetMessage(&msg, NULL, NULL, NULL)) {
+               TranslateMessage(&msg);
+               DispatchMessage(&msg);
+       }
+
+       return (msg.wParam);                            // Returns the value from PostQuitMessage
 
-    while (GetMessage(&msg, NULL, NULL, NULL)) {
-        TranslateMessage(&msg); /* Translates virtual key codes  */
-        DispatchMessage(&msg);  /* Dispatches message to window  */
-    }
-    return (msg.wParam);    /* Returns the value from PostQuitMessage */
-}
+} /* WinMain */
 
 
 /*+**************************************************************************
 
-    FUNCTION: InitApplication(HANDLE)
+       FUNCTION: InitApplication(HANDLE)
 
-    PURPOSE: Initializes window data and registers window class
+       PURPOSE: Initializes window data and registers window class
 
-    COMMENTS:
+       COMMENTS:
 
-        This function is called at initialization time only if no other 
-        instances of the application are running.  This function performs 
-        initialization tasks that can be done once for any number of running 
-        instances.  
+               This function is called at initialization time only if no other 
+               instances of the application are running.  This function performs 
+               initialization tasks that can be done once for any number of running 
+               instances.  
 
-        In this case, we initialize a window class by filling out a data 
-        structure of type WNDCLASS and calling the Windows RegisterClass() 
-        function.  Since all instances of this application use the same window 
-        class, we only need to do this when the first instance is initialized.  
+               In this case, we initialize a window class by filling out a data 
+               structure of type WNDCLASS and calling the Windows RegisterClass() 
+               function.  Since all instances of this application use the same window 
+               class, we only need to do this when the first instance is initialized.  
 
 
 ****************************************************************************/
 
-BOOL
-InitApplication(hInstance)
-HANDLE hInstance;                  /* current instance       */
+BOOL InitApplication(
+       HANDLE hInstance)
 {
-    WNDCLASS  wc;
+       WNDCLASS  wc;
 
        ScreenInit(hInstance);
 
-    /* Fill in window class structure with parameters that describe the       */
-    /* main window.                                                           */
+       /*
+       Fill in window class structure with parameters that describe the
+       main window.
+       */
+       wc.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
+       wc.lpfnWndProc = MainWndProc;       // Function to retrieve messages for
+                                                                               // windows of this class.
+       wc.cbClsExtra = 0;                  // No per-class extra data.
+       wc.cbWndExtra = 0;                  // No per-window extra data.
+       wc.hInstance = hInstance;           // Application that owns the class.
+       wc.hIcon = NULL;                                        // LoadIcon(hInstance, "NCSA");
+       wc.hCursor = NULL;                                      // Cursor(NULL, IDC_ARROW);
+       wc.hbrBackground = NULL;                        // GetStockObject(WHITE_BRUSH); 
+       wc.lpszMenuName =  NULL;                        // Name of menu resource in .RC file.
+       wc.lpszClassName = WINDOW_CLASS;    // Name used in call to CreateWindow.
 
-    wc.style = CS_HREDRAW|CS_VREDRAW;   /* Class style(s).                    */
-    wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  */
-                                        /* windows of this class.             */
-    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
-    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
-    wc.hInstance = hInstance;           /* Application that owns the class.   */
-    wc.hIcon = NULL; //LoadIcon(hInstance, "NCSA");
-    wc.hCursor = NULL; //Cursor(NULL, IDC_ARROW);
-    wc.hbrBackground = NULL; //GetStockObject(WHITE_BRUSH); 
-    wc.lpszMenuName =  NULL;   /* Name of menu resource in .RC file. */
-    wc.lpszClassName = WINDOW_CLASS;    /* Name used in call to CreateWindow. */
+       return(RegisterClass(&wc));
 
-    /* Register the window class and return success/failure code. */
-    return (RegisterClass(&wc));
-}
+} /* InitApplication */
 
 
 /*+**************************************************************************
 
-    FUNCTION:  InitInstance(HANDLE, int)
+       FUNCTION:  InitInstance(HANDLE, int)
 
-    PURPOSE:  Saves instance handle and creates main window
+       PURPOSE:  Saves instance handle and creates main window
 
-    COMMENTS:
+       COMMENTS:
 
-        This function is called at initialization time for every instance of 
-        this application.  This function performs initialization tasks that 
-        cannot be shared by multiple instances.  
+               This function is called at initialization time for every instance of 
+               this application.  This function performs initialization tasks that 
+               cannot be shared by multiple instances.  
 
-        In this case, we save the instance handle in a static variable and 
-        create and display the main program window.  
-        
+               In this case, we save the instance handle in a static variable and 
+               create and display the main program window.  
+               
 ****************************************************************************/
-BOOL
-InitInstance(hInstance, nCmdShow)
-    HANDLE          hInstance;          /* Current instance identifier.       */
-    int             nCmdShow;           /* Param for first ShowWindow() call. */
+
+BOOL InitInstance(
+       HANDLE hInstance,
+       int nCmdShow)
 {
-    int xScreen = 0, yScreen = 0;
-
-    /* Save the instance handle in static variable, which will be used in  */
-    /* many subsequence calls from this application to Windows.            */
-
-    hInst = hInstance;
-
-    /* Create a main window for this application instance.  */
-    hWnd = CreateWindow(
-        WINDOW_CLASS,                   /* See RegisterClass() call.          */
-        "TCPWin",                       /* Text for window title bar.         */
-        WS_SYSMENU,                     /* Window style.                      */
-        xScreen/3,                      /* Default horizontal position.       */
-        yScreen/3,                      /* Default vertical position.         */
-        xScreen/3,                      /* Default width.                     */
-        yScreen/3,                      /* Default height.                    */
-        NULL,                           /* Overlapped windows have no parent. */
-        NULL,                           /* Use the window class menu.         */
-        hInstance,                      /* This instance owns this window.    */
-        NULL                            /* Pointer not needed.                */
-    );
-    if (!hWnd)
-        return (FALSE);
-        
-//    ShowWindow(hWnd, SW_SHOW);   /* Show the window   */
-//    UpdateWindow(hWnd);          /* Sends WM_PAINT message      */        
-
-    {
-        WSADATA wsaData;
-        if (WSAStartup(0x0101, &wsaData) != 0) {   /* Initialize the network */
-               MessageBox(NULL, "Couldn't initialize Winsock!", 
-                NULL, MB_OK | MB_ICONEXCLAMATION);
-               return FALSE;
-               }               
-    }
-
-       if (! OpenTelnetConnection()) {
+       int xScreen = 0;
+       int yScreen = 0;
+       WSADATA wsaData;
+
+       SetScreenInstance(hInstance);
+
+       /*
+       Save the instance handle in static variable, which will be used in
+       many subsequence calls from this application to Windows.
+       */
+       hInst = hInstance;
+
+       /*
+       Create a main window for this application instance.
+       */
+       hWnd = CreateWindow(
+               WINDOW_CLASS,                                   // See RegisterClass() call.          
+               "TCPWin",                                               // Text for window title bar.         
+               WS_SYSMENU,                                             // Window style.                      
+               xScreen / 3,                                    // Default horizontal position.       
+               yScreen / 3,                                    // Default vertical position.         
+               xScreen / 3,                                    // Default width.                     
+               yScreen / 3,                                    // Default height.                    
+               NULL,                                                   // Overlapped windows have no parent. 
+               NULL,                                                   // Use the window class menu.         
+               hInstance,                                              // This instance owns this window.    
+               NULL);                                                  // Pointer not needed.                
+
+       if (!hWnd)
+               return (FALSE);
+               
+       if (WSAStartup(0x0101, &wsaData) != 0) {   /* Initialize the network */
+           MessageBox(NULL, "Couldn't initialize Winsock!", NULL,
+                       MB_OK | MB_ICONEXCLAMATION);
+           return(FALSE);
+       }               
+
+       if (!OpenTelnetConnection()) {
                WSACleanup();
                return(FALSE);
        }
 
-    #ifdef KRB5
+       #ifdef KRB5
                krb5_init_context(&k5_context);
                krb5_init_ets(k5_context);
-    #endif
-    return (TRUE);
-}
+       #endif
+
+       return (TRUE);
+
+} /* InitInstance */
+
 
 /*+***************************************************************************
 
-    FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
+       FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
 
-    PURPOSE:  Processes messages
+       PURPOSE:  Processes messages
 
-    MESSAGES:
+       MESSAGES:
 
-    WM_COMMAND    - application menu (About dialog box)
-    WM_DESTROY    - destroy window
+       WM_COMMAND    - application menu (About dialog box)
+       WM_DESTROY    - destroy window
 
 ****************************************************************************/
 
-long FAR PASCAL
-MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
-    HSCREEN hgScr;
-    SCREEN *fpScr;
-    HGLOBAL hBuffer;
-    LPSTR lpBuffer; 
-    char c;
-    int iEvent, namelen, cnt, ret;
-    char buf[1024];
-    struct sockaddr_in name;
+long FAR PASCAL MainWndProc(
+       HWND hWnd,
+       UINT message,
+       WPARAM wParam,
+       LPARAM lParam)
+{
+       HGLOBAL hBuffer;
+       LPSTR lpBuffer; 
+       char c;
+       int iEvent, namelen, cnt, ret;
+       char buf[1024];
+       struct sockaddr_in name;
        struct sockaddr_in remote_addr;
        struct hostent *remote_host;
        char *tmpCommaLoc;
-    
-    switch (message) {
+       
+       switch (message) {
 
        case WM_MYSCREENCHANGEBKSP:
-           if (!con) break;
+           if (!con)
+                       break;
            con->backspace = wParam;
            if (con->backspace == VK_BACK) {
                con->ctrl_backspace = 0x7f;
                        WritePrivateProfileString(INI_TELNET, INI_BACKSPACE, 
-                INI_BACKSPACE_BS, TELNET_INI);
+                               INI_BACKSPACE_BS, TELNET_INI);
                }
            else {
                con->ctrl_backspace = VK_BACK;
                        WritePrivateProfileString(INI_TELNET, INI_BACKSPACE, 
-                INI_BACKSPACE_DEL, TELNET_INI);
+                               INI_BACKSPACE_DEL, TELNET_INI);
                }
-               GetPrivateProfileString(INI_HOSTS, INI_HOST "0", "", buf, 128, 
-            TELNET_INI);
-               tmpCommaLoc = strchr(buf, ',');
-        if (tmpCommaLoc == NULL) {
-            strcat (buf, ",");
-            tmpCommaLoc = strchr(buf, ',');
-        }
-               if (tmpCommaLoc) {
+               GetPrivateProfileString(INI_HOSTS, INI_HOST "0", "", buf, 128, TELNET_INI);
+               tmpCommaLoc = strchr(buf, ',');
+               if (tmpCommaLoc == NULL) {
+                       strcat (buf, ",");
+                       tmpCommaLoc = strchr(buf, ',');
+               }
+               if (tmpCommaLoc) {
                        tmpCommaLoc++;
                        if (con->backspace == VK_BACK)
                                strcpy(tmpCommaLoc, INI_HOST_BS);
@@ -282,41 +289,42 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
            break;
 
        case WM_MYSCREENCHAR:
-           if (!con) break;
-           if (wParam == VK_BACK)
+               if (!con)
+                       break;
+               if (wParam == VK_BACK)
                wParam = con->backspace;
-               else
-               if (wParam == 0x7f)
-                   wParam = con->ctrl_backspace;
-           TelnetSend(con->ks, (char *)&wParam, 1, NULL);
+               else if (wParam == 0x7f)
+                       wParam = con->ctrl_backspace;
+           TelnetSend(con->ks, (char *) &wParam, 1, NULL);
            break;
-       
+
        case WM_MYSYSCHAR:
-           if (!con) break;
+           if (!con)
+                       break;
            c = (char) wParam;
+
            switch (c) {
-               case 'f':
-                   getsockname(con->socket, (struct sockaddr *) &name, 
-                    (int *) &namelen);
-                   wsprintf(buf, "ftp %d.%d.%d.%d\n", 
-                       name.sin_addr.S_un.S_un_b.s_b1, 
-                       name.sin_addr.S_un.S_un_b.s_b2, 
-                       name.sin_addr.S_un.S_un_b.s_b3, 
-                       name.sin_addr.S_un.S_un_b.s_b4);
-                   TelnetSend(con->ks, buf, lstrlen(buf), NULL);
-                   break;                
-               case 'x':
-                   hgScr = con->hScreen;
-                   fpScr = (SCREEN *) GlobalLock(hgScr);
-                   if (fpScr == NULL) break;
-                   PostMessage(fpScr->hWnd, WM_CLOSE, NULL, NULL);
-                   break;
-                                   
-           }                
+
+               case 'f':
+                       getsockname(con->socket, (struct sockaddr *) &name, (int *) &namelen);
+                       wsprintf(buf, "ftp %d.%d.%d.%d\n", 
+                               name.sin_addr.S_un.S_un_b.s_b1, 
+                               name.sin_addr.S_un.S_un_b.s_b2, 
+                               name.sin_addr.S_un.S_un_b.s_b3, 
+                               name.sin_addr.S_un.S_un_b.s_b4);
+                       TelnetSend(con->ks, buf, lstrlen(buf), NULL);
+                       break;                
+
+               case 'x':
+                       PostMessage(con->pScreen->hWnd, WM_CLOSE, NULL, NULL);
+                       break;
+           }
+
            break;
                
        case WM_MYSCREENBLOCK:
-           if (!con) break;
+           if (!con)
+                       break;
            hBuffer = (HGLOBAL) wParam;
            lpBuffer = GlobalLock(hBuffer);
            TelnetSend(con->ks, lpBuffer, lstrlen(lpBuffer), NULL);
@@ -324,7 +332,8 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
            break;
 
        case WM_MYSCREENCLOSE:
-           if (!con) break;
+           if (!con)
+                       break;
            kstream_destroy(con->ks);
                DestroyWindow(hWnd);
            break;        
@@ -335,8 +344,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
 
        case WM_DESTROY:          /* message: window being destroyed */
            kstream_destroy(con->ks);
-           GlobalUnlock(ghCon);
-           GlobalFree(ghCon); 
+               free(con);
            WSACleanup();
            PostQuitMessage(0);
            break;
@@ -355,13 +363,12 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
                        /* cnt = kstream_read(con->ks, buf, 1024); */
                buf[cnt] = 0;
                parse((CONNECTION *) con, (unsigned char *) buf, cnt);
-               ScreenEm(buf, cnt, con->hScreen);
+               ScreenEm(buf, cnt, con->pScreen);
                break;
 
            case FD_CLOSE:
                        kstream_destroy(con->ks);
-                       GlobalUnlock(ghCon);
-                       GlobalFree(ghCon); 
+                       free(con);
                        WSACleanup();
                        PostQuitMessage(0);
                        break;
@@ -370,10 +377,9 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
                        ret = WSAGETSELECTERROR(lParam);
                        if (ret) {
                                wsprintf(buf, "Error %d on Connect", ret);
-                       MessageBox(NULL, buf, NULL, MB_OK|MB_ICONEXCLAMATION);
+                       MessageBox(NULL, buf, NULL, MB_OK | MB_ICONEXCLAMATION);
                                kstream_destroy(con->ks);
-                               GlobalUnlock(ghCon);
-                               GlobalFree(ghCon); 
+                               free(con);
                                WSACleanup();
                                PostQuitMessage(0);
                                break;
@@ -381,35 +387,36 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
                        start_negotiation(con->ks);
                        break;          
            }
+
            break;              
 
        case WM_HOSTNAMEFOUND:
                ret = WSAGETASYNCERROR(lParam);
                if (ret) {
                        wsprintf(buf, "Error %d on GetHostbyName", ret);
-               MessageBox(NULL, buf, NULL, MB_OK|MB_ICONEXCLAMATION);
+                       MessageBox(NULL, buf, NULL, MB_OK | MB_ICONEXCLAMATION);
                    kstream_destroy(con->ks);
-                   GlobalUnlock(ghCon);
-                   GlobalFree(ghCon); 
+                       free(con);
                    WSACleanup();
                    PostQuitMessage(0);
-               break;
-        }
-        remote_host = (struct hostent *) hostdata;
-               remote_addr.sin_family = AF_INET;    
+                       break;
+               }
+
+               remote_host = (struct hostent *) hostdata;
+               remote_addr.sin_family = AF_INET;
                remote_addr.sin_addr.S_un.S_un_b.s_b1 = remote_host->h_addr[0];
                remote_addr.sin_addr.S_un.S_un_b.s_b2 = remote_host->h_addr[1];
                remote_addr.sin_addr.S_un.S_un_b.s_b3 = remote_host->h_addr[2];
                remote_addr.sin_addr.S_un.S_un_b.s_b4 = remote_host->h_addr[3];
-        remote_addr.sin_port = htons(port_no);
+               remote_addr.sin_port = htons(port_no);
                
-               connect(con->socket, (struct sockaddr*) &remote_addr, 
-                       sizeof(struct sockaddr));    
+               connect(con->socket, (struct sockaddr *) &remote_addr, 
+                       sizeof(struct sockaddr));
                break;
 
        case WM_MYSCREENSIZE:
-               con->width = LOWORD(lParam);                    /* width in characters */
-               con->height = HIWORD(lParam);           /* height in characters */
+               con->width = LOWORD(lParam);            // width in characters
+               con->height = HIWORD(lParam);           // height in characters
                if (con->bResizeable && con->ks)
                        send_naws(con);
                wsprintf(buf, "%d", con->height);
@@ -418,187 +425,181 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
                WritePrivateProfileString(INI_TELNET, INI_WIDTH, buf, TELNET_INI);
            break;
                
-       default:              /* Passes it on if unproccessed    */
+       default:                                                // Passes it on if unproccessed
            return(DefWindowProc(hWnd, message, wParam, lParam));
-    }
-    return (NULL);
-}
+       }
+       return (NULL);
+
+} /* MainWndProc */
 
 
 /*+***************************************************************************
 
-    FUNCTION: SaveHostName(hostname, port)
+       FUNCTION: SaveHostName(hostname, port)
 
-    PURPOSE: Saves the currently selected host name and port number
-        in the KERBEROS.INI file and returns the preferred backspace
-        setting if one exists for that host.
+       PURPOSE: Saves the currently selected host name and port number
+               in the KERBEROS.INI file and returns the preferred backspace
+               setting if one exists for that host.
 
        RETURNS: VK_BACK or 0x7f depending on the desired backspace setting.
 
 ****************************************************************************/
 
-int
-SaveHostName (char *host, int port)
+int SaveHostName(
+       char *host,
+       int port)
 {
-    char buf[128];                              // Scratch buffer
-    char fullhost[128];                         // Host & port combination
-       char hostName[10][128];                     // Entries from INI files
-       char *comma;                                // For parsing del/bs info
-    int len;                                    // Length of fullhost
-       int n;                                      // Number of items written
-    int i;                                      // Index
-       int bs;                                     // What we return
-
-    if (port == 23)                             // Default telnet port
-        strcpy (fullhost, host);                // ...then don't add it on
-    else
-        wsprintf (fullhost, "%s %d", host, port);
-    len = strlen (fullhost);
-
-    comma = NULL;
-    for (i = 0; i < 10; i++) {
-        wsprintf(buf, INI_HOST "%d", i); // INI item to fetch
-        GetPrivateProfileString(INI_HOSTS, buf, "", hostName[i], 
-            128, TELNET_INI);
+       char buf[128];                                          // Scratch buffer
+       char fullhost[128];                                     // Host & port combination
+       char hostName[10][128];                         // Entries from INI files
+       char *comma;                                            // For parsing del/bs info
+       int len;                                                        // Length of fullhost
+       int n;                                                          // Number of items written
+       int i;                                                          // Index
+       int bs;                                                         // What we return
+
+       if (port == 23)                                         // Default telnet port
+               strcpy(fullhost, host);                 // ...then don't add it on
+       else
+               wsprintf(fullhost, "%s %d", host, port);
+       len = strlen(fullhost);
+
+       comma = NULL;
+       for (i = 0; i < 10; i++) {
+               wsprintf(buf, INI_HOST "%d", i); // INI item to fetch
+               GetPrivateProfileString(INI_HOSTS, buf, "", hostName[i], 
+                       128, TELNET_INI);
 
                if (!hostName[i][0])
                        break;
 
-        if (strncmp (hostName[i], fullhost, len)) // A match??
-            continue;                           // Nope, keep going
-        comma = strchr (hostName[i], ',');
-    }
+               if (strncmp (hostName[i], fullhost, len))       // A match??
+                       continue;                                                               // Nope, keep going
+               comma = strchr (hostName[i], ',');
+       }
 
-    if (comma) {
-        ++comma;                                // Past the comma
-        while (*comma == ' ')                   // Past leading white space
-            ++comma;
-        bs = VK_BACK;                           // Default for unknown entry
+       if (comma) {
+               ++comma;                                                // Past the comma
+               while (*comma == ' ')                   // Past leading white space
+                       ++comma;
+               bs = VK_BACK;                                   // Default for unknown entry
                if (_stricmp(comma, INI_HOST_DEL) == 0)
                        bs = 0x7f;
        }
-    else {                                      // No matching entry
+       else {                                                          // No matching entry
            GetPrivateProfileString(INI_TELNET, INI_BACKSPACE, INI_BACKSPACE_BS, 
                        buf, sizeof(buf), TELNET_INI);
-        bs = VK_BACK;                           // Default value
+               bs = VK_BACK;                                   // Default value
                if (_stricmp(buf, INI_BACKSPACE_DEL) == 0)
                        bs = 0x7f;
        }
 
-    /*
-    ** Build up default host name
-    */
+       /*
+       ** Build up default host name
+       */
        strcpy(buf, fullhost);
        strcat(buf, ", ");
-    strcat(buf, (bs == VK_BACK) ? INI_BACKSPACE_BS : INI_BACKSPACE_DEL);
+       strcat(buf, (bs == VK_BACK) ? INI_BACKSPACE_BS : INI_BACKSPACE_DEL);
        WritePrivateProfileString(INI_HOSTS, INI_HOST "0", buf, TELNET_INI);
 
        n = 0;
-    for (i = 0; i < 10; i++) {
-               if (!hostName[i][0])                    // End of the list?
+       for (i = 0; i < 10; i++) {
+               if (!hostName[i][0])                    // End of the list?
                        break;
-        if (strncmp(hostName[i], fullhost, len) != 0) {
+               if (strncmp(hostName[i], fullhost, len) != 0) {
                wsprintf(buf, INI_HOST "%d", ++n);
-                       WritePrivateProfileString(INI_HOSTS, buf, hostName[i], 
-                TELNET_INI);
+                       WritePrivateProfileString(INI_HOSTS, buf, hostName[i], TELNET_INI);
                }
-    }
-       return bs;
-}
-
-/*+*/
-int
-OpenTelnetConnection(void) {
-    int nReturn, ret;
-    struct sockaddr_in sockaddr;
+       }
+       return(bs);
+
+} /* SaveHostName */
+
+
+int OpenTelnetConnection(void)
+{
+       int nReturn, ret;
+       struct sockaddr_in sockaddr;
        char *p;
        static struct kstream_crypt_ctl_block ctl;
-    char buf[128];
-
-    hGlobalMem = GlobalAlloc(GPTR, sizeof(CONFIG));
-    tmpConfig = (CONFIG *) GlobalLock(hGlobalMem);
-    
-    if (bAutoConnection) {
-               hTitleMem = GlobalAlloc(GPTR, lstrlen(szHostName));
-               tmpConfig->title = (char *) GlobalLock(hTitleMem);            
+       char buf[128];
+
+       tmpConfig = calloc(sizeof(CONFIG), 1);
+       
+       if (bAutoConnection) {
+               tmpConfig->title = calloc(lstrlen(szHostName), 1);
                lstrcpy(tmpConfig->title, (char *) szHostName);
-    } else {
-       nReturn = DoDialog("OPENTELNETDLG", OpenTelnetDlg);
-       if (nReturn == FALSE) return(FALSE);
+       } else {
+               nReturn = DoDialog("OPENTELNETDLG", OpenTelnetDlg);
+               if (nReturn == FALSE)
+                       return(FALSE);
        }
-                       
-    con = (CONNECTION *) GetNewConnection();
-    if (con == NULL) return(0);
-
-       tmpConfig->width = GetPrivateProfileInt(INI_TELNET, INI_WIDTH, 
-        DEF_WIDTH, TELNET_INI);
-       tmpConfig->height = GetPrivateProfileInt(INI_TELNET, INI_HEIGHT, 
-        DEF_HEIGHT, TELNET_INI);
+                                               
+       con = (CONNECTION *) GetNewConnection();
+       if (con == NULL)
+               return(0);
+
+       tmpConfig->width =
+               GetPrivateProfileInt(INI_TELNET, INI_WIDTH, DEF_WIDTH, TELNET_INI);
+
+       tmpConfig->height =
+               GetPrivateProfileInt(INI_TELNET, INI_HEIGHT, DEF_HEIGHT, TELNET_INI);
        con->width = tmpConfig->width;
        con->height = tmpConfig->height;
 
        con->backspace = SaveHostName(tmpConfig->title, port_no);
 
        if (con->backspace == VK_BACK) {
-        tmpConfig->backspace = TRUE;
-        con->ctrl_backspace = 0x7f;
-    } else {
-        tmpConfig->backspace = FALSE;
-        con->ctrl_backspace = 0x08;
+               tmpConfig->backspace = TRUE;
+               con->ctrl_backspace = 0x7f;
+       } else {
+               tmpConfig->backspace = FALSE;
+               con->ctrl_backspace = 0x08;
        }
 
-    tmpConfig->hwndTel = hWnd;
-    con->hScreen = (HSCREEN) InitNewScreen((CONFIG *) tmpConfig);
-    if (!(con->hScreen)) {
-       OutputDebugString("Failed to initialize new screen! \r\n");
-        GlobalUnlock(con->hScreen);
-        GlobalUnlock(ghCon);
-        GlobalFree(ghCon);
-        GlobalUnlock(hGlobalMem); 
-        GlobalFree(hGlobalMem);
-        return(-1);
-    }
-
-    ret = (SOCKET) socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-    
-    if (ret == SOCKET_ERROR) {
-        wsprintf(buf, "Socket error on socket = %d!", WSAGetLastError());
-        MessageBox(NULL, buf, NULL, MB_OK|MB_ICONEXCLAMATION);
-        fpScr = (SCREEN *) GlobalLock(con->hScreen);
-        if (fpScr != NULL)
-               DestroyWindow(fpScr->hWnd);
-        GlobalUnlock(con->hScreen);
-        GlobalUnlock(ghCon);
-        GlobalFree(ghCon);
-        GlobalUnlock(hGlobalMem);
-        GlobalFree(hGlobalMem);
-        return(-1);
-    } 
-    
-    con->socket = ret;
-    
-    sockaddr.sin_family = AF_INET ;  
-    sockaddr.sin_addr.s_addr = htonl( INADDR_ANY );
-    sockaddr.sin_port = htons( 0 ) ;
-    
-    ret = bind(con->socket, (struct sockaddr *) &sockaddr, 
-        (int) sizeof(struct sockaddr_in));
-    
-    if (ret == SOCKET_ERROR) {
-        wsprintf(buf, "Socket error on bind!");
-        MessageBox(NULL, buf, NULL, MB_OK|MB_ICONEXCLAMATION);
-        fpScr = (SCREEN *) GlobalLock(con->hScreen);
-        if (fpScr != NULL)
-               DestroyWindow(fpScr->hWnd);
-        GlobalUnlock(con->hScreen);
-        GlobalUnlock(ghCon);
-        GlobalFree(ghCon);
-        GlobalUnlock(hGlobalMem);
-        GlobalFree(hGlobalMem);
-        return(-1);
-    }
-    WSAAsyncSelect(con->socket, hWnd, WM_NETWORKEVENT, 
-        FD_READ | FD_CLOSE | FD_CONNECT);
+       tmpConfig->hwndTel = hWnd;
+       con->pScreen = InitNewScreen(tmpConfig);
+       if (!con->pScreen) {
+               assert(FALSE);
+               free(con->pScreen);
+               free(con);
+               free(tmpConfig);
+               return(-1);
+       }
+
+       ret = (SOCKET) socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+       
+       if (ret == SOCKET_ERROR) {
+               wsprintf(buf, "Socket error on socket = %d!", WSAGetLastError());
+               MessageBox(NULL, buf, NULL, MB_OK | MB_ICONEXCLAMATION);
+               if (con->pScreen != NULL)
+                       DestroyWindow(con->pScreen->hWnd);
+               free(con);
+               free(tmpConfig);
+               return(-1);
+       } 
+       
+       con->socket = ret;
+       
+       sockaddr.sin_family = AF_INET;  
+       sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+       sockaddr.sin_port = htons(0);
+       
+       ret = bind(con->socket, (struct sockaddr *) &sockaddr, 
+                       (int) sizeof(struct sockaddr_in));
+       
+       if (ret == SOCKET_ERROR) {
+               wsprintf(buf, "Socket error on bind!");
+               MessageBox(NULL, buf, NULL, MB_OK | MB_ICONEXCLAMATION);
+               if (con->pScreen != NULL)
+                       DestroyWindow(con->pScreen->hWnd);
+               free(con);
+               free(tmpConfig);
+               return(-1);
+       }
+
+       WSAAsyncSelect(con->socket, hWnd, WM_NETWORKEVENT,
+               FD_READ | FD_CLOSE | FD_CONNECT);
 
        lstrcpy(szHostName, tmpConfig->title);
        p = strchr(szHostName, '@');
@@ -609,16 +610,12 @@ OpenTelnetConnection(void) {
        }
 
        WSAAsyncGetHostByName(hWnd, WM_HOSTNAMEFOUND, szHostName, hostdata, 
-        MAXGETHOSTSTRUCT); 
-    GlobalUnlock(con->hScreen);
-//    GlobalUnlock(ghCon);
-//    GlobalFree(ghCon);
-    GlobalUnlock(hGlobalMem);
-    GlobalFree(hGlobalMem);
+               MAXGETHOSTSTRUCT); 
+       free(tmpConfig);
 
        ctl.encrypt = auth_encrypt;
        ctl.decrypt = auth_decrypt;
-       ctl.init    = auth_init;
+       ctl.init = auth_init;
        ctl.destroy = auth_destroy;
 
        con->ks = kstream_create_from_fd(con->socket, &ctl, NULL);
@@ -628,131 +625,142 @@ OpenTelnetConnection(void) {
        if (con->ks == NULL)
                return(-1);
 
-    return(1);
-}
-
-/*+*/
-CONNECTION *
-GetNewConnection(void) {
-    CONNECTION *fpCon;
-
-    ghCon = GlobalAlloc(GHND, sizeof(CONNECTION));
-    if (ghCon == NULL) return NULL;
-    fpCon = (CONNECTION *) GlobalLock(ghCon);
-    if (fpCon == NULL) return NULL;
-    fpCon->backspace = TRUE;
-       fpCon->bResizeable = TRUE;
-    return(fpCon);
-}
-   
-/*+***************************************************************************/
-int NEAR
-DoDialog(char *szDialog, FARPROC lpfnDlgProc) {
-    int nReturn;
-    
-    lpfnDlgProc = MakeProcInstance(lpfnDlgProc, hInst);
-    if (lpfnDlgProc == NULL)
-        MessageBox(hWnd, "Couldn't make procedure instance", NULL, MB_OK);    
-    
-    nReturn = DialogBox(hInst, szDialog, hWnd, lpfnDlgProc);
-    FreeProcInstance(lpfnDlgProc);
-    return (nReturn);
-}    
+       return(1);
+
+} /* OpenTelnetConnection */
+
+
+CONNECTION *GetNewConnection(void)
+{
+       CONNECTION *pCon;
+
+       pCon = calloc(sizeof(CONNECTION), 1);
+       if (pCon == NULL)
+               return NULL;
+       pCon->backspace = TRUE;
+       pCon->bResizeable = TRUE;
+       return(pCon);
+
+} /* GetNewConnection */
+
+
+int NEAR DoDialog(
+       char *szDialog,
+       FARPROC lpfnDlgProc)
+{
+       int nReturn;
+       
+       lpfnDlgProc = MakeProcInstance(lpfnDlgProc, hInst);
+       if (lpfnDlgProc == NULL)
+               MessageBox(hWnd, "Couldn't make procedure instance", NULL, MB_OK);    
+       
+       nReturn = DialogBox(hInst, szDialog, hWnd, lpfnDlgProc);
+       FreeProcInstance(lpfnDlgProc);
+       return (nReturn);
+
+} /* DoDialog */
+
 
 /*+***************************************************************************
 
-    FUNCTION: OpenTelnetDlg(HWND, unsigned, WORD, LONG)
+       FUNCTION: OpenTelnetDlg(HWND, unsigned, WORD, LONG)
 
-    PURPOSE:  Processes messages for "Open New Telnet Connection" dialog box
+       PURPOSE:  Processes messages for "Open New Telnet Connection" dialog box
 
-    MESSAGES:
+       MESSAGES:
 
-    WM_INITDIALOG - initialize dialog box
-    WM_COMMAND    - Input received
+       WM_INITDIALOG - initialize dialog box
+       WM_COMMAND    - Input received
 
 ****************************************************************************/
 
-BOOL FAR PASCAL
-OpenTelnetDlg(HWND hDlg, WORD message, WORD wParam, LONG lParam) {
-    char szConnectName[256];
-    HDC  hDC;
-    int  xExt, yExt;
-    DWORD Ext;
-    HWND hEdit;
-    int  n;
-    int iHostNum = 0;
-    char tmpName[128], tmpBuf[80];
-    char *tmpCommaLoc;
-    
-    switch (message) {
-        case WM_INITDIALOG:        /* message: initialize dialog box */
-            hDC = GetDC(hDlg);
-            Ext = GetDialogBaseUnits();
-            xExt = (190 *LOWORD(Ext)) /4 ;
-            yExt = (72 * HIWORD(Ext)) /8 ;
-            GetPrivateProfileString(INI_HOSTS, INI_HOST "0", "", tmpName, 
-                128, TELNET_INI);
-            if (tmpName[0]) {
-               tmpCommaLoc = strchr(tmpName, ',');
-                               if (tmpCommaLoc)
-                                       *tmpCommaLoc = '\0';
-               SetDlgItemText(hDlg, TEL_CONNECT_NAME, tmpName);
-            }  
-            hEdit = GetWindow(GetDlgItem(hDlg, TEL_CONNECT_NAME), GW_CHILD);
-            while (TRUE) {
-                wsprintf(tmpBuf, INI_HOST "%d", iHostNum++);
-                GetPrivateProfileString(INI_HOSTS, tmpBuf, "", tmpName, 
-                    128, TELNET_INI);
-                tmpCommaLoc = strchr(tmpName, ',');  
-                if (tmpCommaLoc)
-                                       *tmpCommaLoc = '\0';
-                if (tmpName[0])
-                    SendDlgItemMessage(hDlg, TEL_CONNECT_NAME, CB_ADDSTRING, 0, 
-                        (LPARAM) ((LPSTR) tmpName));
-                else
-                                       break;
-            }
-            SetWindowPos(hDlg, NULL,
-                (GetSystemMetrics(SM_CXSCREEN)/2)-(xExt/2),
-                (GetSystemMetrics(SM_CYSCREEN)/2)-(yExt/2),
-                0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
-            ReleaseDC(hDlg, hDC);      
-            SendMessage(hEdit, WM_USER+1, NULL, NULL);
-            SendMessage(hDlg, WM_SETFOCUS, NULL, NULL);
-            return (TRUE);
-
-        case WM_COMMAND:              /* message: received a command */
-            switch (wParam) {
-            case TEL_CANCEL:
-                EndDialog(hDlg, FALSE);         /* Exits the dialog box   */
-                break;
-                 
-            case TEL_OK:
-                GetDlgItemText(hDlg, TEL_CONNECT_NAME, szConnectName, 256);
-                
-                n = parse_cmdline (szConnectName);
-                if (! n) {
-                    MessageBox(hDlg, "You must enter a session name!",
-                        NULL, MB_OK);
-                    break;
-                }
-
-                hTitleMem = GlobalAlloc(GPTR, lstrlen(szHostName)+1);
-                tmpConfig->title = (char *) GlobalLock(hTitleMem);
-                lstrcpy(tmpConfig->title, szConnectName);
-                EndDialog(hDlg, TRUE);
-                break;
-            }                
-            return (FALSE);                    
-    }
-    return (FALSE);               /* Didn't process a message    */
-}
+BOOL FAR PASCAL OpenTelnetDlg(
+       HWND hDlg,
+       WORD message,
+       WORD wParam,
+       LONG lParam)
+{
+       char szConnectName[256];
+       HDC hDC;
+       int xExt, yExt;
+       DWORD Ext;
+       HWND hEdit;
+       int n;
+       int iHostNum = 0;
+       char tmpName[128];
+       char tmpBuf[80];
+       char *tmpCommaLoc;
+       
+       switch (message) {
+
+       case WM_INITDIALOG:
+               hDC = GetDC(hDlg);
+               Ext = GetDialogBaseUnits();
+               xExt = (190 *LOWORD(Ext)) /4 ;
+               yExt = (72 * HIWORD(Ext)) /8 ;
+               GetPrivateProfileString(INI_HOSTS, INI_HOST "0", "", tmpName, 
+                       128, TELNET_INI);
+               if (tmpName[0]) {
+                       tmpCommaLoc = strchr(tmpName, ',');
+                       if (tmpCommaLoc)
+                               *tmpCommaLoc = '\0';
+                       SetDlgItemText(hDlg, TEL_CONNECT_NAME, tmpName);
+               }       
+               hEdit = GetWindow(GetDlgItem(hDlg, TEL_CONNECT_NAME), GW_CHILD);
+               while (TRUE) {
+                       wsprintf(tmpBuf, INI_HOST "%d", iHostNum++);
+                       GetPrivateProfileString(INI_HOSTS, tmpBuf, "", tmpName, 
+                               128, TELNET_INI);
+                       tmpCommaLoc = strchr(tmpName, ',');  
+                       if (tmpCommaLoc)
+                               *tmpCommaLoc = '\0';
+                       if (tmpName[0])
+                               SendDlgItemMessage(hDlg, TEL_CONNECT_NAME, CB_ADDSTRING, 0, 
+                                       (LPARAM) ((LPSTR) tmpName));
+                       else
+                               break;
+               }
+               SetWindowPos(hDlg, NULL,
+                       (GetSystemMetrics(SM_CXSCREEN)/2)-(xExt/2),
+                       (GetSystemMetrics(SM_CYSCREEN)/2)-(yExt/2),
+                       0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
+               ReleaseDC(hDlg, hDC);      
+               SendMessage(hEdit, WM_USER+1, NULL, NULL);
+               SendMessage(hDlg, WM_SETFOCUS, NULL, NULL);
+               return (TRUE);
+
+       case WM_COMMAND:
+               switch (wParam) {
+               case TEL_CANCEL:
+                       EndDialog(hDlg, FALSE);
+                       break;
+                               
+               case TEL_OK:
+                       GetDlgItemText(hDlg, TEL_CONNECT_NAME, szConnectName, 256);
+                       
+                       n = parse_cmdline (szConnectName);
+                       if (! n) {
+                               MessageBox(hDlg, "You must enter a session name!",
+                                       NULL, MB_OK);
+                               break;
+                       }
+                       tmpConfig->title = calloc(lstrlen(szHostName) + 1, 1);
+                       lstrcpy(tmpConfig->title, szConnectName);
+                       EndDialog(hDlg, TRUE);
+                       break;
+               }                
+               return (FALSE);                    
+       }
+       return(FALSE);
+
+} /* OpenTelnetDlg */
+
 
 /*+***************************************************************************
 
-    FUNCTION: TelnetSend(kstream ks, char *buf, int len, int flags)
+       FUNCTION: TelnetSend(kstream ks, char *buf, int len, int flags)
 
-    PURPOSE:   This is a replacement for the WinSock send() function, to
+       PURPOSE:        This is a replacement for the WinSock send() function, to
                send a buffer of characters to an output socket.  It differs
                by retrying endlessly if sending the bytes would cause
                the send() to block.  <gnu@cygnus.com> observed EWOULDBLOCK
@@ -770,9 +778,12 @@ OpenTelnetDlg(HWND hDlg, WORD message, WORD wParam, LONG lParam) {
 
 ****************************************************************************/
 
-int
-TelnetSend(kstream ks, char *buf, int len, int flags) {
-
+int TelnetSend(
+       kstream ks,
+       char *buf,
+       int len,
+       int flags)
+{
        int writelen;
        int origlen = len;
 
@@ -793,15 +804,17 @@ TelnetSend(kstream ks, char *buf, int len, int flags) {
                        buf += writelen;
                }
        }
-}
+
+} /* TelnetSend */
+
+
 /*+
  * Function: Trim leading and trailing white space from a string.
  *
  * Parameters:
  *     s - the string to trim.
  */
-void
-trim (
+void trim(
        char *s)
 {
        int l;
@@ -821,6 +834,8 @@ trim (
        s[l + 1] = 0;
 
 } /* trim */
+
+
 /*+
 ** 
 ** Parse_cmdline
@@ -834,26 +849,28 @@ trim (
 **
 ** Returns: TRUE if we have a hostname
 */
-BOOL
-parse_cmdline (char *cmdline) {
-    char *ptr;
-    
-    *szHostName = '\0';                         // Nothing yet
-    if (*cmdline == '\0')                       // Empty command line?
-        return FALSE;
-
-    trim (cmdline);                             // Remove excess spaces
-    ptr = strchr (cmdline, ' ');                // Find 2nd token
-
-    if (ptr != NULL) {                          // Port number given
-        *ptr++ = '\0';                          // Separate into 2 words
-        port_no = atoi (ptr);
-    }
-
-    if (*cmdline != '-' && *cmdline != '/') {   // Host name given
+BOOL parse_cmdline(
+       char *cmdline)
+{
+       char *ptr;
+       
+       *szHostName = '\0';                 // Nothing yet
+       if (*cmdline == '\0')               // Empty command line?
+               return(FALSE);
+
+       trim (cmdline);                     // Remove excess spaces
+       ptr = strchr (cmdline, ' ');        // Find 2nd token
+
+       if (ptr != NULL) {                  // Port number given
+               *ptr++ = '\0';                  // Separate into 2 words
+               port_no = atoi (ptr);
+       }
+
+       if (*cmdline != '-' && *cmdline != '/') {   // Host name given
                lstrcpy (szHostName, cmdline);
-        return TRUE;
-    }
+               return(TRUE);
+       }
+
+       return(FALSE);
 
-    return FALSE;
-}
+} /* parse_cmdline */
index e5c1061d9539ce8757a21821b416f87ec40a1866..e2d2ab93ff269b2e9682fda75266338328bcdc11 100644 (file)
@@ -1,22 +1,12 @@
 ; module-definition file for testdll -- used by LINK.EXE
-NAME         telnet        ; application's module name
-
-DESCRIPTION  'Sample Microsoft Windows Application'
-
-EXETYPE      WINDOWS       ; required for all Windows applications
-
-STUB         'WINSTUB.EXE' ; Generates error message if application
-               ; is run without Windows
-
-;CODE can be moved in memory and discarded/reloaded
-CODE  PRELOAD MOVEABLE 
-;DISCARDABLE
-
-;DATA must be MULTIPLE if program can be invoked more than once
-DATA  PRELOAD MOVEABLE
-
-
-HEAPSIZE     10240
+NAME TELNET
+DESCRIPTION 'Sample Microsoft Windows Application'
+EXETYPE WINDOWS
+STUB 'WINSTUB.EXE'
+SEGMENTS _TEXT CLASS 'CODE' PRELOAD
+CODE DISCARDABLE
+DATA PRELOAD MOVEABLE MULTIPLE
+HEAPSIZE 10240
 
 ; All functions that will be called by any Windows routine
 ; MUST be exported.
index ee68d76308336a4528d676a31d7dd308a9bd348a..5694f9f5f173feb44c0cf0c7574b95a9cbd1ff15 100644 (file)
@@ -5,8 +5,8 @@
 #include <stdarg.h>
 
 #ifdef KRB5
-#include "krb5.h"
-#include "k5stream.h"
+       #include "krb5.h"
+       #include "k5stream.h"
 #endif
 
 #include "dialog.h"
@@ -25,8 +25,14 @@ extern char szHostName[64];
    extern krb5_context k5_context;
 #endif
 
-extern void parse(CONNECTION *con,unsigned char *st,int cnt);
-extern void send_naws(CONNECTION *con);
+extern void parse(
+       CONNECTION *con,
+       unsigned char *st,
+       int cnt);
+
+extern void send_naws(
+       CONNECTION *con);
+
 extern char __near strTmp[];
 
 #define DEF_WIDTH 80
index 76692117ce03d44efa2aacdf764c6bc8991f7dd1..dc23f3e213a7792f87c5caa8d50fb3b8b774681f 100644 (file)
@@ -1,21 +1,60 @@
-int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
-BOOL InitApplication(HANDLE);
-BOOL InitInstance(HANDLE, int);
-long FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
-BOOL FAR PASCAL About(HWND, WORD, WORD, LONG);
-BOOL FAR PASCAL OpenTelnetDlg(HWND, WORD, WORD, LONG);
-int TelnetSend(kstream, char *, int, int);
-BOOL FAR PASCAL ConfigSessionDlg(HWND, WORD, WORD, LONG);
-
-int OpenTelnetConnection(void);
-int NEAR DoDialog(char *szDialog, FARPROC lpfnDlgProc);
-BOOL parse_cmdline (char *cmdline);
-
-///HCONNECTION FindConnectionFromPortNum(int ID);
-///HCONNECTION FindConnectionFromTelstate(int telstate);
-///HCONNECTION FindConnectionFromScreen(HSCREEN hScreen);
-CONNECTION * GetNewConnection(void);
-void start_negotiation(kstream ks);
-/* somewhere... */
-struct machinfo * FAR PASCAL Shostlook(char *hname);
+/* wt-proto.h */
+       int PASCAL WinMain(
+               HANDLE,
+               HANDLE,
+               LPSTR,
+               int);
 
+       BOOL InitApplication(
+               HANDLE);
+
+       BOOL InitInstance(
+               HANDLE,
+               int);
+
+       long FAR PASCAL MainWndProc(
+               HWND,
+               UINT,
+               WPARAM,
+               LPARAM);
+
+       BOOL FAR PASCAL About(
+               HWND,
+               WORD,
+               WORD,
+               LONG);
+
+       BOOL FAR PASCAL OpenTelnetDlg(
+               HWND,
+               WORD,
+               WORD,
+               LONG);
+
+       int TelnetSend(
+               kstream,
+               char *,
+               int,
+               int);
+
+       BOOL FAR PASCAL ConfigSessionDlg(
+               HWND,
+               WORD,
+               WORD,
+               LONG);
+
+       int OpenTelnetConnection(void);
+
+       int NEAR DoDialog(char *szDialog,
+               FARPROC lpfnDlgProc);
+
+       BOOL parse_cmdline(
+               char *cmdline);
+
+       CONNECTION *GetNewConnection(void);
+
+       void start_negotiation(
+               kstream ks);
+
+       /* somewhere... */
+       struct machinfo *FAR PASCAL Shostlook(
+               char *hname);