📄 utils.c
字号:
plen = strlen( prompt );
answer = buffer + plen;
strcpy( answer, name );
/*
* let user edit default string
*/
regx_help_on = FALSE;
len = strlen( answer );
col = strlen( buffer );
g_status.prompt_line = line;
g_status.prompt_col = col;
cp = answer + len;
normal = g_display.text_color;
save_screen_line( 0, line, line_buff );
s_output( buffer, line, 0, color );
eol_clear( col, line, normal );
for (stop = FALSE; stop == FALSE;) {
if (regx_help_on == TRUE)
xygoto( -1, -1 );
else
xygoto( col, line );
if (g_status.macro_executing) {
next = g_status.macro_next;
g_status.macro_next = macro.strokes[g_status.macro_next].next;
if (g_status.macro_next != -1) {
c = macro.strokes[g_status.macro_next].key;
func = getfunc( c );
if (func == PlayBack) {
stop = TRUE;
g_status.macro_next = next;
}
} else {
c = 0x100;
func = AbortCommand;
stop = TRUE;
}
} else {
if (local_macro == FALSE) {
c = getkey( );
func = getfunc( c );
/*
* User may have redefined the Enter and ESC keys. Make the Enter
* key perform a Rturn in this function. Make the ESC key do an
* AbortCommand.
*/
if (c == RTURN)
func = Rturn;
else if (c == ESC)
func = AbortCommand;
if (func == PlayBack) {
local_macro = TRUE;
next = macro.first_stroke[ c-256 ];
c = macro.strokes[next].key;
func = getfunc( c );
next = macro.strokes[next].next;
} else {
g_status.key_pressed = c;
record_keys( line );
}
} else {
if (next != -1) {
c = macro.strokes[next].key;
next = macro.strokes[next].next;
} else {
local_macro = FALSE;
c = 0x100;
}
func = getfunc( c );
}
}
if (c == _F1)
func = Help;
if (regx_help_on == TRUE && g_status.current_window != NULL) {
redraw_screen( g_status.current_window );
s_output( buffer, line, 0, color );
eol_clear( col, line, normal );
s_output( cp, line, col, color );
regx_help_on = FALSE;
} else {
switch (func) {
case Help :
if ((g_status.command == FindRegX ||
g_status.command == RepeatFindRegX) &&
regx_help_on == FALSE) {
regx_help_on = TRUE;
for (i=3,pp=regx_help; *pp != NULL; pp++, i++)
s_output( *pp, i, 12, g_display.help_color );
}
break;
case ToggleSearchCase :
mode.search_case = mode.search_case == IGNORE ? MATCH : IGNORE;
build_boyer_array( );
show_search_case( );
break;
case Rturn :
case NextLine :
case BegNextLine :
answer[len] = '\0';
assert( strlen( answer ) < MAX_COLS );
strcpy( name, answer );
/*
* finished
*/
stop = TRUE;
break;
case BackSpace :
/*
* delete to left of cursor
*/
if (cp > answer) {
for (p=cp-1; p < answer+len; p++) {
*p = *(p+1);
}
--len;
--col;
--cp;
c_output( ' ', plen+len, line, normal );
s_output( cp, line, col, color );
*(answer + len) = '\0';
}
break;
case DeleteChar :
/*
* delete char under cursor
*/
if (*cp) {
for (p=cp; p < answer+len; p++) {
*p = *(p+1);
}
--len;
c_output( ' ', plen+len, line, normal );
s_output( cp, line, col, color );
*(answer + len) = '\0';
}
break;
case DeleteLine :
/*
* delete current line
*/
col = plen;
cp = answer;
*cp = '\0';
len = 0;
eol_clear( col, line, normal );
break;
case AbortCommand :
stop = TRUE;
break;
case CharLeft :
/*
* move cursor left
*/
if (cp > answer) {
col--;
cp--;
}
break;
case CharRight :
/*
* move cursor right
*/
if (*cp) {
col++;
cp++;
}
break;
case BegOfLine :
/*
* move cursor to start of line
*/
col = plen;
cp = answer;
break;
case EndOfLine :
/*
* move cursor to end of line
*/
col = plen + len;
cp = answer + len;
break;
default :
if (c < 0x100) {
/*
* insert character at cursor
*/
if (first) {
/*
* delete previous answer
*/
col = plen;
cp = answer;
*cp = '\0';
len = 0;
eol_clear( col, line, normal );
}
/*
* insert new character
*/
if (col < g_display.ncols-1) {
if (*cp == '\0') {
++len;
*(answer + len) = '\0';
}
*cp = (char)c;
c_output( c, col, line, color );
++cp;
++col;
}
}
break;
}
}
first = FALSE;
}
restore_screen_line( 0, line, line_buff );
return( func == AbortCommand ? ERROR : OK );
}
/*
* Name: get_sort_order
* Purpose: To prompt the user and get sort direction
* Date: June 5, 1992
* Passed: window
* Returns: OK if user entered something
* ERROR if user aborted the command
*/
int get_sort_order( WINDOW *window )
{
register int c;
int col;
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute */
save_screen_line( 0, window->bottom_line, line_buff );
/*
* sort ascending or descending
*/
s_output( utils4, window->bottom_line, 0, g_display.message_color );
c = strlen( utils4 );
eol_clear( c, window->bottom_line, g_display.text_color );
xygoto( c, window->bottom_line );
do {
c = getkey( );
col = getfunc( c );
if (c == ESC)
col = AbortCommand;
} while (col != AbortCommand && c != 'A' && c != 'a' &&
c != 'D' && c != 'd');
switch ( c ) {
case 'A' :
case 'a' :
sort.direction = ASCENDING;
break;
case 'D' :
case 'd' :
sort.direction = DESCENDING;
break;
default :
col = AbortCommand;
break;
}
restore_screen_line( 0, window->bottom_line, line_buff );
return( col == AbortCommand ? ERROR : OK );
}
/*
* Name: get_replace_direction
* Purpose: To prompt the user and get replace string direction
* Date: October 31, 1992
* Passed: window
* Returns: OK if user entered something
* ERROR if user aborted the command
*/
int get_replace_direction( WINDOW *window )
{
register int c;
int col;
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute */
save_screen_line( 0, window->bottom_line, line_buff );
/*
* replace forward or backward
*/
s_output( utils5, window->bottom_line, 0, g_display.message_color );
c = strlen( utils5 );
eol_clear( c, window->bottom_line, g_display.text_color );
xygoto( c, window->bottom_line );
do {
c = getkey( );
col = getfunc( c );
if (c == ESC)
col = AbortCommand;
} while (col != AbortCommand && c != 'F' && c != 'f' &&
c != 'B' && c != 'b');
switch ( c ) {
case 'F' :
case 'f' :
c = FORWARD;
break;
case 'B' :
case 'b' :
c = BACKWARD;
break;
default :
c = ERROR;
}
restore_screen_line( 0, window->bottom_line, line_buff );
return( col == AbortCommand ? ERROR : c );
}
/*
* Name: get_yn
* Purpose: To input a response of yes or no.
* Date: October 1, 1989
* Returns: the user's answer. A_??? - see tdestr.h
*/
int get_yn( void )
{
int c; /* the user's response */
register int rc; /* return code */
do {
c = getkey( );
rc = getfunc( c );
if (c== ESC)
rc = AbortCommand;
} while (rc != AbortCommand && c != 'Y' && c != 'y' &&
c != 'N' && c != 'n');
if (rc == AbortCommand || c == ESC)
rc = ERROR;
else {
switch ( c ) {
case 'Y' :
case 'y' :
rc = A_YES;
break;
case 'N' :
case 'n' :
rc = A_NO;
break;
}
}
return( rc );
}
/*
* Name: get_lr
* Purpose: To input a response of yes or no.
* Date: June 1, 1991
* Returns: the user's answer, LEFT or RIGHT.
*/
int get_lr( void )
{
int c; /* the user's response */
register int rc; /* return code */
for (rc=OK; rc == OK;) {
c = getkey( );
if (getfunc( c ) == AbortCommand || c == ESC)
rc = ERROR;
else {
switch ( c ) {
case 'L' :
case 'l' :
rc = LEFT;
break;
case 'R' :
case 'r' :
rc = RIGHT;
break;
}
}
}
return( rc );
}
/*
* Name: get_bc
* Purpose: To input a response of beginning or current cursor postion
* Date: October 31, 1992
* Returns: the user's answer, Beginning or Current.
*/
int get_bc( void )
{
int c; /* the user's response */
register int rc; /* return code */
for (rc=OK; rc == OK;) {
c = getkey( );
if (getfunc( c ) == AbortCommand || c == ESC)
rc = ERROR;
else {
switch ( c ) {
case 'B' :
case 'b' :
rc = BEGINNING;
break;
case 'C' :
case 'c' :
rc = CURRENT;
break;
}
}
}
return( rc );
}
/*
* Name: get_oa
* Purpose: To input a response of overwrite or append.
* Date: October 1, 1989
* Returns: the user's answer. A_??? - see tdestr.h
*/
int get_oa( void )
{
int c; /* the user's response */
register int rc; /* return code */
int func;
rc = 0;
while (rc != AbortCommand && rc != A_OVERWRITE && rc != A_APPEND) {
c = getkey( );
func = getfunc( c );
if (func == AbortCommand || c == ESC)
rc = AbortCommand;
switch ( c ) {
case 'O' :
case 'o' :
rc = A_OVERWRITE;
break;
case 'A' :
case 'a' :
rc = A_APPEND;
break;
}
}
return( rc );
}
/*
* Name: show_eof
* Purpose: display eof message
* Date: September 16, 1991
* Notes: line: ususally, line to is display "<=== eof ===>"
*/
void show_eof( WINDOW *window )
{
register int color;
char temp[MAX_COLS+2];
assert( strlen( mode.eof ) < MAX_COLS );
strcpy( temp, mode.eof );
color = window->end_col + 1 - window->start_col;
if (strlen( temp ) > (unsigned)color)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -