4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
9 | Copyright (c) 2009, Hugh Mahon
10 | All rights reserved.
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions
16 | * Redistributions of source code must retain the above copyright
17 | notice, this list of conditions and the following disclaimer.
18 | * Redistributions in binary form must reproduce the above
19 | copyright notice, this list of conditions and the following
20 | disclaimer in the documentation and/or other materials provided
21 | with the distribution.
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | POSSIBILITY OF SUCH DAMAGE.
36 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
38 | This editor was purposely developed to be simple, both in
39 | interface and implementation. This editor was developed to
40 | address a specific audience: the user who is new to computers
43 | ee is not aimed at technical users; for that reason more
44 | complex features were intentionally left out. In addition,
45 | ee is intended to be compiled by people with little computer
46 | experience, which means that it needs to be small, relatively
47 | simple in implementation, and portable.
49 | This software and documentation contains
50 | proprietary information which is protected by
51 | copyright. All rights are reserved.
53 | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.102 2009/02/17 03:22:50 hugh Exp hugh $
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
60 char *ee_copyright_message =
61 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
63 #include "ee_version.h"
65 char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.102 $";
68 #include "new_curse.h"
81 #include <sys/types.h>
106 #include <nl_types.h>
110 #define catgetlocal(a, b) (b)
111 #endif /* NO_CATGETS */
114 #define SIGCHLD SIGCLD
118 #define max(a, b) (a > b ? a : b)
119 #define min(a, b) (a < b ? a : b)
122 | defines for type of data to show in info window
125 #define CONTROL_KEYS 1
129 unsigned char *line; /* line of characters */
130 int line_number; /* line number */
131 int line_length; /* actual number of characters in the line */
132 int max_length; /* maximum number of characters the line handles */
133 struct text *next_line; /* next line of text */
134 struct text *prev_line; /* previous line of text */
137 struct text *first_line; /* first line of current buffer */
138 struct text *dlt_line; /* structure for info on deleted line */
139 struct text *curr_line; /* current line cursor is on */
140 struct text *tmp_line; /* temporary line pointer */
141 struct text *srch_line; /* temporary pointer for search routine */
143 struct files { /* structure to store names of files to be edited*/
144 unsigned char *name; /* name of file */
145 struct files *next_name;
148 struct files *top_of_stack = NULL;
150 int d_wrd_len; /* length of deleted word */
151 int position; /* offset in bytes from begin of line */
152 int scr_pos; /* horizontal position */
153 int scr_vert; /* vertical position on screen */
154 int scr_horz; /* horizontal position on screen */
155 int absolute_lin; /* number of lines from top */
156 int tmp_vert, tmp_horz;
157 int input_file; /* indicate to read input file */
158 int recv_file; /* indicate reading a file */
159 int edit; /* continue executing while true */
160 int gold; /* 'gold' function key pressed */
161 int fildes; /* file descriptor */
162 int case_sen; /* case sensitive search flag */
163 int last_line; /* last line for text display */
164 int last_col; /* last column for text display */
165 int horiz_offset = 0; /* offset from left edge of text */
166 int clear_com_win; /* flag to indicate com_win needs clearing */
167 int text_changes = FALSE; /* indicate changes have been made to text */
168 int get_fd; /* file descriptor for reading a file */
169 int info_window = TRUE; /* flag to indicate if help window visible */
170 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
171 int expand_tabs = TRUE; /* flag for expanding tabs */
172 int right_margin = 0; /* the right margin */
173 int observ_margins = TRUE; /* flag for whether margins are observed */
175 int temp_stdin; /* temporary storage for stdin */
176 int temp_stdout; /* temp storage for stdout descriptor */
177 int temp_stderr; /* temp storage for stderr descriptor */
178 int pipe_out[2]; /* pipe file desc for output */
179 int pipe_in[2]; /* pipe file descriptors for input */
180 int out_pipe; /* flag that info is piped out */
181 int in_pipe; /* flag that info is piped in */
182 int formatted = FALSE; /* flag indicating paragraph formatted */
183 int auto_format = FALSE; /* flag for auto_format mode */
184 int restricted = FALSE; /* flag to indicate restricted mode */
185 int nohighlight = FALSE; /* turns off highlighting */
186 int eightbit = TRUE; /* eight bit character flag */
187 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
188 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
189 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
190 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
191 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
192 /* by checking for high bit in a byte the */
193 /* code recognizes a two-byte character */
196 unsigned char *point; /* points to current position in line */
197 unsigned char *srch_str; /* pointer for search string */
198 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
199 unsigned char *srch_1; /* pointer to start of suspect string */
200 unsigned char *srch_2; /* pointer to next character of string */
201 unsigned char *srch_3;
202 unsigned char *in_file_name = NULL; /* name of input file */
203 char *tmp_file; /* temporary file name */
204 unsigned char *d_char; /* deleted character */
205 unsigned char *d_word; /* deleted word */
206 unsigned char *d_line; /* deleted line */
207 char in_string[513]; /* buffer for reading a file */
208 unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
209 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
210 int in; /* input character */
212 FILE *temp_fp; /* temporary file pointer */
213 FILE *bit_bucket; /* file pointer to /dev/null */
216 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
217 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
218 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
226 #if defined(__STDC__) || defined(__cplusplus)
234 | The following structure allows menu items to be flexibly declared.
235 | The first item is the string describing the selection, the second
236 | is the address of the procedure to call when the item is selected,
237 | and the third is the argument for the procedure.
239 | For those systems with i18n, the string should be accompanied by a
240 | catalog number. The 'int *' should be replaced with 'void *' on
241 | systems with that type.
243 | The first menu item will be the title of the menu, with NULL
244 | parameters for the procedure and argument, followed by the menu items.
246 | If the procedure value is NULL, the menu item is displayed, but no
247 | procedure is called when the item is selected. The number of the
248 | item will be returned. If the third (argument) parameter is -1, no
249 | argument is given to the procedure when it is called.
252 struct menu_entries {
254 int (*procedure)P_((struct menu_entries *));
255 struct menu_entries *ptr_argument;
256 int (*iprocedure)P_((int));
257 void (*nprocedure)P_((void));
261 int main P_((int argc, char *argv[]));
262 unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
263 void insert P_((int character));
264 void delete P_((int disp));
265 void scanline P_((unsigned char *pos));
266 int tabshift P_((int temp_int));
267 int out_char P_((WINDOW *window, int character, int column));
268 int len_char P_((int character, int column));
269 void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
270 void insert_line P_((int disp));
271 struct text *txtalloc P_((void));
272 struct files *name_alloc P_((void));
273 unsigned char *next_word P_((unsigned char *string));
274 void prev_word P_((void));
275 void control P_((void));
276 void emacs_control P_((void));
277 void bottom P_((void));
279 void nextline P_((void));
280 void prevline P_((void));
281 void left P_((int disp));
282 void right P_((int disp));
283 void find_pos P_((void));
285 void down P_((void));
286 void function_key P_((void));
287 void print_buffer P_((void));
288 void command_prompt P_((void));
289 void command P_((char *cmd_str1));
290 int scan P_((char *line, int offset, int column));
291 char *get_string P_((char *prompt, int advance));
292 int compare P_((char *string1, char *string2, int sensitive));
293 void goto_line P_((char *cmd_str));
294 void midscreen P_((int line, unsigned char *pnt));
295 void get_options P_((int numargs, char *arguments[]));
296 void check_fp P_((void));
297 void get_file P_((char *file_name));
298 void get_line P_((int length, unsigned char *in_string, int *append));
299 void draw_screen P_((void));
300 void finish P_((void));
301 int quit P_((int noverify));
302 void edit_abort P_((int arg));
303 void delete_text P_((void));
304 int write_file P_((char *file_name, int warn_if_exists));
305 int search P_((int display_message));
306 void search_prompt P_((void));
307 void del_char P_((void));
308 void undel_char P_((void));
309 void del_word P_((void));
310 void undel_word P_((void));
311 void del_line P_((void));
312 void undel_line P_((void));
313 void adv_word P_((void));
314 void move_rel P_((char *direction, int lines));
317 void adv_line P_((void));
318 void sh_command P_((char *string));
319 void set_up_term P_((void));
320 void resize_check P_((void));
321 int menu_op P_((struct menu_entries *));
322 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));
323 void help P_((void));
324 void paint_info_win P_((void));
325 void no_info_window P_((void));
326 void create_info_window P_((void));
327 int file_op P_((int arg));
328 void shell_op P_((void));
329 void leave_op P_((void));
330 void redraw P_((void));
331 int Blank_Line P_((struct text *test_line));
332 void Format P_((void));
333 void ee_init P_((void));
334 void dump_ee_conf P_((void));
335 void echo_string P_((char *string));
336 void spell_op P_((void));
337 void ispell_op P_((void));
338 int first_word_len P_((struct text *test_line));
339 void Auto_Format P_((void));
340 void modes_op P_((void));
341 char *is_in_string P_((char *string, char *substring));
342 char *resolve_name P_((char *name));
343 int restrict_mode P_((void));
344 int unique_test P_((char *string, char *list[]));
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;
538 char *separator = "===============================================================================";
540 char *chinese_cmd, *nochinese_cmd;
544 extern char *malloc();
545 extern char *realloc();
546 extern char *getenv();
547 FILE *fopen(); /* declaration for open function */
548 #endif /* HAS_STDLIB */
549 #endif /* __STDC__ */
552 main(argc, argv) /* beginning of main program */
558 for (counter = 1; counter < 24; counter++)
559 signal(counter, SIG_IGN);
561 signal(SIGCHLD, SIG_DFL);
562 signal(SIGSEGV, SIG_DFL);
563 signal(SIGINT, edit_abort);
564 d_char = malloc(3); /* provide a buffer for multi-byte chars */
565 d_word = malloc(150);
568 dlt_line = txtalloc();
569 dlt_line->line = d_line;
570 dlt_line->line_length = 0;
571 curr_line = first_line = txtalloc();
572 curr_line->line = point = malloc(10);
573 curr_line->line_length = 1;
574 curr_line->max_length = 10;
575 curr_line->prev_line = NULL;
576 curr_line->next_line = NULL;
577 curr_line->line_number = 1;
585 bit_bucket = fopen("/dev/null", "w");
587 gold = case_sen = FALSE;
592 get_options(argc, argv);
594 if (right_margin == 0)
595 right_margin = COLS - 1;
596 if (top_of_stack == NULL)
600 wmove(com_win, 0, 0);
602 wprintw(com_win, ree_no_file_msg);
606 wprintw(com_win, no_file_string);
612 clear_com_win = TRUE;
619 | display line and column information
625 wmove(info_win, 5, 0);
626 wprintw(info_win, separator);
627 wmove(info_win, 5, 5);
628 wprintw(info_win, "line %d col %d lines from top %d ",
629 curr_line->line_number, scr_horz, absolute_lin);
635 in = wgetch(text_win);
637 exit(0); /* without this exit ee will go into an
638 infinite loop if the network
645 clear_com_win = FALSE;
646 wmove(com_win, 0, 0);
650 wprintw(com_win, "%s", com_win_message);
657 else if ((in == '\10') || (in == 127))
659 in = 8; /* make sure key is set to backspace */
662 else if ((in > 31) || (in == 9))
664 else if ((in >= 0) && (in <= 31))
676 resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
677 int factor; /* resize factor */
678 struct text *rline; /* position in line */
681 unsigned char *rpoint;
684 rline->max_length += factor;
685 rpoint = rline->line = realloc(rline->line, rline->max_length );
686 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
692 insert(character) /* insert character into line */
693 int character; /* new character */
697 unsigned char *temp; /* temporary pointer */
698 unsigned char *temp2; /* temporary pointer */
700 if ((character == '\011') && (expand_tabs))
702 counter = len_char('\011', scr_horz);
703 for (; counter > 0; counter--)
710 if ((curr_line->max_length - curr_line->line_length) < 5)
711 point = resiz_line(10, curr_line, position);
712 curr_line->line_length++;
715 while (counter < curr_line->line_length) /* find end of line */
720 temp++; /* increase length of line by one */
724 *temp= *temp2; /* shift characters over by one */
727 *point = character; /* insert new character */
729 if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/
731 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
737 waddch(text_win, character);
738 scr_pos = ++scr_horz;
743 if ((observ_margins) && (right_margin < scr_pos))
746 while (scr_pos > right_margin)
750 while (position < counter)
757 for (value = 0; value < counter; value++)
762 if ((scr_horz - horiz_offset) > last_col)
765 midscreen(scr_vert, point);
768 if ((auto_format) && (character == ' ') && (!formatted))
770 else if ((character != ' ') && (character != '\t'))
773 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
777 delete(disp) /* delete character */
781 unsigned char *temp2;
782 struct text *temp_buff;
787 if (point != curr_line->line) /* if not at beginning of line */
791 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
797 position -= del_width;
799 curr_line->line_length -= del_width;
800 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
803 scr_horz -= del_width;
808 *d_char = *point; /* save deleted character */
812 d_char[1] = *(point + 1);
814 d_char[del_width] = '\0';
816 while (temp_pos <= curr_line->line_length)
823 if (scr_horz < horiz_offset)
826 midscreen(scr_vert, point);
829 else if (curr_line->prev_line != NULL)
833 left(disp); /* go to previous line */
834 temp_buff = curr_line->next_line;
835 point = resiz_line(temp_buff->line_length, curr_line, position);
836 if (temp_buff->next_line != NULL)
837 temp_buff->next_line->prev_line = curr_line;
838 curr_line->next_line = temp_buff->next_line;
839 temp2 = temp_buff->line;
847 while (temp_pos < temp_buff->line_length)
849 curr_line->line_length++;
856 free(temp_buff->line);
858 temp_buff = curr_line;
859 temp_vert = scr_vert;
861 if (scr_vert < last_line)
863 wmove(text_win, scr_vert + 1, 0);
866 while ((temp_buff != NULL) && (temp_vert < last_line))
868 temp_buff = temp_buff->next_line;
871 if ((temp_vert == last_line) && (temp_buff != NULL))
873 tp = temp_buff->line;
874 wmove(text_win, last_line,0);
876 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
877 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
880 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
885 scanline(pos) /* find the proper horizontal position for the pointer */
891 ptr = curr_line->line;
898 temp += tabshift(temp);
899 else if ((*ptr >= 10) && (*ptr <= 31))
901 else if ((*ptr >= 32) && (*ptr < 127))
903 else if (*ptr == 127)
912 if ((scr_horz - horiz_offset) > last_col)
914 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
915 midscreen(scr_vert, point);
917 else if (scr_horz < horiz_offset)
919 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
920 midscreen(scr_vert, point);
925 tabshift(temp_int) /* give the number of spaces to shift */
930 leftover = ((temp_int + 1) % 8);
934 return (9 - leftover);
938 out_char(window, character, column) /* output non-printing character */
947 if (character == TAB)
949 i1 = tabshift(column);
951 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
957 else if ((character >= '\0') && (character < ' '))
959 string = table[(int) character];
961 else if ((character < 0) || (character >= 127))
963 if (character == 127)
967 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
972 waddch(window, (char)character );
978 waddch(window, (char)character);
981 for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
982 waddch(window, string[i2]);
983 return(strlen(string));
987 len_char(character, column) /* return the length of the character */
989 int column; /* the column must be known to provide spacing for tabs */
993 if (character == '\t')
994 length = tabshift(column);
995 else if ((character >= 0) && (character < 32))
997 else if ((character >= 32) && (character <= 126))
999 else if (character == 127)
1001 else if (((character > 126) || (character < 0)) && (!eightbit))
1010 draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
1011 int vertical; /* current vertical position on screen */
1012 int horiz; /* current horizontal position on screen */
1013 unsigned char *ptr; /* pointer to line */
1014 int t_pos; /* current position (offset in bytes) from bol */
1015 int length; /* length (in bytes) of line */
1017 int d; /* partial length of special or tab char to display */
1018 unsigned char *temp; /* temporary pointer to position in line */
1019 int abs_column; /* offset in screen units from begin of line */
1020 int column; /* horizontal position on screen */
1021 int row; /* vertical position on screen */
1022 int posit; /* temporary position indicator within line */
1025 column = horiz - horiz_offset;
1032 wmove(text_win, row, 0);
1033 wclrtoeol(text_win);
1037 d = len_char(*temp, abs_column);
1043 wmove(text_win, row, column);
1044 wclrtoeol(text_win);
1045 while ((posit < length) && (column <= last_col))
1047 if ((*temp < 32) || (*temp >= 127))
1049 column += len_char(*temp, abs_column);
1050 abs_column += out_char(text_win, *temp, abs_column);
1056 waddch(text_win, *temp);
1061 if (column < last_col)
1062 wclrtoeol(text_win);
1063 wmove(text_win, vertical, (horiz - horiz_offset));
1067 insert_line(disp) /* insert new line */
1072 unsigned char *temp;
1073 unsigned char *extra;
1074 struct text *temp_nod;
1076 text_changes = TRUE;
1077 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1078 wclrtoeol(text_win);
1079 temp_nod= txtalloc();
1080 temp_nod->line = extra= malloc(10);
1081 temp_nod->line_length = 1;
1082 temp_nod->max_length = 10;
1083 temp_nod->line_number = curr_line->line_number + 1;
1084 temp_nod->next_line = curr_line->next_line;
1085 if (temp_nod->next_line != NULL)
1086 temp_nod->next_line->prev_line = temp_nod;
1087 temp_nod->prev_line = curr_line;
1088 curr_line->next_line = temp_nod;
1089 temp_pos2 = position;
1091 if (temp_pos2 < curr_line->line_length)
1094 while (temp_pos2 < curr_line->line_length)
1096 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1097 extra = resiz_line(10, temp_nod, temp_pos);
1098 temp_nod->line_length++;
1107 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1108 curr_line->line_length = 1 + temp - curr_line->line;
1110 curr_line->line_length = position;
1112 curr_line = temp_nod;
1115 point= curr_line->line;
1118 if (scr_vert < last_line)
1121 wclrtoeol(text_win);
1122 wmove(text_win, scr_vert, 0);
1123 winsertln(text_win);
1127 wmove(text_win, 0,0);
1128 wdeleteln(text_win);
1129 wmove(text_win, last_line,0);
1130 wclrtobot(text_win);
1132 scr_pos = scr_horz = 0;
1136 midscreen(scr_vert, point);
1138 draw_line(scr_vert, scr_horz, point, position,
1139 curr_line->line_length);
1143 struct text *txtalloc() /* allocate space for line structure */
1145 return((struct text *) malloc(sizeof( struct text)));
1148 struct files *name_alloc() /* allocate space for file name list node */
1150 return((struct files *) malloc(sizeof( struct files)));
1153 unsigned char *next_word(string) /* move to next word in string */
1154 unsigned char *string;
1156 while ((*string != '\0') && ((*string != 32) && (*string != 9)))
1158 while ((*string != '\0') && ((*string == 32) || (*string == 9)))
1164 prev_word() /* move to start of previous word in text */
1168 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1169 { /* if at the start of a word */
1170 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1173 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1175 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1177 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1185 control() /* use control for commands */
1189 if (in == 1) /* control a */
1191 string = get_string(ascii_code_str, TRUE);
1192 if (*string != '\0')
1195 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1200 else if (in == 2) /* control b */
1202 else if (in == 3) /* control c */
1206 else if (in == 4) /* control d */
1208 else if (in == 5) /* control e */
1210 else if (in == 6) /* control f */
1212 else if (in == 7) /* control g */
1214 else if (in == 8) /* control h */
1216 else if (in == 9) /* control i */
1218 else if (in == 10) /* control j */
1220 else if (in == 11) /* control k */
1222 else if (in == 12) /* control l */
1224 else if (in == 13) /* control m */
1226 else if (in == 14) /* control n */
1227 move_rel("d", max(5, (last_line - 5)));
1228 else if (in == 15) /* control o */
1230 else if (in == 16) /* control p */
1231 move_rel("u", max(5, (last_line - 5)));
1232 else if (in == 17) /* control q */
1234 else if (in == 18) /* control r */
1236 else if (in == 19) /* control s */
1238 else if (in == 20) /* control t */
1240 else if (in == 21) /* control u */
1242 else if (in == 22) /* control v */
1244 else if (in == 23) /* control w */
1246 else if (in == 24) /* control x */
1248 else if (in == 25) /* control y */
1250 else if (in == 26) /* control z */
1252 else if (in == 27) /* control [ (escape) */
1259 | Emacs control-key bindings
1267 if (in == 1) /* control a */
1269 else if (in == 2) /* control b */
1271 else if (in == 3) /* control c */
1275 else if (in == 4) /* control d */
1277 else if (in == 5) /* control e */
1279 else if (in == 6) /* control f */
1281 else if (in == 7) /* control g */
1282 move_rel("u", max(5, (last_line - 5)));
1283 else if (in == 8) /* control h */
1285 else if (in == 9) /* control i */
1287 else if (in == 10) /* control j */
1289 else if (in == 11) /* control k */
1291 else if (in == 12) /* control l */
1293 else if (in == 13) /* control m */
1295 else if (in == 14) /* control n */
1297 else if (in == 15) /* control o */
1299 string = get_string(ascii_code_str, TRUE);
1300 if (*string != '\0')
1303 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1308 else if (in == 16) /* control p */
1310 else if (in == 17) /* control q */
1312 else if (in == 18) /* control r */
1314 else if (in == 19) /* control s */
1316 else if (in == 20) /* control t */
1318 else if (in == 21) /* control u */
1320 else if (in == 22) /* control v */
1321 move_rel("d", max(5, (last_line - 5)));
1322 else if (in == 23) /* control w */
1324 else if (in == 24) /* control x */
1326 else if (in == 25) /* control y */
1328 else if (in == 26) /* control z */
1330 else if (in == 27) /* control [ (escape) */
1337 bottom() /* go to bottom of file */
1339 while (curr_line->next_line != NULL)
1341 curr_line = curr_line->next_line;
1344 point = curr_line->line;
1348 midscreen(last_line, point);
1353 top() /* go to top of file */
1355 while (curr_line->prev_line != NULL)
1357 curr_line = curr_line->prev_line;
1360 point = curr_line->line;
1364 midscreen(0, point);
1369 nextline() /* move pointers to start of next line */
1371 curr_line = curr_line->next_line;
1373 point = curr_line->line;
1375 if (scr_vert == last_line)
1377 wmove(text_win, 0,0);
1378 wdeleteln(text_win);
1379 wmove(text_win, last_line,0);
1380 wclrtobot(text_win);
1381 draw_line(last_line,0,point,1,curr_line->line_length);
1388 prevline() /* move pointers to start of previous line*/
1390 curr_line = curr_line->prev_line;
1392 point = curr_line->line;
1396 winsertln(text_win);
1397 draw_line(0,0,point,1,curr_line->line_length);
1401 while (position < curr_line->line_length)
1409 left(disp) /* move left one character */
1412 if (point != curr_line->line) /* if not at begin of line */
1414 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1422 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1425 else if (curr_line->prev_line != NULL)
1430 curr_line = curr_line->prev_line;
1431 point = curr_line->line + curr_line->line_length;
1432 position = curr_line->line_length;
1439 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1444 right(disp) /* move right one character */
1447 if (position < curr_line->line_length)
1449 if ((ee_chinese) && (*point > 127) &&
1450 ((curr_line->line_length - position) >= 2))
1458 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1461 else if (curr_line->next_line != NULL)
1466 curr_line = curr_line->next_line;
1467 point = curr_line->line;
1472 scr_pos = scr_horz = 0;
1476 midscreen(scr_vert, point);
1478 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1484 find_pos() /* move to the same column as on other line */
1488 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1491 scr_horz += tabshift(scr_horz);
1492 else if (*point < ' ')
1494 else if ((ee_chinese) && (*point > 127) &&
1495 ((curr_line->line_length - position) >= 2))
1506 if ((scr_horz - horiz_offset) > last_col)
1508 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1509 midscreen(scr_vert, point);
1511 else if (scr_horz < horiz_offset)
1513 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1514 midscreen(scr_vert, point);
1516 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1520 up() /* move up one line */
1522 if (curr_line->prev_line != NULL)
1525 point = curr_line->line;
1531 down() /* move down one line */
1533 if (curr_line->next_line != NULL)
1541 function_key() /* process function key */
1545 else if (in == KEY_RIGHT)
1547 else if (in == KEY_HOME)
1549 else if (in == KEY_END)
1551 else if (in == KEY_UP)
1553 else if (in == KEY_DOWN)
1555 else if (in == KEY_NPAGE)
1556 move_rel("d", max( 5, (last_line - 5)));
1557 else if (in == KEY_PPAGE)
1558 move_rel("u", max(5, (last_line - 5)));
1559 else if (in == KEY_DL)
1561 else if (in == KEY_DC)
1563 else if (in == KEY_BACKSPACE)
1565 else if (in == KEY_IL)
1566 { /* insert a line before current line */
1570 else if (in == KEY_F(1))
1572 else if (in == KEY_F(2))
1582 else if (in == KEY_F(3))
1592 else if (in == KEY_F(4))
1598 midscreen(scr_vert, point);
1603 else if (in == KEY_F(5))
1613 else if (in == KEY_F(6))
1623 else if (in == KEY_F(7))
1633 else if (in == KEY_F(8))
1650 sprintf(buffer, ">!%s", print_command);
1651 wmove(com_win, 0, 0);
1653 wprintw(com_win, printer_msg_str, print_command);
1664 info_type = COMMANDS;
1666 cmd_str = get_string(command_str, TRUE);
1667 if ((result = unique_test(cmd_str, commands)) != 1)
1670 wmove(com_win, 0, 0);
1672 wprintw(com_win, unkn_cmd_str, cmd_str);
1674 wprintw(com_win, non_unique_cmd_msg);
1678 info_type = CONTROL_KEYS;
1681 if (cmd_str != NULL)
1687 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1688 info_type = CONTROL_KEYS;
1690 if (cmd_str != NULL)
1695 command(cmd_str1) /* process commands from keyboard */
1698 char *cmd_str2 = NULL;
1699 char *cmd_str = cmd_str1;
1701 clear_com_win = TRUE;
1702 if (compare(cmd_str, HELP, FALSE))
1704 else if (compare(cmd_str, WRITE, FALSE))
1706 if (restrict_mode())
1710 cmd_str = next_word(cmd_str);
1711 if (*cmd_str == '\0')
1713 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1715 tmp_file = resolve_name(cmd_str);
1716 write_file(tmp_file, 1);
1717 if (tmp_file != cmd_str)
1720 else if (compare(cmd_str, READ, FALSE))
1722 if (restrict_mode())
1726 cmd_str = next_word(cmd_str);
1727 if (*cmd_str == '\0')
1729 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1733 tmp_file = resolve_name(cmd_str);
1735 if (tmp_file != cmd_str)
1738 else if (compare(cmd_str, LINE, FALSE))
1740 wmove(com_win, 0, 0);
1742 wprintw(com_win, line_num_str, curr_line->line_number);
1743 wprintw(com_win, line_len_str, curr_line->line_length);
1745 else if (compare(cmd_str, FILE_str, FALSE))
1747 wmove(com_win, 0, 0);
1749 if (in_file_name == NULL)
1750 wprintw(com_win, no_file_string);
1752 wprintw(com_win, current_file_str, in_file_name);
1754 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1756 else if (compare(cmd_str, CHARACTER, FALSE))
1758 wmove(com_win, 0, 0);
1760 wprintw(com_win, char_str, *point);
1762 else if (compare(cmd_str, REDRAW, FALSE))
1764 else if (compare(cmd_str, RESEQUENCE, FALSE))
1766 tmp_line = first_line->next_line;
1767 while (tmp_line != NULL)
1769 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1770 tmp_line = tmp_line->next_line;
1773 else if (compare(cmd_str, AUTHOR, FALSE))
1775 wmove(com_win, 0, 0);
1777 wprintw(com_win, "written by Hugh Mahon");
1779 else if (compare(cmd_str, VERSION, FALSE))
1781 wmove(com_win, 0, 0);
1783 wprintw(com_win, "%s", version);
1785 else if (compare(cmd_str, CASE, FALSE))
1787 else if (compare(cmd_str, NOCASE, FALSE))
1789 else if (compare(cmd_str, EXPAND, FALSE))
1791 else if (compare(cmd_str, NOEXPAND, FALSE))
1792 expand_tabs = FALSE;
1793 else if (compare(cmd_str, Exit_string, FALSE))
1795 else if (compare(cmd_str, chinese_cmd, FALSE))
1799 nc_setattrib(A_NC_BIG5);
1802 else if (compare(cmd_str, nochinese_cmd, FALSE))
1806 nc_clearattrib(A_NC_BIG5);
1809 else if (compare(cmd_str, QUIT_string, FALSE))
1811 else if (*cmd_str == '!')
1814 if ((*cmd_str == ' ') || (*cmd_str == 9))
1815 cmd_str = next_word(cmd_str);
1816 sh_command(cmd_str);
1818 else if ((*cmd_str == '<') && (!in_pipe))
1823 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1824 cmd_str = next_word(cmd_str);
1829 else if ((*cmd_str == '>') && (!out_pipe))
1833 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1834 cmd_str = next_word(cmd_str);
1840 wmove(com_win, 0, 0);
1842 wprintw(com_win, unkn_cmd_str, cmd_str);
1844 if (cmd_str2 != NULL)
1849 scan(line, offset, column) /* determine horizontal position for get_string */
1864 j += len_char(*stemp, j);
1871 get_string(prompt, advance) /* read string from input on command line */
1872 char *prompt; /* string containing user prompt message */
1873 int advance; /* if true, skip leading spaces and tabs */
1880 int g_horz, g_position, g_pos;
1883 g_point = tmp_string = malloc(512);
1886 waddstr(com_win, prompt);
1888 nam_str = tmp_string;
1889 clear_com_win = TRUE;
1890 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1895 in = wgetch(com_win);
1898 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1902 g_horz = scan(g_point, g_pos, g_position);
1903 tmp_int = tmp_int - g_horz;
1904 for (; 0 < tmp_int; tmp_int--)
1906 if ((g_horz+tmp_int) < (last_col - 1))
1908 waddch(com_win, '\010');
1909 waddch(com_win, ' ');
1910 waddch(com_win, '\010');
1915 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1917 if (in == '\026') /* control-v, accept next character verbatim */
1918 { /* allows entry of ^m, ^j, and ^h */
1920 in = wgetch(com_win);
1926 if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1)))
1927 g_horz += out_char(com_win, in, g_horz);
1931 if (g_horz < (last_col - 1))
1932 waddch(com_win, in);
1939 } while ((in != '\n') && (in != '\r'));
1941 nam_str = tmp_string;
1942 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1943 nam_str = next_word(nam_str);
1944 string = malloc(strlen(nam_str) + 1);
1945 strcpy(string, nam_str);
1952 compare(string1, string2, sensitive) /* compare two strings */
1965 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
1972 if (*strng1 != *strng2)
1977 if (toupper(*strng1) != toupper(*strng2))
1982 if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
1996 char *direction = NULL;
1997 struct text *t_line;
2001 while ((*ptr >='0') && (*ptr <= '9'))
2003 i= i * 10 + (*ptr - '0');
2009 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
2012 t_line = t_line->prev_line;
2015 while ((t_line->line_number < number) && (t_line->next_line != NULL))
2019 t_line = t_line->next_line;
2021 if ((i < 30) && (i > 0))
2023 move_rel(direction, i);
2027 if (!strcmp(direction, "d"))
2036 point = curr_line->line;
2038 midscreen((last_line / 2), point);
2041 wmove(com_win, 0, 0);
2043 wprintw(com_win, line_num_str, curr_line->line_number);
2044 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2048 midscreen(line, pnt) /* put current line in middle of screen */
2052 struct text *mid_line;
2055 line = min(line, last_line);
2056 mid_line = curr_line;
2057 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2058 curr_line = curr_line->prev_line;
2059 scr_vert = scr_horz = 0;
2060 wmove(text_win, 0, 0);
2063 curr_line = mid_line;
2065 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2069 get_options(numargs, arguments) /* get arguments from command line */
2075 struct files *temp_names = NULL;
2078 int no_more_opts = FALSE;
2081 | see if editor was invoked as 'ree' (restricted mode)
2084 if (!(name = strrchr(arguments[0], '/')))
2085 name = arguments[0];
2088 if (!strcmp(name, "ree"))
2091 top_of_stack = NULL;
2095 while ((count < numargs)&& (!no_more_opts))
2097 buff = arguments[count];
2098 if (!strcmp("-i", buff))
2100 info_window = FALSE;
2102 else if (!strcmp("-e", buff))
2104 expand_tabs = FALSE;
2106 else if (!strcmp("-h", buff))
2110 else if (!strcmp("-?", buff))
2112 fprintf(stderr, usage0, arguments[0]);
2113 fprintf(stderr, usage1);
2114 fprintf(stderr, usage2);
2115 fprintf(stderr, usage3);
2116 fprintf(stderr, usage4);
2119 else if ((*buff == '+') && (start_at_line == NULL))
2122 start_at_line = buff;
2124 else if (!(strcmp("--", buff)))
2125 no_more_opts = TRUE;
2129 no_more_opts = TRUE;
2133 while (count < numargs)
2135 buff = arguments[count];
2136 if (top_of_stack == NULL)
2138 temp_names = top_of_stack = name_alloc();
2142 temp_names->next_name = name_alloc();
2143 temp_names = temp_names->next_name;
2145 ptr = temp_names->name = malloc(strlen(buff) + 1);
2146 while (*buff != '\0')
2153 temp_names->next_name = NULL;
2161 check_fp() /* open or close files according to flags */
2167 clear_com_win = TRUE;
2168 tmp_vert = scr_vert;
2169 tmp_horz = scr_horz;
2170 tmp_line = curr_line;
2173 in_file_name = tmp_file = top_of_stack->name;
2174 top_of_stack = top_of_stack->next_name;
2176 temp = stat(tmp_file, &buf);
2177 buf.st_mode &= ~07777;
2178 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2180 wprintw(com_win, file_is_dir_msg, tmp_file);
2190 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2192 wmove(com_win, 0, 0);
2195 wprintw(com_win, new_file_msg, tmp_file);
2197 wprintw(com_win, cant_open_msg, tmp_file);
2199 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2209 line_num = curr_line->line_number;
2210 scr_vert = tmp_vert;
2211 scr_horz = tmp_horz;
2213 curr_line= first_line;
2215 curr_line = tmp_line;
2216 point = curr_line->line;
2221 if (start_at_line != NULL)
2223 line_num = atoi(start_at_line) - 1;
2224 move_rel("d", line_num);
2226 start_at_line = NULL;
2231 wmove(com_win, 0, 0);
2233 text_changes = TRUE;
2234 if ((tmp_file != NULL) && (*tmp_file != '\0'))
2235 wprintw(com_win, file_read_fin_msg, tmp_file);
2238 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2243 get_file(file_name) /* read specified file into current buffer */
2246 int can_read; /* file has at least one character */
2247 int length; /* length of line read by read */
2248 int append; /* should text be appended to current line */
2249 struct text *temp_line;
2250 char ro_flag = FALSE;
2252 if (recv_file) /* if reading a file */
2254 wmove(com_win, 0, 0);
2256 wprintw(com_win, reading_file_msg, file_name);
2257 if (access(file_name, 2)) /* check permission to write */
2259 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2261 wprintw(com_win, read_only_msg);
2267 if (curr_line->line_length > 1) /* if current line is not blank */
2275 can_read = FALSE; /* test if file has any characters */
2276 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2278 can_read = TRUE; /* if set file has at least 1 character */
2279 get_line(length, in_string, &append);
2281 if ((can_read) && (curr_line->line_length == 1))
2283 temp_line = curr_line->prev_line;
2284 temp_line->next_line = curr_line->next_line;
2285 if (temp_line->next_line != NULL)
2286 temp_line->next_line->prev_line = temp_line;
2287 if (curr_line->line != NULL)
2288 free(curr_line->line);
2290 curr_line = temp_line;
2292 if (input_file) /* if this is the file to be edited display number of lines */
2294 wmove(com_win, 0, 0);
2296 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2298 wprintw(com_win, read_only_msg);
2301 else if (can_read) /* not input_file and file is non-zero size */
2302 text_changes = TRUE;
2304 if (recv_file) /* if reading a file */
2311 get_line(length, in_string, append) /* read string and split into lines */
2312 int length; /* length of string read by read */
2313 unsigned char *in_string; /* string read by read */
2314 int *append; /* TRUE if must append more text to end of current line */
2316 unsigned char *str1;
2317 unsigned char *str2;
2318 int num; /* offset from start of string */
2319 int char_count; /* length of new line (or added portion */
2320 int temp_counter; /* temporary counter value */
2321 struct text *tline; /* temporary pointer to new line */
2322 int first_time; /* if TRUE, the first time through the loop */
2327 while (num < length)
2341 /* find end of line */
2342 while ((*str2 != '\n') && (num < length))
2348 if (!(*append)) /* if not append to current line, insert new one */
2350 tline = txtalloc(); /* allocate data structure for next line */
2351 tline->line_number = curr_line->line_number + 1;
2352 tline->next_line = curr_line->next_line;
2353 tline->prev_line = curr_line;
2354 curr_line->next_line = tline;
2355 if (tline->next_line != NULL)
2356 tline->next_line->prev_line = tline;
2358 curr_line->line = point = (unsigned char *) malloc(char_count);
2359 curr_line->line_length = char_count;
2360 curr_line->max_length = char_count;
2364 point = resiz_line(char_count, curr_line, curr_line->line_length);
2365 curr_line->line_length += (char_count - 1);
2367 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2375 if ((num == length) && (*str2 != '\n'))
2381 draw_screen() /* redraw the screen from current postion */
2383 struct text *temp_line;
2384 unsigned char *line_out;
2387 temp_line = curr_line;
2388 temp_vert = scr_vert;
2389 wclrtobot(text_win);
2390 while ((temp_line != NULL) && (temp_vert <= last_line))
2392 line_out = temp_line->line;
2393 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2395 temp_line = temp_line->next_line;
2397 wmove(text_win, temp_vert, 0);
2398 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2402 finish() /* prepare to exit edit session */
2404 char *file_name = in_file_name;
2407 | changes made here should be reflected in the 'save'
2408 | portion of file_op()
2411 if ((file_name == NULL) || (*file_name == '\0'))
2412 file_name = get_string(save_file_name_prompt, TRUE);
2414 if ((file_name == NULL) || (*file_name == '\0'))
2416 wmove(com_win, 0, 0);
2417 wprintw(com_win, file_not_saved_msg);
2420 clear_com_win = TRUE;
2424 tmp_file = resolve_name(file_name);
2425 if (tmp_file != file_name)
2428 file_name = tmp_file;
2431 if (write_file(file_name, 1))
2433 text_changes = FALSE;
2439 quit(noverify) /* exit editor */
2446 if ((text_changes) && (!noverify))
2448 ans = get_string(changes_made_prompt, TRUE);
2449 if (toupper(*ans) == toupper(*yes_char))
2450 text_changes = FALSE;
2455 if (top_of_stack == NULL)
2489 while (curr_line->next_line != NULL)
2490 curr_line = curr_line->next_line;
2491 while (curr_line != first_line)
2493 free(curr_line->line);
2494 curr_line = curr_line->prev_line;
2496 free(curr_line->next_line);
2498 curr_line->next_line = NULL;
2499 *curr_line->line = '\0';
2500 curr_line->line_length = 1;
2501 curr_line->line_number = 1;
2502 point = curr_line->line;
2503 scr_pos = scr_vert = scr_horz = 0;
2508 write_file(file_name, warn_if_exists)
2514 struct text *out_line;
2517 int write_flag = TRUE;
2520 if (warn_if_exists &&
2521 ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
2523 if ((temp_fp = fopen(file_name, "r")))
2525 tmp_point = get_string(file_exists_prompt, TRUE);
2526 if (toupper(*tmp_point) == toupper(*yes_char))
2535 clear_com_win = TRUE;
2539 if ((temp_fp = fopen(file_name, "w")) == NULL)
2541 clear_com_win = TRUE;
2544 wprintw(com_win, create_file_fail_msg, file_name);
2552 wprintw(com_win, writing_file_msg, file_name);
2555 out_line = first_line;
2556 while (out_line != NULL)
2559 tmp_point= out_line->line;
2560 while (temp_pos < out_line->line_length)
2562 putc(*tmp_point, temp_fp);
2566 charac += out_line->line_length;
2567 out_line = out_line->next_line;
2574 wprintw(com_win, file_written_msg, file_name, lines, charac);
2584 search(display_message) /* search for string in srch_str */
2585 int display_message;
2591 if ((srch_str == NULL) || (*srch_str == '\0'))
2593 if (display_message)
2595 wmove(com_win, 0, 0);
2597 wprintw(com_win, searching_msg);
2599 clear_com_win = TRUE;
2603 srch_line = curr_line;
2605 if (position < curr_line->line_length)
2607 iter = position + 1;
2608 while ((!found) && (srch_line != NULL))
2610 while ((iter < srch_line->line_length) && (!found))
2613 if (case_sen) /* if case sensitive */
2616 while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
2623 else /* if not case sensitive */
2625 srch_3 = u_srch_str;
2626 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
2633 if (!((*srch_3 == '\0') && (found)))
2636 if (iter < srch_line->line_length)
2643 srch_line = srch_line->next_line;
2644 if (srch_line != NULL)
2645 srch_1 = srch_line->line;
2652 if (display_message)
2654 wmove(com_win, 0, 0);
2658 if (lines_moved == 0)
2660 while (position < iter)
2665 if (lines_moved < 30)
2667 move_rel("d", lines_moved);
2668 while (position < iter)
2673 absolute_lin += lines_moved;
2674 curr_line = srch_line;
2679 midscreen((last_line / 2), point);
2685 if (display_message)
2687 wmove(com_win, 0, 0);
2689 wprintw(com_win, str_not_found_msg, srch_str);
2692 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2698 search_prompt() /* prompt and read search string (srch_str) */
2700 if (srch_str != NULL)
2702 if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
2704 srch_str = get_string(search_prompt_str, FALSE);
2707 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2708 while (*srch_3 != '\0')
2710 *srch_1 = toupper(*srch_3);
2719 del_char() /* delete current character */
2721 in = 8; /* backspace */
2722 if (position < curr_line->line_length) /* if not end of line */
2724 if ((ee_chinese) && (*point > 127) &&
2725 ((curr_line->line_length - position) >= 2))
2743 undel_char() /* undelete last deleted character */
2745 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2751 if (d_char[1] != '\0')
2760 del_word() /* delete word in front of cursor */
2764 unsigned char *d_word2;
2765 unsigned char *d_word3;
2766 unsigned char tmp_char[3];
2770 d_word = malloc(curr_line->line_length);
2771 tmp_char[0] = d_char[0];
2772 tmp_char[1] = d_char[1];
2773 tmp_char[2] = d_char[2];
2777 while ((tposit < curr_line->line_length) &&
2778 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2781 *d_word2 = *d_word3;
2785 while ((tposit < curr_line->line_length) &&
2786 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2789 *d_word2 = *d_word3;
2794 d_wrd_len = difference = d_word2 - d_word;
2796 while (tposit < curr_line->line_length)
2799 *d_word2 = *d_word3;
2803 curr_line->line_length -= difference;
2805 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2806 d_char[0] = tmp_char[0];
2807 d_char[1] = tmp_char[1];
2808 d_char[2] = tmp_char[2];
2809 text_changes = TRUE;
2814 undel_word() /* undelete last deleted word */
2818 unsigned char *tmp_old_ptr;
2819 unsigned char *tmp_space;
2820 unsigned char *tmp_ptr;
2821 unsigned char *d_word_ptr;
2824 | resize line to handle undeleted word
2826 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2827 point = resiz_line(d_wrd_len, curr_line, position);
2828 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2829 d_word_ptr = d_word;
2832 | copy d_word contents into temp space
2834 while (temp <= d_wrd_len)
2837 *tmp_ptr = *d_word_ptr;
2841 tmp_old_ptr = point;
2844 | copy contents of line from curent position to eol into
2847 while (tposit < curr_line->line_length)
2851 *tmp_ptr = *tmp_old_ptr;
2855 curr_line->line_length += d_wrd_len;
2856 tmp_old_ptr = point;
2858 tmp_ptr = tmp_space;
2861 | now copy contents from temp space back to original line
2863 while (tposit < temp)
2866 *tmp_old_ptr = *tmp_ptr;
2870 *tmp_old_ptr = '\0';
2872 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2876 del_line() /* delete from cursor to end of line */
2884 d_line = malloc(curr_line->line_length);
2888 while (tposit < curr_line->line_length)
2895 dlt_line->line_length = 1 + tposit - position;
2898 curr_line->line_length = position;
2899 wclrtoeol(text_win);
2900 if (curr_line->next_line != NULL)
2905 text_changes = TRUE;
2909 undel_line() /* undelete last deleted line */
2915 if (dlt_line->line_length == 0)
2920 point = resiz_line(dlt_line->line_length, curr_line, position);
2921 curr_line->line_length += dlt_line->line_length - 1;
2925 while (tposit < dlt_line->line_length)
2933 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2937 adv_word() /* advance to next word */
2939 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2941 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2946 move_rel(direction, lines) /* move relative to current line */
2953 if (*direction == 'u')
2956 while (position > 1)
2958 for (i = 0; i < lines; i++)
2962 if ((last_line > 5) && ( scr_vert < 4))
2965 tmp_line = curr_line;
2966 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2970 scr_vert = scr_vert + i;
2971 curr_line = tmp_line;
2979 if ((position != 1) && (curr_line->next_line != NULL))
2982 scr_pos = scr_horz = 0;
2986 midscreen(scr_vert, point);
2991 for (i = 1; i < lines; i++)
2995 if ((last_line > 10) && (scr_vert > (last_line - 5)))
2998 tmp_line = curr_line;
2999 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
3004 scr_vert = scr_vert - i;
3005 curr_line = tmp_line;
3010 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
3014 eol() /* go to end of line */
3016 if (position < curr_line->line_length)
3018 while (position < curr_line->line_length)
3021 else if (curr_line->next_line != NULL)
3024 while (position < curr_line->line_length)
3030 bol() /* move to beginning of line */
3032 if (point != curr_line->line)
3034 while (point != curr_line->line)
3037 else if (curr_line->prev_line != NULL)
3045 adv_line() /* advance to beginning of next line */
3047 if ((point != curr_line->line) || (scr_pos > 0))
3049 while (position < curr_line->line_length)
3053 else if (curr_line->next_line != NULL)
3063 struct text *tmpline = first_line;
3066 while ((tmpline != NULL) && (tmpline != curr_line))
3069 tmpline = tmpline->next_line;
3075 sh_command(string) /* execute shell command */
3076 char *string; /* string containing user command */
3080 char *path; /* directory path to executable */
3081 int parent; /* zero if child, child's pid if parent */
3084 struct text *line_holder;
3086 if (restrict_mode())
3091 if (!(path = getenv("SHELL")))
3093 last_slash = temp_point = path;
3094 while (*temp_point != '\0')
3096 if (*temp_point == '/')
3097 last_slash = ++temp_point;
3103 | if in_pipe is true, then output of the shell operation will be
3104 | read by the editor, and curses doesn't need to be turned off
3109 keypad(com_win, FALSE);
3110 keypad(text_win, FALSE);
3123 pipe(pipe_in); /* create a pipe */
3125 if (!parent) /* if the child */
3128 | child process which will fork and exec shell command (if shell output is
3129 | to be read by editor)
3133 | redirect stdout to pipe
3135 temp_stdout = dup(1);
3139 | redirect stderr to pipe
3141 temp_stderr = dup(2);
3146 | child will now continue down 'if (!in_pipe)'
3150 else /* if the parent */
3153 | prepare editor to read from the pipe
3155 signal(SIGCHLD, SIG_IGN);
3156 line_holder = curr_line;
3157 tmp_vert = scr_vert;
3159 get_fd = pipe_in[0];
3162 scr_vert = tmp_vert;
3163 scr_horz = scr_pos = 0;
3165 curr_line = line_holder;
3167 point = curr_line->line;
3169 signal(SIGCHLD, SIG_DFL);
3171 | since flag "in_pipe" is still TRUE, the path which waits for the child
3172 | process to die will be avoided.
3173 | (the pipe is closed, no more output can be expected)
3179 signal(SIGINT, SIG_IGN);
3185 | fork process which will exec command
3188 if (!parent) /* if the child */
3195 | prepare the child process (soon to exec a shell command) to read from the
3196 | pipe (which will be output from the editor's buffer)
3203 for (value = 1; value < 24; value++)
3204 signal(value, SIG_DFL);
3205 execl(path, last_slash, "-c", string, NULL);
3206 fprintf(stderr, exec_err_msg, path);
3209 else /* if the parent */
3214 | output the contents of the buffer to the pipe (to be read by the
3215 | process forked and exec'd above as stdin)
3218 line_holder = first_line;
3219 while (line_holder != NULL)
3221 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3222 write(pipe_out[1], "\n", 1);
3223 line_holder = line_holder->next_line;
3230 return_val = wait((int *) 0);
3232 while ((return_val != parent) && (return_val != -1));
3234 | if this process is actually the child of the editor, exit. Here's how it
3236 | The editor forks a process. If output must be sent to the command to be
3237 | exec'd another process is forked, and that process (the child's child)
3238 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3239 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3240 | If this is the editor process, shell_fork will be true, otherwise this is
3241 | the child of the edit process.
3246 signal(SIGINT, edit_abort);
3250 printf(continue_msg);
3252 while ((in = getchar()) != '\n')
3262 keypad(text_win, TRUE);
3263 keypad(com_win, TRUE);
3265 clearok(info_win, TRUE);
3272 set_up_term() /* set up the terminal for operating with ae */
3274 if (!curses_initialized)
3281 curses_initialized = TRUE;
3284 if (((LINES > 15) && (COLS >= 80)) && info_window)
3285 last_line = LINES - 8;
3288 info_window = FALSE;
3289 last_line = LINES - 2;
3292 idlok(stdscr, TRUE);
3293 com_win = newwin(1, COLS, (LINES - 1), 0);
3294 keypad(com_win, TRUE);
3295 idlok(com_win, TRUE);
3298 text_win = newwin((LINES - 1), COLS, 0, 0);
3300 text_win = newwin((LINES - 7), COLS, 6, 0);
3301 keypad(text_win, TRUE);
3302 idlok(text_win, TRUE);
3304 help_win = newwin((LINES - 1), COLS, 0, 0);
3305 keypad(help_win, TRUE);
3306 idlok(help_win, TRUE);
3309 info_type = CONTROL_KEYS;
3310 info_win = newwin(6, COLS, 0, 0);
3315 last_col = COLS - 1;
3316 local_LINES = LINES;
3321 nc_setattrib(A_NC_BIG5);
3329 if ((LINES == local_LINES) && (COLS == local_COLS))
3342 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3346 struct menu_entries menu_list[];
3349 int max_width, max_height;
3356 int top_offset; /* offset from top where menu items start */
3357 int vert_pos; /* vertical position */
3358 int vert_size; /* vertical size for menu list item display */
3359 int off_start = 1; /* offset from start of menu items to start display */
3363 | determine number and width of menu items
3367 while (menu_list[list_size + 1].item_string != NULL)
3370 for (counter = 0; counter <= list_size; counter++)
3372 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3376 max_width = max(max_width, strlen(menu_cancel_msg));
3377 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3381 | make sure that window is large enough to handle menu
3382 | if not, print error message and return to calling function
3385 if (max_width > COLS)
3387 wmove(com_win, 0, 0);
3389 wprintw(com_win, menu_too_lrg_msg);
3391 clear_com_win = TRUE;
3397 if (list_size > LINES)
3400 if (max_height > 11)
3401 vert_size = max_height - 8;
3403 vert_size = max_height;
3407 vert_size = list_size;
3408 max_height = list_size;
3411 if (LINES >= (vert_size + 8))
3413 if (menu_list[0].argument != MENU_WARN)
3414 max_height = vert_size + 8;
3416 max_height = vert_size + 7;
3419 x_off = (COLS - max_width) / 2;
3420 y_off = (LINES - max_height - 1) / 2;
3421 temp_win = newwin(max_height, max_width, y_off, x_off);
3422 keypad(temp_win, TRUE);
3424 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3431 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3433 wmove(temp_win, (counter + top_offset - off_start), 3);
3436 in = wgetch(temp_win);
3441 if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
3442 ((input >= '0') && (input <= '9')))
3444 if ((tolower(input) >= 'a') && (tolower(input) <= 'z'))
3446 temp = 1 + tolower(input) - 'a';
3448 else if ((input >= '0') && (input <= '9'))
3450 temp = (2 + 'z' - 'a') + (input - '0');
3453 if (temp <= list_size)
3463 case ' ': /* space */
3464 case '\004': /* ^d, down */
3468 if (counter > list_size)
3471 case '\010': /* ^h, backspace*/
3472 case '\025': /* ^u, up */
3473 case 127: /* ^?, delete */
3479 counter = list_size;
3481 case '\033': /* escape key */
3482 if (menu_list[0].argument != MENU_WARN)
3485 case '\014': /* ^l */
3486 case '\022': /* ^r, redraw */
3487 paint_menu(menu_list, max_width, max_height,
3488 list_size, top_offset, temp_win,
3489 off_start, vert_size);
3496 if (((list_size - off_start) >= (vert_size - 1)) &&
3497 (counter > (off_start + vert_size - 3)) &&
3500 if (counter == list_size)
3501 off_start = (list_size - vert_size) + 2;
3505 paint_menu(menu_list, max_width, max_height,
3506 list_size, top_offset, temp_win, off_start,
3509 else if ((list_size != vert_size) &&
3510 (counter > (off_start + vert_size - 2)))
3512 if (counter == list_size)
3513 off_start = 2 + (list_size - vert_size);
3514 else if (off_start == 1)
3519 paint_menu(menu_list, max_width, max_height,
3520 list_size, top_offset, temp_win, off_start,
3523 else if (counter < off_start)
3528 off_start = counter;
3530 paint_menu(menu_list, max_width, max_height,
3531 list_size, top_offset, temp_win, off_start,
3535 while ((input != '\r') && (input != '\n') && (counter != 0));
3541 if ((menu_list[counter].procedure != NULL) ||
3542 (menu_list[counter].iprocedure != NULL) ||
3543 (menu_list[counter].nprocedure != NULL))
3545 if (menu_list[counter].argument != -1)
3546 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3547 else if (menu_list[counter].ptr_argument != NULL)
3548 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3550 (*menu_list[counter].nprocedure)();
3561 paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
3562 off_start, vert_size)
3563 struct menu_entries menu_list[];
3564 int max_width, max_height, list_size, top_offset;
3566 int off_start, vert_size;
3568 int counter, temp_int;
3573 | output top and bottom portions of menu box only if window
3577 if (max_height > vert_size)
3579 wmove(menu_win, 1, 1);
3581 wstandout(menu_win);
3582 waddch(menu_win, '+');
3583 for (counter = 0; counter < (max_width - 4); counter++)
3584 waddch(menu_win, '-');
3585 waddch(menu_win, '+');
3587 wmove(menu_win, (max_height - 2), 1);
3588 waddch(menu_win, '+');
3589 for (counter = 0; counter < (max_width - 4); counter++)
3590 waddch(menu_win, '-');
3591 waddch(menu_win, '+');
3592 wstandend(menu_win);
3593 wmove(menu_win, 2, 3);
3594 waddstr(menu_win, menu_list[0].item_string);
3595 wmove(menu_win, (max_height - 3), 3);
3596 if (menu_list[0].argument != MENU_WARN)
3597 waddstr(menu_win, menu_cancel_msg);
3600 wstandout(menu_win);
3602 for (counter = 0; counter < (vert_size + top_offset); counter++)
3604 if (top_offset == 4)
3606 temp_int = counter + 2;
3611 wmove(menu_win, temp_int, 1);
3612 waddch(menu_win, '|');
3613 wmove(menu_win, temp_int, (max_width - 2));
3614 waddch(menu_win, '|');
3616 wstandend(menu_win);
3618 if (list_size > vert_size)
3623 wmove(menu_win, top_offset, 3);
3624 waddstr(menu_win, more_above_str);
3629 for (counter = off_start;
3630 ((temp_int + counter - off_start) < (vert_size - 1));
3633 wmove(menu_win, (top_offset + temp_int +
3634 (counter - off_start)), 3);
3636 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3637 waddstr(menu_win, menu_list[counter].item_string);
3640 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3642 if (counter == list_size)
3645 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3646 wprintw(menu_win, menu_list[counter].item_string);
3649 wprintw(menu_win, more_below_str);
3653 for (counter = 1; counter <= list_size; counter++)
3655 wmove(menu_win, (top_offset + counter - 1), 3);
3657 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3658 waddstr(menu_win, menu_list[counter].item_string);
3669 clearok(help_win, TRUE);
3670 for (counter = 0; counter < 22; counter++)
3672 wmove(help_win, counter, 0);
3673 waddstr(help_win, (emacs_keys_mode) ?
3674 emacs_help_text[counter] : help_text[counter]);
3678 wmove(com_win, 0, 0);
3679 wprintw(com_win, press_any_key_msg);
3681 counter = wgetch(com_win);
3685 wmove(com_win, 0, 0);
3701 for (counter = 0; counter < 5; counter++)
3703 wmove(info_win, counter, 0);
3704 wclrtoeol(info_win);
3705 if (info_type == CONTROL_KEYS)
3706 waddstr(info_win, (emacs_keys_mode) ?
3707 emacs_control_keys[counter] : control_keys[counter]);
3708 else if (info_type == COMMANDS)
3709 waddstr(info_win, command_strings[counter]);
3711 wmove(info_win, 5, 0);
3713 wstandout(info_win);
3714 waddstr(info_win, separator);
3715 wstandend(info_win);
3726 info_window = FALSE;
3727 last_line = LINES - 2;
3728 text_win = newwin((LINES - 1), COLS, 0, 0);
3729 keypad(text_win, TRUE);
3730 idlok(text_win, TRUE);
3731 clearok(text_win, TRUE);
3732 midscreen(scr_vert, point);
3734 clear_com_win = TRUE;
3738 create_info_window()
3742 last_line = LINES - 8;
3744 text_win = newwin((LINES - 7), COLS, 6, 0);
3745 keypad(text_win, TRUE);
3746 idlok(text_win, TRUE);
3749 info_win = newwin(6, COLS, 0, 0);
3751 info_type = CONTROL_KEYS;
3752 midscreen(min(scr_vert, last_line), point);
3753 clearok(info_win, TRUE);
3756 clear_com_win = TRUE;
3766 if (restrict_mode())
3771 if (arg == READ_FILE)
3773 string = get_string(file_read_prompt_str, TRUE);
3775 tmp_file = resolve_name(string);
3777 if (tmp_file != string)
3781 else if (arg == WRITE_FILE)
3783 string = get_string(file_write_prompt_str, TRUE);
3784 tmp_file = resolve_name(string);
3785 write_file(tmp_file, 1);
3786 if (tmp_file != string)
3790 else if (arg == SAVE_FILE)
3793 | changes made here should be reflected in finish()
3801 string = in_file_name;
3802 if ((string == NULL) || (*string == '\0'))
3803 string = get_string(save_file_name_prompt, TRUE);
3804 if ((string == NULL) || (*string == '\0'))
3806 wmove(com_win, 0, 0);
3807 wprintw(com_win, file_not_saved_msg);
3810 clear_com_win = TRUE;
3815 tmp_file = resolve_name(string);
3816 if (tmp_file != string)
3822 if (write_file(string, 1))
3824 in_file_name = string;
3825 text_changes = FALSE;
3838 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3851 menu_op(leave_menu);
3862 clearok(info_win, TRUE);
3866 clearok(text_win, TRUE);
3867 midscreen(scr_vert, point);
3871 | The following routines will "format" a paragraph (as defined by a
3872 | block of text with blank lines before and after the block).
3876 Blank_Line(test_line) /* test if line has any non-space characters */
3877 struct text *test_line;
3879 unsigned char *line;
3882 if (test_line == NULL)
3886 line = test_line->line;
3889 | To handle troff/nroff documents, consider a line with a
3890 | period ('.') in the first column to be blank. To handle mail
3891 | messages with included text, consider a line with a '>' blank.
3894 if ((*line == '.') || (*line == '>'))
3897 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3902 if (length != test_line->line_length)
3909 Format() /* format the paragraph according to set margins */
3917 unsigned char *line;
3918 unsigned char *tmp_srchstr;
3919 unsigned char *temp1, *temp2;
3920 unsigned char *temp_dword;
3921 unsigned char temp_d_char[3];
3923 temp_d_char[0] = d_char[0];
3924 temp_d_char[1] = d_char[1];
3925 temp_d_char[2] = d_char[2];
3928 | if observ_margins is not set, or the current line is blank,
3929 | do not format the current paragraph
3932 if ((!observ_margins) || (Blank_Line(curr_line)))
3936 | save the currently set flags, and clear them
3939 wmove(com_win, 0, 0);
3941 wprintw(com_win, formatting_msg);
3945 | get current position in paragraph, so after formatting, the cursor
3946 | will be in the same relative position
3949 tmp_af = auto_format;
3950 auto_format = FALSE;
3954 temp_dword = d_word;
3956 temp_case = case_sen;
3958 tmp_srchstr = srch_str;
3959 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3960 if ((*point == ' ') || (*point == '\t'))
3964 line = temp1 = point;
3965 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3975 while (!Blank_Line(curr_line->prev_line))
3979 while ((line != point) && (status))
3981 status = search(FALSE);
3985 wmove(com_win, 0, 0);
3987 wprintw(com_win, formatting_msg);
3991 | now get back to the start of the paragraph to start formatting
3996 while (!Blank_Line(curr_line->prev_line))
3999 observ_margins = FALSE;
4002 | Start going through lines, putting spaces at end of lines if they do
4003 | not already exist. Append lines together to get one long line, and
4004 | eliminate spacing at begin of lines.
4007 while (!Blank_Line(curr_line->next_line))
4019 if ((*point == ' ') || (*point == '\t'))
4024 | Now there is one long line. Eliminate extra spaces within the line
4025 | after the first word (so as not to blow away any indenting the user
4031 while (position < curr_line->line_length)
4033 if ((*point == ' ') && (*(point + 1) == ' '))
4040 | Now make sure there are two spaces after a '.'.
4044 while (position < curr_line->line_length)
4046 if ((*point == '.') && (*(point + 1) == ' '))
4051 while (*point == ' ')
4057 observ_margins = TRUE;
4060 wmove(com_win, 0, 0);
4062 wprintw(com_win, formatting_msg);
4066 | create lines between margins
4069 while (position < curr_line->line_length)
4071 while ((scr_pos < right_margin) && (position < curr_line->line_length))
4073 if (position < curr_line->line_length)
4083 | go back to begin of paragraph, put cursor back to original position
4087 while (!Blank_Line(curr_line->prev_line))
4091 | find word cursor was in
4094 while ((status) && (string_count > 0))
4101 | offset the cursor to where it was before from the start of the word
4111 | reset flags and strings to what they were before formatting
4116 d_word = temp_dword;
4117 case_sen = temp_case;
4119 srch_str = tmp_srchstr;
4120 d_char[0] = temp_d_char[0];
4121 d_char[1] = temp_d_char[1];
4122 d_char[2] = temp_d_char[2];
4123 auto_format = tmp_af;
4125 midscreen(scr_vert, point);
4130 unsigned char *init_name[3] = {
4131 "/usr/share/misc/init.ee",
4137 ee_init() /* check for init file and read it if it exists */
4140 unsigned char *string;
4141 unsigned char *str1;
4142 unsigned char *str2;
4147 string = getenv("HOME");
4150 str1 = home = malloc(strlen(string)+10);
4151 strcpy(home, string);
4152 strcat(home, "/.init.ee");
4153 init_name[1] = home;
4154 string = malloc(512);
4156 for (counter = 0; counter < 3; counter++)
4158 if (!(access(init_name[counter], 4)))
4160 init_file = fopen(init_name[counter], "r");
4161 while ((str2 = fgets(string, 512, init_file)) != NULL)
4163 str1 = str2 = string;
4164 while (*str2 != '\n')
4168 if (unique_test(string, init_strings) != 1)
4171 if (compare(str1, CASE, FALSE))
4173 else if (compare(str1, NOCASE, FALSE))
4175 else if (compare(str1, EXPAND, FALSE))
4177 else if (compare(str1, NOEXPAND, FALSE))
4178 expand_tabs = FALSE;
4179 else if (compare(str1, INFO, FALSE))
4181 else if (compare(str1, NOINFO, FALSE))
4182 info_window = FALSE;
4183 else if (compare(str1, MARGINS, FALSE))
4184 observ_margins = TRUE;
4185 else if (compare(str1, NOMARGINS, FALSE))
4186 observ_margins = FALSE;
4187 else if (compare(str1, AUTOFORMAT, FALSE))
4190 observ_margins = TRUE;
4192 else if (compare(str1, NOAUTOFORMAT, FALSE))
4193 auto_format = FALSE;
4194 else if (compare(str1, Echo, FALSE))
4196 str1 = next_word(str1);
4200 else if (compare(str1, PRINTCOMMAND, FALSE))
4202 str1 = next_word(str1);
4203 print_command = malloc(strlen(str1)+1);
4204 strcpy(print_command, str1);
4206 else if (compare(str1, RIGHTMARGIN, FALSE))
4208 str1 = next_word(str1);
4209 if ((*str1 >= '0') && (*str1 <= '9'))
4211 temp_int = atoi(str1);
4213 right_margin = temp_int;
4216 else if (compare(str1, HIGHLIGHT, FALSE))
4217 nohighlight = FALSE;
4218 else if (compare(str1, NOHIGHLIGHT, FALSE))
4220 else if (compare(str1, EIGHTBIT, FALSE))
4222 else if (compare(str1, NOEIGHTBIT, FALSE))
4227 else if (compare(str1, EMACS_string, FALSE))
4228 emacs_keys_mode = TRUE;
4229 else if (compare(str1, NOEMACS_string, FALSE))
4230 emacs_keys_mode = FALSE;
4231 else if (compare(str1, chinese_cmd, FALSE))
4236 else if (compare(str1, nochinese_cmd, FALSE))
4245 string = getenv("LANG");
4248 if (strcmp(string, "zh_TW.big5") == 0)
4257 | Save current configuration to .init.ee file in the current directory.
4264 FILE *old_init_file = NULL;
4265 char *file_name = ".init.ee";
4266 char *home_dir = "~/.init.ee";
4273 if (restrict_mode())
4278 option = menu_op(config_dump_menu);
4281 wmove(com_win, 0, 0);
4285 wprintw(com_win, conf_not_saved_msg);
4289 else if (option == 2)
4290 file_name = resolve_name(home_dir);
4293 | If a .init.ee file exists, move it to .init.ee.old.
4296 if (stat(file_name, &buf) != -1)
4298 sprintf(buffer, "%s.old", file_name);
4300 link(file_name, buffer);
4302 old_init_file = fopen(buffer, "r");
4305 init_file = fopen(file_name, "w");
4306 if (init_file == NULL)
4308 wprintw(com_win, conf_dump_err_msg);
4313 if (old_init_file != NULL)
4316 | Copy non-configuration info into new .init.ee file.
4318 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4320 length = strlen(string);
4321 string[length - 1] = '\0';
4323 if (unique_test(string, init_strings) == 1)
4325 if (compare(string, Echo, FALSE))
4327 fprintf(init_file, "%s\n", string);
4331 fprintf(init_file, "%s\n", string);
4334 fclose(old_init_file);
4337 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4338 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4339 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4340 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4341 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4342 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4343 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4344 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4345 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4346 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4347 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4351 wprintw(com_win, conf_dump_success_msg, file_name);
4354 if ((option == 2) && (file_name != home_dir))
4361 echo_string(string) /* echo the given string */
4368 while (*temp != '\0')
4375 else if (*temp == 't')
4377 else if (*temp == 'b')
4379 else if (*temp == 'r')
4381 else if (*temp == 'f')
4383 else if ((*temp == 'e') || (*temp == 'E'))
4384 putchar('\033'); /* escape */
4385 else if (*temp == '\\')
4387 else if (*temp == '\'')
4389 else if ((*temp >= '0') && (*temp <= '9'))
4392 while ((*temp >= '0') && (*temp <= '9'))
4394 Counter = (8 * Counter) + (*temp - '0');
4413 spell_op() /* check spelling of words in the editor */
4415 if (restrict_mode())
4419 top(); /* go to top of file */
4420 insert_line(FALSE); /* create two blank lines */
4423 command(shell_echo_msg);
4425 wmove(com_win, 0, 0);
4426 wprintw(com_win, spell_in_prog_msg);
4428 command("<>!spell"); /* send contents of buffer to command 'spell'
4429 and read the results back into the editor */
4435 char template[128], *name;
4439 if (restrict_mode())
4443 (void)sprintf(template, "/tmp/ee.XXXXXXXX");
4444 fd = mkstemp(template);
4446 wmove(com_win, 0, 0);
4447 wprintw(com_win, create_file_fail_msg, name);
4452 if (write_file(name, 0))
4454 sprintf(string, "ispell %s", name);
4465 first_word_len(test_line)
4466 struct text *test_line;
4471 if (test_line == NULL)
4474 pnt = test_line->line;
4475 if ((pnt == NULL) || (*pnt == '\0') ||
4476 (*pnt == '.') || (*pnt == '>'))
4479 if ((*pnt == ' ') || (*pnt == '\t'))
4481 pnt = next_word(pnt);
4488 while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
4493 while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
4502 Auto_Format() /* format the paragraph according to set margins */
4509 int tmp_d_line_length;
4510 int leave_loop = FALSE;
4514 unsigned char *line;
4515 unsigned char *tmp_srchstr;
4516 unsigned char *temp1, *temp2;
4517 unsigned char *temp_dword;
4518 unsigned char temp_d_char[3];
4519 unsigned char *tmp_d_line;
4522 temp_d_char[0] = d_char[0];
4523 temp_d_char[1] = d_char[1];
4524 temp_d_char[2] = d_char[2];
4527 | if observ_margins is not set, or the current line is blank,
4528 | do not format the current paragraph
4531 if ((!observ_margins) || (Blank_Line(curr_line)))
4535 | get current position in paragraph, so after formatting, the cursor
4536 | will be in the same relative position
4539 tmp_d_line = d_line;
4540 tmp_d_line_length = dlt_line->line_length;
4542 auto_format = FALSE;
4544 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
4546 temp_dword = d_word;
4547 temp_dwl = d_wrd_len;
4550 temp_case = case_sen;
4552 tmp_srchstr = srch_str;
4553 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4554 if ((*point == ' ') || (*point == '\t'))
4558 line = temp1 = point;
4559 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4569 while (!Blank_Line(curr_line->prev_line))
4573 while ((line != point) && (status))
4575 status = search(FALSE);
4580 | now get back to the start of the paragraph to start checking
4585 while (!Blank_Line(curr_line->prev_line))
4589 | Start going through lines, putting spaces at end of lines if they do
4590 | not already exist. Check line length, and move words to the next line
4591 | if they cross the margin. Then get words from the next line if they
4592 | will fit in before the margin.
4599 if (position != curr_line->line_length)
4613 | fill line if first word on next line will fit
4614 | in the line without crossing the margin
4617 while ((curr_line->next_line != NULL) &&
4618 ((word_len = first_word_len(curr_line->next_line)) > 0)
4619 && ((scr_pos + word_len) < right_margin))
4622 if ((*point == ' ') || (*point == '\t'))
4629 | We know this line was not blank before, so
4630 | make sure that it doesn't have one of the
4631 | leading characters that indicate the line
4632 | should not be modified.
4634 | We also know that this character should not
4635 | be left as the first character of this line.
4638 if ((Blank_Line(curr_line)) &&
4639 (curr_line->line[0] != '.') &&
4640 (curr_line->line[0] != '>'))
4649 | go to end of previous line
4655 | make sure there's a space at the end of the line
4668 | make sure line does not cross right margin
4671 while (right_margin <= scr_pos)
4677 if (Blank_Line(curr_line->next_line))
4681 if ((*point == ' ') || (*point == '\t'))
4691 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4701 | go back to begin of paragraph, put cursor back to original position
4706 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4710 | find word cursor was in
4714 while ((status) && (string_count > 0))
4716 status = search(FALSE);
4721 | offset the cursor to where it was before from the start of the word
4730 if ((string_count > 0) && (offset < 0))
4740 | reset flags and strings to what they were before formatting
4745 d_word = temp_dword;
4746 d_wrd_len = temp_dwl;
4747 case_sen = temp_case;
4749 srch_str = tmp_srchstr;
4750 d_char[0] = temp_d_char[0];
4751 d_char[1] = temp_d_char[1];
4752 d_char[2] = temp_d_char[2];
4754 dlt_line->line_length = tmp_d_line_length;
4755 d_line = tmp_d_line;
4758 midscreen(scr_vert, point);
4770 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4771 (expand_tabs ? ON : OFF));
4772 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4773 (case_sen ? ON : OFF));
4774 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4775 (observ_margins ? ON : OFF));
4776 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4777 (auto_format ? ON : OFF));
4778 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4779 (eightbit ? ON : OFF));
4780 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4781 (info_window ? ON : OFF));
4782 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4783 (emacs_keys_mode ? ON : OFF));
4784 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4786 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4787 (ee_chinese ? ON : OFF));
4789 ret_value = menu_op(modes_menu);
4794 expand_tabs = !expand_tabs;
4797 case_sen = !case_sen;
4800 observ_margins = !observ_margins;
4803 auto_format = !auto_format;
4805 observ_margins = TRUE;
4808 eightbit = !eightbit;
4813 nc_setattrib(A_NC_BIG5);
4815 nc_clearattrib(A_NC_BIG5);
4819 wnoutrefresh(text_win);
4825 create_info_window();
4828 emacs_keys_mode = !emacs_keys_mode;
4833 string = get_string(margin_prompt, TRUE);
4836 counter = atoi(string);
4838 right_margin = counter;
4843 ee_chinese = !ee_chinese;
4844 if (ee_chinese != FALSE)
4848 nc_setattrib(A_NC_BIG5);
4850 nc_clearattrib(A_NC_BIG5);
4858 while (ret_value != 0);
4862 is_in_string(string, substring) /* a strchr() look-alike for systems without
4864 char * string, *substring;
4868 for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
4870 for (full = string; (full != NULL) && (*full != '\0');
4881 | handle names of the form "~/file", "~user/file",
4882 | "$HOME/foo", "~/$FOO", etc.
4889 char long_buffer[1024];
4890 char short_buffer[128];
4898 struct passwd *user;
4905 user = (struct passwd *) getpwuid(index);
4910 slash = strchr(name, '/');
4914 user = (struct passwd *) getpwnam((name + 1));
4921 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4922 strcpy(buffer, user->pw_dir);
4923 strcat(buffer, slash);
4928 if (is_in_string(buffer, "$"))
4933 while ((*tmp != '\0') && (index < 1024))
4936 while ((*tmp != '\0') && (*tmp != '$') &&
4939 long_buffer[index] = *tmp;
4944 if ((*tmp == '$') && (index < 1024))
4949 if (*tmp == '{') /* } */ /* bracketed variable name */
4952 while ((*tmp != '\0') &&
4956 short_buffer[counter] = *tmp;
4965 while ((*tmp != '\0') &&
4970 short_buffer[counter] = *tmp;
4975 short_buffer[counter] = '\0';
4976 if ((slash = getenv(short_buffer)) != NULL)
4978 offset = strlen(slash);
4979 if ((offset + index) < 1024)
4980 strcpy(&long_buffer[index], slash);
4985 while ((start_of_var != tmp) && (index < 1024))
4987 long_buffer[index] = *start_of_var;
4998 long_buffer[index] = '\0';
5002 buffer = malloc(index + 1);
5003 strcpy(buffer, long_buffer);
5015 wmove(com_win, 0, 0);
5016 wprintw(com_win, restricted_msg);
5019 clear_com_win = TRUE;
5024 | The following routine tests the input string against the list of
5025 | strings, to determine if the string is a unique match with one of the
5030 unique_test(string, list)
5040 while (list[counter] != NULL)
5042 result = compare(string, list[counter], FALSE);
5052 | Get the catalog entry, and if it got it from the catalog,
5053 | make a copy, since the buffer will be overwritten by the
5054 | next call to catgets().
5058 catgetlocal(number, string)
5065 temp1 = catgets(catalog, 1, number, string);
5066 if (temp1 != string)
5068 temp2 = malloc(strlen(temp1) + 1);
5069 strcpy(temp2, temp1);
5074 #endif /* NO_CATGETS */
5077 | The following is to allow for using message catalogs which allow
5078 | the software to be 'localized', that is, to use different languages
5079 | all with the same binary. For more information, see your system
5080 | documentation, or the X/Open Internationalization Guide.
5089 setlocale(LC_ALL, "");
5090 catalog = catopen("ee", NL_CAT_LOCALE);
5091 #endif /* NO_CATGETS */
5093 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5094 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5095 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5096 mode_strings[3] = catgetlocal( 4, "margins observed ");
5097 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5098 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5099 mode_strings[6] = catgetlocal( 7, "info window ");
5100 mode_strings[8] = catgetlocal( 8, "right margin ");
5101 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5102 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5103 leave_menu[2].item_string = catgetlocal( 11, "no save");
5104 file_menu[0].item_string = catgetlocal( 12, "file menu");
5105 file_menu[1].item_string = catgetlocal( 13, "read a file");
5106 file_menu[2].item_string = catgetlocal( 14, "write a file");
5107 file_menu[3].item_string = catgetlocal( 15, "save file");
5108 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5109 search_menu[0].item_string = catgetlocal( 17, "search menu");
5110 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5111 search_menu[2].item_string = catgetlocal( 19, "search");
5112 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5113 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5114 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5115 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5116 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5117 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5118 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5119 main_menu[0].item_string = catgetlocal( 27, "main menu");
5120 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5121 main_menu[2].item_string = catgetlocal( 29, "help");
5122 main_menu[3].item_string = catgetlocal( 30, "file operations");
5123 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5124 main_menu[5].item_string = catgetlocal( 32, "settings");
5125 main_menu[6].item_string = catgetlocal( 33, "search");
5126 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5127 help_text[0] = catgetlocal( 35, "Control keys: ");
5128 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5129 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5130 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5131 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5132 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5133 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5134 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5135 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5136 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5137 help_text[10] = catgetlocal( 45, " ");
5138 help_text[11] = catgetlocal( 46, "Commands: ");
5139 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5140 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5141 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5142 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5143 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5144 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5145 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5146 help_text[19] = catgetlocal( 54, " ");
5147 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5148 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5149 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5150 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5151 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5152 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5153 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5154 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5155 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5156 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5157 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5158 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5159 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5160 no_file_string = catgetlocal( 68, "no file");
5161 ascii_code_str = catgetlocal( 69, "ascii code: ");
5162 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5163 command_str = catgetlocal( 71, "command: ");
5164 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5165 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5166 char_str = catgetlocal( 74, "character = %d");
5167 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5168 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5169 line_num_str = catgetlocal( 77, "line %d ");
5170 line_len_str = catgetlocal( 78, "length = %d");
5171 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5172 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5173 usage1 = catgetlocal( 81, " -i turn off info window\n");
5174 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5175 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5176 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5177 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5178 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5179 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5180 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5181 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5182 read_only_msg = catgetlocal( 90, ", read only");
5183 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5184 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5185 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5186 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5187 yes_char = catgetlocal( 95, "y");
5188 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5189 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5190 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5191 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5192 searching_msg = catgetlocal( 100, " ...searching");
5193 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5194 search_prompt_str = catgetlocal( 102, "search for: ");
5195 exec_err_msg = catgetlocal( 103, "could not exec %s\n");
5196 continue_msg = catgetlocal( 104, "press return to continue ");
5197 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5198 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5199 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5200 shell_prompt = catgetlocal( 108, "shell command: ");
5201 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5202 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5203 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5204 margin_prompt = catgetlocal( 112, "right margin is: ");
5205 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5206 ON = catgetlocal( 114, "ON");
5207 OFF = catgetlocal( 115, "OFF");
5208 HELP = catgetlocal( 116, "HELP");
5209 WRITE = catgetlocal( 117, "WRITE");
5210 READ = catgetlocal( 118, "READ");
5211 LINE = catgetlocal( 119, "LINE");
5212 FILE_str = catgetlocal( 120, "FILE");
5213 CHARACTER = catgetlocal( 121, "CHARACTER");
5214 REDRAW = catgetlocal( 122, "REDRAW");
5215 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5216 AUTHOR = catgetlocal( 124, "AUTHOR");
5217 VERSION = catgetlocal( 125, "VERSION");
5218 CASE = catgetlocal( 126, "CASE");
5219 NOCASE = catgetlocal( 127, "NOCASE");
5220 EXPAND = catgetlocal( 128, "EXPAND");
5221 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5222 Exit_string = catgetlocal( 130, "EXIT");
5223 QUIT_string = catgetlocal( 131, "QUIT");
5224 INFO = catgetlocal( 132, "INFO");
5225 NOINFO = catgetlocal( 133, "NOINFO");
5226 MARGINS = catgetlocal( 134, "MARGINS");
5227 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5228 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5229 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5230 Echo = catgetlocal( 138, "ECHO");
5231 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5232 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5233 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5234 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5235 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5236 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5240 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5241 emacs_help_text[0] = help_text[0];
5242 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5243 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
5244 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
5245 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5246 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5247 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5248 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5249 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5250 emacs_help_text[9] = help_text[9];
5251 emacs_help_text[10] = help_text[10];
5252 emacs_help_text[11] = help_text[11];
5253 emacs_help_text[12] = help_text[12];
5254 emacs_help_text[13] = help_text[13];
5255 emacs_help_text[14] = help_text[14];
5256 emacs_help_text[15] = help_text[15];
5257 emacs_help_text[16] = help_text[16];
5258 emacs_help_text[17] = help_text[17];
5259 emacs_help_text[18] = help_text[18];
5260 emacs_help_text[19] = help_text[19];
5261 emacs_help_text[20] = help_text[20];
5262 emacs_help_text[21] = help_text[21];
5263 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
5264 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
5265 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
5266 emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
5267 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5268 EMACS_string = catgetlocal( 159, "EMACS");
5269 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5270 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5271 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5272 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5273 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5274 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5275 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5276 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5277 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5278 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5279 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5280 more_above_str = catgetlocal( 181, "^^more^^");
5281 more_below_str = catgetlocal( 182, "VVmoreVV");
5282 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5283 chinese_cmd = catgetlocal( 184, "16BIT");
5284 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5287 commands[1] = WRITE;
5290 commands[4] = FILE_str;
5291 commands[5] = REDRAW;
5292 commands[6] = RESEQUENCE;
5293 commands[7] = AUTHOR;
5294 commands[8] = VERSION;
5296 commands[10] = NOCASE;
5297 commands[11] = EXPAND;
5298 commands[12] = NOEXPAND;
5299 commands[13] = Exit_string;
5300 commands[14] = QUIT_string;
5314 commands[28] = CHARACTER;
5315 commands[29] = chinese_cmd;
5316 commands[30] = nochinese_cmd;
5317 commands[31] = NULL;
5318 init_strings[0] = CASE;
5319 init_strings[1] = NOCASE;
5320 init_strings[2] = EXPAND;
5321 init_strings[3] = NOEXPAND;
5322 init_strings[4] = INFO;
5323 init_strings[5] = NOINFO;
5324 init_strings[6] = MARGINS;
5325 init_strings[7] = NOMARGINS;
5326 init_strings[8] = AUTOFORMAT;
5327 init_strings[9] = NOAUTOFORMAT;
5328 init_strings[10] = Echo;
5329 init_strings[11] = PRINTCOMMAND;
5330 init_strings[12] = RIGHTMARGIN;
5331 init_strings[13] = HIGHLIGHT;
5332 init_strings[14] = NOHIGHLIGHT;
5333 init_strings[15] = EIGHTBIT;
5334 init_strings[16] = NOEIGHTBIT;
5335 init_strings[17] = EMACS_string;
5336 init_strings[18] = NOEMACS_string;
5337 init_strings[19] = chinese_cmd;
5338 init_strings[20] = nochinese_cmd;
5339 init_strings[21] = NULL;
5342 | allocate space for strings here for settings menu
5345 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5347 modes_menu[counter].item_string = malloc(80);
5352 #endif /* NO_CATGETS */