4 | An easy to use, simple screen oriented editor.
6 | written by Hugh Mahon
9 | Copyright (c) 2009, Hugh Mahon
10 | All rights reserved.
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions
16 | * Redistributions of source code must retain the above copyright
17 | notice, this list of conditions and the following disclaimer.
18 | * Redistributions in binary form must reproduce the above
19 | copyright notice, this list of conditions and the following
20 | disclaimer in the documentation and/or other materials provided
21 | with the distribution.
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | POSSIBILITY OF SUCH DAMAGE.
36 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
38 | This editor was purposely developed to be simple, both in
39 | interface and implementation. This editor was developed to
40 | address a specific audience: the user who is new to computers
43 | ee is not aimed at technical users; for that reason more
44 | complex features were intentionally left out. In addition,
45 | ee is intended to be compiled by people with little computer
46 | experience, which means that it needs to be small, relatively
47 | simple in implementation, and portable.
49 | This software and documentation contains
50 | proprietary information which is protected by
51 | copyright. All rights are reserved.
53 | $Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.104 2010/06/04 01:55:31 hugh Exp hugh $
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
60 char *ee_copyright_message =
61 "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
63 #include "ee_version.h"
65 char *version = "@(#) ee, version " EE_VERSION " $Revision: 1.104 $";
68 #include "new_curse.h"
78 #include <sys/types.h>
102 #include <nl_types.h>
106 #define catgetlocal(a, b) (b)
107 #endif /* NO_CATGETS */
110 #define SIGCHLD SIGCLD
114 #define max(a, b) (a > b ? a : b)
115 #define min(a, b) (a < b ? a : b)
118 | defines for type of data to show in info window
121 #define CONTROL_KEYS 1
125 unsigned char *line; /* line of characters */
126 int line_number; /* line number */
127 int line_length; /* actual number of characters in the line */
128 int max_length; /* maximum number of characters the line handles */
129 struct text *next_line; /* next line of text */
130 struct text *prev_line; /* previous line of text */
133 struct text *first_line; /* first line of current buffer */
134 struct text *dlt_line; /* structure for info on deleted line */
135 struct text *curr_line; /* current line cursor is on */
136 struct text *tmp_line; /* temporary line pointer */
137 struct text *srch_line; /* temporary pointer for search routine */
139 struct files { /* structure to store names of files to be edited*/
140 unsigned char *name; /* name of file */
141 struct files *next_name;
144 struct files *top_of_stack = NULL;
146 int d_wrd_len; /* length of deleted word */
147 int position; /* offset in bytes from begin of line */
148 int scr_pos; /* horizontal position */
149 int scr_vert; /* vertical position on screen */
150 int scr_horz; /* horizontal position on screen */
151 int absolute_lin; /* number of lines from top */
152 int tmp_vert, tmp_horz;
153 int input_file; /* indicate to read input file */
154 int recv_file; /* indicate reading a file */
155 int edit; /* continue executing while true */
156 int gold; /* 'gold' function key pressed */
157 int fildes; /* file descriptor */
158 int case_sen; /* case sensitive search flag */
159 int last_line; /* last line for text display */
160 int last_col; /* last column for text display */
161 int horiz_offset = 0; /* offset from left edge of text */
162 int clear_com_win; /* flag to indicate com_win needs clearing */
163 int text_changes = FALSE; /* indicate changes have been made to text */
164 int get_fd; /* file descriptor for reading a file */
165 int info_window = TRUE; /* flag to indicate if help window visible */
166 int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
167 int expand_tabs = TRUE; /* flag for expanding tabs */
168 int right_margin = 0; /* the right margin */
169 int observ_margins = TRUE; /* flag for whether margins are observed */
171 int temp_stdin; /* temporary storage for stdin */
172 int temp_stdout; /* temp storage for stdout descriptor */
173 int temp_stderr; /* temp storage for stderr descriptor */
174 int pipe_out[2]; /* pipe file desc for output */
175 int pipe_in[2]; /* pipe file descriptors for input */
176 int out_pipe; /* flag that info is piped out */
177 int in_pipe; /* flag that info is piped in */
178 int formatted = FALSE; /* flag indicating paragraph formatted */
179 int auto_format = FALSE; /* flag for auto_format mode */
180 int restricted = FALSE; /* flag to indicate restricted mode */
181 int nohighlight = FALSE; /* turns off highlighting */
182 int eightbit = TRUE; /* eight bit character flag */
183 int local_LINES = 0; /* copy of LINES, to detect when win resizes */
184 int local_COLS = 0; /* copy of COLS, to detect when win resizes */
185 int curses_initialized = FALSE; /* flag indicating if curses has been started*/
186 int emacs_keys_mode = FALSE; /* mode for if emacs key binings are used */
187 int ee_chinese = FALSE; /* allows handling of multi-byte characters */
188 /* by checking for high bit in a byte the */
189 /* code recognizes a two-byte character */
192 unsigned char *point; /* points to current position in line */
193 unsigned char *srch_str; /* pointer for search string */
194 unsigned char *u_srch_str; /* pointer to non-case sensitive search */
195 unsigned char *srch_1; /* pointer to start of suspect string */
196 unsigned char *srch_2; /* pointer to next character of string */
197 unsigned char *srch_3;
198 unsigned char *in_file_name = NULL; /* name of input file */
199 char *tmp_file; /* temporary file name */
200 unsigned char *d_char; /* deleted character */
201 unsigned char *d_word; /* deleted word */
202 unsigned char *d_line; /* deleted line */
203 char in_string[513]; /* buffer for reading a file */
204 unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */
205 unsigned char *start_at_line = NULL; /* move to this line at start of session*/
206 int in; /* input character */
208 FILE *temp_fp; /* temporary file pointer */
209 FILE *bit_bucket; /* file pointer to /dev/null */
212 "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
213 "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
214 "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
222 #if defined(__STDC__) || defined(__cplusplus)
230 | The following structure allows menu items to be flexibly declared.
231 | The first item is the string describing the selection, the second
232 | is the address of the procedure to call when the item is selected,
233 | and the third is the argument for the procedure.
235 | For those systems with i18n, the string should be accompanied by a
236 | catalog number. The 'int *' should be replaced with 'void *' on
237 | systems with that type.
239 | The first menu item will be the title of the menu, with NULL
240 | parameters for the procedure and argument, followed by the menu items.
242 | If the procedure value is NULL, the menu item is displayed, but no
243 | procedure is called when the item is selected. The number of the
244 | item will be returned. If the third (argument) parameter is -1, no
245 | argument is given to the procedure when it is called.
248 struct menu_entries {
250 int (*procedure)P_((struct menu_entries *));
251 struct menu_entries *ptr_argument;
252 int (*iprocedure)P_((int));
253 void (*nprocedure)P_((void));
257 int main P_((int argc, char *argv[]));
258 unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
259 void insert P_((int character));
260 void delete P_((int disp));
261 void scanline P_((unsigned char *pos));
262 int tabshift P_((int temp_int));
263 int out_char P_((WINDOW *window, int character, int column));
264 int len_char P_((int character, int column));
265 void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
266 void insert_line P_((int disp));
267 struct text *txtalloc P_((void));
268 struct files *name_alloc P_((void));
269 unsigned char *next_word P_((unsigned char *string));
270 void prev_word P_((void));
271 void control P_((void));
272 void emacs_control P_((void));
273 void bottom P_((void));
275 void nextline P_((void));
276 void prevline P_((void));
277 void left P_((int disp));
278 void right P_((int disp));
279 void find_pos P_((void));
281 void down P_((void));
282 void function_key P_((void));
283 void print_buffer P_((void));
284 void command_prompt P_((void));
285 void command P_((char *cmd_str1));
286 int scan P_((char *line, int offset, int column));
287 char *get_string P_((char *prompt, int advance));
288 int compare P_((char *string1, char *string2, int sensitive));
289 void goto_line P_((char *cmd_str));
290 void midscreen P_((int line, unsigned char *pnt));
291 void get_options P_((int numargs, char *arguments[]));
292 void check_fp P_((void));
293 void get_file P_((char *file_name));
294 void get_line P_((int length, unsigned char *in_string, int *append));
295 void draw_screen P_((void));
296 void finish P_((void));
297 int quit P_((int noverify));
298 void edit_abort P_((int arg));
299 void delete_text P_((void));
300 int write_file P_((char *file_name, int warn_if_exists));
301 int search P_((int display_message));
302 void search_prompt P_((void));
303 void del_char P_((void));
304 void undel_char P_((void));
305 void del_word P_((void));
306 void undel_word P_((void));
307 void del_line P_((void));
308 void undel_line P_((void));
309 void adv_word P_((void));
310 void move_rel P_((int direction, int lines));
313 void adv_line P_((void));
314 void sh_command P_((char *string));
315 void set_up_term P_((void));
316 void resize_check P_((void));
317 int menu_op P_((struct menu_entries *));
318 void paint_menu P_((struct menu_entries menu_list[], int max_width, int max_height, int list_size, int top_offset, WINDOW *menu_win, int off_start, int vert_size));
319 void help P_((void));
320 void paint_info_win P_((void));
321 void no_info_window P_((void));
322 void create_info_window P_((void));
323 int file_op P_((int arg));
324 void shell_op P_((void));
325 void leave_op P_((void));
326 void redraw P_((void));
327 int Blank_Line P_((struct text *test_line));
328 void Format P_((void));
329 void ee_init P_((void));
330 void dump_ee_conf P_((void));
331 void echo_string P_((char *string));
332 void spell_op P_((void));
333 void ispell_op P_((void));
334 int first_word_len P_((struct text *test_line));
335 void Auto_Format P_((void));
336 void modes_op P_((void));
337 char *is_in_string P_((char *string, char *substring));
338 char *resolve_name P_((char *name));
339 int restrict_mode P_((void));
340 int unique_test P_((char *string, char *list[]));
341 void strings_init P_((void));
345 | allocate space here for the strings that will be in the menu
348 struct menu_entries modes_menu[] = {
349 {"", NULL, NULL, NULL, NULL, 0}, /* title */
350 {"", NULL, NULL, NULL, NULL, -1}, /* 1. tabs to spaces */
351 {"", NULL, NULL, NULL, NULL, -1}, /* 2. case sensitive search*/
352 {"", NULL, NULL, NULL, NULL, -1}, /* 3. margins observed */
353 {"", NULL, NULL, NULL, NULL, -1}, /* 4. auto-paragraph */
354 {"", NULL, NULL, NULL, NULL, -1}, /* 5. eightbit characters*/
355 {"", NULL, NULL, NULL, NULL, -1}, /* 6. info window */
356 {"", NULL, NULL, NULL, NULL, -1}, /* 7. emacs key bindings*/
357 {"", NULL, NULL, NULL, NULL, -1}, /* 8. right margin */
358 {"", NULL, NULL, NULL, NULL, -1}, /* 9. chinese text */
359 {"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
360 {NULL, NULL, NULL, NULL, NULL, -1} /* terminator */
363 char *mode_strings[11];
365 #define NUM_MODES_ITEMS 10
367 struct menu_entries config_dump_menu[] = {
368 {"", NULL, NULL, NULL, NULL, 0},
369 {"", NULL, NULL, NULL, NULL, -1},
370 {"", NULL, NULL, NULL, NULL, -1},
371 {NULL, NULL, NULL, NULL, NULL, -1}
374 struct menu_entries leave_menu[] = {
375 {"", NULL, NULL, NULL, NULL, -1},
376 {"", NULL, NULL, NULL, finish, -1},
377 {"", NULL, NULL, quit, NULL, TRUE},
378 {NULL, NULL, NULL, NULL, NULL, -1}
385 struct menu_entries file_menu[] = {
386 {"", NULL, NULL, NULL, NULL, -1},
387 {"", NULL, NULL, file_op, NULL, READ_FILE},
388 {"", NULL, NULL, file_op, NULL, WRITE_FILE},
389 {"", NULL, NULL, file_op, NULL, SAVE_FILE},
390 {"", NULL, NULL, NULL, print_buffer, -1},
391 {NULL, NULL, NULL, NULL, NULL, -1}
394 struct menu_entries search_menu[] = {
395 {"", NULL, NULL, NULL, NULL, 0},
396 {"", NULL, NULL, NULL, search_prompt, -1},
397 {"", NULL, NULL, search, NULL, TRUE},
398 {NULL, NULL, NULL, NULL, NULL, -1}
401 struct menu_entries spell_menu[] = {
402 {"", NULL, NULL, NULL, NULL, -1},
403 {"", NULL, NULL, NULL, spell_op, -1},
404 {"", NULL, NULL, NULL, ispell_op, -1},
405 {NULL, NULL, NULL, NULL, NULL, -1}
408 struct menu_entries misc_menu[] = {
409 {"", NULL, NULL, NULL, NULL, -1},
410 {"", NULL, NULL, NULL, Format, -1},
411 {"", NULL, NULL, NULL, shell_op, -1},
412 {"", menu_op, spell_menu, NULL, NULL, -1},
413 {NULL, NULL, NULL, NULL, NULL, -1}
416 struct menu_entries main_menu[] = {
417 {"", NULL, NULL, NULL, NULL, -1},
418 {"", NULL, NULL, NULL, leave_op, -1},
419 {"", NULL, NULL, NULL, help, -1},
420 {"", menu_op, file_menu, NULL, NULL, -1},
421 {"", NULL, NULL, NULL, redraw, -1},
422 {"", NULL, NULL, NULL, modes_op, -1},
423 {"", menu_op, search_menu, NULL, NULL, -1},
424 {"", menu_op, misc_menu, NULL, NULL, -1},
425 {NULL, NULL, NULL, NULL, NULL, -1}
429 char *control_keys[5];
431 char *emacs_help_text[22];
432 char *emacs_control_keys[5];
434 char *command_strings[5];
436 char *init_strings[22];
440 #define max_alpha_char 36
443 | Declarations for strings for localization
446 char *com_win_message; /* to be shown in com_win if no info window */
447 char *no_file_string;
448 char *ascii_code_str;
449 char *printer_msg_str;
451 char *file_write_prompt_str;
452 char *file_read_prompt_str;
455 char *non_unique_cmd_msg;
458 char *current_file_str;
464 char *file_is_dir_msg;
468 char *file_read_fin_msg;
469 char *reading_file_msg;
471 char *file_read_lines_msg;
472 char *save_file_name_prompt;
473 char *file_not_saved_msg;
474 char *changes_made_prompt;
476 char *file_exists_prompt;
477 char *create_file_fail_msg;
478 char *writing_file_msg;
479 char *file_written_msg;
481 char *str_not_found_msg;
482 char *search_prompt_str;
485 char *menu_cancel_msg;
486 char *menu_size_err_msg;
487 char *press_any_key_msg;
489 char *formatting_msg;
490 char *shell_echo_msg;
491 char *spell_in_prog_msg;
493 char *restricted_msg;
526 char *NOEMACS_string;
527 char *conf_dump_err_msg;
528 char *conf_dump_success_msg;
529 char *conf_not_saved_msg;
530 char *ree_no_file_msg;
532 char *menu_too_lrg_msg;
533 char *more_above_str, *more_below_str;
534 char *separator = "===============================================================================";
536 char *chinese_cmd, *nochinese_cmd;
540 extern char *malloc();
541 extern char *realloc();
542 extern char *getenv();
543 FILE *fopen(); /* declaration for open function */
544 #endif /* HAS_STDLIB */
545 #endif /* __STDC__ */
548 main(argc, argv) /* beginning of main program */
554 for (counter = 1; counter < 24; counter++)
555 signal(counter, SIG_IGN);
557 signal(SIGCHLD, SIG_DFL);
558 signal(SIGSEGV, SIG_DFL);
559 signal(SIGINT, edit_abort);
560 d_char = malloc(3); /* provide a buffer for multi-byte chars */
561 d_word = malloc(150);
564 dlt_line = txtalloc();
565 dlt_line->line = d_line;
566 dlt_line->line_length = 0;
567 curr_line = first_line = txtalloc();
568 curr_line->line = point = malloc(10);
569 curr_line->line_length = 1;
570 curr_line->max_length = 10;
571 curr_line->prev_line = NULL;
572 curr_line->next_line = NULL;
573 curr_line->line_number = 1;
581 bit_bucket = fopen("/dev/null", "w");
583 gold = case_sen = FALSE;
588 get_options(argc, argv);
590 if (right_margin == 0)
591 right_margin = COLS - 1;
592 if (top_of_stack == NULL)
596 wmove(com_win, 0, 0);
598 wprintw(com_win, ree_no_file_msg);
602 wprintw(com_win, no_file_string);
608 clear_com_win = TRUE;
615 | display line and column information
621 wmove(info_win, 5, 0);
622 wprintw(info_win, separator);
623 wmove(info_win, 5, 5);
624 wprintw(info_win, "line %d col %d lines from top %d ",
625 curr_line->line_number, scr_horz, absolute_lin);
631 in = wgetch(text_win);
633 exit(0); /* without this exit ee will go into an
634 infinite loop if the network
641 clear_com_win = FALSE;
642 wmove(com_win, 0, 0);
646 wprintw(com_win, "%s", com_win_message);
653 else if ((in == '\10') || (in == 127))
655 in = 8; /* make sure key is set to backspace */
658 else if ((in > 31) || (in == 9))
660 else if ((in >= 0) && (in <= 31))
672 resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
673 int factor; /* resize factor */
674 struct text *rline; /* position in line */
677 unsigned char *rpoint;
680 rline->max_length += factor;
681 rpoint = rline->line = realloc(rline->line, rline->max_length );
682 for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
688 insert(character) /* insert character into line */
689 int character; /* new character */
693 unsigned char *temp; /* temporary pointer */
694 unsigned char *temp2; /* temporary pointer */
696 if ((character == '\011') && (expand_tabs))
698 counter = len_char('\011', scr_horz);
699 for (; counter > 0; counter--)
706 if ((curr_line->max_length - curr_line->line_length) < 5)
707 point = resiz_line(10, curr_line, position);
708 curr_line->line_length++;
711 while (counter < curr_line->line_length) /* find end of line */
716 temp++; /* increase length of line by one */
720 *temp= *temp2; /* shift characters over by one */
723 *point = character; /* insert new character */
725 if (!isprint((unsigned char)character)) /* check for TAB character*/
727 scr_pos = scr_horz += out_char(text_win, character, scr_horz);
733 waddch(text_win, (unsigned char)character);
734 scr_pos = ++scr_horz;
739 if ((observ_margins) && (right_margin < scr_pos))
742 while (scr_pos > right_margin)
746 while (position < counter)
753 for (value = 0; value < counter; value++)
758 if ((scr_horz - horiz_offset) > last_col)
761 midscreen(scr_vert, point);
764 if ((auto_format) && (character == ' ') && (!formatted))
766 else if ((character != ' ') && (character != '\t'))
769 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
773 delete(disp) /* delete character */
777 unsigned char *temp2;
778 struct text *temp_buff;
783 if (point != curr_line->line) /* if not at beginning of line */
787 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
793 position -= del_width;
795 curr_line->line_length -= del_width;
796 if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
799 scr_horz -= del_width;
804 *d_char = *point; /* save deleted character */
808 d_char[1] = *(point + 1);
810 d_char[del_width] = '\0';
812 while (temp_pos <= curr_line->line_length)
819 if ((scr_horz < horiz_offset) && (horiz_offset > 0))
822 midscreen(scr_vert, point);
825 else if (curr_line->prev_line != NULL)
828 left(disp); /* go to previous line */
829 temp_buff = curr_line->next_line;
830 point = resiz_line(temp_buff->line_length, curr_line, position);
831 if (temp_buff->next_line != NULL)
832 temp_buff->next_line->prev_line = curr_line;
833 curr_line->next_line = temp_buff->next_line;
834 temp2 = temp_buff->line;
842 while (temp_pos < temp_buff->line_length)
844 curr_line->line_length++;
851 free(temp_buff->line);
853 temp_buff = curr_line;
854 temp_vert = scr_vert;
856 if (scr_vert < last_line)
858 wmove(text_win, scr_vert + 1, 0);
861 while ((temp_buff != NULL) && (temp_vert < last_line))
863 temp_buff = temp_buff->next_line;
866 if ((temp_vert == last_line) && (temp_buff != NULL))
868 tp = temp_buff->line;
869 wmove(text_win, last_line,0);
871 draw_line(last_line, 0, tp, 1, temp_buff->line_length);
872 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
875 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
880 scanline(pos) /* find the proper horizontal position for the pointer */
886 ptr = curr_line->line;
893 temp += tabshift(temp);
894 else if ((*ptr >= 10) && (*ptr <= 31))
896 else if ((*ptr >= 32) && (*ptr < 127))
898 else if (*ptr == 127)
907 if ((scr_horz - horiz_offset) > last_col)
909 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
910 midscreen(scr_vert, point);
912 else if (scr_horz < horiz_offset)
914 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
915 midscreen(scr_vert, point);
920 tabshift(temp_int) /* give the number of spaces to shift */
925 leftover = ((temp_int + 1) % 8);
929 return (9 - leftover);
933 out_char(window, character, column) /* output non-printing character */
942 if (character == TAB)
944 i1 = tabshift(column);
946 (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
952 else if ((character >= '\0') && (character < ' '))
954 string = table[(int) character];
956 else if ((character < 0) || (character >= 127))
958 if (character == 127)
962 sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
967 waddch(window, (unsigned char)character );
973 waddch(window, (unsigned char)character);
976 for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
977 waddch(window, (unsigned char)string[i2]);
978 return(strlen(string));
982 len_char(character, column) /* return the length of the character */
984 int column; /* the column must be known to provide spacing for tabs */
988 if (character == '\t')
989 length = tabshift(column);
990 else if ((character >= 0) && (character < 32))
992 else if ((character >= 32) && (character <= 126))
994 else if (character == 127)
996 else if (((character > 126) || (character < 0)) && (!eightbit))
1005 draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
1006 int vertical; /* current vertical position on screen */
1007 int horiz; /* current horizontal position on screen */
1008 unsigned char *ptr; /* pointer to line */
1009 int t_pos; /* current position (offset in bytes) from bol */
1010 int length; /* length (in bytes) of line */
1012 int d; /* partial length of special or tab char to display */
1013 unsigned char *temp; /* temporary pointer to position in line */
1014 int abs_column; /* offset in screen units from begin of line */
1015 int column; /* horizontal position on screen */
1016 int row; /* vertical position on screen */
1017 int posit; /* temporary position indicator within line */
1020 column = horiz - horiz_offset;
1027 wmove(text_win, row, 0);
1028 wclrtoeol(text_win);
1032 d = len_char(*temp, abs_column);
1038 wmove(text_win, row, column);
1039 wclrtoeol(text_win);
1040 while ((posit < length) && (column <= last_col))
1042 if (!isprint(*temp))
1044 column += len_char(*temp, abs_column);
1045 abs_column += out_char(text_win, *temp, abs_column);
1051 waddch(text_win, *temp);
1056 if (column < last_col)
1057 wclrtoeol(text_win);
1058 wmove(text_win, vertical, (horiz - horiz_offset));
1062 insert_line(disp) /* insert new line */
1067 unsigned char *temp;
1068 unsigned char *extra;
1069 struct text *temp_nod;
1071 text_changes = TRUE;
1072 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1073 wclrtoeol(text_win);
1074 temp_nod= txtalloc();
1075 temp_nod->line = extra= malloc(10);
1076 temp_nod->line_length = 1;
1077 temp_nod->max_length = 10;
1078 temp_nod->line_number = curr_line->line_number + 1;
1079 temp_nod->next_line = curr_line->next_line;
1080 if (temp_nod->next_line != NULL)
1081 temp_nod->next_line->prev_line = temp_nod;
1082 temp_nod->prev_line = curr_line;
1083 curr_line->next_line = temp_nod;
1084 temp_pos2 = position;
1086 if (temp_pos2 < curr_line->line_length)
1089 while (temp_pos2 < curr_line->line_length)
1091 if ((temp_nod->max_length - temp_nod->line_length)< 5)
1092 extra = resiz_line(10, temp_nod, temp_pos);
1093 temp_nod->line_length++;
1102 temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
1103 curr_line->line_length = 1 + temp - curr_line->line;
1105 curr_line->line_length = position;
1107 curr_line = temp_nod;
1110 point= curr_line->line;
1113 if (scr_vert < last_line)
1116 wclrtoeol(text_win);
1117 wmove(text_win, scr_vert, 0);
1118 winsertln(text_win);
1122 wmove(text_win, 0,0);
1123 wdeleteln(text_win);
1124 wmove(text_win, last_line,0);
1125 wclrtobot(text_win);
1127 scr_pos = scr_horz = 0;
1131 midscreen(scr_vert, point);
1133 draw_line(scr_vert, scr_horz, point, position,
1134 curr_line->line_length);
1138 struct text *txtalloc() /* allocate space for line structure */
1140 return((struct text *) malloc(sizeof( struct text)));
1143 struct files *name_alloc() /* allocate space for file name list node */
1145 return((struct files *) malloc(sizeof( struct files)));
1148 unsigned char *next_word(string) /* move to next word in string */
1149 unsigned char *string;
1151 while ((*string != '\0') && ((*string != 32) && (*string != 9)))
1153 while ((*string != '\0') && ((*string == 32) || (*string == 9)))
1159 prev_word() /* move to start of previous word in text */
1163 if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
1164 { /* if at the start of a word */
1165 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1168 while ((position != 1) && ((*point == ' ') || (*point == '\t')))
1170 while ((position != 1) && ((*point != ' ') && (*point != '\t')))
1172 if ((position != 1) && ((*point == ' ') || (*point == '\t')))
1180 control() /* use control for commands */
1184 if (in == 1) /* control a */
1186 string = get_string(ascii_code_str, TRUE);
1187 if (*string != '\0')
1190 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1195 else if (in == 2) /* control b */
1197 else if (in == 3) /* control c */
1201 else if (in == 4) /* control d */
1203 else if (in == 5) /* control e */
1205 else if (in == 6) /* control f */
1207 else if (in == 7) /* control g */
1209 else if (in == 8) /* control h */
1211 else if (in == 9) /* control i */
1213 else if (in == 10) /* control j */
1215 else if (in == 11) /* control k */
1217 else if (in == 12) /* control l */
1219 else if (in == 13) /* control m */
1221 else if (in == 14) /* control n */
1222 move_rel('d', max(5, (last_line - 5)));
1223 else if (in == 15) /* control o */
1225 else if (in == 16) /* control p */
1226 move_rel('u', max(5, (last_line - 5)));
1227 else if (in == 17) /* control q */
1229 else if (in == 18) /* control r */
1231 else if (in == 19) /* control s */
1233 else if (in == 20) /* control t */
1235 else if (in == 21) /* control u */
1237 else if (in == 22) /* control v */
1239 else if (in == 23) /* control w */
1241 else if (in == 24) /* control x */
1243 else if (in == 25) /* control y */
1245 else if (in == 26) /* control z */
1247 else if (in == 27) /* control [ (escape) */
1254 | Emacs control-key bindings
1262 if (in == 1) /* control a */
1264 else if (in == 2) /* control b */
1266 else if (in == 3) /* control c */
1270 else if (in == 4) /* control d */
1272 else if (in == 5) /* control e */
1274 else if (in == 6) /* control f */
1276 else if (in == 7) /* control g */
1277 move_rel('u', max(5, (last_line - 5)));
1278 else if (in == 8) /* control h */
1280 else if (in == 9) /* control i */
1282 else if (in == 10) /* control j */
1284 else if (in == 11) /* control k */
1286 else if (in == 12) /* control l */
1288 else if (in == 13) /* control m */
1290 else if (in == 14) /* control n */
1292 else if (in == 15) /* control o */
1294 string = get_string(ascii_code_str, TRUE);
1295 if (*string != '\0')
1298 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1303 else if (in == 16) /* control p */
1305 else if (in == 17) /* control q */
1307 else if (in == 18) /* control r */
1309 else if (in == 19) /* control s */
1311 else if (in == 20) /* control t */
1313 else if (in == 21) /* control u */
1315 else if (in == 22) /* control v */
1316 move_rel('d', max(5, (last_line - 5)));
1317 else if (in == 23) /* control w */
1319 else if (in == 24) /* control x */
1321 else if (in == 25) /* control y */
1323 else if (in == 26) /* control z */
1325 else if (in == 27) /* control [ (escape) */
1332 bottom() /* go to bottom of file */
1334 while (curr_line->next_line != NULL)
1336 curr_line = curr_line->next_line;
1339 point = curr_line->line;
1343 midscreen(last_line, point);
1348 top() /* go to top of file */
1350 while (curr_line->prev_line != NULL)
1352 curr_line = curr_line->prev_line;
1355 point = curr_line->line;
1359 midscreen(0, point);
1364 nextline() /* move pointers to start of next line */
1366 curr_line = curr_line->next_line;
1368 point = curr_line->line;
1370 if (scr_vert == last_line)
1372 wmove(text_win, 0,0);
1373 wdeleteln(text_win);
1374 wmove(text_win, last_line,0);
1375 wclrtobot(text_win);
1376 draw_line(last_line,0,point,1,curr_line->line_length);
1383 prevline() /* move pointers to start of previous line*/
1385 curr_line = curr_line->prev_line;
1387 point = curr_line->line;
1391 winsertln(text_win);
1392 draw_line(0,0,point,1,curr_line->line_length);
1396 while (position < curr_line->line_length)
1404 left(disp) /* move left one character */
1407 if (point != curr_line->line) /* if not at begin of line */
1409 if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
1417 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1420 else if (curr_line->prev_line != NULL)
1425 curr_line = curr_line->prev_line;
1426 point = curr_line->line + curr_line->line_length;
1427 position = curr_line->line_length;
1434 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1439 right(disp) /* move right one character */
1442 if (position < curr_line->line_length)
1444 if ((ee_chinese) && (*point > 127) &&
1445 ((curr_line->line_length - position) >= 2))
1453 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1456 else if (curr_line->next_line != NULL)
1461 curr_line = curr_line->next_line;
1462 point = curr_line->line;
1467 scr_pos = scr_horz = 0;
1471 midscreen(scr_vert, point);
1473 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1479 find_pos() /* move to the same column as on other line */
1483 while ((scr_horz < scr_pos) && (position < curr_line->line_length))
1486 scr_horz += tabshift(scr_horz);
1487 else if (*point < ' ')
1489 else if ((ee_chinese) && (*point > 127) &&
1490 ((curr_line->line_length - position) >= 2))
1501 if ((scr_horz - horiz_offset) > last_col)
1503 horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
1504 midscreen(scr_vert, point);
1506 else if (scr_horz < horiz_offset)
1508 horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
1509 midscreen(scr_vert, point);
1511 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1515 up() /* move up one line */
1517 if (curr_line->prev_line != NULL)
1520 point = curr_line->line;
1526 down() /* move down one line */
1528 if (curr_line->next_line != NULL)
1536 function_key() /* process function key */
1540 else if (in == KEY_RIGHT)
1542 else if (in == KEY_HOME)
1544 else if (in == KEY_END)
1546 else if (in == KEY_UP)
1548 else if (in == KEY_DOWN)
1550 else if (in == KEY_NPAGE)
1551 move_rel('d', max( 5, (last_line - 5)));
1552 else if (in == KEY_PPAGE)
1553 move_rel('u', max(5, (last_line - 5)));
1554 else if (in == KEY_DL)
1556 else if (in == KEY_DC)
1558 else if (in == KEY_BACKSPACE)
1560 else if (in == KEY_IL)
1561 { /* insert a line before current line */
1565 else if (in == KEY_F(1))
1567 else if (in == KEY_F(2))
1577 else if (in == KEY_F(3))
1587 else if (in == KEY_F(4))
1593 midscreen(scr_vert, point);
1598 else if (in == KEY_F(5))
1608 else if (in == KEY_F(6))
1618 else if (in == KEY_F(7))
1628 else if (in == KEY_F(8))
1645 sprintf(buffer, ">!%s", print_command);
1646 wmove(com_win, 0, 0);
1648 wprintw(com_win, printer_msg_str, print_command);
1659 info_type = COMMANDS;
1661 cmd_str = get_string(command_str, TRUE);
1662 if ((result = unique_test(cmd_str, commands)) != 1)
1665 wmove(com_win, 0, 0);
1667 wprintw(com_win, unkn_cmd_str, cmd_str);
1669 wprintw(com_win, non_unique_cmd_msg);
1673 info_type = CONTROL_KEYS;
1676 if (cmd_str != NULL)
1682 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
1683 info_type = CONTROL_KEYS;
1685 if (cmd_str != NULL)
1690 command(cmd_str1) /* process commands from keyboard */
1693 char *cmd_str2 = NULL;
1694 char *cmd_str = cmd_str1;
1696 clear_com_win = TRUE;
1697 if (compare(cmd_str, HELP, FALSE))
1699 else if (compare(cmd_str, WRITE, FALSE))
1701 if (restrict_mode())
1705 cmd_str = next_word(cmd_str);
1706 if (*cmd_str == '\0')
1708 cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
1710 tmp_file = resolve_name(cmd_str);
1711 write_file(tmp_file, 1);
1712 if (tmp_file != cmd_str)
1715 else if (compare(cmd_str, READ, FALSE))
1717 if (restrict_mode())
1721 cmd_str = next_word(cmd_str);
1722 if (*cmd_str == '\0')
1724 cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
1728 tmp_file = resolve_name(cmd_str);
1730 if (tmp_file != cmd_str)
1733 else if (compare(cmd_str, LINE, FALSE))
1735 wmove(com_win, 0, 0);
1737 wprintw(com_win, line_num_str, curr_line->line_number);
1738 wprintw(com_win, line_len_str, curr_line->line_length);
1740 else if (compare(cmd_str, FILE_str, FALSE))
1742 wmove(com_win, 0, 0);
1744 if (in_file_name == NULL)
1745 wprintw(com_win, no_file_string);
1747 wprintw(com_win, current_file_str, in_file_name);
1749 else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1751 else if (compare(cmd_str, CHARACTER, FALSE))
1753 wmove(com_win, 0, 0);
1755 wprintw(com_win, char_str, *point);
1757 else if (compare(cmd_str, REDRAW, FALSE))
1759 else if (compare(cmd_str, RESEQUENCE, FALSE))
1761 tmp_line = first_line->next_line;
1762 while (tmp_line != NULL)
1764 tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1765 tmp_line = tmp_line->next_line;
1768 else if (compare(cmd_str, AUTHOR, FALSE))
1770 wmove(com_win, 0, 0);
1772 wprintw(com_win, "written by Hugh Mahon");
1774 else if (compare(cmd_str, VERSION, FALSE))
1776 wmove(com_win, 0, 0);
1778 wprintw(com_win, "%s", version);
1780 else if (compare(cmd_str, CASE, FALSE))
1782 else if (compare(cmd_str, NOCASE, FALSE))
1784 else if (compare(cmd_str, EXPAND, FALSE))
1786 else if (compare(cmd_str, NOEXPAND, FALSE))
1787 expand_tabs = FALSE;
1788 else if (compare(cmd_str, Exit_string, FALSE))
1790 else if (compare(cmd_str, chinese_cmd, FALSE))
1794 nc_setattrib(A_NC_BIG5);
1797 else if (compare(cmd_str, nochinese_cmd, FALSE))
1801 nc_clearattrib(A_NC_BIG5);
1804 else if (compare(cmd_str, QUIT_string, FALSE))
1806 else if (*cmd_str == '!')
1809 if ((*cmd_str == ' ') || (*cmd_str == 9))
1810 cmd_str = next_word(cmd_str);
1811 sh_command(cmd_str);
1813 else if ((*cmd_str == '<') && (!in_pipe))
1818 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1819 cmd_str = next_word(cmd_str);
1824 else if ((*cmd_str == '>') && (!out_pipe))
1828 if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1829 cmd_str = next_word(cmd_str);
1835 wmove(com_win, 0, 0);
1837 wprintw(com_win, unkn_cmd_str, cmd_str);
1839 if (cmd_str2 != NULL)
1844 scan(line, offset, column) /* determine horizontal position for get_string */
1859 j += len_char(*stemp, j);
1866 get_string(prompt, advance) /* read string from input on command line */
1867 char *prompt; /* string containing user prompt message */
1868 int advance; /* if true, skip leading spaces and tabs */
1875 int g_horz, g_position, g_pos;
1878 g_point = tmp_string = malloc(512);
1881 waddstr(com_win, prompt);
1883 nam_str = tmp_string;
1884 clear_com_win = TRUE;
1885 g_horz = g_position = scan(prompt, strlen(prompt), 0);
1890 in = wgetch(com_win);
1893 if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
1897 g_horz = scan(g_point, g_pos, g_position);
1898 tmp_int = tmp_int - g_horz;
1899 for (; 0 < tmp_int; tmp_int--)
1901 if ((g_horz+tmp_int) < (last_col - 1))
1903 waddch(com_win, '\010');
1904 waddch(com_win, ' ');
1905 waddch(com_win, '\010');
1910 else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
1912 if (in == '\026') /* control-v, accept next character verbatim */
1913 { /* allows entry of ^m, ^j, and ^h */
1915 in = wgetch(com_win);
1921 if (!isprint((unsigned char)in) && (g_horz < (last_col - 1)))
1922 g_horz += out_char(com_win, in, g_horz);
1926 if (g_horz < (last_col - 1))
1927 waddch(com_win, (unsigned char)in);
1934 } while ((in != '\n') && (in != '\r'));
1936 nam_str = tmp_string;
1937 if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
1938 nam_str = next_word(nam_str);
1939 string = malloc(strlen(nam_str) + 1);
1940 strcpy(string, nam_str);
1947 compare(string1, string2, sensitive) /* compare two strings */
1960 if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
1967 if (*strng1 != *strng2)
1972 if (toupper((unsigned char)*strng1) != toupper((unsigned char)*strng2))
1977 if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
1991 char direction = '\0';
1992 struct text *t_line;
1996 while ((*ptr >='0') && (*ptr <= '9'))
1998 i= i * 10 + (*ptr - '0');
2004 while ((t_line->line_number > number) && (t_line->prev_line != NULL))
2007 t_line = t_line->prev_line;
2010 while ((t_line->line_number < number) && (t_line->next_line != NULL))
2014 t_line = t_line->next_line;
2016 if ((i < 30) && (i > 0))
2018 move_rel(direction, i);
2022 if (direction != 'd')
2031 point = curr_line->line;
2033 midscreen((last_line / 2), point);
2036 wmove(com_win, 0, 0);
2038 wprintw(com_win, line_num_str, curr_line->line_number);
2039 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2043 midscreen(line, pnt) /* put current line in middle of screen */
2047 struct text *mid_line;
2050 line = min(line, last_line);
2051 mid_line = curr_line;
2052 for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
2053 curr_line = curr_line->prev_line;
2054 scr_vert = scr_horz = 0;
2055 wmove(text_win, 0, 0);
2058 curr_line = mid_line;
2060 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2064 get_options(numargs, arguments) /* get arguments from command line */
2070 struct files *temp_names = NULL;
2073 int no_more_opts = FALSE;
2076 | see if editor was invoked as 'ree' (restricted mode)
2079 if (!(name = strrchr(arguments[0], '/')))
2080 name = arguments[0];
2083 if (!strcmp(name, "ree"))
2086 top_of_stack = NULL;
2090 while ((count < numargs)&& (!no_more_opts))
2092 buff = arguments[count];
2093 if (!strcmp("-i", buff))
2095 info_window = FALSE;
2097 else if (!strcmp("-e", buff))
2099 expand_tabs = FALSE;
2101 else if (!strcmp("-h", buff))
2105 else if (!strcmp("-?", buff))
2107 fprintf(stderr, usage0, arguments[0]);
2108 fputs(usage1, stderr);
2109 fputs(usage2, stderr);
2110 fputs(usage3, stderr);
2111 fputs(usage4, stderr);
2114 else if ((*buff == '+') && (start_at_line == NULL))
2117 start_at_line = buff;
2119 else if (!(strcmp("--", buff)))
2120 no_more_opts = TRUE;
2124 no_more_opts = TRUE;
2128 while (count < numargs)
2130 buff = arguments[count];
2131 if (top_of_stack == NULL)
2133 temp_names = top_of_stack = name_alloc();
2137 temp_names->next_name = name_alloc();
2138 temp_names = temp_names->next_name;
2140 ptr = temp_names->name = malloc(strlen(buff) + 1);
2141 while (*buff != '\0')
2148 temp_names->next_name = NULL;
2156 check_fp() /* open or close files according to flags */
2162 clear_com_win = TRUE;
2163 tmp_vert = scr_vert;
2164 tmp_horz = scr_horz;
2165 tmp_line = curr_line;
2168 in_file_name = tmp_file = top_of_stack->name;
2169 top_of_stack = top_of_stack->next_name;
2171 temp = stat(tmp_file, &buf);
2172 buf.st_mode &= ~07777;
2173 if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
2175 wprintw(com_win, file_is_dir_msg, tmp_file);
2185 if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
2187 wmove(com_win, 0, 0);
2190 wprintw(com_win, new_file_msg, tmp_file);
2192 wprintw(com_win, cant_open_msg, tmp_file);
2194 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2204 line_num = curr_line->line_number;
2205 scr_vert = tmp_vert;
2206 scr_horz = tmp_horz;
2208 curr_line= first_line;
2210 curr_line = tmp_line;
2211 point = curr_line->line;
2216 if (start_at_line != NULL)
2218 line_num = atoi(start_at_line) - 1;
2219 move_rel('d', line_num);
2221 start_at_line = NULL;
2226 wmove(com_win, 0, 0);
2228 text_changes = TRUE;
2229 if ((tmp_file != NULL) && (*tmp_file != '\0'))
2230 wprintw(com_win, file_read_fin_msg, tmp_file);
2233 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2238 get_file(file_name) /* read specified file into current buffer */
2241 int can_read; /* file has at least one character */
2242 int length; /* length of line read by read */
2243 int append; /* should text be appended to current line */
2244 struct text *temp_line;
2245 char ro_flag = FALSE;
2247 if (recv_file) /* if reading a file */
2249 wmove(com_win, 0, 0);
2251 wprintw(com_win, reading_file_msg, file_name);
2252 if (access(file_name, 2)) /* check permission to write */
2254 if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
2256 wprintw(com_win, read_only_msg);
2262 if (curr_line->line_length > 1) /* if current line is not blank */
2270 can_read = FALSE; /* test if file has any characters */
2271 while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
2273 can_read = TRUE; /* if set file has at least 1 character */
2274 get_line(length, in_string, &append);
2276 if ((can_read) && (curr_line->line_length == 1))
2278 temp_line = curr_line->prev_line;
2279 temp_line->next_line = curr_line->next_line;
2280 if (temp_line->next_line != NULL)
2281 temp_line->next_line->prev_line = temp_line;
2282 if (curr_line->line != NULL)
2283 free(curr_line->line);
2285 curr_line = temp_line;
2287 if (input_file) /* if this is the file to be edited display number of lines */
2289 wmove(com_win, 0, 0);
2291 wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
2293 wprintw(com_win, read_only_msg);
2296 else if (can_read) /* not input_file and file is non-zero size */
2297 text_changes = TRUE;
2299 if (recv_file) /* if reading a file */
2306 get_line(length, in_string, append) /* read string and split into lines */
2307 int length; /* length of string read by read */
2308 unsigned char *in_string; /* string read by read */
2309 int *append; /* TRUE if must append more text to end of current line */
2311 unsigned char *str1;
2312 unsigned char *str2;
2313 int num; /* offset from start of string */
2314 int char_count; /* length of new line (or added portion */
2315 int temp_counter; /* temporary counter value */
2316 struct text *tline; /* temporary pointer to new line */
2317 int first_time; /* if TRUE, the first time through the loop */
2322 while (num < length)
2336 /* find end of line */
2337 while ((*str2 != '\n') && (num < length))
2343 if (!(*append)) /* if not append to current line, insert new one */
2345 tline = txtalloc(); /* allocate data structure for next line */
2346 tline->line_number = curr_line->line_number + 1;
2347 tline->next_line = curr_line->next_line;
2348 tline->prev_line = curr_line;
2349 curr_line->next_line = tline;
2350 if (tline->next_line != NULL)
2351 tline->next_line->prev_line = tline;
2353 curr_line->line = point = (unsigned char *) malloc(char_count);
2354 curr_line->line_length = char_count;
2355 curr_line->max_length = char_count;
2359 point = resiz_line(char_count, curr_line, curr_line->line_length);
2360 curr_line->line_length += (char_count - 1);
2362 for (temp_counter = 1; temp_counter < char_count; temp_counter++)
2370 if ((num == length) && (*str2 != '\n'))
2376 draw_screen() /* redraw the screen from current postion */
2378 struct text *temp_line;
2379 unsigned char *line_out;
2382 temp_line = curr_line;
2383 temp_vert = scr_vert;
2384 wclrtobot(text_win);
2385 while ((temp_line != NULL) && (temp_vert <= last_line))
2387 line_out = temp_line->line;
2388 draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
2390 temp_line = temp_line->next_line;
2392 wmove(text_win, temp_vert, 0);
2393 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
2397 finish() /* prepare to exit edit session */
2399 char *file_name = in_file_name;
2402 | changes made here should be reflected in the 'save'
2403 | portion of file_op()
2406 if ((file_name == NULL) || (*file_name == '\0'))
2407 file_name = get_string(save_file_name_prompt, TRUE);
2409 if ((file_name == NULL) || (*file_name == '\0'))
2411 wmove(com_win, 0, 0);
2412 wprintw(com_win, file_not_saved_msg);
2415 clear_com_win = TRUE;
2419 tmp_file = resolve_name(file_name);
2420 if (tmp_file != file_name)
2423 file_name = tmp_file;
2426 if (write_file(file_name, 1))
2428 text_changes = FALSE;
2434 quit(noverify) /* exit editor */
2441 if ((text_changes) && (!noverify))
2443 ans = get_string(changes_made_prompt, TRUE);
2444 if (toupper((unsigned char)*ans) == toupper((unsigned char)*yes_char))
2445 text_changes = FALSE;
2450 if (top_of_stack == NULL)
2484 while (curr_line->next_line != NULL)
2485 curr_line = curr_line->next_line;
2486 while (curr_line != first_line)
2488 free(curr_line->line);
2489 curr_line = curr_line->prev_line;
2491 free(curr_line->next_line);
2493 curr_line->next_line = NULL;
2494 *curr_line->line = '\0';
2495 curr_line->line_length = 1;
2496 curr_line->line_number = 1;
2497 point = curr_line->line;
2498 scr_pos = scr_vert = scr_horz = 0;
2503 write_file(file_name, warn_if_exists)
2509 struct text *out_line;
2512 int write_flag = TRUE;
2515 if (warn_if_exists &&
2516 ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
2518 if ((temp_fp = fopen(file_name, "r")))
2520 tmp_point = get_string(file_exists_prompt, TRUE);
2521 if (toupper((unsigned char)*tmp_point) == toupper((unsigned char)*yes_char))
2530 clear_com_win = TRUE;
2534 if ((temp_fp = fopen(file_name, "w")) == NULL)
2536 clear_com_win = TRUE;
2539 wprintw(com_win, create_file_fail_msg, file_name);
2547 wprintw(com_win, writing_file_msg, file_name);
2550 out_line = first_line;
2551 while (out_line != NULL)
2554 tmp_point= out_line->line;
2555 while (temp_pos < out_line->line_length)
2557 putc(*tmp_point, temp_fp);
2561 charac += out_line->line_length;
2562 out_line = out_line->next_line;
2569 wprintw(com_win, file_written_msg, file_name, lines, charac);
2579 search(display_message) /* search for string in srch_str */
2580 int display_message;
2586 if ((srch_str == NULL) || (*srch_str == '\0'))
2588 if (display_message)
2590 wmove(com_win, 0, 0);
2592 wprintw(com_win, searching_msg);
2594 clear_com_win = TRUE;
2598 srch_line = curr_line;
2600 if (position < curr_line->line_length)
2602 iter = position + 1;
2603 while ((!found) && (srch_line != NULL))
2605 while ((iter < srch_line->line_length) && (!found))
2608 if (case_sen) /* if case sensitive */
2611 while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
2618 else /* if not case sensitive */
2620 srch_3 = u_srch_str;
2621 while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
2628 if (!((*srch_3 == '\0') && (found)))
2631 if (iter < srch_line->line_length)
2638 srch_line = srch_line->next_line;
2639 if (srch_line != NULL)
2640 srch_1 = srch_line->line;
2647 if (display_message)
2649 wmove(com_win, 0, 0);
2653 if (lines_moved == 0)
2655 while (position < iter)
2660 if (lines_moved < 30)
2662 move_rel('d', lines_moved);
2663 while (position < iter)
2668 absolute_lin += lines_moved;
2669 curr_line = srch_line;
2674 midscreen((last_line / 2), point);
2680 if (display_message)
2682 wmove(com_win, 0, 0);
2684 wprintw(com_win, str_not_found_msg, srch_str);
2687 wmove(text_win, scr_vert,(scr_horz - horiz_offset));
2693 search_prompt() /* prompt and read search string (srch_str) */
2695 if (srch_str != NULL)
2697 if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
2699 srch_str = get_string(search_prompt_str, FALSE);
2702 srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
2703 while (*srch_3 != '\0')
2705 *srch_1 = toupper(*srch_3);
2714 del_char() /* delete current character */
2716 in = 8; /* backspace */
2717 if (position < curr_line->line_length) /* if not end of line */
2719 if ((ee_chinese) && (*point > 127) &&
2720 ((curr_line->line_length - position) >= 2))
2738 undel_char() /* undelete last deleted character */
2740 if (d_char[0] == '\n') /* insert line if last del_char deleted eol */
2746 if (d_char[1] != '\0')
2755 del_word() /* delete word in front of cursor */
2759 unsigned char *d_word2;
2760 unsigned char *d_word3;
2761 unsigned char tmp_char[3];
2765 d_word = malloc(curr_line->line_length);
2766 tmp_char[0] = d_char[0];
2767 tmp_char[1] = d_char[1];
2768 tmp_char[2] = d_char[2];
2772 while ((tposit < curr_line->line_length) &&
2773 ((*d_word3 != ' ') && (*d_word3 != '\t')))
2776 *d_word2 = *d_word3;
2780 while ((tposit < curr_line->line_length) &&
2781 ((*d_word3 == ' ') || (*d_word3 == '\t')))
2784 *d_word2 = *d_word3;
2789 d_wrd_len = difference = d_word2 - d_word;
2791 while (tposit < curr_line->line_length)
2794 *d_word2 = *d_word3;
2798 curr_line->line_length -= difference;
2800 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2801 d_char[0] = tmp_char[0];
2802 d_char[1] = tmp_char[1];
2803 d_char[2] = tmp_char[2];
2804 text_changes = TRUE;
2809 undel_word() /* undelete last deleted word */
2813 unsigned char *tmp_old_ptr;
2814 unsigned char *tmp_space;
2815 unsigned char *tmp_ptr;
2816 unsigned char *d_word_ptr;
2819 | resize line to handle undeleted word
2821 if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
2822 point = resiz_line(d_wrd_len, curr_line, position);
2823 tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
2824 d_word_ptr = d_word;
2827 | copy d_word contents into temp space
2829 while (temp <= d_wrd_len)
2832 *tmp_ptr = *d_word_ptr;
2836 tmp_old_ptr = point;
2839 | copy contents of line from curent position to eol into
2842 while (tposit < curr_line->line_length)
2846 *tmp_ptr = *tmp_old_ptr;
2850 curr_line->line_length += d_wrd_len;
2851 tmp_old_ptr = point;
2853 tmp_ptr = tmp_space;
2856 | now copy contents from temp space back to original line
2858 while (tposit < temp)
2861 *tmp_old_ptr = *tmp_ptr;
2865 *tmp_old_ptr = '\0';
2867 draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
2871 del_line() /* delete from cursor to end of line */
2879 d_line = malloc(curr_line->line_length);
2883 while (tposit < curr_line->line_length)
2890 dlt_line->line_length = 1 + tposit - position;
2893 curr_line->line_length = position;
2894 wclrtoeol(text_win);
2895 if (curr_line->next_line != NULL)
2900 text_changes = TRUE;
2904 undel_line() /* undelete last deleted line */
2910 if (dlt_line->line_length == 0)
2915 point = resiz_line(dlt_line->line_length, curr_line, position);
2916 curr_line->line_length += dlt_line->line_length - 1;
2920 while (tposit < dlt_line->line_length)
2928 draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
2932 adv_word() /* advance to next word */
2934 while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
2936 while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
2941 move_rel(direction, lines) /* move relative to current line */
2948 if (direction == 'u')
2951 while (position > 1)
2953 for (i = 0; i < lines; i++)
2957 if ((last_line > 5) && ( scr_vert < 4))
2960 tmp_line = curr_line;
2961 for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
2965 scr_vert = scr_vert + i;
2966 curr_line = tmp_line;
2974 if ((position != 1) && (curr_line->next_line != NULL))
2977 scr_pos = scr_horz = 0;
2981 midscreen(scr_vert, point);
2986 for (i = 1; i < lines; i++)
2990 if ((last_line > 10) && (scr_vert > (last_line - 5)))
2993 tmp_line = curr_line;
2994 for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
2999 scr_vert = scr_vert - i;
3000 curr_line = tmp_line;
3005 wmove(text_win, scr_vert, (scr_horz - horiz_offset));
3009 eol() /* go to end of line */
3011 if (position < curr_line->line_length)
3013 while (position < curr_line->line_length)
3016 else if (curr_line->next_line != NULL)
3019 while (position < curr_line->line_length)
3025 bol() /* move to beginning of line */
3027 if (point != curr_line->line)
3029 while (point != curr_line->line)
3032 else if (curr_line->prev_line != NULL)
3040 adv_line() /* advance to beginning of next line */
3042 if ((point != curr_line->line) || (scr_pos > 0))
3044 while (position < curr_line->line_length)
3048 else if (curr_line->next_line != NULL)
3058 struct text *tmpline = first_line;
3061 while ((tmpline != NULL) && (tmpline != curr_line))
3064 tmpline = tmpline->next_line;
3070 sh_command(string) /* execute shell command */
3071 char *string; /* string containing user command */
3075 char *path; /* directory path to executable */
3076 int parent; /* zero if child, child's pid if parent */
3079 struct text *line_holder;
3081 if (restrict_mode())
3086 if (!(path = getenv("SHELL")))
3088 last_slash = temp_point = path;
3089 while (*temp_point != '\0')
3091 if (*temp_point == '/')
3092 last_slash = ++temp_point;
3098 | if in_pipe is true, then output of the shell operation will be
3099 | read by the editor, and curses doesn't need to be turned off
3104 keypad(com_win, FALSE);
3105 keypad(text_win, FALSE);
3118 pipe(pipe_in); /* create a pipe */
3120 if (!parent) /* if the child */
3123 | child process which will fork and exec shell command (if shell output is
3124 | to be read by editor)
3128 | redirect stdout to pipe
3130 temp_stdout = dup(1);
3134 | redirect stderr to pipe
3136 temp_stderr = dup(2);
3141 | child will now continue down 'if (!in_pipe)'
3145 else /* if the parent */
3148 | prepare editor to read from the pipe
3150 signal(SIGCHLD, SIG_IGN);
3151 line_holder = curr_line;
3152 tmp_vert = scr_vert;
3154 get_fd = pipe_in[0];
3157 scr_vert = tmp_vert;
3158 scr_horz = scr_pos = 0;
3160 curr_line = line_holder;
3162 point = curr_line->line;
3164 signal(SIGCHLD, SIG_DFL);
3166 | since flag "in_pipe" is still TRUE, the path which waits for the child
3167 | process to die will be avoided.
3168 | (the pipe is closed, no more output can be expected)
3174 signal(SIGINT, SIG_IGN);
3180 | fork process which will exec command
3183 if (!parent) /* if the child */
3190 | prepare the child process (soon to exec a shell command) to read from the
3191 | pipe (which will be output from the editor's buffer)
3198 for (value = 1; value < 24; value++)
3199 signal(value, SIG_DFL);
3200 execl(path, last_slash, "-c", string, NULL);
3201 fprintf(stderr, exec_err_msg, path);
3204 else /* if the parent */
3209 | output the contents of the buffer to the pipe (to be read by the
3210 | process forked and exec'd above as stdin)
3213 line_holder = first_line;
3214 while (line_holder != NULL)
3216 write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
3217 write(pipe_out[1], "\n", 1);
3218 line_holder = line_holder->next_line;
3225 return_val = wait((int *) 0);
3227 while ((return_val != parent) && (return_val != -1));
3229 | if this process is actually the child of the editor, exit. Here's how it
3231 | The editor forks a process. If output must be sent to the command to be
3232 | exec'd another process is forked, and that process (the child's child)
3233 | will exec the command. In this case, "shell_fork" will be FALSE. If no
3234 | output is to be performed to the shell command, "shell_fork" will be TRUE.
3235 | If this is the editor process, shell_fork will be true, otherwise this is
3236 | the child of the edit process.
3241 signal(SIGINT, edit_abort);
3245 fputs(continue_msg, stdout);
3247 while ((in = getchar()) != '\n')
3257 keypad(text_win, TRUE);
3258 keypad(com_win, TRUE);
3260 clearok(info_win, TRUE);
3267 set_up_term() /* set up the terminal for operating with ae */
3269 if (!curses_initialized)
3276 curses_initialized = TRUE;
3279 if (((LINES > 15) && (COLS >= 80)) && info_window)
3280 last_line = LINES - 8;
3283 info_window = FALSE;
3284 last_line = LINES - 2;
3287 idlok(stdscr, TRUE);
3288 com_win = newwin(1, COLS, (LINES - 1), 0);
3289 keypad(com_win, TRUE);
3290 idlok(com_win, TRUE);
3293 text_win = newwin((LINES - 1), COLS, 0, 0);
3295 text_win = newwin((LINES - 7), COLS, 6, 0);
3296 keypad(text_win, TRUE);
3297 idlok(text_win, TRUE);
3299 help_win = newwin((LINES - 1), COLS, 0, 0);
3300 keypad(help_win, TRUE);
3301 idlok(help_win, TRUE);
3304 info_type = CONTROL_KEYS;
3305 info_win = newwin(6, COLS, 0, 0);
3310 last_col = COLS - 1;
3311 local_LINES = LINES;
3316 nc_setattrib(A_NC_BIG5);
3324 if ((LINES == local_LINES) && (COLS == local_COLS))
3337 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
3341 struct menu_entries menu_list[];
3344 int max_width, max_height;
3351 int top_offset; /* offset from top where menu items start */
3352 int vert_pos; /* vertical position */
3353 int vert_size; /* vertical size for menu list item display */
3354 int off_start = 1; /* offset from start of menu items to start display */
3358 | determine number and width of menu items
3362 while (menu_list[list_size + 1].item_string != NULL)
3365 for (counter = 0; counter <= list_size; counter++)
3367 if ((length = strlen(menu_list[counter].item_string)) > max_width)
3371 max_width = max(max_width, strlen(menu_cancel_msg));
3372 max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
3376 | make sure that window is large enough to handle menu
3377 | if not, print error message and return to calling function
3380 if (max_width > COLS)
3382 wmove(com_win, 0, 0);
3384 wprintw(com_win, menu_too_lrg_msg);
3386 clear_com_win = TRUE;
3392 if (list_size > LINES)
3395 if (max_height > 11)
3396 vert_size = max_height - 8;
3398 vert_size = max_height;
3402 vert_size = list_size;
3403 max_height = list_size;
3406 if (LINES >= (vert_size + 8))
3408 if (menu_list[0].argument != MENU_WARN)
3409 max_height = vert_size + 8;
3411 max_height = vert_size + 7;
3414 x_off = (COLS - max_width) / 2;
3415 y_off = (LINES - max_height - 1) / 2;
3416 temp_win = newwin(max_height, max_width, y_off, x_off);
3417 keypad(temp_win, TRUE);
3419 paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
3426 wmove(temp_win, (1 + counter + top_offset - off_start), 3);
3428 wmove(temp_win, (counter + top_offset - off_start), 3);
3431 in = wgetch(temp_win);
3436 if (isascii(input) && isalnum(input))
3440 temp = 1 + tolower(input) - 'a';
3442 else if (isdigit(input))
3444 temp = (2 + 'z' - 'a') + (input - '0');
3447 if (temp <= list_size)
3457 case ' ': /* space */
3458 case '\004': /* ^d, down */
3462 if (counter > list_size)
3465 case '\010': /* ^h, backspace*/
3466 case '\025': /* ^u, up */
3467 case 127: /* ^?, delete */
3473 counter = list_size;
3475 case '\033': /* escape key */
3476 if (menu_list[0].argument != MENU_WARN)
3479 case '\014': /* ^l */
3480 case '\022': /* ^r, redraw */
3481 paint_menu(menu_list, max_width, max_height,
3482 list_size, top_offset, temp_win,
3483 off_start, vert_size);
3490 if (((list_size - off_start) >= (vert_size - 1)) &&
3491 (counter > (off_start + vert_size - 3)) &&
3494 if (counter == list_size)
3495 off_start = (list_size - vert_size) + 2;
3499 paint_menu(menu_list, max_width, max_height,
3500 list_size, top_offset, temp_win, off_start,
3503 else if ((list_size != vert_size) &&
3504 (counter > (off_start + vert_size - 2)))
3506 if (counter == list_size)
3507 off_start = 2 + (list_size - vert_size);
3508 else if (off_start == 1)
3513 paint_menu(menu_list, max_width, max_height,
3514 list_size, top_offset, temp_win, off_start,
3517 else if (counter < off_start)
3522 off_start = counter;
3524 paint_menu(menu_list, max_width, max_height,
3525 list_size, top_offset, temp_win, off_start,
3529 while ((input != '\r') && (input != '\n') && (counter != 0));
3535 if ((menu_list[counter].procedure != NULL) ||
3536 (menu_list[counter].iprocedure != NULL) ||
3537 (menu_list[counter].nprocedure != NULL))
3539 if (menu_list[counter].argument != -1)
3540 (*menu_list[counter].iprocedure)(menu_list[counter].argument);
3541 else if (menu_list[counter].ptr_argument != NULL)
3542 (*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
3544 (*menu_list[counter].nprocedure)();
3555 paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
3556 off_start, vert_size)
3557 struct menu_entries menu_list[];
3558 int max_width, max_height, list_size, top_offset;
3560 int off_start, vert_size;
3562 int counter, temp_int;
3567 | output top and bottom portions of menu box only if window
3571 if (max_height > vert_size)
3573 wmove(menu_win, 1, 1);
3575 wstandout(menu_win);
3576 waddch(menu_win, '+');
3577 for (counter = 0; counter < (max_width - 4); counter++)
3578 waddch(menu_win, '-');
3579 waddch(menu_win, '+');
3581 wmove(menu_win, (max_height - 2), 1);
3582 waddch(menu_win, '+');
3583 for (counter = 0; counter < (max_width - 4); counter++)
3584 waddch(menu_win, '-');
3585 waddch(menu_win, '+');
3586 wstandend(menu_win);
3587 wmove(menu_win, 2, 3);
3588 waddstr(menu_win, menu_list[0].item_string);
3589 wmove(menu_win, (max_height - 3), 3);
3590 if (menu_list[0].argument != MENU_WARN)
3591 waddstr(menu_win, menu_cancel_msg);
3594 wstandout(menu_win);
3596 for (counter = 0; counter < (vert_size + top_offset); counter++)
3598 if (top_offset == 4)
3600 temp_int = counter + 2;
3605 wmove(menu_win, temp_int, 1);
3606 waddch(menu_win, '|');
3607 wmove(menu_win, temp_int, (max_width - 2));
3608 waddch(menu_win, '|');
3610 wstandend(menu_win);
3612 if (list_size > vert_size)
3617 wmove(menu_win, top_offset, 3);
3618 waddstr(menu_win, more_above_str);
3623 for (counter = off_start;
3624 ((temp_int + counter - off_start) < (vert_size - 1));
3627 wmove(menu_win, (top_offset + temp_int +
3628 (counter - off_start)), 3);
3630 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3631 waddstr(menu_win, menu_list[counter].item_string);
3634 wmove(menu_win, (top_offset + (vert_size - 1)), 3);
3636 if (counter == list_size)
3639 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3640 wprintw(menu_win, menu_list[counter].item_string);
3643 wprintw(menu_win, more_below_str);
3647 for (counter = 1; counter <= list_size; counter++)
3649 wmove(menu_win, (top_offset + counter - 1), 3);
3651 wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
3652 waddstr(menu_win, menu_list[counter].item_string);
3663 clearok(help_win, TRUE);
3664 for (counter = 0; counter < 22; counter++)
3666 wmove(help_win, counter, 0);
3667 waddstr(help_win, (emacs_keys_mode) ?
3668 emacs_help_text[counter] : help_text[counter]);
3672 wmove(com_win, 0, 0);
3673 wprintw(com_win, press_any_key_msg);
3675 counter = wgetch(com_win);
3679 wmove(com_win, 0, 0);
3695 for (counter = 0; counter < 5; counter++)
3697 wmove(info_win, counter, 0);
3698 wclrtoeol(info_win);
3699 if (info_type == CONTROL_KEYS)
3700 waddstr(info_win, (emacs_keys_mode) ?
3701 emacs_control_keys[counter] : control_keys[counter]);
3702 else if (info_type == COMMANDS)
3703 waddstr(info_win, command_strings[counter]);
3705 wmove(info_win, 5, 0);
3707 wstandout(info_win);
3708 waddstr(info_win, separator);
3709 wstandend(info_win);
3720 info_window = FALSE;
3721 last_line = LINES - 2;
3722 text_win = newwin((LINES - 1), COLS, 0, 0);
3723 keypad(text_win, TRUE);
3724 idlok(text_win, TRUE);
3725 clearok(text_win, TRUE);
3726 midscreen(scr_vert, point);
3728 clear_com_win = TRUE;
3732 create_info_window()
3736 last_line = LINES - 8;
3738 text_win = newwin((LINES - 7), COLS, 6, 0);
3739 keypad(text_win, TRUE);
3740 idlok(text_win, TRUE);
3743 info_win = newwin(6, COLS, 0, 0);
3745 info_type = CONTROL_KEYS;
3746 midscreen(min(scr_vert, last_line), point);
3747 clearok(info_win, TRUE);
3750 clear_com_win = TRUE;
3760 if (restrict_mode())
3765 if (arg == READ_FILE)
3767 string = get_string(file_read_prompt_str, TRUE);
3769 tmp_file = resolve_name(string);
3771 if (tmp_file != string)
3775 else if (arg == WRITE_FILE)
3777 string = get_string(file_write_prompt_str, TRUE);
3778 tmp_file = resolve_name(string);
3779 write_file(tmp_file, 1);
3780 if (tmp_file != string)
3784 else if (arg == SAVE_FILE)
3787 | changes made here should be reflected in finish()
3795 string = in_file_name;
3796 if ((string == NULL) || (*string == '\0'))
3797 string = get_string(save_file_name_prompt, TRUE);
3798 if ((string == NULL) || (*string == '\0'))
3800 wmove(com_win, 0, 0);
3801 wprintw(com_win, file_not_saved_msg);
3804 clear_com_win = TRUE;
3809 tmp_file = resolve_name(string);
3810 if (tmp_file != string)
3816 if (write_file(string, 1))
3818 in_file_name = string;
3819 text_changes = FALSE;
3832 if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
3845 menu_op(leave_menu);
3856 clearok(info_win, TRUE);
3860 clearok(text_win, TRUE);
3861 midscreen(scr_vert, point);
3865 | The following routines will "format" a paragraph (as defined by a
3866 | block of text with blank lines before and after the block).
3870 Blank_Line(test_line) /* test if line has any non-space characters */
3871 struct text *test_line;
3873 unsigned char *line;
3876 if (test_line == NULL)
3880 line = test_line->line;
3883 | To handle troff/nroff documents, consider a line with a
3884 | period ('.') in the first column to be blank. To handle mail
3885 | messages with included text, consider a line with a '>' blank.
3888 if ((*line == '.') || (*line == '>'))
3891 while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
3896 if (length != test_line->line_length)
3903 Format() /* format the paragraph according to set margins */
3911 unsigned char *line;
3912 unsigned char *tmp_srchstr;
3913 unsigned char *temp1, *temp2;
3914 unsigned char *temp_dword;
3915 unsigned char temp_d_char[3];
3917 temp_d_char[0] = d_char[0];
3918 temp_d_char[1] = d_char[1];
3919 temp_d_char[2] = d_char[2];
3922 | if observ_margins is not set, or the current line is blank,
3923 | do not format the current paragraph
3926 if ((!observ_margins) || (Blank_Line(curr_line)))
3930 | save the currently set flags, and clear them
3933 wmove(com_win, 0, 0);
3935 wprintw(com_win, formatting_msg);
3939 | get current position in paragraph, so after formatting, the cursor
3940 | will be in the same relative position
3943 tmp_af = auto_format;
3944 auto_format = FALSE;
3948 temp_dword = d_word;
3950 temp_case = case_sen;
3952 tmp_srchstr = srch_str;
3953 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
3954 if ((*point == ' ') || (*point == '\t'))
3958 line = temp1 = point;
3959 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
3969 while (!Blank_Line(curr_line->prev_line))
3973 while ((line != point) && (status))
3975 status = search(FALSE);
3979 wmove(com_win, 0, 0);
3981 wprintw(com_win, formatting_msg);
3985 | now get back to the start of the paragraph to start formatting
3990 while (!Blank_Line(curr_line->prev_line))
3993 observ_margins = FALSE;
3996 | Start going through lines, putting spaces at end of lines if they do
3997 | not already exist. Append lines together to get one long line, and
3998 | eliminate spacing at begin of lines.
4001 while (!Blank_Line(curr_line->next_line))
4013 if ((*point == ' ') || (*point == '\t'))
4018 | Now there is one long line. Eliminate extra spaces within the line
4019 | after the first word (so as not to blow away any indenting the user
4025 while (position < curr_line->line_length)
4027 if ((*point == ' ') && (*(point + 1) == ' '))
4034 | Now make sure there are two spaces after a '.'.
4038 while (position < curr_line->line_length)
4040 if ((*point == '.') && (*(point + 1) == ' '))
4045 while (*point == ' ')
4051 observ_margins = TRUE;
4054 wmove(com_win, 0, 0);
4056 wprintw(com_win, formatting_msg);
4060 | create lines between margins
4063 while (position < curr_line->line_length)
4065 while ((scr_pos < right_margin) && (position < curr_line->line_length))
4067 if (position < curr_line->line_length)
4077 | go back to begin of paragraph, put cursor back to original position
4081 while (!Blank_Line(curr_line->prev_line))
4085 | find word cursor was in
4088 while ((status) && (string_count > 0))
4095 | offset the cursor to where it was before from the start of the word
4105 | reset flags and strings to what they were before formatting
4110 d_word = temp_dword;
4111 case_sen = temp_case;
4113 srch_str = tmp_srchstr;
4114 d_char[0] = temp_d_char[0];
4115 d_char[1] = temp_d_char[1];
4116 d_char[2] = temp_d_char[2];
4117 auto_format = tmp_af;
4119 midscreen(scr_vert, point);
4124 unsigned char *init_name[3] = {
4125 "/usr/share/misc/init.ee",
4131 ee_init() /* check for init file and read it if it exists */
4134 unsigned char *string;
4135 unsigned char *str1;
4136 unsigned char *str2;
4141 string = getenv("HOME");
4144 str1 = home = malloc(strlen(string)+10);
4145 strcpy(home, string);
4146 strcat(home, "/.init.ee");
4147 init_name[1] = home;
4148 string = malloc(512);
4150 for (counter = 0; counter < 3; counter++)
4152 if (!(access(init_name[counter], 4)))
4154 init_file = fopen(init_name[counter], "r");
4155 while ((str2 = fgets(string, 512, init_file)) != NULL)
4157 str1 = str2 = string;
4158 while (*str2 != '\n')
4162 if (unique_test(string, init_strings) != 1)
4165 if (compare(str1, CASE, FALSE))
4167 else if (compare(str1, NOCASE, FALSE))
4169 else if (compare(str1, EXPAND, FALSE))
4171 else if (compare(str1, NOEXPAND, FALSE))
4172 expand_tabs = FALSE;
4173 else if (compare(str1, INFO, FALSE))
4175 else if (compare(str1, NOINFO, FALSE))
4176 info_window = FALSE;
4177 else if (compare(str1, MARGINS, FALSE))
4178 observ_margins = TRUE;
4179 else if (compare(str1, NOMARGINS, FALSE))
4180 observ_margins = FALSE;
4181 else if (compare(str1, AUTOFORMAT, FALSE))
4184 observ_margins = TRUE;
4186 else if (compare(str1, NOAUTOFORMAT, FALSE))
4187 auto_format = FALSE;
4188 else if (compare(str1, Echo, FALSE))
4190 str1 = next_word(str1);
4194 else if (compare(str1, PRINTCOMMAND, FALSE))
4196 str1 = next_word(str1);
4197 print_command = malloc(strlen(str1)+1);
4198 strcpy(print_command, str1);
4200 else if (compare(str1, RIGHTMARGIN, FALSE))
4202 str1 = next_word(str1);
4203 if ((*str1 >= '0') && (*str1 <= '9'))
4205 temp_int = atoi(str1);
4207 right_margin = temp_int;
4210 else if (compare(str1, HIGHLIGHT, FALSE))
4211 nohighlight = FALSE;
4212 else if (compare(str1, NOHIGHLIGHT, FALSE))
4214 else if (compare(str1, EIGHTBIT, FALSE))
4216 else if (compare(str1, NOEIGHTBIT, FALSE))
4221 else if (compare(str1, EMACS_string, FALSE))
4222 emacs_keys_mode = TRUE;
4223 else if (compare(str1, NOEMACS_string, FALSE))
4224 emacs_keys_mode = FALSE;
4225 else if (compare(str1, chinese_cmd, FALSE))
4230 else if (compare(str1, nochinese_cmd, FALSE))
4239 string = getenv("LANG");
4242 if (strcmp(string, "zh_TW.big5") == 0)
4251 | Save current configuration to .init.ee file in the current directory.
4258 FILE *old_init_file = NULL;
4259 char *file_name = ".init.ee";
4260 char *home_dir = "~/.init.ee";
4267 if (restrict_mode())
4272 option = menu_op(config_dump_menu);
4275 wmove(com_win, 0, 0);
4279 wprintw(com_win, conf_not_saved_msg);
4283 else if (option == 2)
4284 file_name = resolve_name(home_dir);
4287 | If a .init.ee file exists, move it to .init.ee.old.
4290 if (stat(file_name, &buf) != -1)
4292 sprintf(buffer, "%s.old", file_name);
4294 link(file_name, buffer);
4296 old_init_file = fopen(buffer, "r");
4299 init_file = fopen(file_name, "w");
4300 if (init_file == NULL)
4302 wprintw(com_win, conf_dump_err_msg);
4307 if (old_init_file != NULL)
4310 | Copy non-configuration info into new .init.ee file.
4312 while ((string = fgets(buffer, 512, old_init_file)) != NULL)
4314 length = strlen(string);
4315 string[length - 1] = '\0';
4317 if (unique_test(string, init_strings) == 1)
4319 if (compare(string, Echo, FALSE))
4321 fprintf(init_file, "%s\n", string);
4325 fprintf(init_file, "%s\n", string);
4328 fclose(old_init_file);
4331 fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
4332 fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
4333 fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
4334 fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
4335 fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
4336 fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
4337 fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
4338 fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
4339 fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
4340 fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
4341 fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
4345 wprintw(com_win, conf_dump_success_msg, file_name);
4348 if ((option == 2) && (file_name != home_dir))
4355 echo_string(string) /* echo the given string */
4362 while (*temp != '\0')
4369 else if (*temp == 't')
4371 else if (*temp == 'b')
4373 else if (*temp == 'r')
4375 else if (*temp == 'f')
4377 else if ((*temp == 'e') || (*temp == 'E'))
4378 putchar('\033'); /* escape */
4379 else if (*temp == '\\')
4381 else if (*temp == '\'')
4383 else if ((*temp >= '0') && (*temp <= '9'))
4386 while ((*temp >= '0') && (*temp <= '9'))
4388 Counter = (8 * Counter) + (*temp - '0');
4407 spell_op() /* check spelling of words in the editor */
4409 if (restrict_mode())
4413 top(); /* go to top of file */
4414 insert_line(FALSE); /* create two blank lines */
4417 command(shell_echo_msg);
4419 wmove(com_win, 0, 0);
4420 wprintw(com_win, spell_in_prog_msg);
4422 command("<>!spell"); /* send contents of buffer to command 'spell'
4423 and read the results back into the editor */
4429 char template[128], *name;
4433 if (restrict_mode())
4437 (void)sprintf(template, "/tmp/ee.XXXXXXXX");
4438 fd = mkstemp(template);
4440 wmove(com_win, 0, 0);
4441 wprintw(com_win, create_file_fail_msg, name);
4446 if (write_file(name, 0))
4448 sprintf(string, "ispell %s", name);
4459 first_word_len(test_line)
4460 struct text *test_line;
4465 if (test_line == NULL)
4468 pnt = test_line->line;
4469 if ((pnt == NULL) || (*pnt == '\0') ||
4470 (*pnt == '.') || (*pnt == '>'))
4473 if ((*pnt == ' ') || (*pnt == '\t'))
4475 pnt = next_word(pnt);
4482 while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
4487 while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
4496 Auto_Format() /* format the paragraph according to set margins */
4503 int tmp_d_line_length;
4504 int leave_loop = FALSE;
4508 unsigned char *line;
4509 unsigned char *tmp_srchstr;
4510 unsigned char *temp1, *temp2;
4511 unsigned char *temp_dword;
4512 unsigned char temp_d_char[3];
4513 unsigned char *tmp_d_line;
4516 temp_d_char[0] = d_char[0];
4517 temp_d_char[1] = d_char[1];
4518 temp_d_char[2] = d_char[2];
4521 | if observ_margins is not set, or the current line is blank,
4522 | do not format the current paragraph
4525 if ((!observ_margins) || (Blank_Line(curr_line)))
4529 | get current position in paragraph, so after formatting, the cursor
4530 | will be in the same relative position
4533 tmp_d_line = d_line;
4534 tmp_d_line_length = dlt_line->line_length;
4536 auto_format = FALSE;
4538 if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
4540 temp_dword = d_word;
4541 temp_dwl = d_wrd_len;
4544 temp_case = case_sen;
4546 tmp_srchstr = srch_str;
4547 temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
4548 if ((*point == ' ') || (*point == '\t'))
4552 line = temp1 = point;
4553 while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
4563 while (!Blank_Line(curr_line->prev_line))
4567 while ((line != point) && (status))
4569 status = search(FALSE);
4574 | now get back to the start of the paragraph to start checking
4579 while (!Blank_Line(curr_line->prev_line))
4583 | Start going through lines, putting spaces at end of lines if they do
4584 | not already exist. Check line length, and move words to the next line
4585 | if they cross the margin. Then get words from the next line if they
4586 | will fit in before the margin.
4593 if (position != curr_line->line_length)
4607 | fill line if first word on next line will fit
4608 | in the line without crossing the margin
4611 while ((curr_line->next_line != NULL) &&
4612 ((word_len = first_word_len(curr_line->next_line)) > 0)
4613 && ((scr_pos + word_len) < right_margin))
4616 if ((*point == ' ') || (*point == '\t'))
4623 | We know this line was not blank before, so
4624 | make sure that it doesn't have one of the
4625 | leading characters that indicate the line
4626 | should not be modified.
4628 | We also know that this character should not
4629 | be left as the first character of this line.
4632 if ((Blank_Line(curr_line)) &&
4633 (curr_line->line[0] != '.') &&
4634 (curr_line->line[0] != '>'))
4643 | go to end of previous line
4649 | make sure there's a space at the end of the line
4662 | make sure line does not cross right margin
4665 while (right_margin <= scr_pos)
4671 if (Blank_Line(curr_line->next_line))
4675 if ((*point == ' ') || (*point == '\t'))
4685 if ((!Blank_Line(curr_line->next_line)) || (not_blank))
4695 | go back to begin of paragraph, put cursor back to original position
4700 while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
4704 | find word cursor was in
4708 while ((status) && (string_count > 0))
4710 status = search(FALSE);
4715 | offset the cursor to where it was before from the start of the word
4724 if ((string_count > 0) && (offset < 0))
4734 | reset flags and strings to what they were before formatting
4739 d_word = temp_dword;
4740 d_wrd_len = temp_dwl;
4741 case_sen = temp_case;
4743 srch_str = tmp_srchstr;
4744 d_char[0] = temp_d_char[0];
4745 d_char[1] = temp_d_char[1];
4746 d_char[2] = temp_d_char[2];
4748 dlt_line->line_length = tmp_d_line_length;
4749 d_line = tmp_d_line;
4752 midscreen(scr_vert, point);
4764 sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
4765 (expand_tabs ? ON : OFF));
4766 sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
4767 (case_sen ? ON : OFF));
4768 sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
4769 (observ_margins ? ON : OFF));
4770 sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
4771 (auto_format ? ON : OFF));
4772 sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
4773 (eightbit ? ON : OFF));
4774 sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
4775 (info_window ? ON : OFF));
4776 sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
4777 (emacs_keys_mode ? ON : OFF));
4778 sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
4780 sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
4781 (ee_chinese ? ON : OFF));
4783 ret_value = menu_op(modes_menu);
4788 expand_tabs = !expand_tabs;
4791 case_sen = !case_sen;
4794 observ_margins = !observ_margins;
4797 auto_format = !auto_format;
4799 observ_margins = TRUE;
4802 eightbit = !eightbit;
4807 nc_setattrib(A_NC_BIG5);
4809 nc_clearattrib(A_NC_BIG5);
4813 wnoutrefresh(text_win);
4819 create_info_window();
4822 emacs_keys_mode = !emacs_keys_mode;
4827 string = get_string(margin_prompt, TRUE);
4830 counter = atoi(string);
4832 right_margin = counter;
4837 ee_chinese = !ee_chinese;
4838 if (ee_chinese != FALSE)
4842 nc_setattrib(A_NC_BIG5);
4844 nc_clearattrib(A_NC_BIG5);
4852 while (ret_value != 0);
4856 is_in_string(string, substring) /* a strchr() look-alike for systems without
4858 char * string, *substring;
4862 for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
4864 for (full = string; (full != NULL) && (*full != '\0');
4875 | handle names of the form "~/file", "~user/file",
4876 | "$HOME/foo", "~/$FOO", etc.
4883 char long_buffer[1024];
4884 char short_buffer[128];
4892 struct passwd *user;
4899 user = (struct passwd *) getpwuid(index);
4904 slash = strchr(name, '/');
4908 user = (struct passwd *) getpwnam((name + 1));
4915 buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
4916 strcpy(buffer, user->pw_dir);
4917 strcat(buffer, slash);
4922 if (is_in_string(buffer, "$"))
4927 while ((*tmp != '\0') && (index < 1024))
4930 while ((*tmp != '\0') && (*tmp != '$') &&
4933 long_buffer[index] = *tmp;
4938 if ((*tmp == '$') && (index < 1024))
4943 if (*tmp == '{') /* } */ /* bracketed variable name */
4946 while ((*tmp != '\0') &&
4950 short_buffer[counter] = *tmp;
4959 while ((*tmp != '\0') &&
4964 short_buffer[counter] = *tmp;
4969 short_buffer[counter] = '\0';
4970 if ((slash = getenv(short_buffer)) != NULL)
4972 offset = strlen(slash);
4973 if ((offset + index) < 1024)
4974 strcpy(&long_buffer[index], slash);
4979 while ((start_of_var != tmp) && (index < 1024))
4981 long_buffer[index] = *start_of_var;
4992 long_buffer[index] = '\0';
4996 buffer = malloc(index + 1);
4997 strcpy(buffer, long_buffer);
5009 wmove(com_win, 0, 0);
5010 wprintw(com_win, restricted_msg);
5013 clear_com_win = TRUE;
5018 | The following routine tests the input string against the list of
5019 | strings, to determine if the string is a unique match with one of the
5024 unique_test(string, list)
5034 while (list[counter] != NULL)
5036 result = compare(string, list[counter], FALSE);
5046 | Get the catalog entry, and if it got it from the catalog,
5047 | make a copy, since the buffer will be overwritten by the
5048 | next call to catgets().
5052 catgetlocal(number, string)
5059 temp1 = catgets(catalog, 1, number, string);
5060 if (temp1 != string)
5062 temp2 = malloc(strlen(temp1) + 1);
5063 strcpy(temp2, temp1);
5068 #endif /* NO_CATGETS */
5071 | The following is to allow for using message catalogs which allow
5072 | the software to be 'localized', that is, to use different languages
5073 | all with the same binary. For more information, see your system
5074 | documentation, or the X/Open Internationalization Guide.
5082 setlocale(LC_ALL, "");
5084 catalog = catopen("ee", NL_CAT_LOCALE);
5085 #endif /* NO_CATGETS */
5087 modes_menu[0].item_string = catgetlocal( 1, "modes menu");
5088 mode_strings[1] = catgetlocal( 2, "tabs to spaces ");
5089 mode_strings[2] = catgetlocal( 3, "case sensitive search");
5090 mode_strings[3] = catgetlocal( 4, "margins observed ");
5091 mode_strings[4] = catgetlocal( 5, "auto-paragraph format");
5092 mode_strings[5] = catgetlocal( 6, "eightbit characters ");
5093 mode_strings[6] = catgetlocal( 7, "info window ");
5094 mode_strings[8] = catgetlocal( 8, "right margin ");
5095 leave_menu[0].item_string = catgetlocal( 9, "leave menu");
5096 leave_menu[1].item_string = catgetlocal( 10, "save changes");
5097 leave_menu[2].item_string = catgetlocal( 11, "no save");
5098 file_menu[0].item_string = catgetlocal( 12, "file menu");
5099 file_menu[1].item_string = catgetlocal( 13, "read a file");
5100 file_menu[2].item_string = catgetlocal( 14, "write a file");
5101 file_menu[3].item_string = catgetlocal( 15, "save file");
5102 file_menu[4].item_string = catgetlocal( 16, "print editor contents");
5103 search_menu[0].item_string = catgetlocal( 17, "search menu");
5104 search_menu[1].item_string = catgetlocal( 18, "search for ...");
5105 search_menu[2].item_string = catgetlocal( 19, "search");
5106 spell_menu[0].item_string = catgetlocal( 20, "spell menu");
5107 spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
5108 spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
5109 misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
5110 misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
5111 misc_menu[2].item_string = catgetlocal( 25, "shell command");
5112 misc_menu[3].item_string = catgetlocal( 26, "check spelling");
5113 main_menu[0].item_string = catgetlocal( 27, "main menu");
5114 main_menu[1].item_string = catgetlocal( 28, "leave editor");
5115 main_menu[2].item_string = catgetlocal( 29, "help");
5116 main_menu[3].item_string = catgetlocal( 30, "file operations");
5117 main_menu[4].item_string = catgetlocal( 31, "redraw screen");
5118 main_menu[5].item_string = catgetlocal( 32, "settings");
5119 main_menu[6].item_string = catgetlocal( 33, "search");
5120 main_menu[7].item_string = catgetlocal( 34, "miscellaneous");
5121 help_text[0] = catgetlocal( 35, "Control keys: ");
5122 help_text[1] = catgetlocal( 36, "^a ascii code ^i tab ^r right ");
5123 help_text[2] = catgetlocal( 37, "^b bottom of text ^j newline ^t top of text ");
5124 help_text[3] = catgetlocal( 38, "^c command ^k delete char ^u up ");
5125 help_text[4] = catgetlocal( 39, "^d down ^l left ^v undelete word ");
5126 help_text[5] = catgetlocal( 40, "^e search prompt ^m newline ^w delete word ");
5127 help_text[6] = catgetlocal( 41, "^f undelete char ^n next page ^x search ");
5128 help_text[7] = catgetlocal( 42, "^g begin of line ^o end of line ^y delete line ");
5129 help_text[8] = catgetlocal( 43, "^h backspace ^p prev page ^z undelete line ");
5130 help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
5131 help_text[10] = catgetlocal( 45, " ");
5132 help_text[11] = catgetlocal( 46, "Commands: ");
5133 help_text[12] = catgetlocal( 47, "help : get this info file : print file name ");
5134 help_text[13] = catgetlocal( 48, "read : read a file char : ascii code of char ");
5135 help_text[14] = catgetlocal( 49, "write : write a file case : case sensitive search ");
5136 help_text[15] = catgetlocal( 50, "exit : leave and save nocase : case insensitive search ");
5137 help_text[16] = catgetlocal( 51, "quit : leave, no save !cmd : execute \"cmd\" in shell ");
5138 help_text[17] = catgetlocal( 52, "line : display line # 0-9 : go to line \"#\" ");
5139 help_text[18] = catgetlocal( 53, "expand : expand tabs noexpand: do not expand tabs ");
5140 help_text[19] = catgetlocal( 54, " ");
5141 help_text[20] = catgetlocal( 55, " ee [+#] [-i] [-e] [-h] [file(s)] ");
5142 help_text[21] = catgetlocal( 56, "+# :go to line # -i :no info window -e : don't expand tabs -h :no highlight");
5143 control_keys[0] = catgetlocal( 57, "^[ (escape) menu ^e search prompt ^y delete line ^u up ^p prev page ");
5144 control_keys[1] = catgetlocal( 58, "^a ascii code ^x search ^z undelete line ^d down ^n next page ");
5145 control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line ^w delete word ^l left ");
5146 control_keys[3] = catgetlocal( 60, "^t top of text ^o end of line ^v undelete word ^r right ");
5147 control_keys[4] = catgetlocal( 61, "^c command ^k delete char ^f undelete char ESC-Enter: exit ee ");
5148 command_strings[0] = catgetlocal( 62, "help : get help info |file : print file name |line : print line # ");
5149 command_strings[1] = catgetlocal( 63, "read : read a file |char : ascii code of char |0-9 : go to line \"#\"");
5150 command_strings[2] = catgetlocal( 64, "write: write a file |case : case sensitive search |exit : leave and save ");
5151 command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\" |nocase: ignore case in search |quit : leave, no save");
5152 command_strings[4] = catgetlocal( 66, "expand: expand tabs |noexpand: do not expand tabs ");
5153 com_win_message = catgetlocal( 67, " press Escape (^[) for menu");
5154 no_file_string = catgetlocal( 68, "no file");
5155 ascii_code_str = catgetlocal( 69, "ascii code: ");
5156 printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
5157 command_str = catgetlocal( 71, "command: ");
5158 file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
5159 file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
5160 char_str = catgetlocal( 74, "character = %d");
5161 unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
5162 non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
5163 line_num_str = catgetlocal( 77, "line %d ");
5164 line_len_str = catgetlocal( 78, "length = %d");
5165 current_file_str = catgetlocal( 79, "current file is \"%s\" ");
5166 usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
5167 usage1 = catgetlocal( 81, " -i turn off info window\n");
5168 usage2 = catgetlocal( 82, " -e do not convert tabs to spaces\n");
5169 usage3 = catgetlocal( 83, " -h do not use highlighting\n");
5170 file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
5171 new_file_msg = catgetlocal( 85, "new file \"%s\"");
5172 cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
5173 open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
5174 file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
5175 reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
5176 read_only_msg = catgetlocal( 90, ", read only");
5177 file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
5178 save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
5179 file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
5180 changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
5181 yes_char = catgetlocal( 95, "y");
5182 file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
5183 create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
5184 writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
5185 file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
5186 searching_msg = catgetlocal( 100, " ...searching");
5187 str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
5188 search_prompt_str = catgetlocal( 102, "search for: ");
5189 exec_err_msg = catgetlocal( 103, "could not exec %s\n");
5190 continue_msg = catgetlocal( 104, "press return to continue ");
5191 menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
5192 menu_size_err_msg = catgetlocal( 106, "menu too large for window");
5193 press_any_key_msg = catgetlocal( 107, "press any key to continue ");
5194 shell_prompt = catgetlocal( 108, "shell command: ");
5195 formatting_msg = catgetlocal( 109, "...formatting paragraph...");
5196 shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
5197 spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
5198 margin_prompt = catgetlocal( 112, "right margin is: ");
5199 restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
5200 ON = catgetlocal( 114, "ON");
5201 OFF = catgetlocal( 115, "OFF");
5202 HELP = catgetlocal( 116, "HELP");
5203 WRITE = catgetlocal( 117, "WRITE");
5204 READ = catgetlocal( 118, "READ");
5205 LINE = catgetlocal( 119, "LINE");
5206 FILE_str = catgetlocal( 120, "FILE");
5207 CHARACTER = catgetlocal( 121, "CHARACTER");
5208 REDRAW = catgetlocal( 122, "REDRAW");
5209 RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
5210 AUTHOR = catgetlocal( 124, "AUTHOR");
5211 VERSION = catgetlocal( 125, "VERSION");
5212 CASE = catgetlocal( 126, "CASE");
5213 NOCASE = catgetlocal( 127, "NOCASE");
5214 EXPAND = catgetlocal( 128, "EXPAND");
5215 NOEXPAND = catgetlocal( 129, "NOEXPAND");
5216 Exit_string = catgetlocal( 130, "EXIT");
5217 QUIT_string = catgetlocal( 131, "QUIT");
5218 INFO = catgetlocal( 132, "INFO");
5219 NOINFO = catgetlocal( 133, "NOINFO");
5220 MARGINS = catgetlocal( 134, "MARGINS");
5221 NOMARGINS = catgetlocal( 135, "NOMARGINS");
5222 AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
5223 NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
5224 Echo = catgetlocal( 138, "ECHO");
5225 PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
5226 RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
5227 HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
5228 NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
5229 EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
5230 NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
5234 mode_strings[7] = catgetlocal( 145, "emacs key bindings ");
5235 emacs_help_text[0] = help_text[0];
5236 emacs_help_text[1] = catgetlocal( 146, "^a beginning of line ^i tab ^r restore word ");
5237 emacs_help_text[2] = catgetlocal( 147, "^b back 1 char ^j undel char ^t top of text ");
5238 emacs_help_text[3] = catgetlocal( 148, "^c command ^k delete line ^u bottom of text ");
5239 emacs_help_text[4] = catgetlocal( 149, "^d delete char ^l undelete line ^v next page ");
5240 emacs_help_text[5] = catgetlocal( 150, "^e end of line ^m newline ^w delete word ");
5241 emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char ^n next line ^x search ");
5242 emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page ^o ascii char insert ^y search prompt ");
5243 emacs_help_text[8] = catgetlocal( 153, "^h backspace ^p prev line ^z next word ");
5244 emacs_help_text[9] = help_text[9];
5245 emacs_help_text[10] = help_text[10];
5246 emacs_help_text[11] = help_text[11];
5247 emacs_help_text[12] = help_text[12];
5248 emacs_help_text[13] = help_text[13];
5249 emacs_help_text[14] = help_text[14];
5250 emacs_help_text[15] = help_text[15];
5251 emacs_help_text[16] = help_text[16];
5252 emacs_help_text[17] = help_text[17];
5253 emacs_help_text[18] = help_text[18];
5254 emacs_help_text[19] = help_text[19];
5255 emacs_help_text[20] = help_text[20];
5256 emacs_help_text[21] = help_text[21];
5257 emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page");
5258 emacs_control_keys[1] = catgetlocal( 155, "^o ascii code ^x search ^l undelete line ^n next li ^v next page");
5259 emacs_control_keys[2] = catgetlocal( 156, "^u end of file ^a begin of line ^w delete word ^b back 1 char ^z next word");
5260 emacs_control_keys[3] = catgetlocal( 157, "^t top of text ^e end of line ^r restore word ^f forward char ");
5261 emacs_control_keys[4] = catgetlocal( 158, "^c command ^d delete char ^j undelete char ESC-Enter: exit");
5262 EMACS_string = catgetlocal( 159, "EMACS");
5263 NOEMACS_string = catgetlocal( 160, "NOEMACS");
5264 usage4 = catgetlocal( 161, " +# put cursor at line #\n");
5265 conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
5266 conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
5267 modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5268 config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
5269 config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
5270 config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
5271 conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
5272 ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
5273 menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
5274 more_above_str = catgetlocal( 181, "^^more^^");
5275 more_below_str = catgetlocal( 182, "VVmoreVV");
5276 mode_strings[9] = catgetlocal( 183, "16 bit characters ");
5277 chinese_cmd = catgetlocal( 184, "16BIT");
5278 nochinese_cmd = catgetlocal( 185, "NO16BIT");
5281 commands[1] = WRITE;
5284 commands[4] = FILE_str;
5285 commands[5] = REDRAW;
5286 commands[6] = RESEQUENCE;
5287 commands[7] = AUTHOR;
5288 commands[8] = VERSION;
5290 commands[10] = NOCASE;
5291 commands[11] = EXPAND;
5292 commands[12] = NOEXPAND;
5293 commands[13] = Exit_string;
5294 commands[14] = QUIT_string;
5308 commands[28] = CHARACTER;
5309 commands[29] = chinese_cmd;
5310 commands[30] = nochinese_cmd;
5311 commands[31] = NULL;
5312 init_strings[0] = CASE;
5313 init_strings[1] = NOCASE;
5314 init_strings[2] = EXPAND;
5315 init_strings[3] = NOEXPAND;
5316 init_strings[4] = INFO;
5317 init_strings[5] = NOINFO;
5318 init_strings[6] = MARGINS;
5319 init_strings[7] = NOMARGINS;
5320 init_strings[8] = AUTOFORMAT;
5321 init_strings[9] = NOAUTOFORMAT;
5322 init_strings[10] = Echo;
5323 init_strings[11] = PRINTCOMMAND;
5324 init_strings[12] = RIGHTMARGIN;
5325 init_strings[13] = HIGHLIGHT;
5326 init_strings[14] = NOHIGHLIGHT;
5327 init_strings[15] = EIGHTBIT;
5328 init_strings[16] = NOEIGHTBIT;
5329 init_strings[17] = EMACS_string;
5330 init_strings[18] = NOEMACS_string;
5331 init_strings[19] = chinese_cmd;
5332 init_strings[20] = nochinese_cmd;
5333 init_strings[21] = NULL;
5336 | allocate space for strings here for settings menu
5339 for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
5341 modes_menu[counter].item_string = malloc(80);
5346 #endif /* NO_CATGETS */