4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
9 | Copyright (c) 2009, Hugh Mahon
10 | All rights reserved.
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions
16 | * Redistributions of source code must retain the above copyright
17 | notice, this list of conditions and the following disclaimer.
18 | * Redistributions in binary form must reproduce the above
19 | copyright notice, this list of conditions and the following
20 | disclaimer in the documentation and/or other materials provided
21 | with the distribution.
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | POSSIBILITY OF SUCH DAMAGE.
36 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
38 | This editor was purposely developed to be simple, both in
39 | interface and implementation. This editor was developed to
40 | address a specific audience: the user who is new to computers
43 | ee is not aimed at technical users; for that reason more
44 | complex features were intentionally left out. In addition,
45 | ee is intended to be compiled by people with little computer
46 | experience, which means that it needs to be small, relatively
47 | simple in implementation, and portable.
49 | This software and documentation contains
50 | proprietary information which is protected by
51 | copyright. All rights are reserved.
53 | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.104 2010/06/04 01:55:31 hugh Exp hugh $
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
60 char *ee_copyright_message =
61 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
63 #include "ee_version.h"
65 char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.104 $";
68 #include "new_curse.h"
78 #include <sys/types.h>
102 #include <nl_types.h>
106 #define catgetlocal(a, b) (b)
107 #endif /* NO_CATGETS */
110 #define SIGCHLD SIGCLD
114 #define max(a, b) (a > b ? a : b)
115 #define min(a, b) (a < b ? a : b)
118 | defines for type of data to show in info window
121 #define CONTROL_KEYS 1
125 unsigned char *line; /* line of characters */
126 int line_number; /* line number */
127 int line_length; /* actual number of characters in the line */
128 int max_length; /* maximum number of characters the line handles */
129 struct text *next_line; /* next line of text */
130 struct text *prev_line; /* previous line of text */
133 struct text *first_line; /* first line of current buffer */
134 struct text *dlt_line; /* structure for info on deleted line */
135 struct text *curr_line; /* current line cursor is on */
136 struct text *tmp_line; /* temporary line pointer */
137 struct text *srch_line; /* temporary pointer for search routine */
139 struct files { /* structure to store names of files to be edited*/
140 unsigned char *name; /* name of file */
141 struct files *next_name;
144 struct files *top_of_stack = NULL;
146 int d_wrd_len; /* length of deleted word */
147 int position; /* offset in bytes from begin of line */
148 int scr_pos; /* horizontal position */
149 int scr_vert; /* vertical position on screen */
150 int scr_horz; /* horizontal position on screen */
151 int absolute_lin; /* number of lines from top */
152 int tmp_vert, tmp_horz;
153 int input_file; /* indicate to read input file */
154 int recv_file; /* indicate reading a file */
155 int edit; /* continue executing while true */
156 int gold; /* 'gold' function key pressed */
157 int fildes; /* file descriptor */
158 int case_sen; /* case sensitive search flag */
159 int last_line; /* last line for text display */
160 int last_col; /* last column for text display */
161 int horiz_offset = 0; /* offset from left edge of text */
162 int clear_com_win; /* flag to indicate com_win needs clearing */
163 int text_changes = FALSE; /* indicate changes have been made to text */
164 int get_fd; /* file descriptor for reading a file */
165 int info_window = TRUE; /* flag to indicate if help window visible */
166 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
167 int expand_tabs = TRUE; /* flag for expanding tabs */
168 int right_margin = 0; /* the right margin */
169 int observ_margins = TRUE; /* flag for whether margins are observed */
171 int temp_stdin; /* temporary storage for stdin */
172 int temp_stdout; /* temp storage for stdout descriptor */
173 int temp_stderr; /* temp storage for stderr descriptor */
174 int pipe_out[2]; /* pipe file desc for output */
175 int pipe_in[2]; /* pipe file descriptors for input */
176 int out_pipe; /* flag that info is piped out */
177 int in_pipe; /* flag that info is piped in */
178 int formatted = FALSE; /* flag indicating paragraph formatted */
179 int auto_format = FALSE; /* flag for auto_format mode */
180 int restricted = FALSE; /* flag to indicate restricted mode */
181 int nohighlight = FALSE; /* turns off highlighting */
182 int eightbit = TRUE; /* eight bit character flag */
183 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
184 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
185 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
186 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
187 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
188 /* by checking for high bit in a byte the */
189 /* code recognizes a two-byte character */
192 unsigned char *point; /* points to current position in line */
193 unsigned char *srch_str; /* pointer for search string */
194 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
195 unsigned char *srch_1; /* pointer to start of suspect string */
196 unsigned char *srch_2; /* pointer to next character of string */
197 unsigned char *srch_3;
198 unsigned char *in_file_name = NULL; /* name of input file */
199 char *tmp_file; /* temporary file name */
200 unsigned char *d_char; /* deleted character */
201 unsigned char *d_word; /* deleted word */
202 unsigned char *d_line; /* deleted line */
203 char in_string[513]; /* buffer for reading a file */
204 unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
205 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
206 int in; /* input character */
208 FILE *temp_fp; /* temporary file pointer */
209 FILE *bit_bucket; /* file pointer to /dev/null */
212 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
213 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
214 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
222 #if defined(__STDC__) || defined(__cplusplus)
230 | The following structure allows menu items to be flexibly declared.
231 | The first item is the string describing the selection, the second
232 | is the address of the procedure to call when the item is selected,
233 | and the third is the argument for the procedure.
235 | For those systems with i18n, the string should be accompanied by a
236 | catalog number. The 'int *' should be replaced with 'void *' on
237 | systems with that type.
239 | The first menu item will be the title of the menu, with NULL
240 | parameters for the procedure and argument, followed by the menu items.
242 | If the procedure value is NULL, the menu item is displayed, but no
243 | procedure is called when the item is selected. The number of the
244 | item will be returned. If the third (argument) parameter is -1, no
245 | argument is given to the procedure when it is called.
248 struct menu_entries {
250 int (*procedure)P_((struct menu_entries *));
251 struct menu_entries *ptr_argument;
252 int (*iprocedure)P_((int));
253 void (*nprocedure)P_((void));
257 int main P_((int argc, char *argv[]));
258 unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
259 void insert P_((int character));
260 void delete P_((int disp));
261 void scanline P_((unsigned char *pos));
262 int tabshift P_((int temp_int));
263 int out_char P_((WINDOW *window, int character, int column));
264 int len_char P_((int character, int column));
265 void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
266 void insert_line P_((int disp));
267 struct text *txtalloc P_((void));
268 struct files *name_alloc P_((void));
269 unsigned char *next_word P_((unsigned char *string));
270 void prev_word P_((void));
271 void control P_((void));
272 void emacs_control P_((void));
273 void bottom P_((void));
275 void nextline P_((void));
276 void prevline P_((void));
277 void left P_((int disp));
278 void right P_((int disp));
279 void find_pos P_((void));
281 void down P_((void));
282 void function_key P_((void));
283 void print_buffer P_((void));
284 void command_prompt P_((void));
285 void command P_((char *cmd_str1));
286 int scan P_((char *line, int offset, int column));
287 char *get_string P_((char *prompt, int advance));
288 int compare P_((char *string1, char *string2, int sensitive));
289 void goto_line P_((char *cmd_str));
290 void midscreen P_((int line, unsigned char *pnt));
291 void get_options P_((int numargs, char *arguments[]));
292 void check_fp P_((void));
293 void get_file P_((char *file_name));
294 void get_line P_((int length, unsigned char *in_string, int *append));
295 void draw_screen P_((void));
296 void finish P_((void));
297 int quit P_((int noverify));
298 void edit_abort P_((int arg));
299 void delete_text P_((void));
300 int write_file P_((char *file_name, int warn_if_exists));
301 int search P_((int display_message));
302 void search_prompt P_((void));
303 void del_char P_((void));
304 void undel_char P_((void));
305 void del_word P_((void));
306 void undel_word P_((void));
307 void del_line P_((void));
308 void undel_line P_((void));
309 void adv_word P_((void));
310 void move_rel P_((int direction, int lines));
313 void adv_line P_((void));
314 void sh_command P_((char *string));
315 void set_up_term P_((void));
316 void resize_check P_((void));
317 int menu_op P_((struct menu_entries *));
318 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));
319 void help P_((void));
320 void paint_info_win P_((void));
321 void no_info_window P_((void));
322 void create_info_window P_((void));
323 int file_op P_((int arg));
324 void shell_op P_((void));
325 void leave_op P_((void));
326 void redraw P_((void));
327 int Blank_Line P_((struct text *test_line));
328 void Format P_((void));
329 void ee_init P_((void));
330 void dump_ee_conf P_((void));
331 void echo_string P_((char *string));
332 void spell_op P_((void));
333 void ispell_op P_((void));
334 int first_word_len P_((struct text *test_line));
335 void Auto_Format P_((void));
336 void modes_op P_((void));
337 char *is_in_string P_((char *string, char *substring));
338 char *resolve_name P_((char *name));
339 int restrict_mode P_((void));
340 int unique_test P_((char *string, char *list[]));
341 void strings_init P_((void));
345 | allocate space here for the strings that will be in the menu
348 struct menu_entries modes_menu[] = {
349 {"", NULL, NULL, NULL, NULL, 0}, /* title */
350 {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */
351 {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/
352 {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */
353 {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */
354 {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/
355 {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */
356 {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/
357 {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */
358 {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */
359 {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
360 {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */
363 char *mode_strings[11];
365 #define NUM_MODES_ITEMS 10
367 struct menu_entries config_dump_menu[] = {
368 {"", NULL, NULL, NULL, NULL, 0},
369 {"", NULL, NULL, NULL, NULL, -1},
370 {"", NULL, NULL, NULL, NULL, -1},
371 {NULL, NULL, NULL, NULL, NULL, -1}
374 struct menu_entries leave_menu[] = {
375 {"", NULL, NULL, NULL, NULL, -1},
376 {"", NULL, NULL, NULL, finish, -1},
377 {"", NULL, NULL, quit, NULL, TRUE},
378 {NULL, NULL, NULL, NULL, NULL, -1}
385 struct menu_entries file_menu[] = {
386 {"", NULL, NULL, NULL, NULL, -1},
387 {"", NULL, NULL, file_op, NULL, READ_FILE},
388 {"", NULL, NULL, file_op, NULL, WRITE_FILE},
389 {"", NULL, NULL, file_op, NULL, SAVE_FILE},
390 {"", NULL, NULL, NULL, print_buffer, -1},
391 {NULL, NULL, NULL, NULL, NULL, -1}
394 struct menu_entries search_menu[] = {
395 {"", NULL, NULL, NULL, NULL, 0},
396 {"", NULL, NULL, NULL, search_prompt, -1},
397 {"", NULL, NULL, search, NULL, TRUE},
398 {NULL, NULL, NULL, NULL, NULL, -1}
401 struct menu_entries spell_menu[] = {
402 {"", NULL, NULL, NULL, NULL, -1},
403 {"", NULL, NULL, NULL, spell_op, -1},
404 {"", NULL, NULL, NULL, ispell_op, -1},
405 {NULL, NULL, NULL, NULL, NULL, -1}
408 struct menu_entries misc_menu[] = {
409 {"", NULL, NULL, NULL, NULL, -1},
410 {"", NULL, NULL, NULL, Format, -1},
411 {"", NULL, NULL, NULL, shell_op, -1},
412 {"", menu_op, spell_menu, NULL, NULL, -1},
413 {NULL, NULL, NULL, NULL, NULL, -1}
416 struct menu_entries main_menu[] = {
417 {"", NULL, NULL, NULL, NULL, -1},
418 {"", NULL, NULL, NULL, leave_op, -1},
419 {"", NULL, NULL, NULL, help, -1},
420 {"", menu_op, file_menu, NULL, NULL, -1},
421 {"", NULL, NULL, NULL, redraw, -1},
422 {"", NULL, NULL, NULL, modes_op, -1},
423 {"", menu_op, search_menu, NULL, NULL, -1},
424 {"", menu_op, misc_menu, NULL, NULL, -1},
425 {NULL, NULL, NULL, NULL, NULL, -1}
429 char *control_keys[5];
431 char *emacs_help_text[22];
432 char *emacs_control_keys[5];
434 char *command_strings[5];
436 char *init_strings[22];
440 #define max_alpha_char 36
443 | Declarations for strings for localization
446 char *com_win_message; /* to be shown in com_win if no info window */
447 char *no_file_string;
448 char *ascii_code_str;
449 char *printer_msg_str;
451 char *file_write_prompt_str;
452 char *file_read_prompt_str;
455 char *non_unique_cmd_msg;
458 char *current_file_str;
464 char *file_is_dir_msg;
468 char *file_read_fin_msg;
469 char *reading_file_msg;
471 char *file_read_lines_msg;
472 char *save_file_name_prompt;
473 char *file_not_saved_msg;
474 char *changes_made_prompt;
476 char *file_exists_prompt;
477 char *create_file_fail_msg;
478 char *writing_file_msg;
479 char *file_written_msg;
481 char *str_not_found_msg;
482 char *search_prompt_str;
485 char *menu_cancel_msg;
486 char *menu_size_err_msg;
487 char *press_any_key_msg;
489 char *formatting_msg;
490 char *shell_echo_msg;
491 char *spell_in_prog_msg;
493 char *restricted_msg;
526 char *NOEMACS_string;
527 char *conf_dump_err_msg;
528 char *conf_dump_success_msg;
529 char *conf_not_saved_msg;
530 char *ree_no_file_msg;
532 char *menu_too_lrg_msg;
533 char *more_above_str, *more_below_str;
534 char *separator = "===============================================================================";
536 char *chinese_cmd, *nochinese_cmd;
540 extern char *malloc();
541 extern char *realloc();
542 extern char *getenv();
543 FILE *fopen(); /* declaration for open function */
544 #endif /* HAS_STDLIB */
545 #endif /* __STDC__ */
548 main(argc, argv) /* beginning of main program */
554 for (counter = 1; counter < 24; counter++)
555 signal(counter, SIG_IGN);
557 /* Always read from (and write to) a terminal. */
558 if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
560 "ee's standard input and output must be a terminal\n");
564 signal(SIGCHLD, SIG_DFL);
565 signal(SIGSEGV, SIG_DFL);
566 signal(SIGINT, edit_abort);
567 d_char = malloc(3); /* provide a buffer for multi-byte chars */
568 d_word = malloc(150);
571 dlt_line = txtalloc();
572 dlt_line->line = d_line;
573 dlt_line->line_length = 0;
574 curr_line = first_line = txtalloc();
575 curr_line->line = point = malloc(10);
576 curr_line->line_length = 1;
577 curr_line->max_length = 10;
578 curr_line->prev_line = NULL;
579 curr_line->next_line = NULL;
580 curr_line->line_number = 1;
588 bit_bucket = fopen("/dev/null", "w");
590 gold = case_sen = FALSE;
595 get_options(argc, argv);
597 if (right_margin == 0)
598 right_margin = COLS - 1;
599 if (top_of_stack == NULL)
603 wmove(com_win, 0, 0);
605 wprintw(com_win, ree_no_file_msg);
609 wprintw(com_win, no_file_string);
615 clear_com_win = TRUE;
622 | display line and column information
628 wmove(info_win, 5, 0);
629 wprintw(info_win, separator);
630 wmove(info_win, 5, 5);
631 wprintw(info_win, "line %d col %d lines from top %d ",
632 curr_line->line_number, scr_horz, absolute_lin);
638 in = wgetch(text_win);
640 exit(0); /* without this exit ee will go into an
641 infinite loop if the network
648 clear_com_win = FALSE;
649 wmove(com_win, 0, 0);
653 wprintw(com_win, "%s", com_win_message);
660 else if ((in == '\10') || (in == 127))
662 in = 8; /* make sure key is set to backspace */
665 else if ((in > 31) || (in == 9))
667 else if ((in >= 0) && (in <= 31))
679 resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
680 int factor; /* resize factor */
681 struct text *rline; /* position in line */
684 unsigned char *rpoint;
687 rline->max_length += factor;
688 rpoint = rline->line = realloc(rline->line, rline->max_length );
689 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
695 insert(character) /* insert character into line */
696 int character; /* new character */
700 unsigned char *temp; /* temporary pointer */
701 unsigned char *temp2; /* temporary pointer */
703 if ((character == '\011') && (expand_tabs))
705 counter = len_char('\011', scr_horz);
706 for (; counter > 0; counter--)
713 if ((curr_line->max_length - curr_line->line_length) < 5)
714 point = resiz_line(10, curr_line, position);
715 curr_line->line_length++;
718 while (counter < curr_line->line_length) /* find end of line */
723 temp++; /* increase length of line by one */
727 *temp= *temp2; /* shift characters over by one */
730 *point = character; /* insert new character */
732 if (!isprint((unsigned char)character)) /* check for TAB character*/
734 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
740 waddch(text_win, (unsigned char)character);
741 scr_pos = ++scr_horz;
746 if ((observ_margins) && (right_margin < scr_pos))
749 while (scr_pos > right_margin)
753 while (position < counter)
760 for (value = 0; value < counter; value++)
765 if ((scr_horz - horiz_offset) > last_col)
768 midscreen(scr_vert, point);
771 if ((auto_format) && (character == ' ') && (!formatted))
773 else if ((character != ' ') && (character != '\t'))
776 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
780 delete(disp) /* delete character */
784 unsigned char *temp2;
785 struct text *temp_buff;
790 if (point != curr_line->line) /* if not at beginning of line */
794 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
800 position -= del_width;
802 curr_line->line_length -= del_width;
803 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
806 scr_horz -= del_width;
811 *d_char = *point; /* save deleted character */
815 d_char[1] = *(point + 1);
817 d_char[del_width] = '\0';
819 while (temp_pos <= curr_line->line_length)
826 if ((scr_horz < horiz_offset) && (horiz_offset > 0))
829 midscreen(scr_vert, point);
832 else if (curr_line->prev_line != NULL)
835 left(disp); /* go to previous line */
836 temp_buff = curr_line->next_line;
837 point = resiz_line(temp_buff->line_length, curr_line, position);
838 if (temp_buff->next_line != NULL)
839 temp_buff->next_line->prev_line = curr_line;
840 curr_line->next_line = temp_buff->next_line;
841 temp2 = temp_buff->line;
849 while (temp_pos < temp_buff->line_length)
851 curr_line->line_length++;
858 free(temp_buff->line);
860 temp_buff = curr_line;
861 temp_vert = scr_vert;
863 if (scr_vert < last_line)
865 wmove(text_win, scr_vert + 1, 0);
868 while ((temp_buff != NULL) && (temp_vert < last_line))
870 temp_buff = temp_buff->next_line;
873 if ((temp_vert == last_line) && (temp_buff != NULL))
875 tp = temp_buff->line;
876 wmove(text_win, last_line,0);
878 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
879 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
882 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
887 scanline(pos) /* find the proper horizontal position for the pointer */
893 ptr = curr_line->line;
900 temp += tabshift(temp);
901 else if ((*ptr >= 10) && (*ptr <= 31))
903 else if ((*ptr >= 32) && (*ptr < 127))
905 else if (*ptr == 127)
914 if ((scr_horz - horiz_offset) > last_col)
916 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
917 midscreen(scr_vert, point);
919 else if (scr_horz < horiz_offset)
921 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
922 midscreen(scr_vert, point);
927 tabshift(temp_int) /* give the number of spaces to shift */
932 leftover = ((temp_int + 1) % 8);
936 return (9 - leftover);
940 out_char(window, character, column) /* output non-printing character */
949 if (character == TAB)
951 i1 = tabshift(column);
953 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
959 else if ((character >= '\0') && (character < ' '))
961 string = table[(int) character];
963 else if ((character < 0) || (character >= 127))
965 if (character == 127)
969 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
974 waddch(window, (unsigned char)character );
980 waddch(window, (unsigned char)character);
983 for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
984 waddch(window, (unsigned char)string[i2]);
985 return(strlen(string));
989 len_char(character, column) /* return the length of the character */
991 int column; /* the column must be known to provide spacing for tabs */
995 if (character == '\t')
996 length = tabshift(column);
997 else if ((character >= 0) && (character < 32))
999 else if ((character >= 32) && (character <= 126))
1001 else if (character == 127)
1003 else if (((character > 126) || (character < 0)) && (!eightbit))
1012 draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
1013 int vertical; /* current vertical position on screen */
1014 int horiz; /* current horizontal position on screen */
1015 unsigned char *ptr; /* pointer to line */
1016 int t_pos; /* current position (offset in bytes) from bol */
1017 int length; /* length (in bytes) of line */
1019 int d; /* partial length of special or tab char to display */
1020 unsigned char *temp; /* temporary pointer to position in line */
1021 int abs_column; /* offset in screen units from begin of line */
1022 int column; /* horizontal position on screen */
1023 int row; /* vertical position on screen */
1024 int posit; /* temporary position indicator within line */
1027 column = horiz - horiz_offset;
1034 wmove(text_win, row, 0);
1035 wclrtoeol(text_win);
1039 d = len_char(*temp, abs_column);
1045 wmove(text_win, row, column);
1046 wclrtoeol(text_win);
1047 while ((posit < length) && (column <= last_col))
1049 if (!isprint(*temp))
1051 column += len_char(*temp, abs_column);
1052 abs_column += out_char(text_win, *temp, abs_column);
1058 waddch(text_win, *temp);
1063 if (column < last_col)
1064 wclrtoeol(text_win);
1065 wmove(text_win, vertical, (horiz - horiz_offset));
1069 insert_line(disp) /* insert new line */
1074 unsigned char *temp;
1075 unsigned char *extra;
1076 struct text *temp_nod;
1078 text_changes = TRUE;
1079 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1080 wclrtoeol(text_win);
1081 temp_nod= txtalloc();
1082 temp_nod->line = extra= malloc(10);
1083 temp_nod->line_length = 1;
1084 temp_nod->max_length = 10;
1085 temp_nod->line_number = curr_line->line_number + 1;
1086 temp_nod->next_line = curr_line->next_line;
1087 if (temp_nod->next_line != NULL)
1088 temp_nod->next_line->prev_line = temp_nod;
1089 temp_nod->prev_line = curr_line;
1090 curr_line->next_line = temp_nod;
1091 temp_pos2 = position;
1093 if (temp_pos2 < curr_line->line_length)
1096 while (temp_pos2 < curr_line->line_length)
1098 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1099 extra = resiz_line(10, temp_nod, temp_pos);
1100 temp_nod->line_length++;
1109 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1110 curr_line->line_length = 1 + temp - curr_line->line;
1112 curr_line->line_length = position;
1114 curr_line = temp_nod;
1117 point= curr_line->line;
1120 if (scr_vert < last_line)
1123 wclrtoeol(text_win);
1124 wmove(text_win, scr_vert, 0);
1125 winsertln(text_win);
1129 wmove(text_win, 0,0);
1130 wdeleteln(text_win);
1131 wmove(text_win, last_line,0);
1132 wclrtobot(text_win);
1134 scr_pos = scr_horz = 0;
1138 midscreen(scr_vert, point);
1140 draw_line(scr_vert, scr_horz, point, position,
1141 curr_line->line_length);
1145 struct text *txtalloc() /* allocate space for line structure */
1147 return((struct text *) malloc(sizeof( struct text)));
1150 struct files *name_alloc() /* allocate space for file name list node */
1152 return((struct files *) malloc(sizeof( struct files)));
1155 unsigned char *next_word(string) /* move to next word in string */
1156 unsigned char *string;
1158 while ((*string != '\0') && ((*string != 32) && (*string != 9)))
1160 while ((*string != '\0') && ((*string == 32) || (*string == 9)))
1166 prev_word() /* move to start of previous word in text */
1170 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1171 { /* if at the start of a word */
1172 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1175 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1177 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1179 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1187 control() /* use control for commands */
1191 if (in == 1) /* control a */
1193 string = get_string(ascii_code_str, TRUE);
1194 if (*string != '\0')
1197 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1202 else if (in == 2) /* control b */
1204 else if (in == 3) /* control c */
1208 else if (in == 4) /* control d */
1210 else if (in == 5) /* control e */
1212 else if (in == 6) /* control f */
1214 else if (in == 7) /* control g */
1216 else if (in == 8) /* control h */
1218 else if (in == 9) /* control i */
1220 else if (in == 10) /* control j */
1222 else if (in == 11) /* control k */
1224 else if (in == 12) /* control l */
1226 else if (in == 13) /* control m */
1228 else if (in == 14) /* control n */
1229 move_rel('d', max(5, (last_line - 5)));
1230 else if (in == 15) /* control o */
1232 else if (in == 16) /* control p */
1233 move_rel('u', max(5, (last_line - 5)));
1234 else if (in == 17) /* control q */
1236 else if (in == 18) /* control r */
1238 else if (in == 19) /* control s */
1240 else if (in == 20) /* control t */
1242 else if (in == 21) /* control u */
1244 else if (in == 22) /* control v */
1246 else if (in == 23) /* control w */
1248 else if (in == 24) /* control x */
1250 else if (in == 25) /* control y */
1252 else if (in == 26) /* control z */
1254 else if (in == 27) /* control [ (escape) */
1261 | Emacs control-key bindings
1269 if (in == 1) /* control a */
1271 else if (in == 2) /* control b */
1273 else if (in == 3) /* control c */
1277 else if (in == 4) /* control d */
1279 else if (in == 5) /* control e */
1281 else if (in == 6) /* control f */
1283 else if (in == 7) /* control g */
1284 move_rel('u', max(5, (last_line - 5)));
1285 else if (in == 8) /* control h */
1287 else if (in == 9) /* control i */
1289 else if (in == 10) /* control j */
1291 else if (in == 11) /* control k */
1293 else if (in == 12) /* control l */
1295 else if (in == 13) /* control m */
1297 else if (in == 14) /* control n */
1299 else if (in == 15) /* control o */
1301 string = get_string(ascii_code_str, TRUE);
1302 if (*string != '\0')
1305 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1310 else if (in == 16) /* control p */
1312 else if (in == 17) /* control q */
1314 else if (in == 18) /* control r */
1316 else if (in == 19) /* control s */
1318 else if (in == 20) /* control t */
1320 else if (in == 21) /* control u */
1322 else if (in == 22) /* control v */
1323 move_rel('d', max(5, (last_line - 5)));
1324 else if (in == 23) /* control w */
1326 else if (in == 24) /* control x */
1328 else if (in == 25) /* control y */
1330 else if (in == 26) /* control z */
1332 else if (in == 27) /* control [ (escape) */
1339 bottom() /* go to bottom of file */
1341 while (curr_line->next_line != NULL)
1343 curr_line = curr_line->next_line;
1346 point = curr_line->line;
1350 midscreen(last_line, point);
1355 top() /* go to top of file */
1357 while (curr_line->prev_line != NULL)
1359 curr_line = curr_line->prev_line;
1362 point = curr_line->line;
1366 midscreen(0, point);
1371 nextline() /* move pointers to start of next line */
1373 curr_line = curr_line->next_line;
1375 point = curr_line->line;
1377 if (scr_vert == last_line)
1379 wmove(text_win, 0,0);
1380 wdeleteln(text_win);
1381 wmove(text_win, last_line,0);
1382 wclrtobot(text_win);
1383 draw_line(last_line,0,point,1,curr_line->line_length);
1390 prevline() /* move pointers to start of previous line*/
1392 curr_line = curr_line->prev_line;
1394 point = curr_line->line;
1398 winsertln(text_win);
1399 draw_line(0,0,point,1,curr_line->line_length);
1403 while (position < curr_line->line_length)
1411 left(disp) /* move left one character */
1414 if (point != curr_line->line) /* if not at begin of line */
1416 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1424 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1427 else if (curr_line->prev_line != NULL)
1432 curr_line = curr_line->prev_line;
1433 point = curr_line->line + curr_line->line_length;
1434 position = curr_line->line_length;
1441 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1446 right(disp) /* move right one character */
1449 if (position < curr_line->line_length)
1451 if ((ee_chinese) && (*point > 127) &&
1452 ((curr_line->line_length - position) >= 2))
1460 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1463 else if (curr_line->next_line != NULL)
1468 curr_line = curr_line->next_line;
1469 point = curr_line->line;
1474 scr_pos = scr_horz = 0;
1478 midscreen(scr_vert, point);
1480 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1486 find_pos() /* move to the same column as on other line */
1490 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1493 scr_horz += tabshift(scr_horz);
1494 else if (*point < ' ')
1496 else if ((ee_chinese) && (*point > 127) &&
1497 ((curr_line->line_length - position) >= 2))
1508 if ((scr_horz - horiz_offset) > last_col)
1510 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1511 midscreen(scr_vert, point);
1513 else if (scr_horz < horiz_offset)
1515 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1516 midscreen(scr_vert, point);
1518 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1522 up() /* move up one line */
1524 if (curr_line->prev_line != NULL)
1527 point = curr_line->line;
1533 down() /* move down one line */
1535 if (curr_line->next_line != NULL)
1543 function_key() /* process function key */
1547 else if (in == KEY_RIGHT)
1549 else if (in == KEY_HOME)
1551 else if (in == KEY_END)
1553 else if (in == KEY_UP)
1555 else if (in == KEY_DOWN)
1557 else if (in == KEY_NPAGE)
1558 move_rel('d', max( 5, (last_line - 5)));
1559 else if (in == KEY_PPAGE)
1560 move_rel('u', max(5, (last_line - 5)));
1561 else if (in == KEY_DL)
1563 else if (in == KEY_DC)
1565 else if (in == KEY_BACKSPACE)
1567 else if (in == KEY_IL)
1568 { /* insert a line before current line */
1572 else if (in == KEY_F(1))
1574 else if (in == KEY_F(2))
1584 else if (in == KEY_F(3))
1594 else if (in == KEY_F(4))
1600 midscreen(scr_vert, point);
1605 else if (in == KEY_F(5))
1615 else if (in == KEY_F(6))
1625 else if (in == KEY_F(7))
1635 else if (in == KEY_F(8))
1652 sprintf(buffer, ">!%s", print_command);
1653 wmove(com_win, 0, 0);
1655 wprintw(com_win, printer_msg_str, print_command);
1666 info_type = COMMANDS;
1668 cmd_str = get_string(command_str, TRUE);
1669 if ((result = unique_test(cmd_str, commands)) != 1)
1672 wmove(com_win, 0, 0);
1674 wprintw(com_win, unkn_cmd_str, cmd_str);
1676 wprintw(com_win, non_unique_cmd_msg);
1680 info_type = CONTROL_KEYS;
1683 if (cmd_str != NULL)
1689 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1690 info_type = CONTROL_KEYS;
1692 if (cmd_str != NULL)
1697 command(cmd_str1) /* process commands from keyboard */
1700 char *cmd_str2 = NULL;
1701 char *cmd_str = cmd_str1;
1703 clear_com_win = TRUE;
1704 if (compare(cmd_str, HELP, FALSE))
1706 else if (compare(cmd_str, WRITE, FALSE))
1708 if (restrict_mode())
1712 cmd_str = next_word(cmd_str);
1713 if (*cmd_str == '\0')
1715 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1717 tmp_file = resolve_name(cmd_str);
1718 write_file(tmp_file, 1);
1719 if (tmp_file != cmd_str)
1722 else if (compare(cmd_str, READ, FALSE))
1724 if (restrict_mode())
1728 cmd_str = next_word(cmd_str);
1729 if (*cmd_str == '\0')
1731 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1735 tmp_file = resolve_name(cmd_str);
1737 if (tmp_file != cmd_str)
1740 else if (compare(cmd_str, LINE, FALSE))
1742 wmove(com_win, 0, 0);
1744 wprintw(com_win, line_num_str, curr_line->line_number);
1745 wprintw(com_win, line_len_str, curr_line->line_length);
1747 else if (compare(cmd_str, FILE_str, FALSE))
1749 wmove(com_win, 0, 0);
1751 if (in_file_name == NULL)
1752 wprintw(com_win, no_file_string);
1754 wprintw(com_win, current_file_str, in_file_name);
1756 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1758 else if (compare(cmd_str, CHARACTER, FALSE))
1760 wmove(com_win, 0, 0);
1762 wprintw(com_win, char_str, *point);
1764 else if (compare(cmd_str, REDRAW, FALSE))
1766 else if (compare(cmd_str, RESEQUENCE, FALSE))
1768 tmp_line = first_line->next_line;
1769 while (tmp_line != NULL)
1771 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1772 tmp_line = tmp_line->next_line;
1775 else if (compare(cmd_str, AUTHOR, FALSE))
1777 wmove(com_win, 0, 0);
1779 wprintw(com_win, "written by Hugh Mahon");
1781 else if (compare(cmd_str, VERSION, FALSE))
1783 wmove(com_win, 0, 0);
1785 wprintw(com_win, "%s", version);
1787 else if (compare(cmd_str, CASE, FALSE))
1789 else if (compare(cmd_str, NOCASE, FALSE))
1791 else if (compare(cmd_str, EXPAND, FALSE))
1793 else if (compare(cmd_str, NOEXPAND, FALSE))
1794 expand_tabs = FALSE;
1795 else if (compare(cmd_str, Exit_string, FALSE))
1797 else if (compare(cmd_str, chinese_cmd, FALSE))
1801 nc_setattrib(A_NC_BIG5);
1804 else if (compare(cmd_str, nochinese_cmd, FALSE))
1808 nc_clearattrib(A_NC_BIG5);
1811 else if (compare(cmd_str, QUIT_string, FALSE))
1813 else if (*cmd_str == '!')
1816 if ((*cmd_str == ' ') || (*cmd_str == 9))
1817 cmd_str = next_word(cmd_str);
1818 sh_command(cmd_str);
1820 else if ((*cmd_str == '<') && (!in_pipe))
1825 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1826 cmd_str = next_word(cmd_str);
1831 else if ((*cmd_str == '>') && (!out_pipe))
1835 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1836 cmd_str = next_word(cmd_str);
1842 wmove(com_win, 0, 0);
1844 wprintw(com_win, unkn_cmd_str, cmd_str);
1846 if (cmd_str2 != NULL)
1851 scan(line, offset, column) /* determine horizontal position for get_string */
1866 j += len_char(*stemp, j);
1873 get_string(prompt, advance) /* read string from input on command line */
1874 char *prompt; /* string containing user prompt message */
1875 int advance; /* if true, skip leading spaces and tabs */
1882 int g_horz, g_position, g_pos;
1885 g_point = tmp_string = malloc(512);
1888 waddstr(com_win, prompt);
1890 nam_str = tmp_string;
1891 clear_com_win = TRUE;
1892 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1897 in = wgetch(com_win);
1900 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1904 g_horz = scan(g_point, g_pos, g_position);
1905 tmp_int = tmp_int - g_horz;
1906 for (; 0 < tmp_int; tmp_int--)
1908 if ((g_horz+tmp_int) < (last_col - 1))
1910 waddch(com_win, '\010');
1911 waddch(com_win, ' ');
1912 waddch(com_win, '\010');
1917 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1919 if (in == '\026') /* control-v, accept next character verbatim */
1920 { /* allows entry of ^m, ^j, and ^h */
1922 in = wgetch(com_win);
1928 if (!isprint((unsigned char)in) && (g_horz < (last_col - 1)))
1929 g_horz += out_char(com_win, in, g_horz);
1933 if (g_horz < (last_col - 1))
1934 waddch(com_win, (unsigned char)in);
1941 } while ((in != '\n') && (in != '\r'));
1943 nam_str = tmp_string;
1944 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1945 nam_str = next_word(nam_str);
1946 string = malloc(strlen(nam_str) + 1);
1947 strcpy(string, nam_str);
1954 compare(string1, string2, sensitive) /* compare two strings */
1967 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
1974 if (*strng1 != *strng2)
1979 if (toupper((unsigned char)*strng1) != toupper((unsigned char)*strng2))
1984 if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
1998 char direction = '\0';
1999 struct text *t_line;
2003 while ((*ptr >='0') && (*ptr <= '9'))
2005 i= i * 10 + (*ptr - '0');
2011 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
2014 t_line = t_line->prev_line;
2017 while ((t_line->line_number < number) && (t_line->next_line != NULL))
2021 t_line = t_line->next_line;
2023 if ((i < 30) && (i > 0))
2025 move_rel(direction, i);
2029 if (direction != 'd')
2038 point = curr_line->line;
2040 midscreen((last_line / 2), point);
2043 wmove(com_win, 0, 0);
2045 wprintw(com_win, line_num_str, curr_line->line_number);
2046 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2050 midscreen(line, pnt) /* put current line in middle of screen */
2054 struct text *mid_line;
2057 line = min(line, last_line);
2058 mid_line = curr_line;
2059 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2060 curr_line = curr_line->prev_line;
2061 scr_vert = scr_horz = 0;
2062 wmove(text_win, 0, 0);
2065 curr_line = mid_line;
2067 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2071 get_options(numargs, arguments) /* get arguments from command line */
2077 struct files *temp_names = NULL;
2080 int no_more_opts = FALSE;
2083 | see if editor was invoked as 'ree' (restricted mode)
2086 if (!(name = strrchr(arguments[0], '/')))
2087 name = arguments[0];
2090 if (!strcmp(name, "ree"))
2093 top_of_stack = NULL;
2097 while ((count < numargs)&& (!no_more_opts))
2099 buff = arguments[count];
2100 if (!strcmp("-i", buff))
2102 info_window = FALSE;
2104 else if (!strcmp("-e", buff))
2106 expand_tabs = FALSE;
2108 else if (!strcmp("-h", buff))
2112 else if (!strcmp("-?", buff))
2114 fprintf(stderr, usage0, arguments[0]);
2115 fputs(usage1, stderr);
2116 fputs(usage2, stderr);
2117 fputs(usage3, stderr);
2118 fputs(usage4, stderr);
2121 else if ((*buff == '+') && (start_at_line == NULL))
2124 start_at_line = buff;
2126 else if (!(strcmp("--", buff)))
2127 no_more_opts = TRUE;
2131 no_more_opts = TRUE;
2135 while (count < numargs)
2137 buff = arguments[count];
2138 if (top_of_stack == NULL)
2140 temp_names = top_of_stack = name_alloc();
2144 temp_names->next_name = name_alloc();
2145 temp_names = temp_names->next_name;
2147 ptr = temp_names->name = malloc(strlen(buff) + 1);
2148 while (*buff != '\0')
2155 temp_names->next_name = NULL;
2163 check_fp() /* open or close files according to flags */
2169 clear_com_win = TRUE;
2170 tmp_vert = scr_vert;
2171 tmp_horz = scr_horz;
2172 tmp_line = curr_line;
2175 in_file_name = tmp_file = top_of_stack->name;
2176 top_of_stack = top_of_stack->next_name;
2178 temp = stat(tmp_file, &buf);
2179 buf.st_mode &= ~07777;
2180 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2182 wprintw(com_win, file_is_dir_msg, tmp_file);
2192 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2194 wmove(com_win, 0, 0);
2197 wprintw(com_win, new_file_msg, tmp_file);
2199 wprintw(com_win, cant_open_msg, tmp_file);
2201 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2211 line_num = curr_line->line_number;
2212 scr_vert = tmp_vert;
2213 scr_horz = tmp_horz;
2215 curr_line= first_line;
2217 curr_line = tmp_line;
2218 point = curr_line->line;
2223 if (start_at_line != NULL)
2225 line_num = atoi(start_at_line) - 1;
2226 move_rel('d', line_num);
2228 start_at_line = NULL;
2233 wmove(com_win, 0, 0);
2235 text_changes = TRUE;
2236 if ((tmp_file != NULL) && (*tmp_file != '\0'))
2237 wprintw(com_win, file_read_fin_msg, tmp_file);
2240 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2245 get_file(file_name) /* read specified file into current buffer */
2248 int can_read; /* file has at least one character */
2249 int length; /* length of line read by read */
2250 int append; /* should text be appended to current line */
2251 struct text *temp_line;
2252 char ro_flag = FALSE;
2254 if (recv_file) /* if reading a file */
2256 wmove(com_win, 0, 0);
2258 wprintw(com_win, reading_file_msg, file_name);
2259 if (access(file_name, 2)) /* check permission to write */
2261 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2263 wprintw(com_win, read_only_msg);
2269 if (curr_line->line_length > 1) /* if current line is not blank */
2277 can_read = FALSE; /* test if file has any characters */
2278 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2280 can_read = TRUE; /* if set file has at least 1 character */
2281 get_line(length, in_string, &append);
2283 if ((can_read) && (curr_line->line_length == 1))
2285 temp_line = curr_line->prev_line;
2286 temp_line->next_line = curr_line->next_line;
2287 if (temp_line->next_line != NULL)
2288 temp_line->next_line->prev_line = temp_line;
2289 if (curr_line->line != NULL)
2290 free(curr_line->line);
2292 curr_line = temp_line;
2294 if (input_file) /* if this is the file to be edited display number of lines */
2296 wmove(com_win, 0, 0);
2298 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2300 wprintw(com_win, read_only_msg);
2303 else if (can_read) /* not input_file and file is non-zero size */
2304 text_changes = TRUE;
2306 if (recv_file) /* if reading a file */
2313 get_line(length, in_string, append) /* read string and split into lines */
2314 int length; /* length of string read by read */
2315 unsigned char *in_string; /* string read by read */
2316 int *append; /* TRUE if must append more text to end of current line */
2318 unsigned char *str1;
2319 unsigned char *str2;
2320 int num; /* offset from start of string */
2321 int char_count; /* length of new line (or added portion */
2322 int temp_counter; /* temporary counter value */
2323 struct text *tline; /* temporary pointer to new line */
2324 int first_time; /* if TRUE, the first time through the loop */
2329 while (num < length)
2343 /* find end of line */
2344 while ((*str2 != '\n') && (num < length))
2350 if (!(*append)) /* if not append to current line, insert new one */
2352 tline = txtalloc(); /* allocate data structure for next line */
2353 tline->line_number = curr_line->line_number + 1;
2354 tline->next_line = curr_line->next_line;
2355 tline->prev_line = curr_line;
2356 curr_line->next_line = tline;
2357 if (tline->next_line != NULL)
2358 tline->next_line->prev_line = tline;
2360 curr_line->line = point = (unsigned char *) malloc(char_count);
2361 curr_line->line_length = char_count;
2362 curr_line->max_length = char_count;
2366 point = resiz_line(char_count, curr_line, curr_line->line_length);
2367 curr_line->line_length += (char_count - 1);
2369 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2377 if ((num == length) && (*str2 != '\n'))
2383 draw_screen() /* redraw the screen from current postion */
2385 struct text *temp_line;
2386 unsigned char *line_out;
2389 temp_line = curr_line;
2390 temp_vert = scr_vert;
2391 wclrtobot(text_win);
2392 while ((temp_line != NULL) && (temp_vert <= last_line))
2394 line_out = temp_line->line;
2395 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2397 temp_line = temp_line->next_line;
2399 wmove(text_win, temp_vert, 0);
2400 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2404 finish() /* prepare to exit edit session */
2406 char *file_name = in_file_name;
2409 | changes made here should be reflected in the 'save'
2410 | portion of file_op()
2413 if ((file_name == NULL) || (*file_name == '\0'))
2414 file_name = get_string(save_file_name_prompt, TRUE);
2416 if ((file_name == NULL) || (*file_name == '\0'))
2418 wmove(com_win, 0, 0);
2419 wprintw(com_win, file_not_saved_msg);
2422 clear_com_win = TRUE;
2426 tmp_file = resolve_name(file_name);
2427 if (tmp_file != file_name)
2430 file_name = tmp_file;
2433 if (write_file(file_name, 1))
2435 text_changes = FALSE;
2441 quit(noverify) /* exit editor */
2448 if ((text_changes) && (!noverify))
2450 ans = get_string(changes_made_prompt, TRUE);
2451 if (toupper((unsigned char)*ans) == toupper((unsigned char)*yes_char))
2452 text_changes = FALSE;
2457 if (top_of_stack == NULL)
2491 while (curr_line->next_line != NULL)
2492 curr_line = curr_line->next_line;
2493 while (curr_line != first_line)
2495 free(curr_line->line);
2496 curr_line = curr_line->prev_line;
2498 free(curr_line->next_line);
2500 curr_line->next_line = NULL;
2501 *curr_line->line = '\0';
2502 curr_line->line_length = 1;
2503 curr_line->line_number = 1;
2504 point = curr_line->line;
2505 scr_pos = scr_vert = scr_horz = 0;
2510 write_file(file_name, warn_if_exists)
2516 struct text *out_line;
2519 int write_flag = TRUE;
2522 if (warn_if_exists &&
2523 ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
2525 if ((temp_fp = fopen(file_name, "r")))
2527 tmp_point = get_string(file_exists_prompt, TRUE);
2528 if (toupper((unsigned char)*tmp_point) == toupper((unsigned char)*yes_char))
2537 clear_com_win = TRUE;
2541 if ((temp_fp = fopen(file_name, "w")) == NULL)
2543 clear_com_win = TRUE;
2546 wprintw(com_win, create_file_fail_msg, file_name);
2554 wprintw(com_win, writing_file_msg, file_name);
2557 out_line = first_line;
2558 while (out_line != NULL)
2561 tmp_point= out_line->line;
2562 while (temp_pos < out_line->line_length)
2564 putc(*tmp_point, temp_fp);
2568 charac += out_line->line_length;
2569 out_line = out_line->next_line;
2576 wprintw(com_win, file_written_msg, file_name, lines, charac);
2586 search(display_message) /* search for string in srch_str */
2587 int display_message;
2593 if ((srch_str == NULL) || (*srch_str == '\0'))
2595 if (display_message)
2597 wmove(com_win, 0, 0);
2599 wprintw(com_win, searching_msg);
2601 clear_com_win = TRUE;
2605 srch_line = curr_line;
2607 if (position < curr_line->line_length)
2609 iter = position + 1;
2610 while ((!found) && (srch_line != NULL))
2612 while ((iter < srch_line->line_length) && (!found))
2615 if (case_sen) /* if case sensitive */
2618 while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
2625 else /* if not case sensitive */
2627 srch_3 = u_srch_str;
2628 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
2635 if (!((*srch_3 == '\0') && (found)))
2638 if (iter < srch_line->line_length)
2645 srch_line = srch_line->next_line;
2646 if (srch_line != NULL)
2647 srch_1 = srch_line->line;
2654 if (display_message)
2656 wmove(com_win, 0, 0);
2660 if (lines_moved == 0)
2662 while (position < iter)
2667 if (lines_moved < 30)
2669 move_rel('d', lines_moved);
2670 while (position < iter)
2675 absolute_lin += lines_moved;
2676 curr_line = srch_line;
2681 midscreen((last_line / 2), point);
2687 if (display_message)
2689 wmove(com_win, 0, 0);
2691 wprintw(com_win, str_not_found_msg, srch_str);
2694 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2700 search_prompt() /* prompt and read search string (srch_str) */
2702 if (srch_str != NULL)
2704 if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
2706 srch_str = get_string(search_prompt_str, FALSE);
2709 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2710 while (*srch_3 != '\0')
2712 *srch_1 = toupper(*srch_3);
2721 del_char() /* delete current character */
2723 in = 8; /* backspace */
2724 if (position < curr_line->line_length) /* if not end of line */
2726 if ((ee_chinese) && (*point > 127) &&
2727 ((curr_line->line_length - position) >= 2))
2745 undel_char() /* undelete last deleted character */
2747 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2753 if (d_char[1] != '\0')
2762 del_word() /* delete word in front of cursor */
2766 unsigned char *d_word2;
2767 unsigned char *d_word3;
2768 unsigned char tmp_char[3];
2772 d_word = malloc(curr_line->line_length);
2773 tmp_char[0] = d_char[0];
2774 tmp_char[1] = d_char[1];
2775 tmp_char[2] = d_char[2];
2779 while ((tposit < curr_line->line_length) &&
2780 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2783 *d_word2 = *d_word3;
2787 while ((tposit < curr_line->line_length) &&
2788 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2791 *d_word2 = *d_word3;
2796 d_wrd_len = difference = d_word2 - d_word;
2798 while (tposit < curr_line->line_length)
2801 *d_word2 = *d_word3;
2805 curr_line->line_length -= difference;
2807 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2808 d_char[0] = tmp_char[0];
2809 d_char[1] = tmp_char[1];
2810 d_char[2] = tmp_char[2];
2811 text_changes = TRUE;
2816 undel_word() /* undelete last deleted word */
2820 unsigned char *tmp_old_ptr;
2821 unsigned char *tmp_space;
2822 unsigned char *tmp_ptr;
2823 unsigned char *d_word_ptr;
2826 | resize line to handle undeleted word
2828 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2829 point = resiz_line(d_wrd_len, curr_line, position);
2830 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2831 d_word_ptr = d_word;
2834 | copy d_word contents into temp space
2836 while (temp <= d_wrd_len)
2839 *tmp_ptr = *d_word_ptr;
2843 tmp_old_ptr = point;
2846 | copy contents of line from curent position to eol into
2849 while (tposit < curr_line->line_length)
2853 *tmp_ptr = *tmp_old_ptr;
2857 curr_line->line_length += d_wrd_len;
2858 tmp_old_ptr = point;
2860 tmp_ptr = tmp_space;
2863 | now copy contents from temp space back to original line
2865 while (tposit < temp)
2868 *tmp_old_ptr = *tmp_ptr;
2872 *tmp_old_ptr = '\0';
2874 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2878 del_line() /* delete from cursor to end of line */
2886 d_line = malloc(curr_line->line_length);
2890 while (tposit < curr_line->line_length)
2897 dlt_line->line_length = 1 + tposit - position;
2900 curr_line->line_length = position;
2901 wclrtoeol(text_win);
2902 if (curr_line->next_line != NULL)
2907 text_changes = TRUE;
2911 undel_line() /* undelete last deleted line */
2917 if (dlt_line->line_length == 0)
2922 point = resiz_line(dlt_line->line_length, curr_line, position);
2923 curr_line->line_length += dlt_line->line_length - 1;
2927 while (tposit < dlt_line->line_length)
2935 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2939 adv_word() /* advance to next word */
2941 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2943 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2948 move_rel(direction, lines) /* move relative to current line */
2955 if (direction == 'u')
2958 while (position > 1)
2960 for (i = 0; i < lines; i++)
2964 if ((last_line > 5) && ( scr_vert < 4))
2967 tmp_line = curr_line;
2968 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2972 scr_vert = scr_vert + i;
2973 curr_line = tmp_line;
2981 if ((position != 1) && (curr_line->next_line != NULL))
2984 scr_pos = scr_horz = 0;
2988 midscreen(scr_vert, point);
2993 for (i = 1; i < lines; i++)
2997 if ((last_line > 10) && (scr_vert > (last_line - 5)))
3000 tmp_line = curr_line;
3001 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
3006 scr_vert = scr_vert - i;
3007 curr_line = tmp_line;
3012 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
3016 eol() /* go to end of line */
3018 if (position < curr_line->line_length)
3020 while (position < curr_line->line_length)
3023 else if (curr_line->next_line != NULL)
3026 while (position < curr_line->line_length)
3032 bol() /* move to beginning of line */
3034 if (point != curr_line->line)
3036 while (point != curr_line->line)
3039 else if (curr_line->prev_line != NULL)
3047 adv_line() /* advance to beginning of next line */
3049 if ((point != curr_line->line) || (scr_pos > 0))
3051 while (position < curr_line->line_length)
3055 else if (curr_line->next_line != NULL)
3065 struct text *tmpline = first_line;
3068 while ((tmpline != NULL) && (tmpline != curr_line))
3071 tmpline = tmpline->next_line;
3077 sh_command(string) /* execute shell command */
3078 char *string; /* string containing user command */
3082 char *path; /* directory path to executable */
3083 int parent; /* zero if child, child's pid if parent */
3086 struct text *line_holder;
3088 if (restrict_mode())
3093 if (!(path = getenv("SHELL")))
3095 last_slash = temp_point = path;
3096 while (*temp_point != '\0')
3098 if (*temp_point == '/')
3099 last_slash = ++temp_point;
3105 | if in_pipe is true, then output of the shell operation will be
3106 | read by the editor, and curses doesn't need to be turned off
3111 keypad(com_win, FALSE);
3112 keypad(text_win, FALSE);
3125 pipe(pipe_in); /* create a pipe */
3127 if (!parent) /* if the child */
3130 | child process which will fork and exec shell command (if shell output is
3131 | to be read by editor)
3135 | redirect stdout to pipe
3137 temp_stdout = dup(1);
3141 | redirect stderr to pipe
3143 temp_stderr = dup(2);
3148 | child will now continue down 'if (!in_pipe)'
3152 else /* if the parent */
3155 | prepare editor to read from the pipe
3157 signal(SIGCHLD, SIG_IGN);
3158 line_holder = curr_line;
3159 tmp_vert = scr_vert;
3161 get_fd = pipe_in[0];
3164 scr_vert = tmp_vert;
3165 scr_horz = scr_pos = 0;
3167 curr_line = line_holder;
3169 point = curr_line->line;
3171 signal(SIGCHLD, SIG_DFL);
3173 | since flag "in_pipe" is still TRUE, the path which waits for the child
3174 | process to die will be avoided.
3175 | (the pipe is closed, no more output can be expected)
3181 signal(SIGINT, SIG_IGN);
3187 | fork process which will exec command
3190 if (!parent) /* if the child */
3197 | prepare the child process (soon to exec a shell command) to read from the
3198 | pipe (which will be output from the editor's buffer)
3205 for (value = 1; value < 24; value++)
3206 signal(value, SIG_DFL);
3207 execl(path, last_slash, "-c", string, NULL);
3208 fprintf(stderr, exec_err_msg, path);
3211 else /* if the parent */
3216 | output the contents of the buffer to the pipe (to be read by the
3217 | process forked and exec'd above as stdin)
3220 line_holder = first_line;
3221 while (line_holder != NULL)
3223 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3224 write(pipe_out[1], "\n", 1);
3225 line_holder = line_holder->next_line;
3232 return_val = wait((int *) 0);
3234 while ((return_val != parent) && (return_val != -1));
3236 | if this process is actually the child of the editor, exit. Here's how it
3238 | The editor forks a process. If output must be sent to the command to be
3239 | exec'd another process is forked, and that process (the child's child)
3240 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3241 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3242 | If this is the editor process, shell_fork will be true, otherwise this is
3243 | the child of the edit process.
3248 signal(SIGINT, edit_abort);
3252 fputs(continue_msg, stdout);
3254 while ((in = getchar()) != '\n')
3264 keypad(text_win, TRUE);
3265 keypad(com_win, TRUE);
3267 clearok(info_win, TRUE);
3274 set_up_term() /* set up the terminal for operating with ae */
3276 if (!curses_initialized)
3283 curses_initialized = TRUE;
3286 if (((LINES > 15) && (COLS >= 80)) && info_window)
3287 last_line = LINES - 8;
3290 info_window = FALSE;
3291 last_line = LINES - 2;
3294 idlok(stdscr, TRUE);
3295 com_win = newwin(1, COLS, (LINES - 1), 0);
3296 keypad(com_win, TRUE);
3297 idlok(com_win, TRUE);
3300 text_win = newwin((LINES - 1), COLS, 0, 0);
3302 text_win = newwin((LINES - 7), COLS, 6, 0);
3303 keypad(text_win, TRUE);
3304 idlok(text_win, TRUE);
3306 help_win = newwin((LINES - 1), COLS, 0, 0);
3307 keypad(help_win, TRUE);
3308 idlok(help_win, TRUE);
3311 info_type = CONTROL_KEYS;
3312 info_win = newwin(6, COLS, 0, 0);
3317 last_col = COLS - 1;
3318 local_LINES = LINES;
3323 nc_setattrib(A_NC_BIG5);
3331 if ((LINES == local_LINES) && (COLS == local_COLS))
3344 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3348 struct menu_entries menu_list[];
3351 int max_width, max_height;
3358 int top_offset; /* offset from top where menu items start */
3359 int vert_pos; /* vertical position */
3360 int vert_size; /* vertical size for menu list item display */
3361 int off_start = 1; /* offset from start of menu items to start display */
3365 | determine number and width of menu items
3369 while (menu_list[list_size + 1].item_string != NULL)
3372 for (counter = 0; counter <= list_size; counter++)
3374 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3378 max_width = max(max_width, strlen(menu_cancel_msg));
3379 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3383 | make sure that window is large enough to handle menu
3384 | if not, print error message and return to calling function
3387 if (max_width > COLS)
3389 wmove(com_win, 0, 0);
3391 wprintw(com_win, menu_too_lrg_msg);
3393 clear_com_win = TRUE;
3399 if (list_size > LINES)
3402 if (max_height > 11)
3403 vert_size = max_height - 8;
3405 vert_size = max_height;
3409 vert_size = list_size;
3410 max_height = list_size;
3413 if (LINES >= (vert_size + 8))
3415 if (menu_list[0].argument != MENU_WARN)
3416 max_height = vert_size + 8;
3418 max_height = vert_size + 7;
3421 x_off = (COLS - max_width) / 2;
3422 y_off = (LINES - max_height - 1) / 2;
3423 temp_win = newwin(max_height, max_width, y_off, x_off);
3424 keypad(temp_win, TRUE);
3426 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3433 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3435 wmove(temp_win, (counter + top_offset - off_start), 3);
3438 in = wgetch(temp_win);
3443 if (isascii(input) && isalnum(input))
3447 temp = 1 + tolower(input) - 'a';
3449 else if (isdigit(input))
3451 temp = (2 + 'z' - 'a') + (input - '0');
3454 if (temp <= list_size)
3464 case ' ': /* space */
3465 case '\004': /* ^d, down */
3469 if (counter > list_size)
3472 case '\010': /* ^h, backspace*/
3473 case '\025': /* ^u, up */
3474 case 127: /* ^?, delete */
3480 counter = list_size;
3482 case '\033': /* escape key */
3483 if (menu_list[0].argument != MENU_WARN)
3486 case '\014': /* ^l */
3487 case '\022': /* ^r, redraw */
3488 paint_menu(menu_list, max_width, max_height,
3489 list_size, top_offset, temp_win,
3490 off_start, vert_size);
3497 if (((list_size - off_start) >= (vert_size - 1)) &&
3498 (counter > (off_start + vert_size - 3)) &&
3501 if (counter == list_size)
3502 off_start = (list_size - vert_size) + 2;
3506 paint_menu(menu_list, max_width, max_height,
3507 list_size, top_offset, temp_win, off_start,
3510 else if ((list_size != vert_size) &&
3511 (counter > (off_start + vert_size - 2)))
3513 if (counter == list_size)
3514 off_start = 2 + (list_size - vert_size);
3515 else if (off_start == 1)
3520 paint_menu(menu_list, max_width, max_height,
3521 list_size, top_offset, temp_win, off_start,
3524 else if (counter < off_start)
3529 off_start = counter;
3531 paint_menu(menu_list, max_width, max_height,
3532 list_size, top_offset, temp_win, off_start,
3536 while ((input != '\r') && (input != '\n') && (counter != 0));
3542 if ((menu_list[counter].procedure != NULL) ||
3543 (menu_list[counter].iprocedure != NULL) ||
3544 (menu_list[counter].nprocedure != NULL))
3546 if (menu_list[counter].argument != -1)
3547 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3548 else if (menu_list[counter].ptr_argument != NULL)
3549 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3551 (*menu_list[counter].nprocedure)();
3562 paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
3563 off_start, vert_size)
3564 struct menu_entries menu_list[];
3565 int max_width, max_height, list_size, top_offset;
3567 int off_start, vert_size;
3569 int counter, temp_int;
3574 | output top and bottom portions of menu box only if window
3578 if (max_height > vert_size)
3580 wmove(menu_win, 1, 1);
3582 wstandout(menu_win);
3583 waddch(menu_win, '+');
3584 for (counter = 0; counter < (max_width - 4); counter++)
3585 waddch(menu_win, '-');
3586 waddch(menu_win, '+');
3588 wmove(menu_win, (max_height - 2), 1);
3589 waddch(menu_win, '+');
3590 for (counter = 0; counter < (max_width - 4); counter++)
3591 waddch(menu_win, '-');
3592 waddch(menu_win, '+');
3593 wstandend(menu_win);
3594 wmove(menu_win, 2, 3);
3595 waddstr(menu_win, menu_list[0].item_string);
3596 wmove(menu_win, (max_height - 3), 3);
3597 if (menu_list[0].argument != MENU_WARN)
3598 waddstr(menu_win, menu_cancel_msg);
3601 wstandout(menu_win);
3603 for (counter = 0; counter < (vert_size + top_offset); counter++)
3605 if (top_offset == 4)
3607 temp_int = counter + 2;
3612 wmove(menu_win, temp_int, 1);
3613 waddch(menu_win, '|');
3614 wmove(menu_win, temp_int, (max_width - 2));
3615 waddch(menu_win, '|');
3617 wstandend(menu_win);
3619 if (list_size > vert_size)
3624 wmove(menu_win, top_offset, 3);
3625 waddstr(menu_win, more_above_str);
3630 for (counter = off_start;
3631 ((temp_int + counter - off_start) < (vert_size - 1));
3634 wmove(menu_win, (top_offset + temp_int +
3635 (counter - off_start)), 3);
3637 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3638 waddstr(menu_win, menu_list[counter].item_string);
3641 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3643 if (counter == list_size)
3646 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3647 wprintw(menu_win, menu_list[counter].item_string);
3650 wprintw(menu_win, more_below_str);
3654 for (counter = 1; counter <= list_size; counter++)
3656 wmove(menu_win, (top_offset + counter - 1), 3);
3658 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3659 waddstr(menu_win, menu_list[counter].item_string);
3670 clearok(help_win, TRUE);
3671 for (counter = 0; counter < 22; counter++)
3673 wmove(help_win, counter, 0);
3674 waddstr(help_win, (emacs_keys_mode) ?
3675 emacs_help_text[counter] : help_text[counter]);
3679 wmove(com_win, 0, 0);
3680 wprintw(com_win, press_any_key_msg);
3682 counter = wgetch(com_win);
3686 wmove(com_win, 0, 0);
3702 for (counter = 0; counter < 5; counter++)
3704 wmove(info_win, counter, 0);
3705 wclrtoeol(info_win);
3706 if (info_type == CONTROL_KEYS)
3707 waddstr(info_win, (emacs_keys_mode) ?
3708 emacs_control_keys[counter] : control_keys[counter]);
3709 else if (info_type == COMMANDS)
3710 waddstr(info_win, command_strings[counter]);
3712 wmove(info_win, 5, 0);
3714 wstandout(info_win);
3715 waddstr(info_win, separator);
3716 wstandend(info_win);
3727 info_window = FALSE;
3728 last_line = LINES - 2;
3729 text_win = newwin((LINES - 1), COLS, 0, 0);
3730 keypad(text_win, TRUE);
3731 idlok(text_win, TRUE);
3732 clearok(text_win, TRUE);
3733 midscreen(scr_vert, point);
3735 clear_com_win = TRUE;
3739 create_info_window()
3743 last_line = LINES - 8;
3745 text_win = newwin((LINES - 7), COLS, 6, 0);
3746 keypad(text_win, TRUE);
3747 idlok(text_win, TRUE);
3750 info_win = newwin(6, COLS, 0, 0);
3752 info_type = CONTROL_KEYS;
3753 midscreen(min(scr_vert, last_line), point);
3754 clearok(info_win, TRUE);
3757 clear_com_win = TRUE;
3767 if (restrict_mode())
3772 if (arg == READ_FILE)
3774 string = get_string(file_read_prompt_str, TRUE);
3776 tmp_file = resolve_name(string);
3778 if (tmp_file != string)
3782 else if (arg == WRITE_FILE)
3784 string = get_string(file_write_prompt_str, TRUE);
3785 tmp_file = resolve_name(string);
3786 write_file(tmp_file, 1);
3787 if (tmp_file != string)
3791 else if (arg == SAVE_FILE)
3794 | changes made here should be reflected in finish()
3802 string = in_file_name;
3803 if ((string == NULL) || (*string == '\0'))
3804 string = get_string(save_file_name_prompt, TRUE);
3805 if ((string == NULL) || (*string == '\0'))
3807 wmove(com_win, 0, 0);
3808 wprintw(com_win, file_not_saved_msg);
3811 clear_com_win = TRUE;
3816 tmp_file = resolve_name(string);
3817 if (tmp_file != string)
3823 if (write_file(string, 1))
3825 in_file_name = string;
3826 text_changes = FALSE;
3839 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3852 menu_op(leave_menu);
3863 clearok(info_win, TRUE);
3867 clearok(text_win, TRUE);
3868 midscreen(scr_vert, point);
3872 | The following routines will "format" a paragraph (as defined by a
3873 | block of text with blank lines before and after the block).
3877 Blank_Line(test_line) /* test if line has any non-space characters */
3878 struct text *test_line;
3880 unsigned char *line;
3883 if (test_line == NULL)
3887 line = test_line->line;
3890 | To handle troff/nroff documents, consider a line with a
3891 | period ('.') in the first column to be blank. To handle mail
3892 | messages with included text, consider a line with a '>' blank.
3895 if ((*line == '.') || (*line == '>'))
3898 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3903 if (length != test_line->line_length)
3910 Format() /* format the paragraph according to set margins */
3918 unsigned char *line;
3919 unsigned char *tmp_srchstr;
3920 unsigned char *temp1, *temp2;
3921 unsigned char *temp_dword;
3922 unsigned char temp_d_char[3];
3924 temp_d_char[0] = d_char[0];
3925 temp_d_char[1] = d_char[1];
3926 temp_d_char[2] = d_char[2];
3929 | if observ_margins is not set, or the current line is blank,
3930 | do not format the current paragraph
3933 if ((!observ_margins) || (Blank_Line(curr_line)))
3937 | save the currently set flags, and clear them
3940 wmove(com_win, 0, 0);
3942 wprintw(com_win, formatting_msg);
3946 | get current position in paragraph, so after formatting, the cursor
3947 | will be in the same relative position
3950 tmp_af = auto_format;
3951 auto_format = FALSE;
3955 temp_dword = d_word;
3957 temp_case = case_sen;
3959 tmp_srchstr = srch_str;
3960 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3961 if ((*point == ' ') || (*point == '\t'))
3965 line = temp1 = point;
3966 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3976 while (!Blank_Line(curr_line->prev_line))
3980 while ((line != point) && (status))
3982 status = search(FALSE);
3986 wmove(com_win, 0, 0);
3988 wprintw(com_win, formatting_msg);
3992 | now get back to the start of the paragraph to start formatting
3997 while (!Blank_Line(curr_line->prev_line))
4000 observ_margins = FALSE;
4003 | Start going through lines, putting spaces at end of lines if they do
4004 | not already exist. Append lines together to get one long line, and
4005 | eliminate spacing at begin of lines.
4008 while (!Blank_Line(curr_line->next_line))
4020 if ((*point == ' ') || (*point == '\t'))
4025 | Now there is one long line. Eliminate extra spaces within the line
4026 | after the first word (so as not to blow away any indenting the user
4032 while (position < curr_line->line_length)
4034 if ((*point == ' ') && (*(point + 1) == ' '))
4041 | Now make sure there are two spaces after a '.'.
4045 while (position < curr_line->line_length)
4047 if ((*point == '.') && (*(point + 1) == ' '))
4052 while (*point == ' ')
4058 observ_margins = TRUE;
4061 wmove(com_win, 0, 0);
4063 wprintw(com_win, formatting_msg);
4067 | create lines between margins
4070 while (position < curr_line->line_length)
4072 while ((scr_pos < right_margin) && (position < curr_line->line_length))
4074 if (position < curr_line->line_length)
4084 | go back to begin of paragraph, put cursor back to original position
4088 while (!Blank_Line(curr_line->prev_line))
4092 | find word cursor was in
4095 while ((status) && (string_count > 0))
4102 | offset the cursor to where it was before from the start of the word
4112 | reset flags and strings to what they were before formatting
4117 d_word = temp_dword;
4118 case_sen = temp_case;
4120 srch_str = tmp_srchstr;
4121 d_char[0] = temp_d_char[0];
4122 d_char[1] = temp_d_char[1];
4123 d_char[2] = temp_d_char[2];
4124 auto_format = tmp_af;
4126 midscreen(scr_vert, point);
4131 unsigned char *init_name[3] = {
4132 "/usr/share/misc/init.ee",
4138 ee_init() /* check for init file and read it if it exists */
4141 unsigned char *string;
4142 unsigned char *str1;
4143 unsigned char *str2;
4148 string = getenv("HOME");
4151 str1 = home = malloc(strlen(string)+10);
4152 strcpy(home, string);
4153 strcat(home, "/.init.ee");
4154 init_name[1] = home;
4155 string = malloc(512);
4157 for (counter = 0; counter < 3; counter++)
4159 if (!(access(init_name[counter], 4)))
4161 init_file = fopen(init_name[counter], "r");
4162 while ((str2 = fgets(string, 512, init_file)) != NULL)
4164 str1 = str2 = string;
4165 while (*str2 != '\n')
4169 if (unique_test(string, init_strings) != 1)
4172 if (compare(str1, CASE, FALSE))
4174 else if (compare(str1, NOCASE, FALSE))
4176 else if (compare(str1, EXPAND, FALSE))
4178 else if (compare(str1, NOEXPAND, FALSE))
4179 expand_tabs = FALSE;
4180 else if (compare(str1, INFO, FALSE))
4182 else if (compare(str1, NOINFO, FALSE))
4183 info_window = FALSE;
4184 else if (compare(str1, MARGINS, FALSE))
4185 observ_margins = TRUE;
4186 else if (compare(str1, NOMARGINS, FALSE))
4187 observ_margins = FALSE;
4188 else if (compare(str1, AUTOFORMAT, FALSE))
4191 observ_margins = TRUE;
4193 else if (compare(str1, NOAUTOFORMAT, FALSE))
4194 auto_format = FALSE;
4195 else if (compare(str1, Echo, FALSE))
4197 str1 = next_word(str1);
4201 else if (compare(str1, PRINTCOMMAND, FALSE))
4203 str1 = next_word(str1);
4204 print_command = malloc(strlen(str1)+1);
4205 strcpy(print_command, str1);
4207 else if (compare(str1, RIGHTMARGIN, FALSE))
4209 str1 = next_word(str1);
4210 if ((*str1 >= '0') && (*str1 <= '9'))
4212 temp_int = atoi(str1);
4214 right_margin = temp_int;
4217 else if (compare(str1, HIGHLIGHT, FALSE))
4218 nohighlight = FALSE;
4219 else if (compare(str1, NOHIGHLIGHT, FALSE))
4221 else if (compare(str1, EIGHTBIT, FALSE))
4223 else if (compare(str1, NOEIGHTBIT, FALSE))
4228 else if (compare(str1, EMACS_string, FALSE))
4229 emacs_keys_mode = TRUE;
4230 else if (compare(str1, NOEMACS_string, FALSE))
4231 emacs_keys_mode = FALSE;
4232 else if (compare(str1, chinese_cmd, FALSE))
4237 else if (compare(str1, nochinese_cmd, FALSE))
4246 string = getenv("LANG");
4249 if (strcmp(string, "zh_TW.big5") == 0)
4258 | Save current configuration to .init.ee file in the current directory.
4265 FILE *old_init_file = NULL;
4266 char *file_name = ".init.ee";
4267 char *home_dir = "~/.init.ee";
4274 if (restrict_mode())
4279 option = menu_op(config_dump_menu);
4282 wmove(com_win, 0, 0);
4286 wprintw(com_win, conf_not_saved_msg);
4290 else if (option == 2)
4291 file_name = resolve_name(home_dir);
4294 | If a .init.ee file exists, move it to .init.ee.old.
4297 if (stat(file_name, &buf) != -1)
4299 sprintf(buffer, "%s.old", file_name);
4301 link(file_name, buffer);
4303 old_init_file = fopen(buffer, "r");
4306 init_file = fopen(file_name, "w");
4307 if (init_file == NULL)
4309 wprintw(com_win, conf_dump_err_msg);
4314 if (old_init_file != NULL)
4317 | Copy non-configuration info into new .init.ee file.
4319 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4321 length = strlen(string);
4322 string[length - 1] = '\0';
4324 if (unique_test(string, init_strings) == 1)
4326 if (compare(string, Echo, FALSE))
4328 fprintf(init_file, "%s\n", string);
4332 fprintf(init_file, "%s\n", string);
4335 fclose(old_init_file);
4338 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4339 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4340 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4341 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4342 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4343 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4344 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4345 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4346 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4347 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4348 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4352 wprintw(com_win, conf_dump_success_msg, file_name);
4355 if ((option == 2) && (file_name != home_dir))
4362 echo_string(string) /* echo the given string */
4369 while (*temp != '\0')
4376 else if (*temp == 't')
4378 else if (*temp == 'b')
4380 else if (*temp == 'r')
4382 else if (*temp == 'f')
4384 else if ((*temp == 'e') || (*temp == 'E'))
4385 putchar('\033'); /* escape */
4386 else if (*temp == '\\')
4388 else if (*temp == '\'')
4390 else if ((*temp >= '0') && (*temp <= '9'))
4393 while ((*temp >= '0') && (*temp <= '9'))
4395 Counter = (8 * Counter) + (*temp - '0');
4414 spell_op() /* check spelling of words in the editor */
4416 if (restrict_mode())
4420 top(); /* go to top of file */
4421 insert_line(FALSE); /* create two blank lines */
4424 command(shell_echo_msg);
4426 wmove(com_win, 0, 0);
4427 wprintw(com_win, spell_in_prog_msg);
4429 command("<>!spell"); /* send contents of buffer to command 'spell'
4430 and read the results back into the editor */
4436 char template[128], *name;
4440 if (restrict_mode())
4444 (void)sprintf(template, "/tmp/ee.XXXXXXXX");
4445 fd = mkstemp(template);
4447 wmove(com_win, 0, 0);
4448 wprintw(com_win, create_file_fail_msg, name);
4453 if (write_file(name, 0))
4455 sprintf(string, "ispell %s", name);
4466 first_word_len(test_line)
4467 struct text *test_line;
4472 if (test_line == NULL)
4475 pnt = test_line->line;
4476 if ((pnt == NULL) || (*pnt == '\0') ||
4477 (*pnt == '.') || (*pnt == '>'))
4480 if ((*pnt == ' ') || (*pnt == '\t'))
4482 pnt = next_word(pnt);
4489 while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
4494 while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
4503 Auto_Format() /* format the paragraph according to set margins */
4510 int tmp_d_line_length;
4511 int leave_loop = FALSE;
4515 unsigned char *line;
4516 unsigned char *tmp_srchstr;
4517 unsigned char *temp1, *temp2;
4518 unsigned char *temp_dword;
4519 unsigned char temp_d_char[3];
4520 unsigned char *tmp_d_line;
4523 temp_d_char[0] = d_char[0];
4524 temp_d_char[1] = d_char[1];
4525 temp_d_char[2] = d_char[2];
4528 | if observ_margins is not set, or the current line is blank,
4529 | do not format the current paragraph
4532 if ((!observ_margins) || (Blank_Line(curr_line)))
4536 | get current position in paragraph, so after formatting, the cursor
4537 | will be in the same relative position
4540 tmp_d_line = d_line;
4541 tmp_d_line_length = dlt_line->line_length;
4543 auto_format = FALSE;
4545 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
4547 temp_dword = d_word;
4548 temp_dwl = d_wrd_len;
4551 temp_case = case_sen;
4553 tmp_srchstr = srch_str;
4554 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4555 if ((*point == ' ') || (*point == '\t'))
4559 line = temp1 = point;
4560 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4570 while (!Blank_Line(curr_line->prev_line))
4574 while ((line != point) && (status))
4576 status = search(FALSE);
4581 | now get back to the start of the paragraph to start checking
4586 while (!Blank_Line(curr_line->prev_line))
4590 | Start going through lines, putting spaces at end of lines if they do
4591 | not already exist. Check line length, and move words to the next line
4592 | if they cross the margin. Then get words from the next line if they
4593 | will fit in before the margin.
4600 if (position != curr_line->line_length)
4614 | fill line if first word on next line will fit
4615 | in the line without crossing the margin
4618 while ((curr_line->next_line != NULL) &&
4619 ((word_len = first_word_len(curr_line->next_line)) > 0)
4620 && ((scr_pos + word_len) < right_margin))
4623 if ((*point == ' ') || (*point == '\t'))
4630 | We know this line was not blank before, so
4631 | make sure that it doesn't have one of the
4632 | leading characters that indicate the line
4633 | should not be modified.
4635 | We also know that this character should not
4636 | be left as the first character of this line.
4639 if ((Blank_Line(curr_line)) &&
4640 (curr_line->line[0] != '.') &&
4641 (curr_line->line[0] != '>'))
4650 | go to end of previous line
4656 | make sure there's a space at the end of the line
4669 | make sure line does not cross right margin
4672 while (right_margin <= scr_pos)
4678 if (Blank_Line(curr_line->next_line))
4682 if ((*point == ' ') || (*point == '\t'))
4692 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4702 | go back to begin of paragraph, put cursor back to original position
4707 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4711 | find word cursor was in
4715 while ((status) && (string_count > 0))
4717 status = search(FALSE);
4722 | offset the cursor to where it was before from the start of the word
4731 if ((string_count > 0) && (offset < 0))
4741 | reset flags and strings to what they were before formatting
4746 d_word = temp_dword;
4747 d_wrd_len = temp_dwl;
4748 case_sen = temp_case;
4750 srch_str = tmp_srchstr;
4751 d_char[0] = temp_d_char[0];
4752 d_char[1] = temp_d_char[1];
4753 d_char[2] = temp_d_char[2];
4755 dlt_line->line_length = tmp_d_line_length;
4756 d_line = tmp_d_line;
4759 midscreen(scr_vert, point);
4771 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4772 (expand_tabs ? ON : OFF));
4773 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4774 (case_sen ? ON : OFF));
4775 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4776 (observ_margins ? ON : OFF));
4777 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4778 (auto_format ? ON : OFF));
4779 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4780 (eightbit ? ON : OFF));
4781 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4782 (info_window ? ON : OFF));
4783 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4784 (emacs_keys_mode ? ON : OFF));
4785 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4787 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4788 (ee_chinese ? ON : OFF));
4790 ret_value = menu_op(modes_menu);
4795 expand_tabs = !expand_tabs;
4798 case_sen = !case_sen;
4801 observ_margins = !observ_margins;
4804 auto_format = !auto_format;
4806 observ_margins = TRUE;
4809 eightbit = !eightbit;
4814 nc_setattrib(A_NC_BIG5);
4816 nc_clearattrib(A_NC_BIG5);
4820 wnoutrefresh(text_win);
4826 create_info_window();
4829 emacs_keys_mode = !emacs_keys_mode;
4834 string = get_string(margin_prompt, TRUE);
4837 counter = atoi(string);
4839 right_margin = counter;
4844 ee_chinese = !ee_chinese;
4845 if (ee_chinese != FALSE)
4849 nc_setattrib(A_NC_BIG5);
4851 nc_clearattrib(A_NC_BIG5);
4859 while (ret_value != 0);
4863 is_in_string(string, substring) /* a strchr() look-alike for systems without
4865 char * string, *substring;
4869 for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
4871 for (full = string; (full != NULL) && (*full != '\0');
4882 | handle names of the form "~/file", "~user/file",
4883 | "$HOME/foo", "~/$FOO", etc.
4890 char long_buffer[1024];
4891 char short_buffer[128];
4899 struct passwd *user;
4906 user = (struct passwd *) getpwuid(index);
4911 slash = strchr(name, '/');
4915 user = (struct passwd *) getpwnam((name + 1));
4922 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4923 strcpy(buffer, user->pw_dir);
4924 strcat(buffer, slash);
4929 if (is_in_string(buffer, "$"))
4934 while ((*tmp != '\0') && (index < 1024))
4937 while ((*tmp != '\0') && (*tmp != '$') &&
4940 long_buffer[index] = *tmp;
4945 if ((*tmp == '$') && (index < 1024))
4950 if (*tmp == '{') /* } */ /* bracketed variable name */
4953 while ((*tmp != '\0') &&
4957 short_buffer[counter] = *tmp;
4966 while ((*tmp != '\0') &&
4971 short_buffer[counter] = *tmp;
4976 short_buffer[counter] = '\0';
4977 if ((slash = getenv(short_buffer)) != NULL)
4979 offset = strlen(slash);
4980 if ((offset + index) < 1024)
4981 strcpy(&long_buffer[index], slash);
4986 while ((start_of_var != tmp) && (index < 1024))
4988 long_buffer[index] = *start_of_var;
4999 long_buffer[index] = '\0';
5003 buffer = malloc(index + 1);
5004 strcpy(buffer, long_buffer);
5016 wmove(com_win, 0, 0);
5017 wprintw(com_win, restricted_msg);
5020 clear_com_win = TRUE;
5025 | The following routine tests the input string against the list of
5026 | strings, to determine if the string is a unique match with one of the
5031 unique_test(string, list)
5041 while (list[counter] != NULL)
5043 result = compare(string, list[counter], FALSE);
5053 | Get the catalog entry, and if it got it from the catalog,
5054 | make a copy, since the buffer will be overwritten by the
5055 | next call to catgets().
5059 catgetlocal(number, string)
5066 temp1 = catgets(catalog, 1, number, string);
5067 if (temp1 != string)
5069 temp2 = malloc(strlen(temp1) + 1);
5070 strcpy(temp2, temp1);
5075 #endif /* NO_CATGETS */
5078 | The following is to allow for using message catalogs which allow
5079 | the software to be 'localized', that is, to use different languages
5080 | all with the same binary. For more information, see your system
5081 | documentation, or the X/Open Internationalization Guide.
5089 setlocale(LC_ALL, "");
5091 catalog = catopen("ee", NL_CAT_LOCALE);
5092 #endif /* NO_CATGETS */
5094 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5095 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5096 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5097 mode_strings[3] = catgetlocal( 4, "margins observed ");
5098 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5099 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5100 mode_strings[6] = catgetlocal( 7, "info window ");
5101 mode_strings[8] = catgetlocal( 8, "right margin ");
5102 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5103 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5104 leave_menu[2].item_string = catgetlocal( 11, "no save");
5105 file_menu[0].item_string = catgetlocal( 12, "file menu");
5106 file_menu[1].item_string = catgetlocal( 13, "read a file");
5107 file_menu[2].item_string = catgetlocal( 14, "write a file");
5108 file_menu[3].item_string = catgetlocal( 15, "save file");
5109 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5110 search_menu[0].item_string = catgetlocal( 17, "search menu");
5111 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5112 search_menu[2].item_string = catgetlocal( 19, "search");
5113 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5114 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5115 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5116 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5117 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5118 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5119 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5120 main_menu[0].item_string = catgetlocal( 27, "main menu");
5121 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5122 main_menu[2].item_string = catgetlocal( 29, "help");
5123 main_menu[3].item_string = catgetlocal( 30, "file operations");
5124 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5125 main_menu[5].item_string = catgetlocal( 32, "settings");
5126 main_menu[6].item_string = catgetlocal( 33, "search");
5127 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5128 help_text[0] = catgetlocal( 35, "Control keys: ");
5129 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5130 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5131 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5132 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5133 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5134 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5135 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5136 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5137 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5138 help_text[10] = catgetlocal( 45, " ");
5139 help_text[11] = catgetlocal( 46, "Commands: ");
5140 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5141 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5142 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5143 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5144 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5145 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5146 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5147 help_text[19] = catgetlocal( 54, " ");
5148 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5149 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5150 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5151 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5152 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5153 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5154 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5155 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5156 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5157 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5158 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5159 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5160 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5161 no_file_string = catgetlocal( 68, "no file");
5162 ascii_code_str = catgetlocal( 69, "ascii code: ");
5163 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5164 command_str = catgetlocal( 71, "command: ");
5165 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5166 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5167 char_str = catgetlocal( 74, "character = %d");
5168 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5169 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5170 line_num_str = catgetlocal( 77, "line %d ");
5171 line_len_str = catgetlocal( 78, "length = %d");
5172 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5173 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5174 usage1 = catgetlocal( 81, " -i turn off info window\n");
5175 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5176 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5177 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5178 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5179 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5180 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5181 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5182 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5183 read_only_msg = catgetlocal( 90, ", read only");
5184 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5185 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5186 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5187 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5188 yes_char = catgetlocal( 95, "y");
5189 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5190 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5191 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5192 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5193 searching_msg = catgetlocal( 100, " ...searching");
5194 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5195 search_prompt_str = catgetlocal( 102, "search for: ");
5196 exec_err_msg = catgetlocal( 103, "could not exec %s\n");
5197 continue_msg = catgetlocal( 104, "press return to continue ");
5198 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5199 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5200 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5201 shell_prompt = catgetlocal( 108, "shell command: ");
5202 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5203 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5204 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5205 margin_prompt = catgetlocal( 112, "right margin is: ");
5206 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5207 ON = catgetlocal( 114, "ON");
5208 OFF = catgetlocal( 115, "OFF");
5209 HELP = catgetlocal( 116, "HELP");
5210 WRITE = catgetlocal( 117, "WRITE");
5211 READ = catgetlocal( 118, "READ");
5212 LINE = catgetlocal( 119, "LINE");
5213 FILE_str = catgetlocal( 120, "FILE");
5214 CHARACTER = catgetlocal( 121, "CHARACTER");
5215 REDRAW = catgetlocal( 122, "REDRAW");
5216 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5217 AUTHOR = catgetlocal( 124, "AUTHOR");
5218 VERSION = catgetlocal( 125, "VERSION");
5219 CASE = catgetlocal( 126, "CASE");
5220 NOCASE = catgetlocal( 127, "NOCASE");
5221 EXPAND = catgetlocal( 128, "EXPAND");
5222 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5223 Exit_string = catgetlocal( 130, "EXIT");
5224 QUIT_string = catgetlocal( 131, "QUIT");
5225 INFO = catgetlocal( 132, "INFO");
5226 NOINFO = catgetlocal( 133, "NOINFO");
5227 MARGINS = catgetlocal( 134, "MARGINS");
5228 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5229 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5230 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5231 Echo = catgetlocal( 138, "ECHO");
5232 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5233 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5234 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5235 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5236 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5237 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5241 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5242 emacs_help_text[0] = help_text[0];
5243 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5244 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
5245 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
5246 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5247 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5248 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5249 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5250 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5251 emacs_help_text[9] = help_text[9];
5252 emacs_help_text[10] = help_text[10];
5253 emacs_help_text[11] = help_text[11];
5254 emacs_help_text[12] = help_text[12];
5255 emacs_help_text[13] = help_text[13];
5256 emacs_help_text[14] = help_text[14];
5257 emacs_help_text[15] = help_text[15];
5258 emacs_help_text[16] = help_text[16];
5259 emacs_help_text[17] = help_text[17];
5260 emacs_help_text[18] = help_text[18];
5261 emacs_help_text[19] = help_text[19];
5262 emacs_help_text[20] = help_text[20];
5263 emacs_help_text[21] = help_text[21];
5264 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
5265 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
5266 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
5267 emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
5268 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5269 EMACS_string = catgetlocal( 159, "EMACS");
5270 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5271 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5272 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5273 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5274 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5275 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5276 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5277 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5278 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5279 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5280 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5281 more_above_str = catgetlocal( 181, "^^more^^");
5282 more_below_str = catgetlocal( 182, "VVmoreVV");
5283 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5284 chinese_cmd = catgetlocal( 184, "16BIT");
5285 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5288 commands[1] = WRITE;
5291 commands[4] = FILE_str;
5292 commands[5] = REDRAW;
5293 commands[6] = RESEQUENCE;
5294 commands[7] = AUTHOR;
5295 commands[8] = VERSION;
5297 commands[10] = NOCASE;
5298 commands[11] = EXPAND;
5299 commands[12] = NOEXPAND;
5300 commands[13] = Exit_string;
5301 commands[14] = QUIT_string;
5315 commands[28] = CHARACTER;
5316 commands[29] = chinese_cmd;
5317 commands[30] = nochinese_cmd;
5318 commands[31] = NULL;
5319 init_strings[0] = CASE;
5320 init_strings[1] = NOCASE;
5321 init_strings[2] = EXPAND;
5322 init_strings[3] = NOEXPAND;
5323 init_strings[4] = INFO;
5324 init_strings[5] = NOINFO;
5325 init_strings[6] = MARGINS;
5326 init_strings[7] = NOMARGINS;
5327 init_strings[8] = AUTOFORMAT;
5328 init_strings[9] = NOAUTOFORMAT;
5329 init_strings[10] = Echo;
5330 init_strings[11] = PRINTCOMMAND;
5331 init_strings[12] = RIGHTMARGIN;
5332 init_strings[13] = HIGHLIGHT;
5333 init_strings[14] = NOHIGHLIGHT;
5334 init_strings[15] = EIGHTBIT;
5335 init_strings[16] = NOEIGHTBIT;
5336 init_strings[17] = EMACS_string;
5337 init_strings[18] = NOEMACS_string;
5338 init_strings[19] = chinese_cmd;
5339 init_strings[20] = nochinese_cmd;
5340 init_strings[21] = NULL;
5343 | allocate space for strings here for settings menu
5346 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5348 modes_menu[counter].item_string = malloc(80);
5353 #endif /* NO_CATGETS */