📄 block.c
字号:
else
do_box_block( window, source_window, action,
source_file, dest_file, source, dest, br, er,
block_inc, rline, block_num, block_just, fill_char,
same, block_len, bc, ec, rcol, &rc );
dest_file->modified = TRUE;
dest_file->dirty = GLOBAL;
if (action == MOVE || action == DELETE || action == FILL || action==NUMBER) {
source_file->modified = TRUE;
source_file->dirty = GLOBAL;
}
if (action == KOPY) {
if (same && !source_first && block_type == LINE && rc != ERROR) {
number = (er+1) - br;
source_file->block_br += number;
source_file->block_er += number;
}
} else if (action != FILL && action != OVERLAY && action != NUMBER)
unmark_block( window );
show_avail_mem( );
g_status.copied = FALSE;
return( rc );
}
void do_line_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 br, long er, int *rc )
{
line_list_ptr temp_ll;
text_ptr l;
int lens;
long li;
long diff;
if (action == COPY || action == KOPY) {
assert( br >= 1 );
assert( br <= source_file->length );
assert( er >= br );
assert( er <= source_file->length );
for (li=br; li <= er && *rc == OK; li++) {
lens = source->len;
assert( lens * sizeof(char) < MAX_LINE_LENGTH );
l = (text_ptr)my_malloc( lens * sizeof(char), rc );
temp_ll = (line_list_ptr)my_malloc( sizeof(line_list_struc), 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 {
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_cursors( dest_file );
if (dest_file != source_file)
restore_cursors( source_file );
show_avail_mem( );
}
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;
text_ptr l;
int lens;
int lend;
long li;
long diff;
WINDOW s_w, d_w;
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;
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 );
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 );
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) {
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 );
}
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 {
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) {
if (ptoul( dest ) == ptoul( block_start )) {
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 );
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 );
}
} else if (ptoul( dest ) == ptoul( block_end )) {
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 );
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 );
}
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_cursors( dest_file );
if (dest_file != source_file)
restore_cursors( source_file );
show_avail_mem( );
}
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;
int lens;
int lend;
int add;
char *block_buff;
char *swap_buff;
int xbc, xec;
long li;
long dest_add;
WINDOW s_w, d_w;
int padded_file;
WINDOW *w;
padded_file = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -