4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
8 | THIS MATERIAL IS PROVIDED "AS IS". THERE ARE
9 | NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
10 | MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
11 | IMPLIED WARRANTIES OF MERCHANTABILITY AND
12 | FITNESS FOR A PARTICULAR PURPOSE. Neither
13 | Hewlett-Packard nor Hugh Mahon shall be liable
14 | for errors contained herein, nor for
15 | incidental or consequential damages in
16 | connection with the furnishing, performance or
17 | use of this material. Neither Hewlett-Packard
18 | nor Hugh Mahon assumes any responsibility for
19 | the use or reliability of this software or
20 | documentation. This software and
21 | documentation is totally UNSUPPORTED. There
22 | is no support contract available. Hewlett-
23 | Packard has done NO Quality Assurance on ANY
24 | of the program or documentation. You may find
25 | the quality of the materials inferior to
26 | supported materials.
28 | This software is not a product of Hewlett-Packard, Co., or any
29 | other company. No support is implied or offered with this software.
30 | You've got the source, and you're on your own.
32 | This software may be distributed under the terms of Larry Wall's
33 | Artistic license, a copy of which is included in this distribution.
35 | This notice must be included with this software and any derivatives.
37 | This editor was purposely developed to be simple, both in
38 | interface and implementation. This editor was developed to
39 | address a specific audience: the user who is new to computers
42 | ee is not aimed at technical users; for that reason more
43 | complex features were intentionally left out. In addition,
44 | ee is intended to be compiled by people with little computer
45 | experience, which means that it needs to be small, relatively
46 | simple in implementation, and portable.
48 | This software and documentation contains
49 | proprietary information which is protected by
50 | copyright. All rights are reserved.
52 * $FreeBSD: src/usr.bin/ee/ee.c,v 1.16.2.6 2002/05/11 16:33:06 mp Exp $
53 * $DragonFly: src/usr.bin/ee/ee.c,v 1.3 2003/10/04 20:36:43 hmp Exp $
56 char *ee_copyright_message =
57 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996 Hugh Mahon ";
59 char *ee_long_notice[] = {
60 "This software and documentation contains",
61 "proprietary information which is protected by",
62 "copyright. All rights are reserved."
65 char *version = "@(#) ee, version 1.4.1";
68 #include "new_curse.h"
84 #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 tmp_vert, tmp_horz;
152 int input_file; /* indicate to read input file */
153 int recv_file; /* indicate reading a file */
154 int edit; /* continue executing while true */
155 int gold; /* 'gold' function key pressed */
156 int fildes; /* file descriptor */
157 int case_sen; /* case sensitive search flag */
158 int last_line; /* last line for text display */
159 int last_col; /* last column for text display */
160 int horiz_offset = 0; /* offset from left edge of text */
161 int clear_com_win; /* flag to indicate com_win needs clearing */
162 int text_changes = FALSE; /* indicate changes have been made to text */
163 int get_fd; /* file descriptor for reading a file */
164 int info_window = TRUE; /* flag to indicate if help window visible */
165 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
166 int expand_tabs = TRUE; /* flag for expanding tabs */
167 int right_margin = 0; /* the right margin */
168 int observ_margins = TRUE; /* flag for whether margins are observed */
170 int temp_stdin; /* temporary storage for stdin */
171 int temp_stdout; /* temp storage for stdout descriptor */
172 int temp_stderr; /* temp storage for stderr descriptor */
173 int pipe_out[2]; /* pipe file desc for output */
174 int pipe_in[2]; /* pipe file descriptors for input */
175 int out_pipe; /* flag that info is piped out */
176 int in_pipe; /* flag that info is piped in */
177 int formatted = FALSE; /* flag indicating paragraph formatted */
178 int auto_format = FALSE; /* flag for auto_format mode */
179 int restricted = FALSE; /* flag to indicate restricted mode */
180 int nohighlight = FALSE; /* turns off highlighting */
181 int eightbit = TRUE; /* eight bit character flag */
182 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
183 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
184 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
185 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
186 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
187 /* by checking for high bit in a byte the */
188 /* code recognizes a two-byte character */
191 unsigned char *point; /* points to current position in line */
192 unsigned char *srch_str; /* pointer for search string */
193 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
194 unsigned char *srch_1; /* pointer to start of suspect string */
195 unsigned char *srch_2; /* pointer to next character of string */
196 unsigned char *srch_3;
197 unsigned char *in_file_name = NULL; /* name of input file */
198 char *tmp_file; /* temporary file name */
199 unsigned char *d_char; /* deleted character */
200 unsigned char *d_word; /* deleted word */
201 unsigned char *d_line; /* deleted line */
202 char in_string[513]; /* buffer for reading a file */
203 unsigned char *print_command = "lpr"; /* string to use for the print command */
204 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
205 const char count_text_default[] = "===============================================================================";
206 int count_text_len = sizeof(count_text_default); /* length of the line above */
207 char count_text[sizeof(count_text_default)]; /* buffer for current position display */
208 int in; /* input character */
210 FILE *temp_fp; /* temporary file pointer */
211 FILE *bit_bucket; /* file pointer to /dev/null */
214 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
215 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
216 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
225 #if defined(__STDC__) || defined(__cplusplus)
233 | The following structure allows menu items to be flexibly declared.
234 | The first item is the string describing the selection, the second
235 | is the address of the procedure to call when the item is selected,
236 | and the third is the argument for the procedure.
238 | For those systems with i18n, the string should be accompanied by a
239 | catalog number. The 'int *' should be replaced with 'void *' on
240 | systems with that type.
242 | The first menu item will be the title of the menu, with NULL
243 | parameters for the procedure and argument, followed by the menu items.
245 | If the procedure value is NULL, the menu item is displayed, but no
246 | procedure is called when the item is selected. The number of the
247 | item will be returned. If the third (argument) parameter is -1, no
248 | argument is given to the procedure when it is called.
251 struct menu_entries {
253 int (*procedure)P_((struct menu_entries *));
254 struct menu_entries *ptr_argument;
255 int (*iprocedure)P_((int));
256 void (*nprocedure)P_((void));
260 int main P_((int argc, char *argv[]));
261 unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
262 void insert P_((int character));
263 void delete P_((int disp));
264 void scanline P_((unsigned char *pos));
265 int tabshift P_((int temp_int));
266 int out_char P_((WINDOW *window, int character, int column));
267 int len_char P_((int character, int column));
268 void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
269 void insert_line P_((int disp));
270 struct text *txtalloc P_((void));
271 struct files *name_alloc P_((void));
272 unsigned char *next_word P_((unsigned char *string));
273 void prev_word P_((void));
274 void control P_((void));
275 void emacs_control P_((void));
276 void bottom P_((void));
278 void nextline P_((void));
279 void prevline P_((void));
280 void left P_((int disp));
281 void right P_((int disp));
282 void find_pos P_((void));
284 void down P_((void));
285 void function_key P_((void));
286 void print_buffer P_((void));
287 void command_prompt P_((void));
288 void command P_((char *cmd_str1));
289 int scan P_((char *line, int offset, int column));
290 char *get_string P_((char *prompt, int advance));
291 int compare P_((char *string1, char *string2, int sensitive));
292 void goto_line P_((char *cmd_str));
293 void midscreen P_((int line, unsigned char *pnt));
294 void get_options P_((int numargs, char *arguments[]));
295 void check_fp P_((void));
296 void get_file P_((char *file_name));
297 void get_line P_((int length, unsigned char *in_string, int *append));
298 void draw_screen P_((void));
299 void finish P_((void));
300 int quit P_((int noverify));
301 void edit_abort P_((int arg));
302 void delete_text P_((void));
303 int write_file P_((char *file_name));
304 int search P_((int display_message));
305 void search_prompt P_((void));
306 void del_char P_((void));
307 void undel_char P_((void));
308 void del_word P_((void));
309 void undel_word P_((void));
310 void del_line P_((void));
311 void undel_line P_((void));
312 void adv_word P_((void));
313 void move_rel P_((char *direction, int lines));
316 void adv_line P_((void));
317 void sh_command P_((char *string));
318 void set_up_term P_((void));
319 void resize_check P_((void));
320 int menu_op P_((struct menu_entries *));
321 void paint_menu P_((struct menu_entries menu_list[], int max_width, int max_height, int list_size, int top_offset, WINDOW *menu_win, int off_start, int vert_size));
322 void help P_((void));
323 void paint_info_win P_((void));
324 void no_info_window P_((void));
325 void create_info_window P_((void));
326 int file_op P_((int arg));
327 void shell_op P_((void));
328 void leave_op P_((void));
329 void redraw P_((void));
330 int Blank_Line P_((struct text *test_line));
331 void Format P_((void));
332 void ee_init P_((void));
333 void dump_ee_conf P_((void));
334 void echo_string P_((char *string));
335 void spell_op P_((void));
336 void ispell_op P_((void));
337 int first_word_len P_((struct text *test_line));
338 void Auto_Format P_((void));
339 void modes_op P_((void));
340 char *is_in_string P_((char *string, char *substring));
341 char *resolve_name P_((char *name));
342 int restrict_mode P_((void));
343 int unique_test P_((char *string, char *list[]));
344 void renumber_lines P_((struct text *firstline, int startnumber));
345 void strings_init P_((void));
349 | allocate space here for the strings that will be in the menu
352 struct menu_entries modes_menu[] = {
353 {"", NULL, NULL, NULL, NULL, 0}, /* title */
354 {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */
355 {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/
356 {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */
357 {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */
358 {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/
359 {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */
360 {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/
361 {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */
362 {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */
363 {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
364 {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */
367 char *mode_strings[11];
369 #define NUM_MODES_ITEMS 10
371 struct menu_entries config_dump_menu[] = {
372 {"", NULL, NULL, NULL, NULL, 0},
373 {"", NULL, NULL, NULL, NULL, -1},
374 {"", NULL, NULL, NULL, NULL, -1},
375 {NULL, NULL, NULL, NULL, NULL, -1}
378 struct menu_entries leave_menu[] = {
379 {"", NULL, NULL, NULL, NULL, -1},
380 {"", NULL, NULL, NULL, finish, -1},
381 {"", NULL, NULL, quit, NULL, TRUE},
382 {NULL, NULL, NULL, NULL, NULL, -1}
389 struct menu_entries file_menu[] = {
390 {"", NULL, NULL, NULL, NULL, -1},
391 {"", NULL, NULL, file_op, NULL, READ_FILE},
392 {"", NULL, NULL, file_op, NULL, WRITE_FILE},
393 {"", NULL, NULL, file_op, NULL, SAVE_FILE},
394 {"", NULL, NULL, NULL, print_buffer, -1},
395 {NULL, NULL, NULL, NULL, NULL, -1}
398 struct menu_entries search_menu[] = {
399 {"", NULL, NULL, NULL, NULL, 0},
400 {"", NULL, NULL, NULL, search_prompt, -1},
401 {"", NULL, NULL, search, NULL, TRUE},
402 {NULL, NULL, NULL, NULL, NULL, -1}
405 struct menu_entries spell_menu[] = {
406 {"", NULL, NULL, NULL, NULL, -1},
407 {"", NULL, NULL, NULL, spell_op, -1},
408 {"", NULL, NULL, NULL, ispell_op, -1},
409 {NULL, NULL, NULL, NULL, NULL, -1}
412 struct menu_entries misc_menu[] = {
413 {"", NULL, NULL, NULL, NULL, -1},
414 {"", NULL, NULL, NULL, Format, -1},
415 {"", NULL, NULL, NULL, shell_op, -1},
416 {"", menu_op, spell_menu, NULL, NULL, -1},
417 {NULL, NULL, NULL, NULL, NULL, -1}
420 struct menu_entries main_menu[] = {
421 {"", NULL, NULL, NULL, NULL, -1},
422 {"", NULL, NULL, NULL, leave_op, -1},
423 {"", NULL, NULL, NULL, help, -1},
424 {"", menu_op, file_menu, NULL, NULL, -1},
425 {"", NULL, NULL, NULL, redraw, -1},
426 {"", NULL, NULL, NULL, modes_op, -1},
427 {"", menu_op, search_menu, NULL, NULL, -1},
428 {"", menu_op, misc_menu, NULL, NULL, -1},
429 {NULL, NULL, NULL, NULL, NULL, -1}
433 char *control_keys[5];
435 char *emacs_help_text[22];
436 char *emacs_control_keys[5];
438 char *command_strings[5];
440 char *init_strings[22];
444 #define max_alpha_char 36
447 | Declarations for strings for localization
450 char *com_win_message; /* to be shown in com_win if no info window */
451 char *no_file_string;
452 char *ascii_code_str;
453 char *printer_msg_str;
455 char *file_write_prompt_str;
456 char *file_read_prompt_str;
459 char *non_unique_cmd_msg;
462 char *current_file_str;
468 char *file_is_dir_msg;
472 char *file_read_fin_msg;
473 char *reading_file_msg;
475 char *file_read_lines_msg;
476 char *save_file_name_prompt;
477 char *file_not_saved_msg;
478 char *changes_made_prompt;
480 char *file_exists_prompt;
481 char *create_file_fail_msg;
482 char *writing_file_msg;
483 char *file_written_msg;
485 char *str_not_found_msg;
486 char *search_prompt_str;
489 char *menu_cancel_msg;
490 char *menu_size_err_msg;
491 char *press_any_key_msg;
493 char *formatting_msg;
494 char *shell_echo_msg;
495 char *spell_in_prog_msg;
497 char *restricted_msg;
530 char *NOEMACS_string;
531 char *conf_dump_err_msg;
532 char *conf_dump_success_msg;
533 char *conf_not_saved_msg;
534 char *ree_no_file_msg;
536 char *menu_too_lrg_msg;
537 char *more_above_str, *more_below_str;
539 char *chinese_cmd, *nochinese_cmd;
543 extern char *malloc();
544 extern char *realloc();
545 extern char *getenv();
546 FILE *fopen(); /* declaration for open function */
547 #endif /* HAS_STDLIB */
548 #endif /* __STDC__ */
551 main(int argc, char **argv) /* beginning of main program */
555 for (counter = 1; counter < 24; counter++)
556 signal(counter, SIG_IGN);
558 signal(SIGCHLD, SIG_DFL);
559 signal(SIGSEGV, SIG_DFL);
560 signal(SIGINT, edit_abort);
561 signal(SIGHUP, edit_abort);
563 d_char = malloc(3); /* provide a buffer for multi-byte chars */
564 d_word = malloc(150);
565 *d_word = (char) NULL;
567 dlt_line = txtalloc();
568 dlt_line->line = d_line;
569 dlt_line->line_length = 0;
570 curr_line = first_line = txtalloc();
571 curr_line->line = point = malloc(10);
572 curr_line->line_length = 1;
573 curr_line->max_length = 10;
574 curr_line->prev_line = NULL;
575 curr_line->next_line = NULL;
576 curr_line->line_number = 1;
583 bit_bucket = fopen(_PATH_DEVNULL, "w");
585 gold = case_sen = FALSE;
590 get_options(argc, argv);
592 if (right_margin == 0)
593 right_margin = COLS - 1;
594 if (top_of_stack == NULL)
598 wmove(com_win, 0, 0);
600 wprintw(com_win, ree_no_file_msg);
604 wprintw(com_win, no_file_string);
610 clear_com_win = TRUE;
616 snprintf(count_text, count_text_len, "L: %d C: %d %s", \
617 curr_line->line_number, scr_horz + 1, count_text_default);
618 wmove(count_win, 0, 0);
620 wstandout(count_win);
621 wprintw(count_win, count_text);
622 wstandend(count_win);
623 wnoutrefresh(count_win);
626 wnoutrefresh(text_win);
628 in = wgetch(text_win);
636 clear_com_win = FALSE;
637 wmove(com_win, 0, 0);
641 wprintw(com_win, "%s", com_win_message);
648 else if ((in == '\10') || (in == 127))
650 in = 8; /* make sure key is set to backspace */
653 else if ((in > 31) || (in == 9))
655 else if ((in >= 0) && (in <= 31))
666 /* factor: resize factor */
667 /* rline: position in line */
669 resiz_line(int factor, struct text *rline, int rpos)
670 /* resize the line to length + factor*/
672 unsigned char *rpoint;
675 rline->max_length += factor;
676 rpoint = rline->line = realloc(rline->line, rline->max_length );
677 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
683 insert(int character) /* insert character into line */
687 unsigned char *temp; /* temporary pointer */
688 unsigned char *temp2; /* temporary pointer */
690 if ((character == '\011') && (expand_tabs))
692 counter = len_char('\011', scr_horz);
693 for (; counter > 0; counter--)
700 if ((curr_line->max_length - curr_line->line_length) < 5)
701 point = resiz_line(10, curr_line, position);
702 curr_line->line_length++;
705 while (counter < curr_line->line_length) /* find end of line */
710 temp++; /* increase length of line by one */
714 *temp= *temp2; /* shift characters over by one */
717 *point = character; /* insert new character */
719 if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/
721 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
727 waddch(text_win, character);
728 scr_pos = ++scr_horz;
733 if ((observ_margins) && (right_margin < scr_pos))
736 while (scr_pos > right_margin)
740 while (position < counter)
747 for (value = 0; value < counter; value++)
752 if ((scr_horz - horiz_offset) > last_col)
755 midscreen(scr_vert, point);
758 if ((auto_format) && (character == ' ') && (!formatted))
760 else if ((character != ' ') && (character != '\t'))
763 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
767 delete(int disp) /* delete character */
770 unsigned char *temp2;
771 struct text *temp_buff;
776 if (point != curr_line->line) /* if not at beginning of line */
780 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
786 position -= del_width;
788 curr_line->line_length -= del_width;
789 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
792 scr_horz -= del_width;
797 *d_char = *point; /* save deleted character */
801 d_char[1] = *(point + 1);
803 d_char[del_width] = (unsigned char) NULL;
805 while (temp_pos <= curr_line->line_length)
812 if (scr_horz < horiz_offset)
815 midscreen(scr_vert, point);
818 else if (curr_line->prev_line != NULL)
821 left(disp); /* go to previous line */
822 temp_buff = curr_line->next_line;
823 point = resiz_line(temp_buff->line_length, curr_line, position);
824 if (temp_buff->next_line != NULL)
825 temp_buff->next_line->prev_line = curr_line;
826 curr_line->next_line = temp_buff->next_line;
827 renumber_lines(curr_line->next_line, curr_line->line_number + 1);
828 temp2 = temp_buff->line;
832 d_char[1] = (unsigned char) NULL;
836 while (temp_pos < temp_buff->line_length)
838 curr_line->line_length++;
845 free(temp_buff->line);
847 temp_buff = curr_line;
848 temp_vert = scr_vert;
850 if (scr_vert < last_line)
852 wmove(text_win, scr_vert + 1, 0);
855 while ((temp_buff != NULL) && (temp_vert < last_line))
857 temp_buff = temp_buff->next_line;
860 if ((temp_vert == last_line) && (temp_buff != NULL))
862 tp = temp_buff->line;
863 wmove(text_win, last_line,0);
865 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
866 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
869 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
874 scanline(unsigned char *pos) /* find the proper horizontal position for the pointer */
879 ptr = curr_line->line;
886 temp += tabshift(temp);
887 else if ((*ptr >= 10) && (*ptr <= 31))
889 else if ((*ptr >= 32) && (*ptr < 127))
891 else if (*ptr == 127)
900 if ((scr_horz - horiz_offset) > last_col)
902 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
903 midscreen(scr_vert, point);
905 else if (scr_horz < horiz_offset)
907 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
908 midscreen(scr_vert, point);
913 tabshift(int temp_int) /* give the number of spaces to shift */
917 leftover = ((temp_int + 1) % 8);
921 return (9 - leftover);
925 out_char(WINDOW *window, int character, int column)
926 /* output non-printing character */
929 unsigned char *string;
932 if (character == TAB)
934 i1 = tabshift(column);
936 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
942 else if ((character >= '\0') && (character < ' '))
944 string = table[(int) character];
946 else if ((character < 0) || (character >= 127))
948 if (character == 127)
952 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
957 waddch(window, (unsigned char)character );
963 waddch(window, (unsigned char)character);
966 for (i2 = 0; (string[i2] != (char) NULL) && (((column+i2+1)-horiz_offset) < last_col); i2++)
967 waddch(window, string[i2]);
968 return(strlen(string));
971 /* column: the column must be known to provide spacing for tabs */
973 len_char(int character, int column) /* return the length of the character */
977 if (character == '\t')
978 length = tabshift(column);
979 else if ((character >= 0) && (character < 32))
981 else if ((character >= 32) && (character <= 126))
983 else if (character == 127)
985 else if (((character > 126) || (character < 0)) && (!eightbit))
994 vertical: current vertical position on screen
995 horiz: current horizontal position on screen
997 t_pos: current position (offset in bytes) from bol
998 length: length (in bytes) of line
1001 draw_line(int vertical, int horiz, unsigned char *ptr, int t_pos, int length)
1002 /* redraw line from current position */
1004 int d; /* partial length of special or tab char to display */
1005 unsigned char *temp; /* temporary pointer to position in line */
1006 int abs_column; /* offset in screen units from begin of line */
1007 int column; /* horizontal position on screen */
1008 int row; /* vertical position on screen */
1009 int posit; /* temporary position indicator within line */
1012 column = horiz - horiz_offset;
1019 wmove(text_win, row, 0);
1020 wclrtoeol(text_win);
1024 d = len_char(*temp, abs_column);
1030 wmove(text_win, row, column);
1031 wclrtoeol(text_win);
1032 while ((posit < length) && (column <= last_col))
1034 if ((*temp < 32) || (*temp >= 127))
1036 column += len_char(*temp, abs_column);
1037 abs_column += out_char(text_win, *temp, abs_column);
1043 waddch(text_win, *temp);
1048 if (column < last_col)
1049 wclrtoeol(text_win);
1050 wmove(text_win, vertical, (horiz - horiz_offset));
1054 insert_line(int disp) /* insert new line */
1058 unsigned char *temp;
1059 unsigned char *extra;
1060 struct text *temp_nod;
1062 text_changes = TRUE;
1063 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1064 wclrtoeol(text_win);
1065 temp_nod= txtalloc();
1066 temp_nod->line = extra= malloc(10);
1067 temp_nod->line_length = 1;
1068 temp_nod->max_length = 10;
1069 temp_nod->next_line = curr_line->next_line;
1070 renumber_lines(temp_nod, curr_line->line_number + 1);
1071 if (temp_nod->next_line != NULL)
1072 temp_nod->next_line->prev_line = temp_nod;
1073 temp_nod->prev_line = curr_line;
1074 curr_line->next_line = temp_nod;
1075 temp_pos2 = position;
1077 if (temp_pos2 < curr_line->line_length)
1080 while (temp_pos2 < curr_line->line_length)
1082 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1083 extra = resiz_line(10, temp_nod, temp_pos);
1084 temp_nod->line_length++;
1092 *temp = (char) NULL;
1093 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1094 curr_line->line_length = 1 + temp - curr_line->line;
1096 curr_line->line_length = position;
1097 curr_line = temp_nod;
1098 *extra = (char) NULL;
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 struct text *txtalloc(void) /* allocate space for line structure */
1130 return((struct text *) malloc(sizeof( struct text)));
1133 struct files *name_alloc(void) /* allocate space for file name list node */
1135 return((struct files *) malloc(sizeof( struct files)));
1138 unsigned char *next_word(unsigned char *string)
1139 /* move to next word in string */
1141 while ((*string != (char) NULL) && ((*string != 32) && (*string != 9)))
1143 while ((*string != (char) NULL) && ((*string == 32) || (*string == 9)))
1149 prev_word(void) /* move to start of previous word in text */
1153 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1154 { /* if at the start of a word */
1155 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1158 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1160 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1162 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1170 control(void) /* use control for commands */
1174 if (in == 1) /* control a */
1176 string = get_string(ascii_code_str, TRUE);
1177 if (*string != (char) NULL)
1180 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1185 else if (in == 2) /* control b */
1187 else if (in == 3) /* control c */
1191 else if (in == 4) /* control d */
1193 else if (in == 5) /* control e */
1195 else if (in == 6) /* control f */
1197 else if (in == 7) /* control g */
1199 else if (in == 8) /* control h */
1201 else if (in == 9) /* control i */
1203 else if (in == 10) /* control j */
1205 else if (in == 11) /* control k */
1207 else if (in == 12) /* control l */
1209 else if (in == 13) /* control m */
1211 else if (in == 14) /* control n */
1212 move_rel("d", max(5, (last_line - 5)));
1213 else if (in == 15) /* control o */
1215 else if (in == 16) /* control p */
1216 move_rel("u", max(5, (last_line - 5)));
1217 else if (in == 17) /* control q */
1219 else if (in == 18) /* control r */
1221 else if (in == 19) /* control s */
1223 else if (in == 20) /* control t */
1225 else if (in == 21) /* control u */
1227 else if (in == 22) /* control v */
1229 else if (in == 23) /* control w */
1231 else if (in == 24) /* control x */
1233 else if (in == 25) /* control y */
1235 else if (in == 26) /* control z */
1237 else if (in == 27) /* control [ (escape) */
1244 | Emacs control-key bindings
1252 if (in == 1) /* control a */
1254 else if (in == 2) /* control b */
1256 else if (in == 3) /* control c */
1260 else if (in == 4) /* control d */
1262 else if (in == 5) /* control e */
1264 else if (in == 6) /* control f */
1266 else if (in == 7) /* control g */
1267 move_rel("u", max(5, (last_line - 5)));
1268 else if (in == 8) /* control h */
1270 else if (in == 9) /* control i */
1272 else if (in == 10) /* control j */
1274 else if (in == 11) /* control k */
1276 else if (in == 12) /* control l */
1278 else if (in == 13) /* control m */
1280 else if (in == 14) /* control n */
1282 else if (in == 15) /* control o */
1284 string = get_string(ascii_code_str, TRUE);
1285 if (*string != (char) NULL)
1288 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1293 else if (in == 16) /* control p */
1295 else if (in == 17) /* control q */
1297 else if (in == 18) /* control r */
1299 else if (in == 19) /* control s */
1301 else if (in == 20) /* control t */
1303 else if (in == 21) /* control u */
1305 else if (in == 22) /* control v */
1306 move_rel("d", max(5, (last_line - 5)));
1307 else if (in == 23) /* control w */
1309 else if (in == 24) /* control x */
1311 else if (in == 25) /* control y */
1313 else if (in == 26) /* control z */
1315 else if (in == 27) /* control [ (escape) */
1322 bottom(void) /* go to bottom of file */
1324 while (curr_line->next_line != NULL)
1325 curr_line = curr_line->next_line;
1326 point = curr_line->line;
1330 midscreen(last_line, point);
1335 top(void) /* go to top of file */
1337 while (curr_line->prev_line != NULL)
1338 curr_line = curr_line->prev_line;
1339 point = curr_line->line;
1343 midscreen(0, point);
1348 nextline(void) /* move pointers to start of next line */
1350 curr_line = curr_line->next_line;
1351 point = curr_line->line;
1353 if (scr_vert == last_line)
1355 wmove(text_win, 0,0);
1356 wdeleteln(text_win);
1357 wmove(text_win, last_line,0);
1358 wclrtobot(text_win);
1359 draw_line(last_line,0,point,1,curr_line->line_length);
1366 prevline(void) /* move pointers to start of previous line*/
1368 curr_line = curr_line->prev_line;
1369 point = curr_line->line;
1373 winsertln(text_win);
1374 draw_line(0,0,point,1,curr_line->line_length);
1378 while (position < curr_line->line_length)
1386 left(int disp) /* move left one character */
1388 if (point != curr_line->line) /* if not at begin of line */
1390 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1398 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1401 else if (curr_line->prev_line != NULL)
1405 curr_line = curr_line->prev_line;
1406 point = curr_line->line + curr_line->line_length;
1407 position = curr_line->line_length;
1414 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1419 right(int disp) /* move right one character */
1421 if (position < curr_line->line_length)
1423 if ((ee_chinese) && (*point > 127) &&
1424 ((curr_line->line_length - position) >= 2))
1432 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1435 else if (curr_line->next_line != NULL)
1439 curr_line = curr_line->next_line;
1440 point = curr_line->line;
1445 scr_pos = scr_horz = 0;
1449 midscreen(scr_vert, point);
1451 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1457 find_pos(void) /* move to the same column as on other line */
1461 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1464 scr_horz += tabshift(scr_horz);
1465 else if (*point < ' ')
1467 else if ((ee_chinese) && (*point > 127) &&
1468 ((curr_line->line_length - position) >= 2))
1479 if ((scr_horz - horiz_offset) > last_col)
1481 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1482 midscreen(scr_vert, point);
1484 else if (scr_horz < horiz_offset)
1486 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1487 midscreen(scr_vert, point);
1489 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1493 up(void) /* move up one line */
1495 if (curr_line->prev_line != NULL)
1498 point = curr_line->line;
1504 down(void) /* move down one line */
1506 if (curr_line->next_line != NULL)
1514 function_key(void) /* process function key */
1518 else if (in == KEY_RIGHT)
1520 else if (in == KEY_HOME)
1522 else if (in == KEY_END)
1524 else if ( in == KEY_UP)
1526 else if (in == KEY_DOWN)
1528 else if (in == KEY_NPAGE)
1529 move_rel("d", max( 5, (last_line - 5)));
1530 else if (in == KEY_PPAGE)
1531 move_rel("u", max(5, (last_line - 5)));
1532 else if (in == KEY_DL)
1534 else if (in == KEY_DC)
1536 else if (in == KEY_BACKSPACE)
1538 else if (in == KEY_IL)
1539 { /* insert a line before current line */
1543 else if (in == KEY_F(1))
1545 else if (in == KEY_F(2))
1555 else if (in == KEY_F(3))
1565 else if (in == KEY_F(4))
1571 midscreen(scr_vert, point);
1576 else if (in == KEY_F(5))
1586 else if (in == KEY_F(6))
1596 else if (in == KEY_F(7))
1606 else if (in == KEY_F(8))
1623 sprintf(buffer, ">!%s", print_command);
1624 wmove(com_win, 0, 0);
1626 wprintw(com_win, printer_msg_str, print_command);
1632 command_prompt(void)
1637 info_type = COMMANDS;
1639 cmd_str = get_string(command_str, TRUE);
1640 if ((result = unique_test(cmd_str, commands)) != 1)
1643 wmove(com_win, 0, 0);
1645 wprintw(com_win, unkn_cmd_str, cmd_str);
1647 wprintw(com_win, non_unique_cmd_msg);
1651 info_type = CONTROL_KEYS;
1654 if (cmd_str != NULL)
1660 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1661 info_type = CONTROL_KEYS;
1663 if (cmd_str != NULL)
1668 command(char *cmd_str1) /* process commands from keyboard */
1670 char *cmd_str2 = NULL;
1671 char *cmd_str = cmd_str1;
1673 clear_com_win = TRUE;
1674 if (compare(cmd_str, HELP, FALSE))
1676 else if (compare(cmd_str, WRITE, FALSE))
1678 if (restrict_mode())
1682 cmd_str = next_word(cmd_str);
1683 if (*cmd_str == (char) NULL)
1685 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1687 tmp_file = resolve_name(cmd_str);
1688 write_file(tmp_file);
1689 if (tmp_file != cmd_str)
1692 else if (compare(cmd_str, READ, FALSE))
1694 if (restrict_mode())
1698 cmd_str = next_word(cmd_str);
1699 if (*cmd_str == (char) NULL)
1701 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1705 tmp_file = resolve_name(cmd_str);
1707 if (tmp_file != cmd_str)
1710 else if (compare(cmd_str, LINE, FALSE))
1712 wmove(com_win, 0, 0);
1714 wprintw(com_win, line_num_str, curr_line->line_number);
1715 wprintw(com_win, line_len_str, curr_line->line_length);
1717 else if (compare(cmd_str, FILE_str, FALSE))
1719 wmove(com_win, 0, 0);
1721 if (in_file_name == NULL)
1722 wprintw(com_win, no_file_string);
1724 wprintw(com_win, current_file_str, in_file_name);
1726 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1728 else if (compare(cmd_str, CHARACTER, FALSE))
1730 wmove(com_win, 0, 0);
1732 wprintw(com_win, char_str, *point);
1734 else if (compare(cmd_str, REDRAW, FALSE))
1736 else if (compare(cmd_str, RESEQUENCE, FALSE))
1738 tmp_line = first_line->next_line;
1739 while (tmp_line != NULL)
1741 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1742 tmp_line = tmp_line->next_line;
1745 else if (compare(cmd_str, AUTHOR, FALSE))
1747 wmove(com_win, 0, 0);
1749 wprintw(com_win, "written by Hugh Mahon");
1751 else if (compare(cmd_str, VERSION, FALSE))
1753 wmove(com_win, 0, 0);
1755 wprintw(com_win, "%s", version);
1757 else if (compare(cmd_str, CASE, FALSE))
1759 else if (compare(cmd_str, NOCASE, FALSE))
1761 else if (compare(cmd_str, EXPAND, FALSE))
1763 else if (compare(cmd_str, NOEXPAND, FALSE))
1764 expand_tabs = FALSE;
1765 else if (compare(cmd_str, Exit_string, FALSE))
1767 else if (compare(cmd_str, chinese_cmd, FALSE))
1771 nc_setattrib(A_NC_BIG5);
1774 else if (compare(cmd_str, nochinese_cmd, FALSE))
1778 nc_clearattrib(A_NC_BIG5);
1781 else if (compare(cmd_str, QUIT_string, FALSE))
1783 else if (*cmd_str == '!')
1786 if ((*cmd_str == ' ') || (*cmd_str == 9))
1787 cmd_str = next_word(cmd_str);
1788 sh_command(cmd_str);
1790 else if ((*cmd_str == '<') && (!in_pipe))
1795 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1796 cmd_str = next_word(cmd_str);
1801 else if ((*cmd_str == '>') && (!out_pipe))
1805 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1806 cmd_str = next_word(cmd_str);
1812 wmove(com_win, 0, 0);
1814 wprintw(com_win, unkn_cmd_str, cmd_str);
1816 if (cmd_str2 != NULL)
1821 scan(char *line, int offset, int column)
1822 /* determine horizontal position for get_string */
1834 j += len_char(*stemp, j);
1841 prompt: string containing user prompt message
1842 advance: if true, skip leading spaces and tabs
1845 get_string(char *prompt, int advance)
1846 /* read string from input on command line */
1853 int g_horz, g_position, g_pos;
1856 g_point = tmp_string = malloc(512);
1859 waddstr(com_win, prompt);
1861 nam_str = tmp_string;
1862 clear_com_win = TRUE;
1863 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1868 in = wgetch(com_win);
1871 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1875 g_horz = scan(g_point, g_pos, g_position);
1876 tmp_int = tmp_int - g_horz;
1877 for (; 0 < tmp_int; tmp_int--)
1879 if ((g_horz+tmp_int) < (last_col - 1))
1881 waddch(com_win, '\010');
1882 waddch(com_win, ' ');
1883 waddch(com_win, '\010');
1888 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1890 if (in == '\026') /* control-v, accept next character verbatim */
1891 { /* allows entry of ^m, ^j, and ^h */
1893 in = wgetch(com_win);
1899 if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1)))
1900 g_horz += out_char(com_win, in, g_horz);
1904 if (g_horz < (last_col - 1))
1905 waddch(com_win, in);
1912 } while ((in != '\n') && (in != '\r'));
1913 *nam_str = (char) NULL;
1914 nam_str = tmp_string;
1915 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1916 nam_str = next_word(nam_str);
1917 string = malloc(strlen(nam_str) + 1);
1918 strcpy(string, nam_str);
1925 compare(char *string1, char *string2, int sensitive) /* compare two strings */
1935 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == (char) NULL) || (*strng2 == (char) NULL))
1942 if (*strng1 != *strng2)
1947 if (toupper(*strng1) != toupper(*strng2))
1952 if ((*strng1 == (char) NULL) || (*strng2 == (char) NULL) || (*strng1 == ' ') || (*strng2 == ' '))
1960 goto_line(char *cmd_str)
1965 char *direction = NULL;
1966 struct text *t_line;
1970 while ((*ptr >='0') && (*ptr <= '9'))
1972 i= i * 10 + (*ptr - '0');
1978 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
1981 t_line = t_line->prev_line;
1984 while ((t_line->line_number < number) && (t_line->next_line != NULL))
1988 t_line = t_line->next_line;
1990 if ((i < 30) && (i > 0))
1992 move_rel(direction, i);
1997 point = curr_line->line;
1999 midscreen((last_line / 2), point);
2002 wmove(com_win, 0, 0);
2004 wprintw(com_win, line_num_str, curr_line->line_number);
2005 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2009 midscreen(int line, unsigned char *pnt)
2010 /* put current line in middle of screen */
2012 struct text *mid_line;
2015 line = min(line, last_line);
2016 mid_line = curr_line;
2017 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2018 curr_line = curr_line->prev_line;
2019 scr_vert = scr_horz = 0;
2020 wmove(text_win, 0, 0);
2023 curr_line = mid_line;
2025 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2029 get_options(int numargs, char **arguments)
2030 /* get arguments from command line */
2034 struct files *temp_names = NULL;
2039 | see if editor was invoked as 'ree' (restricted mode)
2042 if (!(name = strrchr(arguments[0], '/')))
2043 name = arguments[0];
2046 if (!strcmp(name, "ree"))
2049 top_of_stack = NULL;
2053 while (count < numargs)
2055 buff = arguments[count];
2056 if (!strcmp("-i", buff))
2058 info_window = FALSE;
2060 else if (!strcmp("-e", buff))
2062 expand_tabs = FALSE;
2064 else if (!strcmp("-h", buff))
2068 else if (!strcmp("-?", buff))
2070 fprintf(stderr, usage0, arguments[0]);
2071 fprintf(stderr, usage1);
2072 fprintf(stderr, usage2);
2073 fprintf(stderr, usage3);
2074 fprintf(stderr, usage4);
2077 else if (*buff == '+')
2080 start_at_line = buff;
2085 if (top_of_stack == NULL)
2087 temp_names = top_of_stack = name_alloc();
2091 temp_names->next_name = name_alloc();
2092 temp_names = temp_names->next_name;
2094 ptr = temp_names->name = malloc(strlen(buff) + 1);
2095 while (*buff != (char) NULL)
2102 temp_names->next_name = NULL;
2111 check_fp(void) /* open or close files according to flags */
2117 clear_com_win = TRUE;
2118 tmp_vert = scr_vert;
2119 tmp_horz = scr_horz;
2120 tmp_line = curr_line;
2123 in_file_name = tmp_file = top_of_stack->name;
2124 top_of_stack = top_of_stack->next_name;
2126 temp = stat(tmp_file, &buf);
2127 buf.st_mode &= ~07777;
2128 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2130 wprintw(com_win, file_is_dir_msg, tmp_file);
2140 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2142 wmove(com_win, 0, 0);
2145 wprintw(com_win, new_file_msg, tmp_file);
2147 wprintw(com_win, cant_open_msg, tmp_file);
2149 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2159 line_num = curr_line->line_number;
2160 scr_vert = tmp_vert;
2161 scr_horz = tmp_horz;
2163 curr_line= first_line;
2165 curr_line = tmp_line;
2166 point = curr_line->line;
2171 if (start_at_line != NULL)
2173 line_num = atoi(start_at_line) - 1;
2174 move_rel("d", line_num);
2176 start_at_line = NULL;
2181 wmove(com_win, 0, 0);
2183 text_changes = TRUE;
2184 if ((tmp_file != NULL) && (*tmp_file != (char) NULL))
2185 wprintw(com_win, file_read_fin_msg, tmp_file);
2188 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2193 get_file(char *file_name) /* read specified file into current buffer */
2195 int can_read; /* file has at least one character */
2196 int length; /* length of line read by read */
2197 int append; /* should text be appended to current line */
2198 struct text *temp_line;
2199 char ro_flag = FALSE;
2201 if (recv_file) /* if reading a file */
2203 wmove(com_win, 0, 0);
2205 wprintw(com_win, reading_file_msg, file_name);
2206 if (access(file_name, 2)) /* check permission to write */
2208 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2210 wprintw(com_win, read_only_msg);
2216 if (curr_line->line_length > 1) /* if current line is not blank */
2224 can_read = FALSE; /* test if file has any characters */
2225 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2227 can_read = TRUE; /* if set file has at least 1 character */
2228 get_line(length, in_string, &append);
2230 if ((can_read) && (curr_line->line_length == 1))
2232 temp_line = curr_line->prev_line;
2233 temp_line->next_line = curr_line->next_line;
2234 if (temp_line->next_line != NULL)
2235 temp_line->next_line->prev_line = temp_line;
2236 if (curr_line->line != NULL)
2237 free(curr_line->line);
2239 curr_line = temp_line;
2241 if (input_file) /* if this is the file to be edited display number of lines */
2243 wmove(com_win, 0, 0);
2245 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2247 wprintw(com_win, read_only_msg);
2250 else if (can_read) /* not input_file and file is non-zero size */
2251 text_changes = TRUE;
2253 if (recv_file) /* if reading a file */
2260 length: length of string read by read
2261 in_string: string read by read
2262 append: TRUE if must append more text to end of current line
2265 get_line(int length, unsigned char *in_string, int *append)
2266 /* read string and split into lines */
2268 unsigned char *str1;
2269 unsigned char *str2;
2270 int num; /* offset from start of string */
2271 int char_count; /* length of new line (or added portion */
2272 int temp_counter; /* temporary counter value */
2273 struct text *tline; /* temporary pointer to new line */
2274 int first_time; /* if TRUE, the first time through the loop */
2279 while (num < length)
2293 /* find end of line */
2294 while ((*str2 != '\n') && (num < length))
2300 if (!(*append)) /* if not append to current line, insert new one */
2302 tline = txtalloc(); /* allocate data structure for next line */
2303 tline->next_line = curr_line->next_line;
2304 renumber_lines(tline, curr_line->line_number + 1);
2305 tline->prev_line = curr_line;
2306 curr_line->next_line = tline;
2307 if (tline->next_line != NULL)
2308 tline->next_line->prev_line = tline;
2310 curr_line->line = point = (unsigned char *) malloc(char_count);
2311 curr_line->line_length = char_count;
2312 curr_line->max_length = char_count;
2316 point = resiz_line(char_count, curr_line, curr_line->line_length);
2317 curr_line->line_length += (char_count - 1);
2319 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2325 *point = (char) NULL;
2327 if ((num == length) && (*str2 != '\n'))
2333 draw_screen(void) /* redraw the screen from current postion */
2335 struct text *temp_line;
2336 unsigned char *line_out;
2339 temp_line = curr_line;
2340 temp_vert = scr_vert;
2341 wclrtobot(text_win);
2342 while ((temp_line != NULL) && (temp_vert <= last_line))
2344 line_out = temp_line->line;
2345 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2347 temp_line = temp_line->next_line;
2349 wmove(text_win, temp_vert, 0);
2350 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2354 finish(void) /* prepare to exit edit session */
2356 char *file_name = in_file_name;
2359 | changes made here should be reflected in the 'save'
2360 | portion of file_op()
2363 if ((file_name == NULL) || (*file_name == (char) NULL))
2364 file_name = get_string(save_file_name_prompt, TRUE);
2366 if ((file_name == NULL) || (*file_name == (char) NULL))
2368 wmove(com_win, 0, 0);
2369 wprintw(com_win, file_not_saved_msg);
2372 clear_com_win = TRUE;
2376 tmp_file = resolve_name(file_name);
2377 if (tmp_file != file_name)
2380 file_name = tmp_file;
2383 if (write_file(file_name))
2385 text_changes = FALSE;
2391 quit(int noverify) /* exit editor */
2397 if ((text_changes) && (!noverify))
2399 ans = get_string(changes_made_prompt, TRUE);
2400 if (toupper(*ans) == toupper(*yes_char))
2401 text_changes = FALSE;
2406 if (top_of_stack == NULL)
2422 text_changes = FALSE;
2440 while (curr_line->next_line != NULL)
2441 curr_line = curr_line->next_line;
2442 while (curr_line != first_line)
2444 free(curr_line->line);
2445 curr_line = curr_line->prev_line;
2446 free(curr_line->next_line);
2448 curr_line->next_line = NULL;
2449 *curr_line->line = (char) NULL;
2450 curr_line->line_length = 1;
2451 curr_line->line_number = 1;
2452 point = curr_line->line;
2453 scr_pos = scr_vert = scr_horz = 0;
2458 write_file(char *file_name)
2462 struct text *out_line;
2465 int write_flag = TRUE;
2468 if ((in_file_name == NULL) || strcmp(in_file_name, file_name))
2470 if ((temp_fp = fopen(file_name, "r")))
2472 tmp_point = get_string(file_exists_prompt, TRUE);
2473 if (toupper(*tmp_point) == toupper(*yes_char))
2482 clear_com_win = TRUE;
2486 if ((temp_fp = fopen(file_name, "w")) == NULL)
2488 clear_com_win = TRUE;
2491 wprintw(com_win, create_file_fail_msg, file_name);
2499 wprintw(com_win, writing_file_msg, file_name);
2502 out_line = first_line;
2503 while (out_line != NULL)
2506 tmp_point= out_line->line;
2507 while (temp_pos < out_line->line_length)
2509 putc(*tmp_point, temp_fp);
2513 charac += out_line->line_length;
2514 out_line = out_line->next_line;
2521 wprintw(com_win, file_written_msg, file_name, lines, charac);
2531 search(int display_message) /* search for string in srch_str */
2537 if ((srch_str == NULL) || (*srch_str == (char) NULL))
2539 if (display_message)
2541 wmove(com_win, 0, 0);
2543 wprintw(com_win, searching_msg);
2545 clear_com_win = TRUE;
2549 srch_line = curr_line;
2551 if (position < curr_line->line_length)
2553 iter = position + 1;
2554 while ((!found) && (srch_line != NULL))
2556 while ((iter < srch_line->line_length) && (!found))
2559 if (case_sen) /* if case sensitive */
2562 while ((*srch_2 == *srch_3) && (*srch_3 != (char) NULL))
2569 else /* if not case sensitive */
2571 srch_3 = u_srch_str;
2572 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != (char) NULL))
2579 if (!((*srch_3 == (char) NULL) && (found)))
2582 if (iter < srch_line->line_length)
2589 srch_line = srch_line->next_line;
2590 if (srch_line != NULL)
2591 srch_1 = srch_line->line;
2598 if (display_message)
2600 wmove(com_win, 0, 0);
2604 if (lines_moved == 0)
2606 while (position < iter)
2611 if (lines_moved < 30)
2613 move_rel("d", lines_moved);
2614 while (position < iter)
2619 curr_line = srch_line;
2624 midscreen((last_line / 2), point);
2630 if (display_message)
2632 wmove(com_win, 0, 0);
2634 wprintw(com_win, str_not_found_msg, srch_str);
2637 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2643 search_prompt(void) /* prompt and read search string (srch_str) */
2645 if (srch_str != NULL)
2647 if ((u_srch_str != NULL) && (*u_srch_str != (char) NULL))
2649 srch_str = get_string(search_prompt_str, FALSE);
2652 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2653 while (*srch_3 != (char) NULL)
2655 *srch_1 = toupper(*srch_3);
2659 *srch_1 = (char) NULL;
2664 del_char(void) /* delete current character */
2666 in = 8; /* backspace */
2667 if (position < curr_line->line_length) /* if not end of line */
2669 if ((ee_chinese) && (*point > 127) &&
2670 ((curr_line->line_length - position) >= 2))
2688 undel_char(void) /* undelete last deleted character */
2690 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2696 if (d_char[1] != (unsigned char) NULL)
2705 del_word(void) /* delete word in front of cursor */
2709 unsigned char *d_word2;
2710 unsigned char *d_word3;
2711 unsigned char tmp_char[3];
2715 d_word = malloc(curr_line->line_length);
2716 tmp_char[0] = d_char[0];
2717 tmp_char[1] = d_char[1];
2718 tmp_char[2] = d_char[2];
2722 while ((tposit < curr_line->line_length) &&
2723 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2726 *d_word2 = *d_word3;
2730 while ((tposit < curr_line->line_length) &&
2731 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2734 *d_word2 = *d_word3;
2738 *d_word2 = (char) NULL;
2739 d_wrd_len = difference = d_word2 - d_word;
2741 while (tposit < curr_line->line_length)
2744 *d_word2 = *d_word3;
2748 curr_line->line_length -= difference;
2749 *d_word2 = (char) NULL;
2750 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2751 d_char[0] = tmp_char[0];
2752 d_char[1] = tmp_char[1];
2753 d_char[2] = tmp_char[2];
2754 text_changes = TRUE;
2759 undel_word(void) /* undelete last deleted word */
2763 unsigned char *tmp_old_ptr;
2764 unsigned char *tmp_space;
2765 unsigned char *tmp_ptr;
2766 unsigned char *d_word_ptr;
2769 | resize line to handle undeleted word
2771 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2772 point = resiz_line(d_wrd_len, curr_line, position);
2773 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2774 d_word_ptr = d_word;
2777 | copy d_word contents into temp space
2779 while (temp <= d_wrd_len)
2782 *tmp_ptr = *d_word_ptr;
2786 tmp_old_ptr = point;
2789 | copy contents of line from curent position to eol into
2792 while (tposit < curr_line->line_length)
2796 *tmp_ptr = *tmp_old_ptr;
2800 curr_line->line_length += d_wrd_len;
2801 tmp_old_ptr = point;
2802 *tmp_ptr = (char) NULL;
2803 tmp_ptr = tmp_space;
2806 | now copy contents from temp space back to original line
2808 while (tposit < temp)
2811 *tmp_old_ptr = *tmp_ptr;
2815 *tmp_old_ptr = (char) NULL;
2817 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2821 del_line(void) /* delete from cursor to end of line */
2829 d_line = malloc(curr_line->line_length);
2833 while (tposit < curr_line->line_length)
2840 dlt_line->line_length = 1 + tposit - position;
2842 *point = (char) NULL;
2843 curr_line->line_length = position;
2844 wclrtoeol(text_win);
2845 if (curr_line->next_line != NULL)
2850 text_changes = TRUE;
2854 undel_line(void) /* undelete last deleted line */
2860 if (dlt_line->line_length == 0)
2865 point = resiz_line(dlt_line->line_length, curr_line, position);
2866 curr_line->line_length += dlt_line->line_length - 1;
2870 while (tposit < dlt_line->line_length)
2878 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2882 adv_word(void) /* advance to next word */
2884 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2886 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2891 move_rel(char *direction, int lines) /* move relative to current line */
2896 if (*direction == 'u')
2899 while (position > 1)
2901 for (i = 0; i < lines; i++)
2905 if ((last_line > 5) && ( scr_vert < 4))
2908 tmp_line = curr_line;
2909 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2913 scr_vert = scr_vert + i;
2914 curr_line = tmp_line;
2921 if ((position != 1) && (curr_line->next_line != NULL))
2924 scr_pos = scr_horz = 0;
2928 midscreen(scr_vert, point);
2933 for (i = 1; i < lines; i++)
2937 if ((last_line > 10) && (scr_vert > (last_line - 5)))
2940 tmp_line = curr_line;
2941 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
2945 scr_vert = scr_vert - i;
2946 curr_line = tmp_line;
2951 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2955 eol(void) /* go to end of line */
2957 if (position < curr_line->line_length)
2959 while (position < curr_line->line_length)
2962 else if (curr_line->next_line != NULL)
2965 while (position < curr_line->line_length)
2971 bol(void) /* move to beginning of line */
2973 if (point != curr_line->line)
2975 while (point != curr_line->line)
2978 else if (curr_line->prev_line != NULL)
2986 adv_line(void) /* advance to beginning of next line */
2988 if ((point != curr_line->line) || (scr_pos > 0))
2990 while (position < curr_line->line_length)
2994 else if (curr_line->next_line != NULL)
3001 /* string: string containing user command */
3003 sh_command(char *string) /* execute shell command */
3007 char *path; /* directory path to executable */
3008 int parent; /* zero if child, child's pid if parent */
3011 struct text *line_holder;
3013 if (restrict_mode())
3018 if (!(path = getenv("SHELL")))
3020 last_slash = temp_point = path;
3021 while (*temp_point != (char) NULL)
3023 if (*temp_point == '/')
3024 last_slash = ++temp_point;
3030 | if in_pipe is true, then output of the shell operation will be
3031 | read by the editor, and curses doesn't need to be turned off
3036 keypad(com_win, FALSE);
3037 keypad(text_win, FALSE);
3050 pipe(pipe_in); /* create a pipe */
3052 if (!parent) /* if the child */
3055 | child process which will fork and exec shell command (if shell output is
3056 | to be read by editor)
3060 | redirect stdout to pipe
3062 temp_stdout = dup(1);
3066 | redirect stderr to pipe
3068 temp_stderr = dup(2);
3073 | child will now continue down 'if (!in_pipe)'
3077 else /* if the parent */
3080 | prepare editor to read from the pipe
3082 signal(SIGCHLD, SIG_IGN);
3083 line_holder = curr_line;
3084 tmp_vert = scr_vert;
3086 get_fd = pipe_in[0];
3089 scr_vert = tmp_vert;
3090 scr_horz = scr_pos = 0;
3092 curr_line = line_holder;
3093 point = curr_line->line;
3095 signal(SIGCHLD, SIG_DFL);
3097 | since flag "in_pipe" is still TRUE, the path which waits for the child
3098 | process to die will be avoided.
3099 | (the pipe is closed, no more output can be expected)
3105 signal(SIGINT, SIG_IGN);
3111 | fork process which will exec command
3114 if (!parent) /* if the child */
3121 | prepare the child process (soon to exec a shell command) to read from the
3122 | pipe (which will be output from the editor's buffer)
3129 for (value = 1; value < 24; value++)
3130 signal(value, SIG_DFL);
3131 execl(path, last_slash, "-c", string, NULL);
3132 errx(1, exec_err_msg, path);
3134 else /* if the parent */
3139 | output the contents of the buffer to the pipe (to be read by the
3140 | process forked and exec'd above as stdin)
3143 line_holder = first_line;
3144 while (line_holder != NULL)
3146 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3147 write(pipe_out[1], "\n", 1);
3148 line_holder = line_holder->next_line;
3155 return_val = wait((int *) 0);
3157 while ((return_val != parent) && (return_val != -1));
3159 | if this process is actually the child of the editor, exit. Here's how it
3161 | The editor forks a process. If output must be sent to the command to be
3162 | exec'd another process is forked, and that process (the child's child)
3163 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3164 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3165 | If this is the editor process, shell_fork will be true, otherwise this is
3166 | the child of the edit process.
3171 signal(SIGINT, edit_abort);
3175 printf("%s", continue_msg);
3177 while ((in = getchar()) != '\n')
3187 keypad(text_win, TRUE);
3188 keypad(com_win, TRUE);
3190 clearok(info_win, TRUE);
3197 set_up_term(void) /* set up the terminal for operating with ae */
3199 if (!curses_initialized)
3206 curses_initialized = TRUE;
3209 if (((LINES > 15) && (COLS >= 80)) && info_window)
3210 last_line = LINES - 8;
3213 info_window = FALSE;
3214 last_line = LINES - 2;
3217 idlok(stdscr, TRUE);
3218 com_win = newwin(1, COLS, (LINES - 1), 0);
3219 keypad(com_win, TRUE);
3220 idlok(com_win, TRUE);
3223 text_win = newwin((LINES - 1), COLS, 0, 0);
3225 text_win = newwin((LINES - 7), COLS, 6, 0);
3226 keypad(text_win, TRUE);
3227 idlok(text_win, TRUE);
3229 help_win = newwin((LINES - 1), COLS, 0, 0);
3230 keypad(help_win, TRUE);
3231 idlok(help_win, TRUE);
3234 info_type = CONTROL_KEYS;
3235 info_win = newwin(5, COLS, 0, 0);
3238 count_win = newwin(1, COLS, 5, 0);
3239 leaveok(count_win, TRUE);
3240 wrefresh(count_win);
3243 last_col = COLS - 1;
3244 local_LINES = LINES;
3249 nc_setattrib(A_NC_BIG5);
3257 if ((LINES == local_LINES) && (COLS == local_COLS))
3271 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3274 menu_op(struct menu_entries *menu_list)
3277 int max_width, max_height;
3284 int top_offset; /* offset from top where menu items start */
3285 int vert_pos; /* vertical position */
3286 int vert_size; /* vertical size for menu list item display */
3287 int off_start = 1; /* offset from start of menu items to start display */
3291 | determine number and width of menu items
3295 while (menu_list[list_size + 1].item_string != NULL)
3298 for (counter = 0; counter <= list_size; counter++)
3300 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3304 max_width = max(max_width, strlen(menu_cancel_msg));
3305 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3309 | make sure that window is large enough to handle menu
3310 | if not, print error message and return to calling function
3313 if (max_width > COLS)
3315 wmove(com_win, 0, 0);
3317 wprintw(com_win, menu_too_lrg_msg);
3319 clear_com_win = TRUE;
3325 if (list_size > LINES)
3328 if (max_height > 11)
3329 vert_size = max_height - 8;
3331 vert_size = max_height;
3335 vert_size = list_size;
3336 max_height = list_size;
3339 if (LINES >= (vert_size + 8))
3341 if (menu_list[0].argument != MENU_WARN)
3342 max_height = vert_size + 8;
3344 max_height = vert_size + 7;
3347 x_off = (COLS - max_width) / 2;
3348 y_off = (LINES - max_height - 1) / 2;
3349 temp_win = newwin(max_height, max_width, y_off, x_off);
3350 keypad(temp_win, TRUE);
3352 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3359 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3361 wmove(temp_win, (counter + top_offset - off_start), 3);
3364 input = wgetch(temp_win);
3366 if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
3367 ((input >= '0') && (input <= '9')))
3369 if ((tolower(input) >= 'a') && (tolower(input) <= 'z'))
3371 temp = 1 + tolower(input) - 'a';
3373 else if ((input >= '0') && (input <= '9'))
3375 temp = (2 + 'z' - 'a') + (input - '0');
3378 if (temp <= list_size)
3388 case ' ': /* space */
3389 case '\004': /* ^d, down */
3393 if (counter > list_size)
3396 case '\010': /* ^h, backspace*/
3397 case '\025': /* ^u, up */
3398 case 127: /* ^?, delete */
3404 counter = list_size;
3406 case '\033': /* escape key */
3407 if (menu_list[0].argument != MENU_WARN)
3410 case '\014': /* ^l */
3411 case '\022': /* ^r, redraw */
3412 paint_menu(menu_list, max_width, max_height,
3413 list_size, top_offset, temp_win,
3414 off_start, vert_size);
3421 if (((list_size - off_start) >= (vert_size - 1)) &&
3422 (counter > (off_start + vert_size - 3)) &&
3425 if (counter == list_size)
3426 off_start = (list_size - vert_size) + 2;
3430 paint_menu(menu_list, max_width, max_height,
3431 list_size, top_offset, temp_win, off_start,
3434 else if ((list_size != vert_size) &&
3435 (counter > (off_start + vert_size - 2)))
3437 if (counter == list_size)
3438 off_start = 2 + (list_size - vert_size);
3439 else if (off_start == 1)
3444 paint_menu(menu_list, max_width, max_height,
3445 list_size, top_offset, temp_win, off_start,
3448 else if (counter < off_start)
3453 off_start = counter;
3455 paint_menu(menu_list, max_width, max_height,
3456 list_size, top_offset, temp_win, off_start,
3460 while ((input != '\r') && (input != '\n') && (counter != 0));
3466 if ((menu_list[counter].procedure != NULL) ||
3467 (menu_list[counter].iprocedure != NULL) ||
3468 (menu_list[counter].nprocedure != NULL))
3470 if (menu_list[counter].argument != -1)
3471 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3472 else if (menu_list[counter].ptr_argument != NULL)
3473 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3475 (*menu_list[counter].nprocedure)();
3486 paint_menu(struct menu_entries *menu_list, int max_width, int max_height,
3487 int list_size, int top_offset, WINDOW *menu_win, int off_start,
3490 int counter, temp_int;
3495 | output top and bottom portions of menu box only if window
3499 if (max_height > vert_size)
3501 wmove(menu_win, 1, 1);
3503 wstandout(menu_win);
3504 waddch(menu_win, '+');
3505 for (counter = 0; counter < (max_width - 4); counter++)
3506 waddch(menu_win, '-');
3507 waddch(menu_win, '+');
3509 wmove(menu_win, (max_height - 2), 1);
3510 waddch(menu_win, '+');
3511 for (counter = 0; counter < (max_width - 4); counter++)
3512 waddch(menu_win, '-');
3513 waddch(menu_win, '+');
3514 wstandend(menu_win);
3515 wmove(menu_win, 2, 3);
3516 waddstr(menu_win, menu_list[0].item_string);
3517 wmove(menu_win, (max_height - 3), 3);
3518 if (menu_list[0].argument != MENU_WARN)
3519 waddstr(menu_win, menu_cancel_msg);
3522 wstandout(menu_win);
3524 for (counter = 0; counter < (vert_size + top_offset); counter++)
3526 if (top_offset == 4)
3528 temp_int = counter + 2;
3533 wmove(menu_win, temp_int, 1);
3534 waddch(menu_win, '|');
3535 wmove(menu_win, temp_int, (max_width - 2));
3536 waddch(menu_win, '|');
3538 wstandend(menu_win);
3540 if (list_size > vert_size)
3545 wmove(menu_win, top_offset, 3);
3546 waddstr(menu_win, more_above_str);
3551 for (counter = off_start;
3552 ((temp_int + counter - off_start) < (vert_size - 1));
3555 wmove(menu_win, (top_offset + temp_int +
3556 (counter - off_start)), 3);
3558 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3559 waddstr(menu_win, menu_list[counter].item_string);
3562 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3564 if (counter == list_size)
3567 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3568 wprintw(menu_win, menu_list[counter].item_string);
3571 wprintw(menu_win, more_below_str);
3575 for (counter = 1; counter <= list_size; counter++)
3577 wmove(menu_win, (top_offset + counter - 1), 3);
3579 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3580 waddstr(menu_win, menu_list[counter].item_string);
3591 clearok(help_win, TRUE);
3592 for (counter = 0; counter < 22; counter++)
3594 wmove(help_win, counter, 0);
3595 waddstr(help_win, (emacs_keys_mode) ?
3596 emacs_help_text[counter] : help_text[counter]);
3600 wmove(com_win, 0, 0);
3601 wprintw(com_win, press_any_key_msg);
3603 counter = wgetch(com_win);
3605 wmove(com_win, 0, 0);
3613 paint_info_win(void)
3621 for (counter = 0; counter < 5; counter++)
3623 wmove(info_win, counter, 0);
3624 wclrtoeol(info_win);
3625 if (info_type == CONTROL_KEYS)
3626 waddstr(info_win, (emacs_keys_mode) ?
3627 emacs_control_keys[counter] : control_keys[counter]);
3628 else if (info_type == COMMANDS)
3629 waddstr(info_win, command_strings[counter]);
3635 no_info_window(void)
3641 info_window = FALSE;
3642 last_line = LINES - 2;
3643 text_win = newwin((LINES - 1), COLS, 0, 0);
3644 keypad(text_win, TRUE);
3645 idlok(text_win, TRUE);
3646 clearok(text_win, TRUE);
3647 midscreen(scr_vert, point);
3649 clear_com_win = TRUE;
3653 create_info_window(void)
3657 last_line = LINES - 8;
3659 text_win = newwin((LINES - 7), COLS, 6, 0);
3660 keypad(text_win, TRUE);
3661 idlok(text_win, TRUE);
3664 info_win = newwin(5, COLS, 0, 0);
3666 info_type = CONTROL_KEYS;
3667 midscreen(min(scr_vert, last_line), point);
3668 clearok(info_win, TRUE);
3670 count_win = newwin(1, COLS, 5, 0);
3671 leaveok(count_win, TRUE);
3672 wrefresh(count_win);
3674 clear_com_win = TRUE;
3683 if (restrict_mode())
3688 if (arg == READ_FILE)
3690 string = get_string(file_read_prompt_str, TRUE);
3692 tmp_file = resolve_name(string);
3694 if (tmp_file != string)
3698 else if (arg == WRITE_FILE)
3700 string = get_string(file_write_prompt_str, TRUE);
3701 tmp_file = resolve_name(string);
3702 write_file(tmp_file);
3703 if (tmp_file != string)
3707 else if (arg == SAVE_FILE)
3710 | changes made here should be reflected in finish()
3718 string = in_file_name;
3719 if ((string == NULL) || (*string == (char) NULL))
3720 string = get_string(save_file_name_prompt, TRUE);
3721 if ((string == NULL) || (*string == (char) NULL))
3723 wmove(com_win, 0, 0);
3724 wprintw(com_win, file_not_saved_msg);
3727 clear_com_win = TRUE;
3732 tmp_file = resolve_name(string);
3733 if (tmp_file != string)
3739 if (write_file(string))
3741 in_file_name = string;
3742 text_changes = FALSE;
3755 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3756 (*string != (char) NULL))
3768 menu_op(leave_menu);
3779 clearok(info_win, TRUE);
3783 clearok(text_win, TRUE);
3784 midscreen(scr_vert, point);
3788 | The following routines will "format" a paragraph (as defined by a
3789 | block of text with blank lines before and after the block).
3793 Blank_Line(struct text *test_line)
3794 /* test if line has any non-space characters */
3796 unsigned char *line;
3799 if (test_line == NULL)
3803 line = test_line->line;
3806 | To handle troff/nroff documents, consider a line with a
3807 | period ('.') in the first column to be blank. To handle mail
3808 | messages with included text, consider a line with a '>' blank.
3811 if ((*line == '.') || (*line == '>'))
3814 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3819 if (length != test_line->line_length)
3826 Format(void) /* format the paragraph according to set margins */
3834 unsigned char *line;
3835 unsigned char *tmp_srchstr;
3836 unsigned char *temp1, *temp2;
3837 unsigned char *temp_dword;
3838 unsigned char temp_d_char[3];
3840 temp_d_char[0] = d_char[0];
3841 temp_d_char[1] = d_char[1];
3842 temp_d_char[2] = d_char[2];
3845 | if observ_margins is not set, or the current line is blank,
3846 | do not format the current paragraph
3849 if ((!observ_margins) || (Blank_Line(curr_line)))
3853 | save the currently set flags, and clear them
3856 wmove(com_win, 0, 0);
3858 wprintw(com_win, formatting_msg);
3862 | get current position in paragraph, so after formatting, the cursor
3863 | will be in the same relative position
3866 tmp_af = auto_format;
3867 auto_format = FALSE;
3871 temp_dword = d_word;
3873 temp_case = case_sen;
3875 tmp_srchstr = srch_str;
3876 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3877 if ((*point == ' ') || (*point == '\t'))
3881 line = temp1 = point;
3882 while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3889 *temp2 = (char) NULL;
3892 while (!Blank_Line(curr_line->prev_line))
3896 while ((line != point) && (status))
3898 status = search(FALSE);
3902 wmove(com_win, 0, 0);
3904 wprintw(com_win, formatting_msg);
3908 | now get back to the start of the paragraph to start formatting
3913 while (!Blank_Line(curr_line->prev_line))
3916 observ_margins = FALSE;
3919 | Start going through lines, putting spaces at end of lines if they do
3920 | not already exist. Append lines together to get one long line, and
3921 | eliminate spacing at begin of lines.
3924 while (!Blank_Line(curr_line->next_line))
3936 if ((*point == ' ') || (*point == '\t'))
3941 | Now there is one long line. Eliminate extra spaces within the line
3942 | after the first word (so as not to blow away any indenting the user
3948 while (position < curr_line->line_length)
3950 if ((*point == ' ') && (*(point + 1) == ' '))
3957 | Now make sure there are two spaces after a '.'.
3961 while (position < curr_line->line_length)
3963 if ((*point == '.') && (*(point + 1) == ' '))
3968 while (*point == ' ')
3974 observ_margins = TRUE;
3977 wmove(com_win, 0, 0);
3979 wprintw(com_win, formatting_msg);
3983 | create lines between margins
3986 while (position < curr_line->line_length)
3988 while ((scr_pos < right_margin) && (position < curr_line->line_length))
3990 if (position < curr_line->line_length)
4000 | go back to begin of paragraph, put cursor back to original position
4004 while (!Blank_Line(curr_line->prev_line))
4008 | find word cursor was in
4011 while ((status) && (string_count > 0))
4018 | offset the cursor to where it was before from the start of the word
4028 | reset flags and strings to what they were before formatting
4033 d_word = temp_dword;
4034 case_sen = temp_case;
4036 srch_str = tmp_srchstr;
4037 d_char[0] = temp_d_char[0];
4038 d_char[1] = temp_d_char[1];
4039 d_char[2] = temp_d_char[2];
4040 auto_format = tmp_af;
4042 midscreen(scr_vert, point);
4047 unsigned char *init_name[3] = {
4048 "/usr/share/misc/init.ee",
4054 ee_init(void) /* check for init file and read it if it exists */
4057 unsigned char *string;
4058 unsigned char *str1;
4059 unsigned char *str2;
4064 string = getenv("HOME");
4066 string = "/root"; /* Set to reasonable default so we don't crash */
4067 str1 = home = malloc(strlen(string)+10);
4068 strcpy(home, string);
4069 strcat(home, "/.init.ee");
4070 init_name[1] = home;
4071 string = malloc(512);
4073 for (counter = 0; counter < 3; counter++)
4075 if (!(access(init_name[counter], 4)))
4077 init_file = fopen(init_name[counter], "r");
4078 while ((str2 = fgets(string, 512, init_file)) != NULL)
4080 str1 = str2 = string;
4081 while (*str2 != '\n')
4083 *str2 = (char) NULL;
4085 if (unique_test(string, init_strings) != 1)
4088 if (compare(str1, CASE, FALSE))
4090 else if (compare(str1, NOCASE, FALSE))
4092 else if (compare(str1, EXPAND, FALSE))
4094 else if (compare(str1, NOEXPAND, FALSE))
4095 expand_tabs = FALSE;
4096 else if (compare(str1, INFO, FALSE))
4098 else if (compare(str1, NOINFO, FALSE))
4099 info_window = FALSE;
4100 else if (compare(str1, MARGINS, FALSE))
4101 observ_margins = TRUE;
4102 else if (compare(str1, NOMARGINS, FALSE))
4103 observ_margins = FALSE;
4104 else if (compare(str1, AUTOFORMAT, FALSE))
4107 observ_margins = TRUE;
4109 else if (compare(str1, NOAUTOFORMAT, FALSE))
4110 auto_format = FALSE;
4111 else if (compare(str1, Echo, FALSE))
4113 str1 = next_word(str1);
4114 if (*str1 != (char) NULL)
4117 else if (compare(str1, PRINTCOMMAND, FALSE))
4119 str1 = next_word(str1);
4120 print_command = malloc(strlen(str1)+1);
4121 strcpy(print_command, str1);
4123 else if (compare(str1, RIGHTMARGIN, FALSE))
4125 str1 = next_word(str1);
4126 if ((*str1 >= '0') && (*str1 <= '9'))
4128 temp_int = atoi(str1);
4130 right_margin = temp_int;
4133 else if (compare(str1, HIGHLIGHT, FALSE))
4134 nohighlight = FALSE;
4135 else if (compare(str1, NOHIGHLIGHT, FALSE))
4137 else if (compare(str1, EIGHTBIT, FALSE))
4139 else if (compare(str1, NOEIGHTBIT, FALSE))
4144 else if (compare(str1, EMACS_string, FALSE))
4145 emacs_keys_mode = TRUE;
4146 else if (compare(str1, NOEMACS_string, FALSE))
4147 emacs_keys_mode = FALSE;
4148 else if (compare(str1, chinese_cmd, FALSE))
4153 else if (compare(str1, nochinese_cmd, FALSE))
4162 string = getenv("LANG");
4165 if (strcmp(string, "zh_TW.big5") == 0)
4174 | Save current configuration to .init.ee file in the current directory.
4181 FILE *old_init_file = NULL;
4182 char *file_name = ".init.ee";
4183 char *home_dir = "~/.init.ee";
4190 if (restrict_mode())
4195 option = menu_op(config_dump_menu);
4198 wmove(com_win, 0, 0);
4202 wprintw(com_win, conf_not_saved_msg);
4206 else if (option == 2)
4207 file_name = resolve_name(home_dir);
4210 | If a .init.ee file exists, move it to .init.ee.old.
4213 if (stat(file_name, &buf) != -1)
4215 sprintf(buffer, "%s.old", file_name);
4217 link(file_name, buffer);
4219 old_init_file = fopen(buffer, "r");
4222 init_file = fopen(file_name, "w");
4223 if (init_file == NULL)
4225 wprintw(com_win, conf_dump_err_msg);
4230 if (old_init_file != NULL)
4233 | Copy non-configuration info into new .init.ee file.
4235 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4237 length = strlen(string);
4238 string[length - 1] = (char) NULL;
4240 if (unique_test(string, init_strings) == 1)
4242 if (compare(string, Echo, FALSE))
4244 fprintf(init_file, "%s\n", string);
4248 fprintf(init_file, "%s\n", string);
4251 fclose(old_init_file);
4254 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4255 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4256 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4257 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4258 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4259 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4260 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4261 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4262 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4263 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4264 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4268 wprintw(com_win, conf_dump_success_msg, file_name);
4271 if ((option == 2) && (file_name != home_dir))
4278 echo_string(char *string) /* echo the given string */
4284 while (*temp != (char) NULL)
4291 else if (*temp == 't')
4293 else if (*temp == 'b')
4295 else if (*temp == 'r')
4297 else if (*temp == 'f')
4299 else if ((*temp == 'e') || (*temp == 'E'))
4300 putchar('\033'); /* escape */
4301 else if (*temp == '\\')
4303 else if (*temp == '\'')
4305 else if ((*temp >= '0') && (*temp <= '9'))
4308 while ((*temp >= '0') && (*temp <= '9'))
4310 Counter = (8 * Counter) + (*temp - '0');
4329 spell_op(void) /* check spelling of words in the editor */
4331 if (restrict_mode())
4335 top(); /* go to top of file */
4336 insert_line(FALSE); /* create two blank lines */
4339 command(shell_echo_msg);
4341 wmove(com_win, 0, 0);
4342 wprintw(com_win, spell_in_prog_msg);
4344 command("<>!spell"); /* send contents of buffer to command 'spell'
4345 and read the results back into the editor */
4355 if (restrict_mode())
4360 sprintf(name, "/tmp/ee.%d", pid);
4361 if (write_file(name))
4363 sprintf(string, "ispell %s", name);
4374 first_word_len(struct text *test_line)
4379 if (test_line == NULL)
4382 pnt = test_line->line;
4383 if ((pnt == NULL) || (*pnt == (char) NULL) ||
4384 (*pnt == '.') || (*pnt == '>'))
4387 if ((*pnt == ' ') || (*pnt == '\t'))
4389 pnt = next_word(pnt);
4392 if (*pnt == (char) NULL)
4396 while ((*pnt != (char) NULL) && ((*pnt != ' ') && (*pnt != '\t')))
4401 while ((*pnt != (char) NULL) && ((*pnt == ' ') || (*pnt == '\t')))
4410 Auto_Format(void) /* format the paragraph according to set margins */
4417 int tmp_d_line_length;
4418 int leave_loop = FALSE;
4422 unsigned char *line;
4423 unsigned char *tmp_srchstr;
4424 unsigned char *temp1, *temp2;
4425 unsigned char *temp_dword;
4426 unsigned char temp_d_char[3];
4427 unsigned char *tmp_d_line;
4430 temp_d_char[0] = d_char[0];
4431 temp_d_char[1] = d_char[1];
4432 temp_d_char[2] = d_char[2];
4435 | if observ_margins is not set, or the current line is blank,
4436 | do not format the current paragraph
4439 if ((!observ_margins) || (Blank_Line(curr_line)))
4443 | get current position in paragraph, so after formatting, the cursor
4444 | will be in the same relative position
4447 tmp_d_line = d_line;
4448 tmp_d_line_length = dlt_line->line_length;
4450 auto_format = FALSE;
4452 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == (char) NULL)))
4454 temp_dword = d_word;
4455 temp_dwl = d_wrd_len;
4458 temp_case = case_sen;
4460 tmp_srchstr = srch_str;
4461 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4462 if ((*point == ' ') || (*point == '\t'))
4466 line = temp1 = point;
4467 while ((*temp1 != (char) NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4474 *temp2 = (char) NULL;
4477 while (!Blank_Line(curr_line->prev_line))
4481 while ((line != point) && (status))
4483 status = search(FALSE);
4488 | now get back to the start of the paragraph to start checking
4493 while (!Blank_Line(curr_line->prev_line))
4497 | Start going through lines, putting spaces at end of lines if they do
4498 | not already exist. Check line length, and move words to the next line
4499 | if they cross the margin. Then get words from the next line if they
4500 | will fit in before the margin.
4507 if (position != curr_line->line_length)
4521 | fill line if first word on next line will fit
4522 | in the line without crossing the margin
4525 while ((curr_line->next_line != NULL) &&
4526 ((word_len = first_word_len(curr_line->next_line)) > 0)
4527 && ((scr_pos + word_len) < right_margin))
4530 if ((*point == ' ') || (*point == '\t'))
4537 | We know this line was not blank before, so
4538 | make sure that it doesn't have one of the
4539 | leading characters that indicate the line
4540 | should not be modified.
4542 | We also know that this character should not
4543 | be left as the first character of this line.
4546 if ((Blank_Line(curr_line)) &&
4547 (curr_line->line[0] != '.') &&
4548 (curr_line->line[0] != '>'))
4557 | go to end of previous line
4563 | make sure there's a space at the end of the line
4576 | make sure line does not cross right margin
4579 while (right_margin <= scr_pos)
4585 if (Blank_Line(curr_line->next_line))
4589 if ((*point == ' ') || (*point == '\t'))
4599 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4609 | go back to begin of paragraph, put cursor back to original position
4614 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4618 | find word cursor was in
4622 while ((status) && (string_count > 0))
4624 status = search(FALSE);
4629 | offset the cursor to where it was before from the start of the word
4638 if ((string_count > 0) && (offset < 0))
4648 | reset flags and strings to what they were before formatting
4653 d_word = temp_dword;
4654 d_wrd_len = temp_dwl;
4655 case_sen = temp_case;
4657 srch_str = tmp_srchstr;
4658 d_char[0] = temp_d_char[0];
4659 d_char[1] = temp_d_char[1];
4660 d_char[2] = temp_d_char[2];
4662 dlt_line->line_length = tmp_d_line_length;
4663 d_line = tmp_d_line;
4666 midscreen(scr_vert, point);
4678 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4679 (expand_tabs ? ON : OFF));
4680 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4681 (case_sen ? ON : OFF));
4682 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4683 (observ_margins ? ON : OFF));
4684 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4685 (auto_format ? ON : OFF));
4686 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4687 (eightbit ? ON : OFF));
4688 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4689 (info_window ? ON : OFF));
4690 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4691 (emacs_keys_mode ? ON : OFF));
4692 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4694 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4695 (ee_chinese ? ON : OFF));
4697 ret_value = menu_op(modes_menu);
4702 expand_tabs = !expand_tabs;
4705 case_sen = !case_sen;
4708 observ_margins = !observ_margins;
4711 auto_format = !auto_format;
4713 observ_margins = TRUE;
4716 eightbit = !eightbit;
4721 nc_setattrib(A_NC_BIG5);
4723 nc_clearattrib(A_NC_BIG5);
4727 wnoutrefresh(text_win);
4733 create_info_window();
4736 emacs_keys_mode = !emacs_keys_mode;
4741 string = get_string(margin_prompt, TRUE);
4744 counter = atoi(string);
4746 right_margin = counter;
4751 ee_chinese = !ee_chinese;
4752 if (ee_chinese != FALSE)
4756 nc_setattrib(A_NC_BIG5);
4758 nc_clearattrib(A_NC_BIG5);
4766 while (ret_value != 0);
4770 is_in_string(char *string, char *substring)
4771 /* a strchr() look-alike for systems without strchr() */
4775 for (sub = substring; (sub != NULL) && (*sub != (char)NULL); sub++)
4777 for (full = string; (full != NULL) && (*full != (char)NULL);
4788 | handle names of the form "~/file", "~user/file",
4789 | "$HOME/foo", "~/$FOO", etc.
4793 resolve_name(char *name)
4795 char long_buffer[1024];
4796 char short_buffer[128];
4804 struct passwd *user;
4811 user = (struct passwd *) getpwuid(index);
4816 slash = strchr(name, '/');
4819 *slash = (char) NULL;
4820 user = (struct passwd *) getpwnam((name + 1));
4827 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4828 strcpy(buffer, user->pw_dir);
4829 strcat(buffer, slash);
4834 if (is_in_string(buffer, "$"))
4839 while ((*tmp != (char) NULL) && (index < 1024))
4842 while ((*tmp != (char) NULL) && (*tmp != '$') &&
4845 long_buffer[index] = *tmp;
4850 if ((*tmp == '$') && (index < 1024))
4855 if (*tmp == '{') /* } */ /* bracketed variable name */
4858 while ((*tmp != (char) NULL) &&
4862 short_buffer[counter] = *tmp;
4871 while ((*tmp != (char) NULL) &&
4876 short_buffer[counter] = *tmp;
4881 short_buffer[counter] = (char) NULL;
4882 if ((slash = getenv(short_buffer)) != NULL)
4884 offset = strlen(slash);
4885 if ((offset + index) < 1024)
4886 strcpy(&long_buffer[index], slash);
4891 while ((start_of_var != tmp) && (index < 1024))
4893 long_buffer[index] = *start_of_var;
4904 long_buffer[index] = (char) NULL;
4908 buffer = malloc(index + 1);
4909 strcpy(buffer, long_buffer);
4921 wmove(com_win, 0, 0);
4922 wprintw(com_win, restricted_msg);
4925 clear_com_win = TRUE;
4930 | The following routine tests the input string against the list of
4931 | strings, to determine if the string is a unique match with one of the
4936 unique_test(char *string, char **list)
4944 while (list[counter] != NULL)
4946 result = compare(string, list[counter], FALSE);
4955 renumber_lines(struct text *firstline, int startnumber)
4957 struct text *lineptr;
4961 for (lineptr = firstline; lineptr != NULL; lineptr = lineptr->next_line)
4962 lineptr->line_number = i++;
4967 | Get the catalog entry, and if it got it from the catalog,
4968 | make a copy, since the buffer will be overwritten by the
4969 | next call to catgets().
4973 catgetlocal(int number, char *string)
4978 temp1 = catgets(catalog, 1, number, string);
4979 if (temp1 != string)
4981 temp2 = malloc(strlen(temp1) + 1);
4982 strcpy(temp2, temp1);
4987 #endif /* NO_CATGETS */
4990 | The following is to allow for using message catalogs which allow
4991 | the software to be 'localized', that is, to use different languages
4992 | all with the same binary. For more information, see your system
4993 | documentation, or the X/Open Internationalization Guide.
5002 setlocale(LC_ALL, "");
5003 catalog = catopen("ee", NL_CAT_LOCALE);
5004 #endif /* NO_CATGETS */
5006 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5007 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5008 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5009 mode_strings[3] = catgetlocal( 4, "margins observed ");
5010 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5011 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5012 mode_strings[6] = catgetlocal( 7, "info window ");
5013 mode_strings[8] = catgetlocal( 8, "right margin ");
5014 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5015 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5016 leave_menu[2].item_string = catgetlocal( 11, "no save");
5017 file_menu[0].item_string = catgetlocal( 12, "file menu");
5018 file_menu[1].item_string = catgetlocal( 13, "read a file");
5019 file_menu[2].item_string = catgetlocal( 14, "write a file");
5020 file_menu[3].item_string = catgetlocal( 15, "save file");
5021 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5022 search_menu[0].item_string = catgetlocal( 17, "search menu");
5023 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5024 search_menu[2].item_string = catgetlocal( 19, "search");
5025 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5026 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5027 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5028 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5029 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5030 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5031 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5032 main_menu[0].item_string = catgetlocal( 27, "main menu");
5033 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5034 main_menu[2].item_string = catgetlocal( 29, "help");
5035 main_menu[3].item_string = catgetlocal( 30, "file operations");
5036 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5037 main_menu[5].item_string = catgetlocal( 32, "settings");
5038 main_menu[6].item_string = catgetlocal( 33, "search");
5039 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5040 help_text[0] = catgetlocal( 35, "Control keys: ");
5041 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5042 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5043 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5044 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5045 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5046 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5047 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5048 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5049 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5050 help_text[10] = catgetlocal( 45, " ");
5051 help_text[11] = catgetlocal( 46, "Commands: ");
5052 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5053 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5054 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5055 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5056 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5057 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5058 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5059 help_text[19] = catgetlocal( 54, " ");
5060 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5061 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5062 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5063 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5064 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5065 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5066 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5067 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5068 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5069 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5070 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5071 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5072 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5073 no_file_string = catgetlocal( 68, "no file");
5074 ascii_code_str = catgetlocal( 69, "ascii code: ");
5075 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5076 command_str = catgetlocal( 71, "command: ");
5077 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5078 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5079 char_str = catgetlocal( 74, "character = %d");
5080 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5081 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5082 line_num_str = catgetlocal( 77, "line %d ");
5083 line_len_str = catgetlocal( 78, "length = %d");
5084 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5085 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5086 usage1 = catgetlocal( 81, " -i turn off info window\n");
5087 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5088 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5089 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5090 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5091 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5092 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5093 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5094 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5095 read_only_msg = catgetlocal( 90, ", read only");
5096 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5097 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5098 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5099 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5100 yes_char = catgetlocal( 95, "y");
5101 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5102 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5103 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5104 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5105 searching_msg = catgetlocal( 100, " ...searching");
5106 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5107 search_prompt_str = catgetlocal( 102, "search for: ");
5108 exec_err_msg = catgetlocal( 103, "could not exec %s");
5109 continue_msg = catgetlocal( 104, "press return to continue ");
5110 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5111 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5112 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5113 shell_prompt = catgetlocal( 108, "shell command: ");
5114 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5115 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5116 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5117 margin_prompt = catgetlocal( 112, "right margin is: ");
5118 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5119 ON = catgetlocal( 114, "ON");
5120 OFF = catgetlocal( 115, "OFF");
5121 HELP = catgetlocal( 116, "HELP");
5122 WRITE = catgetlocal( 117, "WRITE");
5123 READ = catgetlocal( 118, "READ");
5124 LINE = catgetlocal( 119, "LINE");
5125 FILE_str = catgetlocal( 120, "FILE");
5126 CHARACTER = catgetlocal( 121, "CHARACTER");
5127 REDRAW = catgetlocal( 122, "REDRAW");
5128 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5129 AUTHOR = catgetlocal( 124, "AUTHOR");
5130 VERSION = catgetlocal( 125, "VERSION");
5131 CASE = catgetlocal( 126, "CASE");
5132 NOCASE = catgetlocal( 127, "NOCASE");
5133 EXPAND = catgetlocal( 128, "EXPAND");
5134 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5135 Exit_string = catgetlocal( 130, "EXIT");
5136 QUIT_string = catgetlocal( 131, "QUIT");
5137 INFO = catgetlocal( 132, "INFO");
5138 NOINFO = catgetlocal( 133, "NOINFO");
5139 MARGINS = catgetlocal( 134, "MARGINS");
5140 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5141 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5142 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5143 Echo = catgetlocal( 138, "ECHO");
5144 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5145 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5146 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5147 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5148 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5149 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5153 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5154 emacs_help_text[0] = help_text[0];
5155 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5156 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t begin of file ");
5157 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u end of file ");
5158 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5159 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5160 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5161 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5162 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5163 emacs_help_text[9] = help_text[9];
5164 emacs_help_text[10] = help_text[10];
5165 emacs_help_text[11] = help_text[11];
5166 emacs_help_text[12] = help_text[12];
5167 emacs_help_text[13] = help_text[13];
5168 emacs_help_text[14] = help_text[14];
5169 emacs_help_text[15] = help_text[15];
5170 emacs_help_text[16] = help_text[16];
5171 emacs_help_text[17] = help_text[17];
5172 emacs_help_text[18] = help_text[18];
5173 emacs_help_text[19] = help_text[19];
5174 emacs_help_text[20] = help_text[20];
5175 emacs_help_text[21] = help_text[21];
5176 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev line ^g prev page");
5177 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next line ^v next page");
5178 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back char ^z next word");
5179 emacs_control_keys[3] = catgetlocal( 157, "^t begin of file ^e end of line ^r restore word ^f forward char ");
5180 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5181 EMACS_string = catgetlocal( 159, "EMACS");
5182 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5183 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5184 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5185 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5186 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5187 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5188 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5189 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5190 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5191 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5192 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5193 more_above_str = catgetlocal( 181, "^^more^^");
5194 more_below_str = catgetlocal( 182, "VVmoreVV");
5195 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5196 chinese_cmd = catgetlocal( 184, "16BIT");
5197 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5200 commands[1] = WRITE;
5203 commands[4] = FILE_str;
5204 commands[5] = REDRAW;
5205 commands[6] = RESEQUENCE;
5206 commands[7] = AUTHOR;
5207 commands[8] = VERSION;
5209 commands[10] = NOCASE;
5210 commands[11] = EXPAND;
5211 commands[12] = NOEXPAND;
5212 commands[13] = Exit_string;
5213 commands[14] = QUIT_string;
5227 commands[28] = CHARACTER;
5228 commands[29] = chinese_cmd;
5229 commands[30] = nochinese_cmd;
5230 commands[31] = NULL;
5231 init_strings[0] = CASE;
5232 init_strings[1] = NOCASE;
5233 init_strings[2] = EXPAND;
5234 init_strings[3] = NOEXPAND;
5235 init_strings[4] = INFO;
5236 init_strings[5] = NOINFO;
5237 init_strings[6] = MARGINS;
5238 init_strings[7] = NOMARGINS;
5239 init_strings[8] = AUTOFORMAT;
5240 init_strings[9] = NOAUTOFORMAT;
5241 init_strings[10] = Echo;
5242 init_strings[11] = PRINTCOMMAND;
5243 init_strings[12] = RIGHTMARGIN;
5244 init_strings[13] = HIGHLIGHT;
5245 init_strings[14] = NOHIGHLIGHT;
5246 init_strings[15] = EIGHTBIT;
5247 init_strings[16] = NOEIGHTBIT;
5248 init_strings[17] = EMACS_string;
5249 init_strings[18] = NOEMACS_string;
5250 init_strings[19] = chinese_cmd;
5251 init_strings[20] = nochinese_cmd;
5252 init_strings[21] = NULL;
5255 | allocate space for strings here for settings menu
5258 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5260 modes_menu[counter].item_string = malloc(80);
5265 #endif /* NO_CATGETS */