opmove.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 623 行 · 第 1/2 页
C
623 行
* MoveShiftTab - move back a tab
*/
int MoveShiftTab( range *r, long count )
{
int i, vc;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
r->start.line = CurrentLineNumber;
r->line_based = FALSE;
vc = VirtualCursorPosition();
while( count ) {
i = ShiftTab( vc, TabAmount );
vc -= i;
if( vc < 1 ) {
r->start.column = 1;
return( ERR_NO_SUCH_COLUMN );
}
count -= 1;
}
r->start.column = RealCursorPosition( vc );
return( ERR_NO_ERR );
} /* MoveShiftTab */
static int doMoveToStartEndOfLine( range *r, long count, bool start )
{
linenum new;
int rc;
line *line;
fcb *fcb;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
new = CurrentLineNumber + count;
rc = checkLine( &new );
r->start.line = new;
if( rc == ERR_NO_ERR ) {
rc = CGimmeLinePtr( new, &fcb, &line );
if( rc == ERR_NO_ERR ) {
if( start == TRUE ) {
r->start.column = FindStartOfALine( line );
} else {
r->start.column = line->len + 1;
}
/*
* Not sure if we should be line-based or not; for now
* I'm just cloning MKS.
*/
r->line_based = TRUE;
}
}
return( rc );
}
int MoveStartNextLine( range *r, long count )
{
return( doMoveToStartEndOfLine( r, count, TRUE ) );
}
int MoveStartPrevLine( range *r, long count )
{
return( doMoveToStartEndOfLine( r, -count, TRUE ) );
}
/*
* moveForwardAWord - move to next word
*/
static int moveForwardAWord( range *r, bool end, bool bigword, int count )
{
int i, rc;
i_mark curr;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
assert( count > 0 );
curr = r->end;
for( i = 0; i < count; i++ ) {
if( end ) {
rc = MarkEndOfNextWordForward( &r->start, &curr, bigword );
} else {
rc = MarkStartOfNextWordForward( &r->start, &curr, bigword );
}
if( rc != ERR_NO_ERR ) break;
curr = r->start;
}
r->line_based = FALSE;
return( rc );
} /* MoveForwardWord */
int MoveForwardWord( range *r, long count )
{
return( moveForwardAWord( r, FALSE, FALSE, count ) );
}
int MoveForwardBigWord( range *r, long count )
{
return( moveForwardAWord( r, FALSE, TRUE, count ) );
}
int MoveForwardWordEnd( range *r, long count )
{
return( moveForwardAWord( r, TRUE, FALSE, count ) );
}
int MoveForwardBigWordEnd( range *r, long count )
{
return( moveForwardAWord( r, TRUE, TRUE, count ) );
}
/*
* moveBackwardsAWord - move back a word
*/
static int moveBackwardsAWord( range *r, bool bigword, int count )
{
int i, rc;
i_mark curr;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
assert( count > 0 );
curr = r->end;
for( i = 0; i < count; i++ ) {
rc = MarkStartOfNextWordBackward( &r->start, &curr, bigword );
if( rc != ERR_NO_ERR ) break;
curr = r->start;
}
r->line_based = FALSE;
return( ERR_NO_ERR );
} /* moveBackwardsAWord */
int MoveBackwardsWord( range *r, long count )
{
return( moveBackwardsAWord( r, FALSE, count ) );
}
int MoveBackwardsBigWord( range *r, long count )
{
return( moveBackwardsAWord( r, TRUE, count ) );
}
/*
* doACharFind - find a character on a line
*/
static int doACharFind( range *r, int forward, int num, long count )
{
int i,c;
char lc;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
r->line_based = FALSE;
lc = LastEvent;
i = FindCharOnCurrentLine( forward, num, &c, count );
if( !i && c >= 0 ) {
lastChar[0] = lc;
lastChar[1] = LastEvent;
r->start.column = c;
return( ERR_NO_ERR );
}
return( i );
} /* doACharFind */
int MoveUpToChar( range *r, long count )
{
return( doACharFind( r, TRUE, 0, count ) );
}
int MoveUpToBeforeChar( range *r, long count )
{
return( doACharFind( r, TRUE, -1, count ) );
}
int MoveBackToChar( range *r, long count )
{
return( doACharFind( r, FALSE, 0, count ) );
}
int MoveBackToAfterChar( range *r, long count )
{
return( doACharFind( r, FALSE, 1, count ) );
}
/*
* DoGo - go to a specified line
*/
int DoGo( range *r, long count )
{
linenum lne;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
CFindLastLine( &lne );
if( NoRepeatInfo ) {
r->start.line = lne;
} else {
if( count > lne ) {
if( EditFlags.Modeless ) {
count = lne;
} else {
return( ERR_NO_SUCH_LINE );
}
}
r->start.line = count;
}
// change column - is this correct? MKS Vi does it...
r->start.column = 1;
r->line_based = TRUE;
return( ERR_NO_ERR );
} /* DoGo */
/*
* moveToLastCFind - go to last character found using f, F, t or T
*/
static int moveToLastCFind( range *r, bool reverse, long count )
{
int rc, tmp, lastc;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
if( lastChar[0] == 0 ) {
return( ERR_NO_PREVIOUS_COMMAND );
}
tmp = *(int *)lastChar;
KeyAdd( lastChar[1] );
lastc = lastChar[0];
if( reverse ) {
if( islower( lastc ) ) {
lastc = toupper( lastc );
} else {
lastc = tolower( lastc );
}
}
rc = (EventList[lastc].rtn.move)( r, count );
*(int *)lastChar = tmp;
return( rc );
} /* moveToLastCFind */
int MoveToLastCharFind( range *r, long count )
{
return( moveToLastCFind( r, FALSE, count ) );
}
int MoveToLastCharFindRev( range *r, long count )
{
return( moveToLastCFind( r, TRUE, count ) );
}
/*
* MoveStartOfFile - go to the first char of file
*/
int MoveStartOfFile( range *r, long count )
{
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
count = count; // not needed here
r->start.line = 1;
r->start.column = 1;
r->line_based = FALSE;
return( ERR_NO_ERR );
} /* MoveStartOfFile */
/*
* MoveEndOfFile - go to the top of file
*/
int MoveEndOfFile( range *r, long count )
{
linenum ln;
if( CurrentLine == NULL ) {
return( ERR_NO_FILE );
}
count = count; // not needed here
CFindLastLine( &ln );
r->start.line = ln;
if( EditFlags.Modeless ) {
r->start.column = LineLength( ln ) + 1;
} else {
r->start.column = LineLength( ln );
}
r->line_based = FALSE;
return( ERR_NO_ERR );
} /* MoveEndOfFile */
int MoveTopOfPage( range *r, long count )
{
count = count;
return( doMoveToStartEndOfLine( r, TopOfPage-CurrentLineNumber, TRUE ) );
}
int MoveBottomOfPage( range *r, long count )
{
int bottom = TopOfPage +
WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) - 1;
count = count;
return( doMoveToStartEndOfLine( r, bottom - CurrentLineNumber, FALSE ) );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?