savebuf.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 643 行 · 第 1/2 页
C
643 行
} else {
*data = MemAlloc( len );
switch( tmp->type ) {
case SAVEBUF_LINE:
strcpy( *data, tmp->first.data );
break;
case SAVEBUF_FCBS:
cfcb = tmp->first.fcb_head;
**data = 0;
while( cfcb != NULL ) {
FetchFcb( cfcb );
cline = cfcb->line_head;
while( cline != NULL ) {
strcat( *data, cline->data );
strcat( *data, "\\n" );
cline = cline->next;
}
cfcb = cfcb->next;
}
break;
}
}
#ifdef __WIN__
if( tmp == &clip ) {
freeSavebuf( &clip );
}
#endif
return( rc );
} /* GetSavebufString */
/*
* InitSavebufs - initalize save buffers
*/
void InitSavebufs( void )
{
int i;
for( i=MAX_SAVEBUFS-1;i>=0;i-- ) {
Savebufs[i].type = SAVEBUF_NOP;
Savebufs[i].first.data = NULL;
Savebufs[i].fcb_tail = NULL;
}
} /* InitSavebufs */
void FiniSavebufs( void )
{
int i;
for( i=MAX_SAVEBUFS-1;i>=0;i-- ) {
freeSavebuf( &Savebufs[i] );
}
} /* FiniSavebufs */
/*
* AddLineToSavebuf - add a single line to save buffer
*/
void AddLineToSavebuf( char *data, int scol, int ecol )
{
savebuf *tmp;
int i,len,j;
/*
* set up for copy
*/
if( scol > ecol ) {
i = scol;
scol = ecol;
ecol = i;
}
len = ecol-scol+1;
/*
* set to appropriate savebuf and rotate others forward
*/
#ifdef __WIN__
if( SavebufNumber == CLIPBOARD_SAVEBUF ) {
AddLineToClipboard( data, scol, ecol );
LastSavebuf = 0;
return;
} else
#endif
if( SavebufNumber == NO_SAVEBUF ) {
j = CurrentSavebuf;
} else {
j = SavebufNumber;
}
if( j >= MAX_SAVEBUFS ) {
LastSavebuf = (char) j + (char) 'a' - (char) MAX_SAVEBUFS;
tmp = &SpecialSavebufs[ j - MAX_SAVEBUFS ];
} else {
LastSavebuf = (char) j + (char) '1';
tmp = &Savebufs[ j ];
rotateSavebufs( j );
}
tmp->type = SAVEBUF_LINE;
/*
* get and copy buffer
*/
tmp->first.data = MemAlloc( len+1 );
for( i=scol;i<=ecol;i++ ) {
tmp->first.data[i-scol] = data[i];
}
tmp->first.data[len] = 0;
} /* AddLineToSavebuf */
/*
* AddSelRgnToSavebuf - copy selected text to savebuf
*/
void AddSelRgnToSavebuf( void )
{
char buf[] = "0";
range r;
if( GetSelectedRegion( &r ) != ERR_NO_ERR ) {
return;
}
NormalizeRange( &r );
SetSavebufNumber( buf );
Yank( &r );
}
/*
* AddSelRgnToSavebufAndDelete - copy selected text to savebuf, then kill it
*/
void AddSelRgnToSavebufAndDelete( void )
{
AddSelRgnToSavebuf();
DeleteSelectedRegion();
}
/*
* AddFcbsToSavebuf - add fcb block to save buffer
*/
void AddFcbsToSavebuf( fcb *head, fcb *tail, int duplflag )
{
int j;
savebuf *tmp;
fcb *cfcb,*nhead=NULL,*ntail=NULL;
/*
* set to appropriate savebuf and rotate others forward
*/
#ifdef __WIN__
if( SavebufNumber == CLIPBOARD_SAVEBUF ) {
AddFcbsToClipboard( head, tail );
LastSavebuf = 0;
return;
} else
#endif
if( SavebufNumber == NO_SAVEBUF ) {
j = CurrentSavebuf;
} else {
j = SavebufNumber;
}
if( j >= MAX_SAVEBUFS ) {
LastSavebuf = (char) j + (char) 'a' - (char) MAX_SAVEBUFS;
tmp = &SpecialSavebufs[ j - MAX_SAVEBUFS ];
} else {
LastSavebuf = (char) j + (char) '1';
tmp = &Savebufs[ j ];
rotateSavebufs( j );
}
tmp->type = SAVEBUF_FCBS;
if( duplflag ) {
cfcb = tail->next;
tail->next = NULL;
CreateDuplicateFcbList( head, &nhead, &ntail );
tail->next = cfcb;
tmp->first.fcb_head = nhead;
tmp->fcb_tail = ntail;
} else {
tmp->first.fcb_head = head;
tmp->fcb_tail = tail;
}
} /* AddFcbsToSavebuf */
/*
* SwitchSavebuf - switch current save buffer
*/
int SwitchSavebuf( void )
{
int buf,i;
linenum lcnt;
savebuf *tmp;
char *data;
fcb *cfcb;
/*
* validate savebuf
*/
buf = -1;
for( i=0;i< MAX_SAVEBUFS;i++ ) {
if( LastEvent == SavebufBound[i] ){
buf = i;
break;
}
}
if( buf < 0 ) {
return( ERR_NO_ERR );
}
CurrentSavebuf = buf;
tmp = &Savebufs[ buf ];
switch( tmp->type ) {
case SAVEBUF_NOP:
Message1( "Buffer %d now active. (empty buffer)",buf+1 );
return( DO_NOT_CLEAR_MESSAGE_WINDOW );
case SAVEBUF_LINE:
data = tmp->first.data;
Message1( "Buffer %d active, %d characters:",buf+1, strlen( tmp->first.data ) );
break;
case SAVEBUF_FCBS:
cfcb = tmp->first.fcb_head;
FetchFcb( cfcb );
data = cfcb->line_head->data;
lcnt = 0;
while( cfcb != NULL ) {
lcnt += cfcb->end_line - cfcb->start_line+1;
cfcb = cfcb->next;
}
Message1( "Buffer %d active, %l lines:",buf+1, lcnt );
break;
}
Message2( "\"%s\"",data );
return( DO_NOT_CLEAR_MESSAGE_WINDOW );
} /* SwitchSavebuf */
/*
* DoSavebufNumber - get a savebuf number
*/
int DoSavebufNumber( void )
{
int i,rc;
char buff[2];
/*
* get savebuf to use
*/
i = GetNextEvent( FALSE );
if( i == VI_KEY( ESC ) ) {
return( ERR_NO_ERR );
}
buff[0] = i;
buff[1] = 0;
rc = SetSavebufNumber( buff );
if( !rc ) {
rc = GOT_A_SAVEBUF;
}
return( rc );
} /* DoSavebufNumber */
/*
* SetSavebufNumber - set savebuf number from a string
*/
int SetSavebufNumber( char *data )
{
char st[MAX_STR];
SavebufNumber = NO_SAVEBUF;
if( NextWord1( data, st ) > 0 ) {
if( st[1] != 0 ) {
Error( GetErrorMsg( ERR_INVALID_SAVEBUF) , st[0] );
return( DO_NOT_CLEAR_MESSAGE_WINDOW );
}
#ifdef __WIN__
if( st[0] == '0' ) {
SavebufNumber = CLIPBOARD_SAVEBUF;
} else
#endif
if( st[0] >= '1' && st[0] <= '9' ) {
SavebufNumber = st[0] - '1';
} else if( st[0] >= 'a' && st[0] <= 'z' ) {
SavebufNumber = st[0] - 'a' + MAX_SAVEBUFS;
} else {
Error( GetErrorMsg( ERR_INVALID_SAVEBUF) , st[0] );
return( DO_NOT_CLEAR_MESSAGE_WINDOW );
}
}
return( ERR_NO_ERR );
} /* SetSavebufNumber */
/*
* IsEmptySavebuf - check if a specified savebuf is empty
*/
bool IsEmptySavebuf( char ch )
{
int bufnum;
#ifdef __WIN__
if( ch == '0' ) {
return( IsClipboardEmpty() );
} else
#endif
if( ch >= '1' && ch <= '9' ) {
bufnum = ch - '1';
if( Savebufs[bufnum].type == SAVEBUF_NOP ) {
return( TRUE );
}
return( FALSE );
} else if( ch >= 'a' && ch <= 'z' ) {
bufnum = ch - 'a';
if( SpecialSavebufs[bufnum].type == SAVEBUF_NOP ) {
return( TRUE );
}
}
return( FALSE );
} /* IsEmptySavebuf */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?