4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
9 | Copyright (c) 2009, Hugh Mahon
10 | All rights reserved.
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions
16 | * Redistributions of source code must retain the above copyright
17 | notice, this list of conditions and the following disclaimer.
18 | * Redistributions in binary form must reproduce the above
19 | copyright notice, this list of conditions and the following
20 | disclaimer in the documentation and/or other materials provided
21 | with the distribution.
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | POSSIBILITY OF SUCH DAMAGE.
36 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
38 | This editor was purposely developed to be simple, both in
39 | interface and implementation. This editor was developed to
40 | address a specific audience: the user who is new to computers
43 | ee is not aimed at technical users; for that reason more
44 | complex features were intentionally left out. In addition,
45 | ee is intended to be compiled by people with little computer
46 | experience, which means that it needs to be small, relatively
47 | simple in implementation, and portable.
49 | This software and documentation contains
50 | proprietary information which is protected by
51 | copyright. All rights are reserved.
53 | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.104 2010/06/04 01:55:31 hugh Exp hugh $
57 char *ee_copyright_message =
58 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
60 #include "ee_version.h"
62 char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.104 $";
65 #include "new_curse.h"
78 #include <sys/types.h>
103 #include <nl_types.h>
107 #define catgetlocal(a, b) (b)
108 #endif /* NO_CATGETS */
111 #define SIGCHLD SIGCLD
115 #define max(a, b) (a > b ? a : b)
116 #define min(a, b) (a < b ? a : b)
119 | defines for type of data to show in info window
122 #define CONTROL_KEYS 1
126 unsigned char *line; /* line of characters */
127 int line_number; /* line number */
128 int line_length; /* actual number of characters in the line */
129 int max_length; /* maximum number of characters the line handles */
130 struct text *next_line; /* next line of text */
131 struct text *prev_line; /* previous line of text */
134 struct text *first_line; /* first line of current buffer */
135 struct text *dlt_line; /* structure for info on deleted line */
136 struct text *curr_line; /* current line cursor is on */
137 struct text *tmp_line; /* temporary line pointer */
138 struct text *srch_line; /* temporary pointer for search routine */
140 struct files { /* structure to store names of files to be edited*/
141 unsigned char *name; /* name of file */
142 struct files *next_name;
145 struct files *top_of_stack = NULL;
147 int d_wrd_len; /* length of deleted word */
148 int position; /* offset in bytes from begin of line */
149 int scr_pos; /* horizontal position */
150 int scr_vert; /* vertical position on screen */
151 int scr_horz; /* horizontal position on screen */
152 int absolute_lin; /* number of lines from top */
153 int tmp_vert, tmp_horz;
154 int input_file; /* indicate to read input file */
155 int recv_file; /* indicate reading a file */
156 int edit; /* continue executing while true */
157 int gold; /* 'gold' function key pressed */
158 int fildes; /* file descriptor */
159 int case_sen; /* case sensitive search flag */
160 int last_line; /* last line for text display */
161 int last_col; /* last column for text display */
162 int horiz_offset = 0; /* offset from left edge of text */
163 int clear_com_win; /* flag to indicate com_win needs clearing */
164 int text_changes = FALSE; /* indicate changes have been made to text */
165 int get_fd; /* file descriptor for reading a file */
166 int info_window = TRUE; /* flag to indicate if help window visible */
167 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
168 int expand_tabs = TRUE; /* flag for expanding tabs */
169 int right_margin = 0; /* the right margin */
170 int observ_margins = TRUE; /* flag for whether margins are observed */
172 int temp_stdin; /* temporary storage for stdin */
173 int temp_stdout; /* temp storage for stdout descriptor */
174 int temp_stderr; /* temp storage for stderr descriptor */
175 int pipe_out[2]; /* pipe file desc for output */
176 int pipe_in[2]; /* pipe file descriptors for input */
177 int out_pipe; /* flag that info is piped out */
178 int in_pipe; /* flag that info is piped in */
179 int formatted = FALSE; /* flag indicating paragraph formatted */
180 int auto_format = FALSE; /* flag for auto_format mode */
181 int restricted = FALSE; /* flag to indicate restricted mode */
182 int nohighlight = FALSE; /* turns off highlighting */
183 int eightbit = TRUE; /* eight bit character flag */
184 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
185 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
186 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
187 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
188 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
189 /* by checking for high bit in a byte the */
190 /* code recognizes a two-byte character */
193 unsigned char *point; /* points to current position in line */
194 unsigned char *srch_str; /* pointer for search string */
195 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
196 unsigned char *srch_1; /* pointer to start of suspect string */
197 unsigned char *srch_2; /* pointer to next character of string */
198 unsigned char *srch_3;
199 unsigned char *in_file_name = NULL; /* name of input file */
200 char *tmp_file; /* temporary file name */
201 unsigned char *d_char; /* deleted character */
202 unsigned char *d_word; /* deleted word */
203 unsigned char *d_line; /* deleted line */
204 char in_string[513]; /* buffer for reading a file */
205 unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
206 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
207 int in; /* input character */
209 FILE *temp_fp; /* temporary file pointer */
210 FILE *bit_bucket; /* file pointer to /dev/null */
213 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
214 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
215 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
223 #if defined(__STDC__) || defined(__cplusplus)
231 | The following structure allows menu items to be flexibly declared.
232 | The first item is the string describing the selection, the second
233 | is the address of the procedure to call when the item is selected,
234 | and the third is the argument for the procedure.
236 | For those systems with i18n, the string should be accompanied by a
237 | catalog number. The 'int *' should be replaced with 'void *' on
238 | systems with that type.
240 | The first menu item will be the title of the menu, with NULL
241 | parameters for the procedure and argument, followed by the menu items.
243 | If the procedure value is NULL, the menu item is displayed, but no
244 | procedure is called when the item is selected. The number of the
245 | item will be returned. If the third (argument) parameter is -1, no
246 | argument is given to the procedure when it is called.
249 struct menu_entries {
251 int (*procedure)P_((struct menu_entries *));
252 struct menu_entries *ptr_argument;
253 int (*iprocedure)P_((int));
254 void (*nprocedure)P_((void));
258 int main P_((int argc, char *argv[]));
259 unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
260 void insert P_((int character));
261 void delete P_((int disp));
262 void scanline P_((unsigned char *pos));
263 int tabshift P_((int temp_int));
264 int out_char P_((WINDOW *window, int character, int column));
265 int len_char P_((int character, int column));
266 void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
267 void insert_line P_((int disp));
268 struct text *txtalloc P_((void));
269 struct files *name_alloc P_((void));
270 unsigned char *next_word P_((unsigned char *string));
271 void prev_word P_((void));
272 void control P_((void));
273 void emacs_control P_((void));
274 void bottom P_((void));
276 void nextline P_((void));
277 void prevline P_((void));
278 void left P_((int disp));
279 void right P_((int disp));
280 void find_pos P_((void));
282 void down P_((void));
283 void function_key P_((void));
284 void print_buffer P_((void));
285 void command_prompt P_((void));
286 void command P_((char *cmd_str1));
287 int scan P_((char *line, int offset, int column));
288 char *get_string P_((char *prompt, int advance));
289 int compare P_((char *string1, char *string2, int sensitive));
290 void goto_line P_((char *cmd_str));
291 void midscreen P_((int line, unsigned char *pnt));
292 void get_options P_((int numargs, char *arguments[]));
293 void check_fp P_((void));
294 void get_file P_((char *file_name));
295 void get_line P_((int length, unsigned char *in_string, int *append));
296 void draw_screen P_((void));
297 void finish P_((void));
298 int quit P_((int noverify));
299 void edit_abort P_((int arg));
300 void delete_text P_((void));
301 int write_file P_((char *file_name, int warn_if_exists));
302 int search P_((int display_message));
303 void search_prompt P_((void));
304 void del_char P_((void));
305 void undel_char P_((void));
306 void del_word P_((void));
307 void undel_word P_((void));
308 void del_line P_((void));
309 void undel_line P_((void));
310 void adv_word P_((void));
311 void move_rel P_((char direction, int lines));
314 void adv_line P_((void));
315 void sh_command P_((char *string));
316 void set_up_term P_((void));
317 void resize_check P_((void));
318 int menu_op P_((struct menu_entries *));
319 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));
320 void help P_((void));
321 void paint_info_win P_((void));
322 void no_info_window P_((void));
323 void create_info_window P_((void));
324 int file_op P_((int arg));
325 void shell_op P_((void));
326 void leave_op P_((void));
327 void redraw P_((void));
328 int Blank_Line P_((struct text *test_line));
329 void Format P_((void));
330 void ee_init P_((void));
331 void dump_ee_conf P_((void));
332 void echo_string P_((char *string));
333 void spell_op P_((void));
334 void ispell_op P_((void));
335 int first_word_len P_((struct text *test_line));
336 void Auto_Format P_((void));
337 void modes_op P_((void));
338 char *is_in_string P_((char *string, char *substring));
339 char *resolve_name P_((char *name));
340 int restrict_mode P_((void));
341 int unique_test P_((char *string, char *list[]));
342 void strings_init P_((void));
346 | allocate space here for the strings that will be in the menu
349 struct menu_entries modes_menu[] = {
350 {"", NULL, NULL, NULL, NULL, 0}, /* title */
351 {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */
352 {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/
353 {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */
354 {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */
355 {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/
356 {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */
357 {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/
358 {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */
359 {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */
360 {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
361 {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */
364 char *mode_strings[11];
366 #define NUM_MODES_ITEMS 10
368 struct menu_entries config_dump_menu[] = {
369 {"", NULL, NULL, NULL, NULL, 0},
370 {"", NULL, NULL, NULL, NULL, -1},
371 {"", NULL, NULL, NULL, NULL, -1},
372 {NULL, NULL, NULL, NULL, NULL, -1}
375 struct menu_entries leave_menu[] = {
376 {"", NULL, NULL, NULL, NULL, -1},
377 {"", NULL, NULL, NULL, finish, -1},
378 {"", NULL, NULL, quit, NULL, TRUE},
379 {NULL, NULL, NULL, NULL, NULL, -1}
386 struct menu_entries file_menu[] = {
387 {"", NULL, NULL, NULL, NULL, -1},
388 {"", NULL, NULL, file_op, NULL, READ_FILE},
389 {"", NULL, NULL, file_op, NULL, WRITE_FILE},
390 {"", NULL, NULL, file_op, NULL, SAVE_FILE},
391 {"", NULL, NULL, NULL, print_buffer, -1},
392 {NULL, NULL, NULL, NULL, NULL, -1}
395 struct menu_entries search_menu[] = {
396 {"", NULL, NULL, NULL, NULL, 0},
397 {"", NULL, NULL, NULL, search_prompt, -1},
398 {"", NULL, NULL, search, NULL, TRUE},
399 {NULL, NULL, NULL, NULL, NULL, -1}
402 struct menu_entries spell_menu[] = {
403 {"", NULL, NULL, NULL, NULL, -1},
404 {"", NULL, NULL, NULL, spell_op, -1},
405 {"", NULL, NULL, NULL, ispell_op, -1},
406 {NULL, NULL, NULL, NULL, NULL, -1}
409 struct menu_entries misc_menu[] = {
410 {"", NULL, NULL, NULL, NULL, -1},
411 {"", NULL, NULL, NULL, Format, -1},
412 {"", NULL, NULL, NULL, shell_op, -1},
413 {"", menu_op, spell_menu, NULL, NULL, -1},
414 {NULL, NULL, NULL, NULL, NULL, -1}
417 struct menu_entries main_menu[] = {
418 {"", NULL, NULL, NULL, NULL, -1},
419 {"", NULL, NULL, NULL, leave_op, -1},
420 {"", NULL, NULL, NULL, help, -1},
421 {"", menu_op, file_menu, NULL, NULL, -1},
422 {"", NULL, NULL, NULL, redraw, -1},
423 {"", NULL, NULL, NULL, modes_op, -1},
424 {"", menu_op, search_menu, NULL, NULL, -1},
425 {"", menu_op, misc_menu, NULL, NULL, -1},
426 {NULL, NULL, NULL, NULL, NULL, -1}
430 char *control_keys[5];
432 char *emacs_help_text[22];
433 char *emacs_control_keys[5];
435 char *command_strings[5];
437 char *init_strings[22];
441 #define max_alpha_char 36
444 | Declarations for strings for localization
447 char *com_win_message; /* to be shown in com_win if no info window */
448 char *no_file_string;
449 char *ascii_code_str;
450 char *printer_msg_str;
452 char *file_write_prompt_str;
453 char *file_read_prompt_str;
456 char *non_unique_cmd_msg;
459 char *current_file_str;
465 char *file_is_dir_msg;
469 char *file_read_fin_msg;
470 char *reading_file_msg;
472 char *file_read_lines_msg;
473 char *save_file_name_prompt;
474 char *file_not_saved_msg;
475 char *changes_made_prompt;
477 char *file_exists_prompt;
478 char *create_file_fail_msg;
479 char *writing_file_msg;
480 char *file_written_msg;
482 char *str_not_found_msg;
483 char *search_prompt_str;
486 char *menu_cancel_msg;
487 char *menu_size_err_msg;
488 char *press_any_key_msg;
490 char *formatting_msg;
491 char *shell_echo_msg;
492 char *spell_in_prog_msg;
494 char *restricted_msg;
527 char *NOEMACS_string;
528 char *conf_dump_err_msg;
529 char *conf_dump_success_msg;
530 char *conf_not_saved_msg;
531 char *ree_no_file_msg;
533 char *menu_too_lrg_msg;
534 char *more_above_str, *more_below_str;
535 char *separator = "===============================================================================";
537 char *chinese_cmd, *nochinese_cmd;
541 extern char *malloc();
542 extern char *realloc();
543 extern char *getenv();
544 FILE *fopen(); /* declaration for open function */
545 #endif /* HAS_STDLIB */
546 #endif /* __STDC__ */
549 main(argc, argv) /* beginning of main program */
555 for (counter = 1; counter < SIGUNUSED; counter++)
556 signal(counter, SIG_IGN);
558 signal(SIGCHLD, SIG_DFL);
559 signal(SIGSEGV, SIG_DFL);
560 signal(SIGINT, edit_abort);
561 d_char = malloc(3); /* provide a buffer for multi-byte chars */
562 d_word = malloc(150);
565 dlt_line = txtalloc();
566 dlt_line->line = d_line;
567 dlt_line->line_length = 0;
568 curr_line = first_line = txtalloc();
569 curr_line->line = point = malloc(10);
570 curr_line->line_length = 1;
571 curr_line->max_length = 10;
572 curr_line->prev_line = NULL;
573 curr_line->next_line = NULL;
574 curr_line->line_number = 1;
582 bit_bucket = fopen("/dev/null", "w");
584 gold = case_sen = FALSE;
589 get_options(argc, argv);
591 if (right_margin == 0)
592 right_margin = COLS - 1;
593 if (top_of_stack == NULL)
597 wmove(com_win, 0, 0);
599 wprintw(com_win, ree_no_file_msg);
603 wprintw(com_win, no_file_string);
609 clear_com_win = TRUE;
616 | display line and column information
622 wmove(info_win, 5, 0);
623 wprintw(info_win, separator);
624 wmove(info_win, 5, 5);
625 wprintw(info_win, "line %d col %d lines from top %d ",
626 curr_line->line_number, scr_horz, absolute_lin);
632 in = wgetch(text_win);
634 exit(0); /* without this exit ee will go into an
635 infinite loop if the network
642 clear_com_win = FALSE;
643 wmove(com_win, 0, 0);
647 wprintw(com_win, "%s", com_win_message);
654 else if ((in == '\10') || (in == 127))
656 in = 8; /* make sure key is set to backspace */
659 else if ((in > 31) || (in == 9))
661 else if ((in >= 0) && (in <= 31))
673 resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
674 int factor; /* resize factor */
675 struct text *rline; /* position in line */
678 unsigned char *rpoint;
681 rline->max_length += factor;
682 rpoint = rline->line = realloc(rline->line, rline->max_length );
683 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
689 insert(character) /* insert character into line */
690 int character; /* new character */
694 unsigned char *temp; /* temporary pointer */
695 unsigned char *temp2; /* temporary pointer */
697 if ((character == '\011') && (expand_tabs))
699 counter = len_char('\011', scr_horz);
700 for (; counter > 0; counter--)
707 if ((curr_line->max_length - curr_line->line_length) < 5)
708 point = resiz_line(10, curr_line, position);
709 curr_line->line_length++;
712 while (counter < curr_line->line_length) /* find end of line */
717 temp++; /* increase length of line by one */
721 *temp= *temp2; /* shift characters over by one */
724 *point = character; /* insert new character */
726 if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/
728 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
734 waddch(text_win, character);
735 scr_pos = ++scr_horz;
740 if ((observ_margins) && (right_margin < scr_pos))
743 while (scr_pos > right_margin)
747 while (position < counter)
754 for (value = 0; value < counter; value++)
759 if ((scr_horz - horiz_offset) > last_col)
762 midscreen(scr_vert, point);
765 if ((auto_format) && (character == ' ') && (!formatted))
767 else if ((character != ' ') && (character != '\t'))
770 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
774 delete(disp) /* delete character */
778 unsigned char *temp2;
779 struct text *temp_buff;
784 if (point != curr_line->line) /* if not at beginning of line */
788 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
794 position -= del_width;
796 curr_line->line_length -= del_width;
797 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
800 scr_horz -= del_width;
805 *d_char = *point; /* save deleted character */
809 d_char[1] = *(point + 1);
811 d_char[del_width] = '\0';
813 while (temp_pos <= curr_line->line_length)
820 if ((scr_horz < horiz_offset) && (horiz_offset > 0))
823 midscreen(scr_vert, point);
826 else if (curr_line->prev_line != NULL)
829 left(disp); /* go to previous line */
830 temp_buff = curr_line->next_line;
831 point = resiz_line(temp_buff->line_length, curr_line, position);
832 if (temp_buff->next_line != NULL)
833 temp_buff->next_line->prev_line = curr_line;
834 curr_line->next_line = temp_buff->next_line;
835 temp2 = temp_buff->line;
843 while (temp_pos < temp_buff->line_length)
845 curr_line->line_length++;
852 free(temp_buff->line);
854 temp_buff = curr_line;
855 temp_vert = scr_vert;
857 if (scr_vert < last_line)
859 wmove(text_win, scr_vert + 1, 0);
862 while ((temp_buff != NULL) && (temp_vert < last_line))
864 temp_buff = temp_buff->next_line;
867 if ((temp_vert == last_line) && (temp_buff != NULL))
869 tp = temp_buff->line;
870 wmove(text_win, last_line,0);
872 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
873 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
876 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
881 scanline(pos) /* find the proper horizontal position for the pointer */
887 ptr = curr_line->line;
894 temp += tabshift(temp);
895 else if ((*ptr >= 10) && (*ptr <= 31))
897 else if ((*ptr >= 32) && (*ptr < 127))
899 else if (*ptr == 127)
908 if ((scr_horz - horiz_offset) > last_col)
910 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
911 midscreen(scr_vert, point);
913 else if (scr_horz < horiz_offset)
915 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
916 midscreen(scr_vert, point);
921 tabshift(temp_int) /* give the number of spaces to shift */
926 leftover = ((temp_int + 1) % 8);
930 return (9 - leftover);
934 out_char(window, character, column) /* output non-printing character */
943 if (character == TAB)
945 i1 = tabshift(column);
947 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
953 else if ((character >= '\0') && (character < ' '))
955 string = table[(int) character];
957 else if ((character < 0) || (character >= 127))
959 if (character == 127)
963 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
968 waddch(window, (char)character );
974 waddch(window, (char)character);
977 for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
978 waddch(window, string[i2]);
979 return(strlen(string));
983 len_char(character, column) /* return the length of the character */
985 int column; /* the column must be known to provide spacing for tabs */
989 if (character == '\t')
990 length = tabshift(column);
991 else if ((character >= 0) && (character < 32))
993 else if ((character >= 32) && (character <= 126))
995 else if (character == 127)
997 else if (((character > 126) || (character < 0)) && (!eightbit))
1006 draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
1007 int vertical; /* current vertical position on screen */
1008 int horiz; /* current horizontal position on screen */
1009 unsigned char *ptr; /* pointer to line */
1010 int t_pos; /* current position (offset in bytes) from bol */
1011 int length; /* length (in bytes) of line */
1013 int d; /* partial length of special or tab char to display */
1014 unsigned char *temp; /* temporary pointer to position in line */
1015 int abs_column; /* offset in screen units from begin of line */
1016 int column; /* horizontal position on screen */
1017 int row; /* vertical position on screen */
1018 int posit; /* temporary position indicator within line */
1021 column = horiz - horiz_offset;
1028 wmove(text_win, row, 0);
1029 wclrtoeol(text_win);
1033 d = len_char(*temp, abs_column);
1039 wmove(text_win, row, column);
1040 wclrtoeol(text_win);
1041 while ((posit < length) && (column <= last_col))
1043 if ((*temp < 32) || (*temp >= 127))
1045 column += len_char(*temp, abs_column);
1046 abs_column += out_char(text_win, *temp, abs_column);
1052 waddch(text_win, *temp);
1057 if (column < last_col)
1058 wclrtoeol(text_win);
1059 wmove(text_win, vertical, (horiz - horiz_offset));
1063 insert_line(disp) /* insert new line */
1068 unsigned char *temp;
1069 unsigned char *extra;
1070 struct text *temp_nod;
1072 text_changes = TRUE;
1073 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1074 wclrtoeol(text_win);
1075 temp_nod= txtalloc();
1076 temp_nod->line = extra= malloc(10);
1077 temp_nod->line_length = 1;
1078 temp_nod->max_length = 10;
1079 temp_nod->line_number = curr_line->line_number + 1;
1080 temp_nod->next_line = curr_line->next_line;
1081 if (temp_nod->next_line != NULL)
1082 temp_nod->next_line->prev_line = temp_nod;
1083 temp_nod->prev_line = curr_line;
1084 curr_line->next_line = temp_nod;
1085 temp_pos2 = position;
1087 if (temp_pos2 < curr_line->line_length)
1090 while (temp_pos2 < curr_line->line_length)
1092 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1093 extra = resiz_line(10, temp_nod, temp_pos);
1094 temp_nod->line_length++;
1103 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1104 curr_line->line_length = 1 + temp - curr_line->line;
1106 curr_line->line_length = position;
1108 curr_line = temp_nod;
1111 point= curr_line->line;
1114 if (scr_vert < last_line)
1117 wclrtoeol(text_win);
1118 wmove(text_win, scr_vert, 0);
1119 winsertln(text_win);
1123 wmove(text_win, 0,0);
1124 wdeleteln(text_win);
1125 wmove(text_win, last_line,0);
1126 wclrtobot(text_win);
1128 scr_pos = scr_horz = 0;
1132 midscreen(scr_vert, point);
1134 draw_line(scr_vert, scr_horz, point, position,
1135 curr_line->line_length);
1139 struct text *txtalloc() /* allocate space for line structure */
1141 return((struct text *) malloc(sizeof( struct text)));
1144 struct files *name_alloc() /* allocate space for file name list node */
1146 return((struct files *) malloc(sizeof( struct files)));
1149 unsigned char *next_word(string) /* move to next word in string */
1150 unsigned char *string;
1152 while ((*string != '\0') && ((*string != 32) && (*string != 9)))
1154 while ((*string != '\0') && ((*string == 32) || (*string == 9)))
1160 prev_word() /* move to start of previous word in text */
1164 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1165 { /* if at the start of a word */
1166 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1169 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1171 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1173 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1181 control() /* use control for commands */
1185 if (in == 1) /* control a */
1187 string = get_string(ascii_code_str, TRUE);
1188 if (*string != '\0')
1191 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1196 else if (in == 2) /* control b */
1198 else if (in == 3) /* control c */
1202 else if (in == 4) /* control d */
1204 else if (in == 5) /* control e */
1206 else if (in == 6) /* control f */
1208 else if (in == 7) /* control g */
1210 else if (in == 8) /* control h */
1212 else if (in == 9) /* control i */
1214 else if (in == 10) /* control j */
1216 else if (in == 11) /* control k */
1218 else if (in == 12) /* control l */
1220 else if (in == 13) /* control m */
1222 else if (in == 14) /* control n */
1223 move_rel('d', max(5, (last_line - 5)));
1224 else if (in == 15) /* control o */
1226 else if (in == 16) /* control p */
1227 move_rel('u', max(5, (last_line - 5)));
1228 else if (in == 17) /* control q */
1230 else if (in == 18) /* control r */
1232 else if (in == 19) /* control s */
1234 else if (in == 20) /* control t */
1236 else if (in == 21) /* control u */
1238 else if (in == 22) /* control v */
1240 else if (in == 23) /* control w */
1242 else if (in == 24) /* control x */
1244 else if (in == 25) /* control y */
1246 else if (in == 26) /* control z */
1248 else if (in == 27) /* control [ (escape) */
1255 | Emacs control-key bindings
1263 if (in == 1) /* control a */
1265 else if (in == 2) /* control b */
1267 else if (in == 3) /* control c */
1271 else if (in == 4) /* control d */
1273 else if (in == 5) /* control e */
1275 else if (in == 6) /* control f */
1277 else if (in == 7) /* control g */
1278 move_rel('u', max(5, (last_line - 5)));
1279 else if (in == 8) /* control h */
1281 else if (in == 9) /* control i */
1283 else if (in == 10) /* control j */
1285 else if (in == 11) /* control k */
1287 else if (in == 12) /* control l */
1289 else if (in == 13) /* control m */
1291 else if (in == 14) /* control n */
1293 else if (in == 15) /* control o */
1295 string = get_string(ascii_code_str, TRUE);
1296 if (*string != '\0')
1299 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1304 else if (in == 16) /* control p */
1306 else if (in == 17) /* control q */
1308 else if (in == 18) /* control r */
1310 else if (in == 19) /* control s */
1312 else if (in == 20) /* control t */
1314 else if (in == 21) /* control u */
1316 else if (in == 22) /* control v */
1317 move_rel('d', max(5, (last_line - 5)));
1318 else if (in == 23) /* control w */
1320 else if (in == 24) /* control x */
1322 else if (in == 25) /* control y */
1324 else if (in == 26) /* control z */
1326 else if (in == 27) /* control [ (escape) */
1333 bottom() /* go to bottom of file */
1335 while (curr_line->next_line != NULL)
1337 curr_line = curr_line->next_line;
1340 point = curr_line->line;
1344 midscreen(last_line, point);
1349 top() /* go to top of file */
1351 while (curr_line->prev_line != NULL)
1353 curr_line = curr_line->prev_line;
1356 point = curr_line->line;
1360 midscreen(0, point);
1365 nextline() /* move pointers to start of next line */
1367 curr_line = curr_line->next_line;
1369 point = curr_line->line;
1371 if (scr_vert == last_line)
1373 wmove(text_win, 0,0);
1374 wdeleteln(text_win);
1375 wmove(text_win, last_line,0);
1376 wclrtobot(text_win);
1377 draw_line(last_line,0,point,1,curr_line->line_length);
1384 prevline() /* move pointers to start of previous line*/
1386 curr_line = curr_line->prev_line;
1388 point = curr_line->line;
1392 winsertln(text_win);
1393 draw_line(0,0,point,1,curr_line->line_length);
1397 while (position < curr_line->line_length)
1405 left(disp) /* move left one character */
1408 if (point != curr_line->line) /* if not at begin of line */
1410 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1418 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1421 else if (curr_line->prev_line != NULL)
1426 curr_line = curr_line->prev_line;
1427 point = curr_line->line + curr_line->line_length;
1428 position = curr_line->line_length;
1435 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1440 right(disp) /* move right one character */
1443 if (position < curr_line->line_length)
1445 if ((ee_chinese) && (*point > 127) &&
1446 ((curr_line->line_length - position) >= 2))
1454 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1457 else if (curr_line->next_line != NULL)
1462 curr_line = curr_line->next_line;
1463 point = curr_line->line;
1468 scr_pos = scr_horz = 0;
1472 midscreen(scr_vert, point);
1474 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1480 find_pos() /* move to the same column as on other line */
1484 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1487 scr_horz += tabshift(scr_horz);
1488 else if (*point < ' ')
1490 else if ((ee_chinese) && (*point > 127) &&
1491 ((curr_line->line_length - position) >= 2))
1502 if ((scr_horz - horiz_offset) > last_col)
1504 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1505 midscreen(scr_vert, point);
1507 else if (scr_horz < horiz_offset)
1509 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1510 midscreen(scr_vert, point);
1512 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1516 up() /* move up one line */
1518 if (curr_line->prev_line != NULL)
1521 point = curr_line->line;
1527 down() /* move down one line */
1529 if (curr_line->next_line != NULL)
1537 function_key() /* process function key */
1541 else if (in == KEY_RIGHT)
1543 else if (in == KEY_HOME)
1545 else if (in == KEY_END)
1547 else if (in == KEY_UP)
1549 else if (in == KEY_DOWN)
1551 else if (in == KEY_NPAGE)
1552 move_rel('d', max( 5, (last_line - 5)));
1553 else if (in == KEY_PPAGE)
1554 move_rel('u', max(5, (last_line - 5)));
1555 else if (in == KEY_DL)
1557 else if (in == KEY_DC)
1559 else if (in == KEY_BACKSPACE)
1561 else if (in == KEY_IL)
1562 { /* insert a line before current line */
1566 else if (in == KEY_F(1))
1568 else if (in == KEY_F(2))
1578 else if (in == KEY_F(3))
1588 else if (in == KEY_F(4))
1594 midscreen(scr_vert, point);
1599 else if (in == KEY_F(5))
1609 else if (in == KEY_F(6))
1619 else if (in == KEY_F(7))
1629 else if (in == KEY_F(8))
1646 sprintf(buffer, ">!%s", print_command);
1647 wmove(com_win, 0, 0);
1649 wprintw(com_win, printer_msg_str, print_command);
1660 info_type = COMMANDS;
1662 cmd_str = get_string(command_str, TRUE);
1663 if ((result = unique_test(cmd_str, commands)) != 1)
1666 wmove(com_win, 0, 0);
1668 wprintw(com_win, unkn_cmd_str, cmd_str);
1670 wprintw(com_win, non_unique_cmd_msg);
1674 info_type = CONTROL_KEYS;
1677 if (cmd_str != NULL)
1683 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1684 info_type = CONTROL_KEYS;
1686 if (cmd_str != NULL)
1691 command(cmd_str1) /* process commands from keyboard */
1694 char *cmd_str2 = NULL;
1695 char *cmd_str = cmd_str1;
1697 clear_com_win = TRUE;
1698 if (compare(cmd_str, HELP, FALSE))
1700 else if (compare(cmd_str, WRITE, FALSE))
1702 if (restrict_mode())
1706 cmd_str = next_word(cmd_str);
1707 if (*cmd_str == '\0')
1709 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1711 tmp_file = resolve_name(cmd_str);
1712 write_file(tmp_file, 1);
1713 if (tmp_file != cmd_str)
1716 else if (compare(cmd_str, READ, FALSE))
1718 if (restrict_mode())
1722 cmd_str = next_word(cmd_str);
1723 if (*cmd_str == '\0')
1725 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1729 tmp_file = resolve_name(cmd_str);
1731 if (tmp_file != cmd_str)
1734 else if (compare(cmd_str, LINE, FALSE))
1736 wmove(com_win, 0, 0);
1738 wprintw(com_win, line_num_str, curr_line->line_number);
1739 wprintw(com_win, line_len_str, curr_line->line_length);
1741 else if (compare(cmd_str, FILE_str, FALSE))
1743 wmove(com_win, 0, 0);
1745 if (in_file_name == NULL)
1746 wprintw(com_win, no_file_string);
1748 wprintw(com_win, current_file_str, in_file_name);
1750 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1752 else if (compare(cmd_str, CHARACTER, FALSE))
1754 wmove(com_win, 0, 0);
1756 wprintw(com_win, char_str, *point);
1758 else if (compare(cmd_str, REDRAW, FALSE))
1760 else if (compare(cmd_str, RESEQUENCE, FALSE))
1762 tmp_line = first_line->next_line;
1763 while (tmp_line != NULL)
1765 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1766 tmp_line = tmp_line->next_line;
1769 else if (compare(cmd_str, AUTHOR, FALSE))
1771 wmove(com_win, 0, 0);
1773 wprintw(com_win, "written by Hugh Mahon");
1775 else if (compare(cmd_str, VERSION, FALSE))
1777 wmove(com_win, 0, 0);
1779 wprintw(com_win, "%s", version);
1781 else if (compare(cmd_str, CASE, FALSE))
1783 else if (compare(cmd_str, NOCASE, FALSE))
1785 else if (compare(cmd_str, EXPAND, FALSE))
1787 else if (compare(cmd_str, NOEXPAND, FALSE))
1788 expand_tabs = FALSE;
1789 else if (compare(cmd_str, Exit_string, FALSE))
1791 else if (compare(cmd_str, chinese_cmd, FALSE))
1795 nc_setattrib(A_NC_BIG5);
1798 else if (compare(cmd_str, nochinese_cmd, FALSE))
1802 nc_clearattrib(A_NC_BIG5);
1805 else if (compare(cmd_str, QUIT_string, FALSE))
1807 else if (*cmd_str == '!')
1810 if ((*cmd_str == ' ') || (*cmd_str == 9))
1811 cmd_str = next_word(cmd_str);
1812 sh_command(cmd_str);
1814 else if ((*cmd_str == '<') && (!in_pipe))
1819 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1820 cmd_str = next_word(cmd_str);
1825 else if ((*cmd_str == '>') && (!out_pipe))
1829 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1830 cmd_str = next_word(cmd_str);
1836 wmove(com_win, 0, 0);
1838 wprintw(com_win, unkn_cmd_str, cmd_str);
1840 if (cmd_str2 != NULL)
1845 scan(line, offset, column) /* determine horizontal position for get_string */
1860 j += len_char(*stemp, j);
1867 get_string(prompt, advance) /* read string from input on command line */
1868 char *prompt; /* string containing user prompt message */
1869 int advance; /* if true, skip leading spaces and tabs */
1876 int g_horz, g_position, g_pos;
1879 g_point = tmp_string = malloc(512);
1882 waddstr(com_win, prompt);
1884 nam_str = tmp_string;
1885 clear_com_win = TRUE;
1886 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1891 in = wgetch(com_win);
1894 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1898 g_horz = scan(g_point, g_pos, g_position);
1899 tmp_int = tmp_int - g_horz;
1900 for (; 0 < tmp_int; tmp_int--)
1902 if ((g_horz+tmp_int) < (last_col - 1))
1904 waddch(com_win, '\010');
1905 waddch(com_win, ' ');
1906 waddch(com_win, '\010');
1911 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1913 if (in == '\026') /* control-v, accept next character verbatim */
1914 { /* allows entry of ^m, ^j, and ^h */
1916 in = wgetch(com_win);
1922 if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1)))
1923 g_horz += out_char(com_win, in, g_horz);
1927 if (g_horz < (last_col - 1))
1928 waddch(com_win, in);
1935 } while ((in != '\n') && (in != '\r'));
1937 nam_str = tmp_string;
1938 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1939 nam_str = next_word(nam_str);
1940 string = malloc(strlen(nam_str) + 1);
1941 strcpy(string, nam_str);
1948 compare(string1, string2, sensitive) /* compare two strings */
1961 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
1968 if (*strng1 != *strng2)
1973 if (toupper(*strng1) != toupper(*strng2))
1978 if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
1992 char direction = '\0';
1993 struct text *t_line;
1997 while ((*ptr >='0') && (*ptr <= '9'))
1999 i= i * 10 + (*ptr - '0');
2005 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
2008 t_line = t_line->prev_line;
2011 while ((t_line->line_number < number) && (t_line->next_line != NULL))
2015 t_line = t_line->next_line;
2017 if ((i < 30) && (i > 0))
2019 move_rel(direction, i);
2023 if (direction != 'd')
2032 point = curr_line->line;
2034 midscreen((last_line / 2), point);
2037 wmove(com_win, 0, 0);
2039 wprintw(com_win, line_num_str, curr_line->line_number);
2040 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2044 midscreen(line, pnt) /* put current line in middle of screen */
2048 struct text *mid_line;
2051 line = min(line, last_line);
2052 mid_line = curr_line;
2053 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2054 curr_line = curr_line->prev_line;
2055 scr_vert = scr_horz = 0;
2056 wmove(text_win, 0, 0);
2059 curr_line = mid_line;
2061 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2065 get_options(numargs, arguments) /* get arguments from command line */
2071 struct files *temp_names = NULL;
2074 int no_more_opts = FALSE;
2077 | see if editor was invoked as 'ree' (restricted mode)
2080 if (!(name = strrchr(arguments[0], '/')))
2081 name = arguments[0];
2084 if (!strcmp(name, "ree"))
2087 top_of_stack = NULL;
2091 while ((count < numargs)&& (!no_more_opts))
2093 buff = arguments[count];
2094 if (!strcmp("-i", buff))
2096 info_window = FALSE;
2098 else if (!strcmp("-e", buff))
2100 expand_tabs = FALSE;
2102 else if (!strcmp("-h", buff))
2106 else if (!strcmp("-?", buff))
2108 fprintf(stderr, usage0, arguments[0]);
2109 fprintf(stderr, usage1);
2110 fprintf(stderr, usage2);
2111 fprintf(stderr, usage3);
2112 fprintf(stderr, usage4);
2115 else if ((*buff == '+') && (start_at_line == NULL))
2118 start_at_line = buff;
2120 else if (!(strcmp("--", buff)))
2121 no_more_opts = TRUE;
2125 no_more_opts = TRUE;
2129 while (count < numargs)
2131 buff = arguments[count];
2132 if (top_of_stack == NULL)
2134 temp_names = top_of_stack = name_alloc();
2138 temp_names->next_name = name_alloc();
2139 temp_names = temp_names->next_name;
2141 ptr = temp_names->name = malloc(strlen(buff) + 1);
2142 while (*buff != '\0')
2149 temp_names->next_name = NULL;
2157 check_fp() /* open or close files according to flags */
2163 clear_com_win = TRUE;
2164 tmp_vert = scr_vert;
2165 tmp_horz = scr_horz;
2166 tmp_line = curr_line;
2169 in_file_name = tmp_file = top_of_stack->name;
2170 top_of_stack = top_of_stack->next_name;
2172 temp = stat(tmp_file, &buf);
2173 buf.st_mode &= ~07777;
2174 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2176 wprintw(com_win, file_is_dir_msg, tmp_file);
2186 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2188 wmove(com_win, 0, 0);
2191 wprintw(com_win, new_file_msg, tmp_file);
2193 wprintw(com_win, cant_open_msg, tmp_file);
2195 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2205 line_num = curr_line->line_number;
2206 scr_vert = tmp_vert;
2207 scr_horz = tmp_horz;
2209 curr_line= first_line;
2211 curr_line = tmp_line;
2212 point = curr_line->line;
2217 if (start_at_line != NULL)
2219 line_num = atoi(start_at_line) - 1;
2220 move_rel('d', line_num);
2222 start_at_line = NULL;
2227 wmove(com_win, 0, 0);
2229 text_changes = TRUE;
2230 if ((tmp_file != NULL) && (*tmp_file != '\0'))
2231 wprintw(com_win, file_read_fin_msg, tmp_file);
2234 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2239 get_file(file_name) /* read specified file into current buffer */
2242 int can_read; /* file has at least one character */
2243 int length; /* length of line read by read */
2244 int append; /* should text be appended to current line */
2245 struct text *temp_line;
2246 char ro_flag = FALSE;
2248 if (recv_file) /* if reading a file */
2250 wmove(com_win, 0, 0);
2252 wprintw(com_win, reading_file_msg, file_name);
2253 if (access(file_name, 2)) /* check permission to write */
2255 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2257 wprintw(com_win, read_only_msg);
2263 if (curr_line->line_length > 1) /* if current line is not blank */
2271 can_read = FALSE; /* test if file has any characters */
2272 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2274 can_read = TRUE; /* if set file has at least 1 character */
2275 get_line(length, in_string, &append);
2277 if ((can_read) && (curr_line->line_length == 1))
2279 temp_line = curr_line->prev_line;
2280 temp_line->next_line = curr_line->next_line;
2281 if (temp_line->next_line != NULL)
2282 temp_line->next_line->prev_line = temp_line;
2283 if (curr_line->line != NULL)
2284 free(curr_line->line);
2286 curr_line = temp_line;
2288 if (input_file) /* if this is the file to be edited display number of lines */
2290 wmove(com_win, 0, 0);
2292 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2294 wprintw(com_win, read_only_msg);
2297 else if (can_read) /* not input_file and file is non-zero size */
2298 text_changes = TRUE;
2300 if (recv_file) /* if reading a file */
2307 get_line(length, in_string, append) /* read string and split into lines */
2308 int length; /* length of string read by read */
2309 unsigned char *in_string; /* string read by read */
2310 int *append; /* TRUE if must append more text to end of current line */
2312 unsigned char *str1;
2313 unsigned char *str2;
2314 int num; /* offset from start of string */
2315 int char_count; /* length of new line (or added portion */
2316 int temp_counter; /* temporary counter value */
2317 struct text *tline; /* temporary pointer to new line */
2318 int first_time; /* if TRUE, the first time through the loop */
2323 while (num < length)
2337 /* find end of line */
2338 while ((*str2 != '\n') && (num < length))
2344 if (!(*append)) /* if not append to current line, insert new one */
2346 tline = txtalloc(); /* allocate data structure for next line */
2347 tline->line_number = curr_line->line_number + 1;
2348 tline->next_line = curr_line->next_line;
2349 tline->prev_line = curr_line;
2350 curr_line->next_line = tline;
2351 if (tline->next_line != NULL)
2352 tline->next_line->prev_line = tline;
2354 curr_line->line = point = (unsigned char *) malloc(char_count);
2355 curr_line->line_length = char_count;
2356 curr_line->max_length = char_count;
2360 point = resiz_line(char_count, curr_line, curr_line->line_length);
2361 curr_line->line_length += (char_count - 1);
2363 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2371 if ((num == length) && (*str2 != '\n'))
2377 draw_screen() /* redraw the screen from current postion */
2379 struct text *temp_line;
2380 unsigned char *line_out;
2383 temp_line = curr_line;
2384 temp_vert = scr_vert;
2385 wclrtobot(text_win);
2386 while ((temp_line != NULL) && (temp_vert <= last_line))
2388 line_out = temp_line->line;
2389 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2391 temp_line = temp_line->next_line;
2393 wmove(text_win, temp_vert, 0);
2394 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2398 finish() /* prepare to exit edit session */
2400 char *file_name = in_file_name;
2403 | changes made here should be reflected in the 'save'
2404 | portion of file_op()
2407 if ((file_name == NULL) || (*file_name == '\0'))
2408 file_name = get_string(save_file_name_prompt, TRUE);
2410 if ((file_name == NULL) || (*file_name == '\0'))
2412 wmove(com_win, 0, 0);
2413 wprintw(com_win, file_not_saved_msg);
2416 clear_com_win = TRUE;
2420 tmp_file = resolve_name(file_name);
2421 if (tmp_file != file_name)
2424 file_name = tmp_file;
2427 if (write_file(file_name, 1))
2429 text_changes = FALSE;
2435 quit(noverify) /* exit editor */
2442 if ((text_changes) && (!noverify))
2444 ans = get_string(changes_made_prompt, TRUE);
2445 if (toupper(*ans) == toupper(*yes_char))
2446 text_changes = FALSE;
2451 if (top_of_stack == NULL)
2485 while (curr_line->next_line != NULL)
2486 curr_line = curr_line->next_line;
2487 while (curr_line != first_line)
2489 free(curr_line->line);
2490 curr_line = curr_line->prev_line;
2492 free(curr_line->next_line);
2494 curr_line->next_line = NULL;
2495 *curr_line->line = '\0';
2496 curr_line->line_length = 1;
2497 curr_line->line_number = 1;
2498 point = curr_line->line;
2499 scr_pos = scr_vert = scr_horz = 0;
2504 write_file(file_name, warn_if_exists)
2510 struct text *out_line;
2513 int write_flag = TRUE;
2516 if (warn_if_exists &&
2517 ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
2519 if ((temp_fp = fopen(file_name, "r")))
2521 tmp_point = get_string(file_exists_prompt, TRUE);
2522 if (toupper(*tmp_point) == toupper(*yes_char))
2531 clear_com_win = TRUE;
2535 if ((temp_fp = fopen(file_name, "w")) == NULL)
2537 clear_com_win = TRUE;
2540 wprintw(com_win, create_file_fail_msg, file_name);
2548 wprintw(com_win, writing_file_msg, file_name);
2551 out_line = first_line;
2552 while (out_line != NULL)
2555 tmp_point= out_line->line;
2556 while (temp_pos < out_line->line_length)
2558 putc(*tmp_point, temp_fp);
2562 charac += out_line->line_length;
2563 out_line = out_line->next_line;
2570 wprintw(com_win, file_written_msg, file_name, lines, charac);
2580 search(display_message) /* search for string in srch_str */
2581 int display_message;
2587 if ((srch_str == NULL) || (*srch_str == '\0'))
2589 if (display_message)
2591 wmove(com_win, 0, 0);
2593 wprintw(com_win, searching_msg);
2595 clear_com_win = TRUE;
2599 srch_line = curr_line;
2601 if (position < curr_line->line_length)
2603 iter = position + 1;
2604 while ((!found) && (srch_line != NULL))
2606 while ((iter < srch_line->line_length) && (!found))
2609 if (case_sen) /* if case sensitive */
2612 while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
2619 else /* if not case sensitive */
2621 srch_3 = u_srch_str;
2622 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
2629 if (!((*srch_3 == '\0') && (found)))
2632 if (iter < srch_line->line_length)
2639 srch_line = srch_line->next_line;
2640 if (srch_line != NULL)
2641 srch_1 = srch_line->line;
2648 if (display_message)
2650 wmove(com_win, 0, 0);
2654 if (lines_moved == 0)
2656 while (position < iter)
2661 if (lines_moved < 30)
2663 move_rel('d', lines_moved);
2664 while (position < iter)
2669 absolute_lin += lines_moved;
2670 curr_line = srch_line;
2675 midscreen((last_line / 2), point);
2681 if (display_message)
2683 wmove(com_win, 0, 0);
2685 wprintw(com_win, str_not_found_msg, srch_str);
2688 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2694 search_prompt() /* prompt and read search string (srch_str) */
2696 if (srch_str != NULL)
2698 if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
2700 srch_str = get_string(search_prompt_str, FALSE);
2703 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2704 while (*srch_3 != '\0')
2706 *srch_1 = toupper(*srch_3);
2715 del_char() /* delete current character */
2717 in = 8; /* backspace */
2718 if (position < curr_line->line_length) /* if not end of line */
2720 if ((ee_chinese) && (*point > 127) &&
2721 ((curr_line->line_length - position) >= 2))
2739 undel_char() /* undelete last deleted character */
2741 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2747 if (d_char[1] != '\0')
2756 del_word() /* delete word in front of cursor */
2760 unsigned char *d_word2;
2761 unsigned char *d_word3;
2762 unsigned char tmp_char[3];
2766 d_word = malloc(curr_line->line_length);
2767 tmp_char[0] = d_char[0];
2768 tmp_char[1] = d_char[1];
2769 tmp_char[2] = d_char[2];
2773 while ((tposit < curr_line->line_length) &&
2774 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2777 *d_word2 = *d_word3;
2781 while ((tposit < curr_line->line_length) &&
2782 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2785 *d_word2 = *d_word3;
2790 d_wrd_len = difference = d_word2 - d_word;
2792 while (tposit < curr_line->line_length)
2795 *d_word2 = *d_word3;
2799 curr_line->line_length -= difference;
2801 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2802 d_char[0] = tmp_char[0];
2803 d_char[1] = tmp_char[1];
2804 d_char[2] = tmp_char[2];
2805 text_changes = TRUE;
2810 undel_word() /* undelete last deleted word */
2814 unsigned char *tmp_old_ptr;
2815 unsigned char *tmp_space;
2816 unsigned char *tmp_ptr;
2817 unsigned char *d_word_ptr;
2820 | resize line to handle undeleted word
2822 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2823 point = resiz_line(d_wrd_len, curr_line, position);
2824 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2825 d_word_ptr = d_word;
2828 | copy d_word contents into temp space
2830 while (temp <= d_wrd_len)
2833 *tmp_ptr = *d_word_ptr;
2837 tmp_old_ptr = point;
2840 | copy contents of line from curent position to eol into
2843 while (tposit < curr_line->line_length)
2847 *tmp_ptr = *tmp_old_ptr;
2851 curr_line->line_length += d_wrd_len;
2852 tmp_old_ptr = point;
2854 tmp_ptr = tmp_space;
2857 | now copy contents from temp space back to original line
2859 while (tposit < temp)
2862 *tmp_old_ptr = *tmp_ptr;
2866 *tmp_old_ptr = '\0';
2868 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2872 del_line() /* delete from cursor to end of line */
2880 d_line = malloc(curr_line->line_length);
2884 while (tposit < curr_line->line_length)
2891 dlt_line->line_length = 1 + tposit - position;
2894 curr_line->line_length = position;
2895 wclrtoeol(text_win);
2896 if (curr_line->next_line != NULL)
2901 text_changes = TRUE;
2905 undel_line() /* undelete last deleted line */
2911 if (dlt_line->line_length == 0)
2916 point = resiz_line(dlt_line->line_length, curr_line, position);
2917 curr_line->line_length += dlt_line->line_length - 1;
2921 while (tposit < dlt_line->line_length)
2929 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2933 adv_word() /* advance to next word */
2935 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2937 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2942 move_rel(direction, lines) /* move relative to current line */
2949 if (direction == 'u')
2952 while (position > 1)
2954 for (i = 0; i < lines; i++)
2958 if ((last_line > 5) && ( scr_vert < 4))
2961 tmp_line = curr_line;
2962 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2966 scr_vert = scr_vert + i;
2967 curr_line = tmp_line;
2975 if ((position != 1) && (curr_line->next_line != NULL))
2978 scr_pos = scr_horz = 0;
2982 midscreen(scr_vert, point);
2987 for (i = 1; i < lines; i++)
2991 if ((last_line > 10) && (scr_vert > (last_line - 5)))
2994 tmp_line = curr_line;
2995 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
3000 scr_vert = scr_vert - i;
3001 curr_line = tmp_line;
3006 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
3010 eol() /* go to end of line */
3012 if (position < curr_line->line_length)
3014 while (position < curr_line->line_length)
3017 else if (curr_line->next_line != NULL)
3020 while (position < curr_line->line_length)
3026 bol() /* move to beginning of line */
3028 if (point != curr_line->line)
3030 while (point != curr_line->line)
3033 else if (curr_line->prev_line != NULL)
3041 adv_line() /* advance to beginning of next line */
3043 if ((point != curr_line->line) || (scr_pos > 0))
3045 while (position < curr_line->line_length)
3049 else if (curr_line->next_line != NULL)
3059 struct text *tmpline = first_line;
3062 while ((tmpline != NULL) && (tmpline != curr_line))
3065 tmpline = tmpline->next_line;
3071 sh_command(string) /* execute shell command */
3072 char *string; /* string containing user command */
3076 char *path; /* directory path to executable */
3077 int parent; /* zero if child, child's pid if parent */
3080 struct text *line_holder;
3082 if (restrict_mode())
3087 if (!(path = getenv("SHELL")))
3089 last_slash = temp_point = path;
3090 while (*temp_point != '\0')
3092 if (*temp_point == '/')
3093 last_slash = ++temp_point;
3099 | if in_pipe is true, then output of the shell operation will be
3100 | read by the editor, and curses doesn't need to be turned off
3105 keypad(com_win, FALSE);
3106 keypad(text_win, FALSE);
3119 pipe(pipe_in); /* create a pipe */
3121 if (!parent) /* if the child */
3124 | child process which will fork and exec shell command (if shell output is
3125 | to be read by editor)
3129 | redirect stdout to pipe
3131 temp_stdout = dup(1);
3135 | redirect stderr to pipe
3137 temp_stderr = dup(2);
3142 | child will now continue down 'if (!in_pipe)'
3146 else /* if the parent */
3149 | prepare editor to read from the pipe
3151 signal(SIGCHLD, SIG_IGN);
3152 line_holder = curr_line;
3153 tmp_vert = scr_vert;
3155 get_fd = pipe_in[0];
3158 scr_vert = tmp_vert;
3159 scr_horz = scr_pos = 0;
3161 curr_line = line_holder;
3163 point = curr_line->line;
3165 signal(SIGCHLD, SIG_DFL);
3167 | since flag "in_pipe" is still TRUE, the path which waits for the child
3168 | process to die will be avoided.
3169 | (the pipe is closed, no more output can be expected)
3175 signal(SIGINT, SIG_IGN);
3181 | fork process which will exec command
3184 if (!parent) /* if the child */
3191 | prepare the child process (soon to exec a shell command) to read from the
3192 | pipe (which will be output from the editor's buffer)
3199 for (value = 1; value < 24; value++)
3200 signal(value, SIG_DFL);
3201 execl(path, last_slash, "-c", string, NULL);
3202 fprintf(stderr, exec_err_msg, path);
3205 else /* if the parent */
3210 | output the contents of the buffer to the pipe (to be read by the
3211 | process forked and exec'd above as stdin)
3214 line_holder = first_line;
3215 while (line_holder != NULL)
3217 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3218 write(pipe_out[1], "\n", 1);
3219 line_holder = line_holder->next_line;
3226 return_val = wait((int *) 0);
3228 while ((return_val != parent) && (return_val != -1));
3230 | if this process is actually the child of the editor, exit. Here's how it
3232 | The editor forks a process. If output must be sent to the command to be
3233 | exec'd another process is forked, and that process (the child's child)
3234 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3235 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3236 | If this is the editor process, shell_fork will be true, otherwise this is
3237 | the child of the edit process.
3242 signal(SIGINT, edit_abort);
3246 printf(continue_msg);
3248 while ((in = getchar()) != '\n')
3258 keypad(text_win, TRUE);
3259 keypad(com_win, TRUE);
3261 clearok(info_win, TRUE);
3268 set_up_term() /* set up the terminal for operating with ae */
3270 if (!curses_initialized)
3277 curses_initialized = TRUE;
3280 if (((LINES > 15) && (COLS >= 80)) && info_window)
3281 last_line = LINES - 8;
3284 info_window = FALSE;
3285 last_line = LINES - 2;
3288 idlok(stdscr, TRUE);
3289 com_win = newwin(1, COLS, (LINES - 1), 0);
3290 keypad(com_win, TRUE);
3291 idlok(com_win, TRUE);
3294 text_win = newwin((LINES - 1), COLS, 0, 0);
3296 text_win = newwin((LINES - 7), COLS, 6, 0);
3297 keypad(text_win, TRUE);
3298 idlok(text_win, TRUE);
3300 help_win = newwin((LINES - 1), COLS, 0, 0);
3301 keypad(help_win, TRUE);
3302 idlok(help_win, TRUE);
3305 info_type = CONTROL_KEYS;
3306 info_win = newwin(6, COLS, 0, 0);
3311 last_col = COLS - 1;
3312 local_LINES = LINES;
3317 nc_setattrib(A_NC_BIG5);
3325 if ((LINES == local_LINES) && (COLS == local_COLS))
3338 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3342 struct menu_entries menu_list[];
3345 int max_width, max_height;
3352 int top_offset; /* offset from top where menu items start */
3353 int vert_pos; /* vertical position */
3354 int vert_size; /* vertical size for menu list item display */
3355 int off_start = 1; /* offset from start of menu items to start display */
3359 | determine number and width of menu items
3363 while (menu_list[list_size + 1].item_string != NULL)
3366 for (counter = 0; counter <= list_size; counter++)
3368 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3372 max_width = max(max_width, strlen(menu_cancel_msg));
3373 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3377 | make sure that window is large enough to handle menu
3378 | if not, print error message and return to calling function
3381 if (max_width > COLS)
3383 wmove(com_win, 0, 0);
3385 wprintw(com_win, menu_too_lrg_msg);
3387 clear_com_win = TRUE;
3393 if (list_size > LINES)
3396 if (max_height > 11)
3397 vert_size = max_height - 8;
3399 vert_size = max_height;
3403 vert_size = list_size;
3404 max_height = list_size;
3407 if (LINES >= (vert_size + 8))
3409 if (menu_list[0].argument != MENU_WARN)
3410 max_height = vert_size + 8;
3412 max_height = vert_size + 7;
3415 x_off = (COLS - max_width) / 2;
3416 y_off = (LINES - max_height - 1) / 2;
3417 temp_win = newwin(max_height, max_width, y_off, x_off);
3418 keypad(temp_win, TRUE);
3420 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3427 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3429 wmove(temp_win, (counter + top_offset - off_start), 3);
3432 in = wgetch(temp_win);
3437 if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
3438 ((input >= '0') && (input <= '9')))
3440 if ((tolower(input) >= 'a') && (tolower(input) <= 'z'))
3442 temp = 1 + tolower(input) - 'a';
3444 else if ((input >= '0') && (input <= '9'))
3446 temp = (2 + 'z' - 'a') + (input - '0');
3449 if (temp <= list_size)
3459 case ' ': /* space */
3460 case '\004': /* ^d, down */
3464 if (counter > list_size)
3467 case '\010': /* ^h, backspace*/
3468 case '\025': /* ^u, up */
3469 case 127: /* ^?, delete */
3475 counter = list_size;
3477 case '\033': /* escape key */
3478 if (menu_list[0].argument != MENU_WARN)
3481 case '\014': /* ^l */
3482 case '\022': /* ^r, redraw */
3483 paint_menu(menu_list, max_width, max_height,
3484 list_size, top_offset, temp_win,
3485 off_start, vert_size);
3492 if (((list_size - off_start) >= (vert_size - 1)) &&
3493 (counter > (off_start + vert_size - 3)) &&
3496 if (counter == list_size)
3497 off_start = (list_size - vert_size) + 2;
3501 paint_menu(menu_list, max_width, max_height,
3502 list_size, top_offset, temp_win, off_start,
3505 else if ((list_size != vert_size) &&
3506 (counter > (off_start + vert_size - 2)))
3508 if (counter == list_size)
3509 off_start = 2 + (list_size - vert_size);
3510 else if (off_start == 1)
3515 paint_menu(menu_list, max_width, max_height,
3516 list_size, top_offset, temp_win, off_start,
3519 else if (counter < off_start)
3524 off_start = counter;
3526 paint_menu(menu_list, max_width, max_height,
3527 list_size, top_offset, temp_win, off_start,
3531 while ((input != '\r') && (input != '\n') && (counter != 0));
3537 if ((menu_list[counter].procedure != NULL) ||
3538 (menu_list[counter].iprocedure != NULL) ||
3539 (menu_list[counter].nprocedure != NULL))
3541 if (menu_list[counter].argument != -1)
3542 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3543 else if (menu_list[counter].ptr_argument != NULL)
3544 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3546 (*menu_list[counter].nprocedure)();
3557 paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
3558 off_start, vert_size)
3559 struct menu_entries menu_list[];
3560 int max_width, max_height, list_size, top_offset;
3562 int off_start, vert_size;
3564 int counter, temp_int;
3569 | output top and bottom portions of menu box only if window
3573 if (max_height > vert_size)
3575 wmove(menu_win, 1, 1);
3577 wstandout(menu_win);
3578 waddch(menu_win, '+');
3579 for (counter = 0; counter < (max_width - 4); counter++)
3580 waddch(menu_win, '-');
3581 waddch(menu_win, '+');
3583 wmove(menu_win, (max_height - 2), 1);
3584 waddch(menu_win, '+');
3585 for (counter = 0; counter < (max_width - 4); counter++)
3586 waddch(menu_win, '-');
3587 waddch(menu_win, '+');
3588 wstandend(menu_win);
3589 wmove(menu_win, 2, 3);
3590 waddstr(menu_win, menu_list[0].item_string);
3591 wmove(menu_win, (max_height - 3), 3);
3592 if (menu_list[0].argument != MENU_WARN)
3593 waddstr(menu_win, menu_cancel_msg);
3596 wstandout(menu_win);
3598 for (counter = 0; counter < (vert_size + top_offset); counter++)
3600 if (top_offset == 4)
3602 temp_int = counter + 2;
3607 wmove(menu_win, temp_int, 1);
3608 waddch(menu_win, '|');
3609 wmove(menu_win, temp_int, (max_width - 2));
3610 waddch(menu_win, '|');
3612 wstandend(menu_win);
3614 if (list_size > vert_size)
3619 wmove(menu_win, top_offset, 3);
3620 waddstr(menu_win, more_above_str);
3625 for (counter = off_start;
3626 ((temp_int + counter - off_start) < (vert_size - 1));
3629 wmove(menu_win, (top_offset + temp_int +
3630 (counter - off_start)), 3);
3632 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3633 waddstr(menu_win, menu_list[counter].item_string);
3636 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3638 if (counter == list_size)
3641 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3642 wprintw(menu_win, menu_list[counter].item_string);
3645 wprintw(menu_win, more_below_str);
3649 for (counter = 1; counter <= list_size; counter++)
3651 wmove(menu_win, (top_offset + counter - 1), 3);
3653 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3654 waddstr(menu_win, menu_list[counter].item_string);
3665 clearok(help_win, TRUE);
3666 for (counter = 0; counter < 22; counter++)
3668 wmove(help_win, counter, 0);
3669 waddstr(help_win, (emacs_keys_mode) ?
3670 emacs_help_text[counter] : help_text[counter]);
3674 wmove(com_win, 0, 0);
3675 wprintw(com_win, press_any_key_msg);
3677 counter = wgetch(com_win);
3681 wmove(com_win, 0, 0);
3697 for (counter = 0; counter < 5; counter++)
3699 wmove(info_win, counter, 0);
3700 wclrtoeol(info_win);
3701 if (info_type == CONTROL_KEYS)
3702 waddstr(info_win, (emacs_keys_mode) ?
3703 emacs_control_keys[counter] : control_keys[counter]);
3704 else if (info_type == COMMANDS)
3705 waddstr(info_win, command_strings[counter]);
3707 wmove(info_win, 5, 0);
3709 wstandout(info_win);
3710 waddstr(info_win, separator);
3711 wstandend(info_win);
3722 info_window = FALSE;
3723 last_line = LINES - 2;
3724 text_win = newwin((LINES - 1), COLS, 0, 0);
3725 keypad(text_win, TRUE);
3726 idlok(text_win, TRUE);
3727 clearok(text_win, TRUE);
3728 midscreen(scr_vert, point);
3730 clear_com_win = TRUE;
3734 create_info_window()
3738 last_line = LINES - 8;
3740 text_win = newwin((LINES - 7), COLS, 6, 0);
3741 keypad(text_win, TRUE);
3742 idlok(text_win, TRUE);
3745 info_win = newwin(6, COLS, 0, 0);
3747 info_type = CONTROL_KEYS;
3748 midscreen(min(scr_vert, last_line), point);
3749 clearok(info_win, TRUE);
3752 clear_com_win = TRUE;
3762 if (restrict_mode())
3767 if (arg == READ_FILE)
3769 string = get_string(file_read_prompt_str, TRUE);
3771 tmp_file = resolve_name(string);
3773 if (tmp_file != string)
3777 else if (arg == WRITE_FILE)
3779 string = get_string(file_write_prompt_str, TRUE);
3780 tmp_file = resolve_name(string);
3781 write_file(tmp_file, 1);
3782 if (tmp_file != string)
3786 else if (arg == SAVE_FILE)
3789 | changes made here should be reflected in finish()
3797 string = in_file_name;
3798 if ((string == NULL) || (*string == '\0'))
3799 string = get_string(save_file_name_prompt, TRUE);
3800 if ((string == NULL) || (*string == '\0'))
3802 wmove(com_win, 0, 0);
3803 wprintw(com_win, file_not_saved_msg);
3806 clear_com_win = TRUE;
3811 tmp_file = resolve_name(string);
3812 if (tmp_file != string)
3818 if (write_file(string, 1))
3820 in_file_name = string;
3821 text_changes = FALSE;
3834 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3847 menu_op(leave_menu);
3858 clearok(info_win, TRUE);
3862 clearok(text_win, TRUE);
3863 midscreen(scr_vert, point);
3867 | The following routines will "format" a paragraph (as defined by a
3868 | block of text with blank lines before and after the block).
3872 Blank_Line(test_line) /* test if line has any non-space characters */
3873 struct text *test_line;
3875 unsigned char *line;
3878 if (test_line == NULL)
3882 line = test_line->line;
3885 | To handle troff/nroff documents, consider a line with a
3886 | period ('.') in the first column to be blank. To handle mail
3887 | messages with included text, consider a line with a '>' blank.
3890 if ((*line == '.') || (*line == '>'))
3893 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3898 if (length != test_line->line_length)
3905 Format() /* format the paragraph according to set margins */
3913 unsigned char *line;
3914 unsigned char *tmp_srchstr;
3915 unsigned char *temp1, *temp2;
3916 unsigned char *temp_dword;
3917 unsigned char temp_d_char[3];
3919 temp_d_char[0] = d_char[0];
3920 temp_d_char[1] = d_char[1];
3921 temp_d_char[2] = d_char[2];
3924 | if observ_margins is not set, or the current line is blank,
3925 | do not format the current paragraph
3928 if ((!observ_margins) || (Blank_Line(curr_line)))
3932 | save the currently set flags, and clear them
3935 wmove(com_win, 0, 0);
3937 wprintw(com_win, formatting_msg);
3941 | get current position in paragraph, so after formatting, the cursor
3942 | will be in the same relative position
3945 tmp_af = auto_format;
3946 auto_format = FALSE;
3950 temp_dword = d_word;
3952 temp_case = case_sen;
3954 tmp_srchstr = srch_str;
3955 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3956 if ((*point == ' ') || (*point == '\t'))
3960 line = temp1 = point;
3961 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3971 while (!Blank_Line(curr_line->prev_line))
3975 while ((line != point) && (status))
3977 status = search(FALSE);
3981 wmove(com_win, 0, 0);
3983 wprintw(com_win, formatting_msg);
3987 | now get back to the start of the paragraph to start formatting
3992 while (!Blank_Line(curr_line->prev_line))
3995 observ_margins = FALSE;
3998 | Start going through lines, putting spaces at end of lines if they do
3999 | not already exist. Append lines together to get one long line, and
4000 | eliminate spacing at begin of lines.
4003 while (!Blank_Line(curr_line->next_line))
4015 if ((*point == ' ') || (*point == '\t'))
4020 | Now there is one long line. Eliminate extra spaces within the line
4021 | after the first word (so as not to blow away any indenting the user
4027 while (position < curr_line->line_length)
4029 if ((*point == ' ') && (*(point + 1) == ' '))
4036 | Now make sure there are two spaces after a '.'.
4040 while (position < curr_line->line_length)
4042 if ((*point == '.') && (*(point + 1) == ' '))
4047 while (*point == ' ')
4053 observ_margins = TRUE;
4056 wmove(com_win, 0, 0);
4058 wprintw(com_win, formatting_msg);
4062 | create lines between margins
4065 while (position < curr_line->line_length)
4067 while ((scr_pos < right_margin) && (position < curr_line->line_length))
4069 if (position < curr_line->line_length)
4079 | go back to begin of paragraph, put cursor back to original position
4083 while (!Blank_Line(curr_line->prev_line))
4087 | find word cursor was in
4090 while ((status) && (string_count > 0))
4097 | offset the cursor to where it was before from the start of the word
4107 | reset flags and strings to what they were before formatting
4112 d_word = temp_dword;
4113 case_sen = temp_case;
4115 srch_str = tmp_srchstr;
4116 d_char[0] = temp_d_char[0];
4117 d_char[1] = temp_d_char[1];
4118 d_char[2] = temp_d_char[2];
4119 auto_format = tmp_af;
4121 midscreen(scr_vert, point);
4126 unsigned char *init_name[3] = {
4127 "/usr/local/lib/init.ee",
4133 ee_init() /* check for init file and read it if it exists */
4136 unsigned char *string;
4137 unsigned char *str1;
4138 unsigned char *str2;
4143 string = getenv("HOME");
4146 str1 = home = malloc(strlen(string)+10);
4147 strcpy(home, string);
4148 strcat(home, "/.init.ee");
4149 init_name[1] = home;
4150 string = malloc(512);
4152 for (counter = 0; counter < 3; counter++)
4154 if (!(access(init_name[counter], 4)))
4156 init_file = fopen(init_name[counter], "r");
4157 while ((str2 = fgets(string, 512, init_file)) != NULL)
4159 str1 = str2 = string;
4160 while (*str2 != '\n')
4164 if (unique_test(string, init_strings) != 1)
4167 if (compare(str1, CASE, FALSE))
4169 else if (compare(str1, NOCASE, FALSE))
4171 else if (compare(str1, EXPAND, FALSE))
4173 else if (compare(str1, NOEXPAND, FALSE))
4174 expand_tabs = FALSE;
4175 else if (compare(str1, INFO, FALSE))
4177 else if (compare(str1, NOINFO, FALSE))
4178 info_window = FALSE;
4179 else if (compare(str1, MARGINS, FALSE))
4180 observ_margins = TRUE;
4181 else if (compare(str1, NOMARGINS, FALSE))
4182 observ_margins = FALSE;
4183 else if (compare(str1, AUTOFORMAT, FALSE))
4186 observ_margins = TRUE;
4188 else if (compare(str1, NOAUTOFORMAT, FALSE))
4189 auto_format = FALSE;
4190 else if (compare(str1, Echo, FALSE))
4192 str1 = next_word(str1);
4196 else if (compare(str1, PRINTCOMMAND, FALSE))
4198 str1 = next_word(str1);
4199 print_command = malloc(strlen(str1)+1);
4200 strcpy(print_command, str1);
4202 else if (compare(str1, RIGHTMARGIN, FALSE))
4204 str1 = next_word(str1);
4205 if ((*str1 >= '0') && (*str1 <= '9'))
4207 temp_int = atoi(str1);
4209 right_margin = temp_int;
4212 else if (compare(str1, HIGHLIGHT, FALSE))
4213 nohighlight = FALSE;
4214 else if (compare(str1, NOHIGHLIGHT, FALSE))
4216 else if (compare(str1, EIGHTBIT, FALSE))
4218 else if (compare(str1, NOEIGHTBIT, FALSE))
4223 else if (compare(str1, EMACS_string, FALSE))
4224 emacs_keys_mode = TRUE;
4225 else if (compare(str1, NOEMACS_string, FALSE))
4226 emacs_keys_mode = FALSE;
4227 else if (compare(str1, chinese_cmd, FALSE))
4232 else if (compare(str1, nochinese_cmd, FALSE))
4241 string = getenv("LANG");
4244 if (strcmp(string, "zh_TW.big5") == 0)
4253 | Save current configuration to .init.ee file in the current directory.
4260 FILE *old_init_file = NULL;
4261 char *file_name = ".init.ee";
4262 char *home_dir = "~/.init.ee";
4269 if (restrict_mode())
4274 option = menu_op(config_dump_menu);
4277 wmove(com_win, 0, 0);
4281 wprintw(com_win, conf_not_saved_msg);
4285 else if (option == 2)
4286 file_name = resolve_name(home_dir);
4289 | If a .init.ee file exists, move it to .init.ee.old.
4292 if (stat(file_name, &buf) != -1)
4294 sprintf(buffer, "%s.old", file_name);
4296 link(file_name, buffer);
4298 old_init_file = fopen(buffer, "r");
4301 init_file = fopen(file_name, "w");
4302 if (init_file == NULL)
4304 wprintw(com_win, conf_dump_err_msg);
4309 if (old_init_file != NULL)
4312 | Copy non-configuration info into new .init.ee file.
4314 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4316 length = strlen(string);
4317 string[length - 1] = '\0';
4319 if (unique_test(string, init_strings) == 1)
4321 if (compare(string, Echo, FALSE))
4323 fprintf(init_file, "%s\n", string);
4327 fprintf(init_file, "%s\n", string);
4330 fclose(old_init_file);
4333 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4334 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4335 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4336 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4337 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4338 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4339 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4340 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4341 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4342 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4343 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4347 wprintw(com_win, conf_dump_success_msg, file_name);
4350 if ((option == 2) && (file_name != home_dir))
4357 echo_string(string) /* echo the given string */
4364 while (*temp != '\0')
4371 else if (*temp == 't')
4373 else if (*temp == 'b')
4375 else if (*temp == 'r')
4377 else if (*temp == 'f')
4379 else if ((*temp == 'e') || (*temp == 'E'))
4380 putchar('\033'); /* escape */
4381 else if (*temp == '\\')
4383 else if (*temp == '\'')
4385 else if ((*temp >= '0') && (*temp <= '9'))
4388 while ((*temp >= '0') && (*temp <= '9'))
4390 Counter = (8 * Counter) + (*temp - '0');
4409 spell_op() /* check spelling of words in the editor */
4411 if (restrict_mode())
4415 top(); /* go to top of file */
4416 insert_line(FALSE); /* create two blank lines */
4419 command(shell_echo_msg);
4421 wmove(com_win, 0, 0);
4422 wprintw(com_win, spell_in_prog_msg);
4424 command("<>!spell"); /* send contents of buffer to command 'spell'
4425 and read the results back into the editor */
4431 char template[128], *name;
4435 if (restrict_mode())
4439 (void)sprintf(template, "/tmp/ee.XXXXXXXX");
4440 fd = mkstemp(template);
4442 wmove(com_win, 0, 0);
4443 wprintw(com_win, create_file_fail_msg, name);
4448 if (write_file(name, 0))
4450 sprintf(string, "ispell %s", name);
4461 first_word_len(test_line)
4462 struct text *test_line;
4467 if (test_line == NULL)
4470 pnt = test_line->line;
4471 if ((pnt == NULL) || (*pnt == '\0') ||
4472 (*pnt == '.') || (*pnt == '>'))
4475 if ((*pnt == ' ') || (*pnt == '\t'))
4477 pnt = next_word(pnt);
4484 while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
4489 while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
4498 Auto_Format() /* format the paragraph according to set margins */
4505 int tmp_d_line_length;
4506 int leave_loop = FALSE;
4510 unsigned char *line;
4511 unsigned char *tmp_srchstr;
4512 unsigned char *temp1, *temp2;
4513 unsigned char *temp_dword;
4514 unsigned char temp_d_char[3];
4515 unsigned char *tmp_d_line;
4518 temp_d_char[0] = d_char[0];
4519 temp_d_char[1] = d_char[1];
4520 temp_d_char[2] = d_char[2];
4523 | if observ_margins is not set, or the current line is blank,
4524 | do not format the current paragraph
4527 if ((!observ_margins) || (Blank_Line(curr_line)))
4531 | get current position in paragraph, so after formatting, the cursor
4532 | will be in the same relative position
4535 tmp_d_line = d_line;
4536 tmp_d_line_length = dlt_line->line_length;
4538 auto_format = FALSE;
4540 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
4542 temp_dword = d_word;
4543 temp_dwl = d_wrd_len;
4546 temp_case = case_sen;
4548 tmp_srchstr = srch_str;
4549 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4550 if ((*point == ' ') || (*point == '\t'))
4554 line = temp1 = point;
4555 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4565 while (!Blank_Line(curr_line->prev_line))
4569 while ((line != point) && (status))
4571 status = search(FALSE);
4576 | now get back to the start of the paragraph to start checking
4581 while (!Blank_Line(curr_line->prev_line))
4585 | Start going through lines, putting spaces at end of lines if they do
4586 | not already exist. Check line length, and move words to the next line
4587 | if they cross the margin. Then get words from the next line if they
4588 | will fit in before the margin.
4595 if (position != curr_line->line_length)
4609 | fill line if first word on next line will fit
4610 | in the line without crossing the margin
4613 while ((curr_line->next_line != NULL) &&
4614 ((word_len = first_word_len(curr_line->next_line)) > 0)
4615 && ((scr_pos + word_len) < right_margin))
4618 if ((*point == ' ') || (*point == '\t'))
4625 | We know this line was not blank before, so
4626 | make sure that it doesn't have one of the
4627 | leading characters that indicate the line
4628 | should not be modified.
4630 | We also know that this character should not
4631 | be left as the first character of this line.
4634 if ((Blank_Line(curr_line)) &&
4635 (curr_line->line[0] != '.') &&
4636 (curr_line->line[0] != '>'))
4645 | go to end of previous line
4651 | make sure there's a space at the end of the line
4664 | make sure line does not cross right margin
4667 while (right_margin <= scr_pos)
4673 if (Blank_Line(curr_line->next_line))
4677 if ((*point == ' ') || (*point == '\t'))
4687 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4697 | go back to begin of paragraph, put cursor back to original position
4702 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4706 | find word cursor was in
4710 while ((status) && (string_count > 0))
4712 status = search(FALSE);
4717 | offset the cursor to where it was before from the start of the word
4726 if ((string_count > 0) && (offset < 0))
4736 | reset flags and strings to what they were before formatting
4741 d_word = temp_dword;
4742 d_wrd_len = temp_dwl;
4743 case_sen = temp_case;
4745 srch_str = tmp_srchstr;
4746 d_char[0] = temp_d_char[0];
4747 d_char[1] = temp_d_char[1];
4748 d_char[2] = temp_d_char[2];
4750 dlt_line->line_length = tmp_d_line_length;
4751 d_line = tmp_d_line;
4754 midscreen(scr_vert, point);
4766 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4767 (expand_tabs ? ON : OFF));
4768 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4769 (case_sen ? ON : OFF));
4770 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4771 (observ_margins ? ON : OFF));
4772 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4773 (auto_format ? ON : OFF));
4774 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4775 (eightbit ? ON : OFF));
4776 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4777 (info_window ? ON : OFF));
4778 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4779 (emacs_keys_mode ? ON : OFF));
4780 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4782 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4783 (ee_chinese ? ON : OFF));
4785 ret_value = menu_op(modes_menu);
4790 expand_tabs = !expand_tabs;
4793 case_sen = !case_sen;
4796 observ_margins = !observ_margins;
4799 auto_format = !auto_format;
4801 observ_margins = TRUE;
4804 eightbit = !eightbit;
4809 nc_setattrib(A_NC_BIG5);
4811 nc_clearattrib(A_NC_BIG5);
4815 wnoutrefresh(text_win);
4821 create_info_window();
4824 emacs_keys_mode = !emacs_keys_mode;
4829 string = get_string(margin_prompt, TRUE);
4832 counter = atoi(string);
4834 right_margin = counter;
4839 ee_chinese = !ee_chinese;
4840 if (ee_chinese != FALSE)
4844 nc_setattrib(A_NC_BIG5);
4846 nc_clearattrib(A_NC_BIG5);
4854 while (ret_value != 0);
4858 is_in_string(string, substring) /* a strchr() look-alike for systems without
4860 char * string, *substring;
4864 for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
4866 for (full = string; (full != NULL) && (*full != '\0');
4877 | handle names of the form "~/file", "~user/file",
4878 | "$HOME/foo", "~/$FOO", etc.
4885 char long_buffer[1024];
4886 char short_buffer[128];
4894 struct passwd *user;
4901 user = (struct passwd *) getpwuid(index);
4906 slash = strchr(name, '/');
4910 user = (struct passwd *) getpwnam((name + 1));
4917 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4918 strcpy(buffer, user->pw_dir);
4919 strcat(buffer, slash);
4924 if (is_in_string(buffer, "$"))
4929 while ((*tmp != '\0') && (index < 1024))
4932 while ((*tmp != '\0') && (*tmp != '$') &&
4935 long_buffer[index] = *tmp;
4940 if ((*tmp == '$') && (index < 1024))
4945 if (*tmp == '{') /* } */ /* bracketed variable name */
4948 while ((*tmp != '\0') &&
4952 short_buffer[counter] = *tmp;
4961 while ((*tmp != '\0') &&
4966 short_buffer[counter] = *tmp;
4971 short_buffer[counter] = '\0';
4972 if ((slash = getenv(short_buffer)) != NULL)
4974 offset = strlen(slash);
4975 if ((offset + index) < 1024)
4976 strcpy(&long_buffer[index], slash);
4981 while ((start_of_var != tmp) && (index < 1024))
4983 long_buffer[index] = *start_of_var;
4994 long_buffer[index] = '\0';
4998 buffer = malloc(index + 1);
4999 strcpy(buffer, long_buffer);
5011 wmove(com_win, 0, 0);
5012 wprintw(com_win, restricted_msg);
5015 clear_com_win = TRUE;
5020 | The following routine tests the input string against the list of
5021 | strings, to determine if the string is a unique match with one of the
5026 unique_test(string, list)
5036 while (list[counter] != NULL)
5038 result = compare(string, list[counter], FALSE);
5048 | Get the catalog entry, and if it got it from the catalog,
5049 | make a copy, since the buffer will be overwritten by the
5050 | next call to catgets().
5054 catgetlocal(number, string)
5061 temp1 = catgets(catalog, 1, number, string);
5062 if (temp1 != string)
5064 temp2 = malloc(strlen(temp1) + 1);
5065 strcpy(temp2, temp1);
5070 #endif /* NO_CATGETS */
5073 | The following is to allow for using message catalogs which allow
5074 | the software to be 'localized', that is, to use different languages
5075 | all with the same binary. For more information, see your system
5076 | documentation, or the X/Open Internationalization Guide.
5085 setlocale(LC_ALL, "");
5086 catalog = catopen("ee", 0);
5087 #endif /* NO_CATGETS */
5089 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5090 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5091 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5092 mode_strings[3] = catgetlocal( 4, "margins observed ");
5093 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5094 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5095 mode_strings[6] = catgetlocal( 7, "info window ");
5096 mode_strings[8] = catgetlocal( 8, "right margin ");
5097 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5098 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5099 leave_menu[2].item_string = catgetlocal( 11, "no save");
5100 file_menu[0].item_string = catgetlocal( 12, "file menu");
5101 file_menu[1].item_string = catgetlocal( 13, "read a file");
5102 file_menu[2].item_string = catgetlocal( 14, "write a file");
5103 file_menu[3].item_string = catgetlocal( 15, "save file");
5104 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5105 search_menu[0].item_string = catgetlocal( 17, "search menu");
5106 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5107 search_menu[2].item_string = catgetlocal( 19, "search");
5108 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5109 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5110 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5111 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5112 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5113 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5114 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5115 main_menu[0].item_string = catgetlocal( 27, "main menu");
5116 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5117 main_menu[2].item_string = catgetlocal( 29, "help");
5118 main_menu[3].item_string = catgetlocal( 30, "file operations");
5119 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5120 main_menu[5].item_string = catgetlocal( 32, "settings");
5121 main_menu[6].item_string = catgetlocal( 33, "search");
5122 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5123 help_text[0] = catgetlocal( 35, "Control keys: ");
5124 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5125 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5126 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5127 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5128 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5129 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5130 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5131 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5132 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5133 help_text[10] = catgetlocal( 45, " ");
5134 help_text[11] = catgetlocal( 46, "Commands: ");
5135 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5136 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5137 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5138 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5139 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5140 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5141 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5142 help_text[19] = catgetlocal( 54, " ");
5143 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5144 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5145 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5146 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5147 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5148 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5149 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5150 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5151 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5152 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5153 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5154 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5155 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5156 no_file_string = catgetlocal( 68, "no file");
5157 ascii_code_str = catgetlocal( 69, "ascii code: ");
5158 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5159 command_str = catgetlocal( 71, "command: ");
5160 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5161 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5162 char_str = catgetlocal( 74, "character = %d");
5163 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5164 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5165 line_num_str = catgetlocal( 77, "line %d ");
5166 line_len_str = catgetlocal( 78, "length = %d");
5167 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5168 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5169 usage1 = catgetlocal( 81, " -i turn off info window\n");
5170 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5171 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5172 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5173 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5174 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5175 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5176 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5177 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5178 read_only_msg = catgetlocal( 90, ", read only");
5179 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5180 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5181 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5182 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5183 yes_char = catgetlocal( 95, "y");
5184 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5185 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5186 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5187 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5188 searching_msg = catgetlocal( 100, " ...searching");
5189 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5190 search_prompt_str = catgetlocal( 102, "search for: ");
5191 exec_err_msg = catgetlocal( 103, "could not exec %s\n");
5192 continue_msg = catgetlocal( 104, "press return to continue ");
5193 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5194 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5195 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5196 shell_prompt = catgetlocal( 108, "shell command: ");
5197 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5198 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5199 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5200 margin_prompt = catgetlocal( 112, "right margin is: ");
5201 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5202 ON = catgetlocal( 114, "ON");
5203 OFF = catgetlocal( 115, "OFF");
5204 HELP = catgetlocal( 116, "HELP");
5205 WRITE = catgetlocal( 117, "WRITE");
5206 READ = catgetlocal( 118, "READ");
5207 LINE = catgetlocal( 119, "LINE");
5208 FILE_str = catgetlocal( 120, "FILE");
5209 CHARACTER = catgetlocal( 121, "CHARACTER");
5210 REDRAW = catgetlocal( 122, "REDRAW");
5211 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5212 AUTHOR = catgetlocal( 124, "AUTHOR");
5213 VERSION = catgetlocal( 125, "VERSION");
5214 CASE = catgetlocal( 126, "CASE");
5215 NOCASE = catgetlocal( 127, "NOCASE");
5216 EXPAND = catgetlocal( 128, "EXPAND");
5217 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5218 Exit_string = catgetlocal( 130, "EXIT");
5219 QUIT_string = catgetlocal( 131, "QUIT");
5220 INFO = catgetlocal( 132, "INFO");
5221 NOINFO = catgetlocal( 133, "NOINFO");
5222 MARGINS = catgetlocal( 134, "MARGINS");
5223 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5224 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5225 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5226 Echo = catgetlocal( 138, "ECHO");
5227 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5228 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5229 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5230 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5231 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5232 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5236 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5237 emacs_help_text[0] = help_text[0];
5238 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5239 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
5240 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
5241 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5242 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5243 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5244 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5245 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5246 emacs_help_text[9] = help_text[9];
5247 emacs_help_text[10] = help_text[10];
5248 emacs_help_text[11] = help_text[11];
5249 emacs_help_text[12] = help_text[12];
5250 emacs_help_text[13] = help_text[13];
5251 emacs_help_text[14] = help_text[14];
5252 emacs_help_text[15] = help_text[15];
5253 emacs_help_text[16] = help_text[16];
5254 emacs_help_text[17] = help_text[17];
5255 emacs_help_text[18] = help_text[18];
5256 emacs_help_text[19] = help_text[19];
5257 emacs_help_text[20] = help_text[20];
5258 emacs_help_text[21] = help_text[21];
5259 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
5260 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
5261 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
5262 emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
5263 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5264 EMACS_string = catgetlocal( 159, "EMACS");
5265 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5266 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5267 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5268 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5269 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5270 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5271 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5272 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5273 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5274 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5275 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5276 more_above_str = catgetlocal( 181, "^^more^^");
5277 more_below_str = catgetlocal( 182, "VVmoreVV");
5278 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5279 chinese_cmd = catgetlocal( 184, "16BIT");
5280 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5283 commands[1] = WRITE;
5286 commands[4] = FILE_str;
5287 commands[5] = REDRAW;
5288 commands[6] = RESEQUENCE;
5289 commands[7] = AUTHOR;
5290 commands[8] = VERSION;
5292 commands[10] = NOCASE;
5293 commands[11] = EXPAND;
5294 commands[12] = NOEXPAND;
5295 commands[13] = Exit_string;
5296 commands[14] = QUIT_string;
5310 commands[28] = CHARACTER;
5311 commands[29] = chinese_cmd;
5312 commands[30] = nochinese_cmd;
5313 commands[31] = NULL;
5314 init_strings[0] = CASE;
5315 init_strings[1] = NOCASE;
5316 init_strings[2] = EXPAND;
5317 init_strings[3] = NOEXPAND;
5318 init_strings[4] = INFO;
5319 init_strings[5] = NOINFO;
5320 init_strings[6] = MARGINS;
5321 init_strings[7] = NOMARGINS;
5322 init_strings[8] = AUTOFORMAT;
5323 init_strings[9] = NOAUTOFORMAT;
5324 init_strings[10] = Echo;
5325 init_strings[11] = PRINTCOMMAND;
5326 init_strings[12] = RIGHTMARGIN;
5327 init_strings[13] = HIGHLIGHT;
5328 init_strings[14] = NOHIGHLIGHT;
5329 init_strings[15] = EIGHTBIT;
5330 init_strings[16] = NOEIGHTBIT;
5331 init_strings[17] = EMACS_string;
5332 init_strings[18] = NOEMACS_string;
5333 init_strings[19] = chinese_cmd;
5334 init_strings[20] = nochinese_cmd;
5335 init_strings[21] = NULL;
5338 | allocate space for strings here for settings menu
5341 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5343 modes_menu[counter].item_string = malloc(80);
5348 #endif /* NO_CATGETS */