/* * CheckCurrentColumn - check state of current column, return true if need to * redisplay page */ bool CheckCurrentColumn( void ) { int clen, vcp; bool dispall = false; clen = VirtualLineLen( CurrentLine->data ); if( clen == 0 ) { clen = 1; } ValidateCurrentColumn(); vcp = VirtualColumnOnCurrentLine( CurrentPos.column ); if( vcp != VirtualColumnDesired ) { if( clen >= VirtualColumnDesired ) { CurrentPos.column = RealColumnOnCurrentLine( VirtualColumnDesired ); } else { if( EditFlags.InsertModeActive || EditFlags.Modeless ) { CurrentPos.column = CurrentLine->len + 1; } else { CurrentPos.column = CurrentLine->len; } } ValidateCurrentColumn(); dispall = !CheckLeftColumn(); /* changed CurrentPos.column - update horiz scrollbar */ PositionHorizontalScrollThumb( current_window_id, LeftTopPos.column ); } VarAddGlobalLong( "C", (long) CurrentPos.column ); return( dispall ); } /* CheckCurrentColumn */
/* * trimWorkLine - remove trailing whitespace from work line */ static int trimWorkLine( void ) { int i, len; len = 0; if( EditFlags.CMode || EditFlags.RemoveSpaceTrailing ) { i = WorkLine->len - 1; while( i >= 0 && WHITE_SPACE( WorkLine->data[i] ) ) { i--; } if( i == -1 ) { len = VirtualLineLen( WorkLine->data ); } WorkLine->len = i + 1; WorkLine->data[i + 1] = 0; } return( len ); } /* trimWorkLine */
/* * IMTabs - handle tabs in insert mode */ vi_rc IMTabs( void ) { char *buff; bool back; int cp, vc, tc, add; int i, j; int len; startNewLineUndo(); CheckAbbrev( abbrevBuff, &abbrevCnt ); abbrevCnt = 0; switch( LastEvent ) { case VI_KEY( TAB ): if( EditFlags.RealTabs ) { if( WorkLine->len + 1 >= EditVars.MaxLine ) { break; } addChar( '\t' ); GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 ); checkWrapMargin(); break; } /* fall through if not real tabs */ case VI_KEY( CTRL_T ): case VI_KEY( SHIFT_TAB ): case VI_KEY( CTRL_D ): /* * get position of cursor on virtual line */ vc = VirtualColumnOnCurrentLine( CurrentPos.column ); if( CurrentPos.column - 1 == WorkLine->len && !EditFlags.Modeless ) { add = 1; } else { add = 0; } j = 0; back = FALSE; switch( LastEvent ) { case VI_KEY( SHIFT_TAB ): j = ShiftTab( vc, EditVars.TabAmount ); back = TRUE; break; case VI_KEY( CTRL_D ): j = ShiftTab( vc, EditVars.ShiftWidth ); back = TRUE; break; case VI_KEY( TAB ): j = Tab( vc, EditVars.TabAmount ); break; case VI_KEY( CTRL_T ): j = Tab( vc, EditVars.ShiftWidth ); break; } if( back && (vc - j < 1) ) { break; } else if( VirtualLineLen( WorkLine->data ) + j >= EditVars.MaxLine ) { break; } /* * create a real version of the line */ buff = StaticAlloc(); ExpandTabsInABufferUpToColumn( CurrentPos.column - 1, WorkLine->data, WorkLine->len, buff, EditVars.MaxLine ); len = strlen( buff ); /* * put in/suck out the tab */ tc = vc - 1; if( back ) { for( i = tc; i <= len + 1; i++ ) { buff[i - j] = buff[i]; } len -= j; } else { for( i = len; i >= tc; i-- ) { buff[i + j] = buff[i]; } for( i = 0; i < j; i++ ) { buff[tc + i] = ' '; } len += j; } /* * put tabs back in */ if( back ) { cp = vc - j; } else { cp = vc + j; } if( EditFlags.RealTabs ) { ConvertSpacesToTabsUpToColumn( cp, buff, len, WorkLine->data, EditVars.MaxLine ); } else { strcpy( WorkLine->data, buff ); } WorkLine->len = strlen( WorkLine->data ); StaticFree( buff ); cp = RealColumnOnCurrentLine( cp ) + add; GoToColumn( cp, WorkLine->len + 1 ); DisplayWorkLine( FALSE ); break; } return( ERR_NO_ERR ); } /* IMTabs */
/* * RegSub - perform substitutions after a regexp match */ int RegSub( regexp *prog, char *source, char *dest, linenum lineno ) { char *src, *dst, c; int no, len, splitit = FALSE; bool upper_flag = FALSE, lower_flag = FALSE, perm_flag = FALSE; char *tmp; char buff[MAX_STR]; int i, j; linenum ll; tmp = StaticAlloc(); src = source; dst = dest; while( (c = *src++) != '\0' ) { if( c == '&' ) { no = 0; } else if( c == '\\' && '0' <= *src && *src <= '9' ) { no = *src++ - '0'; } else { no = -1; } /* * do we have a normal character? */ if( no < 0 ) { /* * is this an escaped character? */ if( c == '\\' && EditFlags.RegSubMagic ) { switch( *src ) { case '|': src++; if( !isdigit( *src ) ) { break; } i = 0; while( isdigit( *src ) ) { buff[i++] = *src++; } buff[i] = 0; j = atoi( buff ) - 1; *dst = 0; i = VirtualLineLen( dest ); while( i < j ) { *dst++ = ' '; i++; } break; case '#': src++; CFindLastLine( &ll ); sprintf( buff, "%ld", ll ); i = strlen( buff ); sprintf( buff, "%ld", lineno ); Lead( '0', i, buff ); for( j = 0; j < i; j++ ) { *dst++ = buff[j]; } break; case 't': src++; if( EditFlags.RealTabs ) { *dst++ = '\t'; } else { *dst++ = 't'; } break; case 'n': src++; if( EditFlags.AllowRegSubNewline ) { *dst++ = SPLIT_CHAR; splitit = TRUE; } else { *dst++ = 'n'; } break; case '\\': case '&': c = *src++; *dst++ = c; break; case 'u': src++; upper_flag = TRUE; perm_flag = FALSE; break; case 'l': src++; lower_flag = TRUE; perm_flag = FALSE; break; case 'L': src++; lower_flag = TRUE; perm_flag = TRUE; break; case 'U': src++; upper_flag = TRUE; perm_flag = TRUE; break; case 'e': case 'E': src++; upper_flag = lower_flag = perm_flag = FALSE; break; default: *dst++ = '\\'; break; } /* * not escaped, so just copy it in */ } else { if( upper_flag ) { c = toupper( c ); if( !perm_flag ) { upper_flag = FALSE; } } else if( lower_flag ) { c = tolower( c ); if( !perm_flag ) { lower_flag = FALSE; } } *dst++ = c; } /* * copy in a sub expression */ } else if( prog->startp[no] != NULL && prog->endp[no] != NULL ) { len = prog->endp[no] - prog->startp[no]; if( upper_flag ) { strcpy( tmp, prog->startp[no] ); strncpy( dst, strupr( tmp ), len ); if( !perm_flag ) { upper_flag = FALSE; } } else if( lower_flag ) { strcpy( tmp, prog->startp[no] ); strncpy( dst, strlwr( tmp ), len ); if( !perm_flag ) { lower_flag = FALSE; } } else { strncpy( dst, prog->startp[no], len ); } dst += len; } } *dst++ = 0; StaticFree( tmp ); return( splitit ); } /* RegSub */
vi_rc DCUpdate( void ) { vi_rc rc; int i, nlines; fcb *fcb; line *line; dc dc; bool firstLine, firstTilde; linenum line_no; int displayOffset; char *displayText; #ifdef __WIN__ HDC hdc_wnd; #ifdef BITBLT_BUFFER_DISPLAY HDC hdc_mem; HBITMAP hbitmap; type_style *ws; #endif #else bool hasMouse; unsigned int hdc_wnd = 0; #endif if( EditFlags.Quiet || CurrentInfo == NULL ) { return( ERR_NO_ERR ); } #ifdef __WIN__ MyHideCaret( CurrentWindow ); hdc_wnd = GetDC( CurrentWindow ); #ifdef BITBLT_BUFFER_DISPLAY hdc_mem = CreateCompatibleDC( hdc_wnd ); ws = &(SEType[SE_WHITESPACE]); hbitmap = CreateCompatibleBitmap( hdc_wnd, WindowAuxInfo( CurrentWindow, WIND_INFO_WIDTH ), FontHeight( ws->font ) ); SelectObject( hdc_mem, hbitmap ); SelectObject( hdc_mem, ColorBrush( ws->background ) ); #endif #else hasMouse = DisplayMouse( false ); #endif rc = CGimmeLinePtr( LeftTopPos.line, &fcb, &line ); if( rc != ERR_NO_ERR ) { return( rc ); } nlines = CurrentInfo->dc_size; dc = CurrentInfo->dc; firstLine = true; firstTilde = true; for( i = 0, line_no = LeftTopPos.line; i < nlines; i++, line_no++ ) { if( dc->display ) { if( line ) { if( firstLine ) { if( dc->valid ) { // major speedup SSInitLanguageFlagsGivenValues( &(dc->flags) ); } else { SSInitLanguageFlags( line_no ); } firstLine = false; } displayText = line->data; if( line->u.ld.nolinedata ) { if( WorkLine->len >= 0 ) { displayText = WorkLine->data; } else { displayText = "*** ERR NULL DATA ***"; } } displayOffset = VirtualLineLen( displayText ); if( displayOffset > LeftTopPos.column ) { displayOffset = LeftTopPos.column; } } else { if( EditFlags.DrawTildes ) { displayText = "~"; } else { displayText = ""; if( firstTilde ) { displayText = EditVars.FileEndString; firstTilde = false; } } displayOffset = 0; } #ifdef BITBLT_BUFFER_DISPLAY DisplayLineInWindowWithSyntaxStyle( CurrentWindow, i + 1, line, line_no, displayText, displayOffset, hdc_wnd, hdc_mem ); #else DisplayLineInWindowWithSyntaxStyle( CurrentWindow, i + 1, line, line_no, displayText, displayOffset, hdc_wnd ); #endif dc->display = false; } else { // just in case displaying 2+ blocks in one update firstLine = true; } if( line ) { rc = CGimmeNextLinePtr( &fcb, &line ); } if( rc != ERR_NO_ERR && rc != ERR_NO_MORE_LINES ) { return( rc ); } dc++; } #ifdef __WIN__ #ifdef BITBLT_BUFFER_DISPLAY DeleteDC( hdc_mem ); DeleteObject( hbitmap ); #endif ReleaseDC( CurrentWindow, hdc_wnd ); MyShowCaret( CurrentWindow ); #else DisplayMouse( hasMouse ); #endif return( ERR_NO_ERR ); }