📄 aee.c
字号:
/* +---------------------------------------------------------------+ | | | Hugh F. Mahon | | begun Nov. 22, 1985 | | | | ae (another editor) | +---------------------------------------------------------------+ $Header: /home/hugh/sources/aee/RCS/aee.c,v 1.65 1999/10/10 02:29:39 hugh Exp $*//* | An easy to use, simple screen oriented editor. | | THIS MATERIAL IS PROVIDED "AS IS". THERE ARE | NO WARRANTIES OF ANY KIND WITH REGARD TO THIS | MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE | IMPLIED WARRANTIES OF MERCHANTABILITY AND | FITNESS FOR A PARTICULAR PURPOSE. Neither | Hewlett-Packard nor Hugh Mahon shall be liable | for errors contained herein, nor for | incidental or consequential damages in | connection with the furnishing, performance or | use of this material. Neither Hewlett-Packard | nor Hugh Mahon assumes any responsibility for | the use or reliability of this software or | documentation. This software and | documentation is totally UNSUPPORTED. There | is no support contract available. Hewlett- | Packard has done NO Quality Assurance on ANY | of the program or documentation. You may find | the quality of the materials inferior to | supported materials. | | This software is not a product of Hewlett-Packard, Co., or any | other company. No support is implied or offered with this software. | You've got the source, and you're on your own. | | This software may be distributed under the terms of Larry Wall's | Artistic license, a copy of which is included in this distribution. | | This notice must be included with this software and any derivatives. | | This software and documentation contains | proprietary information which is protected by | copyright. All rights are reserved. | */char *copyright_notice = "Copyright (c) 1986 - 1988, 1991 - 1999 Hugh Mahon.";char *long_notice[] = { "This software and documentation contains", "proprietary information which is protected by", "copyright. All rights are reserved." };char *version_string = "@(#) aee (another easy editor) version 2.2.3 October 1999 $Revision: 1.65 $";#include "aee.h"int eightbit; /* eight bit character flag */struct stat buf;#ifndef NO_CATGETSnl_catd catalog;#endif /* NO_CATGETS */extern int errno;struct text *first_line; /* first line of current buffer */struct text *dlt_line; /* structure for info on deleted line */struct text *curr_line; /* current line cursor is on */struct text *fpste_line; /* first line of select buffer */struct text *cpste_line; /* current paste/select line */struct text *paste_buff; /* first line of paste buffer */struct text *pste_tmp; /* temporary paste pointer */struct text *tmp_line; /* temporary line pointer */struct text *srch_line; /* temporary pointer for search routine */struct files *top_of_stack;struct bufr *first_buff; /* first buffer in list */struct bufr *curr_buff; /* pointer to current buffer */struct bufr *t_buff; /* temporary pointer for buffers */struct tab_stops *tabs;struct del_buffs *undel_first;struct del_buffs *undel_current;WINDOW *com_win; /* command window */WINDOW *help_win; /* window for help facility */int windows; /* flag for windows or no windows */WINDOW *info_win;int lines_moved; /* number of lines moved in search */int d_wrd_len; /* length of deleted word */int value; /* temporary integer value */int tmp_pos; /* temporary position */int tmp_vert; /* temporary vertical position */int tmp_horz; /* temporary horizontal position */int repl_length; /* length of string to replace */int pst_pos; /* position in cpste_line->line */int gold_count; /* number of times to execute pressed key */int fildes; /* file descriptor */int get_fd; /* get file descriptor */int write_fd; /* write file descriptor */int num_of_bufs; /* the number of buffers that exist */int temp_stdin; /* temporary storage for stdin */int temp_stdout; /* temp storage for stdout descriptor */int temp_stderr; /* temp storage for stderr descriptor */int pipe_out[2]; /* pipe file desc for output */int pipe_in[2]; /* pipe file descriptors for input */int line_wrap; /* should line extend forever? */int right_margin; /* right margin (if observ_margins = TRUE) */int left_margin; /* left margin */int info_type;int info_win_height = INFO_WIN_HEIGHT_DEF;int local_LINES = 0; /* copy of LINES, to detect when win resizes */int local_COLS = 0; /* copy of COLS, to detect when win resizes */int bit_bucket; /* file descriptor to /dev/null */int tab_spacing = 8; /* spacing for tabs *//* | boolean flags */char mark_text; /* flag to indicate if MARK is active */char journ_on; /* flag for journaling */char input_file; /* indicate to read input file */char recv_file; /* indicate reading a file */char edit; /* continue executing while true */char gold; /* 'gold' function key pressed */char recover; /* set true if recover operation to occur */char case_sen; /* case sensitive search flag */char change; /* indicate changes have been made to file*/char go_on; /* loop control for help function */char clr_cmd_line; /* flag set to clear command line */char literal; /* is search string to be interpreted literally? */char forward; /* if TRUE, search after cursor, else search before cursor */char echo_flag; /* allow/disallow echo in init file */char status_line; /* place status info in the bottom line */char overstrike; /* overstrike / insert mode flag */char indent; /* auto-indent mode flag */char expand; /* expand tabs flag */char shell_fork;char out_pipe = FALSE; /* flag that info is piped out */char in_pipe = FALSE; /* flag that info is piped in */char observ_margins = FALSE; /* should margins be observed */char right_justify = FALSE; /* justify right margin when formatting */char free_d_line = FALSE; /* free d_line (already freed from del list) */char free_d_word = FALSE; /* free d_word (already freed from del list) */char info_window = TRUE; /* is info window displayed? */char auto_format = FALSE; /* automatically format paragraph */char formatted = FALSE; /* has paragraph been formatted? */char window_resize = FALSE; /* flag to indicate a resize has occurred */char change_dir_allowed = TRUE; /* flag to indicate if chdir is allowed */char restricted = FALSE; /* flag to indicate restricted mode */char com_win_initialized = FALSE;char text_only = TRUE; /* editor is to treat file being read as text only (not a binary file) */long mask; /* mask for sigblock */#ifdef XAEint win_width; /* width and height of edit session window */int win_height;extern char *xsrch_string;extern char *xold_string;extern char *xnew_string;extern Window testwin;#endifchar in_string[513]; /* input buffer string */char *pst_line; /* start of paste line */char *pst_pnt; /* current position within paste line */char *pste1; /* temporary pointers for cut/paste ops */char *pste2;char *pste3;char *old_string; /* old string to be replaced */char *u_old_string; /* upper case verson of old_string */char *new_string; /* new string to insert instead of old */char *srch_str; /* pointer for search string */char *u_srch_str; /* pointer to non-case sensitive search */char *in_file_name; /* name of input file and path */char *short_file_name; /* name of input file only */char *journ; /* name of journal file */char *journal_dir = ""; /* name of journal directory */char *out_file; /* name of output file if not input file*/char *tmp_file; /* temporary file name */char d_char; /* deleted character */char *d_word; /* deleted word */char *d_line; /* deleted line */char *term_type; /* type of terminal being used */char *help_line; /* input line for help facility */char *sline; /* temporary line pointer for help fac */char *subject; /* subject user wants to learn about */char *start_of_string; /* start of search string */char match_char; /* character found by search for match */char in_buff_name[128]; /* input buffer name */char out_buff_name[128]; /* output buffer name */char *start_at_line; /* move to this line at start of session*/char *print_command = "lp"; /* string to hold command for printing file */char nohighlight = FALSE;char *ctr[32]; /* control key strings */char ctr_changed[32]; /* control key strings changed flags */char *g_ctr[32]; /* gold control key strings */char g_ctr_changed[32]; /* gold control key strings changed */char *f[64]; /* function key strings */char f_changed[64]; /* function key strings */char *g_f[64]; /* gold function key strings */char g_f_changed[64]; /* gold function key strings */char *ctrl_table[] = { "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J", "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_", "^?" };char *keypads[5]; /* keypad keys from terminfo */char *g_keypads[5]; /* keypad keys from terminfo */int in; /* input character */FILE *fp; /* file pointer for input */FILE *outp; /* pointer for output file */FILE *temp_fp; /* temporary file pointer */FILE *get_fp; /* read file pointer */FILE *write_fp; /* write file pointer */char info_data[MAX_HELP_LINES][MAX_HELP_COLS];struct edit_keys assignment[] = {{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 }, { "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 },{ "", "", 0, 0, 0, 0 }};/* | allocate space here for the strings that will be in the menu */struct menu_entries modes_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, /* 0 title */ {"", NULL, NULL, NULL, NULL, -1}, /* 1 */ {"", NULL, NULL, NULL, NULL, -1}, /* 2 */ {"", NULL, NULL, NULL, NULL, -1}, /* 3 */ {"", NULL, NULL, NULL, NULL, -1}, /* 4 */ {"", NULL, NULL, NULL, NULL, -1}, /* 5 */ {"", NULL, NULL, NULL, NULL, -1}, /* 6 */ {"", NULL, NULL, NULL, NULL, -1}, /* 7 */ {"", NULL, NULL, NULL, NULL, -1}, /* 8 */ {"", NULL, NULL, NULL, NULL, -1}, /* 9 */ {"", NULL, NULL, NULL, NULL, -1}, /* 10 */ {"", NULL, NULL, NULL, NULL, -1}, /* 11 */ {"", NULL, NULL, NULL, NULL, -1}, /* 12 */ {"", NULL, NULL, NULL, NULL, -1}, /* 13 */ {"", NULL, NULL, NULL, NULL, -1}, /* 14 */ {"", NULL, NULL, NULL, NULL, -1}, /* 15 text/binary mode */ {"", NULL, NULL, NULL, NULL, -1}, /* 16 dos/ux text file */ {"", NULL, NULL, NULL, NULL, -1}, /* 17 save configuration */ {NULL, NULL, NULL, NULL, NULL, -1} };int modes_initialized = FALSE;char *mode_strings[NUM_MODES_ITEMS];struct menu_entries config_dump_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, NULL, -1}, {"", NULL, NULL, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries leave_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, NULL, -1}, {"", NULL, NULL, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries leave_menu_2[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, NULL, -1}, {"", NULL, NULL, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries file_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, file_op, NULL, READ_FILE}, {"", NULL, NULL, file_op, NULL, WRITE_FILE}, {"", NULL, NULL, file_op, NULL, SAVE_FILE}, {"", NULL, NULL, NULL, print_buffer, -1}, {"", NULL, NULL, NULL, recover_op, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries search_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, search_prompt, NULL, TRUE}, {"", NULL, NULL, NULL, search_op, -1}, {"", NULL, NULL, repl_prompt, NULL, TRUE}, {"", NULL, NULL, NULL, replace, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries spell_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, spell_op, -1}, {"", NULL, NULL, NULL, ispell_op, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries misc_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, Format, -1}, {"", NULL, NULL, NULL, shell_op, -1}, {"", menu_op, spell_menu, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries edit_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, slct, NULL, Mark}, {"", NULL, NULL, NULL, copy, -1}, {"", NULL, NULL, NULL, cut, -1}, {"", NULL, NULL, NULL, paste, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries main_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, leave_op, -1}, {"", NULL, NULL, NULL, help, -1}, {"", menu_op, edit_menu, NULL, NULL, -1}, {"", menu_op, file_menu, NULL, NULL, -1}, {"", NULL, NULL, NULL, redraw, -1}, {"", NULL, NULL, NULL, modes_op, -1}, {"", menu_op, search_menu, NULL, NULL, -1}, {"", menu_op, misc_menu, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries del_buff_menu[] = { {"", NULL, NULL, NULL, NULL, MENU_WARN}, {"", NULL, NULL, file_op, NULL, SAVE_FILE}, {"", NULL, NULL, NULL, NULL, -1}, {"", NULL, NULL, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries rae_err_menu[] = { {"", NULL, NULL, NULL, NULL, MENU_WARN}, {"", NULL, NULL, NULL, NULL, -1}, {NULL, NULL, NULL, NULL, NULL, -1} };char *commands[70];char *init_strings[40];/* | memory debugging macros */#ifdef DEBUGFILE *error_fp;#endif /* DEBUG *//* | declaration for localizable strings */char *ae_help_file, *SL_line_str, *SL_col_str, *SL_lit_str, *SL_nolit_str;char *SL_fwd_str, *SL_rev_str, *SL_over_str, *SL_insrt_str, *SL_indent_str;char *SL_noindnt_str, *SL_marg_str, *SL_nomarg_str, *SL_mark_str, *ascii_code_str;char *left_err_msg, *right_err_msg, *help_err_msg, *prompt_for_more, *topic_prompt;char *topic_err_msg, *continue_prompt, *printing_msg, *EXPAND_str, *NOEXPAND_str;char *NOJUSTIFY_str, *JUSTIFY_str, *EXIT_str, *QUIT_str, *AUTOFORMAT_str;char *NOAUTOFORMAT_str, *INFO_str, *NOINFO_str, *TABS_str, *UNTABS_str;char *WRITE_str, *READ_str, *SAVE_str, *LITERAL_str, *NOLITERAL_str;char *STATUS_str, *NOSTATUS_str, *MARGINS_str, *NOMARGINS_str, *INDENT_str;char *NOINDENT_str, *OVERSTRIKE_str, *NOOVERSTRIKE_str, *LEFTMARGIN_str, *RIGHTMARGIN_str;char *LINE_str, *FILE_str, *COPYRIGHT_str, *CHARACTER_str, *REDRAW_str;char *RESEQUENCE_str, *AUTHOR_str, *VERSION_str, *CASE_str, *NOCASE_str;char *EIGHT_str, *NOEIGHT_str, *WINDOWS_str, *NOWINDOWS_str, *DEFINE_str;char *SHOW_str, *HELP_str, *PRINT_str, *BUFFER_str, *DELETE_str;char *GOLD_str, *tab_msg, *file_write_prompt_str, *file_read_prompt_str, *left_mrg_err_msg;char *right_mrg_err_msg, *left_mrg_setting, *right_mrg_setting, *line_num_str, *lines_from_top;char *total_lines_str, *current_file_str, *char_str, *key_def_msg, *unkn_syntax_msg;char *current_buff_msg, *unkn_cmd_msg, *usage_str, *read_only_msg, *no_rcvr_fil_msg;char *cant_opn_rcvr_fil_msg, *fin_read_file_msg, *rcvr_op_comp_msg, *file_is_dir_msg, *path_not_a_dir_msg;char *access_not_allowed_msg, *new_file_msg, *cant_open_msg, *bad_rcvr_msg, *reading_file_msg;char *file_read_lines_msg, *other_buffs_exist_msg, *changes_made_prompt, *no_write_access_msg, *file_exists_prompt;char *cant_creat_fil_msg, *writing_msg, *file_written_msg, *searching_msg, *fwd_srch_msg;char *rev_srch_msg, *str_str, *not_fnd_str, *search_prompt_str, *mark_not_actv_str;char *mark_active_str, *mark_alrdy_actv_str, *no_buff_named_str, *press_ret_to_cont_str, *fn_GOLD_str;char *fn_DL_str, *fn_DC_str, *fn_CL_str, *fn_NP_str, *fn_PP_str;char *fn_NB_str, *fn_PB_str, *fn_UDL_str, *fn_UDC_str, *fn_DW_str;char *fn_UDW_str, *fn_UND_str, *fn_EOL_str, *fn_BOL_str, *fn_BOT_str;char *fn_EOT_str, *fn_FORMAT_str, *fn_MARGINS_str, *fn_NOMARGINS_str, *fn_IL_str;char *fn_PRP_str, *fn_RP_str, *fn_MC_str, *fn_PSRCH_str, *fn_SRCH_str;char *fn_AL_str, *fn_AW_str, *fn_AC_str, *fn_PW_str, *fn_CUT_str;char *fn_FWD_str, *fn_REV_str, *fn_MARK_str, *fn_UNMARK_str, *fn_APPEND_str;char *fn_PREFIX_str, *fn_COPY_str, *fn_CMD_str, *fn_PST_str, *fn_RD_str;char *fn_UP_str, *fn_DOWN_str, *fn_LEFT_str, *fn_RIGHT_str, *fn_BCK_str;char *fn_CR_str, *fn_EXPAND_str, *fn_NOEXPAND_str, *fn_EXIT_str, *fn_QUIT_str;char *fn_LITERAL_str, *fn_NOLITERAL_str, *fn_STATUS_str, *fn_NOSTATUS_str, *fn_INDENT_str;char *fn_NOINDENT_str, *fn_OVERSTRIKE_str, *fn_NOOVERSTRIKE_str, *fn_CASE_str, *fn_NOCASE_str;char *fn_WINDOWS_str, *fn_NOWINDOWS_str, *fn_HELP_str, *fn_MENU_str, *fwd_mode_str;char *rev_mode_str, *ECHO_str, *cmd_prompt, *PRINTCOMMAND_str, *replace_action_prompt;char *replace_prompt_str, *replace_r_char, *replace_skip_char, *replace_all_char, *quit_char;char *yes_char, *no_char, *cant_find_match_str, *fmting_par_msg, *cancel_string;char *menu_too_lrg_msg, *shell_cmd_prompt, *shell_echo_msg, *spell_in_prog_msg, *left_marg_prompt;char *left_mrgn_err_msg, *right_mrgn_prompt, *right_mrgn_err_msg, *cant_redef_msg, *buff_msg;char *cant_chng_while_mark_msg, *too_many_parms_msg, *buff_is_main_msg, *cant_del_while_mark, *main_buffer_name;char *cant_del_buf_msg, *HIGHLIGHT_str, *NOHIGHLIGHT_str;char *non_unique_cmd_msg;char *ON, *OFF;char *save_file_name_prompt, *file_not_saved_msg, *cant_reopen_journ;char *write_err_msg, *jrnl_dir, *CD_str ;char *no_dir_entered_msg, *path_not_dir_msg, *path_not_permitted_msg;char *path_chng_failed_msg, *no_chng_dir_msg, *SPACING_str, *SPACING_msg;char *help_file_str;char *pwd_cmd_str, *pwd_err_msg;char *no_file_string, *no_chng_no_save, *changes_made_title;char *save_then_delete, *dont_delete, *delete_anyway_msg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -