4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
9 | Copyright (c) 2009, Hugh Mahon
10 | All rights reserved.
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions
16 | * Redistributions of source code must retain the above copyright
17 | notice, this list of conditions and the following disclaimer.
18 | * Redistributions in binary form must reproduce the above
19 | copyright notice, this list of conditions and the following
20 | disclaimer in the documentation and/or other materials provided
21 | with the distribution.
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | POSSIBILITY OF SUCH DAMAGE.
36 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
38 | This editor was purposely developed to be simple, both in
39 | interface and implementation. This editor was developed to
40 | address a specific audience: the user who is new to computers
43 | ee is not aimed at technical users; for that reason more
44 | complex features were intentionally left out. In addition,
45 | ee is intended to be compiled by people with little computer
46 | experience, which means that it needs to be small, relatively
47 | simple in implementation, and portable.
49 | This software and documentation contains
50 | proprietary information which is protected by
51 | copyright. All rights are reserved.
53 | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.104 2010/06/04 01:55:31 hugh Exp hugh $
57 char *ee_copyright_message =
58 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
60 #include "ee_version.h"
62 char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.104 $";
65 #include "new_curse.h"
75 #include <sys/types.h>
103 #define catgetlocal(a, b) (b)
104 #endif /* NO_CATGETS */
107 #define SIGCHLD SIGCLD
111 #define max(a, b) (a > b ? a : b)
112 #define min(a, b) (a < b ? a : b)
115 | defines for type of data to show in info window
118 #define CONTROL_KEYS 1
122 unsigned char *line; /* line of characters */
123 int line_number; /* line number */
124 int line_length; /* actual number of characters in the line */
125 int max_length; /* maximum number of characters the line handles */
126 struct text *next_line; /* next line of text */
127 struct text *prev_line; /* previous line of text */
130 struct text *first_line; /* first line of current buffer */
131 struct text *dlt_line; /* structure for info on deleted line */
132 struct text *curr_line; /* current line cursor is on */
133 struct text *tmp_line; /* temporary line pointer */
134 struct text *srch_line; /* temporary pointer for search routine */
136 struct files { /* structure to store names of files to be edited*/
137 unsigned char *name; /* name of file */
138 struct files *next_name;
141 struct files *top_of_stack = NULL;
143 int d_wrd_len; /* length of deleted word */
144 int position; /* offset in bytes from begin of line */
145 int scr_pos; /* horizontal position */
146 int scr_vert; /* vertical position on screen */
147 int scr_horz; /* horizontal position on screen */
148 int absolute_lin; /* number of lines from top */
149 int tmp_vert, tmp_horz;
150 int input_file; /* indicate to read input file */
151 int recv_file; /* indicate reading a file */
152 int edit; /* continue executing while true */
153 int gold; /* 'gold' function key pressed */
154 int fildes; /* file descriptor */
155 int case_sen; /* case sensitive search flag */
156 int last_line; /* last line for text display */
157 int last_col; /* last column for text display */
158 int horiz_offset = 0; /* offset from left edge of text */
159 int clear_com_win; /* flag to indicate com_win needs clearing */
160 int text_changes = FALSE; /* indicate changes have been made to text */
161 int get_fd; /* file descriptor for reading a file */
162 int info_window = TRUE; /* flag to indicate if help window visible */
163 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
164 int expand_tabs = TRUE; /* flag for expanding tabs */
165 int right_margin = 0; /* the right margin */
166 int observ_margins = TRUE; /* flag for whether margins are observed */
168 int temp_stdin; /* temporary storage for stdin */
169 int temp_stdout; /* temp storage for stdout descriptor */
170 int temp_stderr; /* temp storage for stderr descriptor */
171 int pipe_out[2]; /* pipe file desc for output */
172 int pipe_in[2]; /* pipe file descriptors for input */
173 int out_pipe; /* flag that info is piped out */
174 int in_pipe; /* flag that info is piped in */
175 int formatted = FALSE; /* flag indicating paragraph formatted */
176 int auto_format = FALSE; /* flag for auto_format mode */
177 int restricted = FALSE; /* flag to indicate restricted mode */
178 int nohighlight = FALSE; /* turns off highlighting */
179 int eightbit = TRUE; /* eight bit character flag */
180 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
181 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
182 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
183 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
184 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
185 /* by checking for high bit in a byte the */
186 /* code recognizes a two-byte character */
189 unsigned char *point; /* points to current position in line */
190 unsigned char *srch_str; /* pointer for search string */
191 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
192 unsigned char *srch_1; /* pointer to start of suspect string */
193 unsigned char *srch_2; /* pointer to next character of string */
194 unsigned char *srch_3;
195 unsigned char *in_file_name = NULL; /* name of input file */
196 char *tmp_file; /* temporary file name */
197 unsigned char *d_char; /* deleted character */
198 unsigned char *d_word; /* deleted word */
199 unsigned char *d_line; /* deleted line */
200 char in_string[513]; /* buffer for reading a file */
201 unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
202 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
203 int in; /* input character */
205 FILE *temp_fp; /* temporary file pointer */
206 FILE *bit_bucket; /* file pointer to /dev/null */
209 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
210 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
211 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
219 #if defined(__STDC__) || defined(__cplusplus)
227 | The following structure allows menu items to be flexibly declared.
228 | The first item is the string describing the selection, the second
229 | is the address of the procedure to call when the item is selected,
230 | and the third is the argument for the procedure.
232 | For those systems with i18n, the string should be accompanied by a
233 | catalog number. The 'int *' should be replaced with 'void *' on
234 | systems with that type.
236 | The first menu item will be the title of the menu, with NULL
237 | parameters for the procedure and argument, followed by the menu items.
239 | If the procedure value is NULL, the menu item is displayed, but no
240 | procedure is called when the item is selected. The number of the
241 | item will be returned. If the third (argument) parameter is -1, no
242 | argument is given to the procedure when it is called.
245 struct menu_entries {
247 int (*procedure)P_((struct menu_entries *));
248 struct menu_entries *ptr_argument;
249 int (*iprocedure)P_((int));
250 void (*nprocedure)P_((void));
254 int main P_((int argc, char *argv[]));
255 unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
256 void insert P_((int character));
257 void delete P_((int disp));
258 void scanline P_((unsigned char *pos));
259 int tabshift P_((int temp_int));
260 int out_char P_((WINDOW *window, int character, int column));
261 int len_char P_((int character, int column));
262 void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
263 void insert_line P_((int disp));
264 struct text *txtalloc P_((void));
265 struct files *name_alloc P_((void));
266 unsigned char *next_word P_((unsigned char *string));
267 void prev_word P_((void));
268 void control P_((void));
269 void emacs_control P_((void));
270 void bottom P_((void));
272 void nextline P_((void));
273 void prevline P_((void));
274 void left P_((int disp));
275 void right P_((int disp));
276 void find_pos P_((void));
278 void down P_((void));
279 void function_key P_((void));
280 void print_buffer P_((void));
281 void command_prompt P_((void));
282 void command P_((char *cmd_str1));
283 int scan P_((char *line, int offset, int column));
284 char *get_string P_((char *prompt, int advance));
285 int compare P_((char *string1, char *string2, int sensitive));
286 void goto_line P_((char *cmd_str));
287 void midscreen P_((int line, unsigned char *pnt));
288 void get_options P_((int numargs, char *arguments[]));
289 void check_fp P_((void));
290 void get_file P_((char *file_name));
291 void get_line P_((int length, unsigned char *in_string, int *append));
292 void draw_screen P_((void));
293 void finish P_((void));
294 int quit P_((int noverify));
295 void edit_abort P_((int arg));
296 void delete_text P_((void));
297 int write_file P_((char *file_name, int warn_if_exists));
298 int search P_((int display_message));
299 void search_prompt P_((void));
300 void del_char P_((void));
301 void undel_char P_((void));
302 void del_word P_((void));
303 void undel_word P_((void));
304 void del_line P_((void));
305 void undel_line P_((void));
306 void adv_word P_((void));
307 void move_rel P_((int direction, int lines));
310 void adv_line P_((void));
311 void sh_command P_((char *string));
312 void set_up_term P_((void));
313 void resize_check P_((void));
314 int menu_op P_((struct menu_entries *));
315 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));
316 void help P_((void));
317 void paint_info_win P_((void));
318 void no_info_window P_((void));
319 void create_info_window P_((void));
320 int file_op P_((int arg));
321 void shell_op P_((void));
322 void leave_op P_((void));
323 void redraw P_((void));
324 int Blank_Line P_((struct text *test_line));
325 void Format P_((void));
326 void ee_init P_((void));
327 void dump_ee_conf P_((void));
328 void echo_string P_((char *string));
329 void spell_op P_((void));
330 void ispell_op P_((void));
331 int first_word_len P_((struct text *test_line));
332 void Auto_Format P_((void));
333 void modes_op P_((void));
334 char *is_in_string P_((char *string, char *substring));
335 char *resolve_name P_((char *name));
336 int restrict_mode P_((void));
337 int unique_test P_((char *string, char *list[]));
338 void strings_init P_((void));
342 | allocate space here for the strings that will be in the menu
345 struct menu_entries modes_menu[] = {
346 {"", NULL, NULL, NULL, NULL, 0}, /* title */
347 {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */
348 {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/
349 {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */
350 {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */
351 {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/
352 {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */
353 {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/
354 {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */
355 {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */
356 {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
357 {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */
360 char *mode_strings[11];
362 #define NUM_MODES_ITEMS 10
364 struct menu_entries config_dump_menu[] = {
365 {"", NULL, NULL, NULL, NULL, 0},
366 {"", NULL, NULL, NULL, NULL, -1},
367 {"", NULL, NULL, NULL, NULL, -1},
368 {NULL, NULL, NULL, NULL, NULL, -1}
371 struct menu_entries leave_menu[] = {
372 {"", NULL, NULL, NULL, NULL, -1},
373 {"", NULL, NULL, NULL, finish, -1},
374 {"", NULL, NULL, quit, NULL, TRUE},
375 {NULL, NULL, NULL, NULL, NULL, -1}
382 struct menu_entries file_menu[] = {
383 {"", NULL, NULL, NULL, NULL, -1},
384 {"", NULL, NULL, file_op, NULL, READ_FILE},
385 {"", NULL, NULL, file_op, NULL, WRITE_FILE},
386 {"", NULL, NULL, file_op, NULL, SAVE_FILE},
387 {"", NULL, NULL, NULL, print_buffer, -1},
388 {NULL, NULL, NULL, NULL, NULL, -1}
391 struct menu_entries search_menu[] = {
392 {"", NULL, NULL, NULL, NULL, 0},
393 {"", NULL, NULL, NULL, search_prompt, -1},
394 {"", NULL, NULL, search, NULL, TRUE},
395 {NULL, NULL, NULL, NULL, NULL, -1}
398 struct menu_entries spell_menu[] = {
399 {"", NULL, NULL, NULL, NULL, -1},
400 {"", NULL, NULL, NULL, spell_op, -1},
401 {"", NULL, NULL, NULL, ispell_op, -1},
402 {NULL, NULL, NULL, NULL, NULL, -1}
405 struct menu_entries misc_menu[] = {
406 {"", NULL, NULL, NULL, NULL, -1},
407 {"", NULL, NULL, NULL, Format, -1},
408 {"", NULL, NULL, NULL, shell_op, -1},
409 {"", menu_op, spell_menu, NULL, NULL, -1},
410 {NULL, NULL, NULL, NULL, NULL, -1}
413 struct menu_entries main_menu[] = {
414 {"", NULL, NULL, NULL, NULL, -1},
415 {"", NULL, NULL, NULL, leave_op, -1},
416 {"", NULL, NULL, NULL, help, -1},
417 {"", menu_op, file_menu, NULL, NULL, -1},
418 {"", NULL, NULL, NULL, redraw, -1},
419 {"", NULL, NULL, NULL, modes_op, -1},
420 {"", menu_op, search_menu, NULL, NULL, -1},
421 {"", menu_op, misc_menu, NULL, NULL, -1},
422 {NULL, NULL, NULL, NULL, NULL, -1}
426 char *control_keys[5];
428 char *emacs_help_text[22];
429 char *emacs_control_keys[5];
431 char *command_strings[5];
433 char *init_strings[22];
437 #define max_alpha_char 36
440 | Declarations for strings for localization
443 char *com_win_message; /* to be shown in com_win if no info window */
444 char *no_file_string;
445 char *ascii_code_str;
446 char *printer_msg_str;
448 char *file_write_prompt_str;
449 char *file_read_prompt_str;
452 char *non_unique_cmd_msg;
455 char *current_file_str;
461 char *file_is_dir_msg;
465 char *file_read_fin_msg;
466 char *reading_file_msg;
468 char *file_read_lines_msg;
469 char *save_file_name_prompt;
470 char *file_not_saved_msg;
471 char *changes_made_prompt;
473 char *file_exists_prompt;
474 char *create_file_fail_msg;
475 char *writing_file_msg;
476 char *file_written_msg;
478 char *str_not_found_msg;
479 char *search_prompt_str;
482 char *menu_cancel_msg;
483 char *menu_size_err_msg;
484 char *press_any_key_msg;
486 char *formatting_msg;
487 char *shell_echo_msg;
488 char *spell_in_prog_msg;
490 char *restricted_msg;
523 char *NOEMACS_string;
524 char *conf_dump_err_msg;
525 char *conf_dump_success_msg;
526 char *conf_not_saved_msg;
527 char *ree_no_file_msg;
529 char *menu_too_lrg_msg;
530 char *more_above_str, *more_below_str;
531 char *separator = "===============================================================================";
533 char *chinese_cmd, *nochinese_cmd;
537 extern char *malloc();
538 extern char *realloc();
539 extern char *getenv();
540 FILE *fopen(); /* declaration for open function */
541 #endif /* HAS_STDLIB */
542 #endif /* __STDC__ */
545 main(argc, argv) /* beginning of main program */
551 for (counter = 1; counter < 24; counter++)
552 signal(counter, SIG_IGN);
554 signal(SIGCHLD, SIG_DFL);
555 signal(SIGSEGV, SIG_DFL);
556 signal(SIGINT, edit_abort);
557 d_char = malloc(3); /* provide a buffer for multi-byte chars */
558 d_word = malloc(150);
561 dlt_line = txtalloc();
562 dlt_line->line = d_line;
563 dlt_line->line_length = 0;
564 curr_line = first_line = txtalloc();
565 curr_line->line = point = malloc(10);
566 curr_line->line_length = 1;
567 curr_line->max_length = 10;
568 curr_line->prev_line = NULL;
569 curr_line->next_line = NULL;
570 curr_line->line_number = 1;
578 bit_bucket = fopen("/dev/null", "w");
580 gold = case_sen = FALSE;
585 get_options(argc, argv);
587 if (right_margin == 0)
588 right_margin = COLS - 1;
589 if (top_of_stack == NULL)
593 wmove(com_win, 0, 0);
595 wprintw(com_win, ree_no_file_msg);
599 wprintw(com_win, no_file_string);
605 clear_com_win = TRUE;
612 | display line and column information
618 wmove(info_win, 5, 0);
619 wprintw(info_win, separator);
620 wmove(info_win, 5, 5);
621 wprintw(info_win, "line %d col %d lines from top %d ",
622 curr_line->line_number, scr_horz, absolute_lin);
628 in = wgetch(text_win);
630 exit(0); /* without this exit ee will go into an
631 infinite loop if the network
638 clear_com_win = FALSE;
639 wmove(com_win, 0, 0);
643 wprintw(com_win, "%s", com_win_message);
650 else if ((in == '\10') || (in == 127))
652 in = 8; /* make sure key is set to backspace */
655 else if ((in > 31) || (in == 9))
657 else if ((in >= 0) && (in <= 31))
669 resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
670 int factor; /* resize factor */
671 struct text *rline; /* position in line */
674 unsigned char *rpoint;
677 rline->max_length += factor;
678 rpoint = rline->line = realloc(rline->line, rline->max_length );
679 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
685 insert(character) /* insert character into line */
686 int character; /* new character */
690 unsigned char *temp; /* temporary pointer */
691 unsigned char *temp2; /* temporary pointer */
693 if ((character == '\011') && (expand_tabs))
695 counter = len_char('\011', scr_horz);
696 for (; counter > 0; counter--)
703 if ((curr_line->max_length - curr_line->line_length) < 5)
704 point = resiz_line(10, curr_line, position);
705 curr_line->line_length++;
708 while (counter < curr_line->line_length) /* find end of line */
713 temp++; /* increase length of line by one */
717 *temp= *temp2; /* shift characters over by one */
720 *point = character; /* insert new character */
722 if (!isprint((unsigned char)character)) /* check for TAB character*/
724 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
730 waddch(text_win, (unsigned char)character);
731 scr_pos = ++scr_horz;
736 if ((observ_margins) && (right_margin < scr_pos))
739 while (scr_pos > right_margin)
743 while (position < counter)
750 for (value = 0; value < counter; value++)
755 if ((scr_horz - horiz_offset) > last_col)
758 midscreen(scr_vert, point);
761 if ((auto_format) && (character == ' ') && (!formatted))
763 else if ((character != ' ') && (character != '\t'))
766 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
770 delete(disp) /* delete character */
774 unsigned char *temp2;
775 struct text *temp_buff;
780 if (point != curr_line->line) /* if not at beginning of line */
784 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
790 position -= del_width;
792 curr_line->line_length -= del_width;
793 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
796 scr_horz -= del_width;
801 *d_char = *point; /* save deleted character */
805 d_char[1] = *(point + 1);
807 d_char[del_width] = '\0';
809 while (temp_pos <= curr_line->line_length)
816 if ((scr_horz < horiz_offset) && (horiz_offset > 0))
819 midscreen(scr_vert, point);
822 else if (curr_line->prev_line != NULL)
825 left(disp); /* go to previous line */
826 temp_buff = curr_line->next_line;
827 point = resiz_line(temp_buff->line_length, curr_line, position);
828 if (temp_buff->next_line != NULL)
829 temp_buff->next_line->prev_line = curr_line;
830 curr_line->next_line = temp_buff->next_line;
831 temp2 = temp_buff->line;
839 while (temp_pos < temp_buff->line_length)
841 curr_line->line_length++;
848 free(temp_buff->line);
850 temp_buff = curr_line;
851 temp_vert = scr_vert;
853 if (scr_vert < last_line)
855 wmove(text_win, scr_vert + 1, 0);
858 while ((temp_buff != NULL) && (temp_vert < last_line))
860 temp_buff = temp_buff->next_line;
863 if ((temp_vert == last_line) && (temp_buff != NULL))
865 tp = temp_buff->line;
866 wmove(text_win, last_line,0);
868 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
869 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
872 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
877 scanline(pos) /* find the proper horizontal position for the pointer */
883 ptr = curr_line->line;
890 temp += tabshift(temp);
891 else if ((*ptr >= 10) && (*ptr <= 31))
893 else if ((*ptr >= 32) && (*ptr < 127))
895 else if (*ptr == 127)
904 if ((scr_horz - horiz_offset) > last_col)
906 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
907 midscreen(scr_vert, point);
909 else if (scr_horz < horiz_offset)
911 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
912 midscreen(scr_vert, point);
917 tabshift(temp_int) /* give the number of spaces to shift */
922 leftover = ((temp_int + 1) % 8);
926 return (9 - leftover);
930 out_char(window, character, column) /* output non-printing character */
939 if (character == TAB)
941 i1 = tabshift(column);
943 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
949 else if ((character >= '\0') && (character < ' '))
951 string = table[(int) character];
953 else if ((character < 0) || (character >= 127))
955 if (character == 127)
959 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
964 waddch(window, (unsigned char)character );
970 waddch(window, (unsigned char)character);
973 for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
974 waddch(window, (unsigned char)string[i2]);
975 return(strlen(string));
979 len_char(character, column) /* return the length of the character */
981 int column; /* the column must be known to provide spacing for tabs */
985 if (character == '\t')
986 length = tabshift(column);
987 else if ((character >= 0) && (character < 32))
989 else if ((character >= 32) && (character <= 126))
991 else if (character == 127)
993 else if (((character > 126) || (character < 0)) && (!eightbit))
1002 draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
1003 int vertical; /* current vertical position on screen */
1004 int horiz; /* current horizontal position on screen */
1005 unsigned char *ptr; /* pointer to line */
1006 int t_pos; /* current position (offset in bytes) from bol */
1007 int length; /* length (in bytes) of line */
1009 int d; /* partial length of special or tab char to display */
1010 unsigned char *temp; /* temporary pointer to position in line */
1011 int abs_column; /* offset in screen units from begin of line */
1012 int column; /* horizontal position on screen */
1013 int row; /* vertical position on screen */
1014 int posit; /* temporary position indicator within line */
1017 column = horiz - horiz_offset;
1024 wmove(text_win, row, 0);
1025 wclrtoeol(text_win);
1029 d = len_char(*temp, abs_column);
1035 wmove(text_win, row, column);
1036 wclrtoeol(text_win);
1037 while ((posit < length) && (column <= last_col))
1039 if (!isprint(*temp))
1041 column += len_char(*temp, abs_column);
1042 abs_column += out_char(text_win, *temp, abs_column);
1048 waddch(text_win, *temp);
1053 if (column < last_col)
1054 wclrtoeol(text_win);
1055 wmove(text_win, vertical, (horiz - horiz_offset));
1059 insert_line(disp) /* insert new line */
1064 unsigned char *temp;
1065 unsigned char *extra;
1066 struct text *temp_nod;
1068 text_changes = TRUE;
1069 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1070 wclrtoeol(text_win);
1071 temp_nod= txtalloc();
1072 temp_nod->line = extra= malloc(10);
1073 temp_nod->line_length = 1;
1074 temp_nod->max_length = 10;
1075 temp_nod->line_number = curr_line->line_number + 1;
1076 temp_nod->next_line = curr_line->next_line;
1077 if (temp_nod->next_line != NULL)
1078 temp_nod->next_line->prev_line = temp_nod;
1079 temp_nod->prev_line = curr_line;
1080 curr_line->next_line = temp_nod;
1081 temp_pos2 = position;
1083 if (temp_pos2 < curr_line->line_length)
1086 while (temp_pos2 < curr_line->line_length)
1088 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1089 extra = resiz_line(10, temp_nod, temp_pos);
1090 temp_nod->line_length++;
1099 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1100 curr_line->line_length = 1 + temp - curr_line->line;
1102 curr_line->line_length = position;
1104 curr_line = temp_nod;
1107 point= curr_line->line;
1110 if (scr_vert < last_line)
1113 wclrtoeol(text_win);
1114 wmove(text_win, scr_vert, 0);
1115 winsertln(text_win);
1119 wmove(text_win, 0,0);
1120 wdeleteln(text_win);
1121 wmove(text_win, last_line,0);
1122 wclrtobot(text_win);
1124 scr_pos = scr_horz = 0;
1128 midscreen(scr_vert, point);
1130 draw_line(scr_vert, scr_horz, point, position,
1131 curr_line->line_length);
1135 struct text *txtalloc() /* allocate space for line structure */
1137 return((struct text *) malloc(sizeof( struct text)));
1140 struct files *name_alloc() /* allocate space for file name list node */
1142 return((struct files *) malloc(sizeof( struct files)));
1145 unsigned char *next_word(string) /* move to next word in string */
1146 unsigned char *string;
1148 while ((*string != '\0') && ((*string != 32) && (*string != 9)))
1150 while ((*string != '\0') && ((*string == 32) || (*string == 9)))
1156 prev_word() /* move to start of previous word in text */
1160 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1161 { /* if at the start of a word */
1162 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1165 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1167 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1169 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1177 control() /* use control for commands */
1181 if (in == 1) /* control a */
1183 string = get_string(ascii_code_str, TRUE);
1184 if (*string != '\0')
1187 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1192 else if (in == 2) /* control b */
1194 else if (in == 3) /* control c */
1198 else if (in == 4) /* control d */
1200 else if (in == 5) /* control e */
1202 else if (in == 6) /* control f */
1204 else if (in == 7) /* control g */
1206 else if (in == 8) /* control h */
1208 else if (in == 9) /* control i */
1210 else if (in == 10) /* control j */
1212 else if (in == 11) /* control k */
1214 else if (in == 12) /* control l */
1216 else if (in == 13) /* control m */
1218 else if (in == 14) /* control n */
1219 move_rel('d', max(5, (last_line - 5)));
1220 else if (in == 15) /* control o */
1222 else if (in == 16) /* control p */
1223 move_rel('u', max(5, (last_line - 5)));
1224 else if (in == 17) /* control q */
1226 else if (in == 18) /* control r */
1228 else if (in == 19) /* control s */
1230 else if (in == 20) /* control t */
1232 else if (in == 21) /* control u */
1234 else if (in == 22) /* control v */
1236 else if (in == 23) /* control w */
1238 else if (in == 24) /* control x */
1240 else if (in == 25) /* control y */
1242 else if (in == 26) /* control z */
1244 else if (in == 27) /* control [ (escape) */
1251 | Emacs control-key bindings
1259 if (in == 1) /* control a */
1261 else if (in == 2) /* control b */
1263 else if (in == 3) /* control c */
1267 else if (in == 4) /* control d */
1269 else if (in == 5) /* control e */
1271 else if (in == 6) /* control f */
1273 else if (in == 7) /* control g */
1274 move_rel('u', max(5, (last_line - 5)));
1275 else if (in == 8) /* control h */
1277 else if (in == 9) /* control i */
1279 else if (in == 10) /* control j */
1281 else if (in == 11) /* control k */
1283 else if (in == 12) /* control l */
1285 else if (in == 13) /* control m */
1287 else if (in == 14) /* control n */
1289 else if (in == 15) /* control o */
1291 string = get_string(ascii_code_str, TRUE);
1292 if (*string != '\0')
1295 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1300 else if (in == 16) /* control p */
1302 else if (in == 17) /* control q */
1304 else if (in == 18) /* control r */
1306 else if (in == 19) /* control s */
1308 else if (in == 20) /* control t */
1310 else if (in == 21) /* control u */
1312 else if (in == 22) /* control v */
1313 move_rel('d', max(5, (last_line - 5)));
1314 else if (in == 23) /* control w */
1316 else if (in == 24) /* control x */
1318 else if (in == 25) /* control y */
1320 else if (in == 26) /* control z */
1322 else if (in == 27) /* control [ (escape) */
1329 bottom() /* go to bottom of file */
1331 while (curr_line->next_line != NULL)
1333 curr_line = curr_line->next_line;
1336 point = curr_line->line;
1340 midscreen(last_line, point);
1345 top() /* go to top of file */
1347 while (curr_line->prev_line != NULL)
1349 curr_line = curr_line->prev_line;
1352 point = curr_line->line;
1356 midscreen(0, point);
1361 nextline() /* move pointers to start of next line */
1363 curr_line = curr_line->next_line;
1365 point = curr_line->line;
1367 if (scr_vert == last_line)
1369 wmove(text_win, 0,0);
1370 wdeleteln(text_win);
1371 wmove(text_win, last_line,0);
1372 wclrtobot(text_win);
1373 draw_line(last_line,0,point,1,curr_line->line_length);
1380 prevline() /* move pointers to start of previous line*/
1382 curr_line = curr_line->prev_line;
1384 point = curr_line->line;
1388 winsertln(text_win);
1389 draw_line(0,0,point,1,curr_line->line_length);
1393 while (position < curr_line->line_length)
1401 left(disp) /* move left one character */
1404 if (point != curr_line->line) /* if not at begin of line */
1406 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1414 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1417 else if (curr_line->prev_line != NULL)
1422 curr_line = curr_line->prev_line;
1423 point = curr_line->line + curr_line->line_length;
1424 position = curr_line->line_length;
1431 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1436 right(disp) /* move right one character */
1439 if (position < curr_line->line_length)
1441 if ((ee_chinese) && (*point > 127) &&
1442 ((curr_line->line_length - position) >= 2))
1450 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1453 else if (curr_line->next_line != NULL)
1458 curr_line = curr_line->next_line;
1459 point = curr_line->line;
1464 scr_pos = scr_horz = 0;
1468 midscreen(scr_vert, point);
1470 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1476 find_pos() /* move to the same column as on other line */
1480 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1483 scr_horz += tabshift(scr_horz);
1484 else if (*point < ' ')
1486 else if ((ee_chinese) && (*point > 127) &&
1487 ((curr_line->line_length - position) >= 2))
1498 if ((scr_horz - horiz_offset) > last_col)
1500 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1501 midscreen(scr_vert, point);
1503 else if (scr_horz < horiz_offset)
1505 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1506 midscreen(scr_vert, point);
1508 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1512 up() /* move up one line */
1514 if (curr_line->prev_line != NULL)
1517 point = curr_line->line;
1523 down() /* move down one line */
1525 if (curr_line->next_line != NULL)
1533 function_key() /* process function key */
1537 else if (in == KEY_RIGHT)
1539 else if (in == KEY_HOME)
1541 else if (in == KEY_END)
1543 else if (in == KEY_UP)
1545 else if (in == KEY_DOWN)
1547 else if (in == KEY_NPAGE)
1548 move_rel('d', max( 5, (last_line - 5)));
1549 else if (in == KEY_PPAGE)
1550 move_rel('u', max(5, (last_line - 5)));
1551 else if (in == KEY_DL)
1553 else if (in == KEY_DC)
1555 else if (in == KEY_BACKSPACE)
1557 else if (in == KEY_IL)
1558 { /* insert a line before current line */
1562 else if (in == KEY_F(1))
1564 else if (in == KEY_F(2))
1574 else if (in == KEY_F(3))
1584 else if (in == KEY_F(4))
1590 midscreen(scr_vert, point);
1595 else if (in == KEY_F(5))
1605 else if (in == KEY_F(6))
1615 else if (in == KEY_F(7))
1625 else if (in == KEY_F(8))
1642 sprintf(buffer, ">!%s", print_command);
1643 wmove(com_win, 0, 0);
1645 wprintw(com_win, printer_msg_str, print_command);
1656 info_type = COMMANDS;
1658 cmd_str = get_string(command_str, TRUE);
1659 if ((result = unique_test(cmd_str, commands)) != 1)
1662 wmove(com_win, 0, 0);
1664 wprintw(com_win, unkn_cmd_str, cmd_str);
1666 wprintw(com_win, non_unique_cmd_msg);
1670 info_type = CONTROL_KEYS;
1673 if (cmd_str != NULL)
1679 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1680 info_type = CONTROL_KEYS;
1682 if (cmd_str != NULL)
1687 command(cmd_str1) /* process commands from keyboard */
1690 char *cmd_str2 = NULL;
1691 char *cmd_str = cmd_str1;
1693 clear_com_win = TRUE;
1694 if (compare(cmd_str, HELP, FALSE))
1696 else if (compare(cmd_str, WRITE, FALSE))
1698 if (restrict_mode())
1702 cmd_str = next_word(cmd_str);
1703 if (*cmd_str == '\0')
1705 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1707 tmp_file = resolve_name(cmd_str);
1708 write_file(tmp_file, 1);
1709 if (tmp_file != cmd_str)
1712 else if (compare(cmd_str, READ, FALSE))
1714 if (restrict_mode())
1718 cmd_str = next_word(cmd_str);
1719 if (*cmd_str == '\0')
1721 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1725 tmp_file = resolve_name(cmd_str);
1727 if (tmp_file != cmd_str)
1730 else if (compare(cmd_str, LINE, FALSE))
1732 wmove(com_win, 0, 0);
1734 wprintw(com_win, line_num_str, curr_line->line_number);
1735 wprintw(com_win, line_len_str, curr_line->line_length);
1737 else if (compare(cmd_str, FILE_str, FALSE))
1739 wmove(com_win, 0, 0);
1741 if (in_file_name == NULL)
1742 wprintw(com_win, no_file_string);
1744 wprintw(com_win, current_file_str, in_file_name);
1746 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1748 else if (compare(cmd_str, CHARACTER, FALSE))
1750 wmove(com_win, 0, 0);
1752 wprintw(com_win, char_str, *point);
1754 else if (compare(cmd_str, REDRAW, FALSE))
1756 else if (compare(cmd_str, RESEQUENCE, FALSE))
1758 tmp_line = first_line->next_line;
1759 while (tmp_line != NULL)
1761 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1762 tmp_line = tmp_line->next_line;
1765 else if (compare(cmd_str, AUTHOR, FALSE))
1767 wmove(com_win, 0, 0);
1769 wprintw(com_win, "written by Hugh Mahon");
1771 else if (compare(cmd_str, VERSION, FALSE))
1773 wmove(com_win, 0, 0);
1775 wprintw(com_win, "%s", version);
1777 else if (compare(cmd_str, CASE, FALSE))
1779 else if (compare(cmd_str, NOCASE, FALSE))
1781 else if (compare(cmd_str, EXPAND, FALSE))
1783 else if (compare(cmd_str, NOEXPAND, FALSE))
1784 expand_tabs = FALSE;
1785 else if (compare(cmd_str, Exit_string, FALSE))
1787 else if (compare(cmd_str, chinese_cmd, FALSE))
1791 nc_setattrib(A_NC_BIG5);
1794 else if (compare(cmd_str, nochinese_cmd, FALSE))
1798 nc_clearattrib(A_NC_BIG5);
1801 else if (compare(cmd_str, QUIT_string, FALSE))
1803 else if (*cmd_str == '!')
1806 if ((*cmd_str == ' ') || (*cmd_str == 9))
1807 cmd_str = next_word(cmd_str);
1808 sh_command(cmd_str);
1810 else if ((*cmd_str == '<') && (!in_pipe))
1815 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1816 cmd_str = next_word(cmd_str);
1821 else if ((*cmd_str == '>') && (!out_pipe))
1825 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1826 cmd_str = next_word(cmd_str);
1832 wmove(com_win, 0, 0);
1834 wprintw(com_win, unkn_cmd_str, cmd_str);
1836 if (cmd_str2 != NULL)
1841 scan(line, offset, column) /* determine horizontal position for get_string */
1856 j += len_char(*stemp, j);
1863 get_string(prompt, advance) /* read string from input on command line */
1864 char *prompt; /* string containing user prompt message */
1865 int advance; /* if true, skip leading spaces and tabs */
1872 int g_horz, g_position, g_pos;
1875 g_point = tmp_string = malloc(512);
1878 waddstr(com_win, prompt);
1880 nam_str = tmp_string;
1881 clear_com_win = TRUE;
1882 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1887 in = wgetch(com_win);
1890 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1894 g_horz = scan(g_point, g_pos, g_position);
1895 tmp_int = tmp_int - g_horz;
1896 for (; 0 < tmp_int; tmp_int--)
1898 if ((g_horz+tmp_int) < (last_col - 1))
1900 waddch(com_win, '\010');
1901 waddch(com_win, ' ');
1902 waddch(com_win, '\010');
1907 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1909 if (in == '\026') /* control-v, accept next character verbatim */
1910 { /* allows entry of ^m, ^j, and ^h */
1912 in = wgetch(com_win);
1918 if (!isprint((unsigned char)in) && (g_horz < (last_col - 1)))
1919 g_horz += out_char(com_win, in, g_horz);
1923 if (g_horz < (last_col - 1))
1924 waddch(com_win, (unsigned char)in);
1931 } while ((in != '\n') && (in != '\r'));
1933 nam_str = tmp_string;
1934 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1935 nam_str = next_word(nam_str);
1936 string = malloc(strlen(nam_str) + 1);
1937 strcpy(string, nam_str);
1944 compare(string1, string2, sensitive) /* compare two strings */
1957 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
1964 if (*strng1 != *strng2)
1969 if (toupper((unsigned char)*strng1) != toupper((unsigned char)*strng2))
1974 if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
1988 char direction = '\0';
1989 struct text *t_line;
1993 while ((*ptr >='0') && (*ptr <= '9'))
1995 i= i * 10 + (*ptr - '0');
2001 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
2004 t_line = t_line->prev_line;
2007 while ((t_line->line_number < number) && (t_line->next_line != NULL))
2011 t_line = t_line->next_line;
2013 if ((i < 30) && (i > 0))
2015 move_rel(direction, i);
2019 if (direction != 'd')
2028 point = curr_line->line;
2030 midscreen((last_line / 2), point);
2033 wmove(com_win, 0, 0);
2035 wprintw(com_win, line_num_str, curr_line->line_number);
2036 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2040 midscreen(line, pnt) /* put current line in middle of screen */
2044 struct text *mid_line;
2047 line = min(line, last_line);
2048 mid_line = curr_line;
2049 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2050 curr_line = curr_line->prev_line;
2051 scr_vert = scr_horz = 0;
2052 wmove(text_win, 0, 0);
2055 curr_line = mid_line;
2057 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2061 get_options(numargs, arguments) /* get arguments from command line */
2067 struct files *temp_names = NULL;
2070 int no_more_opts = FALSE;
2073 | see if editor was invoked as 'ree' (restricted mode)
2076 if (!(name = strrchr(arguments[0], '/')))
2077 name = arguments[0];
2080 if (!strcmp(name, "ree"))
2083 top_of_stack = NULL;
2087 while ((count < numargs)&& (!no_more_opts))
2089 buff = arguments[count];
2090 if (!strcmp("-i", buff))
2092 info_window = FALSE;
2094 else if (!strcmp("-e", buff))
2096 expand_tabs = FALSE;
2098 else if (!strcmp("-h", buff))
2102 else if (!strcmp("-?", buff))
2104 fprintf(stderr, usage0, arguments[0]);
2105 fputs(usage1, stderr);
2106 fputs(usage2, stderr);
2107 fputs(usage3, stderr);
2108 fputs(usage4, stderr);
2111 else if ((*buff == '+') && (start_at_line == NULL))
2114 start_at_line = buff;
2116 else if (!(strcmp("--", buff)))
2117 no_more_opts = TRUE;
2121 no_more_opts = TRUE;
2125 while (count < numargs)
2127 buff = arguments[count];
2128 if (top_of_stack == NULL)
2130 temp_names = top_of_stack = name_alloc();
2134 temp_names->next_name = name_alloc();
2135 temp_names = temp_names->next_name;
2137 ptr = temp_names->name = malloc(strlen(buff) + 1);
2138 while (*buff != '\0')
2145 temp_names->next_name = NULL;
2153 check_fp() /* open or close files according to flags */
2159 clear_com_win = TRUE;
2160 tmp_vert = scr_vert;
2161 tmp_horz = scr_horz;
2162 tmp_line = curr_line;
2165 in_file_name = tmp_file = top_of_stack->name;
2166 top_of_stack = top_of_stack->next_name;
2168 temp = stat(tmp_file, &buf);
2169 buf.st_mode &= ~07777;
2170 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2172 wprintw(com_win, file_is_dir_msg, tmp_file);
2182 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2184 wmove(com_win, 0, 0);
2187 wprintw(com_win, new_file_msg, tmp_file);
2189 wprintw(com_win, cant_open_msg, tmp_file);
2191 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2201 line_num = curr_line->line_number;
2202 scr_vert = tmp_vert;
2203 scr_horz = tmp_horz;
2205 curr_line= first_line;
2207 curr_line = tmp_line;
2208 point = curr_line->line;
2213 if (start_at_line != NULL)
2215 line_num = atoi(start_at_line) - 1;
2216 move_rel('d', line_num);
2218 start_at_line = NULL;
2223 wmove(com_win, 0, 0);
2225 text_changes = TRUE;
2226 if ((tmp_file != NULL) && (*tmp_file != '\0'))
2227 wprintw(com_win, file_read_fin_msg, tmp_file);
2230 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2235 get_file(file_name) /* read specified file into current buffer */
2238 int can_read; /* file has at least one character */
2239 int length; /* length of line read by read */
2240 int append; /* should text be appended to current line */
2241 struct text *temp_line;
2242 char ro_flag = FALSE;
2244 if (recv_file) /* if reading a file */
2246 wmove(com_win, 0, 0);
2248 wprintw(com_win, reading_file_msg, file_name);
2249 if (access(file_name, 2)) /* check permission to write */
2251 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2253 wprintw(com_win, read_only_msg);
2259 if (curr_line->line_length > 1) /* if current line is not blank */
2267 can_read = FALSE; /* test if file has any characters */
2268 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2270 can_read = TRUE; /* if set file has at least 1 character */
2271 get_line(length, in_string, &append);
2273 if ((can_read) && (curr_line->line_length == 1))
2275 temp_line = curr_line->prev_line;
2276 temp_line->next_line = curr_line->next_line;
2277 if (temp_line->next_line != NULL)
2278 temp_line->next_line->prev_line = temp_line;
2279 if (curr_line->line != NULL)
2280 free(curr_line->line);
2282 curr_line = temp_line;
2284 if (input_file) /* if this is the file to be edited display number of lines */
2286 wmove(com_win, 0, 0);
2288 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2290 wprintw(com_win, read_only_msg);
2293 else if (can_read) /* not input_file and file is non-zero size */
2294 text_changes = TRUE;
2296 if (recv_file) /* if reading a file */
2303 get_line(length, in_string, append) /* read string and split into lines */
2304 int length; /* length of string read by read */
2305 unsigned char *in_string; /* string read by read */
2306 int *append; /* TRUE if must append more text to end of current line */
2308 unsigned char *str1;
2309 unsigned char *str2;
2310 int num; /* offset from start of string */
2311 int char_count; /* length of new line (or added portion */
2312 int temp_counter; /* temporary counter value */
2313 struct text *tline; /* temporary pointer to new line */
2314 int first_time; /* if TRUE, the first time through the loop */
2319 while (num < length)
2333 /* find end of line */
2334 while ((*str2 != '\n') && (num < length))
2340 if (!(*append)) /* if not append to current line, insert new one */
2342 tline = txtalloc(); /* allocate data structure for next line */
2343 tline->line_number = curr_line->line_number + 1;
2344 tline->next_line = curr_line->next_line;
2345 tline->prev_line = curr_line;
2346 curr_line->next_line = tline;
2347 if (tline->next_line != NULL)
2348 tline->next_line->prev_line = tline;
2350 curr_line->line = point = (unsigned char *) malloc(char_count);
2351 curr_line->line_length = char_count;
2352 curr_line->max_length = char_count;
2356 point = resiz_line(char_count, curr_line, curr_line->line_length);
2357 curr_line->line_length += (char_count - 1);
2359 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2367 if ((num == length) && (*str2 != '\n'))
2373 draw_screen() /* redraw the screen from current postion */
2375 struct text *temp_line;
2376 unsigned char *line_out;
2379 temp_line = curr_line;
2380 temp_vert = scr_vert;
2381 wclrtobot(text_win);
2382 while ((temp_line != NULL) && (temp_vert <= last_line))
2384 line_out = temp_line->line;
2385 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2387 temp_line = temp_line->next_line;
2389 wmove(text_win, temp_vert, 0);
2390 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2394 finish() /* prepare to exit edit session */
2396 char *file_name = in_file_name;
2399 | changes made here should be reflected in the 'save'
2400 | portion of file_op()
2403 if ((file_name == NULL) || (*file_name == '\0'))
2404 file_name = get_string(save_file_name_prompt, TRUE);
2406 if ((file_name == NULL) || (*file_name == '\0'))
2408 wmove(com_win, 0, 0);
2409 wprintw(com_win, file_not_saved_msg);
2412 clear_com_win = TRUE;
2416 tmp_file = resolve_name(file_name);
2417 if (tmp_file != file_name)
2420 file_name = tmp_file;
2423 if (write_file(file_name, 1))
2425 text_changes = FALSE;
2431 quit(noverify) /* exit editor */
2438 if ((text_changes) && (!noverify))
2440 ans = get_string(changes_made_prompt, TRUE);
2441 if (toupper((unsigned char)*ans) == toupper((unsigned char)*yes_char))
2442 text_changes = FALSE;
2447 if (top_of_stack == NULL)
2481 while (curr_line->next_line != NULL)
2482 curr_line = curr_line->next_line;
2483 while (curr_line != first_line)
2485 free(curr_line->line);
2486 curr_line = curr_line->prev_line;
2488 free(curr_line->next_line);
2490 curr_line->next_line = NULL;
2491 *curr_line->line = '\0';
2492 curr_line->line_length = 1;
2493 curr_line->line_number = 1;
2494 point = curr_line->line;
2495 scr_pos = scr_vert = scr_horz = 0;
2500 write_file(file_name, warn_if_exists)
2506 struct text *out_line;
2509 int write_flag = TRUE;
2512 if (warn_if_exists &&
2513 ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
2515 if ((temp_fp = fopen(file_name, "r")))
2517 tmp_point = get_string(file_exists_prompt, TRUE);
2518 if (toupper((unsigned char)*tmp_point) == toupper((unsigned char)*yes_char))
2527 clear_com_win = TRUE;
2531 if ((temp_fp = fopen(file_name, "w")) == NULL)
2533 clear_com_win = TRUE;
2536 wprintw(com_win, create_file_fail_msg, file_name);
2544 wprintw(com_win, writing_file_msg, file_name);
2547 out_line = first_line;
2548 while (out_line != NULL)
2551 tmp_point= out_line->line;
2552 while (temp_pos < out_line->line_length)
2554 putc(*tmp_point, temp_fp);
2558 charac += out_line->line_length;
2559 out_line = out_line->next_line;
2566 wprintw(com_win, file_written_msg, file_name, lines, charac);
2576 search(display_message) /* search for string in srch_str */
2577 int display_message;
2583 if ((srch_str == NULL) || (*srch_str == '\0'))
2585 if (display_message)
2587 wmove(com_win, 0, 0);
2589 wprintw(com_win, searching_msg);
2591 clear_com_win = TRUE;
2595 srch_line = curr_line;
2597 if (position < curr_line->line_length)
2599 iter = position + 1;
2600 while ((!found) && (srch_line != NULL))
2602 while ((iter < srch_line->line_length) && (!found))
2605 if (case_sen) /* if case sensitive */
2608 while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
2615 else /* if not case sensitive */
2617 srch_3 = u_srch_str;
2618 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
2625 if (!((*srch_3 == '\0') && (found)))
2628 if (iter < srch_line->line_length)
2635 srch_line = srch_line->next_line;
2636 if (srch_line != NULL)
2637 srch_1 = srch_line->line;
2644 if (display_message)
2646 wmove(com_win, 0, 0);
2650 if (lines_moved == 0)
2652 while (position < iter)
2657 if (lines_moved < 30)
2659 move_rel('d', lines_moved);
2660 while (position < iter)
2665 absolute_lin += lines_moved;
2666 curr_line = srch_line;
2671 midscreen((last_line / 2), point);
2677 if (display_message)
2679 wmove(com_win, 0, 0);
2681 wprintw(com_win, str_not_found_msg, srch_str);
2684 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2690 search_prompt() /* prompt and read search string (srch_str) */
2692 if (srch_str != NULL)
2694 if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
2696 srch_str = get_string(search_prompt_str, FALSE);
2699 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2700 while (*srch_3 != '\0')
2702 *srch_1 = toupper(*srch_3);
2711 del_char() /* delete current character */
2713 in = 8; /* backspace */
2714 if (position < curr_line->line_length) /* if not end of line */
2716 if ((ee_chinese) && (*point > 127) &&
2717 ((curr_line->line_length - position) >= 2))
2735 undel_char() /* undelete last deleted character */
2737 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2743 if (d_char[1] != '\0')
2752 del_word() /* delete word in front of cursor */
2756 unsigned char *d_word2;
2757 unsigned char *d_word3;
2758 unsigned char tmp_char[3];
2762 d_word = malloc(curr_line->line_length);
2763 tmp_char[0] = d_char[0];
2764 tmp_char[1] = d_char[1];
2765 tmp_char[2] = d_char[2];
2769 while ((tposit < curr_line->line_length) &&
2770 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2773 *d_word2 = *d_word3;
2777 while ((tposit < curr_line->line_length) &&
2778 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2781 *d_word2 = *d_word3;
2786 d_wrd_len = difference = d_word2 - d_word;
2788 while (tposit < curr_line->line_length)
2791 *d_word2 = *d_word3;
2795 curr_line->line_length -= difference;
2797 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2798 d_char[0] = tmp_char[0];
2799 d_char[1] = tmp_char[1];
2800 d_char[2] = tmp_char[2];
2801 text_changes = TRUE;
2806 undel_word() /* undelete last deleted word */
2810 unsigned char *tmp_old_ptr;
2811 unsigned char *tmp_space;
2812 unsigned char *tmp_ptr;
2813 unsigned char *d_word_ptr;
2816 | resize line to handle undeleted word
2818 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2819 point = resiz_line(d_wrd_len, curr_line, position);
2820 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2821 d_word_ptr = d_word;
2824 | copy d_word contents into temp space
2826 while (temp <= d_wrd_len)
2829 *tmp_ptr = *d_word_ptr;
2833 tmp_old_ptr = point;
2836 | copy contents of line from curent position to eol into
2839 while (tposit < curr_line->line_length)
2843 *tmp_ptr = *tmp_old_ptr;
2847 curr_line->line_length += d_wrd_len;
2848 tmp_old_ptr = point;
2850 tmp_ptr = tmp_space;
2853 | now copy contents from temp space back to original line
2855 while (tposit < temp)
2858 *tmp_old_ptr = *tmp_ptr;
2862 *tmp_old_ptr = '\0';
2864 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2868 del_line() /* delete from cursor to end of line */
2876 d_line = malloc(curr_line->line_length);
2880 while (tposit < curr_line->line_length)
2887 dlt_line->line_length = 1 + tposit - position;
2890 curr_line->line_length = position;
2891 wclrtoeol(text_win);
2892 if (curr_line->next_line != NULL)
2897 text_changes = TRUE;
2901 undel_line() /* undelete last deleted line */
2907 if (dlt_line->line_length == 0)
2912 point = resiz_line(dlt_line->line_length, curr_line, position);
2913 curr_line->line_length += dlt_line->line_length - 1;
2917 while (tposit < dlt_line->line_length)
2925 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2929 adv_word() /* advance to next word */
2931 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2933 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2938 move_rel(direction, lines) /* move relative to current line */
2945 if (direction == 'u')
2948 while (position > 1)
2950 for (i = 0; i < lines; i++)
2954 if ((last_line > 5) && ( scr_vert < 4))
2957 tmp_line = curr_line;
2958 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2962 scr_vert = scr_vert + i;
2963 curr_line = tmp_line;
2971 if ((position != 1) && (curr_line->next_line != NULL))
2974 scr_pos = scr_horz = 0;
2978 midscreen(scr_vert, point);
2983 for (i = 1; i < lines; i++)
2987 if ((last_line > 10) && (scr_vert > (last_line - 5)))
2990 tmp_line = curr_line;
2991 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
2996 scr_vert = scr_vert - i;
2997 curr_line = tmp_line;
3002 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
3006 eol() /* go to end of line */
3008 if (position < curr_line->line_length)
3010 while (position < curr_line->line_length)
3013 else if (curr_line->next_line != NULL)
3016 while (position < curr_line->line_length)
3022 bol() /* move to beginning of line */
3024 if (point != curr_line->line)
3026 while (point != curr_line->line)
3029 else if (curr_line->prev_line != NULL)
3037 adv_line() /* advance to beginning of next line */
3039 if ((point != curr_line->line) || (scr_pos > 0))
3041 while (position < curr_line->line_length)
3045 else if (curr_line->next_line != NULL)
3055 struct text *tmpline = first_line;
3058 while ((tmpline != NULL) && (tmpline != curr_line))
3061 tmpline = tmpline->next_line;
3067 sh_command(string) /* execute shell command */
3068 char *string; /* string containing user command */
3072 char *path; /* directory path to executable */
3073 int parent; /* zero if child, child's pid if parent */
3076 struct text *line_holder;
3078 if (restrict_mode())
3083 if (!(path = getenv("SHELL")))
3085 last_slash = temp_point = path;
3086 while (*temp_point != '\0')
3088 if (*temp_point == '/')
3089 last_slash = ++temp_point;
3095 | if in_pipe is true, then output of the shell operation will be
3096 | read by the editor, and curses doesn't need to be turned off
3101 keypad(com_win, FALSE);
3102 keypad(text_win, FALSE);
3115 pipe(pipe_in); /* create a pipe */
3117 if (!parent) /* if the child */
3120 | child process which will fork and exec shell command (if shell output is
3121 | to be read by editor)
3125 | redirect stdout to pipe
3127 temp_stdout = dup(1);
3131 | redirect stderr to pipe
3133 temp_stderr = dup(2);
3138 | child will now continue down 'if (!in_pipe)'
3142 else /* if the parent */
3145 | prepare editor to read from the pipe
3147 signal(SIGCHLD, SIG_IGN);
3148 line_holder = curr_line;
3149 tmp_vert = scr_vert;
3151 get_fd = pipe_in[0];
3154 scr_vert = tmp_vert;
3155 scr_horz = scr_pos = 0;
3157 curr_line = line_holder;
3159 point = curr_line->line;
3161 signal(SIGCHLD, SIG_DFL);
3163 | since flag "in_pipe" is still TRUE, the path which waits for the child
3164 | process to die will be avoided.
3165 | (the pipe is closed, no more output can be expected)
3171 signal(SIGINT, SIG_IGN);
3177 | fork process which will exec command
3180 if (!parent) /* if the child */
3187 | prepare the child process (soon to exec a shell command) to read from the
3188 | pipe (which will be output from the editor's buffer)
3195 for (value = 1; value < 24; value++)
3196 signal(value, SIG_DFL);
3197 execl(path, last_slash, "-c", string, NULL);
3198 fprintf(stderr, exec_err_msg, path);
3201 else /* if the parent */
3206 | output the contents of the buffer to the pipe (to be read by the
3207 | process forked and exec'd above as stdin)
3210 line_holder = first_line;
3211 while (line_holder != NULL)
3213 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3214 write(pipe_out[1], "\n", 1);
3215 line_holder = line_holder->next_line;
3222 return_val = wait((int *) 0);
3224 while ((return_val != parent) && (return_val != -1));
3226 | if this process is actually the child of the editor, exit. Here's how it
3228 | The editor forks a process. If output must be sent to the command to be
3229 | exec'd another process is forked, and that process (the child's child)
3230 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3231 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3232 | If this is the editor process, shell_fork will be true, otherwise this is
3233 | the child of the edit process.
3238 signal(SIGINT, edit_abort);
3242 fputs(continue_msg, stdout);
3244 while ((in = getchar()) != '\n')
3254 keypad(text_win, TRUE);
3255 keypad(com_win, TRUE);
3257 clearok(info_win, TRUE);
3264 set_up_term() /* set up the terminal for operating with ae */
3266 if (!curses_initialized)
3273 curses_initialized = TRUE;
3276 if (((LINES > 15) && (COLS >= 80)) && info_window)
3277 last_line = LINES - 8;
3280 info_window = FALSE;
3281 last_line = LINES - 2;
3284 idlok(stdscr, TRUE);
3285 com_win = newwin(1, COLS, (LINES - 1), 0);
3286 keypad(com_win, TRUE);
3287 idlok(com_win, TRUE);
3290 text_win = newwin((LINES - 1), COLS, 0, 0);
3292 text_win = newwin((LINES - 7), COLS, 6, 0);
3293 keypad(text_win, TRUE);
3294 idlok(text_win, TRUE);
3296 help_win = newwin((LINES - 1), COLS, 0, 0);
3297 keypad(help_win, TRUE);
3298 idlok(help_win, TRUE);
3301 info_type = CONTROL_KEYS;
3302 info_win = newwin(6, COLS, 0, 0);
3307 last_col = COLS - 1;
3308 local_LINES = LINES;
3313 nc_setattrib(A_NC_BIG5);
3321 if ((LINES == local_LINES) && (COLS == local_COLS))
3334 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3338 struct menu_entries menu_list[];
3341 int max_width, max_height;
3348 int top_offset; /* offset from top where menu items start */
3349 int vert_pos; /* vertical position */
3350 int vert_size; /* vertical size for menu list item display */
3351 int off_start = 1; /* offset from start of menu items to start display */
3355 | determine number and width of menu items
3359 while (menu_list[list_size + 1].item_string != NULL)
3362 for (counter = 0; counter <= list_size; counter++)
3364 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3368 max_width = max(max_width, strlen(menu_cancel_msg));
3369 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3373 | make sure that window is large enough to handle menu
3374 | if not, print error message and return to calling function
3377 if (max_width > COLS)
3379 wmove(com_win, 0, 0);
3381 wprintw(com_win, menu_too_lrg_msg);
3383 clear_com_win = TRUE;
3389 if (list_size > LINES)
3392 if (max_height > 11)
3393 vert_size = max_height - 8;
3395 vert_size = max_height;
3399 vert_size = list_size;
3400 max_height = list_size;
3403 if (LINES >= (vert_size + 8))
3405 if (menu_list[0].argument != MENU_WARN)
3406 max_height = vert_size + 8;
3408 max_height = vert_size + 7;
3411 x_off = (COLS - max_width) / 2;
3412 y_off = (LINES - max_height - 1) / 2;
3413 temp_win = newwin(max_height, max_width, y_off, x_off);
3414 keypad(temp_win, TRUE);
3416 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3423 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3425 wmove(temp_win, (counter + top_offset - off_start), 3);
3428 in = wgetch(temp_win);
3433 if (isascii(input) && isalnum(input))
3437 temp = 1 + tolower(input) - 'a';
3439 else if (isdigit(input))
3441 temp = (2 + 'z' - 'a') + (input - '0');
3444 if (temp <= list_size)
3454 case ' ': /* space */
3455 case '\004': /* ^d, down */
3459 if (counter > list_size)
3462 case '\010': /* ^h, backspace*/
3463 case '\025': /* ^u, up */
3464 case 127: /* ^?, delete */
3470 counter = list_size;
3472 case '\033': /* escape key */
3473 if (menu_list[0].argument != MENU_WARN)
3476 case '\014': /* ^l */
3477 case '\022': /* ^r, redraw */
3478 paint_menu(menu_list, max_width, max_height,
3479 list_size, top_offset, temp_win,
3480 off_start, vert_size);
3487 if (((list_size - off_start) >= (vert_size - 1)) &&
3488 (counter > (off_start + vert_size - 3)) &&
3491 if (counter == list_size)
3492 off_start = (list_size - vert_size) + 2;
3496 paint_menu(menu_list, max_width, max_height,
3497 list_size, top_offset, temp_win, off_start,
3500 else if ((list_size != vert_size) &&
3501 (counter > (off_start + vert_size - 2)))
3503 if (counter == list_size)
3504 off_start = 2 + (list_size - vert_size);
3505 else if (off_start == 1)
3510 paint_menu(menu_list, max_width, max_height,
3511 list_size, top_offset, temp_win, off_start,
3514 else if (counter < off_start)
3519 off_start = counter;
3521 paint_menu(menu_list, max_width, max_height,
3522 list_size, top_offset, temp_win, off_start,
3526 while ((input != '\r') && (input != '\n') && (counter != 0));
3532 if ((menu_list[counter].procedure != NULL) ||
3533 (menu_list[counter].iprocedure != NULL) ||
3534 (menu_list[counter].nprocedure != NULL))
3536 if (menu_list[counter].argument != -1)
3537 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3538 else if (menu_list[counter].ptr_argument != NULL)
3539 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3541 (*menu_list[counter].nprocedure)();
3552 paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
3553 off_start, vert_size)
3554 struct menu_entries menu_list[];
3555 int max_width, max_height, list_size, top_offset;
3557 int off_start, vert_size;
3559 int counter, temp_int;
3564 | output top and bottom portions of menu box only if window
3568 if (max_height > vert_size)
3570 wmove(menu_win, 1, 1);
3572 wstandout(menu_win);
3573 waddch(menu_win, '+');
3574 for (counter = 0; counter < (max_width - 4); counter++)
3575 waddch(menu_win, '-');
3576 waddch(menu_win, '+');
3578 wmove(menu_win, (max_height - 2), 1);
3579 waddch(menu_win, '+');
3580 for (counter = 0; counter < (max_width - 4); counter++)
3581 waddch(menu_win, '-');
3582 waddch(menu_win, '+');
3583 wstandend(menu_win);
3584 wmove(menu_win, 2, 3);
3585 waddstr(menu_win, menu_list[0].item_string);
3586 wmove(menu_win, (max_height - 3), 3);
3587 if (menu_list[0].argument != MENU_WARN)
3588 waddstr(menu_win, menu_cancel_msg);
3591 wstandout(menu_win);
3593 for (counter = 0; counter < (vert_size + top_offset); counter++)
3595 if (top_offset == 4)
3597 temp_int = counter + 2;
3602 wmove(menu_win, temp_int, 1);
3603 waddch(menu_win, '|');
3604 wmove(menu_win, temp_int, (max_width - 2));
3605 waddch(menu_win, '|');
3607 wstandend(menu_win);
3609 if (list_size > vert_size)
3614 wmove(menu_win, top_offset, 3);
3615 waddstr(menu_win, more_above_str);
3620 for (counter = off_start;
3621 ((temp_int + counter - off_start) < (vert_size - 1));
3624 wmove(menu_win, (top_offset + temp_int +
3625 (counter - off_start)), 3);
3627 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3628 waddstr(menu_win, menu_list[counter].item_string);
3631 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3633 if (counter == list_size)
3636 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3637 wprintw(menu_win, menu_list[counter].item_string);
3640 wprintw(menu_win, more_below_str);
3644 for (counter = 1; counter <= list_size; counter++)
3646 wmove(menu_win, (top_offset + counter - 1), 3);
3648 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3649 waddstr(menu_win, menu_list[counter].item_string);
3660 clearok(help_win, TRUE);
3661 for (counter = 0; counter < 22; counter++)
3663 wmove(help_win, counter, 0);
3664 waddstr(help_win, (emacs_keys_mode) ?
3665 emacs_help_text[counter] : help_text[counter]);
3669 wmove(com_win, 0, 0);
3670 wprintw(com_win, press_any_key_msg);
3672 counter = wgetch(com_win);
3676 wmove(com_win, 0, 0);
3692 for (counter = 0; counter < 5; counter++)
3694 wmove(info_win, counter, 0);
3695 wclrtoeol(info_win);
3696 if (info_type == CONTROL_KEYS)
3697 waddstr(info_win, (emacs_keys_mode) ?
3698 emacs_control_keys[counter] : control_keys[counter]);
3699 else if (info_type == COMMANDS)
3700 waddstr(info_win, command_strings[counter]);
3702 wmove(info_win, 5, 0);
3704 wstandout(info_win);
3705 waddstr(info_win, separator);
3706 wstandend(info_win);
3717 info_window = FALSE;
3718 last_line = LINES - 2;
3719 text_win = newwin((LINES - 1), COLS, 0, 0);
3720 keypad(text_win, TRUE);
3721 idlok(text_win, TRUE);
3722 clearok(text_win, TRUE);
3723 midscreen(scr_vert, point);
3725 clear_com_win = TRUE;
3729 create_info_window()
3733 last_line = LINES - 8;
3735 text_win = newwin((LINES - 7), COLS, 6, 0);
3736 keypad(text_win, TRUE);
3737 idlok(text_win, TRUE);
3740 info_win = newwin(6, COLS, 0, 0);
3742 info_type = CONTROL_KEYS;
3743 midscreen(min(scr_vert, last_line), point);
3744 clearok(info_win, TRUE);
3747 clear_com_win = TRUE;
3757 if (restrict_mode())
3762 if (arg == READ_FILE)
3764 string = get_string(file_read_prompt_str, TRUE);
3766 tmp_file = resolve_name(string);
3768 if (tmp_file != string)
3772 else if (arg == WRITE_FILE)
3774 string = get_string(file_write_prompt_str, TRUE);
3775 tmp_file = resolve_name(string);
3776 write_file(tmp_file, 1);
3777 if (tmp_file != string)
3781 else if (arg == SAVE_FILE)
3784 | changes made here should be reflected in finish()
3792 string = in_file_name;
3793 if ((string == NULL) || (*string == '\0'))
3794 string = get_string(save_file_name_prompt, TRUE);
3795 if ((string == NULL) || (*string == '\0'))
3797 wmove(com_win, 0, 0);
3798 wprintw(com_win, file_not_saved_msg);
3801 clear_com_win = TRUE;
3806 tmp_file = resolve_name(string);
3807 if (tmp_file != string)
3813 if (write_file(string, 1))
3815 in_file_name = string;
3816 text_changes = FALSE;
3829 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3842 menu_op(leave_menu);
3853 clearok(info_win, TRUE);
3857 clearok(text_win, TRUE);
3858 midscreen(scr_vert, point);
3862 | The following routines will "format" a paragraph (as defined by a
3863 | block of text with blank lines before and after the block).
3867 Blank_Line(test_line) /* test if line has any non-space characters */
3868 struct text *test_line;
3870 unsigned char *line;
3873 if (test_line == NULL)
3877 line = test_line->line;
3880 | To handle troff/nroff documents, consider a line with a
3881 | period ('.') in the first column to be blank. To handle mail
3882 | messages with included text, consider a line with a '>' blank.
3885 if ((*line == '.') || (*line == '>'))
3888 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3893 if (length != test_line->line_length)
3900 Format() /* format the paragraph according to set margins */
3908 unsigned char *line;
3909 unsigned char *tmp_srchstr;
3910 unsigned char *temp1, *temp2;
3911 unsigned char *temp_dword;
3912 unsigned char temp_d_char[3];
3914 temp_d_char[0] = d_char[0];
3915 temp_d_char[1] = d_char[1];
3916 temp_d_char[2] = d_char[2];
3919 | if observ_margins is not set, or the current line is blank,
3920 | do not format the current paragraph
3923 if ((!observ_margins) || (Blank_Line(curr_line)))
3927 | save the currently set flags, and clear them
3930 wmove(com_win, 0, 0);
3932 wprintw(com_win, formatting_msg);
3936 | get current position in paragraph, so after formatting, the cursor
3937 | will be in the same relative position
3940 tmp_af = auto_format;
3941 auto_format = FALSE;
3945 temp_dword = d_word;
3947 temp_case = case_sen;
3949 tmp_srchstr = srch_str;
3950 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3951 if ((*point == ' ') || (*point == '\t'))
3955 line = temp1 = point;
3956 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3966 while (!Blank_Line(curr_line->prev_line))
3970 while ((line != point) && (status))
3972 status = search(FALSE);
3976 wmove(com_win, 0, 0);
3978 wprintw(com_win, formatting_msg);
3982 | now get back to the start of the paragraph to start formatting
3987 while (!Blank_Line(curr_line->prev_line))
3990 observ_margins = FALSE;
3993 | Start going through lines, putting spaces at end of lines if they do
3994 | not already exist. Append lines together to get one long line, and
3995 | eliminate spacing at begin of lines.
3998 while (!Blank_Line(curr_line->next_line))
4010 if ((*point == ' ') || (*point == '\t'))
4015 | Now there is one long line. Eliminate extra spaces within the line
4016 | after the first word (so as not to blow away any indenting the user
4022 while (position < curr_line->line_length)
4024 if ((*point == ' ') && (*(point + 1) == ' '))
4031 | Now make sure there are two spaces after a '.'.
4035 while (position < curr_line->line_length)
4037 if ((*point == '.') && (*(point + 1) == ' '))
4042 while (*point == ' ')
4048 observ_margins = TRUE;
4051 wmove(com_win, 0, 0);
4053 wprintw(com_win, formatting_msg);
4057 | create lines between margins
4060 while (position < curr_line->line_length)
4062 while ((scr_pos < right_margin) && (position < curr_line->line_length))
4064 if (position < curr_line->line_length)
4074 | go back to begin of paragraph, put cursor back to original position
4078 while (!Blank_Line(curr_line->prev_line))
4082 | find word cursor was in
4085 while ((status) && (string_count > 0))
4092 | offset the cursor to where it was before from the start of the word
4102 | reset flags and strings to what they were before formatting
4107 d_word = temp_dword;
4108 case_sen = temp_case;
4110 srch_str = tmp_srchstr;
4111 d_char[0] = temp_d_char[0];
4112 d_char[1] = temp_d_char[1];
4113 d_char[2] = temp_d_char[2];
4114 auto_format = tmp_af;
4116 midscreen(scr_vert, point);
4121 unsigned char *init_name[3] = {
4122 "/usr/share/misc/init.ee",
4128 ee_init() /* check for init file and read it if it exists */
4131 unsigned char *string;
4132 unsigned char *str1;
4133 unsigned char *str2;
4138 string = getenv("HOME");
4141 str1 = home = malloc(strlen(string)+10);
4142 strcpy(home, string);
4143 strcat(home, "/.init.ee");
4144 init_name[1] = home;
4145 string = malloc(512);
4147 for (counter = 0; counter < 3; counter++)
4149 if (!(access(init_name[counter], 4)))
4151 init_file = fopen(init_name[counter], "r");
4152 while ((str2 = fgets(string, 512, init_file)) != NULL)
4154 str1 = str2 = string;
4155 while (*str2 != '\n')
4159 if (unique_test(string, init_strings) != 1)
4162 if (compare(str1, CASE, FALSE))
4164 else if (compare(str1, NOCASE, FALSE))
4166 else if (compare(str1, EXPAND, FALSE))
4168 else if (compare(str1, NOEXPAND, FALSE))
4169 expand_tabs = FALSE;
4170 else if (compare(str1, INFO, FALSE))
4172 else if (compare(str1, NOINFO, FALSE))
4173 info_window = FALSE;
4174 else if (compare(str1, MARGINS, FALSE))
4175 observ_margins = TRUE;
4176 else if (compare(str1, NOMARGINS, FALSE))
4177 observ_margins = FALSE;
4178 else if (compare(str1, AUTOFORMAT, FALSE))
4181 observ_margins = TRUE;
4183 else if (compare(str1, NOAUTOFORMAT, FALSE))
4184 auto_format = FALSE;
4185 else if (compare(str1, Echo, FALSE))
4187 str1 = next_word(str1);
4191 else if (compare(str1, PRINTCOMMAND, FALSE))
4193 str1 = next_word(str1);
4194 print_command = malloc(strlen(str1)+1);
4195 strcpy(print_command, str1);
4197 else if (compare(str1, RIGHTMARGIN, FALSE))
4199 str1 = next_word(str1);
4200 if ((*str1 >= '0') && (*str1 <= '9'))
4202 temp_int = atoi(str1);
4204 right_margin = temp_int;
4207 else if (compare(str1, HIGHLIGHT, FALSE))
4208 nohighlight = FALSE;
4209 else if (compare(str1, NOHIGHLIGHT, FALSE))
4211 else if (compare(str1, EIGHTBIT, FALSE))
4213 else if (compare(str1, NOEIGHTBIT, FALSE))
4218 else if (compare(str1, EMACS_string, FALSE))
4219 emacs_keys_mode = TRUE;
4220 else if (compare(str1, NOEMACS_string, FALSE))
4221 emacs_keys_mode = FALSE;
4222 else if (compare(str1, chinese_cmd, FALSE))
4227 else if (compare(str1, nochinese_cmd, FALSE))
4236 string = getenv("LANG");
4239 if (strcmp(string, "zh_TW.big5") == 0)
4248 | Save current configuration to .init.ee file in the current directory.
4255 FILE *old_init_file = NULL;
4256 char *file_name = ".init.ee";
4257 char *home_dir = "~/.init.ee";
4264 if (restrict_mode())
4269 option = menu_op(config_dump_menu);
4272 wmove(com_win, 0, 0);
4276 wprintw(com_win, conf_not_saved_msg);
4280 else if (option == 2)
4281 file_name = resolve_name(home_dir);
4284 | If a .init.ee file exists, move it to .init.ee.old.
4287 if (stat(file_name, &buf) != -1)
4289 sprintf(buffer, "%s.old", file_name);
4291 link(file_name, buffer);
4293 old_init_file = fopen(buffer, "r");
4296 init_file = fopen(file_name, "w");
4297 if (init_file == NULL)
4299 wprintw(com_win, conf_dump_err_msg);
4304 if (old_init_file != NULL)
4307 | Copy non-configuration info into new .init.ee file.
4309 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4311 length = strlen(string);
4312 string[length - 1] = '\0';
4314 if (unique_test(string, init_strings) == 1)
4316 if (compare(string, Echo, FALSE))
4318 fprintf(init_file, "%s\n", string);
4322 fprintf(init_file, "%s\n", string);
4325 fclose(old_init_file);
4328 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4329 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4330 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4331 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4332 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4333 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4334 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4335 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4336 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4337 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4338 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4342 wprintw(com_win, conf_dump_success_msg, file_name);
4345 if ((option == 2) && (file_name != home_dir))
4352 echo_string(string) /* echo the given string */
4359 while (*temp != '\0')
4366 else if (*temp == 't')
4368 else if (*temp == 'b')
4370 else if (*temp == 'r')
4372 else if (*temp == 'f')
4374 else if ((*temp == 'e') || (*temp == 'E'))
4375 putchar('\033'); /* escape */
4376 else if (*temp == '\\')
4378 else if (*temp == '\'')
4380 else if ((*temp >= '0') && (*temp <= '9'))
4383 while ((*temp >= '0') && (*temp <= '9'))
4385 Counter = (8 * Counter) + (*temp - '0');
4404 spell_op() /* check spelling of words in the editor */
4406 if (restrict_mode())
4410 top(); /* go to top of file */
4411 insert_line(FALSE); /* create two blank lines */
4414 command(shell_echo_msg);
4416 wmove(com_win, 0, 0);
4417 wprintw(com_win, spell_in_prog_msg);
4419 command("<>!spell"); /* send contents of buffer to command 'spell'
4420 and read the results back into the editor */
4426 char template[128], *name = NULL;
4430 if (restrict_mode())
4434 (void)sprintf(template, "/tmp/ee.XXXXXXXX");
4435 fd = mkstemp(template);
4437 wmove(com_win, 0, 0);
4438 wprintw(com_win, create_file_fail_msg, name);
4443 if (write_file(name, 0))
4445 sprintf(string, "ispell %s", name);
4456 first_word_len(test_line)
4457 struct text *test_line;
4462 if (test_line == NULL)
4465 pnt = test_line->line;
4466 if ((pnt == NULL) || (*pnt == '\0') ||
4467 (*pnt == '.') || (*pnt == '>'))
4470 if ((*pnt == ' ') || (*pnt == '\t'))
4472 pnt = next_word(pnt);
4479 while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
4484 while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
4493 Auto_Format() /* format the paragraph according to set margins */
4500 int tmp_d_line_length;
4501 int leave_loop = FALSE;
4505 unsigned char *line;
4506 unsigned char *tmp_srchstr;
4507 unsigned char *temp1, *temp2;
4508 unsigned char *temp_dword;
4509 unsigned char temp_d_char[3];
4510 unsigned char *tmp_d_line;
4513 temp_d_char[0] = d_char[0];
4514 temp_d_char[1] = d_char[1];
4515 temp_d_char[2] = d_char[2];
4518 | if observ_margins is not set, or the current line is blank,
4519 | do not format the current paragraph
4522 if ((!observ_margins) || (Blank_Line(curr_line)))
4526 | get current position in paragraph, so after formatting, the cursor
4527 | will be in the same relative position
4530 tmp_d_line = d_line;
4531 tmp_d_line_length = dlt_line->line_length;
4533 auto_format = FALSE;
4535 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
4537 temp_dword = d_word;
4538 temp_dwl = d_wrd_len;
4541 temp_case = case_sen;
4543 tmp_srchstr = srch_str;
4544 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4545 if ((*point == ' ') || (*point == '\t'))
4549 line = temp1 = point;
4550 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4560 while (!Blank_Line(curr_line->prev_line))
4564 while ((line != point) && (status))
4566 status = search(FALSE);
4571 | now get back to the start of the paragraph to start checking
4576 while (!Blank_Line(curr_line->prev_line))
4580 | Start going through lines, putting spaces at end of lines if they do
4581 | not already exist. Check line length, and move words to the next line
4582 | if they cross the margin. Then get words from the next line if they
4583 | will fit in before the margin.
4590 if (position != curr_line->line_length)
4604 | fill line if first word on next line will fit
4605 | in the line without crossing the margin
4608 while ((curr_line->next_line != NULL) &&
4609 ((word_len = first_word_len(curr_line->next_line)) > 0)
4610 && ((scr_pos + word_len) < right_margin))
4613 if ((*point == ' ') || (*point == '\t'))
4620 | We know this line was not blank before, so
4621 | make sure that it doesn't have one of the
4622 | leading characters that indicate the line
4623 | should not be modified.
4625 | We also know that this character should not
4626 | be left as the first character of this line.
4629 if ((Blank_Line(curr_line)) &&
4630 (curr_line->line[0] != '.') &&
4631 (curr_line->line[0] != '>'))
4640 | go to end of previous line
4646 | make sure there's a space at the end of the line
4659 | make sure line does not cross right margin
4662 while (right_margin <= scr_pos)
4668 if (Blank_Line(curr_line->next_line))
4672 if ((*point == ' ') || (*point == '\t'))
4682 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4692 | go back to begin of paragraph, put cursor back to original position
4697 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4701 | find word cursor was in
4705 while ((status) && (string_count > 0))
4707 status = search(FALSE);
4712 | offset the cursor to where it was before from the start of the word
4721 if ((string_count > 0) && (offset < 0))
4731 | reset flags and strings to what they were before formatting
4736 d_word = temp_dword;
4737 d_wrd_len = temp_dwl;
4738 case_sen = temp_case;
4740 srch_str = tmp_srchstr;
4741 d_char[0] = temp_d_char[0];
4742 d_char[1] = temp_d_char[1];
4743 d_char[2] = temp_d_char[2];
4745 dlt_line->line_length = tmp_d_line_length;
4746 d_line = tmp_d_line;
4749 midscreen(scr_vert, point);
4761 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4762 (expand_tabs ? ON : OFF));
4763 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4764 (case_sen ? ON : OFF));
4765 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4766 (observ_margins ? ON : OFF));
4767 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4768 (auto_format ? ON : OFF));
4769 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4770 (eightbit ? ON : OFF));
4771 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4772 (info_window ? ON : OFF));
4773 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4774 (emacs_keys_mode ? ON : OFF));
4775 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4777 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4778 (ee_chinese ? ON : OFF));
4780 ret_value = menu_op(modes_menu);
4785 expand_tabs = !expand_tabs;
4788 case_sen = !case_sen;
4791 observ_margins = !observ_margins;
4794 auto_format = !auto_format;
4796 observ_margins = TRUE;
4799 eightbit = !eightbit;
4804 nc_setattrib(A_NC_BIG5);
4806 nc_clearattrib(A_NC_BIG5);
4810 wnoutrefresh(text_win);
4816 create_info_window();
4819 emacs_keys_mode = !emacs_keys_mode;
4824 string = get_string(margin_prompt, TRUE);
4827 counter = atoi(string);
4829 right_margin = counter;
4834 ee_chinese = !ee_chinese;
4835 if (ee_chinese != FALSE)
4839 nc_setattrib(A_NC_BIG5);
4841 nc_clearattrib(A_NC_BIG5);
4849 while (ret_value != 0);
4853 is_in_string(string, substring) /* a strchr() look-alike for systems without
4855 char * string, *substring;
4859 for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
4861 for (full = string; (full != NULL) && (*full != '\0');
4872 | handle names of the form "~/file", "~user/file",
4873 | "$HOME/foo", "~/$FOO", etc.
4880 char long_buffer[1024];
4881 char short_buffer[128];
4889 struct passwd *user;
4896 user = (struct passwd *) getpwuid(index);
4901 slash = strchr(name, '/');
4905 user = (struct passwd *) getpwnam((name + 1));
4912 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4913 strcpy(buffer, user->pw_dir);
4914 strcat(buffer, slash);
4919 if (is_in_string(buffer, "$"))
4924 while ((*tmp != '\0') && (index < 1024))
4927 while ((*tmp != '\0') && (*tmp != '$') &&
4930 long_buffer[index] = *tmp;
4935 if ((*tmp == '$') && (index < 1024))
4940 if (*tmp == '{') /* } */ /* bracketed variable name */
4943 while ((*tmp != '\0') &&
4947 short_buffer[counter] = *tmp;
4956 while ((*tmp != '\0') &&
4961 short_buffer[counter] = *tmp;
4966 short_buffer[counter] = '\0';
4967 if ((slash = getenv(short_buffer)) != NULL)
4969 offset = strlen(slash);
4970 if ((offset + index) < 1024)
4971 strcpy(&long_buffer[index], slash);
4976 while ((start_of_var != tmp) && (index < 1024))
4978 long_buffer[index] = *start_of_var;
4989 long_buffer[index] = '\0';
4993 buffer = malloc(index + 1);
4994 strcpy(buffer, long_buffer);
5006 wmove(com_win, 0, 0);
5007 wprintw(com_win, restricted_msg);
5010 clear_com_win = TRUE;
5015 | The following routine tests the input string against the list of
5016 | strings, to determine if the string is a unique match with one of the
5021 unique_test(string, list)
5031 while (list[counter] != NULL)
5033 result = compare(string, list[counter], FALSE);
5043 | Get the catalog entry, and if it got it from the catalog,
5044 | make a copy, since the buffer will be overwritten by the
5045 | next call to catgets().
5049 catgetlocal(number, string)
5056 temp1 = catgets(catalog, 1, number, string);
5057 if (temp1 != string)
5059 temp2 = malloc(strlen(temp1) + 1);
5060 strcpy(temp2, temp1);
5065 #endif /* NO_CATGETS */
5068 | The following is to allow for using message catalogs which allow
5069 | the software to be 'localized', that is, to use different languages
5070 | all with the same binary. For more information, see your system
5071 | documentation, or the X/Open Internationalization Guide.
5079 setlocale(LC_ALL, "");
5081 catalog = catopen("ee", NL_CAT_LOCALE);
5082 #endif /* NO_CATGETS */
5084 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5085 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5086 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5087 mode_strings[3] = catgetlocal( 4, "margins observed ");
5088 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5089 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5090 mode_strings[6] = catgetlocal( 7, "info window ");
5091 mode_strings[8] = catgetlocal( 8, "right margin ");
5092 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5093 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5094 leave_menu[2].item_string = catgetlocal( 11, "no save");
5095 file_menu[0].item_string = catgetlocal( 12, "file menu");
5096 file_menu[1].item_string = catgetlocal( 13, "read a file");
5097 file_menu[2].item_string = catgetlocal( 14, "write a file");
5098 file_menu[3].item_string = catgetlocal( 15, "save file");
5099 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5100 search_menu[0].item_string = catgetlocal( 17, "search menu");
5101 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5102 search_menu[2].item_string = catgetlocal( 19, "search");
5103 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5104 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5105 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5106 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5107 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5108 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5109 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5110 main_menu[0].item_string = catgetlocal( 27, "main menu");
5111 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5112 main_menu[2].item_string = catgetlocal( 29, "help");
5113 main_menu[3].item_string = catgetlocal( 30, "file operations");
5114 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5115 main_menu[5].item_string = catgetlocal( 32, "settings");
5116 main_menu[6].item_string = catgetlocal( 33, "search");
5117 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5118 help_text[0] = catgetlocal( 35, "Control keys: ");
5119 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5120 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5121 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5122 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5123 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5124 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5125 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5126 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5127 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5128 help_text[10] = catgetlocal( 45, " ");
5129 help_text[11] = catgetlocal( 46, "Commands: ");
5130 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5131 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5132 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5133 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5134 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5135 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5136 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5137 help_text[19] = catgetlocal( 54, " ");
5138 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5139 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5140 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5141 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5142 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5143 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5144 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5145 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5146 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5147 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5148 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5149 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5150 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5151 no_file_string = catgetlocal( 68, "no file");
5152 ascii_code_str = catgetlocal( 69, "ascii code: ");
5153 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5154 command_str = catgetlocal( 71, "command: ");
5155 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5156 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5157 char_str = catgetlocal( 74, "character = %d");
5158 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5159 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5160 line_num_str = catgetlocal( 77, "line %d ");
5161 line_len_str = catgetlocal( 78, "length = %d");
5162 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5163 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5164 usage1 = catgetlocal( 81, " -i turn off info window\n");
5165 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5166 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5167 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5168 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5169 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5170 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5171 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5172 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5173 read_only_msg = catgetlocal( 90, ", read only");
5174 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5175 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5176 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5177 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5178 yes_char = catgetlocal( 95, "y");
5179 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5180 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5181 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5182 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5183 searching_msg = catgetlocal( 100, " ...searching");
5184 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5185 search_prompt_str = catgetlocal( 102, "search for: ");
5186 exec_err_msg = catgetlocal( 103, "could not exec %s\n");
5187 continue_msg = catgetlocal( 104, "press return to continue ");
5188 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5189 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5190 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5191 shell_prompt = catgetlocal( 108, "shell command: ");
5192 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5193 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5194 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5195 margin_prompt = catgetlocal( 112, "right margin is: ");
5196 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5197 ON = catgetlocal( 114, "ON");
5198 OFF = catgetlocal( 115, "OFF");
5199 HELP = catgetlocal( 116, "HELP");
5200 WRITE = catgetlocal( 117, "WRITE");
5201 READ = catgetlocal( 118, "READ");
5202 LINE = catgetlocal( 119, "LINE");
5203 FILE_str = catgetlocal( 120, "FILE");
5204 CHARACTER = catgetlocal( 121, "CHARACTER");
5205 REDRAW = catgetlocal( 122, "REDRAW");
5206 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5207 AUTHOR = catgetlocal( 124, "AUTHOR");
5208 VERSION = catgetlocal( 125, "VERSION");
5209 CASE = catgetlocal( 126, "CASE");
5210 NOCASE = catgetlocal( 127, "NOCASE");
5211 EXPAND = catgetlocal( 128, "EXPAND");
5212 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5213 Exit_string = catgetlocal( 130, "EXIT");
5214 QUIT_string = catgetlocal( 131, "QUIT");
5215 INFO = catgetlocal( 132, "INFO");
5216 NOINFO = catgetlocal( 133, "NOINFO");
5217 MARGINS = catgetlocal( 134, "MARGINS");
5218 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5219 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5220 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5221 Echo = catgetlocal( 138, "ECHO");
5222 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5223 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5224 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5225 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5226 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5227 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5231 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5232 emacs_help_text[0] = help_text[0];
5233 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5234 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
5235 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
5236 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5237 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5238 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5239 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5240 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5241 emacs_help_text[9] = help_text[9];
5242 emacs_help_text[10] = help_text[10];
5243 emacs_help_text[11] = help_text[11];
5244 emacs_help_text[12] = help_text[12];
5245 emacs_help_text[13] = help_text[13];
5246 emacs_help_text[14] = help_text[14];
5247 emacs_help_text[15] = help_text[15];
5248 emacs_help_text[16] = help_text[16];
5249 emacs_help_text[17] = help_text[17];
5250 emacs_help_text[18] = help_text[18];
5251 emacs_help_text[19] = help_text[19];
5252 emacs_help_text[20] = help_text[20];
5253 emacs_help_text[21] = help_text[21];
5254 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
5255 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
5256 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
5257 emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
5258 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5259 EMACS_string = catgetlocal( 159, "EMACS");
5260 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5261 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5262 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5263 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5264 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5265 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5266 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5267 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5268 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5269 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5270 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5271 more_above_str = catgetlocal( 181, "^^more^^");
5272 more_below_str = catgetlocal( 182, "VVmoreVV");
5273 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5274 chinese_cmd = catgetlocal( 184, "16BIT");
5275 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5278 commands[1] = WRITE;
5281 commands[4] = FILE_str;
5282 commands[5] = REDRAW;
5283 commands[6] = RESEQUENCE;
5284 commands[7] = AUTHOR;
5285 commands[8] = VERSION;
5287 commands[10] = NOCASE;
5288 commands[11] = EXPAND;
5289 commands[12] = NOEXPAND;
5290 commands[13] = Exit_string;
5291 commands[14] = QUIT_string;
5305 commands[28] = CHARACTER;
5306 commands[29] = chinese_cmd;
5307 commands[30] = nochinese_cmd;
5308 commands[31] = NULL;
5309 init_strings[0] = CASE;
5310 init_strings[1] = NOCASE;
5311 init_strings[2] = EXPAND;
5312 init_strings[3] = NOEXPAND;
5313 init_strings[4] = INFO;
5314 init_strings[5] = NOINFO;
5315 init_strings[6] = MARGINS;
5316 init_strings[7] = NOMARGINS;
5317 init_strings[8] = AUTOFORMAT;
5318 init_strings[9] = NOAUTOFORMAT;
5319 init_strings[10] = Echo;
5320 init_strings[11] = PRINTCOMMAND;
5321 init_strings[12] = RIGHTMARGIN;
5322 init_strings[13] = HIGHLIGHT;
5323 init_strings[14] = NOHIGHLIGHT;
5324 init_strings[15] = EIGHTBIT;
5325 init_strings[16] = NOEIGHTBIT;
5326 init_strings[17] = EMACS_string;
5327 init_strings[18] = NOEMACS_string;
5328 init_strings[19] = chinese_cmd;
5329 init_strings[20] = nochinese_cmd;
5330 init_strings[21] = NULL;
5333 | allocate space for strings here for settings menu
5336 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5338 modes_menu[counter].item_string = malloc(80);
5343 #endif /* NO_CATGETS */