📄 ee.c
字号:
/* | ee (easy editor) | | An easy to use, simple screen oriented editor. | | written by Hugh Mahon | | 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 editor was purposely developed to be simple, both in | interface and implementation. This editor was developed to | address a specific audience: the user who is new to computers | (especially UNIX). | | ee is not aimed at technical users; for that reason more | complex features were intentionally left out. In addition, | ee is intended to be compiled by people with little computer | experience, which means that it needs to be small, relatively | simple in implementation, and portable. | | This software and documentation contains | proprietary information which is protected by | copyright. All rights are reserved. | | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.99 2001/12/24 05:43:32 hugh Exp $ | */char *ee_copyright_message = "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996 Hugh Mahon ";char *ee_long_notice[] = { "This software and documentation contains", "proprietary information which is protected by", "copyright. All rights are reserved." };#include "ee_version.h"char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.99 $";#ifdef NCURSE#include "new_curse.h"#else#include <curses.h>#endif#include <signal.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <errno.h>#include <string.h>#include <pwd.h>#ifdef HAS_SYS_WAIT#include <sys/wait.h>#endif#ifdef HAS_STDLIB#include <stdlib.h>#endif#ifdef HAS_STDARG#include <stdarg.h>#endif#ifdef HAS_UNISTD#include <unistd.h>#endif#ifdef HAS_CTYPE#include <ctype.h>#endif#ifndef NO_CATGETS#include <locale.h>#include <nl_types.h>nl_catd catalog;#else#define catgetlocal(a, b) (b)#endif /* NO_CATGETS */#ifndef SIGCHLD#define SIGCHLD SIGCLD#endif#define TAB 9#define max(a, b) (a > b ? a : b)#define min(a, b) (a < b ? a : b)/* | defines for type of data to show in info window */#define CONTROL_KEYS 1#define COMMANDS 2struct text { unsigned char *line; /* line of characters */ int line_number; /* line number */ int line_length; /* actual number of characters in the line */ int max_length; /* maximum number of characters the line handles */ struct text *next_line; /* next line of text */ struct text *prev_line; /* previous line of text */ };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 *tmp_line; /* temporary line pointer */struct text *srch_line; /* temporary pointer for search routine */struct files { /* structure to store names of files to be edited*/ unsigned char *name; /* name of file */ struct files *next_name; };struct files *top_of_stack = NULL;int d_wrd_len; /* length of deleted word */int position; /* offset in bytes from begin of line */int scr_pos; /* horizontal position */int scr_vert; /* vertical position on screen */int scr_horz; /* horizontal position on screen */int tmp_vert, tmp_horz;int input_file; /* indicate to read input file */int recv_file; /* indicate reading a file */int edit; /* continue executing while true */int gold; /* 'gold' function key pressed */int fildes; /* file descriptor */int case_sen; /* case sensitive search flag */int last_line; /* last line for text display */int last_col; /* last column for text display */int horiz_offset = 0; /* offset from left edge of text */int clear_com_win; /* flag to indicate com_win needs clearing */int text_changes = FALSE; /* indicate changes have been made to text */int get_fd; /* file descriptor for reading a file */int info_window = TRUE; /* flag to indicate if help window visible */int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */int expand_tabs = TRUE; /* flag for expanding tabs */int right_margin = 0; /* the right margin */int observ_margins = TRUE; /* flag for whether margins are observed */int shell_fork;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 out_pipe; /* flag that info is piped out */int in_pipe; /* flag that info is piped in */int formatted = FALSE; /* flag indicating paragraph formatted */int auto_format = FALSE; /* flag for auto_format mode */int restricted = FALSE; /* flag to indicate restricted mode */int nohighlight = FALSE; /* turns off highlighting */int eightbit = TRUE; /* eight bit character flag */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 curses_initialized = FALSE; /* flag indicating if curses has been started*/int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */int ee_chinese = FALSE; /* allows handling of multi-byte characters */ /* by checking for high bit in a byte the */ /* code recognizes a two-byte character */ /* sequence */unsigned char *point; /* points to current position in line */unsigned char *srch_str; /* pointer for search string */unsigned char *u_srch_str; /* pointer to non-case sensitive search */unsigned char *srch_1; /* pointer to start of suspect string */unsigned char *srch_2; /* pointer to next character of string */unsigned char *srch_3;unsigned char *in_file_name = NULL; /* name of input file */char *tmp_file; /* temporary file name */unsigned char *d_char; /* deleted character */unsigned char *d_word; /* deleted word */unsigned char *d_line; /* deleted line */char in_string[513]; /* buffer for reading a file */unsigned char *print_command = "lp"; /* string to use for the print command */unsigned char *start_at_line = NULL; /* move to this line at start of session*/int in; /* input character */FILE *temp_fp; /* temporary file pointer */FILE *bit_bucket; /* file pointer to /dev/null */char *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", "^[", "^\\", "^]", "^^", "^_" };WINDOW *com_win;WINDOW *text_win;WINDOW *help_win;WINDOW *info_win;#if defined(__STDC__) || defined(__cplusplus)#define P_(s) s#else#define P_(s) ()#endif/* | The following structure allows menu items to be flexibly declared. | The first item is the string describing the selection, the second | is the address of the procedure to call when the item is selected, | and the third is the argument for the procedure. | | For those systems with i18n, the string should be accompanied by a | catalog number. The 'int *' should be replaced with 'void *' on | systems with that type. | | The first menu item will be the title of the menu, with NULL | parameters for the procedure and argument, followed by the menu items. | | If the procedure value is NULL, the menu item is displayed, but no | procedure is called when the item is selected. The number of the | item will be returned. If the third (argument) parameter is -1, no | argument is given to the procedure when it is called. */struct menu_entries { char *item_string; int (*procedure)P_((struct menu_entries *)); struct menu_entries *ptr_argument; int (*iprocedure)P_((int)); void (*nprocedure)P_((void)); int argument; };int main P_((int argc, char *argv[]));unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));void insert P_((int character));void delete P_((int disp));void scanline P_((unsigned char *pos));int tabshift P_((int temp_int));int out_char P_((WINDOW *window, int character, int column));int len_char P_((int character, int column));void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));void insert_line P_((int disp));struct text *txtalloc P_((void));struct files *name_alloc P_((void));unsigned char *next_word P_((unsigned char *string));void prev_word P_((void));void control P_((void));void emacs_control P_((void));void bottom P_((void));void top P_((void));void nextline P_((void));void prevline P_((void));void left P_((int disp));void right P_((int disp));void find_pos P_((void));void up P_((void));void down P_((void));void function_key P_((void));void print_buffer P_((void));void command_prompt P_((void));void command P_((char *cmd_str1));int scan P_((char *line, int offset, int column));char *get_string P_((char *prompt, int advance));int compare P_((char *string1, char *string2, int sensitive));void goto_line P_((char *cmd_str));void midscreen P_((int line, unsigned char *pnt));void get_options P_((int numargs, char *arguments[]));void check_fp P_((void));void get_file P_((char *file_name));void get_line P_((int length, unsigned char *in_string, int *append));void draw_screen P_((void));void finish P_((void));int quit P_((int noverify));void edit_abort P_((int arg));void delete_text P_((void));int write_file P_((char *file_name));int search P_((int display_message));void search_prompt P_((void));void del_char P_((void));void undel_char P_((void));void del_word P_((void));void undel_word P_((void));void del_line P_((void));void undel_line P_((void));void adv_word P_((void));void move_rel P_((char *direction, int lines));void eol P_((void));void bol P_((void));void adv_line P_((void));void sh_command P_((char *string));void set_up_term P_((void));void resize_check P_((void));int menu_op P_((struct menu_entries *));void paint_menu P_((struct menu_entries menu_list[], int max_width, int max_height, int list_size, int top_offset, WINDOW *menu_win, int off_start, int vert_size));void help P_((void));void paint_info_win P_((void));void no_info_window P_((void));void create_info_window P_((void));int file_op P_((int arg));void shell_op P_((void));void leave_op P_((void));void redraw P_((void));int Blank_Line P_((struct text *test_line));void Format P_((void));void ee_init P_((void));void dump_ee_conf P_((void));void echo_string P_((char *string));void spell_op P_((void));void ispell_op P_((void));int first_word_len P_((struct text *test_line));void Auto_Format P_((void));void modes_op P_((void));char *is_in_string P_((char *string, char *substring));char *resolve_name P_((char *name));int restrict_mode P_((void));int unique_test P_((char *string, char *list[]));void strings_init P_((void));#undef P_/* | allocate space here for the strings that will be in the menu */struct menu_entries modes_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, /* title */ {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */ {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/ {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */ {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */ {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/ {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */ {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/ {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */ {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */ {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */ {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */ };char *mode_strings[11]; #define NUM_MODES_ITEMS 10struct 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, -1}, {"", NULL, NULL, NULL, finish, -1}, {"", NULL, NULL, quit, NULL, TRUE}, {NULL, NULL, NULL, NULL, NULL, -1} };#define READ_FILE 1#define WRITE_FILE 2#define SAVE_FILE 3struct menu_entries file_menu[] = { {"", NULL, NULL, NULL, NULL, -1}, {"", 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, NULL, NULL, -1} };struct menu_entries search_menu[] = { {"", NULL, NULL, NULL, NULL, 0}, {"", NULL, NULL, NULL, search_prompt, -1}, {"", NULL, NULL, search, NULL, TRUE}, {NULL, NULL, NULL, NULL, NULL, -1} };struct menu_entries spell_menu[] = { {"", NULL, NULL, NULL, NULL, -1}, {"", 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, -1}, {"", 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 main_menu[] = { {"", NULL, NULL, NULL, NULL, -1}, {"", NULL, NULL, NULL, leave_op, -1}, {"", NULL, NULL, NULL, help, -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} };char *help_text[23];char *control_keys[5];char *emacs_help_text[22];char *emacs_control_keys[5];char *command_strings[5];char *commands[32];char *init_strings[22];#define MENU_WARN 1#define max_alpha_char 36/* | Declarations for strings for localization */char *com_win_message; /* to be shown in com_win if no info window */char *no_file_string;char *ascii_code_str;char *printer_msg_str;char *command_str;char *file_write_prompt_str;char *file_read_prompt_str;char *char_str;char *unkn_cmd_str;char *non_unique_cmd_msg;char *line_num_str;char *line_len_str;char *current_file_str;char *usage0;char *usage1;char *usage2;char *usage3;char *usage4;char *file_is_dir_msg;char *new_file_msg;char *cant_open_msg;char *open_file_msg;char *file_read_fin_msg;char *reading_file_msg;char *read_only_msg;char *file_read_lines_msg;char *save_file_name_prompt;char *file_not_saved_msg;char *changes_made_prompt;char *yes_char;char *file_exists_prompt;char *create_file_fail_msg;char *writing_file_msg;char *file_written_msg;char *searching_msg;char *str_not_found_msg;char *search_prompt_str;char *exec_err_msg;char *continue_msg;char *menu_cancel_msg;char *menu_size_err_msg;char *press_any_key_msg;char *shell_prompt;char *formatting_msg;char *shell_echo_msg;char *spell_in_prog_msg;char *margin_prompt;char *restricted_msg;char *ON;char *OFF;char *HELP;char *WRITE;char *READ;char *LINE;char *FILE_str;char *CHARACTER;char *REDRAW;char *RESEQUENCE;char *AUTHOR;char *VERSION;char *CASE;char *NOCASE;char *EXPAND;char *NOEXPAND;char *Exit_string;char *QUIT_string;char *INFO;char *NOINFO;char *MARGINS;char *NOMARGINS;char *AUTOFORMAT;char *NOAUTOFORMAT;char *Echo;char *PRINTCOMMAND;char *RIGHTMARGIN;char *HIGHLIGHT;char *NOHIGHLIGHT;char *EIGHTBIT;char *NOEIGHTBIT;char *EMACS_string;char *NOEMACS_string;char *conf_dump_err_msg;char *conf_dump_success_msg;char *conf_not_saved_msg;char *ree_no_file_msg;char *cancel_string;char *menu_too_lrg_msg;char *more_above_str, *more_below_str;char *chinese_cmd, *nochinese_cmd;#ifndef __STDC__#ifndef HAS_STDLIBextern char *malloc();extern char *realloc();extern char *getenv();FILE *fopen(); /* declaration for open function */#endif /* HAS_STDLIB */#endif /* __STDC__ */intmain(argc, argv) /* beginning of main program */int argc;char *argv[];{ int counter; pid_t parent_pid; for (counter = 1; counter < 24; counter++) signal(counter, SIG_IGN); signal(SIGCHLD, SIG_DFL); signal(SIGSEGV, SIG_DFL); signal(SIGINT, edit_abort); d_char = malloc(3); /* provide a buffer for multi-byte chars */ d_word = malloc(150); *d_word = (char) NULL; d_line = NULL; dlt_line = txtalloc(); dlt_line->line = d_line; dlt_line->line_length = 0; curr_line = first_line = txtalloc(); curr_line->line = point = malloc(10); curr_line->line_length = 1; curr_line->max_length = 10; curr_line->prev_line = NULL; curr_line->next_line = NULL; curr_line->line_number = 1; srch_str = NULL; u_srch_str = NULL; position = 1; scr_pos =0; scr_vert = 0; scr_horz = 0; bit_bucket = fopen("/dev/null", "w"); edit = TRUE; gold = case_sen = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -