📄 block.c
字号:
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;
assert( bc >= 0 );
assert( bc <= MAX_LINE_LENGTH );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( rcol >= 0 );
assert( rcol <= MAX_LINE_LENGTH );
_fmemcpy( g_status.line_buff+rcol, block_start->line+bc, lens );
g_status.line_buff_len = lens + rcol;
*rc = un_copy_line( dest, &d_w, TRUE );
dest->dirty = TRUE;
}
if (*rc == OK && ptoul( block_start->next ) != ptoul( block_end )) {
block_start->next->prev = dest;
temp_ll->prev = block_end->prev;
block_end->prev->next = temp_ll;
dest->next = block_start->next;
}
if (*rc == OK) {
copy_line( block_start );
detab_linebuff( );
lend = bc;
lens = block_end->len - (ec + 1);
assert( bc >= 0 );
assert( bc <= MAX_LINE_LENGTH );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( lend >= 0 );
assert( lend <= MAX_LINE_LENGTH );
assert( ec + 1 >= 0 );
assert( ec + 1 <= MAX_LINE_LENGTH );
assert( lens + lend >= 0 );
assert( lens + lend <= MAX_LINE_LENGTH );
_fmemcpy( g_status.line_buff+bc, block_end->line+ec+1, lens );
g_status.line_buff_len = lend + lens;
*rc = un_copy_line( block_start, &s_w, TRUE );
block_start->dirty = TRUE;
block_start->next = block_end->next;
block_end->next->prev = block_start;
if (block_end->line != NULL)
my_free( block_end->line );
my_free( block_end );
}
}
} else if (action == DELETE) {
copy_line( block_start );
lens = block_end->len - (ec + 1);
assert( bc >= 0 );
assert( bc <= MAX_LINE_LENGTH );
assert( lens >= 0 );
assert( lens <= MAX_LINE_LENGTH );
assert( ec + 1 >= 0 );
assert( ec + 1 <= MAX_LINE_LENGTH );
assert( bc + lens >= 0 );
assert( bc + lens <= MAX_LINE_LENGTH );
_fmemcpy( g_status.line_buff+bc, block_end->line + ec+1, lens );
g_status.line_buff_len = bc + lens;
*rc = un_copy_line( block_start, &s_w, TRUE );
block_start->dirty = TRUE;
source = block_start->next;
block_start->next = block_end->next;
block_end->next->prev = block_start;
block_end->next = NULL;
while (source != NULL) {
temp_ll = source;
source = source->next;
if (temp_ll->line != NULL)
my_free( temp_ll->line );
my_free( temp_ll );
}
}
if (*rc == OK) {
diff = er - 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_box_block
* Purpose: delete, move, copy, or kopy a BOX block
* Date: June 5, 1991
* Passed: window: pointer to destination window (current window)
* source_window: pointer to source window
* action: block action -- OVERLAY, FILL, etc...
* source_file: pointer to source file structure
* dest_file: pointer to destination file
* source: pointer to source node
* dest: pointer to destination node
* br: beginning line number in marked block
* er: ending line number in marked block
* block_inc: increment used to number a block
* rline: current line number in destination file
* block_num: starting number when numbering a block
* block_just: LEFT or RIGHT justified numbers in block
* fill_char: character to fill a block
* same: are source and destination files same? T or F
* block_len: width of box block
* bc: beginning column of block
* ec: ending column of block
* rcol: current column of cursor
* rc: return code
*/
void do_box_block( WINDOW *window, WINDOW *source_window, int action,
file_infos *source_file, file_infos *dest_file,
line_list_ptr source, line_list_ptr dest, long br,
long er, long block_inc,
long rline, long block_num, int block_just, int fill_char,
int same, int block_len, int bc, int ec, int rcol, int *rc )
{
line_list_ptr p; /* temporary list pointer */
int lens; /* length of source line */
int lend; /* length of destination line */
int add; /* characters being added from another line */
char *block_buff;
char *swap_buff;
int xbc, xec; /* temporary column variables */
long li; /* temporary line variables */
long dest_add; /* number of bytes added to destination file */
WINDOW s_w, d_w; /* a couple of temporary WINDOWs for BOX stuff */
int padded_file;
WINDOW *w;
padded_file = FALSE;
dup_window_info( &s_w, source_window );
dup_window_info( &d_w, window );
s_w.rline = br;
s_w.ll = source;
s_w.visible = FALSE;
d_w.rline = rline;
d_w.ll = dest;
d_w.visible = FALSE;
block_buff = (char *)calloc( BUFF_SIZE + 2, sizeof(char) );
swap_buff = (char *)calloc( BUFF_SIZE + 2, sizeof(char) );
if (block_buff == NULL || swap_buff == NULL) {
error( WARNING, window->bottom_line, block4 );
*rc = ERROR;
}
/*
* special case for block actions. since block actions always
* move forward thru the file, overlapping text in an OVERLAY
* action don't do right. make the operation start at the end
* of the block and work backwards.
*/
if (*rc == OK && (action == OVERLAY || action == SWAP) &&
same && rline > br && rline <= er) {
/*
* see if we need to add padd lines at eof.
*/
dest_add = rline - br;
if (dest_add + er > window->file_info->length) {
dest_add = dest_add - (window->file_info->length - er);
p = dest_file->line_list_end->prev;
for (; dest_add > 0 && *rc == OK; dest_add--)
*rc = pad_dest_line( window, dest_file, p );
padded_file = TRUE;
}
/*
* move source and dest pointers to the end of the OVERLAY
*/
for (li=er-br; li > 0; li--) {
load_undo_buffer( dest_file, dest->line, dest->len );
dest = dest->next;
++d_w.rline;
source = source->next;
++s_w.rline;
}
/*
* work backwards so the overlapped OVERLAY block don't use
* overlayed text to fill the block. same for SWAPPing blocks.
*/
for (li=er; *rc == OK && li >= br && !g_status.control_break;
li--, s_w.rline--, d_w.rline--) {
lens = find_end( source->line, source->len );
lend = find_end( dest->line, dest->len );
if (lens != 0 || lend != 0) {
load_box_buff( block_buff, source, bc, ec, ' ' );
if (action == SWAP)
load_box_buff( swap_buff, dest, rcol, rcol+block_len, ' ' );
*rc = copy_buff_2file( &d_w, block_buff, dest, rcol,
block_len, action );
dest->dirty = TRUE;
if (action == SWAP) {
add = 0;
*rc = copy_buff_2file( &s_w, swap_buff, source, bc,
block_len, action );
source->dirty = TRUE;
}
}
source = source->prev;
dest = dest->prev;
}
} else {
if (action == FILL)
block_fill( block_buff, fill_char, block_len );
for (li=br; *rc == OK && li <= er && !g_status.control_break;
li++, s_w.rline++, d_w.rline++) {
lens = find_end( source->line, source->len );
lend = find_end( dest->line, dest->len );
switch (action) {
case FILL :
case NUMBER :
case DELETE :
case MOVE :
load_undo_buffer( source_file, source->line, source->len );
break;
case COPY :
case KOPY :
case OVERLAY :
load_undo_buffer( dest_file, dest->line, dest->len );
break;
}
/*
* with FILL and NUMBER operations, we're just adding chars
* to the file at the source location. we don't have to
* worry about bookkeeping.
*/
if (action == FILL || action == NUMBER) {
if (action == NUMBER) {
number_block_buff( block_buff, block_len, block_num, block_just );
block_num += block_inc;
}
*rc = copy_buff_2file( &s_w, block_buff, source, rcol,
block_len, action );
source->dirty = TRUE;
/*
* if we are doing a BOX action and both the source and
* destination are 0 then we have nothing to do.
*/
} else if (lens != 0 || lend != 0) {
/*
* do actions that may require adding to file
*/
if (action == MOVE || action == COPY || action == KOPY ||
action == OVERLAY || action == SWAP) {
xbc = bc;
xec = ec;
if (action != OVERLAY && action != SWAP && same) {
if (rcol < bc && rline > br && rline <=er)
if (li >= rline) {
xbc = bc + block_len;
xec = ec + block_len;
}
}
load_box_buff( block_buff, source, xbc, xec, ' ' );
if (action == SWAP)
load_box_buff( swap_buff, dest, rcol, rcol+block_len, ' ' );
*rc = copy_buff_2file( &d_w, block_buff, dest, rcol,
block_len, action );
dest->dirty = TRUE;
if (action == SWAP && *rc == OK) {
*rc = copy_buff_2file( &s_w, swap_buff, source, xbc,
block_len, action );
source->dirty = TRUE;
}
}
/*
* do actions that may require deleting from file
*/
if (action == MOVE || action == DELETE) {
lens = find_end( source->line, source->len );
if (lens >= (bc + 1)) {
source->dirty = TRUE;
add = block_len;
xbc = bc;
if (lens <= (ec + 1))
add = lens - bc;
if (same && action == MOVE) {
if (rcol < bc && rline >= br && rline <=er)
if (li >= rline) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -