/* * SplitUpLine - split up a line with SPLIT_CHAR's in them */ linenum SplitUpLine( linenum cl ) { linenum extra = 0; int j, i, k; char *buff; /* * run through, and for every 0x01, make a new line */ for( ;; ) { /* * get current line */ CurrentPos.line = cl + extra; CGimmeLinePtr( CurrentPos.line, &CurrentFcb, &CurrentLine ); GetCurrentLine(); for( i = 0; i <= WorkLine->len; i++ ) { /* * found a place to split. make this line shorter, * and create a new line with the rest of the data * for this line */ if( WorkLine->data[i] == SPLIT_CHAR ) { buff = StaticAlloc(); k = 0; for( j = i + 1; j <= WorkLine->len; j++ ) { buff[k++] = WorkLine->data[j]; } WorkLine->data[i] = 0; WorkLine->len = i; ReplaceCurrentLine(); AddNewLineAroundCurrent( buff, k - 1, INSERT_AFTER ); extra++; StaticFree( buff ); break; } /* * at the very end, undo what we did and go back */ if( WorkLine->data[i] == 0 ) { ReplaceCurrentLine(); UndoInsert( cl + 1, cl + extra, UndoStack ); return( extra ); } } } } /* SplitUpLine */
/* * EnterHexKey - enter a hexidecimal key stroke and insert it into the text */ vi_rc EnterHexKey( void ) { int i; char st[MAX_STR], val; vi_rc rc; const char *ptr; rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } if( CurrentLine->len >= EditVars.MaxLine - 1 ) { return( ERR_LINE_FULL ); } rc = PromptForString( "Enter the number of char to insert:", st, sizeof( st ) - 1, NULL ); if( rc != ERR_NO_ERR ) { if( rc == NO_VALUE_ENTERED ) { return( ERR_NO_ERR ); } return( rc ); } /* * get value */ ptr = SkipLeadingSpaces( st ); val = (char)strtol( ptr, NULL, 0 ); if( val == '\0' ) { return( ERR_INVALID_VALUE ); } /* * build undo record */ StartUndoGroup( UndoStack ); CurrentLineReplaceUndoStart(); CurrentLineReplaceUndoEnd( true ); EndUndoGroup( UndoStack ); /* * add the char */ GetCurrentLine(); for( i = WorkLine->len; i >= CurrentPos.column - 1; i-- ) { WorkLine->data[i + 1] = WorkLine->data[i]; } WorkLine->data[CurrentPos.column - 1] = val; WorkLine->len++; DisplayWorkLine( true ); if( CurrentPos.column < WorkLine->len ) { GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 ); } ReplaceCurrentLine(); EditFlags.Dotable = true; return( ERR_NO_ERR ); } /* EnterHexKey */
/* * doneWithCurrentLine - update current line, and update undo record */ static void doneWithCurrentLine( void ) { startNewLineUndo(); ReplaceCurrentLine(); if( currLineRepUndo ) { ConditionalCurrentLineReplaceUndoEnd(); currLineRepUndo = FALSE; } else { EndUndoGroup( UndoStack ); } } /* doneWithCurrentLine */
/* * DeleteAndInsertText - delete text range, then insert at beginning */ vi_rc DeleteAndInsertText( int scol, int ecol ) { int startcol; vi_rc rc; StartUndoGroup( UndoStack ); CurrentLineReplaceUndoStart(); currLineRepUndo = TRUE; if( ecol >= 0 ) { if( CurrentLine->len > 0 ) { rc = DeleteBlockFromCurrentLine( scol, ecol, FALSE ); if( rc == ERR_NO_ERR ) { startcol = CurrentPos.column; if( scol > ecol ) { startcol = ecol + 1; } if( startcol > WorkLine->len ) { startcol = WorkLine->len + 1; } DisplayWorkLine( TRUE ); ReplaceCurrentLine(); rc = GoToColumnOK( startcol ); } if( rc != ERR_NO_ERR ) { CurrentLineReplaceUndoCancel(); EndUndoGroup( UndoStack ); return( rc ); } } else { ReplaceCurrentLine(); } } continueInsertText( CurrentPos.column, FALSE ); return( ERR_NO_ERR ); } /* DeleteAndInsertText */
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT wMessage, WPARAM wParam, LPARAM lParam) { switch (wMessage) { case WM_GETDLGCODE: return DLGC_WANTALLKEYS; case WM_KEYDOWN: if (wParam == VK_UP) { ReplaceCurrentLine(hwnd, GetExpressionFromPrevLocation()); return TRUE; } if (wParam == VK_DOWN) { ReplaceCurrentLine(hwnd, GetExpressionFromNextLocation()); return TRUE; } break; case WM_CHAR: if (wParam == VK_RETURN) { ProcessTextChange(hwnd); } break; } return CallWindowProc(wpOrigEditProc, hwnd, wMessage, wParam, lParam); }
/* * DeleteRangeOnCurrentLine - perform the deletion */ vi_rc DeleteRangeOnCurrentLine( int scol, int ecol, int savebuf_flag ) { int i; vi_rc rc; /* * verify range */ if( scol > ecol ) { i = scol; scol = ecol; ecol = i; } /* * go delete block and set up undo */ CurrentLineReplaceUndoStart(); rc = DeleteBlockFromCurrentLine( scol, ecol, savebuf_flag ); if( rc != ERR_NO_ERR ) { CurrentLineReplaceUndoCancel(); return( rc ); } DisplayWorkLine( TRUE ); ReplaceCurrentLine(); CurrentLineReplaceUndoEnd( TRUE ); EditFlags.Dotable = TRUE; if( savebuf_flag ) { #ifdef __WIN__ if( LastSavebuf == 0 ) { Message1( "%d characters deleted into the clipboard", ecol - scol + 1 ); } else { #endif Message1( "%d %s%s%c", ecol - scol + 1, MSG_CHARACTERS, MSG_DELETEDINTOBUFFER, LastSavebuf ); #ifdef __WIN__ } #endif } return( ERR_NO_ERR ); } /* DeleteRangeOnCurrentLine */
/* * IMCloseBracket - handle a ')' being entered in insert mode */ vi_rc IMCloseBracket( void ) { vi_rc rc; i_mark pos; startNewLineUndo(); insertChar( TRUE, FALSE ); if( EditFlags.ShowMatch ) { ReplaceCurrentLine(); rc = FindMatch( &pos ); if( rc == ERR_NO_ERR ) { tempMatch( &pos ); } GetCurrentLine(); } GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 ); return( ERR_NO_ERR ); } /* IMCloseBracket */
/* * IMCloseBrace - handle '}' in insert mode */ vi_rc IMCloseBrace( void ) { int i, j; int ts; fcb *cfcb; line *cline; vi_rc rc; int newcol; i_mark pos; startNewLineUndo(); insertChar( TRUE, FALSE ); newcol = CurrentPos.column + 1; if( EditFlags.ShowMatch ) { ReplaceCurrentLine(); rc = FindMatch( &pos ); if( rc == ERR_NO_ERR ) { tempMatch( &pos ); } GetCurrentLine(); } if( EditFlags.CMode ) { i = 0; while( isspace( WorkLine->data[i] ) ) { i++; } if( WorkLine->data[i] == '}' ) { /* * added a {, so: * find matching } * find out indentation of that line * shift current line over to that indentation * set current indentation to that */ ReplaceCurrentLine(); rc = findMatchingBrace( &pos ); if( rc == ERR_NO_ERR ) { newcol = VirtualColumnOnCurrentLine( CurrentPos.column ); CGimmeLinePtr( pos.line, &cfcb, &cline ); i = FindStartOfALine( cline ); i = GetVirtualCursorPosition( cline->data, i ); j = i - VirtualColumnOnCurrentLine( CurrentPos.column ); ts = EditVars.ShiftWidth; if( j > 0 ) { EditVars.ShiftWidth = j; Shift( CurrentPos.line, CurrentPos.line, '>', FALSE ); } else if( j < 0 ) { EditVars.ShiftWidth = -j; Shift( CurrentPos.line, CurrentPos.line, '<', FALSE ); } EditVars.ShiftWidth = ts; newcol = 1 + RealColumnOnCurrentLine( j + newcol ); } GetCurrentLine(); } } GoToColumn( newcol, WorkLine->len + 1 ); return( ERR_NO_ERR ); } /* IMCloseBrace */
/* * IMEnter - process the enter key in insert mode */ vi_rc IMEnter( void ) { char *buff, *buffx; int len, col, el; if( CurrentFile == NULL ) { return( ERR_NO_FILE ); } CurrentFile->need_autosave = TRUE; startNewLineUndo(); CheckAbbrev( abbrevBuff, &abbrevCnt ); abbrevCnt = 0; /* * truncate the working line */ buff = StaticAlloc(); buffx = StaticAlloc(); el = WorkLine->len - CurrentPos.column + 1; if( el > 0 && WorkLine->len > 0 ) { memcpy( buff, &WorkLine->data[CurrentPos.column - 1], el + 1 ); WorkLine->len -= el; WorkLine->data[CurrentPos.column - 1] = 0; } else { el = 0; buff[0] = 0; } len = trimWorkLine(); /* * replace the current line with the working copy */ ReplaceCurrentLine(); if( currLineRepUndo ) { CurrentLineReplaceUndoEnd( FALSE ); currLineRepUndo = FALSE; } /* * create a new line, insert leading spaces if needed * and copy in the truncation */ if( EditFlags.AutoIndent ) { len = GetAutoIndentAmount( buffx, len, FALSE ); el += len; strcat( buffx, buff ); AddNewLineAroundCurrent( buffx, el, INSERT_AFTER ); col = len + 1; } else { AddNewLineAroundCurrent( buff, el, INSERT_AFTER ); col = 1; } UndoInsert( CurrentPos.line + 1, CurrentPos.line + 1, UndoStack ); /* * display the result */ DCDisplayAllLines(); GoToLineRelCurs( CurrentPos.line + 1 ); GoToColumnOK( col ); GetCurrentLine(); StaticFree( buff ); StaticFree( buffx ); return( ERR_NO_ERR ); } /* IMEnter */
/* * insertGenericSavebuf - insert contents of a savebuf before/after current pos */ static vi_rc insertGenericSavebuf( int buf, bool afterflag ) { #ifdef __WIN__ savebuf clip; #endif savebuf *tmp; fcb_list fcblist; fcb *end; int i, scol, len; int maxCursor; vi_rc rc; rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } if( EditFlags.Modeless ) { DeleteSelectedRegion(); SelRgn.selected = false; } #ifdef __WIN__ if( buf == CLIPBOARD_SAVEBUF ) { rc = GetClipboardSavebuf( &clip ); if( rc != ERR_NO_ERR ) { return( rc ); } tmp = &clip; } else #endif if( buf >= MAX_SAVEBUFS ) { tmp = &SpecialSavebufs[buf - MAX_SAVEBUFS]; } else { tmp = &Savebufs[buf]; } switch( tmp->type ) { case SAVEBUF_NOP: rc = ERR_EMPTY_SAVEBUF; break; case SAVEBUF_LINE: /* * get starting data */ len = strlen( tmp->u.data ); if( len + CurrentLine->len >= EditVars.MaxLine ) { rc = ERR_LINE_FULL; break; } if( afterflag ) { scol = CurrentPos.column; } else { scol = CurrentPos.column - 1; } CurrentLineReplaceUndoStart(); GetCurrentLine(); /* * open up line and copy in data */ if( WorkLine->len == 0 ) { scol = 0; } for( i = WorkLine->len; i >= scol; i-- ) { WorkLine->data[i + len] = WorkLine->data[i]; } for( i = 0; i < len; i++ ) { WorkLine->data[i + scol] = tmp->u.data[i]; } WorkLine->len += len; DisplayWorkLine( true ); ReplaceCurrentLine(); CurrentLineReplaceUndoEnd( true ); scol += len + 1; maxCursor = CurrentLine->len; if( EditFlags.Modeless ) { maxCursor++; } if( scol > maxCursor ) { scol = maxCursor; } rc = GoToColumn( scol, maxCursor ); break; case SAVEBUF_FCBS: fcblist.head = NULL; fcblist.tail = NULL; end = tmp->u.fcbs.tail->next; tmp->u.fcbs.tail->next = NULL; CreateDuplicateFcbList( tmp->u.fcbs.head, &fcblist ); tmp->u.fcbs.tail->next = end; if( !EditFlags.LineBased ) { rc = InsertLinesAtCursor( &fcblist, UndoStack ); } else { if( afterflag) { rc = InsertLines( CurrentPos.line, &fcblist, UndoStack ); } else { rc = InsertLines( CurrentPos.line - 1, &fcblist, UndoStack ); } } break; } #ifdef __WIN__ if( tmp == &clip ) { freeSavebuf( &clip ); } #endif EditFlags.Dotable = true; return( rc ); } /* insertGenericSavebuf */
/* * GenericJoinCurrentLineToNext */ vi_rc GenericJoinCurrentLineToNext( bool remsp ) { line *nline = CurrentLine; fcb *nfcb = CurrentFcb; int i, j, k; vi_rc rc; /* * get next line data */ rc = CGimmeNextLinePtr( &nfcb, &nline ); if( rc != ERR_NO_ERR ) { return( rc ); } if( CurrentLine->len + nline->len + 1 >= EditVars.MaxLine ) { return( ERR_LINE_FULL ); } /* * now, copy in the data */ StartUndoGroup( UndoStack ); CurrentLineReplaceUndoStart(); CurrentLineReplaceUndoEnd( true ); GetCurrentLine(); if( remsp ) { while( WorkLine->len > 0 && WorkLine->data[WorkLine->len - 1] == ' ' ) { WorkLine->data[WorkLine->len - 1] = 0; WorkLine->len--; } j = FindStartOfALine( nline ) - 1; k = 0; if( !(j == 0 && nline->data[0] == ' ') ) { if( WorkLine->len != 0 ) { WorkLine->data[WorkLine->len] = ' '; k = WorkLine->len + 1; } for( i = j; i <= nline->len; i++ ) { WorkLine->data[k + i - j] = nline->data[i]; } } } else { k = WorkLine->len; for( i = 0; i <= nline->len; i++ ) { WorkLine->data[k + i] = nline->data[i]; } } WorkLine->len = strlen( WorkLine->data ); ReplaceCurrentLine(); /* * delete next line */ rc = DeleteLineRange( CurrentPos.line + 1, CurrentPos.line + 1, 0 ); if( rc != ERR_NO_ERR ) { return( rc ); } EndUndoGroup( UndoStack ); if( remsp ) { if( k < 2 ) { k = 2; } rc = GoToColumn( k - 1, CurrentLine->len ); if( rc != ERR_NO_ERR ) { return( rc ); } } DCDisplayAllLines(); return( ERR_NO_ERR ); } /* GenericJoinCurrentLineToNext */
/* * Substitute - perform substitution */ vi_rc Substitute( linenum n1, linenum n2, char *data ) { char *sstr, *rstr, *newr; char flag[20], *linedata; bool iflag = false; bool gflag = false; bool undoflag = false; bool restline = false; bool splitpending = false; bool undoline = false; int i, rlen, slen; bool splitme; long changecnt = 0, linecnt = 0; linenum llineno, ll, lastline = 0, extra; i_mark pos; vi_rc rc; LastSubstituteCancelled = 0; LastChangeCount = 0; LastLineCount = 0; sstr = alloca( MAX_INPUT_LINE ); if( sstr == NULL ) { return( ERR_NO_STACK ); } strcpy( sstr, data ); rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } strcpy( data, sstr ); rstr = alloca( MAX_INPUT_LINE ); if( rstr == NULL ) { return( ERR_NO_STACK ); } if( NextWordSlash( data, sstr ) < 0 ) { return( ERR_INVALID_SUBS_CMD ); } if( NextWordSlash( data, rstr ) < 0 ) { return( ERR_INVALID_SUBS_CMD ); } slen = NextWord1( data, flag ); for( i = 0; i < slen; i++ ) { switch( flag[i] ) { case 'g': gflag = true; break; case 'i': case 'c': iflag = true; break; } } rc = CurrentRegComp( sstr ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * verify last line */ if( n2 > CurrentFile->fcbs.tail->end_line ) { rc = CFindLastLine( &ll ); if( rc != ERR_NO_ERR ) { return( rc ); } if( n2 > ll ) { return( ERR_INVALID_LINE_RANGE ); } } /* * set for start of search */ if( EditFlags.Verbose && EditFlags.EchoOn ) { ClearWindow( MessageWindow ); } SaveCurrentFilePos(); llineno = n1 - 1; EditFlags.AllowRegSubNewline = true; newr = StaticAlloc(); for( pos.column = 0, pos.line = n1; pos.line <= n2; nextSearchStartPos( &pos, gflag, rlen ) ) { /* * get regular expression, and build replacement string */ rc = FindRegularExpression( NULL, &pos, &linedata, n2, 0 ); if( rc != ERR_NO_ERR || pos.line > n2 ) { break; } slen = GetCurrRegExpLength(); splitme = RegSub( CurrentRegularExpression, rstr, newr, pos.line ); rlen = strlen( newr ); ProcessingMessage( pos.line ); /* * if in global mode, see if we already have an undo for * this line */ if( gflag ) { if( lastline != pos.line ) { undoline = false; } } /* * interactive mode? yes, then display text and ask to change */ if( iflag ) { change_resp rsp; if( !restline ) { ClearWindow( MessageWindow ); } restline = true; GoToLineNoRelCurs( pos.line ); if( EditFlags.GlobalInProgress ) { EditFlags.DisplayHold = false; DCDisplayAllLines(); EditFlags.DisplayHold = true; } HilightSearchString( &pos, slen ); rsp = ChangePrompt(); if( rsp == CHANGE_NO ) { ResetDisplayLine(); rlen = 1; continue; } else if( rsp == CHANGE_CANCEL ) { ResetDisplayLine(); LastSubstituteCancelled = 1; break; } else if( rsp == CHANGE_ALL ) { ResetDisplayLine(); iflag = false; } } /* * set up for global undo if we haven't already */ if( !undoflag ) { StartUndoGroup( UndoStack ); undoflag = true; } /* * bump change counts */ changecnt++; if( llineno != pos.line ) { if( splitpending ) { splitpending = false; extra = SplitUpLine( llineno ); n2 += extra; pos.line += extra; } linecnt++; llineno = pos.line; } /* * get copy of line, and verify that new stuff fits */ CurrentPos.line = pos.line; rc = CGimmeLinePtr( pos.line, &CurrentFcb, &CurrentLine ); if( rc != ERR_NO_ERR ) { break; } if( CurrentLine->len + rlen - slen >= EditVars.MaxLine ) { rc = ERR_LINE_FULL; break; } /* * now build the individual undo */ CurrentFcb->non_swappable = true; if( !undoline ) { CurrentLineReplaceUndoStart(); CurrentLineReplaceUndoEnd( true ); if( gflag ) { undoline = true; lastline = pos.line; } } /* * remove the old string */ GetCurrentLine(); WorkLine->len = ReplaceSubString( WorkLine->data, WorkLine->len, pos.column, pos.column + slen - 1, newr, rlen ); if( iflag ) { DisplayWorkLine( true ); } ReplaceCurrentLine(); /* * if not global, only do this change on this line */ if( splitme ) { splitpending = true; } CurrentFcb->non_swappable = false; } StaticFree( newr ); EditFlags.AllowRegSubNewline = false; /* * is there still a split line pending? */ if( splitpending ) { SplitUpLine( llineno ); } RestoreCurrentFilePos(); if( restline ) { SetCurrentLine( CurrentPos.line ); GoToColumnOK( CurrentPos.column ); } if( undoflag ) { EndUndoGroup( UndoStack ); } switch( rc ) { case ERR_NO_ERR: case ERR_LINE_FULL: case ERR_FIND_PAST_TERM_LINE: case ERR_FIND_NOT_FOUND: case ERR_FIND_END_OF_FILE: /* * display results */ if( rc == ERR_LINE_FULL ) { Message1( "Stopped at line %l - line full", pos.line ); } else { Message1( "%l changes on %l lines", changecnt, linecnt ); LastLineCount = linecnt; LastChangeCount = changecnt; } DCDisplayAllLines(); rc = ERR_NO_ERR; break; default: break; } return( rc ); } /* Substitute */
/* * doCompressExpand - convert tabs to spaces, and spaces to tabs */ static vi_rc doCompressExpand( bool compress ) { int k; long bytes_saved = 0; long bytes_added = 0; long otabcnt; linenum linecnt = 0; char *tmp; vi_rc rc; /* * init */ rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } rc = SaveAndResetFilePos( 1 ); if( rc != ERR_NO_ERR ) { return( rc ); } tmp = StaticAlloc(); /* * process all lines */ TabCnt = 0; for( ;; ) { if( compress ) { otabcnt = TabCnt; ExpandTabsInABuffer( CurrentLine->data, CurrentLine->len, tmp, EditVars.MaxLine ); TabCnt = otabcnt; k = strlen( tmp ); ConvertSpacesToTabsUpToColumn( k, tmp, k, WorkLine->data, EditVars.MaxLine ); WorkLine->len = strlen( WorkLine->data ); bytes_saved += CurrentLine->len - WorkLine->len; } else { ExpandTabsInABuffer( CurrentLine->data, CurrentLine->len, WorkLine->data, EditVars.MaxLine ); WorkLine->len = strlen( WorkLine->data ); bytes_added += WorkLine->len - CurrentLine->len; } ReplaceCurrentLine(); /* * get next line */ linecnt++; rc = CGimmeNextLinePtr( &CurrentFcb, &CurrentLine ); if( rc != ERR_NO_ERR ) { if( rc == ERR_NO_MORE_LINES ) { break; } RestoreCurrentFilePos(); StaticFree( tmp ); return( rc ); } } StaticFree( tmp ); RestoreCurrentFilePos(); Modified( TRUE ); DCDisplayAllLines(); Message1( "%l lines processed in \"%s\"", linecnt, CurrentFile->name ); if( compress ) { Message2( " %l tabs added (%l bytes saved)", TabCnt, bytes_saved ); } else { Message2( " %l tabs removed (%l bytes added)", TabCnt, bytes_added ); } return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } /* doCompressExpand */
/* * Shift - shove a tab in/out over a line range */ vi_rc Shift( linenum s, linenum e, char dir, bool msgflag ) { int shv; linenum fullcnt = 0; vi_rc rc; /* * set up undo */ if( rc = ModificationTest() ) { return( rc ); } rc = UndoReplaceLines( s, e ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * now, point to start line */ rc = SaveAndResetFilePos( s ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * process all lines */ for( CurrentPos.line = s; CurrentPos.line <= e; CurrentPos.line++ ) { /* * Add/Subtract leading tab space */ GetCurrentLine(); shv = ShiftWidth; if( dir != '>' ) { shv *= -1; } if( AddLeadingTabSpace( &WorkLine->len, WorkLine->data, shv ) ) { ++fullcnt; } ReplaceCurrentLine(); if( CurrentPos.line != e ) { rc = CGimmeNextLinePtr( &CurrentFcb, &CurrentLine ); if( rc != ERR_NO_ERR ) { RestoreCurrentFilePos(); return( rc ); } } } /* * done, say so and go back */ RestoreCurrentFilePos(); if( msgflag ) { Message1( "%l lines %c'ed", e - s + 1, dir ); if( fullcnt > 0 ) { Message2( "%l full lines not processed", fullcnt ); } } if( CurrentPos.line >= s && CurrentPos.line <= e ) { CheckCurrentColumn(); } DCDisplayAllLines(); SetWindowCursor(); Modified( TRUE ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } /* Shift */
/* * InsertLinesAtCursor - insert a set of lines at current pos. in file */ vi_rc InsertLinesAtCursor( fcb_list *fcblist, undo_stack *us ) { fcb *cfcb; linenum e; int lastLineLen; char *source; line *tLine; vi_rc rc; rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } /* * find the number of lines inserted */ e = 0; for( cfcb = fcblist->head; cfcb != NULL; cfcb = cfcb->next ) { e += (cfcb->end_line - cfcb->start_line + 1); } // add chars from right of cursor to end of last line of buffer source = CurrentLine->data + CurrentPos.column - 1; lastLineLen = fcblist->tail->lines.tail->len; fcblist->tail->lines.tail->len += CurrentLine->len - CurrentPos.column + 1; fcblist->tail->byte_cnt += CurrentLine->len - CurrentPos.column + 1; tLine = fcblist->tail->lines.tail->prev; fcblist->tail->lines.tail = MemReAlloc( fcblist->tail->lines.tail, sizeof( line ) + fcblist->tail->lines.tail->len + 1 ); if( tLine ) { tLine->next = fcblist->tail->lines.tail; } strcpy( fcblist->tail->lines.tail->data + lastLineLen, source ); StartUndoGroup( us ); // create new current line in work line CurrentLineReplaceUndoStart(); GetCurrentLine(); WorkLine->len = CurrentPos.column + fcblist->head->lines.head->len - 1; strcpy( WorkLine->data + CurrentPos.column - 1, fcblist->head->lines.head->data ); // replace current line ReplaceCurrentLine(); CurrentLineReplaceUndoEnd( true ); // remove first line of buffer FetchFcb( fcblist->head ); fcblist->head->non_swappable = true; fcblist->head->start_line++; fcblist->head->byte_cnt -= fcblist->head->lines.head->len + 1; tLine = fcblist->head->lines.head; fcblist->head->lines.head = fcblist->head->lines.head->next; fcblist->head->lines.head->prev = NULL; MemFree( tLine ); fcblist->head->non_swappable = false; // add rest of lines of buffer & done if( fcblist->head->lines.head) { InsertLines( CurrentPos.line, fcblist, us ); } EndUndoGroup( us ); // if are indeed linebased, move cursor as well if( !EditFlags.LineBased ) { GoToLineNoRelCurs( CurrentPos.line + e - 1 ); GoToColumnOnCurrentLine( lastLineLen + 1 ); } return( ERR_NO_ERR ); } /* InsertLinesAtCursor */