[Ttssh2-commit] [3393] インデントを調整。コード的な変更はないはず。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 5月 12日 (火) 23:26:30 JST


Revision: 3393
          http://svn.sourceforge.jp/view?root=ttssh2&view=rev&rev=3393
Author:   maya
Date:     2009-05-12 23:26:30 +0900 (Tue, 12 May 2009)

Log Message:
-----------
インデントを調整。コード的な変更はないはず。

Modified Paths:
--------------
    trunk/teraterm/teraterm/buffer.c
    trunk/teraterm/teraterm/clipboar.c
    trunk/teraterm/teraterm/commlib.c
    trunk/teraterm/teraterm/ttdialog.c
    trunk/teraterm/teraterm/vtwin.cpp


-------------- next part --------------
Modified: trunk/teraterm/teraterm/buffer.c
===================================================================
--- trunk/teraterm/teraterm/buffer.c	2009-05-12 11:55:27 UTC (rev 3392)
+++ trunk/teraterm/teraterm/buffer.c	2009-05-12 14:26:30 UTC (rev 3393)
@@ -70,324 +70,336 @@
 
 LONG GetLinePtr(int Line)
 {
-  LONG Ptr;
+	LONG Ptr;
 
-  Ptr = (LONG)(BuffStartAbs + Line) *
-	(LONG)(NumOfColumns);
-  while (Ptr>=BufferSize)
-    Ptr = Ptr - BufferSize;
-  return Ptr;
+	Ptr = (LONG)(BuffStartAbs + Line) * (LONG)(NumOfColumns);
+	while (Ptr>=BufferSize) {
+		Ptr = Ptr - BufferSize;
+	}
+	return Ptr;
 }
 
 LONG NextLinePtr(LONG Ptr)
 {
-  Ptr = Ptr + (LONG)NumOfColumns;
-  if (Ptr >= BufferSize)
-    Ptr = Ptr - BufferSize;
-  return Ptr;
+	Ptr = Ptr + (LONG)NumOfColumns;
+	if (Ptr >= BufferSize) {
+		Ptr = Ptr - BufferSize;
+	}
+	return Ptr;
 }
 
 LONG PrevLinePtr(LONG Ptr)
 {
-  Ptr = Ptr - (LONG)NumOfColumns;
-  if (Ptr < 0) Ptr = Ptr + BufferSize;
-  return Ptr;
+	Ptr = Ptr - (LONG)NumOfColumns;
+	if (Ptr < 0) {
+		Ptr = Ptr + BufferSize;
+	}
+	return Ptr;
 }
 
 BOOL ChangeBuffer(int Nx, int Ny)
 {
-  HANDLE HCodeNew, HAttrNew, HAttr2New, HAttrFGNew, HAttrBGNew;
-  LONG NewSize;
-  int NxCopy, NyCopy, i;
-  PCHAR CodeDest, AttrDest, AttrDest2, AttrDestFG, AttrDestBG;
-  PCHAR Ptr;
-  LONG SrcPtr, DestPtr;
-  WORD LockOld;
+	HANDLE HCodeNew, HAttrNew, HAttr2New, HAttrFGNew, HAttrBGNew;
+	LONG NewSize;
+	int NxCopy, NyCopy, i;
+	PCHAR CodeDest, AttrDest, AttrDest2, AttrDestFG, AttrDestBG;
+	PCHAR Ptr;
+	LONG SrcPtr, DestPtr;
+	WORD LockOld;
 
-  if (Nx > BuffXMax) Nx = BuffXMax;
-  if (ts.ScrollBuffMax > BuffYMax)
-    ts.ScrollBuffMax = BuffYMax;
-  if (Ny > ts.ScrollBuffMax) Ny = ts.ScrollBuffMax;
- 
-  if ( (LONG)Nx * (LONG)Ny > BuffSizeMax )
-    Ny = BuffSizeMax / Nx;
+	if (Nx > BuffXMax) {
+		Nx = BuffXMax;
+	}
+	if (ts.ScrollBuffMax > BuffYMax) {
+		ts.ScrollBuffMax = BuffYMax;
+	}
+	if (Ny > ts.ScrollBuffMax) {
+		Ny = ts.ScrollBuffMax;
+	}
 
-  NewSize = (LONG)Nx * (LONG)Ny;
+	if ( (LONG)Nx * (LONG)Ny > BuffSizeMax ) {
+		Ny = BuffSizeMax / Nx;
+	}
 
-  HCodeNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
-  if ( HCodeNew==0 ) return FALSE;
-  Ptr = GlobalLock(HCodeNew);
-  if ( Ptr==NULL )
-  {
-    GlobalFree(HCodeNew);
-    return FALSE;
-  }
-  CodeDest = Ptr;
+	NewSize = (LONG)Nx * (LONG)Ny;
 
-  HAttrNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
-  if ( HAttrNew==0 )
-  {
-    GlobalFree(HCodeNew);
-    return FALSE;
-  }
-  Ptr = GlobalLock(HAttrNew);
-  if ( Ptr==NULL )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    return FALSE;
-  }
-  AttrDest = Ptr;
+	HCodeNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
+	if ( HCodeNew==0 ) {
+		return FALSE;
+	}
+	Ptr = GlobalLock(HCodeNew);
+	if ( Ptr==NULL ) {
+		GlobalFree(HCodeNew);
+		return FALSE;
+	}
+	CodeDest = Ptr;
 
-  HAttr2New = GlobalAlloc(GMEM_MOVEABLE, NewSize);
-  if ( HAttr2New==0 )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    return FALSE;
-  }
-  Ptr = GlobalLock(HAttr2New);
-  if ( Ptr==NULL )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    GlobalFree(HAttr2New);
-    return FALSE;
-  }
-  AttrDest2 = Ptr;
+	HAttrNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
+	if ( HAttrNew==0 ) {
+		GlobalFree(HCodeNew);
+		return FALSE;
+	}
+	Ptr = GlobalLock(HAttrNew);
+	if ( Ptr==NULL ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		return FALSE;
+	}
+	AttrDest = Ptr;
 
-  HAttrFGNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
-  if ( HAttrFGNew==0 )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    GlobalFree(HAttr2New);
-    return FALSE;
-  }
-  Ptr = GlobalLock(HAttrFGNew);
-  if ( Ptr==NULL )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    GlobalFree(HAttr2New);
-    GlobalFree(HAttrFGNew);
-    return FALSE;
-  }
-  AttrDestFG = Ptr;
+	HAttr2New = GlobalAlloc(GMEM_MOVEABLE, NewSize);
+	if ( HAttr2New==0 ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		return FALSE;
+	}
+	Ptr = GlobalLock(HAttr2New);
+	if ( Ptr==NULL ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		GlobalFree(HAttr2New);
+		return FALSE;
+	}
+	AttrDest2 = Ptr;
 
-  HAttrBGNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
-  if ( HAttrBGNew==0 )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    GlobalFree(HAttr2New);
-    GlobalFree(HAttrFGNew);
-    return FALSE;
-  }
-  Ptr = GlobalLock(HAttrBGNew);
-  if ( Ptr==NULL )
-  {
-    GlobalFree(HCodeNew);
-    GlobalFree(HAttrNew);
-    GlobalFree(HAttr2New);
-    GlobalFree(HAttrFGNew);
-    GlobalFree(HAttrBGNew);
-    return FALSE;
-  }
-  AttrDestBG = Ptr;
+	HAttrFGNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
+	if ( HAttrFGNew==0 ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		GlobalFree(HAttr2New);
+		return FALSE;
+	}
+	Ptr = GlobalLock(HAttrFGNew);
+	if ( Ptr==NULL ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		GlobalFree(HAttr2New);
+		GlobalFree(HAttrFGNew);
+		return FALSE;
+	}
+	AttrDestFG = Ptr;
 
-  memset(&CodeDest[0], 0x20, NewSize);
-  memset(&AttrDest[0], AttrDefault, NewSize);
-  memset(&AttrDest2[0], AttrDefault, NewSize);
-  memset(&AttrDestFG[0], AttrDefaultFG, NewSize);
-  memset(&AttrDestBG[0], AttrDefaultBG, NewSize);
-  if ( HCodeBuff!=0 )
-  {
-    if ( NumOfColumns > Nx )
-      NxCopy = Nx;
-    else NxCopy = NumOfColumns;
-    if ( BuffEnd > Ny )
-      NyCopy = Ny;
-    else NyCopy = BuffEnd;
-    LockOld = BuffLock;
-    LockBuffer();
-    SrcPtr = GetLinePtr(BuffEnd-NyCopy);
-    DestPtr = 0;
-    for (i = 1 ; i <= NyCopy ; i++)
-    {
-      memcpy(&CodeDest[DestPtr],&CodeBuff[SrcPtr],NxCopy);
-      memcpy(&AttrDest[DestPtr],&AttrBuff[SrcPtr],NxCopy);
-      memcpy(&AttrDest2[DestPtr],&AttrBuff2[SrcPtr],NxCopy);
-      memcpy(&AttrDestFG[DestPtr],&AttrBuffFG[SrcPtr],NxCopy);
-      memcpy(&AttrDestBG[DestPtr],&AttrBuffBG[SrcPtr],NxCopy);
-      SrcPtr = NextLinePtr(SrcPtr);
-      DestPtr = DestPtr + (LONG)Nx;
-    }
-    FreeBuffer();
-  }
-  else {
-    LockOld = 0;
-    NyCopy = NumOfLines;
-    Selected = FALSE;
-  }
+	HAttrBGNew = GlobalAlloc(GMEM_MOVEABLE, NewSize);
+	if ( HAttrBGNew==0 ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		GlobalFree(HAttr2New);
+		GlobalFree(HAttrFGNew);
+		return FALSE;
+	}
+	Ptr = GlobalLock(HAttrBGNew);
+	if ( Ptr==NULL ) {
+		GlobalFree(HCodeNew);
+		GlobalFree(HAttrNew);
+		GlobalFree(HAttr2New);
+		GlobalFree(HAttrFGNew);
+		GlobalFree(HAttrBGNew);
+		return FALSE;
+	}
+	AttrDestBG = Ptr;
 
-  if (Selected)
-  {
-    SelectStart.y =
-      SelectStart.y - BuffEnd + NyCopy;
-    SelectEnd.y =
-      SelectEnd.y - BuffEnd + NyCopy;
-    if (SelectStart.y < 0)
-    {
-      SelectStart.y = 0;
-      SelectStart.x = 0;
-    }
-    if (SelectEnd.y<0)
-    {
-      SelectEnd.x = 0;
-      SelectEnd.y = 0;
-    }
+	memset(&CodeDest[0], 0x20, NewSize);
+	memset(&AttrDest[0], AttrDefault, NewSize);
+	memset(&AttrDest2[0], AttrDefault, NewSize);
+	memset(&AttrDestFG[0], AttrDefaultFG, NewSize);
+	memset(&AttrDestBG[0], AttrDefaultBG, NewSize);
+	if ( HCodeBuff!=0 ) {
+		if ( NumOfColumns > Nx ) {
+			NxCopy = Nx;
+		}
+		else {
+			NxCopy = NumOfColumns;
+		}
 
-    Selected = (SelectEnd.y > SelectStart.y) ||
-		((SelectEnd.y=SelectStart.y) &&
-		 (SelectEnd.x > SelectStart.x));
-  }
+		if ( BuffEnd > Ny ) {
+			NyCopy = Ny;
+		}
+		else {
+			NyCopy = BuffEnd;
+		}
+		LockOld = BuffLock;
+		LockBuffer();
+		SrcPtr = GetLinePtr(BuffEnd-NyCopy);
+		DestPtr = 0;
+		for (i = 1 ; i <= NyCopy ; i++) {
+			memcpy(&CodeDest[DestPtr],&CodeBuff[SrcPtr],NxCopy);
+			memcpy(&AttrDest[DestPtr],&AttrBuff[SrcPtr],NxCopy);
+			memcpy(&AttrDest2[DestPtr],&AttrBuff2[SrcPtr],NxCopy);
+			memcpy(&AttrDestFG[DestPtr],&AttrBuffFG[SrcPtr],NxCopy);
+			memcpy(&AttrDestBG[DestPtr],&AttrBuffBG[SrcPtr],NxCopy);
+			SrcPtr = NextLinePtr(SrcPtr);
+			DestPtr = DestPtr + (LONG)Nx;
+		}
+		FreeBuffer();
+	}
+	else {
+		LockOld = 0;
+		NyCopy = NumOfLines;
+		Selected = FALSE;
+	}
 
-  HCodeBuff = HCodeNew;
-  HAttrBuff = HAttrNew;
-  HAttrBuff2 = HAttr2New;
-  HAttrBuffFG = HAttrFGNew;
-  HAttrBuffBG = HAttrBGNew;
-  BufferSize = NewSize;
-  NumOfLinesInBuff = Ny;
-  BuffStartAbs = 0;
-  BuffEnd = NyCopy;
+	if (Selected) {
+		SelectStart.y = SelectStart.y - BuffEnd + NyCopy;
+		SelectEnd.y = SelectEnd.y - BuffEnd + NyCopy;
+		if (SelectStart.y < 0) {
+			SelectStart.y = 0;
+			SelectStart.x = 0;
+		}
+		if (SelectEnd.y<0) {
+			SelectEnd.x = 0;
+			SelectEnd.y = 0;
+		}
 
-  if (BuffEnd==NumOfLinesInBuff)
-    BuffEndAbs = 0;
-  else
-    BuffEndAbs = BuffEnd;
+		Selected = (SelectEnd.y > SelectStart.y) ||
+		           ((SelectEnd.y=SelectStart.y) &&
+		            (SelectEnd.x > SelectStart.x));
+	}
 
-  PageStart = BuffEnd - NumOfLines;
+	HCodeBuff = HCodeNew;
+	HAttrBuff = HAttrNew;
+	HAttrBuff2 = HAttr2New;
+	HAttrBuffFG = HAttrFGNew;
+	HAttrBuffBG = HAttrBGNew;
+	BufferSize = NewSize;
+	NumOfLinesInBuff = Ny;
+	BuffStartAbs = 0;
+	BuffEnd = NyCopy;
 
-  LinePtr = 0;
-  if (LockOld>0)
-  {
-    CodeBuff = (PCHAR)GlobalLock(HCodeBuff);
-    AttrBuff = (PCHAR)GlobalLock(HAttrBuff);
-    AttrBuff2 = (PCHAR)GlobalLock(HAttrBuff2);
-    AttrBuffFG = (PCHAR)GlobalLock(HAttrBuffFG);
-    AttrBuffBG = (PCHAR)GlobalLock(HAttrBuffBG);
-    CodeLine = CodeBuff;
-    AttrLine = AttrBuff;
-    AttrLine2 = AttrBuff2;
-    AttrLineFG = AttrBuffFG;
-    AttrLineBG = AttrBuffBG;
-  }
-  else {
-    GlobalUnlock(HCodeNew);
-    GlobalUnlock(HAttrNew);
-  }
-  BuffLock = LockOld;
+	if (BuffEnd==NumOfLinesInBuff) {
+		BuffEndAbs = 0;
+	}
+	else {
+		BuffEndAbs = BuffEnd;
+	}
 
-  return TRUE;
+	PageStart = BuffEnd - NumOfLines;
+
+	LinePtr = 0;
+	if (LockOld>0) {
+		CodeBuff = (PCHAR)GlobalLock(HCodeBuff);
+		AttrBuff = (PCHAR)GlobalLock(HAttrBuff);
+		AttrBuff2 = (PCHAR)GlobalLock(HAttrBuff2);
+		AttrBuffFG = (PCHAR)GlobalLock(HAttrBuffFG);
+		AttrBuffBG = (PCHAR)GlobalLock(HAttrBuffBG);
+		CodeLine = CodeBuff;
+		AttrLine = AttrBuff;
+		AttrLine2 = AttrBuff2;
+		AttrLineFG = AttrBuffFG;
+		AttrLineBG = AttrBuffBG;
+	}
+	else {
+		GlobalUnlock(HCodeNew);
+		GlobalUnlock(HAttrNew);
+	}
+	BuffLock = LockOld;
+
+	return TRUE;
 }
 
 void InitBuffer()
 {
-  int Ny;
+	int Ny;
 
-  /* setup terminal */
-  NumOfColumns = ts.TerminalWidth;
-  NumOfLines = ts.TerminalHeight;
+	/* setup terminal */
+	NumOfColumns = ts.TerminalWidth;
+	NumOfLines = ts.TerminalHeight;
 
-  /* setup window */
-  if (ts.EnableScrollBuff>0)
-  {
-    if (ts.ScrollBuffSize < NumOfLines)
-      ts.ScrollBuffSize = NumOfLines;
-    Ny = ts.ScrollBuffSize;
-  }
-  else
-    Ny = NumOfLines;
+	/* setup window */
+	if (ts.EnableScrollBuff>0) {
+		if (ts.ScrollBuffSize < NumOfLines) {
+			ts.ScrollBuffSize = NumOfLines;
+		}
+		Ny = ts.ScrollBuffSize;
+	}
+	else {
+		Ny = NumOfLines;
+	}
 
-  if (! ChangeBuffer(NumOfColumns,Ny))
-    PostQuitMessage(0);
+	if (! ChangeBuffer(NumOfColumns,Ny)) {
+		PostQuitMessage(0);
+	}
 
-  if (ts.EnableScrollBuff>0)
-    ts.ScrollBuffSize = NumOfLinesInBuff;
+	if (ts.EnableScrollBuff>0) {
+		ts.ScrollBuffSize = NumOfLinesInBuff;
+	}
 
-  StatusLine = 0;
+	StatusLine = 0;
 }
 
 void NewLine(int Line)
 {
-  LinePtr = GetLinePtr(Line);
-  CodeLine = &CodeBuff[LinePtr];
-  AttrLine = &AttrBuff[LinePtr];
-  AttrLine2 = &AttrBuff2[LinePtr];
-  AttrLineFG = &AttrBuffFG[LinePtr];
-  AttrLineBG = &AttrBuffBG[LinePtr];
+	LinePtr = GetLinePtr(Line);
+	CodeLine = &CodeBuff[LinePtr];
+	AttrLine = &AttrBuff[LinePtr];
+	AttrLine2 = &AttrBuff2[LinePtr];
+	AttrLineFG = &AttrBuffFG[LinePtr];
+	AttrLineBG = &AttrBuffBG[LinePtr];
 }
 
 void LockBuffer()
 {
-  BuffLock++;
-  if (BuffLock>1) return;
-  CodeBuff = (PCHAR)GlobalLock(HCodeBuff);
-  AttrBuff = (PCHAR)GlobalLock(HAttrBuff);
-  AttrBuff2 = (PCHAR)GlobalLock(HAttrBuff2);
-  AttrBuffFG = (PCHAR)GlobalLock(HAttrBuffFG);
-  AttrBuffBG = (PCHAR)GlobalLock(HAttrBuffBG);
-  NewLine(PageStart+CursorY);
+	BuffLock++;
+	if (BuffLock>1) {
+		return;
+	}
+	CodeBuff = (PCHAR)GlobalLock(HCodeBuff);
+	AttrBuff = (PCHAR)GlobalLock(HAttrBuff);
+	AttrBuff2 = (PCHAR)GlobalLock(HAttrBuff2);
+	AttrBuffFG = (PCHAR)GlobalLock(HAttrBuffFG);
+	AttrBuffBG = (PCHAR)GlobalLock(HAttrBuffBG);
+	NewLine(PageStart+CursorY);
 }
 
 void UnlockBuffer()
 {
-  if (BuffLock==0) return;
-  BuffLock--;
-  if (BuffLock>0) return;
-  if (HCodeBuff!=NULL)
-    GlobalUnlock(HCodeBuff);
-  if (HAttrBuff!=NULL)
-    GlobalUnlock(HAttrBuff);
-  if (HAttrBuff2!=NULL)
-    GlobalUnlock(HAttrBuff2);
-  if (HAttrBuffFG!=NULL)
-    GlobalUnlock(HAttrBuffFG);
-  if (HAttrBuffBG!=NULL)
-    GlobalUnlock(HAttrBuffBG);
+	if (BuffLock==0) {
+		return;
+	}
+	BuffLock--;
+	if (BuffLock>0) {
+		return;
+	}
+	if (HCodeBuff!=NULL) {
+		GlobalUnlock(HCodeBuff);
+	}
+	if (HAttrBuff!=NULL) {
+		GlobalUnlock(HAttrBuff);
+	}
+	if (HAttrBuff2!=NULL) {
+		GlobalUnlock(HAttrBuff2);
+	}
+	if (HAttrBuffFG!=NULL) {
+		GlobalUnlock(HAttrBuffFG);
+	}
+	if (HAttrBuffBG!=NULL) {
+		GlobalUnlock(HAttrBuffBG);
+	}
 }
 
 void FreeBuffer()
 {
-  BuffLock = 1;
-  UnlockBuffer();
-  if (HCodeBuff!=NULL)
-  {
-    GlobalFree(HCodeBuff);
-    HCodeBuff = NULL;
-  }
-  if (HAttrBuff!=NULL)
-  {
-    GlobalFree(HAttrBuff);
-    HAttrBuff = NULL;
-  }
-  if (HAttrBuff2!=NULL)
-  {
-    GlobalFree(HAttrBuff2);
-    HAttrBuff2 = NULL;
-  }
-  if (HAttrBuffFG!=NULL)
-  {
-    GlobalFree(HAttrBuffFG);
-    HAttrBuffFG = NULL;
-  }
-  if (HAttrBuffBG!=NULL)
-  {
-    GlobalFree(HAttrBuffBG);
-    HAttrBuffBG = NULL;
-  }
+	BuffLock = 1;
+	UnlockBuffer();
+	if (HCodeBuff!=NULL) {
+		GlobalFree(HCodeBuff);
+		HCodeBuff = NULL;
+	}
+	if (HAttrBuff!=NULL) {
+		GlobalFree(HAttrBuff);
+		HAttrBuff = NULL;
+	}
+	if (HAttrBuff2!=NULL) {
+		GlobalFree(HAttrBuff2);
+		HAttrBuff2 = NULL;
+	}
+	if (HAttrBuffFG!=NULL) {
+		GlobalFree(HAttrBuffFG);
+		HAttrBuffFG = NULL;
+	}
+	if (HAttrBuffBG!=NULL) {
+		GlobalFree(HAttrBuffBG);
+		HAttrBuffBG = NULL;
+	}
 }
 
 void BuffAllSelect()
@@ -424,132 +436,127 @@
 // Reset buffer status. don't update real display
 //   called by ResetTerminal()
 {
-  int i;
+	int i;
 
-  /* Cursor */
-  NewLine(PageStart);
-  WinOrgX = 0;
-  WinOrgY = 0;
-  NewOrgX = 0;
-  NewOrgY = 0;
+	/* Cursor */
+	NewLine(PageStart);
+	WinOrgX = 0;
+	WinOrgY = 0;
+	NewOrgX = 0;
+	NewOrgY = 0;
 
-  /* Top/bottom margin */
-  CursorTop = 0;
-  CursorBottom = NumOfLines-1;
+	/* Top/bottom margin */
+	CursorTop = 0;
+	CursorBottom = NumOfLines-1;
 
-  /* Tab stops */
-  NTabStops = (NumOfColumns-1) >> 3;
-  for (i=1 ; i<=NTabStops ; i++)
-    TabStops[i-1] = i*8;
+	/* Tab stops */
+	NTabStops = (NumOfColumns-1) >> 3;
+	for (i=1 ; i<=NTabStops ; i++) {
+		TabStops[i-1] = i*8;
+	}
 
-  /* Initialize text selection region */
-  SelectStart.x = 0;
-  SelectStart.y = 0;
-  SelectEnd = SelectStart;
-  SelectEndOld = SelectStart;
-  Selected = FALSE;
+	/* Initialize text selection region */
+	SelectStart.x = 0;
+	SelectStart.y = 0;
+	SelectEnd = SelectStart;
+	SelectEndOld = SelectStart;
+	Selected = FALSE;
 
-  StrChangeCount = 0;
-  Wrap = FALSE;
-  StatusLine = 0;
+	StrChangeCount = 0;
+	Wrap = FALSE;
+	StatusLine = 0;
 
-  SeveralPageSelect = FALSE; // yutaka
+	SeveralPageSelect = FALSE; // yutaka
 }
 
 void BuffScroll(int Count, int Bottom)
 {
-  int i, n;
-  LONG SrcPtr, DestPtr;
-  int BuffEndOld;
+	int i, n;
+	LONG SrcPtr, DestPtr;
+	int BuffEndOld;
 
-  if (Count>NumOfLinesInBuff)
-    Count = NumOfLinesInBuff;
+	if (Count>NumOfLinesInBuff) {
+		Count = NumOfLinesInBuff;
+	}
 
-  DestPtr = GetLinePtr(PageStart+NumOfLines-1+Count);
-  n = Count;
-  if (Bottom<NumOfLines-1)
-  {
-    SrcPtr = GetLinePtr(PageStart+NumOfLines-1);
-    for (i=NumOfLines-1; i>=Bottom+1; i--)
-    {
-      memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-      memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
-      memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
-      memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2,NumOfColumns);
-      memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
-      memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
-      SrcPtr = PrevLinePtr(SrcPtr);
-      DestPtr = PrevLinePtr(DestPtr);
-      n--;
-    }
-  }
-  for (i = 1 ; i <= n ; i++)
-  {
-    memset(&CodeBuff[DestPtr],0x20,NumOfColumns);
-    memset(&AttrBuff[DestPtr],AttrDefault,NumOfColumns);
-    memset(&AttrBuff2[DestPtr],CurCharAttr.Attr2,NumOfColumns);
-    memset(&AttrBuffFG[DestPtr],CurCharAttr.Fore,NumOfColumns);
-    memset(&AttrBuffBG[DestPtr],CurCharAttr.Back,NumOfColumns);
-    DestPtr = PrevLinePtr(DestPtr);
-  }
+	DestPtr = GetLinePtr(PageStart+NumOfLines-1+Count);
+	n = Count;
+	if (Bottom<NumOfLines-1) {
+		SrcPtr = GetLinePtr(PageStart+NumOfLines-1);
+		for (i=NumOfLines-1; i>=Bottom+1; i--) {
+			memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+			memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
+			memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
+			memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2,NumOfColumns);
+			memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
+			memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
+			SrcPtr = PrevLinePtr(SrcPtr);
+			DestPtr = PrevLinePtr(DestPtr);
+			n--;
+		}
+	}
+	for (i = 1 ; i <= n ; i++) {
+		memset(&CodeBuff[DestPtr],0x20,NumOfColumns);
+		memset(&AttrBuff[DestPtr],AttrDefault,NumOfColumns);
+		memset(&AttrBuff2[DestPtr],CurCharAttr.Attr2,NumOfColumns);
+		memset(&AttrBuffFG[DestPtr],CurCharAttr.Fore,NumOfColumns);
+		memset(&AttrBuffBG[DestPtr],CurCharAttr.Back,NumOfColumns);
+		DestPtr = PrevLinePtr(DestPtr);
+	}
 
-  BuffEndAbs = BuffEndAbs + Count;
-  if (BuffEndAbs >= NumOfLinesInBuff)
-    BuffEndAbs = BuffEndAbs - NumOfLinesInBuff;
-  BuffEndOld = BuffEnd;
-  BuffEnd = BuffEnd + Count;
-  if (BuffEnd >= NumOfLinesInBuff)
-  {
-    BuffEnd = NumOfLinesInBuff;
-    BuffStartAbs = BuffEndAbs;
-  }
-  PageStart = BuffEnd-NumOfLines;
+	BuffEndAbs = BuffEndAbs + Count;
+	if (BuffEndAbs >= NumOfLinesInBuff) {
+		BuffEndAbs = BuffEndAbs - NumOfLinesInBuff;
+	}
+	BuffEndOld = BuffEnd;
+	BuffEnd = BuffEnd + Count;
+	if (BuffEnd >= NumOfLinesInBuff) {
+		BuffEnd = NumOfLinesInBuff;
+		BuffStartAbs = BuffEndAbs;
+	}
+	PageStart = BuffEnd-NumOfLines;
 
-  if (Selected)
-  {
-    SelectStart.y = SelectStart.y - Count + BuffEnd - BuffEndOld;
-    SelectEnd.y = SelectEnd.y - Count + BuffEnd - BuffEndOld;
-    if ( SelectStart.y<0 )
-    {
-      SelectStart.x = 0;
-      SelectStart.y = 0;
-    }
-    if ( SelectEnd.y<0 )
-    {
-      SelectEnd.x = 0;
-      SelectEnd.y = 0;
-    }
-    Selected =
-      (SelectEnd.y > SelectStart.y) ||
-       ((SelectEnd.y==SelectStart.y) &&
-	(SelectEnd.x > SelectStart.x));
-  }
+	if (Selected) {
+		SelectStart.y = SelectStart.y - Count + BuffEnd - BuffEndOld;
+		SelectEnd.y = SelectEnd.y - Count + BuffEnd - BuffEndOld;
+		if ( SelectStart.y<0 ) {
+			SelectStart.x = 0;
+			SelectStart.y = 0;
+		}
+		if ( SelectEnd.y<0 ) {
+			SelectEnd.x = 0;
+			SelectEnd.y = 0;
+		}
+		Selected = (SelectEnd.y > SelectStart.y) ||
+	               ((SelectEnd.y==SelectStart.y) &&
+	                (SelectEnd.x > SelectStart.x));
+	}
 
-  NewLine(PageStart+CursorY);
+	NewLine(PageStart+CursorY);
 }
 
 void NextLine()
 {
-  LinePtr = NextLinePtr(LinePtr);
-  CodeLine = &CodeBuff[LinePtr];
-  AttrLine = &AttrBuff[LinePtr];
-  AttrLine2 = &AttrBuff2[LinePtr];
-  AttrLineFG = &AttrBuffFG[LinePtr];
-  AttrLineBG = &AttrBuffBG[LinePtr];
+	LinePtr = NextLinePtr(LinePtr);
+	CodeLine = &CodeBuff[LinePtr];
+	AttrLine = &AttrBuff[LinePtr];
+	AttrLine2 = &AttrBuff2[LinePtr];
+	AttrLineFG = &AttrBuffFG[LinePtr];
+	AttrLineBG = &AttrBuffBG[LinePtr];
 }
 
 void PrevLine()
 {
-  LinePtr = PrevLinePtr(LinePtr);
-  CodeLine = &CodeBuff[LinePtr];
-  AttrLine = &AttrBuff[LinePtr];
-  AttrLine2 = &AttrBuff2[LinePtr];
-  AttrLineFG = &AttrBuffFG[LinePtr];
-  AttrLineBG = &AttrBuffBG[LinePtr];
+	LinePtr = PrevLinePtr(LinePtr);
+	CodeLine = &CodeBuff[LinePtr];
+	AttrLine = &AttrBuff[LinePtr];
+	AttrLine2 = &AttrBuff2[LinePtr];
+	AttrLineFG = &AttrBuffFG[LinePtr];
+	AttrLineBG = &AttrBuffBG[LinePtr];
 }
 
 void EraseKanji(int LR)
@@ -557,124 +564,128 @@
 // If cursor is on left/right half of a Kanji, erase it.
 //   LR: left(0)/right(1) flag
 
-  if ((CursorX-LR>=0) &&
-      ((AttrLine[CursorX-LR] & AttrKanji) != 0))
-  {
-    CodeLine[CursorX-LR] = 0x20;
-    AttrLine[CursorX-LR] = CurCharAttr.Attr;
-    AttrLine2[CursorX-LR] = CurCharAttr.Attr2;
-    AttrLineFG[CursorX-LR] = CurCharAttr.Fore;
-    AttrLineBG[CursorX-LR] = CurCharAttr.Back;
-    if (CursorX-LR+1 < NumOfColumns)
-    {
-      CodeLine[CursorX-LR+1] = 0x20;
-      AttrLine[CursorX-LR+1] = CurCharAttr.Attr;
-      AttrLine2[CursorX-LR+1] = CurCharAttr.Attr2;
-      AttrLineFG[CursorX-LR+1] = CurCharAttr.Fore;
-      AttrLineBG[CursorX-LR+1] = CurCharAttr.Back;
-    }
-  }
+	if ((CursorX-LR>=0) &&
+	    ((AttrLine[CursorX-LR] & AttrKanji) != 0)) {
+		CodeLine[CursorX-LR] = 0x20;
+		AttrLine[CursorX-LR] = CurCharAttr.Attr;
+		AttrLine2[CursorX-LR] = CurCharAttr.Attr2;
+		AttrLineFG[CursorX-LR] = CurCharAttr.Fore;
+		AttrLineBG[CursorX-LR] = CurCharAttr.Back;
+		if (CursorX-LR+1 < NumOfColumns) {
+			CodeLine[CursorX-LR+1] = 0x20;
+			AttrLine[CursorX-LR+1] = CurCharAttr.Attr;
+			AttrLine2[CursorX-LR+1] = CurCharAttr.Attr2;
+			AttrLineFG[CursorX-LR+1] = CurCharAttr.Fore;
+			AttrLineBG[CursorX-LR+1] = CurCharAttr.Back;
+		}
+	}
 }
 
 void BuffInsertSpace(int Count)
 // Insert space characters at the current position
 //   Count: Number of characters to be inserted
 {
-  NewLine(PageStart+CursorY);
+	NewLine(PageStart+CursorY);
 
-  if (ts.Language==IdJapanese)
-    EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+	if (ts.Language==IdJapanese) {
+		EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+	}
 
-  if (Count > NumOfColumns - CursorX)
-    Count = NumOfColumns - CursorX;
+	if (Count > NumOfColumns - CursorX) {
+		Count = NumOfColumns - CursorX;
+	}
 
-  memmove(&(CodeLine[CursorX+Count]),&(CodeLine[CursorX]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLine[CursorX+Count]),&(AttrLine[CursorX]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLine2[CursorX+Count]),&(AttrLine2[CursorX]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLineFG[CursorX+Count]),&(AttrLineFG[CursorX]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLineBG[CursorX+Count]),&(AttrLineBG[CursorX]),
-	  NumOfColumns-Count-CursorX);
-  memset(&(CodeLine[CursorX]),0x20,Count);
-  memset(&(AttrLine[CursorX]),AttrDefault,Count);
-  memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2,Count);
-  memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
-  memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
-  /* last char in current line is kanji first? */
-  if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0)
-  {
-    /* then delete it */
-    CodeLine[NumOfColumns-1] = 0x20;
-    AttrLine[NumOfColumns-1] = AttrDefault;
-    AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
-    AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
-    AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
-  }
-  BuffUpdateRect(CursorX,CursorY,NumOfColumns-1,CursorY);
+	memmove(&(CodeLine[CursorX+Count]),&(CodeLine[CursorX]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLine[CursorX+Count]),&(AttrLine[CursorX]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLine2[CursorX+Count]),&(AttrLine2[CursorX]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLineFG[CursorX+Count]),&(AttrLineFG[CursorX]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLineBG[CursorX+Count]),&(AttrLineBG[CursorX]),
+	        NumOfColumns-Count-CursorX);
+	memset(&(CodeLine[CursorX]),0x20,Count);
+	memset(&(AttrLine[CursorX]),AttrDefault,Count);
+	memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2,Count);
+	memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
+	memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
+	/* last char in current line is kanji first? */
+	if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
+		/* then delete it */
+		CodeLine[NumOfColumns-1] = 0x20;
+		AttrLine[NumOfColumns-1] = AttrDefault;
+		AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
+		AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
+		AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
+	}
+	BuffUpdateRect(CursorX,CursorY,NumOfColumns-1,CursorY);
 }
 
 void BuffEraseCurToEnd()
 // Erase characters from cursor to the end of screen
 {
-  LONG TmpPtr;
-  int offset;
-  int i, YEnd;
+	LONG TmpPtr;
+	int offset;
+	int i, YEnd;
 
-  NewLine(PageStart+CursorY);
-  if (ts.Language==IdJapanese)
-    EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
-  offset = CursorX;
-  TmpPtr = GetLinePtr(PageStart+CursorY);
-  YEnd = NumOfLines-1;
-  if ((StatusLine>0) &&
-      (CursorY<NumOfLines-1))
-    YEnd--;
-  for (i = CursorY ; i <= YEnd ; i++)
-  {
-    memset(&(CodeBuff[TmpPtr+offset]),0x20,NumOfColumns-offset);
-    memset(&(AttrBuff[TmpPtr+offset]),AttrDefault,NumOfColumns-offset);
-    memset(&(AttrBuff2[TmpPtr+offset]),CurCharAttr.Attr2,NumOfColumns-offset);
-    memset(&(AttrBuffFG[TmpPtr+offset]),CurCharAttr.Fore,NumOfColumns-offset);
-    memset(&(AttrBuffBG[TmpPtr+offset]),CurCharAttr.Back,NumOfColumns-offset);
-    offset = 0;
-    TmpPtr = NextLinePtr(TmpPtr);
-  }
-  /* update window */
-  DispEraseCurToEnd(YEnd);
+	NewLine(PageStart+CursorY);
+	if (ts.Language==IdJapanese) {
+		EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+	}
+	offset = CursorX;
+	TmpPtr = GetLinePtr(PageStart+CursorY);
+	YEnd = NumOfLines-1;
+	if ((StatusLine>0) &&
+		(CursorY<NumOfLines-1)) {
+		YEnd--;
+	}
+	for (i = CursorY ; i <= YEnd ; i++) {
+		memset(&(CodeBuff[TmpPtr+offset]),0x20,NumOfColumns-offset);
+		memset(&(AttrBuff[TmpPtr+offset]),AttrDefault,NumOfColumns-offset);
+		memset(&(AttrBuff2[TmpPtr+offset]),CurCharAttr.Attr2,NumOfColumns-offset);
+		memset(&(AttrBuffFG[TmpPtr+offset]),CurCharAttr.Fore,NumOfColumns-offset);
+		memset(&(AttrBuffBG[TmpPtr+offset]),CurCharAttr.Back,NumOfColumns-offset);
+		offset = 0;
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
+	/* update window */
+	DispEraseCurToEnd(YEnd);
 }
 
 void BuffEraseHomeToCur()
 // Erase characters from home to cursor
 {
-  LONG TmpPtr;
-  int offset;
-  int i, YHome;
+	LONG TmpPtr;
+	int offset;
+	int i, YHome;
 
-  NewLine(PageStart+CursorY);
-  if (ts.Language==IdJapanese)
-    EraseKanji(0); /* if cursor is on left half of a kanji, erase the kanji */
-  offset = NumOfColumns;
-  if ((StatusLine>0) && (CursorY==NumOfLines-1))
-    YHome = CursorY;
-  else
-    YHome = 0;
-  TmpPtr = GetLinePtr(PageStart+YHome);
-  for (i = YHome ; i <= CursorY ; i++)
-  {
-    if (i==CursorY) offset = CursorX+1;
-    memset(&(CodeBuff[TmpPtr]),0x20,offset);
-    memset(&(AttrBuff[TmpPtr]),AttrDefault,offset);
-    memset(&(AttrBuff2[TmpPtr]),CurCharAttr.Attr2,offset);
-    memset(&(AttrBuffFG[TmpPtr]),CurCharAttr.Fore,offset);
-    memset(&(AttrBuffBG[TmpPtr]),CurCharAttr.Back,offset);
-    TmpPtr = NextLinePtr(TmpPtr);
-  }
+	NewLine(PageStart+CursorY);
+	if (ts.Language==IdJapanese) {
+		EraseKanji(0); /* if cursor is on left half of a kanji, erase the kanji */
+	}
+	offset = NumOfColumns;
+	if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
+		YHome = CursorY;
+	}
+	else {
+		YHome = 0;
+	}
+	TmpPtr = GetLinePtr(PageStart+YHome);
+	for (i = YHome ; i <= CursorY ; i++) {
+		if (i==CursorY) {
+			offset = CursorX+1;
+		}
+		memset(&(CodeBuff[TmpPtr]),0x20,offset);
+		memset(&(AttrBuff[TmpPtr]),AttrDefault,offset);
+		memset(&(AttrBuff2[TmpPtr]),CurCharAttr.Attr2,offset);
+		memset(&(AttrBuffFG[TmpPtr]),CurCharAttr.Fore,offset);
+		memset(&(AttrBuffBG[TmpPtr]),CurCharAttr.Back,offset);
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
 
-  /* update window */
-  DispEraseHomeToCur(YHome);
+	/* update window */
+	DispEraseHomeToCur(YHome);
 }
 
 void BuffInsertLines(int Count, int YEnd)
@@ -682,35 +693,34 @@
 //   Count: number of lines to be inserted
 //   YEnd: bottom line number of scroll region (screen coordinate)
 {
-  int i;
-  LONG SrcPtr, DestPtr;
+	int i;
+	LONG SrcPtr, DestPtr;
 
-  BuffUpdateScroll();
+	BuffUpdateScroll();
 
-  SrcPtr = GetLinePtr(PageStart+YEnd-Count);
-  DestPtr = GetLinePtr(PageStart+YEnd);
-  for (i= YEnd-Count ; i>=CursorY ; i--)
-  {
-    memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-    SrcPtr = PrevLinePtr(SrcPtr);
-    DestPtr = PrevLinePtr(DestPtr);
-  }
-  for (i = 1 ; i <= Count ; i++)
-  {
-    memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-    memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-    memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
-    memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-    memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
-    DestPtr = PrevLinePtr(DestPtr);
-  }
+	SrcPtr = GetLinePtr(PageStart+YEnd-Count);
+	DestPtr = GetLinePtr(PageStart+YEnd);
+	for (i= YEnd-Count ; i>=CursorY ; i--) {
+		memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+		SrcPtr = PrevLinePtr(SrcPtr);
+		DestPtr = PrevLinePtr(DestPtr);
+	}
+	for (i = 1 ; i <= Count ; i++) {
+		memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
+		memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
+		memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
+		memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
+		memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+		DestPtr = PrevLinePtr(DestPtr);
+	}
 
-  if (! DispInsertLines(Count,YEnd))
-    BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
+	if (! DispInsertLines(Count,YEnd)) {
+		BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
+	}
 }
 
 void BuffEraseCharsInLine(int XStart, int Count)
@@ -719,35 +729,37 @@
 //  Count: number of characters to be erased
 {
 #ifndef NO_COPYLINE_FIX
-  BOOL LineContinued=FALSE;
+	BOOL LineContinued=FALSE;
 
-  if (ts.EnableContinuedLineCopy && XStart == 0 && (AttrLine[0] & AttrLineContinued))
-    LineContinued = TRUE;
+	if (ts.EnableContinuedLineCopy && XStart == 0 && (AttrLine[0] & AttrLineContinued)) {
+		LineContinued = TRUE;
+	}
 #endif /* NO_COPYLINE_FIX */
 
-  if (ts.Language==IdJapanese)
-    EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+	if (ts.Language==IdJapanese) {
+		EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+	}
 
-  NewLine(PageStart+CursorY);
-  memset(&(CodeLine[XStart]),0x20,Count);
-  memset(&(AttrLine[XStart]),AttrDefault,Count);
-  memset(&(AttrLine2[XStart]),CurCharAttr.Attr2,Count);
-  memset(&(AttrLineFG[XStart]),CurCharAttr.Fore,Count);
-  memset(&(AttrLineBG[XStart]),CurCharAttr.Back,Count);
+	NewLine(PageStart+CursorY);
+	memset(&(CodeLine[XStart]),0x20,Count);
+	memset(&(AttrLine[XStart]),AttrDefault,Count);
+	memset(&(AttrLine2[XStart]),CurCharAttr.Attr2,Count);
+	memset(&(AttrLineFG[XStart]),CurCharAttr.Fore,Count);
+	memset(&(AttrLineBG[XStart]),CurCharAttr.Back,Count);
 
 #ifndef NO_COPYLINE_FIX
-  if (ts.EnableContinuedLineCopy) {
-    if (LineContinued) {
-      BuffLineContinued(TRUE);
-    }
-    
-    if (XStart + Count >= NumOfColumns) {
-      AttrBuff[NextLinePtr(LinePtr)] &= ~AttrLineContinued;
-    }
-  }
+	if (ts.EnableContinuedLineCopy) {
+		if (LineContinued) {
+			BuffLineContinued(TRUE);
+		}
+
+		if (XStart + Count >= NumOfColumns) {
+			AttrBuff[NextLinePtr(LinePtr)] &= ~AttrLineContinued;
+		}
+	}
 #endif /* NO_COPYLINE_FIX */
 
-  DispEraseCharsInLine(XStart, Count);
+	DispEraseCharsInLine(XStart, Count);
 }
 
 void BuffDeleteLines(int Count, int YEnd)
@@ -755,214 +767,226 @@
 //   Count: number of lines to be deleted
 //   YEnd: bottom line number of scroll region (screen coordinate)
 {
-  int i;
-  LONG SrcPtr, DestPtr;
+	int i;
+	LONG SrcPtr, DestPtr;
 
-  BuffUpdateScroll();
+	BuffUpdateScroll();
 
-  SrcPtr = GetLinePtr(PageStart+CursorY+Count);
-  DestPtr = GetLinePtr(PageStart+CursorY);
-  for (i=CursorY ; i<= YEnd-Count ; i++)
-  {
-    memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-    memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-    SrcPtr = NextLinePtr(SrcPtr);
-    DestPtr = NextLinePtr(DestPtr);
-  }
-  for (i = YEnd+1-Count ; i<=YEnd ; i++)
-  {
-    memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-    memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-    memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
-    memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-    memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
-    DestPtr = NextLinePtr(DestPtr);
-  }
+	SrcPtr = GetLinePtr(PageStart+CursorY+Count);
+	DestPtr = GetLinePtr(PageStart+CursorY);
+	for (i=CursorY ; i<= YEnd-Count ; i++) {
+		memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+		memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+		SrcPtr = NextLinePtr(SrcPtr);
+		DestPtr = NextLinePtr(DestPtr);
+	}
+	for (i = YEnd+1-Count ; i<=YEnd ; i++) {
+		memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
+		memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
+		memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
+		memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
+		memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+		DestPtr = NextLinePtr(DestPtr);
+	}
 
-  if (! DispDeleteLines(Count,YEnd))
-    BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
+	if (! DispDeleteLines(Count,YEnd)) {
+		BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
+	}
 }
 
 void BuffDeleteChars(int Count)
 // Delete characters in current line from cursor
 //   Count: number of characters to be deleted
 {
-  NewLine(PageStart+CursorY);
+	NewLine(PageStart+CursorY);
 
-  if (ts.Language==IdJapanese)
-  {
-    EraseKanji(0); /* if cursor is on left harf of a kanji, erase the kanji */
-    EraseKanji(1); /* if cursor on right half... */
-  }
+	if (ts.Language==IdJapanese) {
+		EraseKanji(0); /* if cursor is on left harf of a kanji, erase the kanji */
+		EraseKanji(1); /* if cursor on right half... */
+	}
 
-  if (Count > NumOfColumns-CursorX) Count = NumOfColumns-CursorX;
-  memmove(&(CodeLine[CursorX]),&(CodeLine[CursorX+Count]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLine[CursorX]),&(AttrLine[CursorX+Count]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLine2[CursorX]),&(AttrLine2[CursorX+Count]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLineFG[CursorX]),&(AttrLineFG[CursorX+Count]),
-	  NumOfColumns-Count-CursorX);
-  memmove(&(AttrLineBG[CursorX]),&(AttrLineBG[CursorX+Count]),
-	  NumOfColumns-Count-CursorX);
-  memset(&(CodeLine[NumOfColumns-Count]),0x20,Count);
-  memset(&(AttrLine[NumOfColumns-Count]),AttrDefault,Count);
-  memset(&(AttrLine2[NumOfColumns-Count]),CurCharAttr.Attr2,Count);
-  memset(&(AttrLineFG[NumOfColumns-Count]),CurCharAttr.Fore,Count);
-  memset(&(AttrLineBG[NumOfColumns-Count]),CurCharAttr.Back,Count);
+	if (Count > NumOfColumns-CursorX) {
+		Count = NumOfColumns-CursorX;
+	}
+	memmove(&(CodeLine[CursorX]),&(CodeLine[CursorX+Count]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLine[CursorX]),&(AttrLine[CursorX+Count]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLine2[CursorX]),&(AttrLine2[CursorX+Count]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLineFG[CursorX]),&(AttrLineFG[CursorX+Count]),
+	        NumOfColumns-Count-CursorX);
+	memmove(&(AttrLineBG[CursorX]),&(AttrLineBG[CursorX+Count]),
+	        NumOfColumns-Count-CursorX);
+	memset(&(CodeLine[NumOfColumns-Count]),0x20,Count);
+	memset(&(AttrLine[NumOfColumns-Count]),AttrDefault,Count);
+	memset(&(AttrLine2[NumOfColumns-Count]),CurCharAttr.Attr2,Count);
+	memset(&(AttrLineFG[NumOfColumns-Count]),CurCharAttr.Fore,Count);
+	memset(&(AttrLineBG[NumOfColumns-Count]),CurCharAttr.Back,Count);
 
-  BuffUpdateRect(CursorX,CursorY,WinOrgX+WinWidth-1,CursorY);
+	BuffUpdateRect(CursorX,CursorY,WinOrgX+WinWidth-1,CursorY);
 }
 
 void BuffEraseChars(int Count)
 // Erase characters in current line from cursor
 //   Count: number of characters to be deleted
 {
-  NewLine(PageStart+CursorY);
+	NewLine(PageStart+CursorY);
 
-  if (ts.Language==IdJapanese)
-  {
-    EraseKanji(0); /* if cursor is on left harf of a kanji, erase the kanji */
-    EraseKanji(1); /* if cursor on right half... */
-  }
+	if (ts.Language==IdJapanese) {
+		EraseKanji(0); /* if cursor is on left harf of a kanji, erase the kanji */
+		EraseKanji(1); /* if cursor on right half... */
+	}
 
-  if (Count > NumOfColumns-CursorX) Count = NumOfColumns-CursorX;
-  memset(&(CodeLine[CursorX]),0x20,Count);
-  memset(&(AttrLine[CursorX]),AttrDefault,Count);
-  memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2,Count);
-  memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
-  memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
+	if (Count > NumOfColumns-CursorX) {
+		Count = NumOfColumns-CursorX;
+	}
+	memset(&(CodeLine[CursorX]),0x20,Count);
+	memset(&(AttrLine[CursorX]),AttrDefault,Count);
+	memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2,Count);
+	memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
+	memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
 
-  /* update window */
-  DispEraseCharsInLine(CursorX,Count);
+	/* update window */
+	DispEraseCharsInLine(CursorX,Count);
 }
 
 void BuffFillWithE()
 // Fill screen with 'E' characters
 {
-  LONG TmpPtr;
-  int i;
+	LONG TmpPtr;
+	int i;
 
-  TmpPtr = GetLinePtr(PageStart);
-  for (i = 0 ; i <= NumOfLines-1-StatusLine ; i++)
-  {
-    memset(&(CodeBuff[TmpPtr]),'E',NumOfColumns);
-    memset(&(AttrBuff[TmpPtr]),AttrDefault,NumOfColumns);
-    memset(&(AttrBuff2[TmpPtr]),AttrDefault,NumOfColumns);
-    memset(&(AttrBuffFG[TmpPtr]),AttrDefaultFG,NumOfColumns);
-    memset(&(AttrBuffBG[TmpPtr]),AttrDefaultBG,NumOfColumns);
-    TmpPtr = NextLinePtr(TmpPtr);
-  }
-  BuffUpdateRect(WinOrgX,WinOrgY,WinOrgX+WinWidth-1,WinOrgY+WinHeight-1);
+	TmpPtr = GetLinePtr(PageStart);
+	for (i = 0 ; i <= NumOfLines-1-StatusLine ; i++) {
+		memset(&(CodeBuff[TmpPtr]),'E',NumOfColumns);
+		memset(&(AttrBuff[TmpPtr]),AttrDefault,NumOfColumns);
+		memset(&(AttrBuff2[TmpPtr]),AttrDefault,NumOfColumns);
+		memset(&(AttrBuffFG[TmpPtr]),AttrDefaultFG,NumOfColumns);
+		memset(&(AttrBuffBG[TmpPtr]),AttrDefaultBG,NumOfColumns);
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
+	BuffUpdateRect(WinOrgX,WinOrgY,WinOrgX+WinWidth-1,WinOrgY+WinHeight-1);
 }
 
 void BuffDrawLine(TCharAttr Attr, int Direction, int C)
 { // IO-8256 terminal
-  LONG Ptr;
-  int i, X, Y;
+	LONG Ptr;
+	int i, X, Y;
 
-  if (C==0) return;
-  Attr.Attr |= AttrSpecial;
+	if (C==0) {
+		return;
+	}
+	Attr.Attr |= AttrSpecial;
 
-  switch (Direction) {
-    case 3:
-    case 4:
-      if (Direction==3)
-      {
-	if (CursorY==0) return;
-	Y = CursorY-1;
-      }
-      else {
-	if (CursorY==NumOfLines-1-StatusLine) return;
-	Y = CursorY+1;
-      }
-      if (CursorX+C > NumOfColumns)
-	C = NumOfColumns-CursorX;
-      Ptr = GetLinePtr(PageStart+Y);
-      memset(&(CodeBuff[Ptr+CursorX]),'q',C);
-      memset(&(AttrBuff[Ptr+CursorX]),Attr.Attr,C);
-      memset(&(AttrBuff2[Ptr+CursorX]),Attr.Attr2,C);
-      memset(&(AttrBuffFG[Ptr+CursorX]),Attr.Fore,C);
-      memset(&(AttrBuffBG[Ptr+CursorX]),Attr.Back,C);
-      BuffUpdateRect(CursorX,Y,CursorX+C-1,Y);
-      break;
-    case 5:
-    case 6:
-      if (Direction==5)
-      {
-	if (CursorX==0) return;
-	X = CursorX - 1;
-      }
-      else {
-	if (CursorX==NumOfColumns-1)
-	  X = CursorX-1;
-	else
-	  X = CursorX+1;
-      }
-      Ptr = GetLinePtr(PageStart+CursorY);
-      if (CursorY+C > NumOfLines-StatusLine)
-	C = NumOfLines-StatusLine-CursorY;
-      for (i=1; i<=C; i++)
-      {
-	CodeBuff[Ptr+X] = 'x';
-	AttrBuff[Ptr+X] = Attr.Attr;
-	AttrBuff2[Ptr+X] = Attr.Attr2;
-	AttrBuffFG[Ptr+X] = Attr.Fore;
-	AttrBuffBG[Ptr+X] = Attr.Back;
-	Ptr = NextLinePtr(Ptr);
-      }
-      BuffUpdateRect(X,CursorY,X,CursorY+C-1);
-      break;
-  }
+	switch (Direction) {
+		case 3:
+		case 4:
+			if (Direction==3) {
+				if (CursorY==0) {
+					return;
+				}
+				Y = CursorY-1;
+			}
+			else {
+				if (CursorY==NumOfLines-1-StatusLine) {
+					return;
+				}
+				Y = CursorY+1;
+			}
+			if (CursorX+C > NumOfColumns) {
+				C = NumOfColumns-CursorX;
+			}
+			Ptr = GetLinePtr(PageStart+Y);
+			memset(&(CodeBuff[Ptr+CursorX]),'q',C);
+			memset(&(AttrBuff[Ptr+CursorX]),Attr.Attr,C);
+			memset(&(AttrBuff2[Ptr+CursorX]),Attr.Attr2,C);
+			memset(&(AttrBuffFG[Ptr+CursorX]),Attr.Fore,C);
+			memset(&(AttrBuffBG[Ptr+CursorX]),Attr.Back,C);
+			BuffUpdateRect(CursorX,Y,CursorX+C-1,Y);
+			break;
+		case 5:
+		case 6:
+			if (Direction==5) {
+				if (CursorX==0) {
+					return;
+				}
+				X = CursorX - 1;
+			}
+			else {
+				if (CursorX==NumOfColumns-1) {
+					X = CursorX-1;
+				}
+				else {
+					X = CursorX+1;
+				}
+			}
+			Ptr = GetLinePtr(PageStart+CursorY);
+			if (CursorY+C > NumOfLines-StatusLine) {
+				C = NumOfLines-StatusLine-CursorY;
+			}
+			for (i=1; i<=C; i++) {
+				CodeBuff[Ptr+X] = 'x';
+				AttrBuff[Ptr+X] = Attr.Attr;
+				AttrBuff2[Ptr+X] = Attr.Attr2;
+				AttrBuffFG[Ptr+X] = Attr.Fore;
+				AttrBuffBG[Ptr+X] = Attr.Back;
+				Ptr = NextLinePtr(Ptr);
+			}
+			BuffUpdateRect(X,CursorY,X,CursorY+C-1);
+			break;
+	}
 }
 
 void BuffEraseBox
   (int XStart, int YStart, int XEnd, int YEnd)
 // IO-8256 terminal
 {
-  int C, i;
-  LONG Ptr;
+	int C, i;
+	LONG Ptr;
 
-  if (XEnd>NumOfColumns-1)
-    XEnd = NumOfColumns-1;
-  if (YEnd>NumOfLines-1-StatusLine)
-    YEnd = NumOfLines-1-StatusLine;
-  if (XStart>XEnd) return;
-  if (YStart>YEnd) return;
-  C = XEnd-XStart+1;
-  Ptr = GetLinePtr(PageStart+YStart);
-  for (i=YStart; i<=YEnd; i++)
-  {
-    if ((XStart>0) &&
-	((AttrBuff[Ptr+XStart-1] & AttrKanji) != 0))
-    {
-      CodeBuff[Ptr+XStart-1] = 0x20;
-      AttrBuff[Ptr+XStart-1] = CurCharAttr.Attr;
-      AttrBuff2[Ptr+XStart-1] = CurCharAttr.Attr2;
-      AttrBuffFG[Ptr+XStart-1] = CurCharAttr.Fore;
-      AttrBuffBG[Ptr+XStart-1] = CurCharAttr.Back;
-    }
-    if ((XStart+C<NumOfColumns) &&
-	((AttrBuff[Ptr+XStart+C-1] & AttrKanji) != 0))
-    {
-      CodeBuff[Ptr+XStart+C] = 0x20;
-      AttrBuff[Ptr+XStart+C] = CurCharAttr.Attr;
-      AttrBuff2[Ptr+XStart+C] = CurCharAttr.Attr2;
-      AttrBuffFG[Ptr+XStart+C] = CurCharAttr.Fore;
-      AttrBuffBG[Ptr+XStart+C] = CurCharAttr.Back;
-    }
-    memset(&(CodeBuff[Ptr+XStart]),0x20,C);
-    memset(&(AttrBuff[Ptr+XStart]),AttrDefault,C);
-    memset(&(AttrBuff2[Ptr+XStart]),CurCharAttr.Attr2,C);
-    memset(&(AttrBuffFG[Ptr+XStart]),CurCharAttr.Fore,C);
-    memset(&(AttrBuffBG[Ptr+XStart]),CurCharAttr.Back,C);
-    Ptr = NextLinePtr(Ptr);
-  }
-  BuffUpdateRect(XStart,YStart,XEnd,YEnd);
+	if (XEnd>NumOfColumns-1) {
+		XEnd = NumOfColumns-1;
+	}
+	if (YEnd>NumOfLines-1-StatusLine) {
+		YEnd = NumOfLines-1-StatusLine;
+	}
+	if (XStart>XEnd) {
+		return;
+	}
+	if (YStart>YEnd) {
+		return;
+	}
+	C = XEnd-XStart+1;
+	Ptr = GetLinePtr(PageStart+YStart);
+	for (i=YStart; i<=YEnd; i++) {
+		if ((XStart>0) &&
+		    ((AttrBuff[Ptr+XStart-1] & AttrKanji) != 0)) {
+			CodeBuff[Ptr+XStart-1] = 0x20;
+			AttrBuff[Ptr+XStart-1] = CurCharAttr.Attr;
+			AttrBuff2[Ptr+XStart-1] = CurCharAttr.Attr2;
+			AttrBuffFG[Ptr+XStart-1] = CurCharAttr.Fore;
+			AttrBuffBG[Ptr+XStart-1] = CurCharAttr.Back;
+		}
+		if ((XStart+C<NumOfColumns) &&
+		    ((AttrBuff[Ptr+XStart+C-1] & AttrKanji) != 0)) {
+			CodeBuff[Ptr+XStart+C] = 0x20;
+			AttrBuff[Ptr+XStart+C] = CurCharAttr.Attr;
+			AttrBuff2[Ptr+XStart+C] = CurCharAttr.Attr2;
+			AttrBuffFG[Ptr+XStart+C] = CurCharAttr.Fore;
+			AttrBuffBG[Ptr+XStart+C] = CurCharAttr.Back;
+		}
+		memset(&(CodeBuff[Ptr+XStart]),0x20,C);
+		memset(&(AttrBuff[Ptr+XStart]),AttrDefault,C);
+		memset(&(AttrBuff2[Ptr+XStart]),CurCharAttr.Attr2,C);
+		memset(&(AttrBuffFG[Ptr+XStart]),CurCharAttr.Fore,C);
+		memset(&(AttrBuffBG[Ptr+XStart]),CurCharAttr.Back,C);
+		Ptr = NextLinePtr(Ptr);
+	}
+	BuffUpdateRect(XStart,YStart,XEnd,YEnd);
 }
 
 int LeftHalfOfDBCS(LONG Line, int CharPtr)
@@ -972,10 +996,11 @@
 //   CharPtr: points to a char
 //   return: points to the left half of the DBCS
 {
-  if ((CharPtr>0) &&
-      ((AttrBuff[Line+CharPtr-1] & AttrKanji) != 0))
-    CharPtr--;
-  return CharPtr;
+	if ((CharPtr>0) &&
+		((AttrBuff[Line+CharPtr-1] & AttrKanji) != 0)) {
+		CharPtr--;
+	}
+	return CharPtr;
 }
 
 int MoveCharPtr(LONG Line, int *x, int dx)
@@ -984,292 +1009,306 @@
 //   Line: points to a line in CodeBuff
 //   x: points to a character in the line
 //   dx: moving distance in character unit (-: left, +: right)
-//		One DBCS character is counted as one character.
+//      One DBCS character is counted as one character.
 //      The pointer stops at the beginning or the end of line.
 // Output
 //   x: new pointer. x points to a SBCS character or
 //      the left half of a DBCS character.
 //   return: actual moving distance in character unit
 {
-  int i;
+	int i;
 
-  *x = LeftHalfOfDBCS(Line,*x);
-  i = 0;
-  while (dx!=0)
-  {
-    if (dx>0) // move right
-    {
-      if ((AttrBuff[Line+*x] & AttrKanji) != 0)
-      {
-	if (*x<NumOfColumns-2)
-	{
-	  i++;
-	  *x = *x + 2;
+	*x = LeftHalfOfDBCS(Line,*x);
+	i = 0;
+	while (dx!=0) {
+		if (dx>0) { // move right
+			if ((AttrBuff[Line+*x] & AttrKanji) != 0) {
+				if (*x<NumOfColumns-2) {
+					i++;
+					*x = *x + 2;
+				}
+			}
+			else if (*x<NumOfColumns-1) {
+				i++;
+				(*x)++;
+			}
+			dx--;
+		}
+		else { // move left
+			if (*x>0) {
+				i--;
+				(*x)--;
+			}
+			*x = LeftHalfOfDBCS(Line,*x);
+			dx++;
+		}
 	}
-      }
-      else if (*x<NumOfColumns-1)
-      {
-	i++;
-	(*x)++;
-      }
-      dx--;
-    }
-    else { // move left
-      if (*x>0)
-      {
-	i--;
-	(*x)--;
-      }
-      *x = LeftHalfOfDBCS(Line,*x);
-      dx++;
-    }
-  }
-  return i;
+	return i;
 }
 
 void BuffCBCopy(BOOL Table)
 // copy selected text to clipboard
 {
-  LONG MemSize;
-  PCHAR CBPtr;
-  LONG TmpPtr;
-  int i, j, k, IStart, IEnd;
-  BOOL Sp, FirstChar;
-  BYTE b;
+	LONG MemSize;
+	PCHAR CBPtr;
+	LONG TmpPtr;
+	int i, j, k, IStart, IEnd;
+	BOOL Sp, FirstChar;
+	BYTE b;
 #ifndef NO_COPYLINE_FIX
-  BOOL LineContinued, PrevLineContinued;
-  LineContinued = FALSE;
+	BOOL LineContinued, PrevLineContinued;
+	LineContinued = FALSE;
 #endif /* NO_COPYLINE_FIX */
 
-  if (TalkStatus==IdTalkCB) return;
-  if (! Selected) return;
+	if (TalkStatus==IdTalkCB) {
+		return;
+	}
+	if (! Selected) {
+		return;
+	}
 
 // --- open clipboard and get CB memory
-  if (BoxSelect)
-    MemSize = (SelectEnd.x-SelectStart.x+3)*
-	      (SelectEnd.y-SelectStart.y+1) + 1;
-  else 
-    MemSize = (SelectEnd.y-SelectStart.y)*
-	      (NumOfColumns+2) +
-	      SelectEnd.x - SelectStart.x + 1;
-  CBPtr = CBOpen(MemSize);
-  if (CBPtr==NULL) return;
+	if (BoxSelect) {
+		MemSize = (SelectEnd.x-SelectStart.x+3)*
+		          (SelectEnd.y-SelectStart.y+1) + 1;
+	}
+	else {
+		MemSize = (SelectEnd.y-SelectStart.y)*
+		          (NumOfColumns+2) +
+		          SelectEnd.x - SelectStart.x + 1;
+	}
+	CBPtr = CBOpen(MemSize);
+	if (CBPtr==NULL) {
+		return;
+	}
 
 // --- copy selected text to CB memory
-  LockBuffer();
+	LockBuffer();
 
-  CBPtr[0] = 0;
-  TmpPtr = GetLinePtr(SelectStart.y);
-  k = 0;
-  for (j = SelectStart.y ; j<=SelectEnd.y ; j++)
-  {
-    if (BoxSelect)
-    {
-      IStart = SelectStart.x;
-      IEnd = SelectEnd.x-1;
-    }
-    else {
-      IStart = 0;
-      IEnd = NumOfColumns-1;
-      if (j==SelectStart.y) IStart = SelectStart.x;
-      if (j==SelectEnd.y) IEnd = SelectEnd.x-1;
-    }
-    i = LeftHalfOfDBCS(TmpPtr,IStart);
-    if (i!=IStart)
-    {
-      if (j==SelectStart.y)
-	IStart = i;
-      else
-	IStart = i + 2;
-    }
+	CBPtr[0] = 0;
+	TmpPtr = GetLinePtr(SelectStart.y);
+	k = 0;
+	for (j = SelectStart.y ; j<=SelectEnd.y ; j++) {
+		if (BoxSelect) {
+			IStart = SelectStart.x;
+			IEnd = SelectEnd.x-1;
+		}
+		else {
+			IStart = 0;
+			IEnd = NumOfColumns-1;
+			if (j==SelectStart.y) {
+				IStart = SelectStart.x;
+			}
+			if (j==SelectEnd.y) {
+				IEnd = SelectEnd.x-1;
+			}
+		}
+		i = LeftHalfOfDBCS(TmpPtr,IStart);
+		if (i!=IStart) {
+			if (j==SelectStart.y) {
+				IStart = i;
+			}
+			else {
+				IStart = i + 2;
+			}
+		}
 
-    // exclude right-side space characters
-    IEnd = LeftHalfOfDBCS(TmpPtr,IEnd);
+		// exclude right-side space characters
+		IEnd = LeftHalfOfDBCS(TmpPtr,IEnd);
 #ifndef NO_COPYLINE_FIX
-    PrevLineContinued = LineContinued;
-    LineContinued = FALSE;
-    if (ts.EnableContinuedLineCopy && j!=SelectEnd.y && !BoxSelect)
-    {
-      LONG NextTmpPtr = NextLinePtr(TmpPtr);
-      if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0)
-      LineContinued = TRUE;
-      if (IEnd == NumOfColumns-1 &&
-	(AttrBuff[TmpPtr + IEnd] & AttrLineContinued) != 0)
-      MoveCharPtr(TmpPtr,&IEnd,-1);
-    }
-    if (!LineContinued)
+		PrevLineContinued = LineContinued;
+		LineContinued = FALSE;
+		if (ts.EnableContinuedLineCopy && j!=SelectEnd.y && !BoxSelect) {
+			LONG NextTmpPtr = NextLinePtr(TmpPtr);
+			if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0) {
+				LineContinued = TRUE;
+			}
+			if (IEnd == NumOfColumns-1 &&
+				(AttrBuff[TmpPtr + IEnd] & AttrLineContinued) != 0) {
+				MoveCharPtr(TmpPtr,&IEnd,-1);
+			}
+		}
+		if (!LineContinued)
 #endif /* NO_COPYLINE_FIX */
-    while ((IEnd>0) && (CodeBuff[TmpPtr+IEnd]==0x20))
-      MoveCharPtr(TmpPtr,&IEnd,-1);
-    if ((IEnd==0) && (CodeBuff[TmpPtr]==0x20))
-      IEnd = -1;
-    else if ((AttrBuff[TmpPtr+IEnd] & AttrKanji) != 0) /* DBCS first byte? */
-      IEnd++;
+			while ((IEnd>0) && (CodeBuff[TmpPtr+IEnd]==0x20)) {
+				MoveCharPtr(TmpPtr,&IEnd,-1);
+			}
+		if ((IEnd==0) && (CodeBuff[TmpPtr]==0x20)) {
+			IEnd = -1;
+		}
+		else if ((AttrBuff[TmpPtr+IEnd] & AttrKanji) != 0) { /* DBCS first byte? */
+			IEnd++;
+		}
 
-    Sp = FALSE;
-    FirstChar = TRUE;
-    i = IStart;
-    while (i <= IEnd)
-    {
-      b = CodeBuff[TmpPtr+i];
-      i++;
-      if (! Sp)
-      {
-	if ((Table) && (b<=0x20))
-	{
-	  Sp = TRUE;
-	  b = 0x09;
-	}
+		Sp = FALSE;
+		FirstChar = TRUE;
+		i = IStart;
+		while (i <= IEnd) {
+			b = CodeBuff[TmpPtr+i];
+			i++;
+			if (! Sp) {
+				if ((Table) && (b<=0x20)) {
+					Sp = TRUE;
+					b = 0x09;
+				}
 #ifndef NO_COPYLINE_FIX
-	if ((b!=0x09) || (! FirstChar) || PrevLineContinued)
+				if ((b!=0x09) || (! FirstChar) || PrevLineContinued) {
 #else
-	if ((b!=0x09) || (! FirstChar))
+				if ((b!=0x09) || (! FirstChar)) {
 #endif
-	{
-	  FirstChar = FALSE;
-	  CBPtr[k] = b;
-	  k++;
-	}
-      }
-      else {
-	if (b>0x20)
-	{
-	  Sp = FALSE;
-	  FirstChar = FALSE;
-	  CBPtr[k] = b;
-	  k++;
-	}
-      }
-    }
+					FirstChar = FALSE;
+					CBPtr[k] = b;
+					k++;
+				}
+			}
+			else {
+				if (b>0x20) {
+					Sp = FALSE;
+					FirstChar = FALSE;
+					CBPtr[k] = b;
+					k++;
+				}
+			}
+		}
 
 #ifndef NO_COPYLINE_FIX
-    if (!LineContinued)
+		if (!LineContinued)
 #endif /* NO_COPYLINE_FIX */
-    if (j < SelectEnd.y)
-    {
-      CBPtr[k] = 0x0d;
-      k++;
-      CBPtr[k] = 0x0a;
-      k++;
-    }
+			if (j < SelectEnd.y) {
+				CBPtr[k] = 0x0d;
+				k++;
+				CBPtr[k] = 0x0a;
+				k++;
+			}
 
-    TmpPtr = NextLinePtr(TmpPtr);
-  }
-  CBPtr[k] = 0;
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
+	CBPtr[k] = 0;
 #ifndef NO_COPYLINE_FIX
-    LineContinued = FALSE;
-    if (ts.EnableContinuedLineCopy && j!=SelectEnd.y && !BoxSelect && j<BuffEnd-1)
-    {
-      LONG NextTmpPtr = NextLinePtr(TmpPtr);
-      if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0)
-      LineContinued = TRUE;
-      if (IEnd == NumOfColumns-1 &&
-        (AttrBuff[TmpPtr + IEnd] & AttrLineContinued) != 0)
-      MoveCharPtr(TmpPtr,&IEnd,-1);
-    }
-    if (!LineContinued)
+	LineContinued = FALSE;
+	if (ts.EnableContinuedLineCopy && j!=SelectEnd.y && !BoxSelect && j<BuffEnd-1) {
+		LONG NextTmpPtr = NextLinePtr(TmpPtr);
+		if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0) {
+			LineContinued = TRUE;
+		}
+		if (IEnd == NumOfColumns-1 &&
+			(AttrBuff[TmpPtr + IEnd] & AttrLineContinued) != 0) {
+			MoveCharPtr(TmpPtr,&IEnd,-1);
+		}
+	}
+	if (!LineContinued)
 #endif /* NO_COPYLINE_FIX */
-  UnlockBuffer();
+		UnlockBuffer();
 
 // --- send CB memory to clipboard
-  CBClose();
-  return;
+	CBClose();
+	return;
 }
 
 void BuffPrint(BOOL ScrollRegion)
 // Print screen or selected text
 {
-  int Id;
-  POINT PrintStart, PrintEnd;
-  TCharAttr CurAttr, TempAttr;
-  int i, j, count;
-  int IStart, IEnd;
-  LONG TmpPtr;
+	int Id;
+	POINT PrintStart, PrintEnd;
+	TCharAttr CurAttr, TempAttr;
+	int i, j, count;
+	int IStart, IEnd;
+	LONG TmpPtr;
 
-  TempAttr = DefCharAttr;
+	TempAttr = DefCharAttr;
 
-  if (ScrollRegion)
-    Id = VTPrintInit(IdPrnScrollRegion);
-  else if (Selected)
-    Id = VTPrintInit(IdPrnScreen | IdPrnSelectedText);
-  else
-    Id = VTPrintInit(IdPrnScreen);
-  if (Id==IdPrnCancel) return;
+	if (ScrollRegion) {
+		Id = VTPrintInit(IdPrnScrollRegion);
+	}
+	else if (Selected) {
+		Id = VTPrintInit(IdPrnScreen | IdPrnSelectedText);
+	}
+	else {
+		Id = VTPrintInit(IdPrnScreen);
+	}
+	if (Id==IdPrnCancel) {
+		return;
+	}
 
-  /* set print region */
-  if (Id==IdPrnSelectedText)
-  {
-    /* print selected region */
-    PrintStart = SelectStart;
-    PrintEnd = SelectEnd;
-  }
-  else if (Id==IdPrnScrollRegion)
-  {
-    /* print scroll region */
-    PrintStart.x = 0;
-    PrintStart.y = PageStart + CursorTop;
-    PrintEnd.x = NumOfColumns;
-    PrintEnd.y = PageStart + CursorBottom;
-  }
-  else {
-    /* print current screen */
-    PrintStart.x = 0;
-    PrintStart.y = PageStart;
-    PrintEnd.x = NumOfColumns;
-    PrintEnd.y = PageStart + NumOfLines - 1;
-  }
-  if (PrintEnd.y > BuffEnd-1)
-    PrintEnd.y = BuffEnd-1;
+	/* set print region */
+	if (Id==IdPrnSelectedText) {
+		/* print selected region */
+		PrintStart = SelectStart;
+		PrintEnd = SelectEnd;
+	}
+	else if (Id==IdPrnScrollRegion) {
+		/* print scroll region */
+		PrintStart.x = 0;
+		PrintStart.y = PageStart + CursorTop;
+		PrintEnd.x = NumOfColumns;
+		PrintEnd.y = PageStart + CursorBottom;
+	}
+	else {
+		/* print current screen */
+		PrintStart.x = 0;
+		PrintStart.y = PageStart;
+		PrintEnd.x = NumOfColumns;
+		PrintEnd.y = PageStart + NumOfLines - 1;
+	}
+	if (PrintEnd.y > BuffEnd-1) {
+		PrintEnd.y = BuffEnd-1;
+	}
 
-  LockBuffer();
+	LockBuffer();
 
-  TmpPtr = GetLinePtr(PrintStart.y);
-  for (j = PrintStart.y ; j <= PrintEnd.y ; j++)
-  {
-    if (j==PrintStart.y)
-      IStart = PrintStart.x;
-    else IStart = 0;
-    if (j == PrintEnd.y)
-      IEnd = PrintEnd.x - 1;
-    else
-      IEnd = NumOfColumns - 1;
+	TmpPtr = GetLinePtr(PrintStart.y);
+	for (j = PrintStart.y ; j <= PrintEnd.y ; j++) {
+		if (j==PrintStart.y) {
+			IStart = PrintStart.x;
+		}
+		else {
+			IStart = 0;
+		}
+		if (j == PrintEnd.y) {
+			IEnd = PrintEnd.x - 1;
+		}
+		else {
+			IEnd = NumOfColumns - 1;
+		}
 
-    while ((IEnd>=IStart) &&
-	   (CodeBuff[TmpPtr+IEnd]==0x20) &&
-	   (AttrBuff[TmpPtr+IEnd]==AttrDefault) &&
-	   (AttrBuff2[TmpPtr+IEnd]==AttrDefault))
- 	IEnd--;
+		while ((IEnd>=IStart) &&
+		       (CodeBuff[TmpPtr+IEnd]==0x20) &&
+		       (AttrBuff[TmpPtr+IEnd]==AttrDefault) &&
+		       (AttrBuff2[TmpPtr+IEnd]==AttrDefault)) {
+			IEnd--;
+		}
 
-    i = IStart;
-    while (i <= IEnd) {
-      CurAttr.Attr = AttrBuff[TmpPtr+i] & ~ AttrKanji;
-      CurAttr.Attr2 = AttrBuff2[TmpPtr+i];
-      CurAttr.Fore = AttrBuffFG[TmpPtr+i];
-      CurAttr.Back = AttrBuffBG[TmpPtr+i];
+		i = IStart;
+		while (i <= IEnd) {
+			CurAttr.Attr = AttrBuff[TmpPtr+i] & ~ AttrKanji;
+			CurAttr.Attr2 = AttrBuff2[TmpPtr+i];
+			CurAttr.Fore = AttrBuffFG[TmpPtr+i];
+			CurAttr.Back = AttrBuffBG[TmpPtr+i];
 
-      count = 1;
-      while ((i+count <= IEnd) &&
-	     (CurAttr.Attr == (AttrBuff[TmpPtr+i+count] & ~ AttrKanji)) &&
-	     (CurAttr.Attr2 == AttrBuff2[TmpPtr+i+count]) &&
-	     (CurAttr.Fore == AttrBuffFG[TmpPtr+i+count]) &&
-	     (CurAttr.Back == AttrBuffBG[TmpPtr+i+count]) ||
-	     (i+count<NumOfColumns) &&
-	     ((AttrBuff[TmpPtr+i+count-1] & AttrKanji) != 0))
-	count++;
+			count = 1;
+			while ((i+count <= IEnd) &&
+			       (CurAttr.Attr == (AttrBuff[TmpPtr+i+count] & ~ AttrKanji)) &&
+			       (CurAttr.Attr2 == AttrBuff2[TmpPtr+i+count]) &&
+			       (CurAttr.Fore == AttrBuffFG[TmpPtr+i+count]) &&
+			       (CurAttr.Back == AttrBuffBG[TmpPtr+i+count]) ||
+			       (i+count<NumOfColumns) &&
+			       ((AttrBuff[TmpPtr+i+count-1] & AttrKanji) != 0)) {
+				count++;
+			}
 
-      if (TCharAttrCmp(CurAttr, TempAttr) != 0) {
-	PrnSetAttr(CurAttr);
-	TempAttr = CurAttr;
-      }
-      PrnOutText(&(CodeBuff[TmpPtr+i]),count);	
-      i = i+count;
-    }
-    PrnNewLine();
-    TmpPtr = NextLinePtr(TmpPtr);
-  }
+			if (TCharAttrCmp(CurAttr, TempAttr) != 0) {
+				PrnSetAttr(CurAttr);
+				TempAttr = CurAttr;
+			}
+			PrnOutText(&(CodeBuff[TmpPtr+i]),count);
+			i = i+count;
+		}
+		PrnNewLine();
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
 
-  UnlockBuffer();
-  VTPrintEnd();
+	UnlockBuffer();
+	VTPrintEnd();
 }
 
 void BuffDumpCurrentLine(BYTE TERM)
@@ -1278,19 +1317,20 @@
 //   TERM: terminator character
 //	= LF or VT or FF
 {
-  int i, j;
+	int i, j;
 
-  i = NumOfColumns;
-  while ((i>0) && (CodeLine[i-1]==0x20))
-    i--;
-  for (j=0; j<i; j++)
-    WriteToPrnFile(CodeLine[j],FALSE);
-  WriteToPrnFile(0,TRUE);
-  if ((TERM>=LF) && (TERM<=FF))
-  {
-    WriteToPrnFile(0x0d,FALSE);
-    WriteToPrnFile(TERM,TRUE);
-  }
+	i = NumOfColumns;
+	while ((i>0) && (CodeLine[i-1]==0x20)) {
+		i--;
+	}
+	for (j=0; j<i; j++) {
+		WriteToPrnFile(CodeLine[j],FALSE);
+	}
+	WriteToPrnFile(0,TRUE);
+	if ((TERM>=LF) && (TERM<=FF)) {
+		WriteToPrnFile(0x0d,FALSE);
+		WriteToPrnFile(TERM,TRUE);
+	}
 }
 
 
@@ -1376,66 +1416,70 @@
 //   Attr: attributes
 //   Insert: Insert flag
 {
-  int XStart;
+	int XStart;
 
 #ifndef NO_COPYLINE_FIX
-  if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
-    Attr.Attr |= AttrLineContinued;
-  }
+	if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
+		Attr.Attr |= AttrLineContinued;
+	}
 #endif /* NO_COPYLINE_FIX */
 
-  if (ts.Language==IdJapanese)
-  {
-    EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
-    if (! Insert) EraseKanji(0); /* if cursor on left half... */
-  }
+	if (ts.Language==IdJapanese) {
+		EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+		if (! Insert) {
+			EraseKanji(0); /* if cursor on left half... */
+		}
+	}
 
-  if (Insert)
-  {
-    memmove(&CodeLine[CursorX+1],&CodeLine[CursorX],NumOfColumns-1-CursorX);
-    memmove(&AttrLine[CursorX+1],&AttrLine[CursorX],NumOfColumns-1-CursorX);
-    memmove(&AttrLine2[CursorX+1],&AttrLine2[CursorX],NumOfColumns-1-CursorX);
-    memmove(&AttrLineFG[CursorX+1],&AttrLineFG[CursorX],NumOfColumns-1-CursorX);
-    memmove(&AttrLineBG[CursorX+1],&AttrLineBG[CursorX],NumOfColumns-1-CursorX);
-    CodeLine[CursorX] = b;
-    AttrLine[CursorX] = Attr.Attr;
-    AttrLine2[CursorX] = Attr.Attr2;
-    AttrLineFG[CursorX] = Attr.Fore;
-    AttrLineBG[CursorX] = Attr.Back;
-    /* last char in current line is kanji first? */
-    if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0)
-    {
-      /* then delete it */
-      CodeLine[NumOfColumns-1] = 0x20;
-      AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
-      AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
-      AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
-      AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
-    }
-    /* begin - ishizaki */
-    markURL(CursorX+1);
-    markURL(CursorX);
-    /* end - ishizaki */
+	if (Insert) {
+		memmove(&CodeLine[CursorX+1],&CodeLine[CursorX],NumOfColumns-1-CursorX);
+		memmove(&AttrLine[CursorX+1],&AttrLine[CursorX],NumOfColumns-1-CursorX);
+		memmove(&AttrLine2[CursorX+1],&AttrLine2[CursorX],NumOfColumns-1-CursorX);
+		memmove(&AttrLineFG[CursorX+1],&AttrLineFG[CursorX],NumOfColumns-1-CursorX);
+		memmove(&AttrLineBG[CursorX+1],&AttrLineBG[CursorX],NumOfColumns-1-CursorX);
+		CodeLine[CursorX] = b;
+		AttrLine[CursorX] = Attr.Attr;
+		AttrLine2[CursorX] = Attr.Attr2;
+		AttrLineFG[CursorX] = Attr.Fore;
+		AttrLineBG[CursorX] = Attr.Back;
+		/* last char in current line is kanji first? */
+		if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
+			/* then delete it */
+			CodeLine[NumOfColumns-1] = 0x20;
+			AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
+			AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
+			AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
+			AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
+		}
+		/* begin - ishizaki */
+		markURL(CursorX+1);
+		markURL(CursorX);
+		/* end - ishizaki */
 
-    if (StrChangeCount==0) XStart = CursorX;
-		      else XStart = StrChangeStart;
-    StrChangeCount = 0;
-    BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
-  }
-  else {
-    CodeLine[CursorX] = b;
-    AttrLine[CursorX] = Attr.Attr;
-    AttrLine2[CursorX] = Attr.Attr2;
-    AttrLineFG[CursorX] = Attr.Fore;
-    AttrLineBG[CursorX] = Attr.Back;
-    /* begin - ishizaki */
-    markURL(CursorX);
-    /* end - ishizaki */
+		if (StrChangeCount==0) {
+			XStart = CursorX;
+		}
+		else {
+			XStart = StrChangeStart;
+		}
+		StrChangeCount = 0;
+		BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
+	}
+	else {
+		CodeLine[CursorX] = b;
+		AttrLine[CursorX] = Attr.Attr;
+		AttrLine2[CursorX] = Attr.Attr2;
+		AttrLineFG[CursorX] = Attr.Fore;
+		AttrLineBG[CursorX] = Attr.Back;
+		/* begin - ishizaki */
+		markURL(CursorX);
+		/* end - ishizaki */
 
-    if (StrChangeCount==0)
-      StrChangeStart = CursorX;
-    StrChangeCount++;
-  }
+		if (StrChangeCount==0) {
+			StrChangeStart = CursorX;
+		}
+		StrChangeCount++;
+	}
 }
 
 void BuffPutKanji(WORD w, TCharAttr Attr, BOOL Insert)
@@ -1444,104 +1488,104 @@
 //   Attr: attributes
 //   Insert: Insert flag
 {
-  int XStart;
+	int XStart;
 
 #ifndef NO_COPYLINE_FIX
-  if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
-    Attr.Attr |= AttrLineContinued;
-  }
+	if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
+		Attr.Attr |= AttrLineContinued;
+	}
 #endif /* NO_COPYLINE_FIX */
 
-  EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
+	EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
 
-  if (Insert)
-  {
-    memmove(&CodeLine[CursorX+2],&CodeLine[CursorX],NumOfColumns-2-CursorX);
-    memmove(&AttrLine[CursorX+2],&AttrLine[CursorX],NumOfColumns-2-CursorX);
-    memmove(&AttrLine2[CursorX+2],&AttrLine2[CursorX],NumOfColumns-2-CursorX);
-    memmove(&AttrLineFG[CursorX+2],&AttrLineFG[CursorX],NumOfColumns-2-CursorX);
-    memmove(&AttrLineBG[CursorX+2],&AttrLineBG[CursorX],NumOfColumns-2-CursorX);
+	if (Insert) {
+		memmove(&CodeLine[CursorX+2],&CodeLine[CursorX],NumOfColumns-2-CursorX);
+		memmove(&AttrLine[CursorX+2],&AttrLine[CursorX],NumOfColumns-2-CursorX);
+		memmove(&AttrLine2[CursorX+2],&AttrLine2[CursorX],NumOfColumns-2-CursorX);
+		memmove(&AttrLineFG[CursorX+2],&AttrLineFG[CursorX],NumOfColumns-2-CursorX);
+		memmove(&AttrLineBG[CursorX+2],&AttrLineBG[CursorX],NumOfColumns-2-CursorX);
 
-    CodeLine[CursorX] = HIBYTE(w);
-    AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
-    AttrLine2[CursorX] = Attr.Attr2;
-    AttrLineFG[CursorX] = Attr.Fore;
-    AttrLineBG[CursorX] = Attr.Back;
-    if (CursorX < NumOfColumns-1)
-    {
-      CodeLine[CursorX+1] = LOBYTE(w);
-      AttrLine[CursorX+1] = Attr.Attr;
-      AttrLine2[CursorX+1] = Attr.Attr2;
-      AttrLineFG[CursorX+1] = Attr.Fore;
-      AttrLineBG[CursorX+1] = Attr.Back;
-    }
-    /* begin - ishizaki */
-    markURL(CursorX);
-    markURL(CursorX+1);
-    /* end - ishizaki */
+		CodeLine[CursorX] = HIBYTE(w);
+		AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
+		AttrLine2[CursorX] = Attr.Attr2;
+		AttrLineFG[CursorX] = Attr.Fore;
+		AttrLineBG[CursorX] = Attr.Back;
+		if (CursorX < NumOfColumns-1) {
+			CodeLine[CursorX+1] = LOBYTE(w);
+			AttrLine[CursorX+1] = Attr.Attr;
+			AttrLine2[CursorX+1] = Attr.Attr2;
+			AttrLineFG[CursorX+1] = Attr.Fore;
+			AttrLineBG[CursorX+1] = Attr.Back;
+		}
+		/* begin - ishizaki */
+		markURL(CursorX);
+		markURL(CursorX+1);
+		/* end - ishizaki */
 
-    /* last char in current line is kanji first? */
-    if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0)
-    {
-      /* then delete it */
-      CodeLine[NumOfColumns-1] = 0x20;
-      AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
-      AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
-      AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
-      AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
-    }
+		/* last char in current line is kanji first? */
+		if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
+			/* then delete it */
+			CodeLine[NumOfColumns-1] = 0x20;
+			AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
+			AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
+			AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
+			AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
+		}
 
-    if (StrChangeCount==0) XStart = CursorX;
-		      else XStart = StrChangeStart;
-    StrChangeCount = 0;
-    BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
-  }
-  else {
-    CodeLine[CursorX] = HIBYTE(w);
-    AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
-    AttrLine2[CursorX] = Attr.Attr2;
-    AttrLineFG[CursorX] = Attr.Fore;
-    AttrLineBG[CursorX] = Attr.Back;
-    if (CursorX < NumOfColumns-1)
-    {
-      CodeLine[CursorX+1] = LOBYTE(w);
-      AttrLine[CursorX+1] = Attr.Attr;
-      AttrLine2[CursorX+1] = Attr.Attr2;
-      AttrLineFG[CursorX+1] = Attr.Fore;
-      AttrLineBG[CursorX+1] = Attr.Back;
-    }
-    /* begin - ishizaki */
-    markURL(CursorX);
-    markURL(CursorX+1);
-    /* end - ishizaki */
+		if (StrChangeCount==0) {
+			XStart = CursorX;
+		}
+		else {
+			XStart = StrChangeStart;
+		}
+		StrChangeCount = 0;
+		BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
+	}
+	else {
+		CodeLine[CursorX] = HIBYTE(w);
+		AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
+		AttrLine2[CursorX] = Attr.Attr2;
+		AttrLineFG[CursorX] = Attr.Fore;
+		AttrLineBG[CursorX] = Attr.Back;
+		if (CursorX < NumOfColumns-1) {
+			CodeLine[CursorX+1] = LOBYTE(w);
+			AttrLine[CursorX+1] = Attr.Attr;
+			AttrLine2[CursorX+1] = Attr.Attr2;
+			AttrLineFG[CursorX+1] = Attr.Fore;
+			AttrLineBG[CursorX+1] = Attr.Back;
+		}
+		/* begin - ishizaki */
+		markURL(CursorX);
+		markURL(CursorX+1);
+		/* end - ishizaki */
 
-    if (StrChangeCount==0)
-      StrChangeStart = CursorX;
-    StrChangeCount = StrChangeCount + 2;
-  }
+		if (StrChangeCount==0) {
+			StrChangeStart = CursorX;
+		}
+		StrChangeCount = StrChangeCount + 2;
+	}
 }
 
 BOOL CheckSelect(int x, int y)
 //  subroutine called by BuffUpdateRect
 {
-  LONG L, L1, L2;
+	LONG L, L1, L2;
 
-  if (BoxSelect)
-  {
-    return (Selected &&
-      ((SelectStart.x<=x) && (x<SelectEnd.x) ||
-       (SelectEnd.x<=x) && (x<SelectStart.x)) &&
-      ((SelectStart.y<=y) && (y<=SelectEnd.y) ||
-       (SelectEnd.y<=y) && (y<=SelectStart.y)));
-  }
-  else {
-    L = MAKELONG(x,y);
-    L1 = MAKELONG(SelectStart.x,SelectStart.y);
-    L2 = MAKELONG(SelectEnd.x,SelectEnd.y);
+	if (BoxSelect) {
+		return (Selected &&
+		((SelectStart.x<=x) && (x<SelectEnd.x) ||
+		 (SelectEnd.x<=x) && (x<SelectStart.x)) &&
+		((SelectStart.y<=y) && (y<=SelectEnd.y) ||
+		 (SelectEnd.y<=y) && (y<=SelectStart.y)));
+	}
+	else {
+		L = MAKELONG(x,y);
+		L1 = MAKELONG(SelectStart.x,SelectStart.y);
+		L2 = MAKELONG(SelectEnd.x,SelectEnd.y);
 
-    return (Selected &&
-      ((L1<=L) && (L<L2) || (L2<=L) && (L<L1)));
-  }
+		return (Selected &&
+			((L1<=L) && (L<L2) || (L2<=L) && (L<L1)));
+	}
 }
 
 void BuffUpdateRect
@@ -1552,98 +1596,118 @@
 //   XEnd: x position of the lower-right corner (last character)
 //   YEnd: y position
 {
-  int i, j, count;
-  int IStart, IEnd;
-  int X, Y;
-  LONG TmpPtr;
-  TCharAttr CurAttr, TempAttr;
-  BOOL CurSel, TempSel, Caret;
+	int i, j, count;
+	int IStart, IEnd;
+	int X, Y;
+	LONG TmpPtr;
+	TCharAttr CurAttr, TempAttr;
+	BOOL CurSel, TempSel, Caret;
 
-  if (XStart >= WinOrgX+WinWidth) return;
-  if (YStart >= WinOrgY+WinHeight) return;
-  if (XEnd < WinOrgX) return;
-  if (YEnd < WinOrgY) return;
+	if (XStart >= WinOrgX+WinWidth) {
+		return;
+	}
+	if (YStart >= WinOrgY+WinHeight) {
+		return;
+	}
+	if (XEnd < WinOrgX) {
+		return;
+	}
+	if (YEnd < WinOrgY) {
+		return;
+	}
 
-  if (XStart < WinOrgX) XStart = WinOrgX;
-  if (YStart < WinOrgY) YStart = WinOrgY;
-  if (XEnd >= WinOrgX+WinWidth) XEnd = WinOrgX+WinWidth-1;
-  if (YEnd >= WinOrgY+WinHeight) YEnd = WinOrgY+WinHeight-1;
+	if (XStart < WinOrgX) {
+		XStart = WinOrgX;
+	}
+	if (YStart < WinOrgY) {
+		YStart = WinOrgY;
+	}
+	if (XEnd >= WinOrgX+WinWidth) {
+		XEnd = WinOrgX+WinWidth-1;
+	}
+	if (YEnd >= WinOrgY+WinHeight) {
+		YEnd = WinOrgY+WinHeight-1;
+	}
 
-  TempAttr = DefCharAttr;
-  TempSel = FALSE;
+	TempAttr = DefCharAttr;
+	TempSel = FALSE;
 
-  Caret = IsCaretOn();
-  if (Caret) CaretOff();
+	Caret = IsCaretOn();
+	if (Caret) {
+		CaretOff();
+	}
 
-  DispSetupDC(DefCharAttr, TempSel);
+	DispSetupDC(DefCharAttr, TempSel);
 
-  Y = (YStart-WinOrgY)*FontHeight;
-  TmpPtr = GetLinePtr(PageStart+YStart);
-  for (j = YStart+PageStart ; j <= YEnd+PageStart ; j++)
-  {
-    IStart = XStart;
-    IEnd = XEnd;
+	Y = (YStart-WinOrgY)*FontHeight;
+	TmpPtr = GetLinePtr(PageStart+YStart);
+	for (j = YStart+PageStart ; j <= YEnd+PageStart ; j++) {
+		IStart = XStart;
+		IEnd = XEnd;
 
-    IStart = LeftHalfOfDBCS(TmpPtr,IStart);
+		IStart = LeftHalfOfDBCS(TmpPtr,IStart);
 
-    X = (IStart-WinOrgX)*FontWidth;
+		X = (IStart-WinOrgX)*FontWidth;
 
-    i = IStart;
-    do {
-      CurAttr.Attr = AttrBuff[TmpPtr+i] & ~ AttrKanji;
-      CurAttr.Attr2 = AttrBuff2[TmpPtr+i];
-      CurAttr.Fore = AttrBuffFG[TmpPtr+i];
-      CurAttr.Back = AttrBuffBG[TmpPtr+i];
-      CurSel = CheckSelect(i,j);
-      count = 1;
-      while
-	( (i+count <= IEnd) &&
-	  (CurAttr.Attr == (AttrBuff[TmpPtr+i+count] & ~ AttrKanji)) &&
-	  (CurAttr.Attr2==AttrBuff2[TmpPtr+i+count]) &&
-	  (CurAttr.Fore==AttrBuffFG[TmpPtr+i+count]) &&
-	  (CurAttr.Back==AttrBuffBG[TmpPtr+i+count]) &&
-	  (CurSel==CheckSelect(i+count,j)) ||
-	  (i+count<NumOfColumns) &&
-	  ((AttrBuff[TmpPtr+i+count-1] & AttrKanji) != 0) )
-	count++;
+		i = IStart;
+		do {
+			CurAttr.Attr = AttrBuff[TmpPtr+i] & ~ AttrKanji;
+			CurAttr.Attr2 = AttrBuff2[TmpPtr+i];
+			CurAttr.Fore = AttrBuffFG[TmpPtr+i];
+			CurAttr.Back = AttrBuffBG[TmpPtr+i];
+			CurSel = CheckSelect(i,j);
+			count = 1;
+			while ( (i+count <= IEnd) &&
+			        (CurAttr.Attr == (AttrBuff[TmpPtr+i+count] & ~ AttrKanji)) &&
+			        (CurAttr.Attr2==AttrBuff2[TmpPtr+i+count]) &&
+			        (CurAttr.Fore==AttrBuffFG[TmpPtr+i+count]) &&
+			        (CurAttr.Back==AttrBuffBG[TmpPtr+i+count]) &&
+			        (CurSel==CheckSelect(i+count,j)) ||
+			        (i+count<NumOfColumns) &&
+			        ((AttrBuff[TmpPtr+i+count-1] & AttrKanji) != 0) ) {
+				count++;
+			}
 
-      if (TCharAttrCmp(CurAttr, TempAttr) != 0 || (CurSel != TempSel)) {
-	DispSetupDC(CurAttr, CurSel);
-	TempAttr = CurAttr;
-	TempSel = CurSel;
-      }
-      DispStr(&CodeBuff[TmpPtr+i],count,Y, &X);
-      i = i+count;
-    }
-    while (i<=IEnd);
-    Y = Y + FontHeight;
-    TmpPtr = NextLinePtr(TmpPtr);
-  }
-  if (Caret) CaretOn();
+			if (TCharAttrCmp(CurAttr, TempAttr) != 0 || (CurSel != TempSel)) {
+				DispSetupDC(CurAttr, CurSel);
+				TempAttr = CurAttr;
+				TempSel = CurSel;
+			}
+			DispStr(&CodeBuff[TmpPtr+i],count,Y, &X);
+			i = i+count;
+		}
+		while (i<=IEnd);
+		Y = Y + FontHeight;
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
+	if (Caret) {
+		CaretOn();
+	}
 }
 
 void UpdateStr()
 // Display not-yet-displayed string
 {
-  int X, Y;
-  TCharAttr TempAttr;
+	int X, Y;
+	TCharAttr TempAttr;
 
-  if (StrChangeCount==0) return;
-  X = StrChangeStart;
-  Y = CursorY;
-  if (! IsLineVisible(&X, &Y))
-  {
-    StrChangeCount = 0;
-    return;
-  }
+	if (StrChangeCount==0) {
+		return;
+	}
+	X = StrChangeStart;
+	Y = CursorY;
+	if (! IsLineVisible(&X, &Y)) {
+		StrChangeCount = 0;
+		return;
+	}
 
-  TempAttr.Attr = AttrLine[StrChangeStart];
-  TempAttr.Attr2 = AttrLine2[StrChangeStart];
-  TempAttr.Fore = AttrLineFG[StrChangeStart];
-  TempAttr.Back = AttrLineBG[StrChangeStart];
-  DispSetupDC(TempAttr, FALSE);
-  DispStr(&CodeLine[StrChangeStart],StrChangeCount,Y, &X);
-  StrChangeCount = 0;
+	TempAttr.Attr = AttrLine[StrChangeStart];
+	TempAttr.Attr2 = AttrLine2[StrChangeStart];
+	TempAttr.Fore = AttrLineFG[StrChangeStart];
+	TempAttr.Back = AttrLineBG[StrChangeStart];
+	DispSetupDC(TempAttr, FALSE);
+	DispStr(&CodeLine[StrChangeStart],StrChangeCount,Y, &X);
+	StrChangeCount = 0;
 }
 
 #if 0
@@ -1674,291 +1738,301 @@
 
 void MoveCursor(int Xnew, int Ynew)
 {
-  UpdateStr();
+	UpdateStr();
 
-  if (CursorY!=Ynew) NewLine(PageStart+Ynew);
+	if (CursorY!=Ynew) {
+		NewLine(PageStart+Ynew);
+	}
 
-  CursorX = Xnew;
-  CursorY = Ynew;
-  Wrap = FALSE;
+	CursorX = Xnew;
+	CursorY = Ynew;
+	Wrap = FALSE;
 
-  /* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é*/
-  if (ts.AutoScrollOnlyInBottomLine == 0 || WinOrgY == 0) {
-    DispScrollToCursor(CursorX, CursorY);
-  }
+	/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é*/
+	if (ts.AutoScrollOnlyInBottomLine == 0 || WinOrgY == 0) {
+		DispScrollToCursor(CursorX, CursorY);
+	}
 }
 
 void MoveRight()
 /* move cursor right, but dont update screen.
   this procedure must be called from DispChar&DispKanji only */
 {
-  CursorX++;
-  /* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é */
-  if (ts.AutoScrollOnlyInBottomLine == 0 || WinOrgY == 0) {
-    DispScrollToCursor(CursorX, CursorY);
-  }
+	CursorX++;
+	/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é */
+	if (ts.AutoScrollOnlyInBottomLine == 0 || WinOrgY == 0) {
+		DispScrollToCursor(CursorX, CursorY);
+	}
 }
 
 void BuffSetCaretWidth()
 {
-  BOOL DW;
+	BOOL DW;
 
-  /* check whether cursor on a DBCS character */
-  DW = (((BYTE)(AttrLine[CursorX]) & AttrKanji) != 0);
-  DispSetCaretWidth(DW);
+	/* check whether cursor on a DBCS character */
+	DW = (((BYTE)(AttrLine[CursorX]) & AttrKanji) != 0);
+	DispSetCaretWidth(DW);
 }
 
 void ScrollUp1Line()
 {
-  int i;
-  LONG SrcPtr, DestPtr;
+	int i;
+	LONG SrcPtr, DestPtr;
 
-  if ((CursorTop<=CursorY) && (CursorY<=CursorBottom))
-  {
-    UpdateStr();
+	if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
+		UpdateStr();
 
-    DestPtr = GetLinePtr(PageStart+CursorBottom);
-    for (i = CursorBottom-1 ; i >= CursorTop ; i--)
-    {
-      SrcPtr = PrevLinePtr(DestPtr);
-      memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-      memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-      DestPtr = SrcPtr;
-    }
-    memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
-    memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
-    memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2,NumOfColumns);
-    memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
-    memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
+		DestPtr = GetLinePtr(PageStart+CursorBottom);
+		for (i = CursorBottom-1 ; i >= CursorTop ; i--) {
+			SrcPtr = PrevLinePtr(DestPtr);
+			memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+			memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+			DestPtr = SrcPtr;
+		}
+		memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
+		memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
+		memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2,NumOfColumns);
+		memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
+		memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
 
-    DispScrollNLines(CursorTop,CursorBottom,-1);
-  }
+		DispScrollNLines(CursorTop,CursorBottom,-1);
+	}
 }
 
 void BuffScrollNLines(int n)
 {
-  int i;
-  LONG SrcPtr, DestPtr;
+	int i;
+	LONG SrcPtr, DestPtr;
 
-  if (n<1) return;
-  UpdateStr();
+	if (n<1) {
+		return;
+	}
+	UpdateStr();
 
-  if ((CursorTop == 0) && (CursorBottom == NumOfLines-1))
-  {
-    WinOrgY = WinOrgY-n;
-    /* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é */
-    if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
-      NewOrgY = WinOrgY;
-    }
-    BuffScroll(n,CursorBottom);
-    DispCountScroll(n);
-  }
-  else if ((CursorTop==0) && (CursorY<=CursorBottom))
-  {
-    /* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é */
-    if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
-      /* ƒXƒNƒ[ƒ‹‚³‚¹‚È‚¢ê‡‚̏ˆ— */
-      WinOrgY = WinOrgY-n;
-      NewOrgY = WinOrgY;
-      BuffScroll(n,CursorBottom);
-      DispCountScroll(n);
-    } else {
-      BuffScroll(n,CursorBottom);
-      DispScrollNLines(WinOrgY,CursorBottom,n);
-    }
-  }
-  else if ((CursorTop<=CursorY) && (CursorY<=CursorBottom))
-  {
-    DestPtr = GetLinePtr(PageStart+CursorTop);
-    if (n<CursorBottom-CursorTop+1)
-    {
-      SrcPtr = GetLinePtr(PageStart+CursorTop+n);
-      for (i = CursorTop+n ; i<=CursorBottom ; i++)
-      {
-	memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-	memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-	memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-	memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-	memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-	SrcPtr = NextLinePtr(SrcPtr);
-	DestPtr = NextLinePtr(DestPtr);
-      }
-    }
-    else
-      n = CursorBottom-CursorTop+1;
-    for (i = CursorBottom+1-n ; i<=CursorBottom; i++)
-    {
-      memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-      memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-      memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
-      memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-      memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
-      DestPtr = NextLinePtr(DestPtr);
-    }
-    DispScrollNLines(CursorTop,CursorBottom,n);
-  }
+	if ((CursorTop == 0) && (CursorBottom == NumOfLines-1)) {
+		WinOrgY = WinOrgY-n;
+		/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é */
+		if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
+			NewOrgY = WinOrgY;
+		}
+		BuffScroll(n,CursorBottom);
+		DispCountScroll(n);
+	}
+	else if ((CursorTop==0) && (CursorY<=CursorBottom)) {
+		/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚é */
+		if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
+			/* ƒXƒNƒ[ƒ‹‚³‚¹‚È‚¢ê‡‚̏ˆ— */
+			WinOrgY = WinOrgY-n;
+			NewOrgY = WinOrgY;
+			BuffScroll(n,CursorBottom);
+			DispCountScroll(n);
+		} else {
+			BuffScroll(n,CursorBottom);
+			DispScrollNLines(WinOrgY,CursorBottom,n);
+		}
+	}
+	else if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
+		DestPtr = GetLinePtr(PageStart+CursorTop);
+		if (n<CursorBottom-CursorTop+1) {
+			SrcPtr = GetLinePtr(PageStart+CursorTop+n);
+			for (i = CursorTop+n ; i<=CursorBottom ; i++) {
+				memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+				memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+				memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+				memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+				memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+				SrcPtr = NextLinePtr(SrcPtr);
+				DestPtr = NextLinePtr(DestPtr);
+			}
+		}
+		else {
+			n = CursorBottom-CursorTop+1;
+		}
+		for (i = CursorBottom+1-n ; i<=CursorBottom; i++) {
+			memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
+			memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
+			memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
+			memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
+			memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+			DestPtr = NextLinePtr(DestPtr);
+		}
+		DispScrollNLines(CursorTop,CursorBottom,n);
+	}
 }
 
 void BuffRegionScrollUpNLines(int n) {
-  int i;
-  LONG SrcPtr, DestPtr;
+	int i;
+	LONG SrcPtr, DestPtr;
 
-  if (n<1) return;
-  UpdateStr();
+	if (n<1) {
+		return;
+	}
+	UpdateStr();
 
-  if (n > 0) {
-    if ((CursorTop == 0) && (CursorBottom == NumOfLines-1)) {
-      WinOrgY = WinOrgY-n;
-      BuffScroll(n,CursorBottom);
-      DispCountScroll(n);
-    }
-    else if (CursorTop==0) {
-      BuffScroll(n,CursorBottom);
-      DispScrollNLines(WinOrgY,CursorBottom,n);
-    }
-    else {
-      DestPtr = GetLinePtr(PageStart+CursorTop);
-      if (n<CursorBottom-CursorTop+1) {
-	SrcPtr = GetLinePtr(PageStart+CursorTop+n);
-	for (i = CursorTop+n ; i<=CursorBottom ; i++) {
-	  memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-	  memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-	  memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-	  memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-	  memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-	  SrcPtr = NextLinePtr(SrcPtr);
-	  DestPtr = NextLinePtr(DestPtr);
+	if (n > 0) {
+		if ((CursorTop == 0) && (CursorBottom == NumOfLines-1)) {
+			WinOrgY = WinOrgY-n;
+			BuffScroll(n,CursorBottom);
+			DispCountScroll(n);
+		}
+		else if (CursorTop==0) {
+			BuffScroll(n,CursorBottom);
+			DispScrollNLines(WinOrgY,CursorBottom,n);
+		}
+		else {
+			DestPtr = GetLinePtr(PageStart+CursorTop);
+			if (n<CursorBottom-CursorTop+1) {
+				SrcPtr = GetLinePtr(PageStart+CursorTop+n);
+				for (i = CursorTop+n ; i<=CursorBottom ; i++) {
+					memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+					memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+					memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+					memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+					memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+					SrcPtr = NextLinePtr(SrcPtr);
+					DestPtr = NextLinePtr(DestPtr);
+				}
+			}
+			else {
+				n = CursorBottom-CursorTop+1;
+			}
+			for (i = CursorBottom+1-n ; i<=CursorBottom; i++) {
+				memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
+				memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
+				memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
+				memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
+				memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+				DestPtr = NextLinePtr(DestPtr);
+			}
+			DispScrollNLines(CursorTop,CursorBottom,n);
+		}
 	}
-      }
-      else
-	n = CursorBottom-CursorTop+1;
-      for (i = CursorBottom+1-n ; i<=CursorBottom; i++) {
-	memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-	memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-	memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
-	memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-	memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
-	DestPtr = NextLinePtr(DestPtr);
-      }
-      DispScrollNLines(CursorTop,CursorBottom,n);
-    }
-  }
 }
 
 void BuffRegionScrollDownNLines(int n) {
-  int i;
-  LONG SrcPtr, DestPtr;
+	int i;
+	LONG SrcPtr, DestPtr;
 
-  if (n<1) {
-    return;
-  }
-  UpdateStr();
+	if (n<1) {
+		return;
+	}
+	UpdateStr();
 
-  DestPtr = GetLinePtr(PageStart+CursorBottom);
-  if (n < CursorBottom-CursorTop+1) {
-    SrcPtr = GetLinePtr(PageStart+CursorBottom-n);
-    for (i=CursorBottom-n ; i>=CursorTop ; i--) {
-      memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-      memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-      memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-      memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-      memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
-      SrcPtr = PrevLinePtr(SrcPtr);
-      DestPtr = PrevLinePtr(DestPtr);
-    }
-  }
-  else {
-    n = CursorBottom - CursorTop + 1;
-  }
-  for (i = CursorTop+n-1; i>=CursorTop; i--) {
-    memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-    memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-    memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
-    memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-    memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
-    DestPtr = PrevLinePtr(DestPtr);
-  }
+	DestPtr = GetLinePtr(PageStart+CursorBottom);
+	if (n < CursorBottom-CursorTop+1) {
+		SrcPtr = GetLinePtr(PageStart+CursorBottom-n);
+		for (i=CursorBottom-n ; i>=CursorTop ; i--) {
+			memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
+			memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
+			memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
+			memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
+			memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+			SrcPtr = PrevLinePtr(SrcPtr);
+			DestPtr = PrevLinePtr(DestPtr);
+		}
+	}
+	else {
+		n = CursorBottom - CursorTop + 1;
+	}
+	for (i = CursorTop+n-1; i>=CursorTop; i--) {
+		memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
+		memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
+		memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2,NumOfColumns);
+		memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
+		memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+		DestPtr = PrevLinePtr(DestPtr);
+	}
 
-  DispScrollNLines(CursorTop,CursorBottom,-n);
+	DispScrollNLines(CursorTop,CursorBottom,-n);
 }
 
 void BuffClearScreen()
 { // clear screen
-  if ((StatusLine>0) && (CursorY==NumOfLines-1))
-    BuffScrollNLines(1); /* clear status line */
-  else { /* clear main screen */
-    UpdateStr();
-    BuffScroll(NumOfLines-StatusLine,NumOfLines-1-StatusLine);
-    DispScrollNLines(WinOrgY,NumOfLines-1-StatusLine,NumOfLines-StatusLine);
-  }
+	if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
+		BuffScrollNLines(1); /* clear status line */
+	}
+	else { /* clear main screen */
+		UpdateStr();
+		BuffScroll(NumOfLines-StatusLine,NumOfLines-1-StatusLine);
+		DispScrollNLines(WinOrgY,NumOfLines-1-StatusLine,NumOfLines-StatusLine);
+	}
 }
 
 void BuffUpdateScroll()
 // Updates scrolling
 {
-  UpdateStr();
-  DispUpdateScroll();
+	UpdateStr();
+	DispUpdateScroll();
 }
 
 void CursorUpWithScroll()
 {
-  if ((0<CursorY) && (CursorY<CursorTop) ||
-      (CursorTop<CursorY))
-    MoveCursor(CursorX,CursorY-1);
-  else if (CursorY==CursorTop)
-    ScrollUp1Line();
+	if ((0<CursorY) && (CursorY<CursorTop) ||
+	    (CursorTop<CursorY)) {
+		MoveCursor(CursorX,CursorY-1);
+	}
+	else if (CursorY==CursorTop) {
+		ScrollUp1Line();
+	}
 }
 
 // called by BuffDblClk
 //   check if a character is the word delimiter
 BOOL IsDelimiter(LONG Line, int CharPtr)
 {
-  if ((AttrBuff[Line+CharPtr] & AttrKanji) !=0)
-    return (ts.DelimDBCS!=0);
-  return
-    (strchr(ts.DelimList,CodeBuff[Line+CharPtr])!=NULL);
+	if ((AttrBuff[Line+CharPtr] & AttrKanji) !=0) {
+		return (ts.DelimDBCS!=0);
+	}
+	return (strchr(ts.DelimList,CodeBuff[Line+CharPtr])!=NULL);
 }
 
 void GetMinMax(int i1, int i2, int i3,
-	       int *min, int *max)
+               int *min, int *max)
 {
-  if (i1<i2)
-  {
-    *min = i1;
-    *max = i2;
-  }
-  else {
-    *min = i2;
-    *max = i1;
-  }
-  if (i3<*min)
-    *min = i3;
-  if (i3>*max)
-    *max = i3;
+	if (i1<i2) {
+		*min = i1;
+		*max = i2;
+	}
+	else {
+		*min = i2;
+		*max = i1;
+	}
+	if (i3<*min) {
+		*min = i3;
+	}
+	if (i3>*max) {
+		*max = i3;
+	}
 }
 
 /* start - ishizaki */
 static void invokeBrowser(LONG ptr)
 {
 #ifdef URL_EMPHASIS
-    LONG i, start, end;
-    char url[1024];
+	LONG i, start, end;
+	char url[1024];
 	char *uptr, ch;
 
-    start = ptr;
-    while (AttrBuff[start] & AttrURL) start--;
-    start++;
+	start = ptr;
+	while (AttrBuff[start] & AttrURL) {
+		start--;
+	}
+	start++;
 
-    end = ptr;
-    while (AttrBuff[end] & AttrURL) end++;
-    end--;
+	end = ptr;
+	while (AttrBuff[end] & AttrURL) {
+		end++;
+	}
+	end--;
  
-    if (start + 1024 <= end) end = start + 1023;
+	if (start + 1024 <= end) {
+		end = start + 1023;
+	}
 	uptr = url;
-    for (i = 0; i < end - start + 1; i++) {
+	for (i = 0; i < end - start + 1; i++) {
 		ch = CodeBuff[start + i];
 		if ((start + i) % NumOfColumns == NumOfColumns - 1 
 			&& ch == '\\') {
@@ -1969,122 +2043,135 @@
 		} else {
 			*uptr++ = ch;
 		}
-    }
+	}
 	*uptr = '\0';
-    ShellExecute(NULL, NULL, url, NULL, NULL,SW_SHOWNORMAL);
+	ShellExecute(NULL, NULL, url, NULL, NULL,SW_SHOWNORMAL);
 #endif
 }
 /* end - ishizaki */
 
 void ChangeSelectRegion()
 {
-  POINT TempStart, TempEnd;
-  int j, IStart, IEnd;
-  BOOL Caret;
+	POINT TempStart, TempEnd;
+	int j, IStart, IEnd;
+	BOOL Caret;
 
-  if ((SelectEndOld.x==SelectEnd.x) &&
-      (SelectEndOld.y==SelectEnd.y)) return;
+	if ((SelectEndOld.x==SelectEnd.x) &&
+	    (SelectEndOld.y==SelectEnd.y)) {
+		return;
+	}
 
-  if (BoxSelect)
-  {
-    GetMinMax(SelectStart.x,SelectEndOld.x,SelectEnd.x,
-	      (int *)&TempStart.x,(int *)&TempEnd.x);
-    GetMinMax(SelectStart.y,SelectEndOld.y,SelectEnd.y,
-	      (int *)&TempStart.y,(int *)&TempEnd.y);
-    TempEnd.x--;
-    Caret = IsCaretOn();
-    if (Caret) CaretOff();
-    DispInitDC();
-    BuffUpdateRect(TempStart.x,TempStart.y-PageStart,
-		   TempEnd.x,TempEnd.y-PageStart);
-    DispReleaseDC();
-    if (Caret) CaretOn();
-    SelectEndOld = SelectEnd;
-    return;
-  }
+	if (BoxSelect) {
+		GetMinMax(SelectStart.x,SelectEndOld.x,SelectEnd.x,
+		          (int *)&TempStart.x,(int *)&TempEnd.x);
+		GetMinMax(SelectStart.y,SelectEndOld.y,SelectEnd.y,
+		          (int *)&TempStart.y,(int *)&TempEnd.y);
+		TempEnd.x--;
+		Caret = IsCaretOn();
+		if (Caret) {
+			CaretOff();
+		}
+		DispInitDC();
+		BuffUpdateRect(TempStart.x,TempStart.y-PageStart,
+		               TempEnd.x,TempEnd.y-PageStart);
+		DispReleaseDC();
+		if (Caret) {
+			CaretOn();
+		}
+		SelectEndOld = SelectEnd;
+		return;
+	}
 
-  if ((SelectEndOld.y < SelectEnd.y) ||
-      (SelectEndOld.y==SelectEnd.y) &&
-      (SelectEndOld.x<=SelectEnd.x))
-  {
-    TempStart = SelectEndOld;
-    TempEnd.x = SelectEnd.x-1;
-    TempEnd.y = SelectEnd.y;
-  }
-  else {
-    TempStart = SelectEnd;
-    TempEnd.x = SelectEndOld.x-1;
-    TempEnd.y = SelectEndOld.y;
-  }
-  if (TempEnd.x < 0)
-  {
-    TempEnd.x = NumOfColumns - 1;
-    TempEnd.y--;
-  }
+	if ((SelectEndOld.y < SelectEnd.y) ||
+	    (SelectEndOld.y==SelectEnd.y) &&
+	    (SelectEndOld.x<=SelectEnd.x)) {
+		TempStart = SelectEndOld;
+		TempEnd.x = SelectEnd.x-1;
+		TempEnd.y = SelectEnd.y;
+	}
+	else {
+		TempStart = SelectEnd;
+		TempEnd.x = SelectEndOld.x-1;
+		TempEnd.y = SelectEndOld.y;
+	}
+	if (TempEnd.x < 0) {
+		TempEnd.x = NumOfColumns - 1;
+		TempEnd.y--;
+	}
 
-  Caret = IsCaretOn();
-  if (Caret) CaretOff();
-  for (j = TempStart.y ; j <= TempEnd.y ; j++)
-  {
-    IStart = 0;
-    IEnd = NumOfColumns-1;
-    if (j==TempStart.y) IStart = TempStart.x;
-    if (j==TempEnd.y) IEnd = TempEnd.x;
+	Caret = IsCaretOn();
+	if (Caret) {
+		CaretOff();
+	}
+	for (j = TempStart.y ; j <= TempEnd.y ; j++) {
+		IStart = 0;
+		IEnd = NumOfColumns-1;
+		if (j==TempStart.y) {
+			IStart = TempStart.x;
+		}
+		if (j==TempEnd.y) {
+			IEnd = TempEnd.x;
+		}
 
-    if ((IEnd>=IStart) && (j >= PageStart+WinOrgY) &&
-	(j < PageStart+WinOrgY+WinHeight))
-    {
-      DispInitDC();
-      BuffUpdateRect(IStart,j-PageStart,IEnd,j-PageStart);
-      DispReleaseDC();
-    }
-  }
-  if (Caret) CaretOn();
+		if ((IEnd>=IStart) && (j >= PageStart+WinOrgY) &&
+		    (j < PageStart+WinOrgY+WinHeight)) {
+			DispInitDC();
+			BuffUpdateRect(IStart,j-PageStart,IEnd,j-PageStart);
+			DispReleaseDC();
+		}
+	}
+	if (Caret) {
+		CaretOn();
+	}
 
-  SelectEndOld = SelectEnd;
+	SelectEndOld = SelectEnd;
 }
 
 BOOL BuffUrlDblClk(int Xw, int Yw)
 {
-  int X, Y;
-  LONG TmpPtr;
-  BOOL url_invoked = FALSE;
+	int X, Y;
+	LONG TmpPtr;
+	BOOL url_invoked = FALSE;
 
-  if (! ts.EnableClickableUrl) {
-    return FALSE;
-  }
+	if (! ts.EnableClickableUrl) {
+		return FALSE;
+	}
 
-  CaretOff();
+	CaretOff();
 
-  DispConvWinToScreen(Xw,Yw,&X,&Y,NULL);
-  Y = Y + PageStart;
-  if ((Y<0) || (Y>=BuffEnd)) return 0;
-  if (X<0) X = 0;
-  if (X>=NumOfColumns) X = NumOfColumns-1;
+	DispConvWinToScreen(Xw,Yw,&X,&Y,NULL);
+	Y = Y + PageStart;
+	if ((Y<0) || (Y>=BuffEnd)) {
+		return 0;
+	}
+	if (X<0) X = 0;
+	if (X>=NumOfColumns) {
+		X = NumOfColumns-1;
+	}
 
-  if ((Y>=0) && (Y<BuffEnd)) {
-    LockBuffer();
-    TmpPtr = GetLinePtr(Y);
-    /* start - ishizaki */
-    if (AttrBuff[TmpPtr+X] & AttrURL) {
-      BoxSelect = FALSE;
-      SelectEnd = SelectStart;
-      ChangeSelectRegion();
+	if ((Y>=0) && (Y<BuffEnd)) {
+		LockBuffer();
+		TmpPtr = GetLinePtr(Y);
+		/* start - ishizaki */
+		if (AttrBuff[TmpPtr+X] & AttrURL) {
+			BoxSelect = FALSE;
+			SelectEnd = SelectStart;
+			ChangeSelectRegion();
 
-      url_invoked = TRUE;
-      invokeBrowser(TmpPtr+X);
+			url_invoked = TRUE;
+			invokeBrowser(TmpPtr+X);
 
-      SelectStart.x = 0;
-      SelectStart.y = 0;
-      SelectEnd.x = 0;
-      SelectEnd.y = 0;
-      SelectEndOld.x = 0;
-      SelectEndOld.y = 0;
-      Selected = FALSE;
-    }
-    UnlockBuffer();
-  }
-  return url_invoked;
+			SelectStart.x = 0;
+			SelectStart.y = 0;
+			SelectEnd.x = 0;
+			SelectEnd.y = 0;
+			SelectEndOld.x = 0;
+			SelectEndOld.y = 0;
+			Selected = FALSE;
+		}
+		UnlockBuffer();
+	}
+	return url_invoked;
 }
 
 void BuffDblClk(int Xw, int Yw)
@@ -2092,199 +2179,198 @@
 //    Xw: horizontal position in window coordinate (pixels)
 //    Yw: vertical
 {
-  int X, Y, YStart, YEnd;
-  int IStart, IEnd, i;
-  LONG TmpPtr;
-  BYTE b;
-  BOOL DBCS;
+	int X, Y, YStart, YEnd;
+	int IStart, IEnd, i;
+	LONG TmpPtr;
+	BYTE b;
+	BOOL DBCS;
 
-  CaretOff();
+	CaretOff();
 
-  DispConvWinToScreen(Xw,Yw,&X,&Y,NULL);
-  Y = Y + PageStart;
-  if ((Y<0) || (Y>=BuffEnd)) return;
-  if (X<0) X = 0;
-  if (X>=NumOfColumns) X = NumOfColumns-1;
+	DispConvWinToScreen(Xw,Yw,&X,&Y,NULL);
+	Y = Y + PageStart;
+	if ((Y<0) || (Y>=BuffEnd)) {
+		return;
+	}
+	if (X<0) X = 0;
+	if (X>=NumOfColumns) X = NumOfColumns-1;
 
-  BoxSelect = FALSE;
-  LockBuffer();
-  SelectEnd = SelectStart;
-  ChangeSelectRegion();
+	BoxSelect = FALSE;
+	LockBuffer();
+	SelectEnd = SelectStart;
+	ChangeSelectRegion();
 
-  if ((Y>=0) && (Y<BuffEnd))
-  {
-    TmpPtr = GetLinePtr(Y);
+	if ((Y>=0) && (Y<BuffEnd)) {
+		TmpPtr = GetLinePtr(Y);
 
-    IStart = X;
-    IStart = LeftHalfOfDBCS(TmpPtr,IStart);
-    IEnd = IStart;
-    YStart = YEnd = Y;
+		IStart = X;
+		IStart = LeftHalfOfDBCS(TmpPtr,IStart);
+		IEnd = IStart;
+		YStart = YEnd = Y;
 
-    if (IsDelimiter(TmpPtr,IStart))
-    {
-      b = CodeBuff[TmpPtr+IStart];
-      DBCS = (AttrBuff[TmpPtr+IStart] & AttrKanji) != 0;
-      while ((b==CodeBuff[TmpPtr+IStart]) ||
-             DBCS &&
-			 ((AttrBuff[TmpPtr+IStart] & AttrKanji)!=0)) {
-        MoveCharPtr(TmpPtr,&IStart,-1); // move left
-        if (ts.EnableContinuedLineCopy) {
-          if (IStart<=0) {
-            // ¶’[‚̏ꍇ
-            if (YStart>0 && AttrBuff[TmpPtr] & AttrLineContinued) {
-              // ‘O‚̍s‚Ɉړ®‚·‚é
-              YStart--;
-              TmpPtr = GetLinePtr(YStart);
-              IStart = NumOfColumns;
+		if (IsDelimiter(TmpPtr,IStart)) {
+			b = CodeBuff[TmpPtr+IStart];
+			DBCS = (AttrBuff[TmpPtr+IStart] & AttrKanji) != 0;
+			while ((b==CodeBuff[TmpPtr+IStart]) ||
+			       DBCS &&
+			       ((AttrBuff[TmpPtr+IStart] & AttrKanji)!=0)) {
+				MoveCharPtr(TmpPtr,&IStart,-1); // move left
+				if (ts.EnableContinuedLineCopy) {
+					if (IStart<=0) {
+						// ¶’[‚̏ꍇ
+						if (YStart>0 && AttrBuff[TmpPtr] & AttrLineContinued) {
+							// ‘O‚̍s‚Ɉړ®‚·‚é
+							YStart--;
+							TmpPtr = GetLinePtr(YStart);
+							IStart = NumOfColumns;
+						}
+						else {
+							break;
+						}
+					}
+				}
+				else {
+					if (IStart<=0) {
+						// ¶’[‚̏ꍇ‚͏I‚í‚è
+						break;
+					}
+				}
 			}
-			else {
-              break;
+			if ((b!=CodeBuff[TmpPtr+IStart]) &&
+			    ! (DBCS && ((AttrBuff[TmpPtr+IStart] & AttrKanji)!=0))) {
+				// ÅIˆÊ’u‚ª Delimiter ‚Å‚È‚¢ê‡‚ɂ͂ЂƂ‰E‚É‚¸‚ç‚·
+				if (ts.EnableContinuedLineCopy && IStart == NumOfColumns-1) {
+					// ‰E’[‚̏ꍇ‚É‚ÍŽŸ‚̍s‚ÖˆÚ“®‚·‚é
+					YStart++;
+					TmpPtr = GetLinePtr(YStart);
+					IStart = 0;
+				}
+				else {
+					MoveCharPtr(TmpPtr,&IStart,1);
+				}
 			}
-		  }
+
+			// s‚ªˆÚ“®‚µ‚Ä‚¢‚é‚©‚à‚µ‚ê‚È‚¢‚̂ŁAƒNƒŠƒbƒN‚µ‚½s‚ðŽæ‚è’¼‚·
+			TmpPtr = GetLinePtr(YEnd);
+			i = 1;
+			while (((b==CodeBuff[TmpPtr+IEnd]) ||
+			        DBCS &&
+			        ((AttrBuff[TmpPtr+IEnd] & AttrKanji)!=0))) {
+				i = MoveCharPtr(TmpPtr,&IEnd,1); // move right
+				if (ts.EnableContinuedLineCopy) {
+					if (i==0) {
+						// ‰E’[‚̏ꍇ
+						if (YEnd<BuffEnd &&
+						    AttrBuff[TmpPtr+IEnd+1+DBCS] & AttrLineContinued) {
+							// ŽŸ‚̍s‚Ɉړ®‚·‚é
+							YEnd++;
+							TmpPtr = GetLinePtr(YEnd);
+							IEnd = 0;
+						}
+						else {
+							break;
+						}
+					}
+				}
+				else {
+					if (i==0) {
+						// ‰E’[‚̏ꍇ‚͏I‚í‚è
+						break;
+					}
+				}
+			}
 		}
 		else {
-          if (IStart<=0) {
-            // ¶’[‚̏ꍇ‚͏I‚í‚è
-            break;
-		  }
+			while (! IsDelimiter(TmpPtr,IStart)) {
+				MoveCharPtr(TmpPtr,&IStart,-1); // move left
+				if (ts.EnableContinuedLineCopy) {
+					if (IStart<=0) {
+						// ¶’[‚̏ꍇ
+						if (YStart>0 && AttrBuff[TmpPtr] & AttrLineContinued) {
+							// ‘O‚̍s‚Ɉړ®‚·‚é
+							YStart--;
+							TmpPtr = GetLinePtr(YStart);
+							IStart = NumOfColumns;
+						}
+						else {
+							break;
+						}
+					}
+				}
+				else {
+					if (IStart<=0) {
+						// ¶’[‚̏ꍇ‚͏I‚í‚è
+						break;
+					}
+				}
+			}
+			if (IsDelimiter(TmpPtr,IStart)) {
+				// ÅIˆÊ’u‚ª Delimiter ‚̏ꍇ‚ɂ͂ЂƂ‰E‚É‚¸‚ç‚·
+				if (ts.EnableContinuedLineCopy && IStart == NumOfColumns-1) {
+					// ‰E’[‚̏ꍇ‚É‚ÍŽŸ‚̍s‚ÖˆÚ“®‚·‚é
+					YStart++;
+					TmpPtr = GetLinePtr(YStart);
+					IStart = 0;
+				}
+				else {
+					MoveCharPtr(TmpPtr,&IStart,1);
+				}
+			}
+			
+			// s‚ªˆÚ“®‚µ‚Ä‚¢‚é‚©‚à‚µ‚ê‚È‚¢‚̂ŁAƒNƒŠƒbƒN‚µ‚½s‚ðŽæ‚è’¼‚·
+			TmpPtr = GetLinePtr(YEnd);
+			i = 1;
+			while (! IsDelimiter(TmpPtr,IEnd)) {
+				i = MoveCharPtr(TmpPtr,&IEnd,1); // move right
+				if (ts.EnableContinuedLineCopy) {
+					if (i==0) {
+						// ‰E’[‚̏ꍇ
+						if (YEnd<BuffEnd && AttrBuff[TmpPtr+IEnd+1] & AttrLineContinued) {
+							// ŽŸ‚̍s‚Ɉړ®‚·‚é
+							YEnd++;
+							TmpPtr = GetLinePtr(YEnd);
+							IEnd = 0;
+						}
+						else {
+							break;
+						}
+					}
+				}
+				else {
+					if (i==0) {
+						// ‰E’[‚̏ꍇ‚͏I‚í‚è
+						break;
+					}
+				}
+			}
 		}
-	  }
-      if ((b!=CodeBuff[TmpPtr+IStart]) &&
-          ! (DBCS &&
-          ((AttrBuff[TmpPtr+IStart] & AttrKanji)!=0))) {
-        // ÅIˆÊ’u‚ª Delimiter ‚Å‚È‚¢ê‡‚ɂ͂ЂƂ‰E‚É‚¸‚ç‚·
-        if (ts.EnableContinuedLineCopy && IStart == NumOfColumns-1) {
-          // ‰E’[‚̏ꍇ‚É‚ÍŽŸ‚̍s‚ÖˆÚ“®‚·‚é
-          YStart++;
-          TmpPtr = GetLinePtr(YStart);
-          IStart = 0;
-        }
-        else {
-          MoveCharPtr(TmpPtr,&IStart,1);
-        }
-	  }
+		if (ts.EnableContinuedLineCopy) {
+			if (IEnd == 0) {
+				// ¶’[‚̏ꍇ‚É‚Í‘O‚̍s‚ÖˆÚ“®‚·‚é
+				YEnd--;
+				IEnd = NumOfColumns;
+			}
+			else if (i==0) {
+				IEnd = NumOfColumns;
+			}
+		}
+		else {
+			if (i==0)
+				IEnd = NumOfColumns;
+		}
 
-      // s‚ªˆÚ“®‚µ‚Ä‚¢‚é‚©‚à‚µ‚ê‚È‚¢‚̂ŁAƒNƒŠƒbƒN‚µ‚½s‚ðŽæ‚è’¼‚·
-      TmpPtr = GetLinePtr(YEnd);
-      i = 1;
-      while (((b==CodeBuff[TmpPtr+IEnd]) ||
-              DBCS &&
-              ((AttrBuff[TmpPtr+IEnd] & AttrKanji)!=0))) {
-        i = MoveCharPtr(TmpPtr,&IEnd,1); // move right
-        if (ts.EnableContinuedLineCopy) {
-          if (i==0) {
-            // ‰E’[‚̏ꍇ
-            if (YEnd<BuffEnd &&
-                AttrBuff[TmpPtr+IEnd+1+DBCS] & AttrLineContinued) {
-              // ŽŸ‚̍s‚Ɉړ®‚·‚é
-              YEnd++;
-              TmpPtr = GetLinePtr(YEnd);
-              IEnd = 0;
-            }
-            else {
-              break;
-            }
-          }
-        }
-        else {
-          if (i==0) {
-            // ‰E’[‚̏ꍇ‚͏I‚í‚è
-            break;
-          }
-        }
-	  }
-    }
-    else {
-      while (! IsDelimiter(TmpPtr,IStart)) {
-        MoveCharPtr(TmpPtr,&IStart,-1); // move left
-        if (ts.EnableContinuedLineCopy) {
-          if (IStart<=0) {
-            // ¶’[‚̏ꍇ
-            if (YStart>0 && AttrBuff[TmpPtr] & AttrLineContinued) {
-              // ‘O‚̍s‚Ɉړ®‚·‚é
-              YStart--;
-              TmpPtr = GetLinePtr(YStart);
-              IStart = NumOfColumns;
-            }
-            else {
-              break;
-            }
-          }
-        }
-        else {
-          if (IStart<=0) {
-            // ¶’[‚̏ꍇ‚͏I‚í‚è
-            break;
-          }
-        }
-      }
-      if (IsDelimiter(TmpPtr,IStart)) {
-        // ÅIˆÊ’u‚ª Delimiter ‚̏ꍇ‚ɂ͂ЂƂ‰E‚É‚¸‚ç‚·
-        if (ts.EnableContinuedLineCopy && IStart == NumOfColumns-1) {
-          // ‰E’[‚̏ꍇ‚É‚ÍŽŸ‚̍s‚ÖˆÚ“®‚·‚é
-          YStart++;
-          TmpPtr = GetLinePtr(YStart);
-          IStart = 0;
-        }
-        else {
-          MoveCharPtr(TmpPtr,&IStart,1);
-        }
-      }
-      
-      // s‚ªˆÚ“®‚µ‚Ä‚¢‚é‚©‚à‚µ‚ê‚È‚¢‚̂ŁAƒNƒŠƒbƒN‚µ‚½s‚ðŽæ‚è’¼‚·
-      TmpPtr = GetLinePtr(YEnd);
-      i = 1;
-      while (! IsDelimiter(TmpPtr,IEnd)) {
-        i = MoveCharPtr(TmpPtr,&IEnd,1); // move right
-        if (ts.EnableContinuedLineCopy) {
-          if (i==0) {
-            // ‰E’[‚̏ꍇ
-            if (YEnd<BuffEnd && AttrBuff[TmpPtr+IEnd+1] & AttrLineContinued) {
-              // ŽŸ‚̍s‚Ɉړ®‚·‚é
-              YEnd++;
-              TmpPtr = GetLinePtr(YEnd);
-              IEnd = 0;
-            }
-            else {
-              break;
-            }
-          }
-        }
-        else {
-          if (i==0) {
-            // ‰E’[‚̏ꍇ‚͏I‚í‚è
-            break;
-          }
-        }
-      }
-    }
-    if (ts.EnableContinuedLineCopy) {
-      if (IEnd == 0) {
-        // ¶’[‚̏ꍇ‚É‚Í‘O‚̍s‚ÖˆÚ“®‚·‚é
-        YEnd--;
-        IEnd = NumOfColumns;
-      }
-      else if (i==0) {
-        IEnd = NumOfColumns;
-      }
-    }
-    else {
-      if (i==0)
-        IEnd = NumOfColumns;
-    }
-
-    SelectStart.x = IStart;
-    SelectStart.y = YStart;
-    SelectEnd.x = IEnd;
-    SelectEnd.y = YEnd;
-    SelectEndOld = SelectStart;
-    DblClkStart = SelectStart;
-    DblClkEnd = SelectEnd;
-    Selected = TRUE;
-    ChangeSelectRegion();
-  }
-  UnlockBuffer();
-  return;
+		SelectStart.x = IStart;
+		SelectStart.y = YStart;
+		SelectEnd.x = IEnd;
+		SelectEnd.y = YEnd;
+		SelectEndOld = SelectStart;
+		DblClkStart = SelectStart;
+		DblClkEnd = SelectEnd;
+		Selected = TRUE;
+		ChangeSelectRegion();
+	}
+	UnlockBuffer();
+	return;
 }
 
 void BuffTplClk(int Yw)
@@ -2292,27 +2378,29 @@
 //    Yw: vertical clicked position
 //			in window coordinate (pixels)
 {
-  int Y;
+	int Y;
 
-  CaretOff();
+	CaretOff();
 
-  DispConvWinToScreen(0,Yw,NULL,&Y,NULL);
-  Y = Y + PageStart;
-  if ((Y<0) || (Y>=BuffEnd)) return;
+	DispConvWinToScreen(0,Yw,NULL,&Y,NULL);
+	Y = Y + PageStart;
+	if ((Y<0) || (Y>=BuffEnd)) {
+		return;
+	}
 
-  LockBuffer();
-  SelectEnd = SelectStart;
-  ChangeSelectRegion();
-  SelectStart.x = 0;
-  SelectStart.y = Y;
-  SelectEnd.x = NumOfColumns;
-  SelectEnd.y = Y;
-  SelectEndOld = SelectStart;
-  DblClkStart = SelectStart;
-  DblClkEnd = SelectEnd;
-  Selected = TRUE;
-  ChangeSelectRegion();
-  UnlockBuffer();
+	LockBuffer();
+	SelectEnd = SelectStart;
+	ChangeSelectRegion();
+	SelectStart.x = 0;
+	SelectStart.y = Y;
+	SelectEnd.x = NumOfColumns;
+	SelectEnd.y = Y;
+	SelectEndOld = SelectStart;
+	DblClkStart = SelectStart;
+	DblClkEnd = SelectEnd;
+	Selected = TRUE;
+	ChangeSelectRegion();
+	UnlockBuffer();
 }
 
 
@@ -2329,9 +2417,13 @@
 
 	DispConvWinToScreen(Xw,Yw, &X,&Y,&Right);
 	Y = Y + PageStart;
-	if ((Y<0) || (Y>=BuffEnd)) return;
+	if ((Y<0) || (Y>=BuffEnd)) {
+		return;
+	}
 	if (X<0) X = 0;
-	if (X>=NumOfColumns) X = NumOfColumns-1;
+	if (X>=NumOfColumns) {
+		X = NumOfColumns-1;
+	}
 
 	SelectEnd.x = X;
 	SelectEnd.y = Y;
@@ -2345,44 +2437,56 @@
 //    Yw: vertical
 //    Box: Box selection if TRUE
 {
-  int X, Y;
-  BOOL Right;
-  LONG TmpPtr;
+	int X, Y;
+	BOOL Right;
+	LONG TmpPtr;
 
-  DispConvWinToScreen(Xw,Yw, &X,&Y,&Right);
-  Y = Y + PageStart;
-  if ((Y<0) || (Y>=BuffEnd)) return;
-  if (X<0) X = 0;
-  if (X>=NumOfColumns) X = NumOfColumns-1;
+	DispConvWinToScreen(Xw,Yw, &X,&Y,&Right);
+	Y = Y + PageStart;
+	if ((Y<0) || (Y>=BuffEnd)) {
+		return;
+	}
+	if (X<0) X = 0;
+	if (X>=NumOfColumns) {
+		X = NumOfColumns-1;
+	}
 
-  SelectEndOld = SelectEnd;
-  SelectEnd = SelectStart;
+	SelectEndOld = SelectEnd;
+	SelectEnd = SelectStart;
 
-  LockBuffer();
-  ChangeSelectRegion();
-  UnlockBuffer();
+	LockBuffer();
+	ChangeSelectRegion();
+	UnlockBuffer();
 
-  SelectStart.x = X;
-  SelectStart.y = Y;
-  if (SelectStart.x<0) SelectStart.x = 0;
-  if (SelectStart.x > NumOfColumns)
-    SelectStart.x = NumOfColumns;
-  if (SelectStart.y < 0) SelectStart.y = 0;
-  if (SelectStart.y >= BuffEnd)
-    SelectStart.y = BuffEnd - 1;
+	SelectStart.x = X;
+	SelectStart.y = Y;
+	if (SelectStart.x<0) {
+		SelectStart.x = 0;
+	}
+	if (SelectStart.x > NumOfColumns) {
+		SelectStart.x = NumOfColumns;
+	}
+	if (SelectStart.y < 0) {
+		SelectStart.y = 0;
+	}
+	if (SelectStart.y >= BuffEnd) {
+		SelectStart.y = BuffEnd - 1;
+	}
 
-  TmpPtr = GetLinePtr(SelectStart.y);
-  // check if the cursor is on the right half of a character
-  if ((SelectStart.x>0) &&
-      ((AttrBuff[TmpPtr+SelectStart.x-1] & AttrKanji) != 0) ||
-      ((AttrBuff[TmpPtr+SelectStart.x] & AttrKanji) == 0) &&
-       Right) SelectStart.x++;
+	TmpPtr = GetLinePtr(SelectStart.y);
+	// check if the cursor is on the right half of a character
+	if ((SelectStart.x>0) &&
+	    ((AttrBuff[TmpPtr+SelectStart.x-1] & AttrKanji) != 0) ||
+	    ((AttrBuff[TmpPtr+SelectStart.x] & AttrKanji) == 0) &&
+	     Right) {
+		SelectStart.x++;
+	}
 
-  SelectEnd = SelectStart;
-  SelectEndOld = SelectEnd;
-  CaretOff();
-  Selected = TRUE;
-  BoxSelect = Box;
+	SelectEnd = SelectStart;
+	SelectEndOld = SelectEnd;
+	CaretOff();
+	Selected = TRUE;
+	BoxSelect = Box;
 }
 
 void BuffChangeSelect(int Xw, int Yw, int NClick)
@@ -2402,23 +2506,28 @@
 	Y = Y + PageStart;
 
 	if (X<0) X = 0;
-	if (X > NumOfColumns)
+	if (X > NumOfColumns) {
 		X = NumOfColumns;
+	}
 	if (Y < 0) Y = 0;
-	if (Y >= BuffEnd)
+	if (Y >= BuffEnd) {
 		Y = BuffEnd - 1;
+	}
 
 	TmpPtr = GetLinePtr(Y);
 	LockBuffer();
 	// check if the cursor is on the right half of a character
 	if ((X>0) &&
-		((AttrBuff[TmpPtr+X-1] & AttrKanji) != 0) ||
-		(X<NumOfColumns) &&
-		((AttrBuff[TmpPtr+X] & AttrKanji) == 0) &&
-		Right) X++;
+	    ((AttrBuff[TmpPtr+X-1] & AttrKanji) != 0) ||
+	    (X<NumOfColumns) &&
+	    ((AttrBuff[TmpPtr+X] & AttrKanji) == 0) &&
+	    Right) {
+		X++;
+	}
 
-	if (X > NumOfColumns)
+	if (X > NumOfColumns) {
 		X = NumOfColumns;
+	}
 
 	// check URL string on mouse over(2005/4/3 yutaka)
 	if (NClick == 0) {
@@ -2457,14 +2566,11 @@
 	SelectEnd.x = X;
 	SelectEnd.y = Y;
 
-	if (NClick==2) // drag after double click
-	{
+	if (NClick==2) { // drag after double click
 		if ((SelectEnd.y>SelectStart.y) ||
-			(SelectEnd.y==SelectStart.y) &&
-			(SelectEnd.x>=SelectStart.x))
-		{
-			if (SelectStart.x==DblClkEnd.x)
-			{
+		    (SelectEnd.y==SelectStart.y) &&
+		    (SelectEnd.x>=SelectStart.x)) {
+			if (SelectStart.x==DblClkEnd.x) {
 				SelectEnd = DblClkStart;
 				ChangeSelectRegion();
 				SelectStart = DblClkStart;
@@ -2472,67 +2578,70 @@
 				SelectEnd.y = Y;
 			}
 			MoveCharPtr(TmpPtr,&X,-1);
-			if (X<SelectStart.x) X = SelectStart.x;
+			if (X<SelectStart.x) {
+				X = SelectStart.x;
+			}
 
 			i = 1;
-			if (IsDelimiter(TmpPtr,X))
-			{
+			if (IsDelimiter(TmpPtr,X)) {
 				b = CodeBuff[TmpPtr+X];
 				DBCS = (AttrBuff[TmpPtr+X] & AttrKanji) != 0;
 				while ((i!=0) &&
-					((b==CodeBuff[TmpPtr+SelectEnd.x]) ||
-					DBCS &&
-					((AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji)!=0)))
+				       ((b==CodeBuff[TmpPtr+SelectEnd.x]) ||
+				        DBCS &&
+				        ((AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji)!=0))) {
 					i = MoveCharPtr(TmpPtr,(int *)&SelectEnd.x,1); // move right
+				}
 			}
 			else {
 				while ((i!=0) &&
-					! IsDelimiter(TmpPtr,SelectEnd.x))
+				       ! IsDelimiter(TmpPtr,SelectEnd.x)) {
 					i = MoveCharPtr(TmpPtr,(int *)&SelectEnd.x,1); // move right
+				}
 			}
-			if (i==0)
+			if (i==0) {
 				SelectEnd.x = NumOfColumns;
+			}
 		}
 		else {
-			if (SelectStart.x==DblClkStart.x)
-			{
+			if (SelectStart.x==DblClkStart.x) {
 				SelectEnd = DblClkEnd;
 				ChangeSelectRegion();
 				SelectStart = DblClkEnd;
 				SelectEnd.x = X;
 				SelectEnd.y = Y; 
 			}
-			if (IsDelimiter(TmpPtr,SelectEnd.x))
-			{
+			if (IsDelimiter(TmpPtr,SelectEnd.x)) {
 				b = CodeBuff[TmpPtr+SelectEnd.x];
 				DBCS = (AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji) != 0;
 				while ((SelectEnd.x>0) &&
-					((b==CodeBuff[TmpPtr+SelectEnd.x]) ||
-					DBCS &&
-					((AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji)!=0)))
+				       ((b==CodeBuff[TmpPtr+SelectEnd.x]) ||
+				       DBCS &&
+				       ((AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji)!=0))) {
 					MoveCharPtr(TmpPtr,(int *)&SelectEnd.x,-1); // move left
+				}
 				if ((b!=CodeBuff[TmpPtr+SelectEnd.x]) &&
-					! (DBCS &&
-					((AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji)!=0)))
+				    ! (DBCS &&
+				    ((AttrBuff[TmpPtr+SelectEnd.x] & AttrKanji)!=0))) {
 					MoveCharPtr(TmpPtr,(int *)&SelectEnd.x,1);
+				}
 			}
 			else {
 				while ((SelectEnd.x>0) &&
-					! IsDelimiter(TmpPtr,SelectEnd.x))
+				       ! IsDelimiter(TmpPtr,SelectEnd.x)) {
 					MoveCharPtr(TmpPtr,(int *)&SelectEnd.x,-1); // move left
-				if (IsDelimiter(TmpPtr,SelectEnd.x))
+				}
+				if (IsDelimiter(TmpPtr,SelectEnd.x)) {
 					MoveCharPtr(TmpPtr,(int *)&SelectEnd.x,1); 
+				}
 			}
 		}
 	}
-	else if (NClick==3) // drag after tripple click
-	{
+	else if (NClick==3) { // drag after tripple click
 		if ((SelectEnd.y>SelectStart.y) ||
-			(SelectEnd.y==SelectStart.y) &&
-			(SelectEnd.x>=SelectStart.x))
-		{
-			if (SelectStart.x==DblClkEnd.x)
-			{
+		    (SelectEnd.y==SelectStart.y) &&
+		    (SelectEnd.x>=SelectStart.x)) {
+			if (SelectStart.x==DblClkEnd.x) {
 				SelectEnd = DblClkStart;
 				ChangeSelectRegion();
 				SelectStart = DblClkStart;
@@ -2542,8 +2651,7 @@
 			SelectEnd.x = NumOfColumns;
 		}
 		else {
-			if (SelectStart.x==DblClkStart.x)
-			{
+			if (SelectStart.x==DblClkStart.x) {
 				SelectEnd = DblClkEnd;
 				ChangeSelectRegion();
 				SelectStart = DblClkEnd;
@@ -2567,51 +2675,45 @@
 void BuffEndSelect()
 //  End text selection by mouse button up
 {
-  Selected = (SelectStart.x!=SelectEnd.x) ||
-	     (SelectStart.y!=SelectEnd.y);
-  if (Selected)
-  {
-    if (BoxSelect)
-    {
-      if (SelectStart.x>SelectEnd.x)
-      {
-        SelectEndOld.x = SelectStart.x;
-        SelectStart.x = SelectEnd.x;
-        SelectEnd.x = SelectEndOld.x;
-      }
-      if (SelectStart.y>SelectEnd.y)
-      {
-        SelectEndOld.y = SelectStart.y;
-        SelectStart.y = SelectEnd.y;
-        SelectEnd.y = SelectEndOld.y;
-      }
-    }
-    else if ((SelectEnd.y < SelectStart.y) ||
-      (SelectEnd.y == SelectStart.y) &&
-      (SelectEnd.x < SelectStart.x))
-    {
-      SelectEndOld = SelectStart;
-      SelectStart = SelectEnd;
-      SelectEnd = SelectEndOld;
-    }
+	Selected = (SelectStart.x!=SelectEnd.x) ||
+	           (SelectStart.y!=SelectEnd.y);
+	if (Selected) {
+		if (BoxSelect) {
+			if (SelectStart.x>SelectEnd.x) {
+				SelectEndOld.x = SelectStart.x;
+				SelectStart.x = SelectEnd.x;
+				SelectEnd.x = SelectEndOld.x;
+			}
+			if (SelectStart.y>SelectEnd.y) {
+				SelectEndOld.y = SelectStart.y;
+				SelectStart.y = SelectEnd.y;
+				SelectEnd.y = SelectEndOld.y;
+			}
+		}
+		else if ((SelectEnd.y < SelectStart.y) ||
+		         (SelectEnd.y == SelectStart.y) &&
+		          (SelectEnd.x < SelectStart.x)) {
+			SelectEndOld = SelectStart;
+			SelectStart = SelectEnd;
+			SelectEnd = SelectEndOld;
+		}
 
-	if (SeveralPageSelect) { // yutaka
-		// ƒy[ƒW‚ð‚Ü‚½‚®‘I‘ð‚̏ꍇAMouse button upŽž‚ɃŠ[ƒWƒ‡ƒ“‚ð“h‚è‘Ö‚¦‚éB
-	    LockBuffer();
-		ChangeSelectRegion();
-        UnlockBuffer();
-		SeveralPageSelect = FALSE;
-		InvalidateRect(HVTWin, NULL, TRUE); // ‚¿‚å‚Á‚Ɖæ–Ê‚ª‚¿‚ç‚‚­
+		if (SeveralPageSelect) { // yutaka
+			// ƒy[ƒW‚ð‚Ü‚½‚®‘I‘ð‚̏ꍇAMouse button upŽž‚ɃŠ[ƒWƒ‡ƒ“‚ð“h‚è‘Ö‚¦‚éB
+			LockBuffer();
+			ChangeSelectRegion();
+			UnlockBuffer();
+			SeveralPageSelect = FALSE;
+			InvalidateRect(HVTWin, NULL, TRUE); // ‚¿‚å‚Á‚Ɖæ–Ê‚ª‚¿‚ç‚‚­
+		}
+
+		/* copy to the clipboard */
+		if (ts.AutoTextCopy>0) {
+			LockBuffer();
+			BuffCBCopy(FALSE);
+			UnlockBuffer();
+		}
 	}
-
-    /* copy to the clipboard */
-    if (ts.AutoTextCopy>0)
-    {
-      LockBuffer();
-      BuffCBCopy(FALSE);
-      UnlockBuffer();
-    }
-  }
 }
 
 void BuffChangeWinSize(int Nx, int Ny)
@@ -2619,195 +2721,232 @@
 //   Nx: new window width (number of characters)
 //   Ny: new window hight
 {
-  if (Nx==0) Nx = 1;
-  if (Ny==0) Ny = 1;
+	if (Nx==0) {
+		Nx = 1;
+	}
+	if (Ny==0) {
+		Ny = 1;
+	}
 
-  if ((ts.TermIsWin>0) &&
-      ((Nx!=NumOfColumns) || (Ny!=NumOfLines)))
-  {
-    LockBuffer();
-    BuffChangeTerminalSize(Nx,Ny-StatusLine);
-    UnlockBuffer();
-    Nx = NumOfColumns;
-    Ny = NumOfLines;
-  }
-  if (Nx>NumOfColumns) Nx = NumOfColumns;
-  if (Ny>BuffEnd) Ny = BuffEnd;
-  DispChangeWinSize(Nx,Ny);
+	if ((ts.TermIsWin>0) &&
+	    ((Nx!=NumOfColumns) || (Ny!=NumOfLines))) {
+		LockBuffer();
+		BuffChangeTerminalSize(Nx,Ny-StatusLine);
+		UnlockBuffer();
+		Nx = NumOfColumns;
+		Ny = NumOfLines;
+	}
+	if (Nx>NumOfColumns) {
+		Nx = NumOfColumns;
+	}
+	if (Ny>BuffEnd) {
+		Ny = BuffEnd;
+	}
+	DispChangeWinSize(Nx,Ny);
 }
 
 void BuffChangeTerminalSize(int Nx, int Ny)
 {
-  int i, Nb, W, H;
-  BOOL St;
+	int i, Nb, W, H;
+	BOOL St;
 
-  Ny = Ny + StatusLine;
-  if (Nx < 1) Nx = 1;
-  if (Ny < 1) Ny = 1;
-  if (Nx > BuffXMax) Nx = BuffXMax;
-  if (ts.ScrollBuffMax > BuffYMax)
-    ts.ScrollBuffMax = BuffYMax;
-  if (Ny > ts.ScrollBuffMax) Ny = ts.ScrollBuffMax;
+	Ny = Ny + StatusLine;
+	if (Nx < 1) {
+		Nx = 1;
+	}
+	if (Ny < 1) {
+		Ny = 1;
+	}
+	if (Nx > BuffXMax) {
+		Nx = BuffXMax;
+	}
+	if (ts.ScrollBuffMax > BuffYMax) {
+		ts.ScrollBuffMax = BuffYMax;
+	}
+	if (Ny > ts.ScrollBuffMax) {
+		Ny = ts.ScrollBuffMax;
+	}
 
-  St = ((StatusLine>0) && (CursorY==NumOfLines-1));
-  if ((Nx!=NumOfColumns) || (Ny!=NumOfLines))
-  {
-    if ((ts.ScrollBuffSize < Ny) ||
-	(ts.EnableScrollBuff==0))
-      Nb = Ny;
-    else Nb = ts.ScrollBuffSize;
+	St = ((StatusLine>0) && (CursorY==NumOfLines-1));
+	if ((Nx!=NumOfColumns) || (Ny!=NumOfLines)) {
+		if ((ts.ScrollBuffSize < Ny) ||
+		    (ts.EnableScrollBuff==0)) {
+			Nb = Ny;
+		}
+		else {
+			Nb = ts.ScrollBuffSize;
+		}
 
-    if (! ChangeBuffer(Nx,Nb)) return;
-    if (ts.EnableScrollBuff>0)
-      ts.ScrollBuffSize = NumOfLinesInBuff;
-    if (Ny > NumOfLinesInBuff) Ny = NumOfLinesInBuff;
+		if (! ChangeBuffer(Nx,Nb)) {
+			return;
+		}
+		if (ts.EnableScrollBuff>0) {
+			ts.ScrollBuffSize = NumOfLinesInBuff;
+		}
+		if (Ny > NumOfLinesInBuff) {
+			Ny = NumOfLinesInBuff;
+		}
 
-    NumOfColumns = Nx;
-    NumOfLines = Ny;
-    ts.TerminalWidth = Nx;
-    ts.TerminalHeight = Ny-StatusLine;
+		NumOfColumns = Nx;
+		NumOfLines = Ny;
+		ts.TerminalWidth = Nx;
+		ts.TerminalHeight = Ny-StatusLine;
 
-    PageStart = BuffEnd - NumOfLines;
-  }
-  BuffScroll(NumOfLines,NumOfLines-1);
-  /* Set Cursor */
-  CursorX = 0;
-  if (St)
-  {
-    CursorY = NumOfLines-1;
-    CursorTop = CursorY;
-    CursorBottom = CursorY;
-  }
-  else {
-    CursorY = 0;
-    CursorTop = 0;
-    CursorBottom = NumOfLines-1-StatusLine;
-  }
+		PageStart = BuffEnd - NumOfLines;
+	}
+	BuffScroll(NumOfLines,NumOfLines-1);
+	/* Set Cursor */
+	CursorX = 0;
+	if (St) {
+		CursorY = NumOfLines-1;
+		CursorTop = CursorY;
+		CursorBottom = CursorY;
+	}
+	else {
+		CursorY = 0;
+		CursorTop = 0;
+		CursorBottom = NumOfLines-1-StatusLine;
+	}
 
-  SelectStart.x = 0;
-  SelectStart.y = 0;
-  SelectEnd = SelectStart;
-  Selected = FALSE;
+	SelectStart.x = 0;
+	SelectStart.y = 0;
+	SelectEnd = SelectStart;
+	Selected = FALSE;
 
-  /* Tab stops */
-  NTabStops = (NumOfColumns-1) >> 3;
-  for (i = 1 ; i <= NTabStops ; i++)
-    TabStops[i-1] = i*8;
+	/* Tab stops */
+	NTabStops = (NumOfColumns-1) >> 3;
+	for (i = 1 ; i <= NTabStops ; i++) {
+		TabStops[i-1] = i*8;
+	}
 
-  if (ts.TermIsWin>0)
-  {
-    W = NumOfColumns;
-    H = NumOfLines;
-  }
-  else {
-    W = WinWidth;
-    H = WinHeight;
-    if ((ts.AutoWinResize>0) ||
-        (NumOfColumns < W)) W = NumOfColumns;
-    if (ts.AutoWinResize>0) H = NumOfLines;
-    else if (BuffEnd < H) H = BuffEnd;
-  }
+	if (ts.TermIsWin>0) {
+		W = NumOfColumns;
+		H = NumOfLines;
+	}
+	else {
+		W = WinWidth;
+		H = WinHeight;
+		if ((ts.AutoWinResize>0) ||
+		    (NumOfColumns < W)) {
+			W = NumOfColumns;
+		}
+		if (ts.AutoWinResize>0) {
+			H = NumOfLines;
+		}
+		else if (BuffEnd < H) {
+			H = BuffEnd;
+		}
+	}
 
-  NewLine(PageStart+CursorY);
+	NewLine(PageStart+CursorY);
 
-  /* Change Window Size */
-  BuffChangeWinSize(W,H);
-  WinOrgY = -NumOfLines;
-  DispScrollHomePos();
+	/* Change Window Size */
+	BuffChangeWinSize(W,H);
+	WinOrgY = -NumOfLines;
+	DispScrollHomePos();
 
-  if (cv.Ready && cv.TelFlag)
-    TelInformWinSize(NumOfColumns,NumOfLines-StatusLine);
+	if (cv.Ready && cv.TelFlag) {
+		TelInformWinSize(NumOfColumns,NumOfLines-StatusLine);
+	}
 
-  TTXSetWinSize(NumOfLines-StatusLine, NumOfColumns); /* TTPLUG */
+	TTXSetWinSize(NumOfLines-StatusLine, NumOfColumns); /* TTPLUG */
 }
 
 void ChangeWin()
 {
-  int Ny;
+	int Ny;
 
-  /* Change buffer */
-  if (ts.EnableScrollBuff>0)
-  {
-    if (ts.ScrollBuffSize < NumOfLines)
-      ts.ScrollBuffSize = NumOfLines;
-    Ny = ts.ScrollBuffSize;
-  }
-  else
-    Ny = NumOfLines;
+	/* Change buffer */
+	if (ts.EnableScrollBuff>0) {
+		if (ts.ScrollBuffSize < NumOfLines) {
+			ts.ScrollBuffSize = NumOfLines;
+		}
+		Ny = ts.ScrollBuffSize;
+	}
+	else {
+		Ny = NumOfLines;
+	}
 
-  if (NumOfLinesInBuff!=Ny)
-  {
-    ChangeBuffer(NumOfColumns,Ny);
-    if (ts.EnableScrollBuff>0)
-      ts.ScrollBuffSize = NumOfLinesInBuff;
+	if (NumOfLinesInBuff!=Ny) {
+		ChangeBuffer(NumOfColumns,Ny);
+		if (ts.EnableScrollBuff>0) {
+			ts.ScrollBuffSize = NumOfLinesInBuff;
+		}
 
-    if (BuffEnd < WinHeight)
-      BuffChangeWinSize(WinWidth,BuffEnd);
-    else
-      BuffChangeWinSize(WinWidth,WinHeight);
-  }
+		if (BuffEnd < WinHeight) {
+			BuffChangeWinSize(WinWidth,BuffEnd);
+		}
+		else {
+			BuffChangeWinSize(WinWidth,WinHeight);
+		}
+	}
 
-  DispChangeWin();
+	DispChangeWin();
 }
 
 void ClearBuffer()
 {
-  /* Reset buffer */
-  PageStart = 0;
-  BuffStartAbs = 0;
-  BuffEnd = NumOfLines;
-  if (NumOfLines==NumOfLinesInBuff)
-    BuffEndAbs = 0;
-  else
-    BuffEndAbs = NumOfLines;
+	/* Reset buffer */
+	PageStart = 0;
+	BuffStartAbs = 0;
+	BuffEnd = NumOfLines;
+	if (NumOfLines==NumOfLinesInBuff) {
+		BuffEndAbs = 0;
+	}
+	else {
+		BuffEndAbs = NumOfLines;
+	}
 
-  SelectStart.x = 0;
-  SelectStart.y = 0;
-  SelectEnd = SelectStart;
-  SelectEndOld = SelectStart;
-  Selected = FALSE;
+	SelectStart.x = 0;
+	SelectStart.y = 0;
+	SelectEnd = SelectStart;
+	SelectEndOld = SelectStart;
+	Selected = FALSE;
 
-  NewLine(0);
-  memset(&CodeBuff[0],0x20,BufferSize);
-  memset(&AttrBuff[0],AttrDefault,BufferSize);
-  memset(&AttrBuff2[0],CurCharAttr.Attr2,BufferSize);
-  memset(&AttrBuffFG[0],CurCharAttr.Fore,BufferSize);
-  memset(&AttrBuffBG[0],CurCharAttr.Back,BufferSize);
+	NewLine(0);
+	memset(&CodeBuff[0],0x20,BufferSize);
+	memset(&AttrBuff[0],AttrDefault,BufferSize);
+	memset(&AttrBuff2[0],CurCharAttr.Attr2,BufferSize);
+	memset(&AttrBuffFG[0],CurCharAttr.Fore,BufferSize);
+	memset(&AttrBuffBG[0],CurCharAttr.Back,BufferSize);
 
-  /* Home position */
-  CursorX = 0;
-  CursorY = 0;
-  WinOrgX = 0;
-  WinOrgY = 0;
-  NewOrgX = 0;
-  NewOrgY = 0;
+	/* Home position */
+	CursorX = 0;
+	CursorY = 0;
+	WinOrgX = 0;
+	WinOrgY = 0;
+	NewOrgX = 0;
+	NewOrgY = 0;
 
-  /* Top/bottom margin */
-  CursorTop = 0;
-  CursorBottom = NumOfLines-1;
+	/* Top/bottom margin */
+	CursorTop = 0;
+	CursorBottom = NumOfLines-1;
 
-  StrChangeCount = 0;
+	StrChangeCount = 0;
 
-  DispClearWin();
+	DispClearWin();
 }
 
 void SetTabStop()
 {
-  int i,j;
+	int i,j;
 
-  if (NTabStops<NumOfColumns)
-  {
-    i = 0;
-    while ((TabStops[i]<CursorX) && (i<NTabStops))
-      i++;
+	if (NTabStops<NumOfColumns) {
+		i = 0;
+		while ((TabStops[i]<CursorX) && (i<NTabStops)) {
+			i++;
+		}
 
-    if ((i<NTabStops) && (TabStops[i]==CursorX)) return;
+		if ((i<NTabStops) && (TabStops[i]==CursorX)) {
+			return;
+		}
 
-    for (j=NTabStops ; j>=i+1 ; j--)
-      TabStops[j] = TabStops[j-1];
-    TabStops[i] = CursorX;
-    NTabStops++;
-  }
+		for (j=NTabStops ; j>=i+1 ; j--) {
+			TabStops[j] = TabStops[j-1];
+		}
+		TabStops[i] = CursorX;
+		NTabStops++;
+	}
 }
 
 void CursorForwardTab(int count, BOOL AutoWrapMode) {
@@ -2826,10 +2965,12 @@
 	}
 	else {
 		MoveCursor(NumOfColumns-1, CursorY);
-		if (!ts.VTCompatTab)
+		if (!ts.VTCompatTab) {
 			Wrap = AutoWrapMode;
-		else
+		}
+		else {
 			Wrap = WrapState;
+		}
 	}
 }
 
@@ -2839,10 +2980,12 @@
 	for (i=0; i<NTabStops && TabStops[i] < CursorX; i++)
 		;
 
-	if (i < count)
+	if (i < count) {
 		MoveCursor(0, CursorY);
-	else
+	}
+	else {
 		MoveCursor(TabStops[i-count], CursorY);
+	}
 }
 
 void ClearTabStop(int Ps)
@@ -2850,85 +2993,106 @@
 //   Ps = 0: clear the tab stop at cursor
 //      = 3: clear all tab stops
 {
-  int i,j;
+	int i,j;
 
-  if (NTabStops>0)
-    switch (Ps) {
-      case 0:
-	i = 0;
-	while ((TabStops[i]!=CursorX) && (i<NTabStops-1))
-	  i++;
-	if (TabStops[i] == CursorX)
-	{
-	  NTabStops--;
-	  for (j=i ; j<=NTabStops ; j++)
-	    TabStops[j] = TabStops[j+1];
+	if (NTabStops>0) {
+		switch (Ps) {
+			case 0:
+				i = 0;
+				while ((TabStops[i]!=CursorX) && (i<NTabStops-1)) {
+					i++;
+				}
+				if (TabStops[i] == CursorX) {
+					NTabStops--;
+					for (j=i ; j<=NTabStops ; j++) {
+						TabStops[j] = TabStops[j+1];
+					}
+				}
+				break;
+			case 3:
+				NTabStops = 0;
+				break;
+		}
 	}
-	break;
-      case 3: NTabStops = 0; break;
-    }
 }
 
 void ShowStatusLine(int Show)
 // show/hide status line
 {
-  int Ny, Nb, W, H;
+	int Ny, Nb, W, H;
 
-  BuffUpdateScroll();
-  if (Show==StatusLine) return;
-  StatusLine = Show;
+	BuffUpdateScroll();
+	if (Show==StatusLine) {
+		return;
+	}
+	StatusLine = Show;
 
-  if (StatusLine==0)
-  {
-    NumOfLines--;
-    BuffEnd--;
-    BuffEndAbs=PageStart+NumOfLines;
-    if (BuffEndAbs >= NumOfLinesInBuff)
-      BuffEndAbs = BuffEndAbs-NumOfLinesInBuff;
-    Ny = NumOfLines;
-  }
-  else
-    Ny = ts.TerminalHeight+1;
+	if (StatusLine==0) {
+		NumOfLines--;
+		BuffEnd--;
+		BuffEndAbs=PageStart+NumOfLines;
+		if (BuffEndAbs >= NumOfLinesInBuff) {
+			BuffEndAbs = BuffEndAbs-NumOfLinesInBuff;
+		}
+		Ny = NumOfLines;
+	}
+	else {
+		Ny = ts.TerminalHeight+1;
+	}
 
-  if ((ts.ScrollBuffSize < Ny) ||
-      (ts.EnableScrollBuff==0))
-   Nb = Ny;
-  else Nb = ts.ScrollBuffSize;
+	if ((ts.ScrollBuffSize < Ny) ||
+	    (ts.EnableScrollBuff==0)) {
+		Nb = Ny;
+	}
+	else {
+		Nb = ts.ScrollBuffSize;
+	}
 
-  if (! ChangeBuffer(NumOfColumns,Nb)) return;
-  if (ts.EnableScrollBuff>0)
-    ts.ScrollBuffSize = NumOfLinesInBuff;
-  if (Ny > NumOfLinesInBuff) Ny = NumOfLinesInBuff;
+	if (! ChangeBuffer(NumOfColumns,Nb)) {
+		return;
+	}
+	if (ts.EnableScrollBuff>0) {
+		ts.ScrollBuffSize = NumOfLinesInBuff;
+	}
+	if (Ny > NumOfLinesInBuff) {
+		Ny = NumOfLinesInBuff;
+	}
 
-  NumOfLines = Ny;
-  ts.TerminalHeight = Ny-StatusLine;
+	NumOfLines = Ny;
+	ts.TerminalHeight = Ny-StatusLine;
 
-  if (StatusLine==1)
-    BuffScroll(1,NumOfLines-1);
+	if (StatusLine==1) {
+		BuffScroll(1,NumOfLines-1);
+	}
 
-  if (ts.TermIsWin>0)
-  {
-    W = NumOfColumns;
-    H = NumOfLines;
-  }
-  else {
-    W = WinWidth;
-    H = WinHeight;
-    if ((ts.AutoWinResize>0) ||
-	(NumOfColumns < W)) W = NumOfColumns;
-    if (ts.AutoWinResize>0) H = NumOfLines;
-    else if (BuffEnd < H) H = BuffEnd;
-  }
+	if (ts.TermIsWin>0) {
+		W = NumOfColumns;
+		H = NumOfLines;
+	}
+	else {
+		W = WinWidth;
+		H = WinHeight;
+		if ((ts.AutoWinResize>0) ||
+		    (NumOfColumns < W)) {
+			W = NumOfColumns;
+		}
+		if (ts.AutoWinResize>0) {
+			H = NumOfLines;
+		}
+		else if (BuffEnd < H) {
+			H = BuffEnd;
+		}
+	}
 
-  PageStart = BuffEnd-NumOfLines;
-  NewLine(PageStart+CursorY);
+	PageStart = BuffEnd-NumOfLines;
+	NewLine(PageStart+CursorY);
 
-  /* Change Window Size */
-  BuffChangeWinSize(W,H);
-  WinOrgY = -NumOfLines;
-  DispScrollHomePos();
+	/* Change Window Size */
+	BuffChangeWinSize(W,H);
+	WinOrgY = -NumOfLines;
+	DispScrollHomePos();
 
-  MoveCursor(CursorX,CursorY);
+	MoveCursor(CursorX,CursorY);
 }
 
 #ifndef NO_COPYLINE_FIX

Modified: trunk/teraterm/teraterm/clipboar.c
===================================================================
--- trunk/teraterm/teraterm/clipboar.c	2009-05-12 11:55:27 UTC (rev 3392)
+++ trunk/teraterm/teraterm/clipboar.c	2009-05-12 14:26:30 UTC (rev 3393)
@@ -35,98 +35,114 @@
 
 PCHAR CBOpen(LONG MemSize)
 {
-  if (MemSize==0) return (NULL);
-  if (CBCopyHandle!=NULL) return (NULL);
-  CBCopyPtr = NULL;
-  CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
-  if (CBCopyHandle == NULL) 
-    MessageBeep(0);
-  else {
-    CBCopyPtr = GlobalLock(CBCopyHandle);
-    if (CBCopyPtr == NULL)
-    {
-      GlobalFree(CBCopyHandle);
-      CBCopyHandle = NULL;
-      MessageBeep(0);
-    }
-  }
-  return (CBCopyPtr);
+	if (MemSize==0) {
+		return (NULL);
+	}
+	if (CBCopyHandle!=NULL) {
+		return (NULL);
+	}
+	CBCopyPtr = NULL;
+	CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
+	if (CBCopyHandle == NULL) {
+		MessageBeep(0);
+	}
+	else {
+		CBCopyPtr = GlobalLock(CBCopyHandle);
+		if (CBCopyPtr == NULL) {
+			GlobalFree(CBCopyHandle);
+			CBCopyHandle = NULL;
+			MessageBeep(0);
+		}
+	}
+	return (CBCopyPtr);
 }
 
 void CBClose()
 {
-  BOOL Empty;
-  if (CBCopyHandle==NULL) return;
+	BOOL Empty;
+	if (CBCopyHandle==NULL) {
+		return;
+	}
 
-  Empty = FALSE;
-  if (CBCopyPtr!=NULL)
-    Empty = (CBCopyPtr[0]==0);
+	Empty = FALSE;
+	if (CBCopyPtr!=NULL) {
+		Empty = (CBCopyPtr[0]==0);
+	}
 
-  GlobalUnlock(CBCopyHandle);
-  CBCopyPtr = NULL;
+	GlobalUnlock(CBCopyHandle);
+	CBCopyPtr = NULL;
 
-  if (OpenClipboard(HVTWin))
-  {
-    EmptyClipboard();
-    if (! Empty)
-      SetClipboardData(CF_TEXT, CBCopyHandle);
-    CloseClipboard();
-  }
-  CBCopyHandle = NULL;
+	if (OpenClipboard(HVTWin)) {
+		EmptyClipboard();
+		if (! Empty) {
+			SetClipboardData(CF_TEXT, CBCopyHandle);
+		}
+		CloseClipboard();
+	}
+	CBCopyHandle = NULL;
 }
 
 void CBStartPaste(HWND HWin, BOOL AddCR,
-		  int BuffSize, PCHAR DataPtr, int DataSize)
+                  int BuffSize, PCHAR DataPtr, int DataSize)
 //
 //  DataPtr and DataSize are used only for DDE
 //	  For clipboard, BuffSize should be 0
 //	  DataSize should be <= BuffSize
 {
-  UINT Cf;
+	UINT Cf;
 
-  if (! cv.Ready) return;
-  if (TalkStatus!=IdTalkKeyb) return;
+	if (! cv.Ready) {
+		return;
+	}
+	if (TalkStatus!=IdTalkKeyb) {
+		return;
+	}
 
-  CBAddCR = AddCR;
+	CBAddCR = AddCR;
 
-  if (BuffSize==0) // for clipboard
-  {
-    if (IsClipboardFormatAvailable(CF_TEXT))
-      Cf = CF_TEXT;
-    else if (IsClipboardFormatAvailable(CF_OEMTEXT))
-      Cf = CF_OEMTEXT;
-    else return;
-  }
+	if (BuffSize==0) { // for clipboar
+		if (IsClipboardFormatAvailable(CF_TEXT)) {
+			Cf = CF_TEXT;
+		}
+		else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
+			Cf = CF_OEMTEXT;
+		}
+		else {
+			return;
+		}
+	}
 
-  CBMemHandle = NULL;
-  CBMemPtr = NULL;
-  CBMemPtr2 = 0;
-  CBDDE = FALSE;
-  if (BuffSize==0) //clipboard
-  {
-    if (OpenClipboard(HWin))
-      CBMemHandle = GetClipboardData(Cf);
-    if (CBMemHandle!=NULL) TalkStatus=IdTalkCB;
-  }
-  else { // dde
-    CBMemHandle = GlobalAlloc(GHND,BuffSize);
-    if (CBMemHandle != NULL)
-    {
-      CBDDE = TRUE;
-      CBMemPtr = GlobalLock(CBMemHandle);
-      if (CBMemPtr != NULL)
-      {
-	memcpy(CBMemPtr,DataPtr,DataSize);
-	GlobalUnlock(CBMemHandle);
-	CBMemPtr=NULL;
-	TalkStatus=IdTalkCB;
-      }
-    }
-  }
-  CBRetrySend = FALSE;
-  CBRetryEcho = FALSE;
-  CBSendCR = FALSE;
-  if (TalkStatus != IdTalkCB) CBEndPaste();
+	CBMemHandle = NULL;
+	CBMemPtr = NULL;
+	CBMemPtr2 = 0;
+	CBDDE = FALSE;
+	if (BuffSize==0) { //clipboard
+		if (OpenClipboard(HWin)) {
+			CBMemHandle = GetClipboardData(Cf);
+		}
+		if (CBMemHandle!=NULL) {
+			TalkStatus=IdTalkCB;
+		}
+	}
+	else { // dde
+		CBMemHandle = GlobalAlloc(GHND,BuffSize);
+		if (CBMemHandle != NULL) {
+			CBDDE = TRUE;
+			CBMemPtr = GlobalLock(CBMemHandle);
+			if (CBMemPtr != NULL) {
+				memcpy(CBMemPtr,DataPtr,DataSize);
+				GlobalUnlock(CBMemHandle);
+				CBMemPtr=NULL;
+				TalkStatus=IdTalkCB;
+			}
+		}
+	}
+	CBRetrySend = FALSE;
+	CBRetryEcho = FALSE;
+	CBSendCR = FALSE;
+	if (TalkStatus != IdTalkCB) {
+		CBEndPaste();
+	}
 }
 
 // ‚±‚̊֐”‚̓NƒŠƒbƒvƒ{[ƒh‚¨‚æ‚ÑDDEƒf[ƒ^‚ð’[––‚Ö‘—‚荞‚ށB
@@ -138,107 +154,111 @@
 // (2006.11.6 yutaka)
 void CBSend()
 {
-  int c;
-  BOOL EndFlag;
+	int c;
+	BOOL EndFlag;
 
-  if (CBMemHandle==NULL) return;
+	if (CBMemHandle==NULL) {
+		return;
+	}
 
-  if (CBRetrySend)
-  {
-    CBRetryEcho = (ts.LocalEcho>0);
-    c = CommTextOut(&cv,(PCHAR)&CBByte,1);
-    CBRetrySend = (c==0);
-    if (CBRetrySend) return;
-  }
+	if (CBRetrySend) {
+		CBRetryEcho = (ts.LocalEcho>0);
+		c = CommTextOut(&cv,(PCHAR)&CBByte,1);
+		CBRetrySend = (c==0);
+		if (CBRetrySend) {
+			return;
+		}
+	}
 
-  if (CBRetryEcho)
-  {
-    c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
-    CBRetryEcho = (c==0);
-    if (CBRetryEcho) return;
-  }
+	if (CBRetryEcho) {
+		c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
+		CBRetryEcho = (c==0);
+		if (CBRetryEcho) {
+			return;
+		}
+	}
 
-  CBMemPtr = GlobalLock(CBMemHandle);
-  if (CBMemPtr==NULL) return;
-  
-  do {
-    if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
-      CBMemPtr2++;
-      // added PasteDelayPerLine (2009.4.12 maya)
-      Sleep(ts.PasteDelayPerLine);
-    }
+	CBMemPtr = GlobalLock(CBMemHandle);
+	if (CBMemPtr==NULL) {
+		return;
+	}
 
-    EndFlag = (CBMemPtr[CBMemPtr2]==0);
-    if (! EndFlag)
-    {
-      CBByte = CBMemPtr[CBMemPtr2];
-      CBMemPtr2++;
+	do {
+		if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
+			CBMemPtr2++;
+			// added PasteDelayPerLine (2009.4.12 maya)
+			Sleep(ts.PasteDelayPerLine);
+		}
+
+		EndFlag = (CBMemPtr[CBMemPtr2]==0);
+		if (! EndFlag) {
+			CBByte = CBMemPtr[CBMemPtr2];
+			CBMemPtr2++;
 // Decoding characters which are encoded by MACRO
 //   to support NUL character sending
 //
 //  [encoded character] --> [decoded character]
 //         01 01        -->     00
 //         01 02        -->     01
-      if (CBByte==0x01) /* 0x01 from MACRO */
-      {
-        CBByte = CBMemPtr[CBMemPtr2];
-        CBMemPtr2++;
-        CBByte = CBByte - 1; // character just after 0x01
-      }
-    }
-    else if (CBAddCR)
-    {
-	  EndFlag = FALSE;
-      CBAddCR = FALSE;
-      CBByte = 0x0d;
-    }
-    else {
-      CBEndPaste();
-      return;
-    }
+			if (CBByte==0x01) { /* 0x01 from MACRO */
+				CBByte = CBMemPtr[CBMemPtr2];
+				CBMemPtr2++;
+				CBByte = CBByte - 1; // character just after 0x01
+			}
+		}
+		else if (CBAddCR) {
+			EndFlag = FALSE;
+			CBAddCR = FALSE;
+			CBByte = 0x0d;
+		}
+		else {
+			CBEndPaste();
+			return;
+		}
 
-    if (! EndFlag)
-    {
-      c = CommTextOut(&cv,(PCHAR)&CBByte,1);
-      CBSendCR = (CBByte==0x0D);
-      CBRetrySend = (c==0);
-      if ((! CBRetrySend) &&
-	  (ts.LocalEcho>0))
-      {
-	c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
-	CBRetryEcho = (c==0);
-      }
-    }
-    else
-      c=0;
-  }
-  while (c>0);
+		if (! EndFlag) {
+			c = CommTextOut(&cv,(PCHAR)&CBByte,1);
+			CBSendCR = (CBByte==0x0D);
+			CBRetrySend = (c==0);
+			if ((! CBRetrySend) &&
+			    (ts.LocalEcho>0)) {
+				c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
+				CBRetryEcho = (c==0);
+			}
+		}
+		else {
+			c=0;
+		}
+	}
+	while (c>0);
 
-  if (CBMemPtr!=NULL)
-  {
-    GlobalUnlock(CBMemHandle);
-    CBMemPtr=NULL;
-  }
+	if (CBMemPtr!=NULL) {
+		GlobalUnlock(CBMemHandle);
+		CBMemPtr=NULL;
+	}
 }
 
 void CBEndPaste()
 {
-  TalkStatus = IdTalkKeyb;
+	TalkStatus = IdTalkKeyb;
 
-  if (CBMemHandle!=NULL)
-  {
-    if (CBMemPtr!=NULL)
-      GlobalUnlock(CBMemHandle);
-    if (CBDDE)
-      GlobalFree(CBMemHandle);
-  }
-  if (!CBDDE) CloseClipboard();
+	if (CBMemHandle!=NULL) {
+		if (CBMemPtr!=NULL) {
+			GlobalUnlock(CBMemHandle);
+		}
+		if (CBDDE) {
+			GlobalFree(CBMemHandle);
+		}
+	}
+	if (!CBDDE) {
+		CloseClipboard();
+	}
 
-  CBDDE = FALSE;
-  CBMemHandle = NULL;
-  CBMemPtr = NULL;
-  CBMemPtr2 = 0;
-  CBAddCR = FALSE;
+	CBDDE = FALSE;
+	CBMemHandle = NULL;
+	CBMemPtr = NULL;
+	CBMemPtr2 = 0;
+	CBAddCR = FALSE;
 }
 
 

Modified: trunk/teraterm/teraterm/commlib.c
===================================================================
--- trunk/teraterm/teraterm/commlib.c	2009-05-12 11:55:27 UTC (rev 3392)
+++ trunk/teraterm/teraterm/commlib.c	2009-05-12 14:26:30 UTC (rev 3393)
@@ -31,48 +31,47 @@
 /* create socket */
 static SOCKET OpenSocket(PComVar cv)
 {
-  cv->s = cv->res->ai_family;
-  cv->s = Psocket(cv->res->ai_family, cv->res->ai_socktype, cv->res->ai_protocol);
-  return cv->s;
+	cv->s = cv->res->ai_family;
+	cv->s = Psocket(cv->res->ai_family, cv->res->ai_socktype, cv->res->ai_protocol);
+	return cv->s;
 }
 
 /* connect with asynchronous mode */
 static void AsyncConnect(PComVar cv)
 {
-  int Err;
-  BOOL BBuf;
-  BBuf = TRUE;
-  /* set synchronous mode */
-  PWSAAsyncSelect(cv->s,cv->HWin,0,0);
-  Psetsockopt(cv->s,(int)SOL_SOCKET,SO_OOBINLINE,(char FAR *)&BBuf,sizeof(BBuf));
-  /* set asynchronous mode */
-  PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMOPEN, FD_CONNECT);
+	int Err;
+	BOOL BBuf;
+	BBuf = TRUE;
+	/* set synchronous mode */
+	PWSAAsyncSelect(cv->s,cv->HWin,0,0);
+	Psetsockopt(cv->s,(int)SOL_SOCKET,SO_OOBINLINE,(char FAR *)&BBuf,sizeof(BBuf));
+	/* set asynchronous mode */
+	PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMOPEN, FD_CONNECT);
 
-  // ƒzƒXƒg‚ւ̐ڑ±’†‚Ɉê’莞ŠÔ—§‚‚ƁA‹­§“I‚Ƀ\ƒPƒbƒg‚ðƒNƒ[ƒY‚µ‚āA
-  // Ú‘±ˆ—‚ðƒLƒƒƒ“ƒZƒ‹‚³‚¹‚éB’l‚ª0‚̏ꍇ‚͉½‚à‚µ‚È‚¢B
-  // (2007.1.11 yutaka)
-  if (*cv->ConnetingTimeout > 0) {
-	SetTimer(cv->HWin, IdCancelConnectTimer, *cv->ConnetingTimeout * 1000, NULL);
-  }
+	// ƒzƒXƒg‚ւ̐ڑ±’†‚Ɉê’莞ŠÔ—§‚‚ƁA‹­§“I‚Ƀ\ƒPƒbƒg‚ðƒNƒ[ƒY‚µ‚āA
+	// Ú‘±ˆ—‚ðƒLƒƒƒ“ƒZƒ‹‚³‚¹‚éB’l‚ª0‚̏ꍇ‚͉½‚à‚µ‚È‚¢B
+	// (2007.1.11 yutaka)
+	if (*cv->ConnetingTimeout > 0) {
+		SetTimer(cv->HWin, IdCancelConnectTimer, *cv->ConnetingTimeout * 1000, NULL);
+	}
 
-  /* WM_USER_COMMOPEN occurs, CommOpen is called, then CommStart is called */
-  Err = Pconnect(cv->s, cv->res->ai_addr, cv->res->ai_addrlen);
-  if (Err != 0) {
-    Err = PWSAGetLastError();
-    if (Err == WSAEWOULDBLOCK)
-    {
-      /* Do nothing */
-    } else if (Err!=0 ) {
-      PostMessage(cv->HWin, WM_USER_COMMOPEN,0,
-		  MAKELONG(FD_CONNECT,Err));
-    }
-  }
+	/* WM_USER_COMMOPEN occurs, CommOpen is called, then CommStart is called */
+	Err = Pconnect(cv->s, cv->res->ai_addr, cv->res->ai_addrlen);
+	if (Err != 0) {
+		Err = PWSAGetLastError();
+		if (Err == WSAEWOULDBLOCK)  {
+			/* Do nothing */
+		} else if (Err!=0 ) {
+			PostMessage(cv->HWin, WM_USER_COMMOPEN,0,
+			            MAKELONG(FD_CONNECT,Err));
+		}
+	}
 }
 
 /* close socket */
 static int CloseSocket(SOCKET s)
 {
-  return Pclosesocket(s);
+	return Pclosesocket(s);
 }
 
 #define CommInQueSize 8192
@@ -103,275 +102,279 @@
 // by the initialization procedure of Tera Term.
 void CommInit(PComVar cv)
 {
-  cv->Open = FALSE;
-  cv->Ready = FALSE;
+	cv->Open = FALSE;
+	cv->Ready = FALSE;
 
 // log-buffer variables
-  cv->HLogBuf = 0;
-  cv->HBinBuf = 0;
-  cv->LogBuf = NULL;
-  cv->BinBuf = NULL;
-  cv->LogPtr = 0;
-  cv->LStart = 0;
-  cv->LCount = 0;
-  cv->BinPtr = 0;
-  cv->BStart = 0;
-  cv->BCount = 0;
-  cv->DStart = 0;
-  cv->DCount = 0;
-  cv->BinSkip = 0;
-  cv->FilePause = 0;
-  cv->ProtoFlag = FALSE;
+	cv->HLogBuf = 0;
+	cv->HBinBuf = 0;
+	cv->LogBuf = NULL;
+	cv->BinBuf = NULL;
+	cv->LogPtr = 0;
+	cv->LStart = 0;
+	cv->LCount = 0;
+	cv->BinPtr = 0;
+	cv->BStart = 0;
+	cv->BCount = 0;
+	cv->DStart = 0;
+	cv->DCount = 0;
+	cv->BinSkip = 0;
+	cv->FilePause = 0;
+	cv->ProtoFlag = FALSE;
 /* message flag */
-  cv->NoMsg = 0;
+	cv->NoMsg = 0;
 }
 
 /* reset a serial port which is already open */
 void CommResetSerial(PTTSet ts, PComVar cv, BOOL ClearBuff)
 {
-  DCB dcb;
-  DWORD DErr;
-  COMMTIMEOUTS ctmo;
+	DCB dcb;
+	DWORD DErr;
+	COMMTIMEOUTS ctmo;
 
-  if (! cv->Open ||
-      (cv->PortType != IdSerial)) return;
+	if (! cv->Open ||
+		(cv->PortType != IdSerial)) {
+			return;
+	}
 
-  ClearCommError(cv->ComID,&DErr,NULL);
-  SetupComm(cv->ComID,CommInQueSize,CommOutQueSize);
-  /* flush input and output buffers */
-  if (ClearBuff)
-    PurgeComm(cv->ComID, PURGE_TXABORT | PURGE_RXABORT |
-      PURGE_TXCLEAR | PURGE_RXCLEAR);
+	ClearCommError(cv->ComID,&DErr,NULL);
+	SetupComm(cv->ComID,CommInQueSize,CommOutQueSize);
+	/* flush input and output buffers */
+	if (ClearBuff) {
+		PurgeComm(cv->ComID, PURGE_TXABORT | PURGE_RXABORT |
+		                     PURGE_TXCLEAR | PURGE_RXCLEAR);
+	}
 
-  memset(&ctmo,0,sizeof(ctmo));
-  ctmo.ReadIntervalTimeout = MAXDWORD;
-  ctmo.WriteTotalTimeoutConstant = 500;
-  SetCommTimeouts(cv->ComID,&ctmo);
-  cv->InBuffCount = 0;
-  cv->InPtr = 0;
-  cv->OutBuffCount = 0;
-  cv->OutPtr = 0;
+	memset(&ctmo,0,sizeof(ctmo));
+	ctmo.ReadIntervalTimeout = MAXDWORD;
+	ctmo.WriteTotalTimeoutConstant = 500;
+	SetCommTimeouts(cv->ComID,&ctmo);
+	cv->InBuffCount = 0;
+	cv->InPtr = 0;
+	cv->OutBuffCount = 0;
+	cv->OutPtr = 0;
 
-  cv->DelayPerChar = ts->DelayPerChar;
-  cv->DelayPerLine = ts->DelayPerLine;
+	cv->DelayPerChar = ts->DelayPerChar;
+	cv->DelayPerLine = ts->DelayPerLine;
 
-  memset(&dcb,0,sizeof(DCB));
-  dcb.DCBlength = sizeof(DCB);
-  dcb.BaudRate = GetCommSerialBaudRate(ts->Baud);
-  dcb.fBinary = TRUE;
-  switch (ts->Parity) {
-    case IdParityEven:
-      dcb.fParity = TRUE;
-      dcb.Parity = EVENPARITY;
-      break;
-    case IdParityOdd:
-      dcb.fParity = TRUE;
-      dcb.Parity = ODDPARITY;
-      break;
-    case IdParityNone:
-      dcb.Parity = NOPARITY;
-      break;
-  }
+	memset(&dcb,0,sizeof(DCB));
+	dcb.DCBlength = sizeof(DCB);
+	dcb.BaudRate = GetCommSerialBaudRate(ts->Baud);
+	dcb.fBinary = TRUE;
+	switch (ts->Parity) {
+		case IdParityEven:
+			dcb.fParity = TRUE;
+			dcb.Parity = EVENPARITY;
+			break;
+		case IdParityOdd:
+			dcb.fParity = TRUE;
+			dcb.Parity = ODDPARITY;
+			break;
+		case IdParityNone:
+			dcb.Parity = NOPARITY;
+			break;
+	}
 
-  dcb.fDtrControl = DTR_CONTROL_ENABLE;
-  dcb.fRtsControl = RTS_CONTROL_ENABLE;
-  switch (ts->Flow) {
-    case IdFlowX:
-      dcb.fOutX = TRUE;
-      dcb.fInX = TRUE;
-      dcb.XonLim = CommXonLim;
-      dcb.XoffLim = CommXoffLim;
-      dcb.XonChar = XON;
-      dcb.XoffChar = XOFF;
-      break;
-    case IdFlowHard:
-      dcb.fOutxCtsFlow = TRUE;
-      dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
-      break;
-  }
+	dcb.fDtrControl = DTR_CONTROL_ENABLE;
+	dcb.fRtsControl = RTS_CONTROL_ENABLE;
+	switch (ts->Flow) {
+		case IdFlowX:
+			dcb.fOutX = TRUE;
+			dcb.fInX = TRUE;
+			dcb.XonLim = CommXonLim;
+			dcb.XoffLim = CommXoffLim;
+			dcb.XonChar = XON;
+			dcb.XoffChar = XOFF;
+			break;
+		case IdFlowHard:
+			dcb.fOutxCtsFlow = TRUE;
+			dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
+			break;
+	}
 
-  switch (ts->DataBit) {
-    case IdDataBit7: dcb.ByteSize = 7; break;
-    case IdDataBit8: dcb.ByteSize = 8; break;
-  }
-  switch (ts->StopBit) {
-    case IdStopBit1: dcb.StopBits = ONESTOPBIT; break;
-    case IdStopBit2: dcb.StopBits = TWOSTOPBITS; break;
-  }
+	switch (ts->DataBit) {
+		case IdDataBit7:
+			dcb.ByteSize = 7;
+			break;
+		case IdDataBit8:
+			dcb.ByteSize = 8;
+			break;
+	}
+	switch (ts->StopBit) {
+		case IdStopBit1:
+			dcb.StopBits = ONESTOPBIT;
+			break;
+		case IdStopBit2:
+			dcb.StopBits = TWOSTOPBITS;
+			break;
+	}
 
-  SetCommState(cv->ComID, &dcb);
+	SetCommState(cv->ComID, &dcb);
 
-  /* enable receive request */
-  SetCommMask(cv->ComID,0);
-  SetCommMask(cv->ComID,EV_RXCHAR);
+	/* enable receive request */
+	SetCommMask(cv->ComID,0);
+	SetCommMask(cv->ComID,EV_RXCHAR);
 }
 
 void CommOpen(HWND HW, PTTSet ts, PComVar cv)
 {
 #ifdef NO_INET6
-  int Err;
+	int Err;
 #endif /* NO_INET6 */
-  char ErrMsg[21];
-  char P[50];
+	char ErrMsg[21];
+	char P[50];
 
-  MSG Msg;
+	MSG Msg;
 #ifndef NO_INET6
-  ADDRINFO hints;
-  char pname[NI_MAXSERV];
+	ADDRINFO hints;
+	char pname[NI_MAXSERV];
 #else
-  char HEntBuff[MAXGETHOSTSTRUCT];
-  u_long addr;
-  SOCKADDR_IN saddr;
+	char HEntBuff[MAXGETHOSTSTRUCT];
+	u_long addr;
+	SOCKADDR_IN saddr;
 #endif /* NO_INET6 */
 
-  BOOL InvalidHost;
+	BOOL InvalidHost;
 #ifdef NO_INET6
-  BOOL BBuf;
+	BOOL BBuf;
 #endif /* NO_INET6 */
 
-  char uimsg[MAX_UIMSG];
+	char uimsg[MAX_UIMSG];
 
-  /* initialize ComVar */
-  cv->InBuffCount = 0;
-  cv->InPtr = 0;
-  cv->OutBuffCount = 0;
-  cv->OutPtr = 0;
-  cv->HWin = HW;
-  cv->Ready = FALSE;
-  cv->Open = FALSE;
-  cv->PortType = ts->PortType;
-  cv->ComPort = 0;
-  cv->RetryCount = 0;
+	/* initialize ComVar */
+	cv->InBuffCount = 0;
+	cv->InPtr = 0;
+	cv->OutBuffCount = 0;
+	cv->OutPtr = 0;
+	cv->HWin = HW;
+	cv->Ready = FALSE;
+	cv->Open = FALSE;
+	cv->PortType = ts->PortType;
+	cv->ComPort = 0;
+	cv->RetryCount = 0;
 #ifndef NO_INET6
-  cv->RetryWithOtherProtocol = TRUE;
+	cv->RetryWithOtherProtocol = TRUE;
 #endif /* NO_INET6 */
-  cv->s = INVALID_SOCKET;
-  cv->ComID = INVALID_HANDLE_VALUE;
-  cv->CanSend = TRUE;
-  cv->RRQ = FALSE;
-  cv->SendKanjiFlag = FALSE;
-  cv->SendCode = IdASCII;
-  cv->EchoKanjiFlag = FALSE;
-  cv->EchoCode = IdASCII;
-  cv->Language = ts->Language;
-  cv->CRSend = ts->CRSend;
-  cv->KanjiCodeEcho = ts->KanjiCode;
-  cv->JIS7KatakanaEcho = ts->JIS7Katakana;
-  cv->KanjiCodeSend = ts->KanjiCodeSend;
-  cv->JIS7KatakanaSend = ts->JIS7KatakanaSend;
-  cv->KanjiIn = ts->KanjiIn;
-  cv->KanjiOut = ts->KanjiOut;
-  cv->RussHost = ts->RussHost;
-  cv->RussClient = ts->RussClient;
-  cv->DelayFlag = TRUE;
-  cv->DelayPerChar = ts->DelayPerChar;
-  cv->DelayPerLine = ts->DelayPerLine;
-  cv->TelBinRecv = FALSE;
-  cv->TelBinSend = FALSE;
-  cv->TelFlag = FALSE;
-  cv->TelMode = FALSE;
-  cv->IACFlag = FALSE;
-  cv->TelCRFlag = FALSE;
-  cv->TelCRSend = FALSE;
-  cv->TelCRSendEcho = FALSE;
-  cv->TelAutoDetect = ts->TelAutoDetect; /* TTPLUG */
-  cv->Locale = ts->Locale;
-  cv->CodePage = &ts->CodePage;
-  cv->ConnetingTimeout = &ts->ConnectingTimeout;
-  cv->LastSendTime = time(NULL);
+	cv->s = INVALID_SOCKET;
+	cv->ComID = INVALID_HANDLE_VALUE;
+	cv->CanSend = TRUE;
+	cv->RRQ = FALSE;
+	cv->SendKanjiFlag = FALSE;
+	cv->SendCode = IdASCII;
+	cv->EchoKanjiFlag = FALSE;
+	cv->EchoCode = IdASCII;
+	cv->Language = ts->Language;
+	cv->CRSend = ts->CRSend;
+	cv->KanjiCodeEcho = ts->KanjiCode;
+	cv->JIS7KatakanaEcho = ts->JIS7Katakana;
+	cv->KanjiCodeSend = ts->KanjiCodeSend;
+	cv->JIS7KatakanaSend = ts->JIS7KatakanaSend;
+	cv->KanjiIn = ts->KanjiIn;
+	cv->KanjiOut = ts->KanjiOut;
+	cv->RussHost = ts->RussHost;
+	cv->RussClient = ts->RussClient;
+	cv->DelayFlag = TRUE;
+	cv->DelayPerChar = ts->DelayPerChar;
+	cv->DelayPerLine = ts->DelayPerLine;
+	cv->TelBinRecv = FALSE;
+	cv->TelBinSend = FALSE;
+	cv->TelFlag = FALSE;
+	cv->TelMode = FALSE;
+	cv->IACFlag = FALSE;
+	cv->TelCRFlag = FALSE;
+	cv->TelCRSend = FALSE;
+	cv->TelCRSendEcho = FALSE;
+	cv->TelAutoDetect = ts->TelAutoDetect; /* TTPLUG */
+	cv->Locale = ts->Locale;
+	cv->CodePage = &ts->CodePage;
+	cv->ConnetingTimeout = &ts->ConnectingTimeout;
+	cv->LastSendTime = time(NULL);
 
-  if ((ts->PortType!=IdSerial) && (strlen(ts->HostName)==0))
-  {
-    PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
-    return;
-  }
-
-  switch (ts->PortType) {
-    case IdTCPIP:
-      cv->TelFlag = (ts->Telnet > 0);
-      if (! LoadWinsock())
-      {
-	if (cv->NoMsg==0)
+	if ((ts->PortType!=IdSerial) && (strlen(ts->HostName)==0))
 	{
-	  get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
-	  get_lang_msg("MSG_WINSOCK_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot use winsock", ts->UILanguageFile);
-	  MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+		PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
+		return;
 	}
-	InvalidHost = TRUE;
-      }
-      else {
-        TTXOpenTCP(); /* TTPLUG */
-	cv->Open = TRUE;
+
+	switch (ts->PortType) {
+		case IdTCPIP:
+			cv->TelFlag = (ts->Telnet > 0);
+			if (! LoadWinsock()) {
+				if (cv->NoMsg==0) {
+					get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+					get_lang_msg("MSG_WINSOCK_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot use winsock", ts->UILanguageFile);
+					MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+				}
+				InvalidHost = TRUE;
+			}
+			else {
+				TTXOpenTCP(); /* TTPLUG */
+				cv->Open = TRUE;
 #ifndef NO_INET6
-	/* resolving address */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = ts->ProtocolFamily;
-	hints.ai_socktype = SOCK_STREAM;
-	hints.ai_protocol = IPPROTO_TCP;
-	_snprintf_s(pname, sizeof(pname), _TRUNCATE, "%d", ts->TCPPort);
+				/* resolving address */
+				memset(&hints, 0, sizeof(hints));
+				hints.ai_family = ts->ProtocolFamily;
+				hints.ai_socktype = SOCK_STREAM;
+				hints.ai_protocol = IPPROTO_TCP;
+				_snprintf_s(pname, sizeof(pname), _TRUNCATE, "%d", ts->TCPPort);
 
-	HAsync = WSAAsyncGetAddrInfo(HW, WM_USER_GETHOST,
-				     ts->HostName, pname, &hints, &cv->res0);
-	if (HAsync == 0)
-	  InvalidHost = TRUE;
-	else {
-	    cv->ComPort = 1; // set "getting host" flag
-			     //  (see CVTWindow::OnSysCommand())
-	    do {
-	      if (GetMessage(&Msg,0,0,0))
-	      {
-		if ((Msg.hwnd==HW) &&
-		    ((Msg.message == WM_SYSCOMMAND) &&
-		     ((Msg.wParam & 0xfff0) == SC_CLOSE) ||
-		     (Msg.message == WM_COMMAND) &&
-		     (LOWORD(Msg.wParam) == ID_FILE_EXIT) ||
-		     (Msg.message == WM_CLOSE)))
-		{ /* Exit when the user closes Tera Term */
-		  PWSACancelAsyncRequest(HAsync);
-		  CloseHandle(HAsync);
-		  HAsync = 0;
-		  cv->ComPort = 0; // clear "getting host" flag
-		  PostMessage(HW,Msg.message,Msg.wParam,Msg.lParam);
-		  return;
-		}
-		if (Msg.message != WM_USER_GETHOST)
-		{ /* Prosess messages */
-		  TranslateMessage(&Msg);
-		  DispatchMessage(&Msg);
-		}
-	      }
-	      else {
-		return;
-	      }
-	    } while (Msg.message!=WM_USER_GETHOST);
-	    cv->ComPort = 0; // clear "getting host" flag
-    	CloseHandle(HAsync);
-	    HAsync = 0;
-	    InvalidHost = WSAGETASYNCERROR(Msg.lParam) != 0;
-	}
-      } /* if (!LoadWinsock()) */
+				HAsync = WSAAsyncGetAddrInfo(HW, WM_USER_GETHOST,
+				                             ts->HostName, pname, &hints, &cv->res0);
+				if (HAsync == 0)
+					InvalidHost = TRUE;
+				else {
+					cv->ComPort = 1; // set "getting host" flag
+					                 //  (see CVTWindow::OnSysCommand())
+					do {
+						if (GetMessage(&Msg,0,0,0)) {
+							if ((Msg.hwnd==HW) &&
+							    ((Msg.message == WM_SYSCOMMAND) &&
+							     ((Msg.wParam & 0xfff0) == SC_CLOSE) ||
+							     (Msg.message == WM_COMMAND) &&
+							     (LOWORD(Msg.wParam) == ID_FILE_EXIT) ||
+							     (Msg.message == WM_CLOSE))) { /* Exit when the user closes Tera Term */
+								PWSACancelAsyncRequest(HAsync);
+								CloseHandle(HAsync);
+								HAsync = 0;
+								cv->ComPort = 0; // clear "getting host" flag
+								PostMessage(HW,Msg.message,Msg.wParam,Msg.lParam);
+								return;
+							}
+							if (Msg.message != WM_USER_GETHOST) { /* Prosess messages */
+								TranslateMessage(&Msg);
+								DispatchMessage(&Msg);
+							}
+						}
+						else {
+							return;
+						}
+					} while (Msg.message!=WM_USER_GETHOST);
+					cv->ComPort = 0; // clear "getting host" flag
+					CloseHandle(HAsync);
+					HAsync = 0;
+					InvalidHost = WSAGETASYNCERROR(Msg.lParam) != 0;
+				}
+			} /* if (!LoadWinsock()) */
 
-      if (InvalidHost)
-      {
-	if (cv->NoMsg==0)
-	{
-	  get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
-	  get_lang_msg("MSG_INVALID_HOST_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Invalid host", ts->UILanguageFile);
-	  MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
-	}
-	goto BreakSC;
-      }
-      for (cv->res = cv->res0; cv->res; cv->res = cv->res->ai_next) {
-	cv->s =  OpenSocket(cv);
-	if (cv->s == INVALID_SOCKET) {
-	  CloseSocket(cv->s);
-	  continue;
-	}
-	/* start asynchronous connect */
-	AsyncConnect(cv);
-	break; /* break for-loop immediately */
-      }
-      break;
+			if (InvalidHost) {
+				if (cv->NoMsg==0) {
+					get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+					get_lang_msg("MSG_INVALID_HOST_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Invalid host", ts->UILanguageFile);
+					MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+				}
+				goto BreakSC;
+			}
+			for (cv->res = cv->res0; cv->res; cv->res = cv->res->ai_next) {
+				cv->s =  OpenSocket(cv);
+				if (cv->s == INVALID_SOCKET) {
+					CloseSocket(cv->s);
+					continue;
+				}
+				/* start asynchronous connect */
+				AsyncConnect(cv);
+				break; /* break for-loop immediately */
+			}
+			break;
 #else
 	if ((ts->HostName[0] >= 0x30) && (ts->HostName[0] <= 0x39))
 	{
@@ -467,170 +470,173 @@
       break;
 #endif /* NO_INET6 */
 
-    case IdSerial:
-      InitFileIO(IdSerial);  /* TTPLUG */
-      TTXOpenFile(); /* TTPLUG */
-      _snprintf_s(P, sizeof(P), _TRUNCATE, "COM%d", ts->ComPort);
-      strncpy_s(ErrMsg, sizeof(ErrMsg),P, _TRUNCATE);
-      strncpy_s(P, sizeof(P),"\\\\.\\", _TRUNCATE);
-      strncat_s(P, sizeof(P),ErrMsg, _TRUNCATE);
-      cv->ComID =
-        PCreateFile(P,GENERIC_READ | GENERIC_WRITE,
-                   0,NULL,OPEN_EXISTING,
-                   FILE_FLAG_OVERLAPPED,NULL);
-      if (cv->ComID == INVALID_HANDLE_VALUE )
-      {
+		case IdSerial:
+			InitFileIO(IdSerial);  /* TTPLUG */
+			TTXOpenFile(); /* TTPLUG */
+			_snprintf_s(P, sizeof(P), _TRUNCATE, "COM%d", ts->ComPort);
+			strncpy_s(ErrMsg, sizeof(ErrMsg),P, _TRUNCATE);
+			strncpy_s(P, sizeof(P),"\\\\.\\", _TRUNCATE);
+			strncat_s(P, sizeof(P),ErrMsg, _TRUNCATE);
+			cv->ComID =
+			PCreateFile(P,GENERIC_READ | GENERIC_WRITE,
+			            0,NULL,OPEN_EXISTING,
+			            FILE_FLAG_OVERLAPPED,NULL);
+			if (cv->ComID == INVALID_HANDLE_VALUE ) {
+				get_lang_msg("MSG_CANTOEPN_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot open %s", ts->UILanguageFile);
+				_snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, ts->UIMsg, &P[4]);
 
-        get_lang_msg("MSG_CANTOEPN_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot open %s", ts->UILanguageFile);
-        _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, ts->UIMsg, &P[4]);
+				if (cv->NoMsg==0) {
+					get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+					MessageBox(cv->HWin,ErrMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+				}
+				InvalidHost = TRUE;
+			}
+			else {
+				cv->Open = TRUE;
+				cv->ComPort = ts->ComPort;
+				CommResetSerial(ts, cv, ts->ClearComBuffOnOpen);
+				if (!ts->ClearComBuffOnOpen) {
+					cv->RRQ = TRUE;
+				}
 
-        if (cv->NoMsg==0)
-        {
-          get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
-          MessageBox(cv->HWin,ErrMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
-        }
-        InvalidHost = TRUE;
-      }
-      else {
-        cv->Open = TRUE;
-        cv->ComPort = ts->ComPort;
-        CommResetSerial(ts, cv, ts->ClearComBuffOnOpen);
-	if (!ts->ClearComBuffOnOpen)
-	  cv->RRQ = TRUE;
+				/* notify to VT window that Comm Port is open */
+				PostMessage(cv->HWin, WM_USER_COMMOPEN, 0, 0);
+				InvalidHost = FALSE;
 
-        /* notify to VT window that Comm Port is open */
-        PostMessage(cv->HWin, WM_USER_COMMOPEN, 0, 0);
-        InvalidHost = FALSE;
+				SetCOMFlag(ts->ComPort);
+			}
+			break; /* end of "case IdSerial:" */
 
-        SetCOMFlag(ts->ComPort);
-      }
-      break; /* end of "case IdSerial:" */
+		case IdFile:
+			InitFileIO(IdFile);  /* TTPLUG */
+			TTXOpenFile(); /* TTPLUG */
+			cv->ComID = PCreateFile(ts->HostName,GENERIC_READ,0,NULL,
+			                        OPEN_EXISTING,0,NULL);
+			InvalidHost = (cv->ComID == INVALID_HANDLE_VALUE);
+			if (InvalidHost) {
+				if (cv->NoMsg==0) {
+					get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+					get_lang_msg("MSG_CANTOEPN_FILE_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot open file", ts->UILanguageFile);
+					MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+				}
+			}
+			else {
+				cv->Open = TRUE;
+				PostMessage(cv->HWin, WM_USER_COMMOPEN, 0, 0);
+			}
+			break;
+	} /* end of "switch" */
 
-    case IdFile:
-      InitFileIO(IdFile);  /* TTPLUG */
-      TTXOpenFile(); /* TTPLUG */
-      cv->ComID = PCreateFile(ts->HostName,GENERIC_READ,0,NULL,
-                             OPEN_EXISTING,0,NULL);
-      InvalidHost = (cv->ComID == INVALID_HANDLE_VALUE);
-      if (InvalidHost)
-      {
-        if (cv->NoMsg==0)
-        {
-          get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
-          get_lang_msg("MSG_CANTOEPN_FILE_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot open file", ts->UILanguageFile);
-          MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
-        }
-      }
-      else {
-        cv->Open = TRUE;
-        PostMessage(cv->HWin, WM_USER_COMMOPEN, 0, 0);
-      }
-      break;
-  } /* end of "switch" */
-
 #ifndef NO_INET6
 BreakSC:
 #endif /* NO_INET6 */
-  if (InvalidHost)
-  {
-    PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
-    if ( (ts->PortType==IdTCPIP) && cv->Open )
-    {
-      if ( cv->s!=INVALID_SOCKET ) Pclosesocket(cv->s);
-      FreeWinsock();
-    }
-    return;
-  }
+	if (InvalidHost) {
+		PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
+		if ( (ts->PortType==IdTCPIP) && cv->Open ) {
+			if ( cv->s!=INVALID_SOCKET ) {
+				Pclosesocket(cv->s);
+			}
+			FreeWinsock();
+		}
+		return;
+	}
 }
 
 void CommThread(void *arg)
 {
-  DWORD Evt;
-  PComVar cv = (PComVar)arg;
-  DWORD DErr;
-  HANDLE REnd;
-  char Temp[20];
+	DWORD Evt;
+	PComVar cv = (PComVar)arg;
+	DWORD DErr;
+	HANDLE REnd;
+	char Temp[20];
 
-  _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort);
-  REnd = OpenEvent(EVENT_ALL_ACCESS,FALSE, Temp);
-  while (TRUE) {
-    if (WaitCommEvent(cv->ComID,&Evt,NULL))
-    {
-      if (! cv->Ready) _endthread();
-      if (! cv->RRQ)
-	PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_READ);
-      WaitForSingleObject(REnd,INFINITE);
-    }
-    else {
-      if (! cv->Ready) _endthread();
-      ClearCommError(cv->ComID,&DErr,NULL);
-    }
-  }
+	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort);
+	REnd = OpenEvent(EVENT_ALL_ACCESS,FALSE, Temp);
+	while (TRUE) {
+		if (WaitCommEvent(cv->ComID,&Evt,NULL)) {
+			if (! cv->Ready) {
+				_endthread();
+			}
+			if (! cv->RRQ) {
+				PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_READ);
+			}
+			WaitForSingleObject(REnd,INFINITE);
+		}
+		else {
+			if (! cv->Ready) {
+				_endthread();
+			}
+			ClearCommError(cv->ComID,&DErr,NULL);
+		}
+	}
 }
 
 void CommStart(PComVar cv, LONG lParam, PTTSet ts)
 {
-  char ErrMsg[31];
-  char Temp[20];
-  char uimsg[MAX_UIMSG];
+	char ErrMsg[31];
+	char Temp[20];
+	char uimsg[MAX_UIMSG];
 
-  if (! cv->Open ) return;
-  if ( cv->Ready ) return;
+	if (! cv->Open ) {
+		return;
+	}
+	if ( cv->Ready ) {
+		return;
+	}
 
-  // ƒLƒƒƒ“ƒZƒ‹ƒ^ƒCƒ}‚ª‚ ‚ê‚ÎŽæ‚èÁ‚·B‚½‚¾‚µA‚±‚ÌŽž“_‚Å WM_TIMER ‚ª‘—‚ç‚ê‚Ä‚¢‚é‰Â”\«‚Í‚ ‚éB
-  if (*cv->ConnetingTimeout > 0) {
-	KillTimer(cv->HWin, IdCancelConnectTimer);
-  }
+	// ƒLƒƒƒ“ƒZƒ‹ƒ^ƒCƒ}‚ª‚ ‚ê‚ÎŽæ‚èÁ‚·B‚½‚¾‚µA‚±‚ÌŽž“_‚Å WM_TIMER ‚ª‘—‚ç‚ê‚Ä‚¢‚é‰Â”\«‚Í‚ ‚éB
+	if (*cv->ConnetingTimeout > 0) {
+		KillTimer(cv->HWin, IdCancelConnectTimer);
+	}
 
-  switch (cv->PortType) {
-    case IdTCPIP:
-      ErrMsg[0] = 0;
-      switch (HIWORD(lParam)) {
-	case WSAECONNREFUSED:
-	  get_lang_msg("MSG_COMM_REFUSE_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Connection refused", ts->UILanguageFile);
-	  _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
-	  break;
-	case WSAENETUNREACH:
-	  get_lang_msg("MSG_COMM_REACH_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Network cannot be reached", ts->UILanguageFile);
-	  _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
-	  break;
-	case WSAETIMEDOUT:
-	  get_lang_msg("MSG_COMM_CONNECT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Connection timed out", ts->UILanguageFile);
-	  _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
-	  break;
-	default:
-	  get_lang_msg("MSG_COMM_TIMEOUT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot connect the host", ts->UILanguageFile);
-	  _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
-      }
-      if (HIWORD(lParam)>0)
-      {
+	switch (cv->PortType) {
+		case IdTCPIP:
+			ErrMsg[0] = 0;
+			switch (HIWORD(lParam)) {
+				case WSAECONNREFUSED:
+					get_lang_msg("MSG_COMM_REFUSE_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Connection refused", ts->UILanguageFile);
+					_snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
+					break;
+				case WSAENETUNREACH:
+					get_lang_msg("MSG_COMM_REACH_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Network cannot be reached", ts->UILanguageFile);
+					_snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
+					break;
+				case WSAETIMEDOUT:
+					get_lang_msg("MSG_COMM_CONNECT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Connection timed out", ts->UILanguageFile);
+					_snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
+					break;
+				default:
+					get_lang_msg("MSG_COMM_TIMEOUT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot connect the host", ts->UILanguageFile);
+					_snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
+			}
+			if (HIWORD(lParam)>0) {
 #ifndef NO_INET6
-	/* connect() failed */
-	if (cv->res->ai_next != NULL) {
-	  /* try to connect with other protocol */
-	  CloseSocket(cv->s);
-	  for (cv->res = cv->res->ai_next; cv->res; cv->res = cv->res->ai_next) {
-	    cv->s = OpenSocket(cv);
-	    if (cv->s == INVALID_SOCKET) {
-	      CloseSocket(cv->s);
-	      continue;
-	    }
-	    AsyncConnect(cv);
-	    cv->Ready = FALSE;
-	    cv->RetryWithOtherProtocol = TRUE; /* retry with other procotol */
-	    return;
-	  }
-	} else {
-	  /* trying with all protocol family are failed */
-	  if (cv->NoMsg==0)
-	  {
-	    get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
-	    MessageBox(cv->HWin,ErrMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
-	  }
-	  PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
-	  cv->RetryWithOtherProtocol = FALSE;
-	  return;
-	}
+				/* connect() failed */
+				if (cv->res->ai_next != NULL) {
+					/* try to connect with other protocol */
+					CloseSocket(cv->s);
+					for (cv->res = cv->res->ai_next; cv->res; cv->res = cv->res->ai_next) {
+						cv->s = OpenSocket(cv);
+						if (cv->s == INVALID_SOCKET) {
+							CloseSocket(cv->s);
+							continue;
+						}
+						AsyncConnect(cv);
+						cv->Ready = FALSE;
+						cv->RetryWithOtherProtocol = TRUE; /* retry with other procotol */
+						return;
+					}
+				} else {
+					/* trying with all protocol family are failed */
+					if (cv->NoMsg==0)
+					{
+						get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+						MessageBox(cv->HWin,ErrMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+					}
+					PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
+					cv->RetryWithOtherProtocol = FALSE;
+					return;
+				}
 #else
 	if (cv->NoMsg==0)
 	  MessageBox(cv->HWin,ErrMsg,ErrorCaption,
@@ -638,375 +644,407 @@
 	PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
 	return;
 #endif /* NO_INET6 */
-      }
+			}
 
 #ifndef NO_INET6
-      /* here is connection established */
-      cv->RetryWithOtherProtocol = FALSE;
+			/* here is connection established */
+			cv->RetryWithOtherProtocol = FALSE;
 #endif /* NO_INET6 */
-      PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMNOTIFY, FD_READ | FD_OOB | FD_CLOSE);
-      TCPIPClosed = FALSE;
-      break;
+			PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMNOTIFY, FD_READ | FD_OOB | FD_CLOSE);
+			TCPIPClosed = FALSE;
+			break;
 
-    case IdSerial:
-      _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort);
-      ReadEnd = CreateEvent(NULL,FALSE,FALSE,Temp);
-      _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", WRITENAME, cv->ComPort);
-      memset(&wol,0,sizeof(OVERLAPPED));
-      wol.hEvent = CreateEvent(NULL,TRUE,TRUE,Temp);
-      _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READNAME, cv->ComPort);
-      memset(&rol,0,sizeof(OVERLAPPED));
-      rol.hEvent = CreateEvent(NULL,TRUE,FALSE,Temp);
+		case IdSerial:
+			_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort);
+			ReadEnd = CreateEvent(NULL,FALSE,FALSE,Temp);
+			_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", WRITENAME, cv->ComPort);
+			memset(&wol,0,sizeof(OVERLAPPED));
+			wol.hEvent = CreateEvent(NULL,TRUE,TRUE,Temp);
+			_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READNAME, cv->ComPort);
+			memset(&rol,0,sizeof(OVERLAPPED));
+			rol.hEvent = CreateEvent(NULL,TRUE,FALSE,Temp);
 
-      /* create the receiver thread */
-      if (_beginthread(CommThread,0,cv) == -1)
-      {
-        get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
-        get_lang_msg("MSG_TT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Can't create thread", ts->UILanguageFile);
-        MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
-      }
-      break;
+			/* create the receiver thread */
+			if (_beginthread(CommThread,0,cv) == -1) {
+				get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);
+				get_lang_msg("MSG_TT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Can't create thread", ts->UILanguageFile);
+				MessageBox(cv->HWin,ts->UIMsg,uimsg,MB_TASKMODAL | MB_ICONEXCLAMATION);
+			}
+			break;
 
-    case IdFile:
-      cv->RRQ = TRUE;
-      break;
-  }
-  cv->Ready = TRUE;
+		case IdFile:
+			cv->RRQ = TRUE;
+			break;
+	}
+	cv->Ready = TRUE;
 }
 
 BOOL CommCanClose(PComVar cv)
 { // check if data remains in buffer
-  if (! cv->Open) return TRUE;
-  if (cv->InBuffCount>0) return FALSE;
-  if ((cv->HLogBuf!=NULL) &&
-      ((cv->LCount>0) ||
-       (cv->DCount>0))) return FALSE;
-  if ((cv->HBinBuf!=NULL) &&
-      (cv->BCount>0)) return FALSE;
-  return TRUE;
+	if (! cv->Open) {
+		return TRUE;
+	}
+	if (cv->InBuffCount>0) {
+		return FALSE;
+	}
+	if ((cv->HLogBuf!=NULL) &&
+	    ((cv->LCount>0) ||
+	     (cv->DCount>0))) {
+		return FALSE;
+	}
+	if ((cv->HBinBuf!=NULL) &&
+	    (cv->BCount>0)) {
+		return FALSE;
+	}
+	return TRUE;
 }
 
 void CommClose(PComVar cv)
 {
-  if ( ! cv->Open ) return;
-  cv->Open = FALSE;
+	if ( ! cv->Open ) {
+		return;
+	}
+	cv->Open = FALSE;
 
-  /* disable event message posting & flush buffer */
-  cv->RRQ = FALSE;
-  cv->Ready = FALSE;
-  cv->InPtr = 0;
-  cv->InBuffCount = 0;
-  cv->OutPtr = 0;
-  cv->OutBuffCount = 0;
+	/* disable event message posting & flush buffer */
+	cv->RRQ = FALSE;
+	cv->Ready = FALSE;
+	cv->InPtr = 0;
+	cv->InBuffCount = 0;
+	cv->OutPtr = 0;
+	cv->OutBuffCount = 0;
 
-  /* close port & release resources */
-  switch (cv->PortType) {
-    case IdTCPIP:
-      if (HAsync!=0)
-	PWSACancelAsyncRequest(HAsync);
-      HAsync = 0;
+	/* close port & release resources */
+	switch (cv->PortType) {
+		case IdTCPIP:
+			if (HAsync!=0) {
+				PWSACancelAsyncRequest(HAsync);
+			}
+			HAsync = 0;
 #ifndef NO_INET6
-      freeaddrinfo(cv->res0);
+			freeaddrinfo(cv->res0);
 #endif /* NO_INET6 */
-      if ( cv->s!=INVALID_SOCKET )
-	Pclosesocket(cv->s);
-      cv->s = INVALID_SOCKET;
-      TTXCloseTCP(); /* TTPLUG */
-      FreeWinsock();
-      break;
-    case IdSerial:
-      if ( cv->ComID != INVALID_HANDLE_VALUE )
-      {
-	CloseHandle(ReadEnd);
-	CloseHandle(wol.hEvent);
-	CloseHandle(rol.hEvent);
-	PurgeComm(cv->ComID,
-		  PURGE_TXABORT | PURGE_RXABORT |
-		  PURGE_TXCLEAR | PURGE_RXCLEAR);
-	EscapeCommFunction(cv->ComID,CLRDTR);
-	SetCommMask(cv->ComID,0);
-	PCloseFile(cv->ComID);
-	ClearCOMFlag(cv->ComPort);
-      }
-      TTXCloseFile(); /* TTPLUG */
-      break;
-    case IdFile:
-      if (cv->ComID != INVALID_HANDLE_VALUE)
-	PCloseFile(cv->ComID);
-      TTXCloseFile(); /* TTPLUG */
-      break;
-  }
-  cv->ComID = INVALID_HANDLE_VALUE;
-  cv->PortType = 0;
+			if ( cv->s!=INVALID_SOCKET ) {
+				Pclosesocket(cv->s);
+			}
+			cv->s = INVALID_SOCKET;
+			TTXCloseTCP(); /* TTPLUG */
+			FreeWinsock();
+			break;
+		case IdSerial:
+			if ( cv->ComID != INVALID_HANDLE_VALUE ) {
+				CloseHandle(ReadEnd);
+				CloseHandle(wol.hEvent);
+				CloseHandle(rol.hEvent);
+				PurgeComm(cv->ComID, PURGE_TXABORT | PURGE_RXABORT |
+				                     PURGE_TXCLEAR | PURGE_RXCLEAR);
+				EscapeCommFunction(cv->ComID,CLRDTR);
+				SetCommMask(cv->ComID,0);
+				PCloseFile(cv->ComID);
+				ClearCOMFlag(cv->ComPort);
+			}
+			TTXCloseFile(); /* TTPLUG */
+			break;
+		case IdFile:
+			if (cv->ComID != INVALID_HANDLE_VALUE) {
+				PCloseFile(cv->ComID);
+			}
+			TTXCloseFile(); /* TTPLUG */
+			break;
+	}
+	cv->ComID = INVALID_HANDLE_VALUE;
+	cv->PortType = 0;
 }
 
 void CommProcRRQ(PComVar cv)
 {
-  if ( ! cv->Ready ) return;
-  /* disable receive request */
-  switch (cv->PortType) {
-    case IdTCPIP:
-      if (! TCPIPClosed)
-	PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMNOTIFY, FD_OOB | FD_CLOSE);
-      break;
-    case IdSerial:
-      break;
-  }
-  cv->RRQ = TRUE;
-  CommReceive(cv);
+	if ( ! cv->Ready ) {
+		return;
+	}
+	/* disable receive request */
+	switch (cv->PortType) {
+		case IdTCPIP:
+			if (! TCPIPClosed) {
+				PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMNOTIFY, FD_OOB | FD_CLOSE);
+			}
+			break;
+		case IdSerial:
+			break;
+	}
+	cv->RRQ = TRUE;
+	CommReceive(cv);
 }
 
 void CommReceive(PComVar cv)
 {
-  DWORD C;
-  DWORD DErr;
+	DWORD C;
+	DWORD DErr;
 
-  if (! cv->Ready || ! cv->RRQ ||
-      (cv->InBuffCount>=InBuffSize)) return;
+	if (! cv->Ready || ! cv->RRQ ||
+	    (cv->InBuffCount>=InBuffSize)) {
+		return;
+	}
 
-  /* Compact buffer */
-  if ((cv->InBuffCount>0) && (cv->InPtr>0))
-  {
-    memmove(cv->InBuff,&(cv->InBuff[cv->InPtr]),cv->InBuffCount);
-    cv->InPtr = 0;
-  }
+	/* Compact buffer */
+	if ((cv->InBuffCount>0) && (cv->InPtr>0)) {
+		memmove(cv->InBuff,&(cv->InBuff[cv->InPtr]),cv->InBuffCount);
+		cv->InPtr = 0;
+	}
 
-  if (cv->InBuffCount<InBuffSize)
-  {
-    switch (cv->PortType) {
-      case IdTCPIP:
-	C = Precv(cv->s, &(cv->InBuff[cv->InBuffCount]),
-		 InBuffSize-cv->InBuffCount, 0);
-	if (C == SOCKET_ERROR)
-	{
-	  C = 0;
-	  PWSAGetLastError();
+	if (cv->InBuffCount<InBuffSize) {
+		switch (cv->PortType) {
+			case IdTCPIP:
+				C = Precv(cv->s, &(cv->InBuff[cv->InBuffCount]),
+				          InBuffSize-cv->InBuffCount, 0);
+				if (C == SOCKET_ERROR) {
+					C = 0;
+					PWSAGetLastError();
+				}
+				cv->InBuffCount = cv->InBuffCount + C;
+				break;
+			case IdSerial:
+				do {
+					ClearCommError(cv->ComID,&DErr,NULL);
+					if (! PReadFile(cv->ComID,&(cv->InBuff[cv->InBuffCount]),
+					                InBuffSize-cv->InBuffCount,&C,&rol)) {
+						if (GetLastError() == ERROR_IO_PENDING) {
+							if (WaitForSingleObject(rol.hEvent, 1000) != WAIT_OBJECT_0) {
+								C = 0;
+							}
+							else {
+								GetOverlappedResult(cv->ComID,&rol,&C,FALSE);
+							}
+						}
+						else {
+							C = 0;
+						}
+					}
+					cv->InBuffCount = cv->InBuffCount + C;
+				} while ((C!=0) && (cv->InBuffCount<InBuffSize));
+				ClearCommError(cv->ComID,&DErr,NULL);
+				break;
+			case IdFile:
+				if (PReadFile(cv->ComID,&(cv->InBuff[cv->InBuffCount]),
+				              InBuffSize-cv->InBuffCount,&C,NULL)) {
+					if (C == 0) {
+						DErr = ERROR_HANDLE_EOF;
+					}
+					else {
+						cv->InBuffCount = cv->InBuffCount + C;
+					}
+				}
+				else {
+					DErr = GetLastError();
+				}
+				break;
+		}
 	}
-	cv->InBuffCount = cv->InBuffCount + C;
-	break;
-      case IdSerial:
-	do {
-	  ClearCommError(cv->ComID,&DErr,NULL);
-	  if (! PReadFile(cv->ComID,&(cv->InBuff[cv->InBuffCount]),
-	    InBuffSize-cv->InBuffCount,&C,&rol))
-	  {
-	    if (GetLastError() == ERROR_IO_PENDING)
-	    {
-	      if (WaitForSingleObject(rol.hEvent, 1000) !=
-		  WAIT_OBJECT_0)
-		C = 0;
-	      else
-		GetOverlappedResult(cv->ComID,&rol,&C,FALSE);
-	    }
-	    else
-	      C = 0;
-	  }
-	  cv->InBuffCount = cv->InBuffCount + C;
-	} while ((C!=0) && (cv->InBuffCount<InBuffSize));
-	ClearCommError(cv->ComID,&DErr,NULL);
-	break;
-      case IdFile:
-	if (PReadFile(cv->ComID,&(cv->InBuff[cv->InBuffCount]),
-	  InBuffSize-cv->InBuffCount,&C,NULL))
-	{
-	  if (C == 0) {
-	    DErr = ERROR_HANDLE_EOF;
-	  }
-	  else {
-	    cv->InBuffCount = cv->InBuffCount + C;
-	  }
-	}
-	else {
-	  DErr = GetLastError();
-	}
-	break;
-    }
-  }
 
-  if (cv->InBuffCount==0) {
-    switch (cv->PortType) {
-      case IdTCPIP:
-	if (! TCPIPClosed)
-	  PWSAAsyncSelect(cv->s,cv->HWin,
-	    WM_USER_COMMNOTIFY, FD_READ | FD_OOB | FD_CLOSE);
-	break;
-      case IdSerial:
-	cv->RRQ = FALSE;
-	SetEvent(ReadEnd);
-	return;
-      case IdFile:
-	if (DErr != ERROR_IO_PENDING) {
-	  PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
-	  cv->RRQ = FALSE;
+	if (cv->InBuffCount==0) {
+		switch (cv->PortType) {
+			case IdTCPIP:
+				if (! TCPIPClosed) {
+					PWSAAsyncSelect(cv->s,cv->HWin, WM_USER_COMMNOTIFY,
+					                FD_READ | FD_OOB | FD_CLOSE);
+				}
+				break;
+			case IdSerial:
+				cv->RRQ = FALSE;
+				SetEvent(ReadEnd);
+				return;
+			case IdFile:
+				if (DErr != ERROR_IO_PENDING) {
+					PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
+					cv->RRQ = FALSE;
+				}
+				else {
+					cv->RRQ = TRUE;
+				}
+				return;
+		}
+		cv->RRQ = FALSE;
 	}
-	else {
-	  cv->RRQ = TRUE;
-	}
-	return;
-    }
-    cv->RRQ = FALSE;
-  }
 }
 
 void CommSend(PComVar cv)
 {
-  int delay;
-  COMSTAT Stat;
-  BYTE LineEnd;
-  int C, D, Max;
-  DWORD DErr;
+	int delay;
+	COMSTAT Stat;
+	BYTE LineEnd;
+	int C, D, Max;
+	DWORD DErr;
 
-  if ((! cv->Open) || (! cv->Ready))
-  {
-    cv->OutBuffCount = 0;  
-    return;
-  }
+	if ((! cv->Open) || (! cv->Ready)) {
+		cv->OutBuffCount = 0;  
+		return;
+	}
 
-  if ((cv->OutBuffCount == 0) || (! cv->CanSend)) return;
+	if ((cv->OutBuffCount == 0) || (! cv->CanSend)) {
+		return;
+	}
 
-  /* Max num of bytes to be written */
-  switch (cv->PortType) {
-    case IdTCPIP:
-      if (TCPIPClosed) cv->OutBuffCount = 0;
-      Max = cv->OutBuffCount;
-      break;
-    case IdSerial:
-      ClearCommError(cv->ComID,&DErr,&Stat);
-      Max = OutBuffSize - Stat.cbOutQue;
-      break;
-    case IdFile:
-      Max = cv->OutBuffCount;
-      break;
-  }
+	/* Max num of bytes to be written */
+	switch (cv->PortType) {
+		case IdTCPIP:
+			if (TCPIPClosed) {
+				cv->OutBuffCount = 0;
+			}
+			Max = cv->OutBuffCount;
+			break;
+		case IdSerial:
+			ClearCommError(cv->ComID,&DErr,&Stat);
+			Max = OutBuffSize - Stat.cbOutQue;
+			break;
+		case IdFile:
+			Max = cv->OutBuffCount;
+			break;
+	}
 
-  if ( Max<=0 ) return;
-  if ( Max > cv->OutBuffCount ) Max = cv->OutBuffCount;
+	if ( Max<=0 ) {
+		return;
+	}
+	if ( Max > cv->OutBuffCount ) {
+		Max = cv->OutBuffCount;
+	}
 
-  if (cv->PortType == IdTCPIP && cv->TelFlag) {
-    cv->LastSendTime = time(NULL);
-  }
+	if (cv->PortType == IdTCPIP && cv->TelFlag) {
+		cv->LastSendTime = time(NULL);
+	}
 
-  C = Max;
-  delay = 0;
+	C = Max;
+	delay = 0;
 
-  if ( cv->DelayFlag && (cv->PortType==IdSerial) )
-  {
-    if ( cv->DelayPerLine > 0 )
-    {
-      if ( cv->CRSend==IdCR ) LineEnd = 0x0d;
-			 else LineEnd = 0x0a;
-      C = 1;
-      if ( cv->DelayPerChar==0 )
-	while ((C<Max) && (cv->OutBuff[cv->OutPtr+C-1]!=LineEnd))
-	  C++;
-      if ( cv->OutBuff[cv->OutPtr+C-1]==LineEnd )
-	delay = cv->DelayPerLine;
-      else delay = cv->DelayPerChar;
-    }
-    else if ( cv->DelayPerChar > 0 )
-    {
-      C = 1;
-      delay = cv->DelayPerChar;
-    }
-  }
+	if ( cv->DelayFlag && (cv->PortType==IdSerial) ) {
+		if ( cv->DelayPerLine > 0 ) {
+			if ( cv->CRSend==IdCR ) {
+				LineEnd = 0x0d;
+			}
+			else {
+				LineEnd = 0x0a;
+			}
+			C = 1;
+			if ( cv->DelayPerChar==0 ) {
+				while ((C<Max) && (cv->OutBuff[cv->OutPtr+C-1]!=LineEnd)) {
+					C++;
+				}
+			}
+			if ( cv->OutBuff[cv->OutPtr+C-1]==LineEnd ) {
+				delay = cv->DelayPerLine;
+			}
+			else {
+				delay = cv->DelayPerChar;
+			}
+		}
+		else if ( cv->DelayPerChar > 0 ) {
+			C = 1;
+			delay = cv->DelayPerChar;
+		}
+	}
 
-  /* Write to comm driver/Winsock */
-  switch (cv->PortType) {
-    case IdTCPIP:
-      D = Psend(cv->s, &(cv->OutBuff[cv->OutPtr]), C, 0);
-      if ( D==SOCKET_ERROR ) /* if error occurs */
-      {
-	PWSAGetLastError(); /* Clear error */
-	D = 0;
-      }
-      break;
+	/* Write to comm driver/Winsock */
+	switch (cv->PortType) {
+		case IdTCPIP:
+			D = Psend(cv->s, &(cv->OutBuff[cv->OutPtr]), C, 0);
+			if ( D==SOCKET_ERROR ) { /* if error occurs */
+				PWSAGetLastError(); /* Clear error */
+				D = 0;
+			}
+			break;
 
-    case IdSerial:
-      if (! PWriteFile(cv->ComID,&(cv->OutBuff[cv->OutPtr]),C,(LPDWORD)&D,&wol))
-      {
-	if (GetLastError() == ERROR_IO_PENDING)
-	{
-	  if (WaitForSingleObject(wol.hEvent,1000) !=
-	      WAIT_OBJECT_0)
-	    D = C;	/* Time out, ignore data */
-	  else
-	    GetOverlappedResult(cv->ComID,&wol,(LPDWORD)&D,FALSE);
+		case IdSerial:
+			if (! PWriteFile(cv->ComID,&(cv->OutBuff[cv->OutPtr]),C,(LPDWORD)&D,&wol)) {
+				if (GetLastError() == ERROR_IO_PENDING) {
+					if (WaitForSingleObject(wol.hEvent,1000) != WAIT_OBJECT_0) {
+						D = C; /* Time out, ignore data */
+					}
+					else {
+						GetOverlappedResult(cv->ComID,&wol,(LPDWORD)&D,FALSE);
+					}
+				}
+				else { /* I/O error */
+					D = C; /* ignore error */
+				}
+			}
+			ClearCommError(cv->ComID,&DErr,&Stat);
+			break;
+
+		case IdFile:
+			if (! PWriteFile(cv->ComID, &(cv->OutBuff[cv->OutPtr]), C, (LPDWORD)&D, NULL)) {
+				if (! GetLastError() == ERROR_IO_PENDING) {
+					D = C; /* ignore data */
+				}
+			}
+			break;
 	}
-	else /* I/O error */
-	  D = C; /* ignore error */
-      }
-      ClearCommError(cv->ComID,&DErr,&Stat);
-      break;
 
-    case IdFile:
-      if (! PWriteFile(cv->ComID, &(cv->OutBuff[cv->OutPtr]), C, (LPDWORD)&D, NULL)) {
-        if (! GetLastError() == ERROR_IO_PENDING) {
-          D = C; /* ignore data */
-        }
-      }
-      break;
-  }
+	cv->OutBuffCount = cv->OutBuffCount - D;
+	if ( cv->OutBuffCount==0 ) {
+		cv->OutPtr = 0;
+	}
+	else {
+		cv->OutPtr = cv->OutPtr + D;
+	}
 
-  cv->OutBuffCount = cv->OutBuffCount - D;
-  if ( cv->OutBuffCount==0 )
-    cv->OutPtr = 0;
-  else
-    cv->OutPtr = cv->OutPtr + D;
-
-  if ( (C==D) && (delay>0) )
-  {
-    cv->CanSend = FALSE;
-    SetTimer(cv->HWin, IdDelayTimer, delay, NULL);
-  }
+	if ( (C==D) && (delay>0) ) {
+		cv->CanSend = FALSE;
+		SetTimer(cv->HWin, IdDelayTimer, delay, NULL);
+	}
 }
 
 void CommSendBreak(PComVar cv)
 /* for only serial ports */
 {
-  MSG DummyMsg;
+	MSG DummyMsg;
 
-  if ( ! cv->Ready ) return;
+	if ( ! cv->Ready ) {
+		return;
+	}
 
-  switch (cv->PortType) {
-    case IdSerial:
-      /* Set com port into a break state */
-      SetCommBreak(cv->ComID);
+	switch (cv->PortType) {
+		case IdSerial:
+			/* Set com port into a break state */
+			SetCommBreak(cv->ComID);
 
-      /* pause for 1 sec */
-      if (SetTimer(cv->HWin, IdBreakTimer, 1000, NULL) != 0)
-	GetMessage(&DummyMsg,cv->HWin,WM_TIMER,WM_TIMER);
+			/* pause for 1 sec */
+			if (SetTimer(cv->HWin, IdBreakTimer, 1000, NULL) != 0) {
+				GetMessage(&DummyMsg,cv->HWin,WM_TIMER,WM_TIMER);
+			}
 
-      /* Set com port into the nonbreak state */
-      ClearCommBreak(cv->ComID);
-      break;
-  }
+			/* Set com port into the nonbreak state */
+			ClearCommBreak(cv->ComID);
+			break;
+	}
 }
 
 void CommLock(PTTSet ts, PComVar cv, BOOL Lock)
 {
-  BYTE b;
-  DWORD Func;
+	BYTE b;
+	DWORD Func;
 
-  if (! cv->Ready) return;
-  if ((cv->PortType==IdTCPIP) ||
-      (cv->PortType==IdSerial) &&
-      (ts->Flow!=IdFlowHard))
-  {
-    if (Lock)
-      b = XOFF;
-    else
-      b = XON;
-    CommBinaryOut(cv,&b,1);
-  }
-  else if ((cv->PortType==IdSerial) &&
-	   (ts->Flow==IdFlowHard))
-  {
-    if (Lock)
-      Func = CLRRTS;
-    else
-      Func = SETRTS;
-    EscapeCommFunction(cv->ComID,Func);
-  }
+	if (! cv->Ready) {
+		return;
+	}
+	if ((cv->PortType==IdTCPIP) ||
+	    (cv->PortType==IdSerial) &&
+	    (ts->Flow!=IdFlowHard)) {
+		if (Lock) {
+			b = XOFF;
+		}
+		else {
+			b = XON;
+		}
+		CommBinaryOut(cv,&b,1);
+	}
+	else if ((cv->PortType==IdSerial) &&
+	         (ts->Flow==IdFlowHard)) {
+		if (Lock) {
+			Func = CLRRTS;
+		}
+		else {
+			Func = SETRTS;
+		}
+		EscapeCommFunction(cv->ComID,Func);
+	}
 }
 
 int GetCommSerialBaudRate(int id)
@@ -1022,74 +1060,79 @@
 
 BOOL PrnOpen(PCHAR DevName)
 {
-  char Temp[MAXPATHLEN];
-  DCB dcb;
-  DWORD DErr;
-  COMMTIMEOUTS ctmo;
+	char Temp[MAXPATHLEN];
+	DCB dcb;
+	DWORD DErr;
+	COMMTIMEOUTS ctmo;
 
-  strncpy_s(Temp, sizeof(Temp),DevName, _TRUNCATE);
-  Temp[4] = 0; // COMn or LPTn
-  LPTFlag = (Temp[0]=='L') ||
-	    (Temp[0]=='l');
-  PrnID =
-    CreateFile(Temp,GENERIC_WRITE,
-	       0,NULL,OPEN_EXISTING,
-	       0,NULL);
-  if (PrnID == INVALID_HANDLE_VALUE) return FALSE;
+	strncpy_s(Temp, sizeof(Temp),DevName, _TRUNCATE);
+	Temp[4] = 0; // COMn or LPTn
+	LPTFlag = (Temp[0]=='L') ||
+	          (Temp[0]=='l');
+	PrnID = CreateFile(Temp,GENERIC_WRITE,
+	                   0,NULL,OPEN_EXISTING,
+	                   0,NULL);
+	if (PrnID == INVALID_HANDLE_VALUE) {
+		return FALSE;
+	}
 
-  if (GetCommState(PrnID,&dcb))
-  {
-    BuildCommDCB(DevName,&dcb);
-    SetCommState(PrnID,&dcb);
-  }
-  ClearCommError(PrnID,&DErr,NULL);
-  if (! LPTFlag)
-    SetupComm(PrnID,0,CommOutQueSize);
-  /* flush output buffer */
-  PurgeComm(PrnID, PURGE_TXABORT |
-    PURGE_TXCLEAR);
-  memset(&ctmo,0,sizeof(ctmo));
-  ctmo.WriteTotalTimeoutConstant = 1000;
-  SetCommTimeouts(PrnID,&ctmo);
-  if (! LPTFlag)
-    EscapeCommFunction(PrnID,SETDTR);
-  return TRUE;
+	if (GetCommState(PrnID,&dcb)) {
+		BuildCommDCB(DevName,&dcb);
+		SetCommState(PrnID,&dcb);
+	}
+	ClearCommError(PrnID,&DErr,NULL);
+	if (! LPTFlag) {
+		SetupComm(PrnID,0,CommOutQueSize);
+	}
+	/* flush output buffer */
+	PurgeComm(PrnID, PURGE_TXABORT | PURGE_TXCLEAR);
+	memset(&ctmo,0,sizeof(ctmo));
+	ctmo.WriteTotalTimeoutConstant = 1000;
+	SetCommTimeouts(PrnID,&ctmo);
+	if (! LPTFlag) {
+		EscapeCommFunction(PrnID,SETDTR);
+	}
+	return TRUE;
 }
 
 int PrnWrite(PCHAR b, int c)
 {
-  int d;
-  DWORD DErr;
-  COMSTAT Stat;
+	int d;
+	DWORD DErr;
+	COMSTAT Stat;
 
-  if (PrnID == INVALID_HANDLE_VALUE )
-    return c;
+	if (PrnID == INVALID_HANDLE_VALUE ) {
+		return c;
+	}
 
-  ClearCommError(PrnID,&DErr,&Stat);
-  if (! LPTFlag &&
-      (OutBuffSize - (int)Stat.cbOutQue < c))
-    c = OutBuffSize - Stat.cbOutQue;
-  if (c<=0) return 0;
-  if (! WriteFile(PrnID,b,c,(LPDWORD)&d,NULL))
-    d = 0;
-  ClearCommError(PrnID,&DErr,NULL);
-  return d;
+	ClearCommError(PrnID,&DErr,&Stat);
+	if (! LPTFlag &&
+		(OutBuffSize - (int)Stat.cbOutQue < c)) {
+		c = OutBuffSize - Stat.cbOutQue;
+	}
+	if (c<=0) {
+		return 0;
+	}
+	if (! WriteFile(PrnID,b,c,(LPDWORD)&d,NULL)) {
+		d = 0;
+	}
+	ClearCommError(PrnID,&DErr,NULL);
+	return d;
 }
 
 void PrnCancel()
 {
-  PurgeComm(PrnID,
-    PURGE_TXABORT | PURGE_TXCLEAR);
-  PrnClose();
+	PurgeComm(PrnID, PURGE_TXABORT | PURGE_TXCLEAR);
+	PrnClose();
 }
 
 void PrnClose()
 {
-  if (PrnID != INVALID_HANDLE_VALUE)
-  {
-    if (!LPTFlag)
-      EscapeCommFunction(PrnID,CLRDTR);
-    CloseHandle(PrnID);
-  }
-  PrnID = INVALID_HANDLE_VALUE;
+	if (PrnID != INVALID_HANDLE_VALUE) {
+		if (!LPTFlag) {
+			EscapeCommFunction(PrnID,CLRDTR);
+		}
+		CloseHandle(PrnID);
+	}
+	PrnID = INVALID_HANDLE_VALUE;
 }

Modified: trunk/teraterm/teraterm/ttdialog.c
===================================================================
--- trunk/teraterm/teraterm/ttdialog.c	2009-05-12 11:55:27 UTC (rev 3392)
+++ trunk/teraterm/teraterm/ttdialog.c	2009-05-12 14:26:30 UTC (rev 3393)
@@ -39,85 +39,108 @@
 
 BOOL LoadTTDLG()
 {
-  BOOL Err;
+	BOOL Err;
 
-  if (HTTDLG == NULL)
-  {
-    TTDLGUseCount = 0;
+	if (HTTDLG == NULL) {
+		TTDLGUseCount = 0;
 
-    HTTDLG = LoadLibrary("TTPDLG.DLL");
-    if (HTTDLG==NULL) return FALSE;
+		HTTDLG = LoadLibrary("TTPDLG.DLL");
+		if (HTTDLG==NULL) return FALSE;
 
-    TTDLGSetUILanguageFile(ts.UILanguageFile);
+		TTDLGSetUILanguageFile(ts.UILanguageFile);
 
-    Err = FALSE;
-    SetupTerminal = (PSetupTerminal)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdSetupTerminal));
-    if (SetupTerminal==NULL) Err = TRUE;
+		Err = FALSE;
+		SetupTerminal = (PSetupTerminal)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdSetupTerminal));
+		if (SetupTerminal==NULL) {
+			Err = TRUE;
+		}
 
-    SetupWin = (PSetupWin)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdSetupWin));
-    if (SetupWin==NULL) Err = TRUE;
+		SetupWin = (PSetupWin)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdSetupWin));
+		if (SetupWin==NULL) {
+			Err = TRUE;
+		}
 
-    SetupKeyboard = (PSetupKeyboard)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdSetupKeyboard));
-    if (SetupKeyboard==NULL) Err = TRUE;
+		SetupKeyboard = (PSetupKeyboard)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdSetupKeyboard));
+		if (SetupKeyboard==NULL) {
+			Err = TRUE;
+		}
 
-    SetupSerialPort = (PSetupSerialPort)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdSetupSerialPort));
-    if (SetupSerialPort==NULL) Err = TRUE;
+		SetupSerialPort = (PSetupSerialPort)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdSetupSerialPort));
+		if (SetupSerialPort==NULL) {
+			Err = TRUE;
+		}
 
-    SetupTCPIP = (PSetupTCPIP)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdSetupTCPIP));
-    if (SetupTCPIP==NULL) Err = TRUE;
+		SetupTCPIP = (PSetupTCPIP)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdSetupTCPIP));
+		if (SetupTCPIP==NULL) {
+			Err = TRUE;
+		}
 
-    GetHostName = (PGetHostName)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdGetHostName));
-    if (GetHostName==NULL) Err = TRUE;
+		GetHostName = (PGetHostName)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdGetHostName));
+		if (GetHostName==NULL) {
+			Err = TRUE;
+		}
 
-    ChangeDirectory = (PChangeDirectory)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdChangeDirectory));
-    if (ChangeDirectory==NULL) Err = TRUE;
+		ChangeDirectory = (PChangeDirectory)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdChangeDirectory));
+		if (ChangeDirectory==NULL) {
+			Err = TRUE;
+		}
 
-    AboutDialog = (PAboutDialog)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdAboutDialog));
-    if (AboutDialog==NULL) Err = TRUE;
+		AboutDialog = (PAboutDialog)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdAboutDialog));
+		if (AboutDialog==NULL) {
+			Err = TRUE;
+		}
 
-    ChooseFontDlg = (PChooseFontDlg)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdChooseFontDlg));
-    if (ChooseFontDlg==NULL) Err = TRUE;
+		ChooseFontDlg = (PChooseFontDlg)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdChooseFontDlg));
+		if (ChooseFontDlg==NULL) {
+			Err = TRUE;
+		}
 
-    SetupGeneral = (PSetupGeneral)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdSetupGeneral));
-    if (SetupGeneral==NULL) Err = TRUE;
+		SetupGeneral = (PSetupGeneral)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdSetupGeneral));
+		if (SetupGeneral==NULL) {
+			Err = TRUE;
+		}
 
-    WindowWindow = (PWindowWindow)GetProcAddress(HTTDLG,
-      MAKEINTRESOURCE(IdWindowWindow));
-    if (WindowWindow==NULL) Err = TRUE;
+		WindowWindow = (PWindowWindow)GetProcAddress(HTTDLG,
+		  MAKEINTRESOURCE(IdWindowWindow));
+		if (WindowWindow==NULL) {
+			Err = TRUE;
+		}
 
-    if (Err)
-    {
-      FreeLibrary(HTTDLG);
-      HTTDLG = NULL;
-      return FALSE;
-    }
+		if (Err) {
+			FreeLibrary(HTTDLG);
+			HTTDLG = NULL;
+			return FALSE;
+		}
 
-    TTXGetUIHooks(); /* TTPLUG */
-  }
-  TTDLGUseCount++;
-  return TRUE;
+		TTXGetUIHooks(); /* TTPLUG */
+	}
+	TTDLGUseCount++;
+	return TRUE;
 }
 
 BOOL FreeTTDLG()
 {
-  if (TTDLGUseCount==0) return FALSE; 
- TTDLGUseCount--;
-  if (TTDLGUseCount>0) return TRUE;
-  if (HTTDLG!=NULL)
-  {
-    FreeLibrary(HTTDLG);
-    HTTDLG = NULL;
-  }
-  return FALSE;
+	if (TTDLGUseCount==0) {
+		return FALSE; 
+	}
+	TTDLGUseCount--;
+	if (TTDLGUseCount>0) {
+		return TRUE;
+	}
+	if (HTTDLG!=NULL) {
+		FreeLibrary(HTTDLG);
+		HTTDLG = NULL;
+	}
+	return FALSE;
 }
 

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2009-05-12 11:55:27 UTC (rev 3392)
+++ trunk/teraterm/teraterm/vtwin.cpp	2009-05-12 14:26:30 UTC (rev 3393)
@@ -1454,8 +1454,9 @@
 /* called by the [Setup] Terminal command */
 void CVTWindow::SetupTerm()
 {
-	if (ts.Language==IdJapanese || ts.Language==IdKorean)
+	if (ts.Language==IdJapanese || ts.Language==IdKorean) {
 		ResetCharSet();
+	}
 	cv.CRSend = ts.CRSend;
 
 	// for russian mode
@@ -1636,7 +1637,7 @@
 	Code = nChar;
 
 	if ((ts.Language==IdRussian) &&
-		((BYTE)Code>=128)) {
+	    ((BYTE)Code>=128)) {
 		Code = (char)RussConv(ts.RussKeyb,ts.RussClient,(BYTE)Code);
 	}
 



Ttssh2-commit メーリングリストの案内
Back to archive index