📄 ed.c
字号:
* 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;
}
}
/*
* 作用: 建立起编辑器的结构,并且在需要的时候显示变化
*/
void editor( )
{
char *name; /* 开始编辑时的文件的名字 */
register WINDOW *window; /* 当前活动窗口 */
int c;
/*
* 初始化搜索结构
*/
g_status.sas_defined = FALSE;
for (c=0; c<SAS_P; c++)
g_status.sas_arg_pointers[c] = NULL;
g_status.file_mode = TEXT;
/*
* 检查用户是否指定了具体的文件来编辑,如果没有提供帮助
*/
if (g_status.argc > 1) {
c = *g_status.argv[1];
if (c == '/' || c == '-') {
c = *(g_status.argv[1] + 1);
if (c == 'f' || c == 'g') {
/*
* 如果是搜索文件,那么用户在命令参数中至少要提供4个参数
* 比如 editor -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';
/*
* 要编辑的文件名
*/
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 );
/*
* 主循环:在用户结束文档编辑前,处理用户的编辑命令
* 并且负责在视图中反映变化
*/
for (; g_status.stop != TRUE;) {
window = g_status.current_window;
/*
* 在处理任何编辑命令前,检测一些参数的设置
*/
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( window->ll->len < MAX_LINE_LENGTH );
display_dirty_windows( window );
/*
* 在处理编辑命令前,把错误处理器的状态设置成一个已知的状态。
*/
ceh.flag = OK;
/*
* 得到用户的输入。查找赋予用户输入的这个键的命令功能。
* 所有普通文本的输入都赋予了功能0,这些文本包括ASCII码和扩展ASCII码
*/
g_status.key_pressed = getkey( );
g_status.command = getfunc( g_status.key_pressed );
if (g_status.wrapped || g_status.key_pending) {
g_status.key_pending = FALSE;
g_status.wrapped = FALSE;
show_search_message( CLR_SEARCH, g_display.mode_color );
}
g_status.control_break = FALSE;
if (g_status.command >= 0 && g_status.command < NUM_FUNCS) {
record_keys( window->bottom_line );
(*do_it[g_status.command])( window );
}
}
cls( );
xygoto( 0, 0 );
}
/*
* Name: display_dirty_windows
* Purpose: Set up the editor structures and display changes as needed.
* Date: June 5, 1991
* Notes: Display all windows with dirty files.
*/
void display_dirty_windows( WINDOW *window )
{
register WINDOW *below; /* window below current */
register WINDOW *above; /* window above current */
file_infos *file; /* temporary file structure */
/*
* update all windows that point to any file that has been changed
*/
above = below = window;
while (above->prev || below->next) {
if (above->prev) {
above = above->prev;
show_dirty_window( above );
}
if (below->next) {
below = below->next;
show_dirty_window( below );
}
}
file = window->file_info;
if (file->dirty == LOCAL || file->dirty == GLOBAL)
display_current_window( window );
for (file=g_status.file_list; file != NULL; file=file->next)
file->dirty = FALSE;
/*
* Set the cursor position at window->ccol, window->cline. Show the
* user where in the file the cursor is positioned.
*/
xygoto( window->ccol, window->cline );
show_line_col( window );
show_ruler_pointer( window );
}
/*
* Name: show_dirty_window
* Purpose: show changes in non-current window
* Date: June 5, 1991
* Passed: window: pointer to current window
*/
void show_dirty_window( WINDOW *window )
{
register WINDOW *win; /* register window pointer */
int dirty;
win = window;
if (win->visible) {
dirty = win->file_info->dirty;
if (dirty == GLOBAL || dirty == NOT_LOCAL) {
display_current_window( win );
show_size( win );
}
show_asterisk( win );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -