📄 block.c
字号:
int len;
int bc;
int ec;
int last_c;
long lbegin;
long lend;
long l;
int color;
int rc;
color = g_display.message_color;
entab_linebuff( );
if (un_copy_line( window->ll, window, TRUE ) == ERROR)
return( ERROR );
rc = OK;
prompt_line = window->bottom_line;
save_screen_line( 0, prompt_line, line_buff );
assert( strlen( block13 ) < MAX_COLS );
strcpy( answer, block13 );
col = strlen( answer );
s_output( answer, prompt_line, 0, color );
eol_clear( col, prompt_line, g_display.text_color );
xygoto( col, prompt_line );
func = col = 0;
while (col != 'f' && col != 'F' && col != 'b' && col != 'B' &&
func != AbortCommand) {
col = getkey( );
func = getfunc( col );
if (col == ESC || func == AbortCommand)
rc = ERROR;
}
if (rc == OK) {
fflush( stdprn );
if (ceh.flag == ERROR)
rc = ERROR;
}
if (rc != ERROR) {
file = window->file_info;
block_type = NOTMARKED;
if (col == 'f' || col == 'F') {
block_start = file->line_list;
lend = l = file->length;
} else {
check_block( );
if (g_status.marked == TRUE) {
file = g_status.marked_file;
block_start = file->block_start;
block_type = file->block_type;
lend = l = file->block_er + 1l - file->block_br;
} else
rc = ERROR;
}
if (rc != ERROR) {
eol_clear( 0, prompt_line, color );
s_output( block14, prompt_line, 0, color );
ltoa( l, answer, 10 );
s_output( answer, prompt_line, 25, color );
xygoto( 14, prompt_line );
if (block_type == BOX || block_type == STREAM) {
bc = file->block_bc;
ec = file->block_ec;
last_c = ec + 1 - bc;
}
p = g_status.line_buff;
lbegin = 1;
for (col=OK; l>0 && col == OK && !g_status.control_break; l--) {
ltoa( lbegin, answer, 10 );
s_output( answer, prompt_line, 14, color );
g_status.copied = FALSE;
if (block_type == BOX) {
load_box_buff( p, block_start, bc, ec, ' ' );
len = last_c;
} else if (block_type == STREAM && lbegin == 1) {
len = block_start->len;
detab_a_line( block_start->line, &len );
if (bc > len)
len = 0;
else {
if (lbegin == lend) {
load_box_buff( p, block_start, bc, ec, ' ' );
len = last_c;
} else {
len = len - bc;
g_status.copied = TRUE;
assert( len >= 0 );
assert( len < MAX_LINE_LENGTH );
_fmemcpy( p, block_start->line + bc, len );
}
}
} else if (block_type == STREAM && l == 1L) {
copy_line( block_start );
detab_linebuff( );
len = g_status.line_buff_len;
if (len > ec + 1)
len = ec + 1;
} else {
copy_line( block_start );
len = g_status.line_buff_len;
}
assert( len >= 0 );
assert( len < MAX_LINE_LENGTH );
*(p+len) = '\r';
++len;
*(p+len) = '\n';
++len;
if (fwrite( p, sizeof( char ), len, stdprn ) < (unsigned)len ||
ceh.flag == ERROR)
col = ERROR;
block_start = block_start->next;
++lbegin;
}
g_status.copied = FALSE;
if (ceh.flag != ERROR)
fflush( stdprn );
else
rc = ERROR;
}
}
g_status.copied = FALSE;
restore_screen_line( 0, prompt_line, line_buff );
return( rc );
}
int get_block_fill_char( WINDOW *window, int *c )
{
char answer[MAX_COLS];
char line_buff[(MAX_COLS+1)*2];
register int col;
int prompt_line;
int rc;
rc = OK;
prompt_line = window->bottom_line;
save_screen_line( 0, prompt_line, line_buff );
assert( strlen( block15 ) < MAX_COLS );
strcpy( answer, block15 );
s_output( answer, prompt_line, 0, g_display.message_color );
col = strlen( answer );
eol_clear( col, prompt_line, g_display.text_color );
xygoto( col, prompt_line );
col = getkey( );
if (col >= 256)
rc = ERROR;
else
*c = col;
restore_screen_line( 0, prompt_line, line_buff );
return( rc );
}
int get_block_numbers( WINDOW *window, long *block_num, long *block_inc,
int *just )
{
char answer[MAX_COLS];
int prompt_line;
register int rc;
char line_buff[(MAX_COLS+1)*2];
register int col;
prompt_line = window->bottom_line;
answer[0] = '\0';
rc = get_name( block16, prompt_line, answer, g_display.message_color );
if (answer[0] == '\0')
rc = ERROR;
if (rc != ERROR) {
*block_num = atol( answer );
answer[0] = '1';
answer[1] = '\0';
rc = get_name( block17, prompt_line, answer, g_display.message_color );
if (answer[0] == '\0')
rc = ERROR;
if (rc != ERROR) {
*block_inc = atol( answer );
save_screen_line( 0, prompt_line, line_buff );
assert( strlen( block18 ) < MAX_COLS );
strcpy( answer, block18 );
s_output( answer, prompt_line, 0, g_display.message_color );
col = strlen( answer );
eol_clear( col, prompt_line, g_display.text_color );
xygoto( col, prompt_line );
rc = get_lr( );
if (rc != ERROR) {
*just = rc;
rc = OK;
}
restore_screen_line( 0, prompt_line, line_buff );
}
}
return( rc );
}
int block_trim_trailing( WINDOW *window )
{
int prompt_line;
int rc;
line_list_ptr p;
file_infos *file;
WINDOW *sw, s_w;
long er;
int trailing;
prompt_line = window->bottom_line;
entab_linebuff( );
rc = un_copy_line( window->ll, window, TRUE );
check_block( );
if (rc != ERROR && g_status.marked == TRUE) {
trailing = mode.trailing;
mode.trailing = TRUE;
file = g_status.marked_file;
if (file->block_type != LINE) {
error( WARNING, prompt_line, block21 );
return( ERROR );
}
sw = g_status.window_list;
for (; ptoul( sw->file_info ) != ptoul( file );)
sw = sw->next;
if (mode.do_backups == TRUE) {
file->modified = TRUE;
rc = backup_file( sw );
}
dup_window_info( &s_w, sw );
s_w.visible = FALSE;
p = file->block_start;
er = file->block_er;
s_w.rline = file->block_br;
for (; rc == OK && s_w.rline <= er && !g_status.control_break; s_w.rline++) {
copy_line( p );
rc = un_copy_line( p, &s_w, TRUE );
p = p->next;
}
g_status.copied = FALSE;
file->dirty = GLOBAL;
mode.trailing = trailing;
show_avail_mem( );
}
return( rc );
}
int block_email_reply( WINDOW *window )
{
int prompt_line;
int add;
int len;
int rc;
char *source;
char *dest;
line_list_ptr p;
file_infos *file;
WINDOW *sw, s_w;
long er;
prompt_line = window->bottom_line;
entab_linebuff( );
rc = un_copy_line( window->ll, window, TRUE );
check_block( );
if (rc != ERROR && g_status.marked == TRUE) {
file = g_status.marked_file;
if (file->block_type != LINE) {
error( WARNING, prompt_line, block25 );
return( ERROR );
}
sw = g_status.window_list;
for (; ptoul( sw->file_info ) != ptoul( file );)
sw = sw->next;
if (mode.do_backups == TRUE) {
file->modified = TRUE;
rc = backup_file( sw );
}
dup_window_info( &s_w, sw );
s_w.visible = FALSE;
s_w.rline = file->block_br;
p = file->block_start;
er = file->block_er;
for (; rc == OK && s_w.rline <= er && !g_status.control_break;
s_w.rline++) {
copy_line( p );
if (*(p->line) == '>')
add = 1;
else
add = 2;
len = g_status.line_buff_len;
if (len + add < MAX_LINE_LENGTH) {
source = g_status.line_buff;
dest = source + add;
assert( len >= 0 );
assert( len < MAX_LINE_LENGTH );
assert( len + add < MAX_LINE_LENGTH );
memmove( dest, source, len );
*source = '>';
if (add > 1)
*(source+1) = ' ';
g_status.line_buff_len = len + add;
rc = un_copy_line( p, &s_w, TRUE );
}
p = p->next;
g_status.copied = FALSE;
}
g_status.copied = FALSE;
file->dirty = GLOBAL;
show_avail_mem( );
}
return( OK );
}
int block_convert_case( WINDOW *window )
{
int len;
int block_type;
line_list_ptr begin;
register file_infos *file;
WINDOW *sw;
long number;
long er;
unsigned int count;
int bc, ec;
int block_len;
int rc;
void (*char_func)( text_ptr, unsigned int );
entab_linebuff( );
if (un_copy_line( window->ll, window, TRUE ) == ERROR)
return( ERROR );
rc = OK;
check_block( );
if (g_status.marked == TRUE) {
switch (g_status.command) {
case BlockUpperCase :
char_func = upper_case;
break;
case BlockLowerCase :
char_func = lower_case;
break;
case BlockRot13 :
char_func = rot13;
break;
case BlockFixUUE :
char_func = fix_uue;
break;
case BlockStripHiBit :
char_func = strip_hi;
break;
default :
return( ERROR );
}
file = g_status.marked_file;
file->modified = TRUE;
if (mode.do_backups == TRUE) {
sw = g_status.window_list;
for (; ptoul( sw->file_info ) != ptoul( file );)
sw = sw->next;
rc = backup_file( sw );
}
if (rc == OK) {
block_type = file->block_type;
ec = file->block_ec;
begin = file->block_start;
er = file->block_er;
block_len = ec + 1 - file->block_bc;
for (number=file->block_br; number <= er; number++) {
begin->dirty = TRUE;
count = len = begin->len;
bc = 0;
if (block_type == STREAM) {
if (number == file->block_br) {
bc = file->block_bc;
if (len < file->block_bc) {
count = 0;
bc = len;
}
}
if (number == file->block_er) {
if (ec < len)
ec = len;
count = ec - bc + 1;
}
} else if (block_type == BOX) {
bc = file->block_bc;
count = len >= ec ? block_len : len - bc;
}
if (len > bc) {
assert( count < MAX_LINE_LENGTH );
assert( bc >= 0 );
assert( bc < MAX_LINE_LENGTH );
(*char_func)( begin->line+bc, count );
}
begin = begin->next;
}
g_status.copied = FALSE;
file->dirty = GLOBAL;
}
} else
rc = ERROR;
return( rc );
}
void upper_case( text_ptr s, size_t count )
{
if (s != NULL) {
for (; count > 0; s++, count-- ) {
if (*s >= 'a' && *s <= 'z')
*s ^= 0x20;
}
}
}
void lower_case( text_ptr s, size_t count )
{
if (s != NULL) {
for (; count > 0; s++, count-- ) {
if (*s >= 'A' && *s <= 'Z')
*s |= 0x20;
}
}
}
void rot13( text_ptr s, size_t count )
{
register size_t c;
c = *s;
}
void fix_uue( text_ptr s, size_t count )
{
if (s != NULL) {
for (; count > 0; s++, count-- ) {
switch (*s) {
case 0x5d :
*s = 0x7c;
break;
case 0xd5 :
*s = 0x5b;
break;
case 0xe5 :
*s = 0x5d;
break;
default :
break;
}
}
}
}
void strip_hi( text_ptr s, size_t count )
{
if (s != NULL) {
for (; count > 0; s++, count-- ) {
if (*s >= 0x80)
*s &= 0x7f;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -