📄 block.c
字号:
* file too big
*/
error( WARNING, window->bottom_line, dir3 );
if (l != NULL)
my_free( l );
if (temp_ll != NULL)
my_free( temp_ll );
*rc = ERROR;
er = li - 1;
}
}
} else if (action == MOVE) {
if (dest->len != EOF && dest->next != NULL) {
temp_ll = block_start;
for (li=br; li <= er && *rc == OK; li++) {
temp_ll->dirty = TRUE;
temp_ll = temp_ll->next;
}
if (block_start->prev == NULL)
source_file->line_list = block_end->next;
if (block_start->prev != NULL)
block_start->prev->next = block_end->next;
block_end->next->prev = block_start->prev;
dest->next->prev = block_end;
block_start->prev = dest;
block_end->next = dest->next;
dest->next = block_start;
}
} else if (action == DELETE) {
block_end->next->prev = block_start->prev;
if (block_start->prev == NULL)
source_file->line_list = block_end->next;
else
block_start->prev->next = block_end->next;
block_end->next = NULL;
while (block_start != NULL) {
temp_ll = block_start;
block_start = block_start->next;
if (temp_ll->line != NULL)
my_free( temp_ll->line );
my_free( temp_ll );
}
}
diff = er + 1L - br;
if (action == COPY || action == KOPY || action == MOVE)
dest_file->length += diff;
if (action == DELETE || action == MOVE)
source_file->length -= diff;
if (action == DELETE && source_window->rline >= br) {
source_window->rline -= diff;
if (source_window->rline < br)
source_window->rline = br;
}
/*
* restore all cursors in all windows
*/
restore_cursors( dest_file );
if (dest_file != source_file)
restore_cursors( source_file );
show_avail_mem( );
}
/*
* Name: do_stream_block
* Purpose: delete, move, copy, or kopy a STREAM block
* Date: June 5, 1991
* Passed: window: pointer to destination window (current window)
* source_window: pointer to source window
* action: block action -- KOPY, MOVE, etc...
* source_file: pointer to source file structure
* dest_file: pointer to destination file
* block_start: pointer to first node in block
* block_end: pointer to last node in block
* source: pointer to source node
* dest: pointer to destination node
* rline: current line number in destination file
* br: beginning line number in marked block
* er: ending line number in marked block
* bc: beginning column of block
* ec: ending column of block
* rcol: current column of cursor
* rc: return code
*/
void do_stream_block( WINDOW *window, WINDOW *source_window, int action,
file_infos *source_file, file_infos *dest_file,
line_list_ptr block_start, line_list_ptr block_end,
line_list_ptr source, line_list_ptr dest, long rline,
long br, long er, int bc, int ec, int rcol, int *rc )
{
line_list_ptr temp_ll; /* temporary list pointer */
text_ptr l;
int lens; /* length of source line */
int lend; /* length of destination line */
long li; /* temporary line variables */
long diff;
WINDOW s_w, d_w; /* a couple of temporary WINDOWs */
dup_window_info( &s_w, source_window );
dup_window_info( &d_w, window );
s_w.rline = br;
s_w.ll = block_start;
s_w.visible = FALSE;
d_w.rline = rline;
d_w.ll = dest;
d_w.visible = FALSE;
/*
* pad the start of the STREAM block if needed.
*/
lens = block_start->len;
detab_a_line( block_start->line, &lens );
if (lens < bc || mode.inflate_tabs)
*rc = prepare_block( &s_w, block_start, bc );
/*
* pad the end of the STREAM block if needed.
*/
lens = block_end->len;
detab_a_line( block_end->line, &lens );
if (*rc == OK && (lens < ec+1 || mode.inflate_tabs))
*rc = prepare_block( &s_w, block_end, ec+1 );
/*
* pad the destination line if necessary
*/
copy_line( dest );
detab_linebuff( );
*rc = un_copy_line( dest, &d_w, FALSE );
lend = dest->len;
if (*rc == OK && (action==MOVE || action==COPY || action==KOPY)) {
if (lend < rcol || mode.inflate_tabs)
*rc = prepare_block( &d_w, dest, rcol );
}
if ((action == COPY || action == KOPY) && *rc == OK) {
/*
* concatenate the end of the STREAM block with the end of the
* destination line.
*/
lens = dest->len - rcol;
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( ec + 1 >= 0 );
assert( ec + 1 <= MAX_LINE_LENGTH );
assert( rcol >= 0 );
_fmemcpy( g_status.line_buff, block_end->line, ec+1 );
_fmemcpy( g_status.line_buff+ec+1, dest->line+rcol, lens );
lens += ec + 1;
g_status.line_buff_len = lens;
temp_ll = (line_list_ptr)my_malloc( sizeof(line_list_struc), rc );
if (*rc == OK) {
temp_ll->line = NULL;
temp_ll->len = 0;
temp_ll->dirty = FALSE;
g_status.copied = TRUE;
*rc = un_copy_line( temp_ll, &d_w, TRUE );
if (*rc == OK) {
dest->next->prev = temp_ll;
temp_ll->next = dest->next;
dest->next = temp_ll;
temp_ll->prev = dest;
} else
if (temp_ll != NULL)
my_free( temp_ll );
} else {
if (temp_ll != NULL)
my_free( temp_ll );
}
/*
* file too big
*/
if (*rc != OK)
error( WARNING, window->bottom_line, dir3 );
if (*rc == OK) {
g_status.copied = FALSE;
copy_line( dest );
lens = block_start->len - bc;
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( bc >= 0 );
assert( bc <= MAX_LINE_LENGTH );
assert( rcol >= 0 );
_fmemcpy( g_status.line_buff+rcol, block_start->line+bc, lens );
lens = rcol + lens;
g_status.line_buff_len = lens;
*rc = un_copy_line( dest, &d_w, TRUE );
}
source = block_start->next;
for (li=br+1; li < er && *rc == OK; li++) {
lens = source->len;
temp_ll = (line_list_ptr)my_malloc( sizeof(line_list_struc), rc );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
l = (text_ptr)my_malloc( lens * sizeof(char), rc );
if (*rc == OK) {
if (lens > 0)
_fmemcpy( l, source->line, lens );
temp_ll->line = l;
temp_ll->len = lens;
temp_ll->dirty = TRUE;
if (dest->next != NULL) {
dest->next->prev = temp_ll;
temp_ll->next = dest->next;
dest->next = temp_ll;
temp_ll->prev = dest;
} else {
temp_ll->next = dest;
if (dest->prev != NULL)
dest->prev->next = temp_ll;
temp_ll->prev = dest->prev;
dest->prev = temp_ll;
if (temp_ll->prev == NULL)
window->file_info->line_list = temp_ll;
}
dest = temp_ll;
source = source->next;
} else {
/*
* file too big
*/
error( WARNING, window->bottom_line, dir3 );
if (l != NULL)
my_free( l );
if (temp_ll != NULL)
my_free( temp_ll );
*rc = WARNING;
}
}
} else if (action == MOVE) {
/*
* is the dest on the same line as the block_start?
*/
if (ptoul( dest ) == ptoul( block_start )) {
/*
* move the text between rcol and bc in block_start->line
* to block_end->line + ec.
*/
lens = bc - rcol;
lend = block_end->len - (ec + 1);
g_status.copied = FALSE;
copy_line( block_end );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( lend >= 0 );
assert( lend <= MAX_LINE_LENGTH );
assert( ec + lens + 1 <= MAX_LINE_LENGTH );
assert( rcol >= 0 );
_fmemmove( g_status.line_buff + ec + lens + 1,
g_status.line_buff + ec + 1, lend );
_fmemcpy( g_status.line_buff+ec+1, block_start->line+rcol, lens );
g_status.line_buff_len = block_end->len + lens;
*rc = un_copy_line( block_end, &d_w, TRUE );
/*
* now, remove the text between rcol and bc on block_start->line
*/
if (*rc == OK) {
lend = block_start->len - bc;
copy_line( block_start );
assert( lend >= 0 );
assert( lend < MAX_LINE_LENGTH );
_fmemmove( g_status.line_buff + rcol,
g_status.line_buff + bc, lend );
assert( block_start->len - (bc - rcol) >= 0 );
assert( block_start->len - (bc - rcol) <= MAX_LINE_LENGTH );
g_status.line_buff_len = block_start->len - (bc - rcol);
*rc = un_copy_line( block_start, &d_w, TRUE );
}
/*
* is the dest on the same line as the block_end?
*/
} else if (ptoul( dest ) == ptoul( block_end )) {
/*
* move the text between rcol and ec on block_end->line to
* block_start->line + bc.
*/
lens = rcol - ec;
lend = block_start->len - bc;
g_status.copied = FALSE;
copy_line( block_start );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( lend >= 0 );
assert( lend <= MAX_LINE_LENGTH );
assert( bc + lens <= MAX_LINE_LENGTH );
assert( ec + 1 >= 0 );
_fmemmove( g_status.line_buff + bc + lens,
g_status.line_buff + bc, lend );
_fmemcpy( g_status.line_buff+bc, block_end->line+ec+1, lens );
assert( block_start->len + lens >= 0 );
assert( block_start->len + lens <= MAX_LINE_LENGTH );
g_status.line_buff_len = block_start->len + lens;
*rc = un_copy_line( block_start, &d_w, TRUE );
/*
* now, remove the text on block_end->line between rcol and ec
*/
if (*rc == OK) {
lend = block_end->len - (rcol + 1);
copy_line( block_end );
assert( lend >= 0 );
assert( lend <= MAX_LINE_LENGTH );
assert( ec + 1 >= 0 );
assert( rcol + 1 >= 0 );
assert( ec + 1 <= MAX_LINE_LENGTH );
assert( rcol + 1 <= MAX_LINE_LENGTH );
assert( block_end->len - (rcol - ec) >= 0 );
assert( block_end->len - (rcol - ec) <= MAX_LINE_LENGTH );
_fmemmove( g_status.line_buff + ec + 1,
g_status.line_buff + rcol + 1, lend );
g_status.line_buff_len = block_end->len - (rcol - ec);
*rc = un_copy_line( block_end, &d_w, TRUE );
}
} else {
lens = dest->len - rcol;
assert( ec + 1 >= 0 );
assert( ec + 1 <= MAX_LINE_LENGTH );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( rcol >= 0 );
assert( rcol <= MAX_LINE_LENGTH );
_fmemcpy( g_status.line_buff, block_end->line, ec+1 );
_fmemcpy( g_status.line_buff+ec+1, dest->line+rcol, lens );
lens += ec + 1;
g_status.line_buff_len = lens;
temp_ll = (line_list_ptr)my_malloc( sizeof(line_list_struc), rc );
if (*rc == OK) {
temp_ll->line = NULL;
temp_ll->len = 0;
temp_ll->dirty = FALSE;
g_status.copied = TRUE;
*rc = un_copy_line( temp_ll, &d_w, TRUE );
if (*rc != ERROR) {
dest->next->prev = temp_ll;
temp_ll->next = dest->next;
dest->next = temp_ll;
temp_ll->prev = dest;
} else
if (temp_ll != NULL)
my_free( temp_ll );
} else {
if (temp_ll != NULL)
my_free( temp_ll );
}
/*
* file too big
*/
if (*rc != OK)
error( WARNING, window->bottom_line, dir3 );
if (*rc == OK) {
copy_line( dest );
lens = block_start->len - bc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -