📄 file.c
字号:
(mode.inflate_tabs) ? mode.inflate_tabs : 1; } file->len_len = (mode.line_numbers) ? numlen( file->length ) + 1 : 0; g_status.current_file = file; make_backup_fname( file ); } else {#if defined( __MSC__ ) _fheapmin( );#endif my_free( file->undo_top ); my_free( file->line_list_end ); my_free( file->line_list ); free( file ); } return( rc );}/* * Name: edit_another_file * Purpose: Bring in another file to editor. * Date: June 5, 1991 * Passed: window: pointer to current window * Notes: New window replaces old window. Old window becomes invisible. * * jmh: January 24, 1998 - can insert file into current. * jmh 981127: if the name is a wildcard, bring up the directory list. * jmh 990502: if the name is "=", use the current name. * jmh 991028: if the name ends in a slash or backslash, assume a directory * and bring up the list. * jmh 030226: added ScratchWindow. */int edit_another_file( TDE_WIN *window ){char fname[PATH_MAX+2]; /* new name for file */register TDE_WIN *win; /* put window pointer in a register */int rc;int file_mode;int bin_length;fattr_t fattr; win = window; if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR) return( ERROR ); if (g_status.command == InsertFile && win->ll->next == NULL) return( ERROR ); if (g_status.command == ScratchWindow) return( attempt_edit_display( "", LOCAL ) ); /* * read in name, no default */ fname[0] = '\0'; /* * file name to edit */ if ((rc = get_name( (g_status.command == InsertFile) ? ed15a : ed15, win->bottom_line, fname, &h_file )) > 0) { --rc; if (is_pattern( fname ) || fname[rc] == '/' ||#if !defined( __UNIX__ ) fname[rc] == '\\' || fname[rc] == ':' ||#endif file_exists( fname ) == SUBDIRECTORY) { rc = list_and_pick( fname, win ); if (rc != OK) return( ERROR ); } else if (*fname == '=' && fname[1] == '\0') strcpy( fname, win->file_info->file_name ); if (g_status.command == InsertFile) { long change = win->file_info->length; file_mode = TEXT; bin_length = 0; g_option.file_chunk = abs( g_option_all.file_chunk ); rc = binary_file( fname ); if (rc != ERROR) { if (rc == TRUE) { file_mode = BINARY; bin_length = g_option.file_chunk; } rc = load_file(fname,win->file_info,&file_mode,bin_length,win->ll); if (rc == OK) { syntax_check_block( change + 1, win->file_info->length, win->ll->next, win->file_info->syntax ); change = win->file_info->length - change; adjust_windows_cursor( win, change ); restore_marked_block( win, (int)change ); win->file_info->modified = TRUE; win->file_info->dirty = GLOBAL; show_size( win ); } } } else if (get_fattr( fname, &fattr ) == 3) error( WARNING, win->bottom_line, dir2 ); else rc = attempt_edit_display( fname, LOCAL ); } return( rc );}/* * Name: reload_file * Purpose: discard the current changes and reload the file * Author: Jason Hood * Date: March 18, 2003 * Notes: keeps the deleted lines, but resets the undo information. * used explicitly by Revert and implicitly by Shell. * * 051018: don't ERROR on reverting scratch windows or choosing not to reload. */int reload_file( TDE_WIN *window ){file_infos *file;int prompt_line;const char *prompt;int file_mode;int bin_length;line_list_ptr ll;line_list_ptr temp_ll;UNDO *undo;UNDO *temp_u;register TDE_WIN *wp;long n;int rc; file = window->file_info; prompt_line = window->bottom_line; /* * ignore the pipe and scratch windows * make sure the file still exists */ if (g_status.command == Revert) { if (!*file->file_name) return( OK ); if (file_exists( file->file_name ) == ERROR) { error( WARNING, prompt_line, main23a ); return( ERROR ); } prompt = main23; g_status.copied = FALSE; } else { if (window->visible) prompt = main24; else { prompt_line = g_display.end_line; combine_strings( line_out, main7a, file->file_name, main25b ); prompt = line_out; } } if (!auto_reload) if (get_yn( prompt, prompt_line, R_PROMPT | R_ABORT ) != A_YES) return( OK ); my_free_group( TRUE ); ll = file->line_list->next; while (ll->len != EOF) { temp_ll = ll->next; my_free( ll->line ); my_free( ll ); ll = temp_ll; } undo = file->undo; while (undo != NULL) { temp_u = undo->prev; if ((unsigned long)undo->text > 255) my_free( undo->text ); my_free( undo ); undo = temp_u; } my_free_group( FALSE ); file->length = 0; file->line_list->next = file->line_list_end; file->line_list_end->prev = file->line_list; file->undo_count = 0; file->undo = NULL; bin_length = file->binary_len; file_mode = (bin_length == 0) ? TEXT : BINARY; rc = load_file( file->file_name, file, &file_mode, bin_length, file->line_list ); if (rc == OK) { get_ftime( file->file_name, &file->ftime ); syntax_init_lines( file ); for (wp = g_status.window_list; wp; wp = wp->next) { if (wp->file_info == file) { n = wp->rline; if (n > file->length + 1) n = file->length + 1; first_line( wp ); move_to_line( wp, n, TRUE ); check_cline( wp, wp->cline ); } } } show_size( window ); show_avail_mem( ); file->modified = FALSE; file->dirty = GLOBAL | RULER; return( rc );}/* * Name: attempt_edit_display * Purpose: try to load then display a file * Date: June 5, 1991 * Passed: fname: file name to load * update_type: update current window or entire screen * Notes: When we first start the editor, we need to update the entire * screen. When we load in a new file, we only need to update * the current window. * * jmh: September 8, 1997 - call init_syntax() to setup syntax highlighting * jmh 980801: moved the above from create_window (why didn't I think to put * it here in the first place?) * jmh 981111: set deflate tabs when using binary mode. * jmh 981127: determine if a file should be loaded in binary directly here, * rather than in all the calling routines. * jmh 990425: update file and language history here, to recognize the command * line, dir lister and grep files. * jmh 990429: recognize read-only/viewer option. * jmh 990501: binary mode deflate tabs moved to edit_file(). * jmh 020730: if fname is NULL, take g_status.current_file as already having * been loaded (in the workspace). * jmh 021023: handle the command line options appropriately. * jmh 021103: don't store workspace loaded files in the history. * jmh 030303: add a command line flag to update_type. */int attempt_edit_display( char *fname, int update_type ){int rc;TDE_WIN *win;int file_mode;int bin_length;char *old_language;int grep, cmd_line; grep = (g_status.command == DefineGrep || g_status.command == RepeatGrep); cmd_line = (update_type & CMDLINE); file_mode = TEXT; bin_length = 0; if (!cmd_line) { g_option.language = NULL; g_option.scratch = FALSE; if (!grep) g_option.file_chunk = abs( g_option.file_chunk ); /* * Let the tab size still apply, since files from the * same directory probably use the same tabs. */ /* g_option.tab_size = -1; */ } if (g_option.file_mode == BINARY && cmd_line) { bin_length = g_option.file_chunk; if (bin_length != 0) file_mode = BINARY; } else if (fname != NULL) { rc = binary_file( fname ); if (rc == TRUE) { file_mode = BINARY; bin_length = g_option.file_chunk; } else if (rc == ERROR) return( rc ); } if (fname == NULL) rc = OK; else rc = edit_file( fname, file_mode, bin_length ); if (rc != ERROR) { rc = initialize_window( ); if (rc != ERROR) { win = g_status.current_window; if (file_mode == TEXT) init_syntax( win ); if (cmd_line && cmd_title) { if (cmd_title[0] == '.' && cmd_title[1] == '\0') { if (win->file_info->scratch) old_language = NULL; else old_language = win->file_info->file_name; } else { old_language = cmd_title; cmd_title = NULL; } if (old_language) win->title = my_strdup( old_language ); } if ((update_type & O_READ_ONLY) || (g_status.viewer_mode && !(update_type & O_READ_WRITE))) win->file_info->read_only = TRUE; update_type &= ~(O_READ_WRITE | O_READ_ONLY | CMDLINE); set_path( win ); if (update_type == GLOBAL) redraw_screen( win ); else { if (update_type == LOCAL || g_status.window_count > 1) { show_file_count( ); show_window_count( ); show_avail_mem( ); } if (update_type == LOCAL && !make_window) { redraw_current_window( win ); show_tab_modes( ); } } if (grep && !(g_status.search & SEARCH_RESULTS)) { find_adjust( win, g_status.sas_ll, g_status.sas_rline, g_status.sas_rcol ); win->file_info->dirty |= LOCAL; } if (win->file_info->new_file && !(g_status.search & SEARCH_RESULTS)) { g_status.command = AddLine; insert_newline( win ); win->file_info->modified = FALSE; } /* * assume if fname is in the file line buffer, the file * is being loaded from the workspace. Don't store it * in the history, as otherwise it will probably be there * twice: as the complete filename from the workspace and * again as the name entered on the command line from the * restored history. * jmh 031029: don't store the temporary output filename. */ if (fname != line_in + 1 && g_status.command != Execute) add_to_history( fname, &h_file ); if (win->file_info->syntax) add_to_history( win->file_info->syntax->name, &h_lang ); /* * Process the startup macro. */ if (cmd_line && g_option.macro) { g_status.command = PlayBack; g_status.key_macro = macro[KEY_IDX( g_option.macro )]; play_back( win ); } } } return( rc );}/* * Name: file_file * Purpose: To file the current file to disk. * Date: September 17, 1991 * Modified: August 27, 1997, Jason Hood * Passed: window: pointer to current window * * Change: If output has been redirected then send the file to stdout. * If a block has been marked, that will be sent, not the whole file. */int file_file( TDE_WIN *window ){register file_infos *file;long first, last;#if defined( __UNIX__ )extern int stdoutput;#endif if (!g_status.output_redir) { if (save_file( window ) == OK) finish( window ); } else { if (un_copy_line( window->ll, window, TRUE, TRUE ) == ERROR) return( ERROR ); file = window->file_info; if (file->block_type <= NOTMARKED) { first = 1; last = file->length; } else { first = file->block_br; last = file->block_er; }#if defined( __UNIX__ ) console_suspend( ); dup2( stdoutput, fileno( stdout ) ); hw_save( "", file, first, last, file->block_type ); freopen( STDFILE, "w", stdout ); console_resume( FALSE );#else hw_save( "", file, first, last, file->block_type );#endif finish( window ); } return( OK );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -