📄 ed.c
字号:
* Name: toggle_crlf
* Purpose: toggle crlf mode
* Date: November 27, 1991
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_crlf( WINDOW *window )
{
register WINDOW *w;
++window->file_info->crlf;
if (window->file_info->crlf > BINARY)
window->file_info->crlf = CRLF;
w = g_status.window_list;
while (w != NULL) {
if (w->file_info == window->file_info && w->visible)
show_crlf_mode( w );
w = w->next;
}
return( OK );
}
/*
* Name: toggle_ww
* Purpose: toggle word wrap mode
* Date: November 27, 1991
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_ww( WINDOW *arg_filler )
{
++mode.word_wrap;
if (mode.word_wrap > DYNAMIC_WRAP)
mode.word_wrap = NO_WRAP;
show_wordwrap_mode( );
return( OK );
}
/*
* Name: toggle_trailing
* Purpose: toggle eleminating trainling space at eol
* Date: November 25, 1991
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_trailing( WINDOW *arg_filler )
{
mode.trailing = !mode.trailing;
show_trailing( );
return( OK );
}
/*
* Name: toggle_z
* Purpose: toggle writing control z at eof
* Date: November 25, 1991
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_z( WINDOW *arg_filler )
{
mode.control_z = !mode.control_z;
show_control_z( );
return( OK );
}
/*
* Name: toggle_eol
* Purpose: toggle writing eol character at eol
* Date: November 25, 1991
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_eol( WINDOW *arg_filler )
{
register file_infos *file;
mode.show_eol = !mode.show_eol;
for (file=g_status.file_list; file != NULL; file=file->next)
file->dirty = GLOBAL;
return( OK );
}
/*
* Name: toggle_search_case
* Purpose: toggle search case
* Date: September 16, 1991
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_search_case( WINDOW *arg_filler )
{
mode.search_case = (mode.search_case == IGNORE) ? MATCH : IGNORE;
show_search_case( );
build_boyer_array( );
return( OK );
}
/*
* Name: toggle_sync
* Purpose: toggle sync mode
* Date: January 15, 1992
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_sync( WINDOW *arg_filler )
{
mode.sync = !mode.sync;
show_sync_mode( );
return( OK );
}
/*
* Name: toggle_ruler
* Purpose: toggle ruler
* Date: March 5, 1992
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_ruler( WINDOW *arg_filler )
{
register WINDOW *wp;
mode.ruler = !mode.ruler;
wp = g_status.window_list;
while (wp != NULL) {
if (mode.ruler) {
/*
* there has to be more than one line in a window to display a ruler.
* even if the ruler mode is on, we need to check the num of lines.
*/
if (wp->bottom_line - wp->top_line >0) {
if (wp->cline == wp->top_line)
++wp->cline;
if (wp->cline > wp->bottom_line)
wp->cline = wp->bottom_line;
wp->ruler = TRUE;
} else
wp->ruler = FALSE;
} else {
/*
* if this is the first page in a file, then we may need to "pull"
* the file up before displaying the first page.
*/
if (wp->rline == ((wp->cline - wp->ruler) - (wp->top_line - 1)))
--wp->cline;
if (wp->cline < wp->top_line)
wp->cline = wp->top_line;
wp->ruler = FALSE;
}
make_ruler( wp );
setup_window( wp );
if (wp->visible)
redraw_current_window( wp );
wp = wp->next;
}
return( OK );
}
/*
* Name: toggle_tabinflate
* Purpose: toggle inflating tabs
* Date: October 31, 1992
* Passed: arg_filler: argument to satify function prototype
*/
int toggle_tabinflate( WINDOW *arg_filler )
{
register file_infos *file;
mode.inflate_tabs = !mode.inflate_tabs;
for (file=g_status.file_list; file != NULL; file=file->next)
file->dirty = GLOBAL;
show_tab_modes( );
return( OK );
}
/*
* Name: sync
* Purpose: carry out cursor movements in all visible windows
* Date: January 15, 1992
* Passed: window
* Notes: switch sync semaphore when we do this so we don't get into a
* recursive loop. all cursor movement commands un_copy_line before
* moving the cursor off the current line. you MUST make certain
* that the current line is uncopied in the task routines that
* move the cursor off the current line before calling sync.
*/
void sync( WINDOW *window )
{
register WINDOW *wp;
register file_infos *fp;
if (mode.sync && mode.sync_sem) {
/*
* these functions must un_copy a line before sync'ing
*/
#if defined( __MSC__ )
switch (g_status.command) {
case NextLine :
case BegNextLine :
case LineDown :
case LineUp :
case WordRight :
case WordLeft :
case ScreenDown :
case ScreenUp :
case EndOfFile :
case TopOfFile :
case BotOfScreen :
case TopOfScreen :
case JumpToLine :
case CenterWindow :
case CenterLine :
case ScrollDnLine :
case ScrollUpLine :
case PanUp :
case PanDn :
case NextDirtyLine :
case PrevDirtyLine :
case ParenBalance :
assert( g_status.copied == FALSE );
break;
default :
break;
}
#endif
mode.sync_sem = FALSE;
for (wp = g_status.window_list; wp != NULL; wp = wp->next) {
if (wp->visible && wp != window) {
/*
* when we sync a command, we need to use the same assertions
* as those in editor( ).
*
* if everything is everything, these core asserts are TRUE.
*/
#if defined( __MSC__ )
assert( wp != NULL );
assert( wp->file_info != NULL );
assert( wp->file_info->line_list != NULL );
assert( wp->file_info->line_list_end != NULL );
assert( wp->file_info->line_list_end->len == EOF );
assert( wp->visible == TRUE );
assert( wp->rline >= 0 );
assert( wp->rline <= wp->file_info->length + 1 );
assert( wp->rcol >= 0 );
assert( wp->rcol < MAX_LINE_LENGTH );
assert( wp->ccol >= wp->start_col );
assert( wp->ccol <= wp->end_col );
assert( wp->bcol >= 0 );
assert( wp->bcol < MAX_LINE_LENGTH );
assert( wp->bcol == wp->rcol-(wp->ccol - wp->start_col) );
assert( wp->start_col >= 0 );
assert( wp->start_col < wp->end_col );
assert( wp->end_col < g_display.ncols );
assert( wp->cline >= wp->top_line );
assert( wp->cline <= wp->bottom_line );
assert( wp->top_line > 0 );
assert( wp->top_line <= wp->bottom_line );
assert( wp->bottom_line < MAX_LINES );
assert( wp->bin_offset >= 0 );
if (wp->ll->next == NULL)
assert( wp->ll->len == EOF );
else
assert( wp->ll->len >= 0 );
assert( wp->ll->len < MAX_LINE_LENGTH );
#endif
(*do_it[g_status.command])( wp );
show_line_col( wp );
show_ruler_pointer( wp );
}
}
mode.sync_sem = TRUE;
for (fp = g_status.file_list; fp != NULL; fp = fp->next)
if (fp->dirty != FALSE)
fp->dirty = GLOBAL;
}
}
/*
* Name: editor
* Purpose: Set up the editor structures and display changes as needed.
* Date: June 5, 1991
* Notes: Master editor routine.
*/
void editor( )
{
char *name; /* name of file to start editing */
register WINDOW *window; /* current active window */
int c;
/*
* initialize search and seize
*/
g_status.sas_defined = FALSE;
for (c=0; c<SAS_P; c++)
g_status.sas_arg_pointers[c] = NULL;
g_status.file_mode = TEXT;
/*
* Check that user specified file to edit, if not offer help
*/
if (g_status.argc > 1) {
c = *g_status.argv[1];
if (c == '/' || c == '-') {
c = *(g_status.argv[1] + 1);
if (c == 'f' || c == 'g') {
/*
* with search and seize their has to be at least 4 arg's, e.g.
* tde -f findme *.c
*/
if (g_status.argc >= 4) {
assert( strlen( g_status.argv[2] ) < MAX_COLS );
if (c == 'f') {
g_status.command = DefineGrep;
strcpy( (char *)sas_bm.pattern, g_status.argv[2] );
} else {
g_status.command = DefineRegXGrep;
strcpy( (char *)regx.pattern, g_status.argv[2] );
}
for (c=3; c <= g_status.argc; c++)
g_status.sas_arg_pointers[c-3] = g_status.argv[c];
g_status.sas_argc = g_status.argc - 3;
g_status.sas_arg = 0;
g_status.sas_argv = g_status.sas_arg_pointers;
g_status.sas_found_first = FALSE;
if (g_status.command == DefineGrep) {
g_status.sas_defined = TRUE;
g_status.sas_search_type = BOYER_MOORE;
bm.search_defined = sas_bm.search_defined = OK;
build_boyer_array( );
c = OK;
} else {
c = build_nfa( );
if (c == OK) {
g_status.sas_defined = TRUE;
g_status.sas_search_type = REG_EXPRESSION;
regx.search_defined = sas_regx.search_defined = OK;
} else
g_status.sas_defined = FALSE;
}
if (c != ERROR)
c = search_and_seize( g_status.current_window );
} else
c = ERROR;
} else if (c == 'b' || c == 'B') {
c = atoi( g_status.argv[1] + 2 );
if (c <= 0 || c >= MAX_LINE_LENGTH)
c = DEFAULT_BIN_LENGTH;
++g_status.arg;
g_status.file_mode = BINARY;
g_status.file_chunk = c;
c = edit_next_file( g_status.current_window );
} else
c = ERROR;
} else
c = edit_next_file( g_status.current_window );
} else {
name = g_status.rw_name;
*name = '\0';
/*
* file name to edit
*/
c = get_name( ed15, g_display.nlines, name, g_display.text_color );
assert( strlen( name ) < MAX_COLS );
if (c == OK) {
if (*name != '\0')
c = attempt_edit_display( name, GLOBAL, TEXT, 0 );
else
c = dir_help( (WINDOW *)NULL );
}
}
g_status.stop = c == OK ? FALSE : TRUE;
if (c == OK)
set_cursor_size( mode.insert ? g_display.insert_cursor :
g_display.overw_cursor );
/*
* main loop - keep updating the display and processing any commands
* while user has not pressed the stop key
*/
for (; g_status.stop != TRUE;) {
window = g_status.current_window;
/*
* before we do any editor commands, we start out with some basic
* assumptions.
*
* if everything is everything, these core asserts are TRUE.
*/
assert( window != NULL );
assert( window->file_info != NULL );
assert( window->file_info->line_list != NULL );
assert( window->file_info->line_list_end != NULL );
assert( window->file_info->line_list_end->len == EOF );
assert( window->visible == TRUE );
assert( window->rline >= 0 );
assert( window->rline <= window->file_info->length + 1 );
assert( window->rcol >= 0 );
assert( window->rcol < MAX_LINE_LENGTH );
assert( window->ccol >= window->start_col );
assert( window->ccol <= window->end_col );
assert( window->bcol >= 0 );
assert( window->bcol < MAX_LINE_LENGTH );
assert( window->bcol == window->rcol-(window->ccol - window->start_col) );
assert( window->start_col >= 0 );
assert( window->start_col < window->end_col );
assert( window->end_col < g_display.ncols );
assert( window->cline >= window->top_line );
assert( window->cline <= window->bottom_line );
assert( window->top_line > 0 );
assert( window->top_line <= window->bottom_line );
assert( window->bottom_line < MAX_LINES );
assert( window->bin_offset >= 0 );
if (window->ll->next == NULL)
assert( window->ll->len == EOF );
else
assert( window->ll->len >= 0 );
assert( wi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -