4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
9 | Copyright (c) 2009, Hugh Mahon
10 | All rights reserved.
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions
16 | * Redistributions of source code must retain the above copyright
17 | notice, this list of conditions and the following disclaimer.
18 | * Redistributions in binary form must reproduce the above
19 | copyright notice, this list of conditions and the following
20 | disclaimer in the documentation and/or other materials provided
21 | with the distribution.
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | POSSIBILITY OF SUCH DAMAGE.
36 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
38 | This editor was purposely developed to be simple, both in
39 | interface and implementation. This editor was developed to
40 | address a specific audience: the user who is new to computers
43 | ee is not aimed at technical users; for that reason more
44 | complex features were intentionally left out. In addition,
45 | ee is intended to be compiled by people with little computer
46 | experience, which means that it needs to be small, relatively
47 | simple in implementation, and portable.
49 | This software and documentation contains
50 | proprietary information which is protected by
51 | copyright. All rights are reserved.
53 | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.104 2010/06/04 01:55:31 hugh Exp hugh $
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
60 char *ee_copyright_message =
61 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
63 #include "ee_version.h"
65 char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.104 $";
68 #include "new_curse.h"
78 #include <sys/types.h>
102 #include <nl_types.h>
106 #define catgetlocal(a, b) (b)
107 #endif /* NO_CATGETS */
110 #define SIGCHLD SIGCLD
114 #define max(a, b) (a > b ? a : b)
115 #define min(a, b) (a < b ? a : b)
118 | defines for type of data to show in info window
121 #define CONTROL_KEYS 1
125 unsigned char *line; /* line of characters */
126 int line_number; /* line number */
127 int line_length; /* actual number of characters in the line */
128 int max_length; /* maximum number of characters the line handles */
129 struct text *next_line; /* next line of text */
130 struct text *prev_line; /* previous line of text */
133 struct text *first_line; /* first line of current buffer */
134 struct text *dlt_line; /* structure for info on deleted line */
135 struct text *curr_line; /* current line cursor is on */
136 struct text *tmp_line; /* temporary line pointer */
137 struct text *srch_line; /* temporary pointer for search routine */
139 struct files { /* structure to store names of files to be edited*/
140 unsigned char *name; /* name of file */
141 struct files *next_name;
144 struct files *top_of_stack = NULL;
146 int d_wrd_len; /* length of deleted word */
147 int position; /* offset in bytes from begin of line */
148 int scr_pos; /* horizontal position */
149 int scr_vert; /* vertical position on screen */
150 int scr_horz; /* horizontal position on screen */
151 int absolute_lin; /* number of lines from top */
152 int tmp_vert, tmp_horz;
153 int input_file; /* indicate to read input file */
154 int recv_file; /* indicate reading a file */
155 int edit; /* continue executing while true */
156 int gold; /* 'gold' function key pressed */
157 int fildes; /* file descriptor */
158 int case_sen; /* case sensitive search flag */
159 int last_line; /* last line for text display */
160 int last_col; /* last column for text display */
161 int horiz_offset = 0; /* offset from left edge of text */
162 int clear_com_win; /* flag to indicate com_win needs clearing */
163 int text_changes = FALSE; /* indicate changes have been made to text */
164 int get_fd; /* file descriptor for reading a file */
165 int info_window = TRUE; /* flag to indicate if help window visible */
166 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
167 int expand_tabs = TRUE; /* flag for expanding tabs */
168 int right_margin = 0; /* the right margin */
169 int observ_margins = TRUE; /* flag for whether margins are observed */
171 int temp_stdin; /* temporary storage for stdin */
172 int temp_stdout; /* temp storage for stdout descriptor */
173 int temp_stderr; /* temp storage for stderr descriptor */
174 int pipe_out[2]; /* pipe file desc for output */
175 int pipe_in[2]; /* pipe file descriptors for input */
176 int out_pipe; /* flag that info is piped out */
177 int in_pipe; /* flag that info is piped in */
178 int formatted = FALSE; /* flag indicating paragraph formatted */
179 int auto_format = FALSE; /* flag for auto_format mode */
180 int restricted = FALSE; /* flag to indicate restricted mode */
181 int nohighlight = FALSE; /* turns off highlighting */
182 int eightbit = TRUE; /* eight bit character flag */
183 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
184 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
185 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
186 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
187 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
188 /* by checking for high bit in a byte the */
189 /* code recognizes a two-byte character */
192 unsigned char *point; /* points to current position in line */
193 unsigned char *srch_str; /* pointer for search string */
194 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
195 unsigned char *srch_1; /* pointer to start of suspect string */
196 unsigned char *srch_2; /* pointer to next character of string */
197 unsigned char *srch_3;
198 unsigned char *in_file_name = NULL; /* name of input file */
199 char *tmp_file; /* temporary file name */
200 unsigned char *d_char; /* deleted character */
201 unsigned char *d_word; /* deleted word */
202 unsigned char *d_line; /* deleted line */
203 char in_string[513]; /* buffer for reading a file */
204 unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
205 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
206 int in; /* input character */
208 FILE *temp_fp; /* temporary file pointer */
209 FILE *bit_bucket; /* file pointer to /dev/null */
212 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
213 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
214 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
224 | The following structure allows menu items to be flexibly declared.
225 | The first item is the string describing the selection, the second
226 | is the address of the procedure to call when the item is selected,
227 | and the third is the argument for the procedure.
229 | For those systems with i18n, the string should be accompanied by a
230 | catalog number. The 'int *' should be replaced with 'void *' on
231 | systems with that type.
233 | The first menu item will be the title of the menu, with NULL
234 | parameters for the procedure and argument, followed by the menu items.
236 | If the procedure value is NULL, the menu item is displayed, but no
237 | procedure is called when the item is selected. The number of the
238 | item will be returned. If the third (argument) parameter is -1, no
239 | argument is given to the procedure when it is called.
242 struct menu_entries {
244 int (*procedure)(struct menu_entries *);
245 struct menu_entries *ptr_argument;
246 int (*iprocedure)(int);
247 void (*nprocedure)(void);
251 unsigned char *resiz_line(int factor, struct text *rline, int rpos);
252 void insert(int character);
253 void delete(int disp);
254 void scanline(unsigned char *pos);
255 int tabshift(int temp_int);
256 int out_char(WINDOW *window, int character, int column);
257 int len_char(int character, int column);
258 void draw_line(int vertical, int horiz, unsigned char *ptr, int t_pos, int length);
259 void insert_line(int disp);
260 struct text *txtalloc(void);
261 struct files *name_alloc(void);
262 unsigned char *next_word(unsigned char *string);
263 void prev_word(void);
265 void emacs_control(void);
271 void right(int disp);
275 void function_key(void);
276 void print_buffer(void);
277 void command_prompt(void);
278 void command(char *cmd_str1);
279 int scan(char *line, int offset, int column);
280 char *get_string(char *prompt, int advance);
281 int compare(char *string1, char *string2, int sensitive);
282 void goto_line(char *cmd_str);
283 void midscreen(int line, unsigned char *pnt);
284 void get_options(int numargs, char *arguments[]);
286 void get_file(char *file_name);
287 void get_line(int length, unsigned char *in_string, int *append);
288 void draw_screen(void);
290 int quit(int noverify);
291 void edit_abort(int arg);
292 void delete_text(void);
293 int write_file(char *file_name, int warn_if_exists);
294 int search(int display_message);
295 void search_prompt(void);
297 void undel_char(void);
299 void undel_word(void);
301 void undel_line(void);
303 void move_rel(int direction, int lines);
307 void sh_command(char *string);
308 void set_up_term(void);
309 void resize_check(void);
310 int menu_op(struct menu_entries *);
311 void paint_menu(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);
313 void paint_info_win(void);
314 void no_info_window(void);
315 void create_info_window(void);
316 int file_op(int arg);
320 int Blank_Line(struct text *test_line);
323 void dump_ee_conf(void);
324 void echo_string(char *string);
326 void ispell_op(void);
327 int first_word_len(struct text *test_line);
328 void Auto_Format(void);
330 char *is_in_string(char *string, char *substring);
331 char *resolve_name(char *name);
332 int restrict_mode(void);
333 int unique_test(char *string, char *list[]);
334 void strings_init(void);
338 | allocate space here for the strings that will be in the menu
341 struct menu_entries modes_menu[] = {
342 {"", NULL, NULL, NULL, NULL, 0}, /* title */
343 {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */
344 {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/
345 {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */
346 {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */
347 {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/
348 {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */
349 {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/
350 {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */
351 {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */
352 {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
353 {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */
356 char *mode_strings[11];
358 #define NUM_MODES_ITEMS 10
360 struct menu_entries config_dump_menu[] = {
361 {"", NULL, NULL, NULL, NULL, 0},
362 {"", NULL, NULL, NULL, NULL, -1},
363 {"", NULL, NULL, NULL, NULL, -1},
364 {NULL, NULL, NULL, NULL, NULL, -1}
367 struct menu_entries leave_menu[] = {
368 {"", NULL, NULL, NULL, NULL, -1},
369 {"", NULL, NULL, NULL, finish, -1},
370 {"", NULL, NULL, quit, NULL, TRUE},
371 {NULL, NULL, NULL, NULL, NULL, -1}
378 struct menu_entries file_menu[] = {
379 {"", NULL, NULL, NULL, NULL, -1},
380 {"", NULL, NULL, file_op, NULL, READ_FILE},
381 {"", NULL, NULL, file_op, NULL, WRITE_FILE},
382 {"", NULL, NULL, file_op, NULL, SAVE_FILE},
383 {"", NULL, NULL, NULL, print_buffer, -1},
384 {NULL, NULL, NULL, NULL, NULL, -1}
387 struct menu_entries search_menu[] = {
388 {"", NULL, NULL, NULL, NULL, 0},
389 {"", NULL, NULL, NULL, search_prompt, -1},
390 {"", NULL, NULL, search, NULL, TRUE},
391 {NULL, NULL, NULL, NULL, NULL, -1}
394 struct menu_entries spell_menu[] = {
395 {"", NULL, NULL, NULL, NULL, -1},
396 {"", NULL, NULL, NULL, spell_op, -1},
397 {"", NULL, NULL, NULL, ispell_op, -1},
398 {NULL, NULL, NULL, NULL, NULL, -1}
401 struct menu_entries misc_menu[] = {
402 {"", NULL, NULL, NULL, NULL, -1},
403 {"", NULL, NULL, NULL, Format, -1},
404 {"", NULL, NULL, NULL, shell_op, -1},
405 {"", menu_op, spell_menu, NULL, NULL, -1},
406 {NULL, NULL, NULL, NULL, NULL, -1}
409 struct menu_entries main_menu[] = {
410 {"", NULL, NULL, NULL, NULL, -1},
411 {"", NULL, NULL, NULL, leave_op, -1},
412 {"", NULL, NULL, NULL, help, -1},
413 {"", menu_op, file_menu, NULL, NULL, -1},
414 {"", NULL, NULL, NULL, redraw, -1},
415 {"", NULL, NULL, NULL, modes_op, -1},
416 {"", menu_op, search_menu, NULL, NULL, -1},
417 {"", menu_op, misc_menu, NULL, NULL, -1},
418 {NULL, NULL, NULL, NULL, NULL, -1}
422 char *control_keys[5];
424 char *emacs_help_text[22];
425 char *emacs_control_keys[5];
427 char *command_strings[5];
429 char *init_strings[22];
433 #define max_alpha_char 36
436 | Declarations for strings for localization
439 char *com_win_message; /* to be shown in com_win if no info window */
440 char *no_file_string;
441 char *ascii_code_str;
442 char *printer_msg_str;
444 char *file_write_prompt_str;
445 char *file_read_prompt_str;
448 char *non_unique_cmd_msg;
451 char *current_file_str;
457 char *file_is_dir_msg;
461 char *file_read_fin_msg;
462 char *reading_file_msg;
464 char *file_read_lines_msg;
465 char *save_file_name_prompt;
466 char *file_not_saved_msg;
467 char *changes_made_prompt;
469 char *file_exists_prompt;
470 char *create_file_fail_msg;
471 char *writing_file_msg;
472 char *file_written_msg;
474 char *str_not_found_msg;
475 char *search_prompt_str;
478 char *menu_cancel_msg;
479 char *menu_size_err_msg;
480 char *press_any_key_msg;
482 char *formatting_msg;
483 char *shell_echo_msg;
484 char *spell_in_prog_msg;
486 char *restricted_msg;
519 char *NOEMACS_string;
520 char *conf_dump_err_msg;
521 char *conf_dump_success_msg;
522 char *conf_not_saved_msg;
523 char *ree_no_file_msg;
525 char *menu_too_lrg_msg;
526 char *more_above_str, *more_below_str;
527 char *separator = "===============================================================================";
529 char *chinese_cmd, *nochinese_cmd;
533 extern char *malloc();
534 extern char *realloc();
535 extern char *getenv();
536 FILE *fopen(); /* declaration for open function */
537 #endif /* HAS_STDLIB */
538 #endif /* __STDC__ */
540 /* beginning of main program */
542 main(int argc, char *argv[])
546 for (counter = 1; counter < 24; counter++)
547 signal(counter, SIG_IGN);
549 /* Always read from (and write to) a terminal. */
550 if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
552 "ee's standard input and output must be a terminal\n");
556 signal(SIGCHLD, SIG_DFL);
557 signal(SIGSEGV, SIG_DFL);
558 signal(SIGINT, edit_abort);
559 d_char = malloc(3); /* provide a buffer for multi-byte chars */
560 d_word = malloc(150);
563 dlt_line = txtalloc();
564 dlt_line->line = d_line;
565 dlt_line->line_length = 0;
566 curr_line = first_line = txtalloc();
567 curr_line->line = point = malloc(10);
568 curr_line->line_length = 1;
569 curr_line->max_length = 10;
570 curr_line->prev_line = NULL;
571 curr_line->next_line = NULL;
572 curr_line->line_number = 1;
580 bit_bucket = fopen("/dev/null", "w");
582 gold = case_sen = FALSE;
587 get_options(argc, argv);
589 if (right_margin == 0)
590 right_margin = COLS - 1;
591 if (top_of_stack == NULL)
595 wmove(com_win, 0, 0);
597 wprintw(com_win, ree_no_file_msg);
601 wprintw(com_win, no_file_string);
607 clear_com_win = TRUE;
614 | display line and column information
620 wmove(info_win, 5, 0);
621 wprintw(info_win, separator);
622 wmove(info_win, 5, 5);
623 wprintw(info_win, "line %d col %d lines from top %d ",
624 curr_line->line_number, scr_horz, absolute_lin);
630 in = wgetch(text_win);
632 exit(0); /* without this exit ee will go into an
633 infinite loop if the network
640 clear_com_win = FALSE;
641 wmove(com_win, 0, 0);
645 wprintw(com_win, "%s", com_win_message);
652 else if ((in == '\10') || (in == 127))
654 in = 8; /* make sure key is set to backspace */
657 else if ((in > 31) || (in == 9))
659 else if ((in >= 0) && (in <= 31))
670 /* resize the line to length + factor*/
672 resiz_line(int factor, struct text *rline, int rpos)
674 unsigned char *rpoint;
677 rline->max_length += factor;
678 rpoint = rline->line = realloc(rline->line, rline->max_length );
679 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
684 /* insert character into line */
686 insert(int character)
690 unsigned char *temp; /* temporary pointer */
691 unsigned char *temp2; /* temporary pointer */
693 if ((character == '\011') && (expand_tabs))
695 counter = len_char('\011', scr_horz);
696 for (; counter > 0; counter--)
703 if ((curr_line->max_length - curr_line->line_length) < 5)
704 point = resiz_line(10, curr_line, position);
705 curr_line->line_length++;
708 while (counter < curr_line->line_length) /* find end of line */
713 temp++; /* increase length of line by one */
717 *temp= *temp2; /* shift characters over by one */
720 *point = character; /* insert new character */
722 if (!isprint((unsigned char)character)) /* check for TAB character*/
724 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
730 waddch(text_win, (unsigned char)character);
731 scr_pos = ++scr_horz;
736 if ((observ_margins) && (right_margin < scr_pos))
739 while (scr_pos > right_margin)
743 while (position < counter)
750 for (value = 0; value < counter; value++)
755 if ((scr_horz - horiz_offset) > last_col)
758 midscreen(scr_vert, point);
761 if ((auto_format) && (character == ' ') && (!formatted))
763 else if ((character != ' ') && (character != '\t'))
766 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
769 /* delete character */
774 unsigned char *temp2;
775 struct text *temp_buff;
780 if (point != curr_line->line) /* if not at beginning of line */
784 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
790 position -= del_width;
792 curr_line->line_length -= del_width;
793 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
796 scr_horz -= del_width;
801 *d_char = *point; /* save deleted character */
805 d_char[1] = *(point + 1);
807 d_char[del_width] = '\0';
809 while (temp_pos <= curr_line->line_length)
816 if ((scr_horz < horiz_offset) && (horiz_offset > 0))
819 midscreen(scr_vert, point);
822 else if (curr_line->prev_line != NULL)
825 left(disp); /* go to previous line */
826 temp_buff = curr_line->next_line;
827 point = resiz_line(temp_buff->line_length, curr_line, position);
828 if (temp_buff->next_line != NULL)
829 temp_buff->next_line->prev_line = curr_line;
830 curr_line->next_line = temp_buff->next_line;
831 temp2 = temp_buff->line;
839 while (temp_pos < temp_buff->line_length)
841 curr_line->line_length++;
848 free(temp_buff->line);
850 temp_buff = curr_line;
851 temp_vert = scr_vert;
853 if (scr_vert < last_line)
855 wmove(text_win, scr_vert + 1, 0);
858 while ((temp_buff != NULL) && (temp_vert < last_line))
860 temp_buff = temp_buff->next_line;
863 if ((temp_vert == last_line) && (temp_buff != NULL))
865 tp = temp_buff->line;
866 wmove(text_win, last_line,0);
868 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
869 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
872 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
876 /* find the proper horizontal position for the pointer */
878 scanline(unsigned char *pos)
883 ptr = curr_line->line;
890 temp += tabshift(temp);
891 else if ((*ptr >= 10) && (*ptr <= 31))
893 else if ((*ptr >= 32) && (*ptr < 127))
895 else if (*ptr == 127)
904 if ((scr_horz - horiz_offset) > last_col)
906 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
907 midscreen(scr_vert, point);
909 else if (scr_horz < horiz_offset)
911 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
912 midscreen(scr_vert, point);
916 /* give the number of spaces to shift */
918 tabshift(int temp_int)
922 leftover = ((temp_int + 1) % 8);
926 return (9 - leftover);
929 /* output non-printing character */
931 out_char(WINDOW *window, int character, int column)
937 if (character == TAB)
939 i1 = tabshift(column);
941 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
947 else if ((character >= '\0') && (character < ' '))
949 string = table[(int) character];
951 else if ((character < 0) || (character >= 127))
953 if (character == 127)
957 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
962 waddch(window, (unsigned char)character );
968 waddch(window, (unsigned char)character);
971 for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
972 waddch(window, (unsigned char)string[i2]);
973 return(strlen(string));
976 /* return the length of the character */
978 len_char(int character, int column)
982 if (character == '\t')
983 length = tabshift(column);
984 else if ((character >= 0) && (character < 32))
986 else if ((character >= 32) && (character <= 126))
988 else if (character == 127)
990 else if (((character > 126) || (character < 0)) && (!eightbit))
998 /* redraw line from current position */
1000 draw_line(int vertical, int horiz, unsigned char *ptr, int t_pos, int length)
1002 int d; /* partial length of special or tab char to display */
1003 unsigned char *temp; /* temporary pointer to position in line */
1004 int abs_column; /* offset in screen units from begin of line */
1005 int column; /* horizontal position on screen */
1006 int row; /* vertical position on screen */
1007 int posit; /* temporary position indicator within line */
1010 column = horiz - horiz_offset;
1017 wmove(text_win, row, 0);
1018 wclrtoeol(text_win);
1022 d = len_char(*temp, abs_column);
1028 wmove(text_win, row, column);
1029 wclrtoeol(text_win);
1030 while ((posit < length) && (column <= last_col))
1032 if (!isprint(*temp))
1034 column += len_char(*temp, abs_column);
1035 abs_column += out_char(text_win, *temp, abs_column);
1041 waddch(text_win, *temp);
1046 if (column < last_col)
1047 wclrtoeol(text_win);
1048 wmove(text_win, vertical, (horiz - horiz_offset));
1051 /* insert new line */
1053 insert_line(int disp)
1057 unsigned char *temp;
1058 unsigned char *extra;
1059 struct text *temp_nod;
1061 text_changes = TRUE;
1062 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1063 wclrtoeol(text_win);
1064 temp_nod= txtalloc();
1065 temp_nod->line = extra= malloc(10);
1066 temp_nod->line_length = 1;
1067 temp_nod->max_length = 10;
1068 temp_nod->line_number = curr_line->line_number + 1;
1069 temp_nod->next_line = curr_line->next_line;
1070 if (temp_nod->next_line != NULL)
1071 temp_nod->next_line->prev_line = temp_nod;
1072 temp_nod->prev_line = curr_line;
1073 curr_line->next_line = temp_nod;
1074 temp_pos2 = position;
1076 if (temp_pos2 < curr_line->line_length)
1079 while (temp_pos2 < curr_line->line_length)
1081 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1082 extra = resiz_line(10, temp_nod, temp_pos);
1083 temp_nod->line_length++;
1092 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1093 curr_line->line_length = 1 + temp - curr_line->line;
1095 curr_line->line_length = position;
1097 curr_line = temp_nod;
1100 point= curr_line->line;
1103 if (scr_vert < last_line)
1106 wclrtoeol(text_win);
1107 wmove(text_win, scr_vert, 0);
1108 winsertln(text_win);
1112 wmove(text_win, 0,0);
1113 wdeleteln(text_win);
1114 wmove(text_win, last_line,0);
1115 wclrtobot(text_win);
1117 scr_pos = scr_horz = 0;
1121 midscreen(scr_vert, point);
1123 draw_line(scr_vert, scr_horz, point, position,
1124 curr_line->line_length);
1128 /* allocate space for line structure */
1132 return((struct text *) malloc(sizeof( struct text)));
1135 /* allocate space for file name list node */
1139 return((struct files *) malloc(sizeof( struct files)));
1142 /* move to next word in string */
1144 next_word(unsigned char *string)
1146 while ((*string != '\0') && ((*string != 32) && (*string != 9)))
1148 while ((*string != '\0') && ((*string == 32) || (*string == 9)))
1153 /* move to start of previous word in text */
1159 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1160 { /* if at the start of a word */
1161 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1164 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1166 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1168 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1175 /* use control for commands */
1181 if (in == 1) /* control a */
1183 string = get_string(ascii_code_str, TRUE);
1184 if (*string != '\0')
1187 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1192 else if (in == 2) /* control b */
1194 else if (in == 3) /* control c */
1198 else if (in == 4) /* control d */
1200 else if (in == 5) /* control e */
1202 else if (in == 6) /* control f */
1204 else if (in == 7) /* control g */
1206 else if (in == 8) /* control h */
1208 else if (in == 9) /* control i */
1210 else if (in == 10) /* control j */
1212 else if (in == 11) /* control k */
1214 else if (in == 12) /* control l */
1216 else if (in == 13) /* control m */
1218 else if (in == 14) /* control n */
1219 move_rel('d', max(5, (last_line - 5)));
1220 else if (in == 15) /* control o */
1222 else if (in == 16) /* control p */
1223 move_rel('u', max(5, (last_line - 5)));
1224 else if (in == 17) /* control q */
1226 else if (in == 18) /* control r */
1228 else if (in == 19) /* control s */
1230 else if (in == 20) /* control t */
1232 else if (in == 21) /* control u */
1234 else if (in == 22) /* control v */
1236 else if (in == 23) /* control w */
1238 else if (in == 24) /* control x */
1240 else if (in == 25) /* control y */
1242 else if (in == 26) /* control z */
1244 else if (in == 27) /* control [ (escape) */
1251 | Emacs control-key bindings
1259 if (in == 1) /* control a */
1261 else if (in == 2) /* control b */
1263 else if (in == 3) /* control c */
1267 else if (in == 4) /* control d */
1269 else if (in == 5) /* control e */
1271 else if (in == 6) /* control f */
1273 else if (in == 7) /* control g */
1274 move_rel('u', max(5, (last_line - 5)));
1275 else if (in == 8) /* control h */
1277 else if (in == 9) /* control i */
1279 else if (in == 10) /* control j */
1281 else if (in == 11) /* control k */
1283 else if (in == 12) /* control l */
1285 else if (in == 13) /* control m */
1287 else if (in == 14) /* control n */
1289 else if (in == 15) /* control o */
1291 string = get_string(ascii_code_str, TRUE);
1292 if (*string != '\0')
1295 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1300 else if (in == 16) /* control p */
1302 else if (in == 17) /* control q */
1304 else if (in == 18) /* control r */
1306 else if (in == 19) /* control s */
1308 else if (in == 20) /* control t */
1310 else if (in == 21) /* control u */
1312 else if (in == 22) /* control v */
1313 move_rel('d', max(5, (last_line - 5)));
1314 else if (in == 23) /* control w */
1316 else if (in == 24) /* control x */
1318 else if (in == 25) /* control y */
1320 else if (in == 26) /* control z */
1322 else if (in == 27) /* control [ (escape) */
1328 /* go to bottom of file */
1332 while (curr_line->next_line != NULL)
1334 curr_line = curr_line->next_line;
1337 point = curr_line->line;
1341 midscreen(last_line, point);
1345 /* go to top of file */
1349 while (curr_line->prev_line != NULL)
1351 curr_line = curr_line->prev_line;
1354 point = curr_line->line;
1358 midscreen(0, point);
1362 /* move pointers to start of next line */
1366 curr_line = curr_line->next_line;
1368 point = curr_line->line;
1370 if (scr_vert == last_line)
1372 wmove(text_win, 0,0);
1373 wdeleteln(text_win);
1374 wmove(text_win, last_line,0);
1375 wclrtobot(text_win);
1376 draw_line(last_line,0,point,1,curr_line->line_length);
1382 /* move pointers to start of previous line*/
1386 curr_line = curr_line->prev_line;
1388 point = curr_line->line;
1392 winsertln(text_win);
1393 draw_line(0,0,point,1,curr_line->line_length);
1397 while (position < curr_line->line_length)
1404 /* move left one character */
1408 if (point != curr_line->line) /* if not at begin of line */
1410 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1418 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1421 else if (curr_line->prev_line != NULL)
1426 curr_line = curr_line->prev_line;
1427 point = curr_line->line + curr_line->line_length;
1428 position = curr_line->line_length;
1435 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1439 /* move right one character */
1443 if (position < curr_line->line_length)
1445 if ((ee_chinese) && (*point > 127) &&
1446 ((curr_line->line_length - position) >= 2))
1454 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1457 else if (curr_line->next_line != NULL)
1462 curr_line = curr_line->next_line;
1463 point = curr_line->line;
1468 scr_pos = scr_horz = 0;
1472 midscreen(scr_vert, point);
1474 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1479 /* move to the same column as on other line */
1485 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1488 scr_horz += tabshift(scr_horz);
1489 else if (*point < ' ')
1491 else if ((ee_chinese) && (*point > 127) &&
1492 ((curr_line->line_length - position) >= 2))
1503 if ((scr_horz - horiz_offset) > last_col)
1505 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1506 midscreen(scr_vert, point);
1508 else if (scr_horz < horiz_offset)
1510 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1511 midscreen(scr_vert, point);
1513 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1516 /* move up one line */
1520 if (curr_line->prev_line != NULL)
1523 point = curr_line->line;
1528 /* move down one line */
1532 if (curr_line->next_line != NULL)
1539 /* process function key */
1545 else if (in == KEY_RIGHT)
1547 else if (in == KEY_HOME)
1549 else if (in == KEY_END)
1551 else if (in == KEY_UP)
1553 else if (in == KEY_DOWN)
1555 else if (in == KEY_NPAGE)
1556 move_rel('d', max( 5, (last_line - 5)));
1557 else if (in == KEY_PPAGE)
1558 move_rel('u', max(5, (last_line - 5)));
1559 else if (in == KEY_DL)
1561 else if (in == KEY_DC)
1563 else if (in == KEY_BACKSPACE)
1565 else if (in == KEY_IL)
1566 { /* insert a line before current line */
1570 else if (in == KEY_F(1))
1572 else if (in == KEY_F(2))
1582 else if (in == KEY_F(3))
1592 else if (in == KEY_F(4))
1598 midscreen(scr_vert, point);
1603 else if (in == KEY_F(5))
1613 else if (in == KEY_F(6))
1623 else if (in == KEY_F(7))
1633 else if (in == KEY_F(8))
1650 sprintf(buffer, ">!%s", print_command);
1651 wmove(com_win, 0, 0);
1653 wprintw(com_win, printer_msg_str, print_command);
1659 command_prompt(void)
1664 info_type = COMMANDS;
1666 cmd_str = get_string(command_str, TRUE);
1667 if ((result = unique_test(cmd_str, commands)) != 1)
1670 wmove(com_win, 0, 0);
1672 wprintw(com_win, unkn_cmd_str, cmd_str);
1674 wprintw(com_win, non_unique_cmd_msg);
1678 info_type = CONTROL_KEYS;
1681 if (cmd_str != NULL)
1687 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1688 info_type = CONTROL_KEYS;
1690 if (cmd_str != NULL)
1694 /* process commands from keyboard */
1696 command(char *cmd_str1)
1698 char *cmd_str2 = NULL;
1699 char *cmd_str = cmd_str1;
1701 clear_com_win = TRUE;
1702 if (compare(cmd_str, HELP, FALSE))
1704 else if (compare(cmd_str, WRITE, FALSE))
1706 if (restrict_mode())
1710 cmd_str = next_word(cmd_str);
1711 if (*cmd_str == '\0')
1713 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1715 tmp_file = resolve_name(cmd_str);
1716 write_file(tmp_file, 1);
1717 if (tmp_file != cmd_str)
1720 else if (compare(cmd_str, READ, FALSE))
1722 if (restrict_mode())
1726 cmd_str = next_word(cmd_str);
1727 if (*cmd_str == '\0')
1729 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1733 tmp_file = resolve_name(cmd_str);
1735 if (tmp_file != cmd_str)
1738 else if (compare(cmd_str, LINE, FALSE))
1740 wmove(com_win, 0, 0);
1742 wprintw(com_win, line_num_str, curr_line->line_number);
1743 wprintw(com_win, line_len_str, curr_line->line_length);
1745 else if (compare(cmd_str, FILE_str, FALSE))
1747 wmove(com_win, 0, 0);
1749 if (in_file_name == NULL)
1750 wprintw(com_win, no_file_string);
1752 wprintw(com_win, current_file_str, in_file_name);
1754 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1756 else if (compare(cmd_str, CHARACTER, FALSE))
1758 wmove(com_win, 0, 0);
1760 wprintw(com_win, char_str, *point);
1762 else if (compare(cmd_str, REDRAW, FALSE))
1764 else if (compare(cmd_str, RESEQUENCE, FALSE))
1766 tmp_line = first_line->next_line;
1767 while (tmp_line != NULL)
1769 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1770 tmp_line = tmp_line->next_line;
1773 else if (compare(cmd_str, AUTHOR, FALSE))
1775 wmove(com_win, 0, 0);
1777 wprintw(com_win, "written by Hugh Mahon");
1779 else if (compare(cmd_str, VERSION, FALSE))
1781 wmove(com_win, 0, 0);
1783 wprintw(com_win, "%s", version);
1785 else if (compare(cmd_str, CASE, FALSE))
1787 else if (compare(cmd_str, NOCASE, FALSE))
1789 else if (compare(cmd_str, EXPAND, FALSE))
1791 else if (compare(cmd_str, NOEXPAND, FALSE))
1792 expand_tabs = FALSE;
1793 else if (compare(cmd_str, Exit_string, FALSE))
1795 else if (compare(cmd_str, chinese_cmd, FALSE))
1799 nc_setattrib(A_NC_BIG5);
1802 else if (compare(cmd_str, nochinese_cmd, FALSE))
1806 nc_clearattrib(A_NC_BIG5);
1809 else if (compare(cmd_str, QUIT_string, FALSE))
1811 else if (*cmd_str == '!')
1814 if ((*cmd_str == ' ') || (*cmd_str == 9))
1815 cmd_str = next_word(cmd_str);
1816 sh_command(cmd_str);
1818 else if ((*cmd_str == '<') && (!in_pipe))
1823 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1824 cmd_str = next_word(cmd_str);
1829 else if ((*cmd_str == '>') && (!out_pipe))
1833 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1834 cmd_str = next_word(cmd_str);
1840 wmove(com_win, 0, 0);
1842 wprintw(com_win, unkn_cmd_str, cmd_str);
1844 if (cmd_str2 != NULL)
1848 /* determine horizontal position for get_string */
1850 scan(char *line, int offset, int column)
1862 j += len_char(*stemp, j);
1868 /* read string from input on command line */
1870 get_string(char *prompt, int advance)
1877 int g_horz, g_position, g_pos;
1880 g_point = tmp_string = malloc(512);
1883 waddstr(com_win, prompt);
1885 nam_str = tmp_string;
1886 clear_com_win = TRUE;
1887 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1892 in = wgetch(com_win);
1895 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1899 g_horz = scan(g_point, g_pos, g_position);
1900 tmp_int = tmp_int - g_horz;
1901 for (; 0 < tmp_int; tmp_int--)
1903 if ((g_horz+tmp_int) < (last_col - 1))
1905 waddch(com_win, '\010');
1906 waddch(com_win, ' ');
1907 waddch(com_win, '\010');
1912 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1914 if (in == '\026') /* control-v, accept next character verbatim */
1915 { /* allows entry of ^m, ^j, and ^h */
1917 in = wgetch(com_win);
1923 if (!isprint((unsigned char)in) && (g_horz < (last_col - 1)))
1924 g_horz += out_char(com_win, in, g_horz);
1928 if (g_horz < (last_col - 1))
1929 waddch(com_win, (unsigned char)in);
1936 } while ((in != '\n') && (in != '\r'));
1938 nam_str = tmp_string;
1939 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1940 nam_str = next_word(nam_str);
1941 string = malloc(strlen(nam_str) + 1);
1942 strcpy(string, nam_str);
1948 /* compare two strings */
1950 compare(char *string1, char *string2, int sensitive)
1958 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
1965 if (*strng1 != *strng2)
1970 if (toupper((unsigned char)*strng1) != toupper((unsigned char)*strng2))
1975 if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
1982 goto_line(char *cmd_str)
1987 char direction = '\0';
1988 struct text *t_line;
1992 while ((*ptr >='0') && (*ptr <= '9'))
1994 i= i * 10 + (*ptr - '0');
2000 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
2003 t_line = t_line->prev_line;
2006 while ((t_line->line_number < number) && (t_line->next_line != NULL))
2010 t_line = t_line->next_line;
2012 if ((i < 30) && (i > 0))
2014 move_rel(direction, i);
2018 if (direction != 'd')
2027 point = curr_line->line;
2029 midscreen((last_line / 2), point);
2032 wmove(com_win, 0, 0);
2034 wprintw(com_win, line_num_str, curr_line->line_number);
2035 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2038 /* put current line in middle of screen */
2040 midscreen(int line, unsigned char *pnt)
2042 struct text *mid_line;
2045 line = min(line, last_line);
2046 mid_line = curr_line;
2047 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2048 curr_line = curr_line->prev_line;
2049 scr_vert = scr_horz = 0;
2050 wmove(text_win, 0, 0);
2053 curr_line = mid_line;
2055 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2058 /* get arguments from command line */
2060 get_options(int numargs, char *arguments[])
2064 struct files *temp_names = NULL;
2067 int no_more_opts = FALSE;
2070 | see if editor was invoked as 'ree' (restricted mode)
2073 if (!(name = strrchr(arguments[0], '/')))
2074 name = arguments[0];
2077 if (!strcmp(name, "ree"))
2080 top_of_stack = NULL;
2084 while ((count < numargs)&& (!no_more_opts))
2086 buff = arguments[count];
2087 if (!strcmp("-i", buff))
2089 info_window = FALSE;
2091 else if (!strcmp("-e", buff))
2093 expand_tabs = FALSE;
2095 else if (!strcmp("-h", buff))
2099 else if (!strcmp("-?", buff))
2101 fprintf(stderr, usage0, arguments[0]);
2102 fputs(usage1, stderr);
2103 fputs(usage2, stderr);
2104 fputs(usage3, stderr);
2105 fputs(usage4, stderr);
2108 else if ((*buff == '+') && (start_at_line == NULL))
2111 start_at_line = buff;
2113 else if (!(strcmp("--", buff)))
2114 no_more_opts = TRUE;
2118 no_more_opts = TRUE;
2122 while (count < numargs)
2124 buff = arguments[count];
2125 if (top_of_stack == NULL)
2127 temp_names = top_of_stack = name_alloc();
2131 temp_names->next_name = name_alloc();
2132 temp_names = temp_names->next_name;
2134 ptr = temp_names->name = malloc(strlen(buff) + 1);
2135 while (*buff != '\0')
2142 temp_names->next_name = NULL;
2149 /* open or close files according to flags */
2157 clear_com_win = TRUE;
2158 tmp_vert = scr_vert;
2159 tmp_horz = scr_horz;
2160 tmp_line = curr_line;
2163 in_file_name = tmp_file = top_of_stack->name;
2164 top_of_stack = top_of_stack->next_name;
2166 temp = stat(tmp_file, &buf);
2167 buf.st_mode &= ~07777;
2168 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2170 wprintw(com_win, file_is_dir_msg, tmp_file);
2180 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2182 wmove(com_win, 0, 0);
2185 wprintw(com_win, new_file_msg, tmp_file);
2187 wprintw(com_win, cant_open_msg, tmp_file);
2189 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2199 line_num = curr_line->line_number;
2200 scr_vert = tmp_vert;
2201 scr_horz = tmp_horz;
2203 curr_line= first_line;
2205 curr_line = tmp_line;
2206 point = curr_line->line;
2211 if (start_at_line != NULL)
2213 line_num = atoi(start_at_line) - 1;
2214 move_rel('d', line_num);
2216 start_at_line = NULL;
2221 wmove(com_win, 0, 0);
2223 text_changes = TRUE;
2224 if ((tmp_file != NULL) && (*tmp_file != '\0'))
2225 wprintw(com_win, file_read_fin_msg, tmp_file);
2228 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2232 /* read specified file into current buffer */
2234 get_file(char *file_name)
2236 int can_read; /* file has at least one character */
2237 int length; /* length of line read by read */
2238 int append; /* should text be appended to current line */
2239 struct text *temp_line;
2240 char ro_flag = FALSE;
2242 if (recv_file) /* if reading a file */
2244 wmove(com_win, 0, 0);
2246 wprintw(com_win, reading_file_msg, file_name);
2247 if (access(file_name, 2)) /* check permission to write */
2249 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2251 wprintw(com_win, read_only_msg);
2257 if (curr_line->line_length > 1) /* if current line is not blank */
2265 can_read = FALSE; /* test if file has any characters */
2266 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2268 can_read = TRUE; /* if set file has at least 1 character */
2269 get_line(length, in_string, &append);
2271 if ((can_read) && (curr_line->line_length == 1))
2273 temp_line = curr_line->prev_line;
2274 temp_line->next_line = curr_line->next_line;
2275 if (temp_line->next_line != NULL)
2276 temp_line->next_line->prev_line = temp_line;
2277 if (curr_line->line != NULL)
2278 free(curr_line->line);
2280 curr_line = temp_line;
2282 if (input_file) /* if this is the file to be edited display number of lines */
2284 wmove(com_win, 0, 0);
2286 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2288 wprintw(com_win, read_only_msg);
2291 else if (can_read) /* not input_file and file is non-zero size */
2292 text_changes = TRUE;
2294 if (recv_file) /* if reading a file */
2300 /* read string and split into lines */
2302 get_line(int length, unsigned char *in_string, int *append)
2304 unsigned char *str1;
2305 unsigned char *str2;
2306 int num; /* offset from start of string */
2307 int char_count; /* length of new line (or added portion */
2308 int temp_counter; /* temporary counter value */
2309 struct text *tline; /* temporary pointer to new line */
2310 int first_time; /* if TRUE, the first time through the loop */
2315 while (num < length)
2329 /* find end of line */
2330 while ((*str2 != '\n') && (num < length))
2336 if (!(*append)) /* if not append to current line, insert new one */
2338 tline = txtalloc(); /* allocate data structure for next line */
2339 tline->line_number = curr_line->line_number + 1;
2340 tline->next_line = curr_line->next_line;
2341 tline->prev_line = curr_line;
2342 curr_line->next_line = tline;
2343 if (tline->next_line != NULL)
2344 tline->next_line->prev_line = tline;
2346 curr_line->line = point = (unsigned char *) malloc(char_count);
2347 curr_line->line_length = char_count;
2348 curr_line->max_length = char_count;
2352 point = resiz_line(char_count, curr_line, curr_line->line_length);
2353 curr_line->line_length += (char_count - 1);
2355 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2363 if ((num == length) && (*str2 != '\n'))
2369 draw_screen() /* redraw the screen from current postion */
2371 struct text *temp_line;
2372 unsigned char *line_out;
2375 temp_line = curr_line;
2376 temp_vert = scr_vert;
2377 wclrtobot(text_win);
2378 while ((temp_line != NULL) && (temp_vert <= last_line))
2380 line_out = temp_line->line;
2381 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2383 temp_line = temp_line->next_line;
2385 wmove(text_win, temp_vert, 0);
2386 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2389 /* prepare to exit edit session */
2393 char *file_name = in_file_name;
2396 | changes made here should be reflected in the 'save'
2397 | portion of file_op()
2400 if ((file_name == NULL) || (*file_name == '\0'))
2401 file_name = get_string(save_file_name_prompt, TRUE);
2403 if ((file_name == NULL) || (*file_name == '\0'))
2405 wmove(com_win, 0, 0);
2406 wprintw(com_win, file_not_saved_msg);
2409 clear_com_win = TRUE;
2413 tmp_file = resolve_name(file_name);
2414 if (tmp_file != file_name)
2417 file_name = tmp_file;
2420 if (write_file(file_name, 1))
2422 text_changes = FALSE;
2435 if ((text_changes) && (!noverify))
2437 ans = get_string(changes_made_prompt, TRUE);
2438 if (toupper((unsigned char)*ans) == toupper((unsigned char)*yes_char))
2439 text_changes = FALSE;
2444 if (top_of_stack == NULL)
2477 while (curr_line->next_line != NULL)
2478 curr_line = curr_line->next_line;
2479 while (curr_line != first_line)
2481 free(curr_line->line);
2482 curr_line = curr_line->prev_line;
2484 free(curr_line->next_line);
2486 curr_line->next_line = NULL;
2487 *curr_line->line = '\0';
2488 curr_line->line_length = 1;
2489 curr_line->line_number = 1;
2490 point = curr_line->line;
2491 scr_pos = scr_vert = scr_horz = 0;
2496 write_file(char *file_name, int warn_if_exists)
2500 struct text *out_line;
2503 int write_flag = TRUE;
2506 if (warn_if_exists &&
2507 ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
2509 if ((temp_fp = fopen(file_name, "r")))
2511 tmp_point = get_string(file_exists_prompt, TRUE);
2512 if (toupper((unsigned char)*tmp_point) == toupper((unsigned char)*yes_char))
2521 clear_com_win = TRUE;
2525 if ((temp_fp = fopen(file_name, "w")) == NULL)
2527 clear_com_win = TRUE;
2530 wprintw(com_win, create_file_fail_msg, file_name);
2538 wprintw(com_win, writing_file_msg, file_name);
2541 out_line = first_line;
2542 while (out_line != NULL)
2545 tmp_point= out_line->line;
2546 while (temp_pos < out_line->line_length)
2548 putc(*tmp_point, temp_fp);
2552 charac += out_line->line_length;
2553 out_line = out_line->next_line;
2560 wprintw(com_win, file_written_msg, file_name, lines, charac);
2569 /* search for string in srch_str */
2571 search(int display_message)
2577 if ((srch_str == NULL) || (*srch_str == '\0'))
2579 if (display_message)
2581 wmove(com_win, 0, 0);
2583 wprintw(com_win, searching_msg);
2585 clear_com_win = TRUE;
2589 srch_line = curr_line;
2591 if (position < curr_line->line_length)
2593 iter = position + 1;
2594 while ((!found) && (srch_line != NULL))
2596 while ((iter < srch_line->line_length) && (!found))
2599 if (case_sen) /* if case sensitive */
2602 while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
2609 else /* if not case sensitive */
2611 srch_3 = u_srch_str;
2612 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
2619 if (!((*srch_3 == '\0') && (found)))
2622 if (iter < srch_line->line_length)
2629 srch_line = srch_line->next_line;
2630 if (srch_line != NULL)
2631 srch_1 = srch_line->line;
2638 if (display_message)
2640 wmove(com_win, 0, 0);
2644 if (lines_moved == 0)
2646 while (position < iter)
2651 if (lines_moved < 30)
2653 move_rel('d', lines_moved);
2654 while (position < iter)
2659 absolute_lin += lines_moved;
2660 curr_line = srch_line;
2665 midscreen((last_line / 2), point);
2671 if (display_message)
2673 wmove(com_win, 0, 0);
2675 wprintw(com_win, str_not_found_msg, srch_str);
2678 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2683 /* prompt and read search string (srch_str) */
2687 if (srch_str != NULL)
2689 if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
2691 srch_str = get_string(search_prompt_str, FALSE);
2694 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2695 while (*srch_3 != '\0')
2697 *srch_1 = toupper(*srch_3);
2705 /* delete current character */
2709 in = 8; /* backspace */
2710 if (position < curr_line->line_length) /* if not end of line */
2712 if ((ee_chinese) && (*point > 127) &&
2713 ((curr_line->line_length - position) >= 2))
2730 /* undelete last deleted character */
2734 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2740 if (d_char[1] != '\0')
2748 /* delete word in front of cursor */
2754 unsigned char *d_word2;
2755 unsigned char *d_word3;
2756 unsigned char tmp_char[3];
2760 d_word = malloc(curr_line->line_length);
2761 tmp_char[0] = d_char[0];
2762 tmp_char[1] = d_char[1];
2763 tmp_char[2] = d_char[2];
2767 while ((tposit < curr_line->line_length) &&
2768 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2771 *d_word2 = *d_word3;
2775 while ((tposit < curr_line->line_length) &&
2776 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2779 *d_word2 = *d_word3;
2784 d_wrd_len = difference = d_word2 - d_word;
2786 while (tposit < curr_line->line_length)
2789 *d_word2 = *d_word3;
2793 curr_line->line_length -= difference;
2795 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2796 d_char[0] = tmp_char[0];
2797 d_char[1] = tmp_char[1];
2798 d_char[2] = tmp_char[2];
2799 text_changes = TRUE;
2803 /* undelete last deleted word */
2809 unsigned char *tmp_old_ptr;
2810 unsigned char *tmp_space;
2811 unsigned char *tmp_ptr;
2812 unsigned char *d_word_ptr;
2815 | resize line to handle undeleted word
2817 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2818 point = resiz_line(d_wrd_len, curr_line, position);
2819 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2820 d_word_ptr = d_word;
2823 | copy d_word contents into temp space
2825 while (temp <= d_wrd_len)
2828 *tmp_ptr = *d_word_ptr;
2832 tmp_old_ptr = point;
2835 | copy contents of line from curent position to eol into
2838 while (tposit < curr_line->line_length)
2842 *tmp_ptr = *tmp_old_ptr;
2846 curr_line->line_length += d_wrd_len;
2847 tmp_old_ptr = point;
2849 tmp_ptr = tmp_space;
2852 | now copy contents from temp space back to original line
2854 while (tposit < temp)
2857 *tmp_old_ptr = *tmp_ptr;
2861 *tmp_old_ptr = '\0';
2863 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2866 /* delete from cursor to end of line */
2876 d_line = malloc(curr_line->line_length);
2880 while (tposit < curr_line->line_length)
2887 dlt_line->line_length = 1 + tposit - position;
2890 curr_line->line_length = position;
2891 wclrtoeol(text_win);
2892 if (curr_line->next_line != NULL)
2897 text_changes = TRUE;
2900 /* undelete last deleted line */
2908 if (dlt_line->line_length == 0)
2913 point = resiz_line(dlt_line->line_length, curr_line, position);
2914 curr_line->line_length += dlt_line->line_length - 1;
2918 while (tposit < dlt_line->line_length)
2926 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2929 /* advance to next word */
2933 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2935 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2939 /* move relative to current line */
2941 move_rel(int direction, int lines)
2946 if (direction == 'u')
2949 while (position > 1)
2951 for (i = 0; i < lines; i++)
2955 if ((last_line > 5) && ( scr_vert < 4))
2958 tmp_line = curr_line;
2959 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2963 scr_vert = scr_vert + i;
2964 curr_line = tmp_line;
2972 if ((position != 1) && (curr_line->next_line != NULL))
2975 scr_pos = scr_horz = 0;
2979 midscreen(scr_vert, point);
2984 for (i = 1; i < lines; i++)
2988 if ((last_line > 10) && (scr_vert > (last_line - 5)))
2991 tmp_line = curr_line;
2992 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
2997 scr_vert = scr_vert - i;
2998 curr_line = tmp_line;
3003 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
3006 /* go to end of line */
3010 if (position < curr_line->line_length)
3012 while (position < curr_line->line_length)
3015 else if (curr_line->next_line != NULL)
3018 while (position < curr_line->line_length)
3023 /* move to beginning of line */
3027 if (point != curr_line->line)
3029 while (point != curr_line->line)
3032 else if (curr_line->prev_line != NULL)
3039 /* advance to beginning of next line */
3043 if ((point != curr_line->line) || (scr_pos > 0))
3045 while (position < curr_line->line_length)
3049 else if (curr_line->next_line != NULL)
3059 struct text *tmpline = first_line;
3062 while ((tmpline != NULL) && (tmpline != curr_line))
3065 tmpline = tmpline->next_line;
3070 /* execute shell command */
3072 sh_command(char *string)
3076 char *path; /* directory path to executable */
3077 int parent; /* zero if child, child's pid if parent */
3080 struct text *line_holder;
3082 if (restrict_mode())
3087 if (!(path = getenv("SHELL")))
3089 last_slash = temp_point = path;
3090 while (*temp_point != '\0')
3092 if (*temp_point == '/')
3093 last_slash = ++temp_point;
3099 | if in_pipe is true, then output of the shell operation will be
3100 | read by the editor, and curses doesn't need to be turned off
3105 keypad(com_win, FALSE);
3106 keypad(text_win, FALSE);
3119 pipe(pipe_in); /* create a pipe */
3121 if (!parent) /* if the child */
3124 | child process which will fork and exec shell command (if shell output is
3125 | to be read by editor)
3129 | redirect stdout to pipe
3131 temp_stdout = dup(1);
3135 | redirect stderr to pipe
3137 temp_stderr = dup(2);
3142 | child will now continue down 'if (!in_pipe)'
3146 else /* if the parent */
3149 | prepare editor to read from the pipe
3151 signal(SIGCHLD, SIG_IGN);
3152 line_holder = curr_line;
3153 tmp_vert = scr_vert;
3155 get_fd = pipe_in[0];
3158 scr_vert = tmp_vert;
3159 scr_horz = scr_pos = 0;
3161 curr_line = line_holder;
3163 point = curr_line->line;
3165 signal(SIGCHLD, SIG_DFL);
3167 | since flag "in_pipe" is still TRUE, the path which waits for the child
3168 | process to die will be avoided.
3169 | (the pipe is closed, no more output can be expected)
3175 signal(SIGINT, SIG_IGN);
3181 | fork process which will exec command
3184 if (!parent) /* if the child */
3191 | prepare the child process (soon to exec a shell command) to read from the
3192 | pipe (which will be output from the editor's buffer)
3199 for (value = 1; value < 24; value++)
3200 signal(value, SIG_DFL);
3201 execl(path, last_slash, "-c", string, NULL);
3202 fprintf(stderr, exec_err_msg, path);
3205 else /* if the parent */
3210 | output the contents of the buffer to the pipe (to be read by the
3211 | process forked and exec'd above as stdin)
3214 line_holder = first_line;
3215 while (line_holder != NULL)
3217 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3218 write(pipe_out[1], "\n", 1);
3219 line_holder = line_holder->next_line;
3226 return_val = wait((int *) 0);
3228 while ((return_val != parent) && (return_val != -1));
3230 | if this process is actually the child of the editor, exit. Here's how it
3232 | The editor forks a process. If output must be sent to the command to be
3233 | exec'd another process is forked, and that process (the child's child)
3234 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3235 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3236 | If this is the editor process, shell_fork will be true, otherwise this is
3237 | the child of the edit process.
3242 signal(SIGINT, edit_abort);
3246 fputs(continue_msg, stdout);
3248 while ((in = getchar()) != '\n')
3258 keypad(text_win, TRUE);
3259 keypad(com_win, TRUE);
3261 clearok(info_win, TRUE);
3267 /* set up the terminal for operating with ae */
3271 if (!curses_initialized)
3278 curses_initialized = TRUE;
3281 if (((LINES > 15) && (COLS >= 80)) && info_window)
3282 last_line = LINES - 8;
3285 info_window = FALSE;
3286 last_line = LINES - 2;
3289 idlok(stdscr, TRUE);
3290 com_win = newwin(1, COLS, (LINES - 1), 0);
3291 keypad(com_win, TRUE);
3292 idlok(com_win, TRUE);
3295 text_win = newwin((LINES - 1), COLS, 0, 0);
3297 text_win = newwin((LINES - 7), COLS, 6, 0);
3298 keypad(text_win, TRUE);
3299 idlok(text_win, TRUE);
3301 help_win = newwin((LINES - 1), COLS, 0, 0);
3302 keypad(help_win, TRUE);
3303 idlok(help_win, TRUE);
3306 info_type = CONTROL_KEYS;
3307 info_win = newwin(6, COLS, 0, 0);
3312 last_col = COLS - 1;
3313 local_LINES = LINES;
3318 nc_setattrib(A_NC_BIG5);
3326 if ((LINES == local_LINES) && (COLS == local_COLS))
3339 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3342 menu_op(struct menu_entries menu_list[])
3345 int max_width, max_height;
3352 int top_offset; /* offset from top where menu items start */
3353 int vert_size; /* vertical size for menu list item display */
3354 int off_start = 1; /* offset from start of menu items to start display */
3358 | determine number and width of menu items
3362 while (menu_list[list_size + 1].item_string != NULL)
3365 for (counter = 0; counter <= list_size; counter++)
3367 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3371 max_width = max(max_width, strlen(menu_cancel_msg));
3372 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3376 | make sure that window is large enough to handle menu
3377 | if not, print error message and return to calling function
3380 if (max_width > COLS)
3382 wmove(com_win, 0, 0);
3384 wprintw(com_win, menu_too_lrg_msg);
3386 clear_com_win = TRUE;
3392 if (list_size > LINES)
3395 if (max_height > 11)
3396 vert_size = max_height - 8;
3398 vert_size = max_height;
3402 vert_size = list_size;
3403 max_height = list_size;
3406 if (LINES >= (vert_size + 8))
3408 if (menu_list[0].argument != MENU_WARN)
3409 max_height = vert_size + 8;
3411 max_height = vert_size + 7;
3414 x_off = (COLS - max_width) / 2;
3415 y_off = (LINES - max_height - 1) / 2;
3416 temp_win = newwin(max_height, max_width, y_off, x_off);
3417 keypad(temp_win, TRUE);
3419 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3425 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3427 wmove(temp_win, (counter + top_offset - off_start), 3);
3430 in = wgetch(temp_win);
3435 if (isascii(input) && isalnum(input))
3439 temp = 1 + tolower(input) - 'a';
3441 else if (isdigit(input))
3443 temp = (2 + 'z' - 'a') + (input - '0');
3446 if (temp <= list_size)
3456 case ' ': /* space */
3457 case '\004': /* ^d, down */
3461 if (counter > list_size)
3464 case '\010': /* ^h, backspace*/
3465 case '\025': /* ^u, up */
3466 case 127: /* ^?, delete */
3472 counter = list_size;
3474 case '\033': /* escape key */
3475 if (menu_list[0].argument != MENU_WARN)
3478 case '\014': /* ^l */
3479 case '\022': /* ^r, redraw */
3480 paint_menu(menu_list, max_width, max_height,
3481 list_size, top_offset, temp_win,
3482 off_start, vert_size);
3489 if (((list_size - off_start) >= (vert_size - 1)) &&
3490 (counter > (off_start + vert_size - 3)) &&
3493 if (counter == list_size)
3494 off_start = (list_size - vert_size) + 2;
3498 paint_menu(menu_list, max_width, max_height,
3499 list_size, top_offset, temp_win, off_start,
3502 else if ((list_size != vert_size) &&
3503 (counter > (off_start + vert_size - 2)))
3505 if (counter == list_size)
3506 off_start = 2 + (list_size - vert_size);
3507 else if (off_start == 1)
3512 paint_menu(menu_list, max_width, max_height,
3513 list_size, top_offset, temp_win, off_start,
3516 else if (counter < off_start)
3521 off_start = counter;
3523 paint_menu(menu_list, max_width, max_height,
3524 list_size, top_offset, temp_win, off_start,
3528 while ((input != '\r') && (input != '\n') && (counter != 0));
3534 if ((menu_list[counter].procedure != NULL) ||
3535 (menu_list[counter].iprocedure != NULL) ||
3536 (menu_list[counter].nprocedure != NULL))
3538 if (menu_list[counter].argument != -1)
3539 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3540 else if (menu_list[counter].ptr_argument != NULL)
3541 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3543 (*menu_list[counter].nprocedure)();
3554 paint_menu(struct menu_entries menu_list[], int max_width, int max_height,
3555 int list_size, int top_offset, WINDOW *menu_win, int off_start,
3558 int counter, temp_int;
3563 | output top and bottom portions of menu box only if window
3567 if (max_height > vert_size)
3569 wmove(menu_win, 1, 1);
3571 wstandout(menu_win);
3572 waddch(menu_win, '+');
3573 for (counter = 0; counter < (max_width - 4); counter++)
3574 waddch(menu_win, '-');
3575 waddch(menu_win, '+');
3577 wmove(menu_win, (max_height - 2), 1);
3578 waddch(menu_win, '+');
3579 for (counter = 0; counter < (max_width - 4); counter++)
3580 waddch(menu_win, '-');
3581 waddch(menu_win, '+');
3582 wstandend(menu_win);
3583 wmove(menu_win, 2, 3);
3584 waddstr(menu_win, menu_list[0].item_string);
3585 wmove(menu_win, (max_height - 3), 3);
3586 if (menu_list[0].argument != MENU_WARN)
3587 waddstr(menu_win, menu_cancel_msg);
3590 wstandout(menu_win);
3592 for (counter = 0; counter < (vert_size + top_offset); counter++)
3594 if (top_offset == 4)
3596 temp_int = counter + 2;
3601 wmove(menu_win, temp_int, 1);
3602 waddch(menu_win, '|');
3603 wmove(menu_win, temp_int, (max_width - 2));
3604 waddch(menu_win, '|');
3606 wstandend(menu_win);
3608 if (list_size > vert_size)
3613 wmove(menu_win, top_offset, 3);
3614 waddstr(menu_win, more_above_str);
3619 for (counter = off_start;
3620 ((temp_int + counter - off_start) < (vert_size - 1));
3623 wmove(menu_win, (top_offset + temp_int +
3624 (counter - off_start)), 3);
3626 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3627 waddstr(menu_win, menu_list[counter].item_string);
3630 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3632 if (counter == list_size)
3635 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3636 wprintw(menu_win, menu_list[counter].item_string);
3639 wprintw(menu_win, more_below_str);
3643 for (counter = 1; counter <= list_size; counter++)
3645 wmove(menu_win, (top_offset + counter - 1), 3);
3647 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3648 waddstr(menu_win, menu_list[counter].item_string);
3659 clearok(help_win, TRUE);
3660 for (counter = 0; counter < 22; counter++)
3662 wmove(help_win, counter, 0);
3663 waddstr(help_win, (emacs_keys_mode) ?
3664 emacs_help_text[counter] : help_text[counter]);
3668 wmove(com_win, 0, 0);
3669 wprintw(com_win, press_any_key_msg);
3671 counter = wgetch(com_win);
3675 wmove(com_win, 0, 0);
3683 paint_info_win(void)
3691 for (counter = 0; counter < 5; counter++)
3693 wmove(info_win, counter, 0);
3694 wclrtoeol(info_win);
3695 if (info_type == CONTROL_KEYS)
3696 waddstr(info_win, (emacs_keys_mode) ?
3697 emacs_control_keys[counter] : control_keys[counter]);
3698 else if (info_type == COMMANDS)
3699 waddstr(info_win, command_strings[counter]);
3701 wmove(info_win, 5, 0);
3703 wstandout(info_win);
3704 waddstr(info_win, separator);
3705 wstandend(info_win);
3710 no_info_window(void)
3716 info_window = FALSE;
3717 last_line = LINES - 2;
3718 text_win = newwin((LINES - 1), COLS, 0, 0);
3719 keypad(text_win, TRUE);
3720 idlok(text_win, TRUE);
3721 clearok(text_win, TRUE);
3722 midscreen(scr_vert, point);
3724 clear_com_win = TRUE;
3728 create_info_window(void)
3732 last_line = LINES - 8;
3734 text_win = newwin((LINES - 7), COLS, 6, 0);
3735 keypad(text_win, TRUE);
3736 idlok(text_win, TRUE);
3739 info_win = newwin(6, COLS, 0, 0);
3741 info_type = CONTROL_KEYS;
3742 midscreen(min(scr_vert, last_line), point);
3743 clearok(info_win, TRUE);
3746 clear_com_win = TRUE;
3755 if (restrict_mode())
3760 if (arg == READ_FILE)
3762 string = get_string(file_read_prompt_str, TRUE);
3764 tmp_file = resolve_name(string);
3766 if (tmp_file != string)
3770 else if (arg == WRITE_FILE)
3772 string = get_string(file_write_prompt_str, TRUE);
3773 tmp_file = resolve_name(string);
3774 write_file(tmp_file, 1);
3775 if (tmp_file != string)
3779 else if (arg == SAVE_FILE)
3782 | changes made here should be reflected in finish()
3790 string = in_file_name;
3791 if ((string == NULL) || (*string == '\0'))
3792 string = get_string(save_file_name_prompt, TRUE);
3793 if ((string == NULL) || (*string == '\0'))
3795 wmove(com_win, 0, 0);
3796 wprintw(com_win, file_not_saved_msg);
3799 clear_com_win = TRUE;
3804 tmp_file = resolve_name(string);
3805 if (tmp_file != string)
3811 if (write_file(string, 1))
3813 in_file_name = string;
3814 text_changes = FALSE;
3827 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3840 menu_op(leave_menu);
3851 clearok(info_win, TRUE);
3855 clearok(text_win, TRUE);
3856 midscreen(scr_vert, point);
3860 | The following routines will "format" a paragraph (as defined by a
3861 | block of text with blank lines before and after the block).
3864 /* test if line has any non-space characters */
3866 Blank_Line(struct text *test_line)
3868 unsigned char *line;
3871 if (test_line == NULL)
3875 line = test_line->line;
3878 | To handle troff/nroff documents, consider a line with a
3879 | period ('.') in the first column to be blank. To handle mail
3880 | messages with included text, consider a line with a '>' blank.
3883 if ((*line == '.') || (*line == '>'))
3886 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3891 if (length != test_line->line_length)
3897 /* format the paragraph according to set margins */
3907 unsigned char *line;
3908 unsigned char *tmp_srchstr;
3909 unsigned char *temp1, *temp2;
3910 unsigned char *temp_dword;
3911 unsigned char temp_d_char[3];
3913 temp_d_char[0] = d_char[0];
3914 temp_d_char[1] = d_char[1];
3915 temp_d_char[2] = d_char[2];
3918 | if observ_margins is not set, or the current line is blank,
3919 | do not format the current paragraph
3922 if ((!observ_margins) || (Blank_Line(curr_line)))
3926 | save the currently set flags, and clear them
3929 wmove(com_win, 0, 0);
3931 wprintw(com_win, formatting_msg);
3935 | get current position in paragraph, so after formatting, the cursor
3936 | will be in the same relative position
3939 tmp_af = auto_format;
3940 auto_format = FALSE;
3944 temp_dword = d_word;
3946 temp_case = case_sen;
3948 tmp_srchstr = srch_str;
3949 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3950 if ((*point == ' ') || (*point == '\t'))
3954 line = temp1 = point;
3955 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3965 while (!Blank_Line(curr_line->prev_line))
3969 while ((line != point) && (status))
3971 status = search(FALSE);
3975 wmove(com_win, 0, 0);
3977 wprintw(com_win, formatting_msg);
3981 | now get back to the start of the paragraph to start formatting
3986 while (!Blank_Line(curr_line->prev_line))
3989 observ_margins = FALSE;
3992 | Start going through lines, putting spaces at end of lines if they do
3993 | not already exist. Append lines together to get one long line, and
3994 | eliminate spacing at begin of lines.
3997 while (!Blank_Line(curr_line->next_line))
4009 if ((*point == ' ') || (*point == '\t'))
4014 | Now there is one long line. Eliminate extra spaces within the line
4015 | after the first word (so as not to blow away any indenting the user
4021 while (position < curr_line->line_length)
4023 if ((*point == ' ') && (*(point + 1) == ' '))
4030 | Now make sure there are two spaces after a '.'.
4034 while (position < curr_line->line_length)
4036 if ((*point == '.') && (*(point + 1) == ' '))
4041 while (*point == ' ')
4047 observ_margins = TRUE;
4050 wmove(com_win, 0, 0);
4052 wprintw(com_win, formatting_msg);
4056 | create lines between margins
4059 while (position < curr_line->line_length)
4061 while ((scr_pos < right_margin) && (position < curr_line->line_length))
4063 if (position < curr_line->line_length)
4073 | go back to begin of paragraph, put cursor back to original position
4077 while (!Blank_Line(curr_line->prev_line))
4081 | find word cursor was in
4084 while ((status) && (string_count > 0))
4091 | offset the cursor to where it was before from the start of the word
4101 | reset flags and strings to what they were before formatting
4106 d_word = temp_dword;
4107 case_sen = temp_case;
4109 srch_str = tmp_srchstr;
4110 d_char[0] = temp_d_char[0];
4111 d_char[1] = temp_d_char[1];
4112 d_char[2] = temp_d_char[2];
4113 auto_format = tmp_af;
4115 midscreen(scr_vert, point);
4120 unsigned char *init_name[3] = {
4121 "/usr/share/misc/init.ee",
4126 /* check for init file and read it if it exists */
4131 unsigned char *string;
4132 unsigned char *str1;
4133 unsigned char *str2;
4138 string = getenv("HOME");
4141 str1 = home = malloc(strlen(string)+10);
4142 strcpy(home, string);
4143 strcat(home, "/.init.ee");
4144 init_name[1] = home;
4145 string = malloc(512);
4147 for (counter = 0; counter < 3; counter++)
4149 if (!(access(init_name[counter], 4)))
4151 init_file = fopen(init_name[counter], "r");
4152 while ((str2 = fgets(string, 512, init_file)) != NULL)
4154 str1 = str2 = string;
4155 while (*str2 != '\n')
4159 if (unique_test(string, init_strings) != 1)
4162 if (compare(str1, CASE, FALSE))
4164 else if (compare(str1, NOCASE, FALSE))
4166 else if (compare(str1, EXPAND, FALSE))
4168 else if (compare(str1, NOEXPAND, FALSE))
4169 expand_tabs = FALSE;
4170 else if (compare(str1, INFO, FALSE))
4172 else if (compare(str1, NOINFO, FALSE))
4173 info_window = FALSE;
4174 else if (compare(str1, MARGINS, FALSE))
4175 observ_margins = TRUE;
4176 else if (compare(str1, NOMARGINS, FALSE))
4177 observ_margins = FALSE;
4178 else if (compare(str1, AUTOFORMAT, FALSE))
4181 observ_margins = TRUE;
4183 else if (compare(str1, NOAUTOFORMAT, FALSE))
4184 auto_format = FALSE;
4185 else if (compare(str1, Echo, FALSE))
4187 str1 = next_word(str1);
4191 else if (compare(str1, PRINTCOMMAND, FALSE))
4193 str1 = next_word(str1);
4194 print_command = malloc(strlen(str1)+1);
4195 strcpy(print_command, str1);
4197 else if (compare(str1, RIGHTMARGIN, FALSE))
4199 str1 = next_word(str1);
4200 if ((*str1 >= '0') && (*str1 <= '9'))
4202 temp_int = atoi(str1);
4204 right_margin = temp_int;
4207 else if (compare(str1, HIGHLIGHT, FALSE))
4208 nohighlight = FALSE;
4209 else if (compare(str1, NOHIGHLIGHT, FALSE))
4211 else if (compare(str1, EIGHTBIT, FALSE))
4213 else if (compare(str1, NOEIGHTBIT, FALSE))
4218 else if (compare(str1, EMACS_string, FALSE))
4219 emacs_keys_mode = TRUE;
4220 else if (compare(str1, NOEMACS_string, FALSE))
4221 emacs_keys_mode = FALSE;
4222 else if (compare(str1, chinese_cmd, FALSE))
4227 else if (compare(str1, nochinese_cmd, FALSE))
4236 string = getenv("LANG");
4239 if (strcmp(string, "zh_TW.big5") == 0)
4248 | Save current configuration to .init.ee file in the current directory.
4255 FILE *old_init_file = NULL;
4256 char *file_name = ".init.ee";
4257 char *home_dir = "~/.init.ee";
4264 if (restrict_mode())
4269 option = menu_op(config_dump_menu);
4272 wmove(com_win, 0, 0);
4276 wprintw(com_win, conf_not_saved_msg);
4280 else if (option == 2)
4281 file_name = resolve_name(home_dir);
4284 | If a .init.ee file exists, move it to .init.ee.old.
4287 if (stat(file_name, &buf) != -1)
4289 sprintf(buffer, "%s.old", file_name);
4291 link(file_name, buffer);
4293 old_init_file = fopen(buffer, "r");
4296 init_file = fopen(file_name, "w");
4297 if (init_file == NULL)
4299 wprintw(com_win, conf_dump_err_msg);
4304 if (old_init_file != NULL)
4307 | Copy non-configuration info into new .init.ee file.
4309 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4311 length = strlen(string);
4312 string[length - 1] = '\0';
4314 if (unique_test(string, init_strings) == 1)
4316 if (compare(string, Echo, FALSE))
4318 fprintf(init_file, "%s\n", string);
4322 fprintf(init_file, "%s\n", string);
4325 fclose(old_init_file);
4328 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4329 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4330 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4331 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4332 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4333 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4334 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4335 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4336 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4337 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4338 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4342 wprintw(com_win, conf_dump_success_msg, file_name);
4345 if ((option == 2) && (file_name != home_dir))
4351 /* echo the given string */
4353 echo_string(char *string)
4359 while (*temp != '\0')
4366 else if (*temp == 't')
4368 else if (*temp == 'b')
4370 else if (*temp == 'r')
4372 else if (*temp == 'f')
4374 else if ((*temp == 'e') || (*temp == 'E'))
4375 putchar('\033'); /* escape */
4376 else if (*temp == '\\')
4378 else if (*temp == '\'')
4380 else if ((*temp >= '0') && (*temp <= '9'))
4383 while ((*temp >= '0') && (*temp <= '9'))
4385 Counter = (8 * Counter) + (*temp - '0');
4403 /* check spelling of words in the editor */
4407 if (restrict_mode())
4411 top(); /* go to top of file */
4412 insert_line(FALSE); /* create two blank lines */
4415 command(shell_echo_msg);
4417 wmove(com_win, 0, 0);
4418 wprintw(com_win, spell_in_prog_msg);
4420 command("<>!spell"); /* send contents of buffer to command 'spell'
4421 and read the results back into the editor */
4427 char template[128], *name;
4431 if (restrict_mode())
4435 (void)sprintf(template, "/tmp/ee.XXXXXXXX");
4436 fd = mkstemp(template);
4438 wmove(com_win, 0, 0);
4439 wprintw(com_win, create_file_fail_msg, name);
4444 if (write_file(name, 0))
4446 sprintf(string, "ispell %s", name);
4457 first_word_len(struct text *test_line)
4462 if (test_line == NULL)
4465 pnt = test_line->line;
4466 if ((pnt == NULL) || (*pnt == '\0') ||
4467 (*pnt == '.') || (*pnt == '>'))
4470 if ((*pnt == ' ') || (*pnt == '\t'))
4472 pnt = next_word(pnt);
4479 while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
4484 while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
4492 /* format the paragraph according to set margins */
4501 int tmp_d_line_length;
4502 int leave_loop = FALSE;
4506 unsigned char *line;
4507 unsigned char *tmp_srchstr;
4508 unsigned char *temp1, *temp2;
4509 unsigned char *temp_dword;
4510 unsigned char temp_d_char[3];
4511 unsigned char *tmp_d_line;
4514 temp_d_char[0] = d_char[0];
4515 temp_d_char[1] = d_char[1];
4516 temp_d_char[2] = d_char[2];
4519 | if observ_margins is not set, or the current line is blank,
4520 | do not format the current paragraph
4523 if ((!observ_margins) || (Blank_Line(curr_line)))
4527 | get current position in paragraph, so after formatting, the cursor
4528 | will be in the same relative position
4531 tmp_d_line = d_line;
4532 tmp_d_line_length = dlt_line->line_length;
4534 auto_format = FALSE;
4536 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
4538 temp_dword = d_word;
4539 temp_dwl = d_wrd_len;
4542 temp_case = case_sen;
4544 tmp_srchstr = srch_str;
4545 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4546 if ((*point == ' ') || (*point == '\t'))
4550 line = temp1 = point;
4551 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4561 while (!Blank_Line(curr_line->prev_line))
4565 while ((line != point) && (status))
4567 status = search(FALSE);
4572 | now get back to the start of the paragraph to start checking
4577 while (!Blank_Line(curr_line->prev_line))
4581 | Start going through lines, putting spaces at end of lines if they do
4582 | not already exist. Check line length, and move words to the next line
4583 | if they cross the margin. Then get words from the next line if they
4584 | will fit in before the margin.
4591 if (position != curr_line->line_length)
4605 | fill line if first word on next line will fit
4606 | in the line without crossing the margin
4609 while ((curr_line->next_line != NULL) &&
4610 ((word_len = first_word_len(curr_line->next_line)) > 0)
4611 && ((scr_pos + word_len) < right_margin))
4614 if ((*point == ' ') || (*point == '\t'))
4621 | We know this line was not blank before, so
4622 | make sure that it doesn't have one of the
4623 | leading characters that indicate the line
4624 | should not be modified.
4626 | We also know that this character should not
4627 | be left as the first character of this line.
4630 if ((Blank_Line(curr_line)) &&
4631 (curr_line->line[0] != '.') &&
4632 (curr_line->line[0] != '>'))
4641 | go to end of previous line
4647 | make sure there's a space at the end of the line
4660 | make sure line does not cross right margin
4663 while (right_margin <= scr_pos)
4669 if (Blank_Line(curr_line->next_line))
4673 if ((*point == ' ') || (*point == '\t'))
4683 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4693 | go back to begin of paragraph, put cursor back to original position
4698 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4702 | find word cursor was in
4706 while ((status) && (string_count > 0))
4708 status = search(FALSE);
4713 | offset the cursor to where it was before from the start of the word
4722 if ((string_count > 0) && (offset < 0))
4732 | reset flags and strings to what they were before formatting
4737 d_word = temp_dword;
4738 d_wrd_len = temp_dwl;
4739 case_sen = temp_case;
4741 srch_str = tmp_srchstr;
4742 d_char[0] = temp_d_char[0];
4743 d_char[1] = temp_d_char[1];
4744 d_char[2] = temp_d_char[2];
4746 dlt_line->line_length = tmp_d_line_length;
4747 d_line = tmp_d_line;
4750 midscreen(scr_vert, point);
4762 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4763 (expand_tabs ? ON : OFF));
4764 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4765 (case_sen ? ON : OFF));
4766 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4767 (observ_margins ? ON : OFF));
4768 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4769 (auto_format ? ON : OFF));
4770 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4771 (eightbit ? ON : OFF));
4772 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4773 (info_window ? ON : OFF));
4774 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4775 (emacs_keys_mode ? ON : OFF));
4776 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4778 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4779 (ee_chinese ? ON : OFF));
4781 ret_value = menu_op(modes_menu);
4786 expand_tabs = !expand_tabs;
4789 case_sen = !case_sen;
4792 observ_margins = !observ_margins;
4795 auto_format = !auto_format;
4797 observ_margins = TRUE;
4800 eightbit = !eightbit;
4805 nc_setattrib(A_NC_BIG5);
4807 nc_clearattrib(A_NC_BIG5);
4811 wnoutrefresh(text_win);
4817 create_info_window();
4820 emacs_keys_mode = !emacs_keys_mode;
4825 string = get_string(margin_prompt, TRUE);
4828 counter = atoi(string);
4830 right_margin = counter;
4835 ee_chinese = !ee_chinese;
4836 if (ee_chinese != FALSE)
4840 nc_setattrib(A_NC_BIG5);
4842 nc_clearattrib(A_NC_BIG5);
4850 while (ret_value != 0);
4853 /* a strchr() look-alike for systems without strchr() */
4855 is_in_string(char *string, char *substring)
4859 for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
4861 for (full = string; (full != NULL) && (*full != '\0');
4872 | handle names of the form "~/file", "~user/file",
4873 | "$HOME/foo", "~/$FOO", etc.
4877 resolve_name(char *name)
4879 char long_buffer[1024];
4880 char short_buffer[128];
4888 struct passwd *user;
4895 user = (struct passwd *) getpwuid(index);
4900 slash = strchr(name, '/');
4904 user = (struct passwd *) getpwnam((name + 1));
4911 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4912 strcpy(buffer, user->pw_dir);
4913 strcat(buffer, slash);
4918 if (is_in_string(buffer, "$"))
4923 while ((*tmp != '\0') && (index < 1024))
4926 while ((*tmp != '\0') && (*tmp != '$') &&
4929 long_buffer[index] = *tmp;
4934 if ((*tmp == '$') && (index < 1024))
4939 if (*tmp == '{') /* } */ /* bracketed variable name */
4942 while ((*tmp != '\0') &&
4946 short_buffer[counter] = *tmp;
4955 while ((*tmp != '\0') &&
4960 short_buffer[counter] = *tmp;
4965 short_buffer[counter] = '\0';
4966 if ((slash = getenv(short_buffer)) != NULL)
4968 offset = strlen(slash);
4969 if ((offset + index) < 1024)
4970 strcpy(&long_buffer[index], slash);
4975 while ((start_of_var != tmp) && (index < 1024))
4977 long_buffer[index] = *start_of_var;
4988 long_buffer[index] = '\0';
4992 buffer = malloc(index + 1);
4993 strcpy(buffer, long_buffer);
5005 wmove(com_win, 0, 0);
5006 wprintw(com_win, restricted_msg);
5009 clear_com_win = TRUE;
5014 | The following routine tests the input string against the list of
5015 | strings, to determine if the string is a unique match with one of the
5020 unique_test(char *string, char *list[])
5028 while (list[counter] != NULL)
5030 result = compare(string, list[counter], FALSE);
5040 | Get the catalog entry, and if it got it from the catalog,
5041 | make a copy, since the buffer will be overwritten by the
5042 | next call to catgets().
5046 catgetlocal(int number, char *string)
5051 temp1 = catgets(catalog, 1, number, string);
5052 if (temp1 != string)
5054 temp2 = malloc(strlen(temp1) + 1);
5055 strcpy(temp2, temp1);
5060 #endif /* NO_CATGETS */
5063 | The following is to allow for using message catalogs which allow
5064 | the software to be 'localized', that is, to use different languages
5065 | all with the same binary. For more information, see your system
5066 | documentation, or the X/Open Internationalization Guide.
5074 setlocale(LC_ALL, "");
5076 catalog = catopen("ee", NL_CAT_LOCALE);
5077 #endif /* NO_CATGETS */
5079 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5080 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5081 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5082 mode_strings[3] = catgetlocal( 4, "margins observed ");
5083 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5084 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5085 mode_strings[6] = catgetlocal( 7, "info window ");
5086 mode_strings[8] = catgetlocal( 8, "right margin ");
5087 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5088 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5089 leave_menu[2].item_string = catgetlocal( 11, "no save");
5090 file_menu[0].item_string = catgetlocal( 12, "file menu");
5091 file_menu[1].item_string = catgetlocal( 13, "read a file");
5092 file_menu[2].item_string = catgetlocal( 14, "write a file");
5093 file_menu[3].item_string = catgetlocal( 15, "save file");
5094 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5095 search_menu[0].item_string = catgetlocal( 17, "search menu");
5096 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5097 search_menu[2].item_string = catgetlocal( 19, "search");
5098 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5099 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5100 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5101 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5102 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5103 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5104 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5105 main_menu[0].item_string = catgetlocal( 27, "main menu");
5106 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5107 main_menu[2].item_string = catgetlocal( 29, "help");
5108 main_menu[3].item_string = catgetlocal( 30, "file operations");
5109 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5110 main_menu[5].item_string = catgetlocal( 32, "settings");
5111 main_menu[6].item_string = catgetlocal( 33, "search");
5112 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5113 help_text[0] = catgetlocal( 35, "Control keys: ");
5114 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5115 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5116 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5117 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5118 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5119 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5120 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5121 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5122 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5123 help_text[10] = catgetlocal( 45, " ");
5124 help_text[11] = catgetlocal( 46, "Commands: ");
5125 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5126 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5127 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5128 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5129 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5130 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5131 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5132 help_text[19] = catgetlocal( 54, " ");
5133 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5134 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5135 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5136 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5137 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5138 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5139 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5140 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5141 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5142 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5143 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5144 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5145 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5146 no_file_string = catgetlocal( 68, "no file");
5147 ascii_code_str = catgetlocal( 69, "ascii code: ");
5148 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5149 command_str = catgetlocal( 71, "command: ");
5150 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5151 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5152 char_str = catgetlocal( 74, "character = %d");
5153 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5154 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5155 line_num_str = catgetlocal( 77, "line %d ");
5156 line_len_str = catgetlocal( 78, "length = %d");
5157 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5158 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5159 usage1 = catgetlocal( 81, " -i turn off info window\n");
5160 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5161 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5162 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5163 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5164 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5165 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5166 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5167 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5168 read_only_msg = catgetlocal( 90, ", read only");
5169 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5170 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5171 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5172 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5173 yes_char = catgetlocal( 95, "y");
5174 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5175 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5176 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5177 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5178 searching_msg = catgetlocal( 100, " ...searching");
5179 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5180 search_prompt_str = catgetlocal( 102, "search for: ");
5181 exec_err_msg = catgetlocal( 103, "could not exec %s\n");
5182 continue_msg = catgetlocal( 104, "press return to continue ");
5183 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5184 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5185 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5186 shell_prompt = catgetlocal( 108, "shell command: ");
5187 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5188 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5189 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5190 margin_prompt = catgetlocal( 112, "right margin is: ");
5191 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5192 ON = catgetlocal( 114, "ON");
5193 OFF = catgetlocal( 115, "OFF");
5194 HELP = catgetlocal( 116, "HELP");
5195 WRITE = catgetlocal( 117, "WRITE");
5196 READ = catgetlocal( 118, "READ");
5197 LINE = catgetlocal( 119, "LINE");
5198 FILE_str = catgetlocal( 120, "FILE");
5199 CHARACTER = catgetlocal( 121, "CHARACTER");
5200 REDRAW = catgetlocal( 122, "REDRAW");
5201 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5202 AUTHOR = catgetlocal( 124, "AUTHOR");
5203 VERSION = catgetlocal( 125, "VERSION");
5204 CASE = catgetlocal( 126, "CASE");
5205 NOCASE = catgetlocal( 127, "NOCASE");
5206 EXPAND = catgetlocal( 128, "EXPAND");
5207 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5208 Exit_string = catgetlocal( 130, "EXIT");
5209 QUIT_string = catgetlocal( 131, "QUIT");
5210 INFO = catgetlocal( 132, "INFO");
5211 NOINFO = catgetlocal( 133, "NOINFO");
5212 MARGINS = catgetlocal( 134, "MARGINS");
5213 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5214 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5215 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5216 Echo = catgetlocal( 138, "ECHO");
5217 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5218 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5219 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5220 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5221 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5222 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5226 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5227 emacs_help_text[0] = help_text[0];
5228 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5229 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
5230 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
5231 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5232 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5233 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5234 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5235 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5236 emacs_help_text[9] = help_text[9];
5237 emacs_help_text[10] = help_text[10];
5238 emacs_help_text[11] = help_text[11];
5239 emacs_help_text[12] = help_text[12];
5240 emacs_help_text[13] = help_text[13];
5241 emacs_help_text[14] = help_text[14];
5242 emacs_help_text[15] = help_text[15];
5243 emacs_help_text[16] = help_text[16];
5244 emacs_help_text[17] = help_text[17];
5245 emacs_help_text[18] = help_text[18];
5246 emacs_help_text[19] = help_text[19];
5247 emacs_help_text[20] = help_text[20];
5248 emacs_help_text[21] = help_text[21];
5249 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
5250 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
5251 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
5252 emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
5253 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5254 EMACS_string = catgetlocal( 159, "EMACS");
5255 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5256 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5257 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5258 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5259 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5260 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5261 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5262 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5263 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5264 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5265 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5266 more_above_str = catgetlocal( 181, "^^more^^");
5267 more_below_str = catgetlocal( 182, "VVmoreVV");
5268 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5269 chinese_cmd = catgetlocal( 184, "16BIT");
5270 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5273 commands[1] = WRITE;
5276 commands[4] = FILE_str;
5277 commands[5] = REDRAW;
5278 commands[6] = RESEQUENCE;
5279 commands[7] = AUTHOR;
5280 commands[8] = VERSION;
5282 commands[10] = NOCASE;
5283 commands[11] = EXPAND;
5284 commands[12] = NOEXPAND;
5285 commands[13] = Exit_string;
5286 commands[14] = QUIT_string;
5300 commands[28] = CHARACTER;
5301 commands[29] = chinese_cmd;
5302 commands[30] = nochinese_cmd;
5303 commands[31] = NULL;
5304 init_strings[0] = CASE;
5305 init_strings[1] = NOCASE;
5306 init_strings[2] = EXPAND;
5307 init_strings[3] = NOEXPAND;
5308 init_strings[4] = INFO;
5309 init_strings[5] = NOINFO;
5310 init_strings[6] = MARGINS;
5311 init_strings[7] = NOMARGINS;
5312 init_strings[8] = AUTOFORMAT;
5313 init_strings[9] = NOAUTOFORMAT;
5314 init_strings[10] = Echo;
5315 init_strings[11] = PRINTCOMMAND;
5316 init_strings[12] = RIGHTMARGIN;
5317 init_strings[13] = HIGHLIGHT;
5318 init_strings[14] = NOHIGHLIGHT;
5319 init_strings[15] = EIGHTBIT;
5320 init_strings[16] = NOEIGHTBIT;
5321 init_strings[17] = EMACS_string;
5322 init_strings[18] = NOEMACS_string;
5323 init_strings[19] = chinese_cmd;
5324 init_strings[20] = nochinese_cmd;
5325 init_strings[21] = NULL;
5328 | allocate space for strings here for settings menu
5331 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5333 modes_menu[counter].item_string = malloc(80);
5338 #endif /* NO_CATGETS */