xref: /freebsd/contrib/ee/ee.c (revision 96b676e99984e6d4a36614d2d9f02906d83aab79)
172fcea8cSEd Schouten /*
272fcea8cSEd Schouten  |	ee (easy editor)
372fcea8cSEd Schouten  |
472fcea8cSEd Schouten  |	An easy to use, simple screen oriented editor.
572fcea8cSEd Schouten  |
672fcea8cSEd Schouten  |	written by Hugh Mahon
772fcea8cSEd Schouten  |
872fcea8cSEd Schouten  |
996b676e9SEd Schouten  |      Copyright (c) 2009, Hugh Mahon
1096b676e9SEd Schouten  |      All rights reserved.
1172fcea8cSEd Schouten  |
1296b676e9SEd Schouten  |      Redistribution and use in source and binary forms, with or without
1396b676e9SEd Schouten  |      modification, are permitted provided that the following conditions
1496b676e9SEd Schouten  |      are met:
1572fcea8cSEd Schouten  |
1696b676e9SEd Schouten  |          * Redistributions of source code must retain the above copyright
1796b676e9SEd Schouten  |            notice, this list of conditions and the following disclaimer.
1896b676e9SEd Schouten  |          * Redistributions in binary form must reproduce the above
1996b676e9SEd Schouten  |            copyright notice, this list of conditions and the following
2096b676e9SEd Schouten  |            disclaimer in the documentation and/or other materials provided
2196b676e9SEd Schouten  |            with the distribution.
2296b676e9SEd Schouten  |
2396b676e9SEd Schouten  |      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2496b676e9SEd Schouten  |      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2596b676e9SEd Schouten  |      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2696b676e9SEd Schouten  |      FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2796b676e9SEd Schouten  |      COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2896b676e9SEd Schouten  |      INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2996b676e9SEd Schouten  |      BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
3096b676e9SEd Schouten  |      LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3196b676e9SEd Schouten  |      CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3296b676e9SEd Schouten  |      LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
3396b676e9SEd Schouten  |      ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3496b676e9SEd Schouten  |      POSSIBILITY OF SUCH DAMAGE.
3596b676e9SEd Schouten  |
3696b676e9SEd Schouten  |     -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3772fcea8cSEd Schouten  |
3872fcea8cSEd Schouten  |	This editor was purposely developed to be simple, both in
3972fcea8cSEd Schouten  |	interface and implementation.  This editor was developed to
4072fcea8cSEd Schouten  |	address a specific audience: the user who is new to computers
4172fcea8cSEd Schouten  |	(especially UNIX).
4272fcea8cSEd Schouten  |
4372fcea8cSEd Schouten  |	ee is not aimed at technical users; for that reason more
4472fcea8cSEd Schouten  |	complex features were intentionally left out.  In addition,
4572fcea8cSEd Schouten  |	ee is intended to be compiled by people with little computer
4672fcea8cSEd Schouten  |	experience, which means that it needs to be small, relatively
4772fcea8cSEd Schouten  |	simple in implementation, and portable.
4872fcea8cSEd Schouten  |
4972fcea8cSEd Schouten  |	This software and documentation contains
5072fcea8cSEd Schouten  |	proprietary information which is protected by
5172fcea8cSEd Schouten  |	copyright.  All rights are reserved.
5272fcea8cSEd Schouten  |
5396b676e9SEd Schouten  |	$Header: /home/hugh/sources/old_ae/RCS/ee.c,v 1.102 2009/02/17 03:22:50 hugh Exp hugh $
5472fcea8cSEd Schouten  |
5572fcea8cSEd Schouten  */
5672fcea8cSEd Schouten 
57cfe04e82SEd Schouten #include <sys/cdefs.h>
58cfe04e82SEd Schouten __FBSDID("$FreeBSD$");
59cfe04e82SEd Schouten 
6072fcea8cSEd Schouten char *ee_copyright_message =
6196b676e9SEd Schouten "Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2009 Hugh Mahon ";
6272fcea8cSEd Schouten 
6396b676e9SEd Schouten #include "ee_version.h"
6472fcea8cSEd Schouten 
6596b676e9SEd Schouten char *version = "@(#) ee, version "  EE_VERSION  " $Revision: 1.102 $";
6672fcea8cSEd Schouten 
6772fcea8cSEd Schouten #ifdef NCURSE
6872fcea8cSEd Schouten #include "new_curse.h"
69cfe04e82SEd Schouten #elif HAS_NCURSES
70cfe04e82SEd Schouten #include <ncurses.h>
7172fcea8cSEd Schouten #else
7272fcea8cSEd Schouten #include <curses.h>
7372fcea8cSEd Schouten #endif
7472fcea8cSEd Schouten 
7572fcea8cSEd Schouten #ifdef HAS_CTYPE
7672fcea8cSEd Schouten #include <ctype.h>
7772fcea8cSEd Schouten #endif
7896b676e9SEd Schouten 
79cfe04e82SEd Schouten #include <signal.h>
8096b676e9SEd Schouten #include <fcntl.h>
81cfe04e82SEd Schouten #include <sys/types.h>
82cfe04e82SEd Schouten #include <sys/stat.h>
8396b676e9SEd Schouten #include <errno.h>
8496b676e9SEd Schouten #include <string.h>
8596b676e9SEd Schouten #include <pwd.h>
8696b676e9SEd Schouten 
87cfe04e82SEd Schouten #ifdef HAS_SYS_WAIT
88cfe04e82SEd Schouten #include <sys/wait.h>
89cfe04e82SEd Schouten #endif
9096b676e9SEd Schouten 
91cfe04e82SEd Schouten #ifdef HAS_STDLIB
92cfe04e82SEd Schouten #include <stdlib.h>
93cfe04e82SEd Schouten #endif
9496b676e9SEd Schouten 
9596b676e9SEd Schouten #ifdef HAS_STDARG
9696b676e9SEd Schouten #include <stdarg.h>
9796b676e9SEd Schouten #endif
9896b676e9SEd Schouten 
99cfe04e82SEd Schouten #ifdef HAS_UNISTD
100cfe04e82SEd Schouten #include <unistd.h>
101cfe04e82SEd Schouten #endif
10272fcea8cSEd Schouten 
10396b676e9SEd Schouten 
10472fcea8cSEd Schouten #ifndef NO_CATGETS
10572fcea8cSEd Schouten #include <locale.h>
10672fcea8cSEd Schouten #include <nl_types.h>
10772fcea8cSEd Schouten 
10872fcea8cSEd Schouten nl_catd catalog;
10972fcea8cSEd Schouten #else
11072fcea8cSEd Schouten #define catgetlocal(a, b) (b)
11172fcea8cSEd Schouten #endif /* NO_CATGETS */
11272fcea8cSEd Schouten 
11372fcea8cSEd Schouten #ifndef SIGCHLD
11472fcea8cSEd Schouten #define SIGCHLD SIGCLD
11572fcea8cSEd Schouten #endif
11672fcea8cSEd Schouten 
11772fcea8cSEd Schouten #define TAB 9
11872fcea8cSEd Schouten #define max(a, b)	(a > b ? a : b)
11972fcea8cSEd Schouten #define min(a, b)	(a < b ? a : b)
12072fcea8cSEd Schouten 
12172fcea8cSEd Schouten /*
12272fcea8cSEd Schouten  |	defines for type of data to show in info window
12372fcea8cSEd Schouten  */
12472fcea8cSEd Schouten 
12572fcea8cSEd Schouten #define CONTROL_KEYS 1
12672fcea8cSEd Schouten #define COMMANDS     2
12772fcea8cSEd Schouten 
12872fcea8cSEd Schouten struct text {
12972fcea8cSEd Schouten 	unsigned char *line;		/* line of characters		*/
13072fcea8cSEd Schouten 	int line_number;		/* line number			*/
13172fcea8cSEd Schouten 	int line_length;	/* actual number of characters in the line */
13272fcea8cSEd Schouten 	int max_length;	/* maximum number of characters the line handles */
13372fcea8cSEd Schouten 	struct text *next_line;		/* next line of text		*/
13472fcea8cSEd Schouten 	struct text *prev_line;		/* previous line of text	*/
13572fcea8cSEd Schouten 	};
13672fcea8cSEd Schouten 
13772fcea8cSEd Schouten struct text *first_line;	/* first line of current buffer		*/
13872fcea8cSEd Schouten struct text *dlt_line;		/* structure for info on deleted line	*/
13972fcea8cSEd Schouten struct text *curr_line;		/* current line cursor is on		*/
14072fcea8cSEd Schouten struct text *tmp_line;		/* temporary line pointer		*/
14172fcea8cSEd Schouten struct text *srch_line;		/* temporary pointer for search routine */
14272fcea8cSEd Schouten 
14372fcea8cSEd Schouten struct files {		/* structure to store names of files to be edited*/
14472fcea8cSEd Schouten 	unsigned char *name;		/* name of file				*/
14572fcea8cSEd Schouten 	struct files *next_name;
14672fcea8cSEd Schouten 	};
14772fcea8cSEd Schouten 
14872fcea8cSEd Schouten struct files *top_of_stack = NULL;
14972fcea8cSEd Schouten 
15072fcea8cSEd Schouten int d_wrd_len;			/* length of deleted word		*/
15172fcea8cSEd Schouten int position;			/* offset in bytes from begin of line	*/
15272fcea8cSEd Schouten int scr_pos;			/* horizontal position			*/
15372fcea8cSEd Schouten int scr_vert;			/* vertical position on screen		*/
15472fcea8cSEd Schouten int scr_horz;			/* horizontal position on screen	*/
15596b676e9SEd Schouten int absolute_lin;		/* number of lines from top		*/
15672fcea8cSEd Schouten int tmp_vert, tmp_horz;
15772fcea8cSEd Schouten int input_file;			/* indicate to read input file		*/
15872fcea8cSEd Schouten int recv_file;			/* indicate reading a file		*/
15972fcea8cSEd Schouten int edit;			/* continue executing while true	*/
16072fcea8cSEd Schouten int gold;			/* 'gold' function key pressed		*/
16172fcea8cSEd Schouten int fildes;			/* file descriptor			*/
16272fcea8cSEd Schouten int case_sen;			/* case sensitive search flag		*/
16372fcea8cSEd Schouten int last_line;			/* last line for text display		*/
16472fcea8cSEd Schouten int last_col;			/* last column for text display		*/
16572fcea8cSEd Schouten int horiz_offset = 0;		/* offset from left edge of text	*/
16672fcea8cSEd Schouten int clear_com_win;		/* flag to indicate com_win needs clearing */
16772fcea8cSEd Schouten int text_changes = FALSE;	/* indicate changes have been made to text */
16872fcea8cSEd Schouten int get_fd;			/* file descriptor for reading a file	*/
16972fcea8cSEd Schouten int info_window = TRUE;		/* flag to indicate if help window visible */
17072fcea8cSEd Schouten int info_type = CONTROL_KEYS;	/* flag to indicate type of info to display */
17172fcea8cSEd Schouten int expand_tabs = TRUE;		/* flag for expanding tabs		*/
17272fcea8cSEd Schouten int right_margin = 0;		/* the right margin 			*/
17372fcea8cSEd Schouten int observ_margins = TRUE;	/* flag for whether margins are observed */
17472fcea8cSEd Schouten int shell_fork;
17572fcea8cSEd Schouten int temp_stdin;			/* temporary storage for stdin		*/
17672fcea8cSEd Schouten int temp_stdout;		/* temp storage for stdout descriptor	*/
17772fcea8cSEd Schouten int temp_stderr;		/* temp storage for stderr descriptor	*/
17872fcea8cSEd Schouten int pipe_out[2];		/* pipe file desc for output		*/
17972fcea8cSEd Schouten int pipe_in[2];			/* pipe file descriptors for input	*/
18072fcea8cSEd Schouten int out_pipe;			/* flag that info is piped out		*/
18172fcea8cSEd Schouten int in_pipe;			/* flag that info is piped in		*/
18272fcea8cSEd Schouten int formatted = FALSE;		/* flag indicating paragraph formatted	*/
18372fcea8cSEd Schouten int auto_format = FALSE;	/* flag for auto_format mode		*/
18472fcea8cSEd Schouten int restricted = FALSE;		/* flag to indicate restricted mode	*/
18572fcea8cSEd Schouten int nohighlight = FALSE;	/* turns off highlighting		*/
18672fcea8cSEd Schouten int eightbit = TRUE;		/* eight bit character flag		*/
18772fcea8cSEd Schouten int local_LINES = 0;		/* copy of LINES, to detect when win resizes */
18872fcea8cSEd Schouten int local_COLS = 0;		/* copy of COLS, to detect when win resizes  */
18972fcea8cSEd Schouten int curses_initialized = FALSE;	/* flag indicating if curses has been started*/
19072fcea8cSEd Schouten int emacs_keys_mode = FALSE;	/* mode for if emacs key binings are used    */
19172fcea8cSEd Schouten int ee_chinese = FALSE;		/* allows handling of multi-byte characters  */
19272fcea8cSEd Schouten 				/* by checking for high bit in a byte the    */
19372fcea8cSEd Schouten 				/* code recognizes a two-byte character      */
19472fcea8cSEd Schouten 				/* sequence				     */
19572fcea8cSEd Schouten 
19672fcea8cSEd Schouten unsigned char *point;		/* points to current position in line	*/
19772fcea8cSEd Schouten unsigned char *srch_str;	/* pointer for search string		*/
19872fcea8cSEd Schouten unsigned char *u_srch_str;	/* pointer to non-case sensitive search	*/
19972fcea8cSEd Schouten unsigned char *srch_1;		/* pointer to start of suspect string	*/
20072fcea8cSEd Schouten unsigned char *srch_2;		/* pointer to next character of string	*/
20172fcea8cSEd Schouten unsigned char *srch_3;
20272fcea8cSEd Schouten unsigned char *in_file_name = NULL;	/* name of input file		*/
20372fcea8cSEd Schouten char *tmp_file;	/* temporary file name			*/
20472fcea8cSEd Schouten unsigned char *d_char;		/* deleted character			*/
20572fcea8cSEd Schouten unsigned char *d_word;		/* deleted word				*/
20672fcea8cSEd Schouten unsigned char *d_line;		/* deleted line				*/
20772fcea8cSEd Schouten char in_string[513];	/* buffer for reading a file		*/
20896b676e9SEd Schouten unsigned char *print_command = (unsigned char *)"lpr";	/* string to use for the print command 	*/
20972fcea8cSEd Schouten unsigned char *start_at_line = NULL;	/* move to this line at start of session*/
21072fcea8cSEd Schouten int in;				/* input character			*/
21172fcea8cSEd Schouten 
21272fcea8cSEd Schouten FILE *temp_fp;			/* temporary file pointer		*/
21372fcea8cSEd Schouten FILE *bit_bucket;		/* file pointer to /dev/null		*/
21472fcea8cSEd Schouten 
21572fcea8cSEd Schouten char *table[] = {
21672fcea8cSEd Schouten 	"^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "\t", "^J",
21772fcea8cSEd Schouten 	"^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U",
21872fcea8cSEd Schouten 	"^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
21972fcea8cSEd Schouten 	};
22072fcea8cSEd Schouten 
22172fcea8cSEd Schouten WINDOW *com_win;
22272fcea8cSEd Schouten WINDOW *text_win;
22372fcea8cSEd Schouten WINDOW *help_win;
22472fcea8cSEd Schouten WINDOW *info_win;
22572fcea8cSEd Schouten 
22672fcea8cSEd Schouten #if defined(__STDC__) || defined(__cplusplus)
22772fcea8cSEd Schouten #define P_(s) s
22872fcea8cSEd Schouten #else
22972fcea8cSEd Schouten #define P_(s) ()
23072fcea8cSEd Schouten #endif
23172fcea8cSEd Schouten 
23272fcea8cSEd Schouten 
23372fcea8cSEd Schouten /*
23472fcea8cSEd Schouten  |	The following structure allows menu items to be flexibly declared.
23572fcea8cSEd Schouten  |	The first item is the string describing the selection, the second
23672fcea8cSEd Schouten  |	is the address of the procedure to call when the item is selected,
23772fcea8cSEd Schouten  |	and the third is the argument for the procedure.
23872fcea8cSEd Schouten  |
23972fcea8cSEd Schouten  |	For those systems with i18n, the string should be accompanied by a
24072fcea8cSEd Schouten  |	catalog number.  The 'int *' should be replaced with 'void *' on
24172fcea8cSEd Schouten  |	systems with that type.
24272fcea8cSEd Schouten  |
24372fcea8cSEd Schouten  |	The first menu item will be the title of the menu, with NULL
24472fcea8cSEd Schouten  |	parameters for the procedure and argument, followed by the menu items.
24572fcea8cSEd Schouten  |
24672fcea8cSEd Schouten  |	If the procedure value is NULL, the menu item is displayed, but no
24772fcea8cSEd Schouten  |	procedure is called when the item is selected.  The number of the
24872fcea8cSEd Schouten  |	item will be returned.  If the third (argument) parameter is -1, no
24972fcea8cSEd Schouten  |	argument is given to the procedure when it is called.
25072fcea8cSEd Schouten  */
25172fcea8cSEd Schouten 
25272fcea8cSEd Schouten struct menu_entries {
25372fcea8cSEd Schouten 	char *item_string;
25472fcea8cSEd Schouten 	int (*procedure)P_((struct menu_entries *));
25572fcea8cSEd Schouten 	struct menu_entries *ptr_argument;
25672fcea8cSEd Schouten 	int (*iprocedure)P_((int));
25772fcea8cSEd Schouten 	void (*nprocedure)P_((void));
25872fcea8cSEd Schouten 	int argument;
25972fcea8cSEd Schouten 	};
26072fcea8cSEd Schouten 
26172fcea8cSEd Schouten int main P_((int argc, char *argv[]));
26272fcea8cSEd Schouten unsigned char *resiz_line P_((int factor, struct text *rline, int rpos));
26372fcea8cSEd Schouten void insert P_((int character));
26472fcea8cSEd Schouten void delete P_((int disp));
26572fcea8cSEd Schouten void scanline P_((unsigned char *pos));
26672fcea8cSEd Schouten int tabshift P_((int temp_int));
26772fcea8cSEd Schouten int out_char P_((WINDOW *window, int character, int column));
26872fcea8cSEd Schouten int len_char P_((int character, int column));
26972fcea8cSEd Schouten void draw_line P_((int vertical, int horiz, unsigned char *ptr, int t_pos, int length));
27072fcea8cSEd Schouten void insert_line P_((int disp));
27172fcea8cSEd Schouten struct text *txtalloc P_((void));
27272fcea8cSEd Schouten struct files *name_alloc P_((void));
27372fcea8cSEd Schouten unsigned char *next_word P_((unsigned char *string));
27472fcea8cSEd Schouten void prev_word P_((void));
27572fcea8cSEd Schouten void control P_((void));
27672fcea8cSEd Schouten void emacs_control P_((void));
27772fcea8cSEd Schouten void bottom P_((void));
27872fcea8cSEd Schouten void top P_((void));
27972fcea8cSEd Schouten void nextline P_((void));
28072fcea8cSEd Schouten void prevline P_((void));
28172fcea8cSEd Schouten void left P_((int disp));
28272fcea8cSEd Schouten void right P_((int disp));
28372fcea8cSEd Schouten void find_pos P_((void));
28472fcea8cSEd Schouten void up P_((void));
28572fcea8cSEd Schouten void down P_((void));
28672fcea8cSEd Schouten void function_key P_((void));
28772fcea8cSEd Schouten void print_buffer P_((void));
28872fcea8cSEd Schouten void command_prompt P_((void));
28972fcea8cSEd Schouten void command P_((char *cmd_str1));
29072fcea8cSEd Schouten int scan P_((char *line, int offset, int column));
29172fcea8cSEd Schouten char *get_string P_((char *prompt, int advance));
29272fcea8cSEd Schouten int compare P_((char *string1, char *string2, int sensitive));
29372fcea8cSEd Schouten void goto_line P_((char *cmd_str));
29472fcea8cSEd Schouten void midscreen P_((int line, unsigned char *pnt));
29572fcea8cSEd Schouten void get_options P_((int numargs, char *arguments[]));
29672fcea8cSEd Schouten void check_fp P_((void));
29772fcea8cSEd Schouten void get_file P_((char *file_name));
29872fcea8cSEd Schouten void get_line P_((int length, unsigned char *in_string, int *append));
29972fcea8cSEd Schouten void draw_screen P_((void));
30072fcea8cSEd Schouten void finish P_((void));
30172fcea8cSEd Schouten int quit P_((int noverify));
30272fcea8cSEd Schouten void edit_abort P_((int arg));
30372fcea8cSEd Schouten void delete_text P_((void));
304cfe04e82SEd Schouten int write_file P_((char *file_name, int warn_if_exists));
30572fcea8cSEd Schouten int search P_((int display_message));
30672fcea8cSEd Schouten void search_prompt P_((void));
30772fcea8cSEd Schouten void del_char P_((void));
30872fcea8cSEd Schouten void undel_char P_((void));
30972fcea8cSEd Schouten void del_word P_((void));
31072fcea8cSEd Schouten void undel_word P_((void));
31172fcea8cSEd Schouten void del_line P_((void));
31272fcea8cSEd Schouten void undel_line P_((void));
31372fcea8cSEd Schouten void adv_word P_((void));
31472fcea8cSEd Schouten void move_rel P_((char *direction, int lines));
31572fcea8cSEd Schouten void eol P_((void));
31672fcea8cSEd Schouten void bol P_((void));
31772fcea8cSEd Schouten void adv_line P_((void));
31872fcea8cSEd Schouten void sh_command P_((char *string));
31972fcea8cSEd Schouten void set_up_term P_((void));
32072fcea8cSEd Schouten void resize_check P_((void));
32172fcea8cSEd Schouten int menu_op P_((struct menu_entries *));
32272fcea8cSEd Schouten 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));
32372fcea8cSEd Schouten void help P_((void));
32472fcea8cSEd Schouten void paint_info_win P_((void));
32572fcea8cSEd Schouten void no_info_window P_((void));
32672fcea8cSEd Schouten void create_info_window P_((void));
32772fcea8cSEd Schouten int file_op P_((int arg));
32872fcea8cSEd Schouten void shell_op P_((void));
32972fcea8cSEd Schouten void leave_op P_((void));
33072fcea8cSEd Schouten void redraw P_((void));
33172fcea8cSEd Schouten int Blank_Line P_((struct text *test_line));
33272fcea8cSEd Schouten void Format P_((void));
33372fcea8cSEd Schouten void ee_init P_((void));
33472fcea8cSEd Schouten void dump_ee_conf P_((void));
33572fcea8cSEd Schouten void echo_string P_((char *string));
33672fcea8cSEd Schouten void spell_op P_((void));
33772fcea8cSEd Schouten void ispell_op P_((void));
33872fcea8cSEd Schouten int first_word_len P_((struct text *test_line));
33972fcea8cSEd Schouten void Auto_Format P_((void));
34072fcea8cSEd Schouten void modes_op P_((void));
34172fcea8cSEd Schouten char *is_in_string P_((char *string, char *substring));
34272fcea8cSEd Schouten char *resolve_name P_((char *name));
34372fcea8cSEd Schouten int restrict_mode P_((void));
34472fcea8cSEd Schouten int unique_test P_((char *string, char *list[]));
34572fcea8cSEd Schouten void strings_init P_((void));
34672fcea8cSEd Schouten 
34772fcea8cSEd Schouten #undef P_
34872fcea8cSEd Schouten /*
34972fcea8cSEd Schouten  |	allocate space here for the strings that will be in the menu
35072fcea8cSEd Schouten  */
35172fcea8cSEd Schouten 
35272fcea8cSEd Schouten struct menu_entries modes_menu[] = {
35372fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, 0}, 	/* title		*/
35472fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 1. tabs to spaces	*/
35572fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 2. case sensitive search*/
35672fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 3. margins observed	*/
35772fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 4. auto-paragraph	*/
35872fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 5. eightbit characters*/
35972fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 6. info window	*/
36072fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 7. emacs key bindings*/
36172fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 8. right margin	*/
36272fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1}, 	/* 9. chinese text	*/
36372fcea8cSEd Schouten 	{"", NULL, NULL, NULL, dump_ee_conf, -1}, /* 10. save editor config */
36472fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}	/* terminator		*/
36572fcea8cSEd Schouten 	};
36672fcea8cSEd Schouten 
36772fcea8cSEd Schouten char *mode_strings[11];
36872fcea8cSEd Schouten 
36972fcea8cSEd Schouten #define NUM_MODES_ITEMS 10
37072fcea8cSEd Schouten 
37172fcea8cSEd Schouten struct menu_entries config_dump_menu[] = {
37272fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, 0},
37372fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
37472fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
37572fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
37672fcea8cSEd Schouten 	};
37772fcea8cSEd Schouten 
37872fcea8cSEd Schouten struct menu_entries leave_menu[] = {
37972fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
38072fcea8cSEd Schouten 	{"", NULL, NULL, NULL, finish, -1},
38172fcea8cSEd Schouten 	{"", NULL, NULL, quit, NULL, TRUE},
38272fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
38372fcea8cSEd Schouten 	};
38472fcea8cSEd Schouten 
38572fcea8cSEd Schouten #define READ_FILE 1
38672fcea8cSEd Schouten #define WRITE_FILE 2
38772fcea8cSEd Schouten #define SAVE_FILE 3
38872fcea8cSEd Schouten 
38972fcea8cSEd Schouten struct menu_entries file_menu[] = {
39072fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
39172fcea8cSEd Schouten 	{"", NULL, NULL, file_op, NULL, READ_FILE},
39272fcea8cSEd Schouten 	{"", NULL, NULL, file_op, NULL, WRITE_FILE},
39372fcea8cSEd Schouten 	{"", NULL, NULL, file_op, NULL, SAVE_FILE},
39472fcea8cSEd Schouten 	{"", NULL, NULL, NULL, print_buffer, -1},
39572fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
39672fcea8cSEd Schouten 	};
39772fcea8cSEd Schouten 
39872fcea8cSEd Schouten struct menu_entries search_menu[] = {
39972fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, 0},
40072fcea8cSEd Schouten 	{"", NULL, NULL, NULL, search_prompt, -1},
40172fcea8cSEd Schouten 	{"", NULL, NULL, search, NULL, TRUE},
40272fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
40372fcea8cSEd Schouten 	};
40472fcea8cSEd Schouten 
40572fcea8cSEd Schouten struct menu_entries spell_menu[] = {
40672fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
40772fcea8cSEd Schouten 	{"", NULL, NULL, NULL, spell_op, -1},
40872fcea8cSEd Schouten 	{"", NULL, NULL, NULL, ispell_op, -1},
40972fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
41072fcea8cSEd Schouten 	};
41172fcea8cSEd Schouten 
41272fcea8cSEd Schouten struct menu_entries misc_menu[] = {
41372fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
41472fcea8cSEd Schouten 	{"", NULL, NULL, NULL, Format, -1},
41572fcea8cSEd Schouten 	{"", NULL, NULL, NULL, shell_op, -1},
41672fcea8cSEd Schouten 	{"", menu_op, spell_menu, NULL, NULL, -1},
41772fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
41872fcea8cSEd Schouten 	};
41972fcea8cSEd Schouten 
42072fcea8cSEd Schouten struct menu_entries main_menu[] = {
42172fcea8cSEd Schouten 	{"", NULL, NULL, NULL, NULL, -1},
42272fcea8cSEd Schouten 	{"", NULL, NULL, NULL, leave_op, -1},
42372fcea8cSEd Schouten 	{"", NULL, NULL, NULL, help, -1},
42472fcea8cSEd Schouten 	{"", menu_op, file_menu, NULL, NULL, -1},
42572fcea8cSEd Schouten 	{"", NULL, NULL, NULL, redraw, -1},
42672fcea8cSEd Schouten 	{"", NULL, NULL, NULL, modes_op, -1},
42772fcea8cSEd Schouten 	{"", menu_op, search_menu, NULL, NULL, -1},
42872fcea8cSEd Schouten 	{"", menu_op, misc_menu, NULL, NULL, -1},
42972fcea8cSEd Schouten 	{NULL, NULL, NULL, NULL, NULL, -1}
43072fcea8cSEd Schouten 	};
43172fcea8cSEd Schouten 
43272fcea8cSEd Schouten char *help_text[23];
43372fcea8cSEd Schouten char *control_keys[5];
43472fcea8cSEd Schouten 
43572fcea8cSEd Schouten char *emacs_help_text[22];
43672fcea8cSEd Schouten char *emacs_control_keys[5];
43772fcea8cSEd Schouten 
43872fcea8cSEd Schouten char *command_strings[5];
43972fcea8cSEd Schouten char *commands[32];
44072fcea8cSEd Schouten char *init_strings[22];
44172fcea8cSEd Schouten 
44272fcea8cSEd Schouten #define MENU_WARN 1
44372fcea8cSEd Schouten 
44472fcea8cSEd Schouten #define max_alpha_char 36
44572fcea8cSEd Schouten 
44672fcea8cSEd Schouten /*
44772fcea8cSEd Schouten  |	Declarations for strings for localization
44872fcea8cSEd Schouten  */
44972fcea8cSEd Schouten 
45072fcea8cSEd Schouten char *com_win_message;		/* to be shown in com_win if no info window */
45172fcea8cSEd Schouten char *no_file_string;
45272fcea8cSEd Schouten char *ascii_code_str;
45372fcea8cSEd Schouten char *printer_msg_str;
45472fcea8cSEd Schouten char *command_str;
45572fcea8cSEd Schouten char *file_write_prompt_str;
45672fcea8cSEd Schouten char *file_read_prompt_str;
45772fcea8cSEd Schouten char *char_str;
45872fcea8cSEd Schouten char *unkn_cmd_str;
45972fcea8cSEd Schouten char *non_unique_cmd_msg;
46072fcea8cSEd Schouten char *line_num_str;
46172fcea8cSEd Schouten char *line_len_str;
46272fcea8cSEd Schouten char *current_file_str;
46372fcea8cSEd Schouten char *usage0;
46472fcea8cSEd Schouten char *usage1;
46572fcea8cSEd Schouten char *usage2;
46672fcea8cSEd Schouten char *usage3;
46772fcea8cSEd Schouten char *usage4;
46872fcea8cSEd Schouten char *file_is_dir_msg;
46972fcea8cSEd Schouten char *new_file_msg;
47072fcea8cSEd Schouten char *cant_open_msg;
47172fcea8cSEd Schouten char *open_file_msg;
47272fcea8cSEd Schouten char *file_read_fin_msg;
47372fcea8cSEd Schouten char *reading_file_msg;
47472fcea8cSEd Schouten char *read_only_msg;
47572fcea8cSEd Schouten char *file_read_lines_msg;
47672fcea8cSEd Schouten char *save_file_name_prompt;
47772fcea8cSEd Schouten char *file_not_saved_msg;
47872fcea8cSEd Schouten char *changes_made_prompt;
47972fcea8cSEd Schouten char *yes_char;
48072fcea8cSEd Schouten char *file_exists_prompt;
48172fcea8cSEd Schouten char *create_file_fail_msg;
48272fcea8cSEd Schouten char *writing_file_msg;
48372fcea8cSEd Schouten char *file_written_msg;
48472fcea8cSEd Schouten char *searching_msg;
48572fcea8cSEd Schouten char *str_not_found_msg;
48672fcea8cSEd Schouten char *search_prompt_str;
48772fcea8cSEd Schouten char *exec_err_msg;
48872fcea8cSEd Schouten char *continue_msg;
48972fcea8cSEd Schouten char *menu_cancel_msg;
49072fcea8cSEd Schouten char *menu_size_err_msg;
49172fcea8cSEd Schouten char *press_any_key_msg;
49272fcea8cSEd Schouten char *shell_prompt;
49372fcea8cSEd Schouten char *formatting_msg;
49472fcea8cSEd Schouten char *shell_echo_msg;
49572fcea8cSEd Schouten char *spell_in_prog_msg;
49672fcea8cSEd Schouten char *margin_prompt;
49772fcea8cSEd Schouten char *restricted_msg;
49872fcea8cSEd Schouten char *ON;
49972fcea8cSEd Schouten char *OFF;
50072fcea8cSEd Schouten char *HELP;
50172fcea8cSEd Schouten char *WRITE;
50272fcea8cSEd Schouten char *READ;
50372fcea8cSEd Schouten char *LINE;
50472fcea8cSEd Schouten char *FILE_str;
50572fcea8cSEd Schouten char *CHARACTER;
50672fcea8cSEd Schouten char *REDRAW;
50772fcea8cSEd Schouten char *RESEQUENCE;
50872fcea8cSEd Schouten char *AUTHOR;
50972fcea8cSEd Schouten char *VERSION;
51072fcea8cSEd Schouten char *CASE;
51172fcea8cSEd Schouten char *NOCASE;
51272fcea8cSEd Schouten char *EXPAND;
51372fcea8cSEd Schouten char *NOEXPAND;
51472fcea8cSEd Schouten char *Exit_string;
51572fcea8cSEd Schouten char *QUIT_string;
51672fcea8cSEd Schouten char *INFO;
51772fcea8cSEd Schouten char *NOINFO;
51872fcea8cSEd Schouten char *MARGINS;
51972fcea8cSEd Schouten char *NOMARGINS;
52072fcea8cSEd Schouten char *AUTOFORMAT;
52172fcea8cSEd Schouten char *NOAUTOFORMAT;
52272fcea8cSEd Schouten char *Echo;
52372fcea8cSEd Schouten char *PRINTCOMMAND;
52472fcea8cSEd Schouten char *RIGHTMARGIN;
52572fcea8cSEd Schouten char *HIGHLIGHT;
52672fcea8cSEd Schouten char *NOHIGHLIGHT;
52772fcea8cSEd Schouten char *EIGHTBIT;
52872fcea8cSEd Schouten char *NOEIGHTBIT;
52972fcea8cSEd Schouten char *EMACS_string;
53072fcea8cSEd Schouten char *NOEMACS_string;
53172fcea8cSEd Schouten char *conf_dump_err_msg;
53272fcea8cSEd Schouten char *conf_dump_success_msg;
53372fcea8cSEd Schouten char *conf_not_saved_msg;
53472fcea8cSEd Schouten char *ree_no_file_msg;
53572fcea8cSEd Schouten char *cancel_string;
53672fcea8cSEd Schouten char *menu_too_lrg_msg;
53772fcea8cSEd Schouten char *more_above_str, *more_below_str;
53896b676e9SEd Schouten char *separator = "===============================================================================";
53972fcea8cSEd Schouten 
54072fcea8cSEd Schouten char *chinese_cmd, *nochinese_cmd;
54172fcea8cSEd Schouten 
54296b676e9SEd Schouten #ifndef __STDC__
54396b676e9SEd Schouten #ifndef HAS_STDLIB
54496b676e9SEd Schouten extern char *malloc();
54596b676e9SEd Schouten extern char *realloc();
54696b676e9SEd Schouten extern char *getenv();
54796b676e9SEd Schouten FILE *fopen();			/* declaration for open function	*/
54896b676e9SEd Schouten #endif /* HAS_STDLIB */
54996b676e9SEd Schouten #endif /* __STDC__ */
55072fcea8cSEd Schouten 
55172fcea8cSEd Schouten int
55272fcea8cSEd Schouten main(argc, argv)		/* beginning of main program		*/
55372fcea8cSEd Schouten int argc;
55472fcea8cSEd Schouten char *argv[];
55572fcea8cSEd Schouten {
55696b676e9SEd Schouten 	int counter;
55796b676e9SEd Schouten 
55896b676e9SEd Schouten 	for (counter = 1; counter < 24; counter++)
55996b676e9SEd Schouten 		signal(counter, SIG_IGN);
56072fcea8cSEd Schouten 
56172fcea8cSEd Schouten 	signal(SIGCHLD, SIG_DFL);
56272fcea8cSEd Schouten 	signal(SIGSEGV, SIG_DFL);
56372fcea8cSEd Schouten 	signal(SIGINT, edit_abort);
56472fcea8cSEd Schouten 	d_char = malloc(3);	/* provide a buffer for multi-byte chars */
56572fcea8cSEd Schouten 	d_word = malloc(150);
56696b676e9SEd Schouten 	*d_word = '\0';
56772fcea8cSEd Schouten 	d_line = NULL;
56872fcea8cSEd Schouten 	dlt_line = txtalloc();
56972fcea8cSEd Schouten 	dlt_line->line = d_line;
57072fcea8cSEd Schouten 	dlt_line->line_length = 0;
57172fcea8cSEd Schouten 	curr_line = first_line = txtalloc();
57272fcea8cSEd Schouten 	curr_line->line = point = malloc(10);
57372fcea8cSEd Schouten 	curr_line->line_length = 1;
57472fcea8cSEd Schouten 	curr_line->max_length = 10;
57572fcea8cSEd Schouten 	curr_line->prev_line = NULL;
57672fcea8cSEd Schouten 	curr_line->next_line = NULL;
57772fcea8cSEd Schouten 	curr_line->line_number  = 1;
57872fcea8cSEd Schouten 	srch_str = NULL;
57972fcea8cSEd Schouten 	u_srch_str = NULL;
58072fcea8cSEd Schouten 	position = 1;
58172fcea8cSEd Schouten 	scr_pos =0;
58272fcea8cSEd Schouten 	scr_vert = 0;
58372fcea8cSEd Schouten 	scr_horz = 0;
58496b676e9SEd Schouten 	absolute_lin = 1;
58596b676e9SEd Schouten 	bit_bucket = fopen("/dev/null", "w");
58672fcea8cSEd Schouten 	edit = TRUE;
58772fcea8cSEd Schouten 	gold = case_sen = FALSE;
58872fcea8cSEd Schouten 	shell_fork = TRUE;
58972fcea8cSEd Schouten 	strings_init();
59072fcea8cSEd Schouten 	ee_init();
59172fcea8cSEd Schouten 	if (argc > 0 )
59272fcea8cSEd Schouten 		get_options(argc, argv);
59372fcea8cSEd Schouten 	set_up_term();
59472fcea8cSEd Schouten 	if (right_margin == 0)
59572fcea8cSEd Schouten 		right_margin = COLS - 1;
59672fcea8cSEd Schouten 	if (top_of_stack == NULL)
59772fcea8cSEd Schouten 	{
59872fcea8cSEd Schouten 		if (restrict_mode())
59972fcea8cSEd Schouten 		{
60072fcea8cSEd Schouten 			wmove(com_win, 0, 0);
60172fcea8cSEd Schouten 			werase(com_win);
60272fcea8cSEd Schouten 			wprintw(com_win, ree_no_file_msg);
60372fcea8cSEd Schouten 			wrefresh(com_win);
60472fcea8cSEd Schouten 			edit_abort(0);
60572fcea8cSEd Schouten 		}
60672fcea8cSEd Schouten 		wprintw(com_win, no_file_string);
60772fcea8cSEd Schouten 		wrefresh(com_win);
60872fcea8cSEd Schouten 	}
60972fcea8cSEd Schouten 	else
61072fcea8cSEd Schouten 		check_fp();
61172fcea8cSEd Schouten 
61272fcea8cSEd Schouten 	clear_com_win = TRUE;
61372fcea8cSEd Schouten 
61496b676e9SEd Schouten 	counter = 0;
61596b676e9SEd Schouten 
61672fcea8cSEd Schouten 	while(edit)
61772fcea8cSEd Schouten 	{
61896b676e9SEd Schouten 		/*
61996b676e9SEd Schouten 		 |  display line and column information
62096b676e9SEd Schouten 		 */
621cfe04e82SEd Schouten 		if (info_window)
622cfe04e82SEd Schouten 		{
623cfe04e82SEd Schouten 			if (!nohighlight)
62496b676e9SEd Schouten 				wstandout(info_win);
62596b676e9SEd Schouten 			wmove(info_win, 5, 0);
62696b676e9SEd Schouten 			wprintw(info_win, separator);
62796b676e9SEd Schouten 			wmove(info_win, 5, 5);
62896b676e9SEd Schouten 			wprintw(info_win, "line %d col %d lines from top %d ",
62996b676e9SEd Schouten 			          curr_line->line_number, scr_horz, absolute_lin);
63096b676e9SEd Schouten 			wstandend(info_win);
63196b676e9SEd Schouten 			wrefresh(info_win);
632cfe04e82SEd Schouten 		}
633cfe04e82SEd Schouten 
63496b676e9SEd Schouten 		wrefresh(text_win);
63572fcea8cSEd Schouten 		in = wgetch(text_win);
63672fcea8cSEd Schouten 		if (in == -1)
63796b676e9SEd Schouten 			exit(0);  /* without this exit ee will go into an
63896b676e9SEd Schouten 			             infinite loop if the network
63996b676e9SEd Schouten 			             session detaches */
64072fcea8cSEd Schouten 
64172fcea8cSEd Schouten 		resize_check();
64272fcea8cSEd Schouten 
64372fcea8cSEd Schouten 		if (clear_com_win)
64472fcea8cSEd Schouten 		{
64572fcea8cSEd Schouten 			clear_com_win = FALSE;
64672fcea8cSEd Schouten 			wmove(com_win, 0, 0);
64772fcea8cSEd Schouten 			werase(com_win);
64872fcea8cSEd Schouten 			if (!info_window)
64972fcea8cSEd Schouten 			{
65072fcea8cSEd Schouten 				wprintw(com_win, "%s", com_win_message);
65172fcea8cSEd Schouten 			}
65272fcea8cSEd Schouten 			wrefresh(com_win);
65372fcea8cSEd Schouten 		}
65472fcea8cSEd Schouten 
65572fcea8cSEd Schouten 		if (in > 255)
65672fcea8cSEd Schouten 			function_key();
65772fcea8cSEd Schouten 		else if ((in == '\10') || (in == 127))
65872fcea8cSEd Schouten 		{
65972fcea8cSEd Schouten 			in = 8;		/* make sure key is set to backspace */
66072fcea8cSEd Schouten 			delete(TRUE);
66172fcea8cSEd Schouten 		}
66272fcea8cSEd Schouten 		else if ((in > 31) || (in == 9))
66372fcea8cSEd Schouten 			insert(in);
66472fcea8cSEd Schouten 		else if ((in >= 0) && (in <= 31))
66572fcea8cSEd Schouten 		{
66672fcea8cSEd Schouten 			if (emacs_keys_mode)
66772fcea8cSEd Schouten 				emacs_control();
66872fcea8cSEd Schouten 			else
66972fcea8cSEd Schouten 				control();
67072fcea8cSEd Schouten 		}
67172fcea8cSEd Schouten 	}
67272fcea8cSEd Schouten 	return(0);
67372fcea8cSEd Schouten }
67472fcea8cSEd Schouten 
67572fcea8cSEd Schouten unsigned char *
67672fcea8cSEd Schouten resiz_line(factor, rline, rpos)	/* resize the line to length + factor*/
67772fcea8cSEd Schouten int factor;		/* resize factor				*/
67872fcea8cSEd Schouten struct text *rline;	/* position in line				*/
67972fcea8cSEd Schouten int rpos;
68072fcea8cSEd Schouten {
68172fcea8cSEd Schouten 	unsigned char *rpoint;
68272fcea8cSEd Schouten 	int resiz_var;
68372fcea8cSEd Schouten 
68472fcea8cSEd Schouten 	rline->max_length += factor;
68572fcea8cSEd Schouten 	rpoint = rline->line = realloc(rline->line, rline->max_length );
68672fcea8cSEd Schouten 	for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
68772fcea8cSEd Schouten 		rpoint++;
68872fcea8cSEd Schouten 	return(rpoint);
68972fcea8cSEd Schouten }
69072fcea8cSEd Schouten 
69172fcea8cSEd Schouten void
69272fcea8cSEd Schouten insert(character)		/* insert character into line		*/
69372fcea8cSEd Schouten int character;			/* new character			*/
69472fcea8cSEd Schouten {
69572fcea8cSEd Schouten 	int counter;
69672fcea8cSEd Schouten 	int value;
69772fcea8cSEd Schouten 	unsigned char *temp;	/* temporary pointer			*/
69872fcea8cSEd Schouten 	unsigned char *temp2;	/* temporary pointer			*/
69972fcea8cSEd Schouten 
70072fcea8cSEd Schouten 	if ((character == '\011') && (expand_tabs))
70172fcea8cSEd Schouten 	{
70272fcea8cSEd Schouten 		counter = len_char('\011', scr_horz);
70372fcea8cSEd Schouten 		for (; counter > 0; counter--)
70472fcea8cSEd Schouten 			insert(' ');
70572fcea8cSEd Schouten 		if (auto_format)
70672fcea8cSEd Schouten 			Auto_Format();
70772fcea8cSEd Schouten 		return;
70872fcea8cSEd Schouten 	}
70972fcea8cSEd Schouten 	text_changes = TRUE;
71072fcea8cSEd Schouten 	if ((curr_line->max_length - curr_line->line_length) < 5)
71172fcea8cSEd Schouten 		point = resiz_line(10, curr_line, position);
71272fcea8cSEd Schouten 	curr_line->line_length++;
71372fcea8cSEd Schouten 	temp = point;
71472fcea8cSEd Schouten 	counter = position;
71572fcea8cSEd Schouten 	while (counter < curr_line->line_length)	/* find end of line */
71672fcea8cSEd Schouten 	{
71772fcea8cSEd Schouten 		counter++;
71872fcea8cSEd Schouten 		temp++;
71972fcea8cSEd Schouten 	}
72072fcea8cSEd Schouten 	temp++;			/* increase length of line by one	*/
72172fcea8cSEd Schouten 	while (point < temp)
72272fcea8cSEd Schouten 	{
72372fcea8cSEd Schouten 		temp2=temp - 1;
72472fcea8cSEd Schouten 		*temp= *temp2;	/* shift characters over by one		*/
72572fcea8cSEd Schouten 		temp--;
72672fcea8cSEd Schouten 	}
72772fcea8cSEd Schouten 	*point = character;	/* insert new character			*/
72872fcea8cSEd Schouten 	wclrtoeol(text_win);
72972fcea8cSEd Schouten 	if (((character >= 0) && (character < ' ')) || (character >= 127)) /* check for TAB character*/
73072fcea8cSEd Schouten 	{
73172fcea8cSEd Schouten 		scr_pos = scr_horz += out_char(text_win, character, scr_horz);
73272fcea8cSEd Schouten 		point++;
73372fcea8cSEd Schouten 		position++;
73472fcea8cSEd Schouten 	}
73572fcea8cSEd Schouten 	else
73672fcea8cSEd Schouten 	{
73772fcea8cSEd Schouten 		waddch(text_win, character);
73872fcea8cSEd Schouten 		scr_pos = ++scr_horz;
73972fcea8cSEd Schouten 		point++;
74072fcea8cSEd Schouten 		position ++;
74172fcea8cSEd Schouten 	}
74272fcea8cSEd Schouten 
74372fcea8cSEd Schouten 	if ((observ_margins) && (right_margin < scr_pos))
74472fcea8cSEd Schouten 	{
74572fcea8cSEd Schouten 		counter = position;
74672fcea8cSEd Schouten 		while (scr_pos > right_margin)
74772fcea8cSEd Schouten 			prev_word();
74872fcea8cSEd Schouten 		if (scr_pos == 0)
74972fcea8cSEd Schouten 		{
75072fcea8cSEd Schouten 			while (position < counter)
75172fcea8cSEd Schouten 				right(TRUE);
75272fcea8cSEd Schouten 		}
75372fcea8cSEd Schouten 		else
75472fcea8cSEd Schouten 		{
75572fcea8cSEd Schouten 			counter -= position;
75672fcea8cSEd Schouten 			insert_line(TRUE);
75772fcea8cSEd Schouten 			for (value = 0; value < counter; value++)
75872fcea8cSEd Schouten 				right(TRUE);
75972fcea8cSEd Schouten 		}
76072fcea8cSEd Schouten 	}
76172fcea8cSEd Schouten 
76272fcea8cSEd Schouten 	if ((scr_horz - horiz_offset) > last_col)
76372fcea8cSEd Schouten 	{
76472fcea8cSEd Schouten 		horiz_offset += 8;
76572fcea8cSEd Schouten 		midscreen(scr_vert, point);
76672fcea8cSEd Schouten 	}
76772fcea8cSEd Schouten 
76872fcea8cSEd Schouten 	if ((auto_format) && (character == ' ') && (!formatted))
76972fcea8cSEd Schouten 		Auto_Format();
77072fcea8cSEd Schouten 	else if ((character != ' ') && (character != '\t'))
77172fcea8cSEd Schouten 		formatted = FALSE;
77272fcea8cSEd Schouten 
77372fcea8cSEd Schouten 	draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
77472fcea8cSEd Schouten }
77572fcea8cSEd Schouten 
77672fcea8cSEd Schouten void
77772fcea8cSEd Schouten delete(disp)			/* delete character		*/
77872fcea8cSEd Schouten int disp;
77972fcea8cSEd Schouten {
78072fcea8cSEd Schouten 	unsigned char *tp;
78172fcea8cSEd Schouten 	unsigned char *temp2;
78272fcea8cSEd Schouten 	struct text *temp_buff;
78372fcea8cSEd Schouten 	int temp_vert;
78472fcea8cSEd Schouten 	int temp_pos;
78572fcea8cSEd Schouten 	int del_width = 1;
78672fcea8cSEd Schouten 
78772fcea8cSEd Schouten 	if (point != curr_line->line)	/* if not at beginning of line	*/
78872fcea8cSEd Schouten 	{
78972fcea8cSEd Schouten 		text_changes = TRUE;
79072fcea8cSEd Schouten 		temp2 = tp = point;
79172fcea8cSEd Schouten 		if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
79272fcea8cSEd Schouten 		{
79372fcea8cSEd Schouten 			del_width = 2;
79472fcea8cSEd Schouten 		}
79572fcea8cSEd Schouten 		tp -= del_width;
79672fcea8cSEd Schouten 		point -= del_width;
79772fcea8cSEd Schouten 		position -= del_width;
79872fcea8cSEd Schouten 		temp_pos = position;
79972fcea8cSEd Schouten 		curr_line->line_length -= del_width;
80072fcea8cSEd Schouten 		if ((*tp < ' ') || (*tp >= 127))	/* check for TAB */
80172fcea8cSEd Schouten 			scanline(tp);
80272fcea8cSEd Schouten 		else
80372fcea8cSEd Schouten 			scr_horz -= del_width;
80472fcea8cSEd Schouten 		scr_pos = scr_horz;
80572fcea8cSEd Schouten 		if (in == 8)
80672fcea8cSEd Schouten 		{
80772fcea8cSEd Schouten 			if (del_width == 1)
80872fcea8cSEd Schouten 				*d_char = *point; /* save deleted character  */
80972fcea8cSEd Schouten 			else
81072fcea8cSEd Schouten 			{
81172fcea8cSEd Schouten 				d_char[0] = *point;
81272fcea8cSEd Schouten 				d_char[1] = *(point + 1);
81372fcea8cSEd Schouten 			}
81496b676e9SEd Schouten 			d_char[del_width] = '\0';
81572fcea8cSEd Schouten 		}
81672fcea8cSEd Schouten 		while (temp_pos <= curr_line->line_length)
81772fcea8cSEd Schouten 		{
81872fcea8cSEd Schouten 			temp_pos++;
81972fcea8cSEd Schouten 			*tp = *temp2;
82072fcea8cSEd Schouten 			tp++;
82172fcea8cSEd Schouten 			temp2++;
82272fcea8cSEd Schouten 		}
82372fcea8cSEd Schouten 		if (scr_horz < horiz_offset)
82472fcea8cSEd Schouten 		{
82572fcea8cSEd Schouten 			horiz_offset -= 8;
82672fcea8cSEd Schouten 			midscreen(scr_vert, point);
82772fcea8cSEd Schouten 		}
82872fcea8cSEd Schouten 	}
82972fcea8cSEd Schouten 	else if (curr_line->prev_line != NULL)
83072fcea8cSEd Schouten 	{
83196b676e9SEd Schouten 		absolute_lin--;
83272fcea8cSEd Schouten 		text_changes = TRUE;
83372fcea8cSEd Schouten 		left(disp);			/* go to previous line	*/
83472fcea8cSEd Schouten 		temp_buff = curr_line->next_line;
83572fcea8cSEd Schouten 		point = resiz_line(temp_buff->line_length, curr_line, position);
83672fcea8cSEd Schouten 		if (temp_buff->next_line != NULL)
83772fcea8cSEd Schouten 			temp_buff->next_line->prev_line = curr_line;
83872fcea8cSEd Schouten 		curr_line->next_line = temp_buff->next_line;
83972fcea8cSEd Schouten 		temp2 = temp_buff->line;
84072fcea8cSEd Schouten 		if (in == 8)
84172fcea8cSEd Schouten 		{
84272fcea8cSEd Schouten 			d_char[0] = '\n';
84396b676e9SEd Schouten 			d_char[1] = '\0';
84472fcea8cSEd Schouten 		}
84572fcea8cSEd Schouten 		tp = point;
84672fcea8cSEd Schouten 		temp_pos = 1;
84772fcea8cSEd Schouten 		while (temp_pos < temp_buff->line_length)
84872fcea8cSEd Schouten 		{
84972fcea8cSEd Schouten 			curr_line->line_length++;
85072fcea8cSEd Schouten 			temp_pos++;
85172fcea8cSEd Schouten 			*tp = *temp2;
85272fcea8cSEd Schouten 			tp++;
85372fcea8cSEd Schouten 			temp2++;
85472fcea8cSEd Schouten 		}
85596b676e9SEd Schouten 		*tp = '\0';
85672fcea8cSEd Schouten 		free(temp_buff->line);
85772fcea8cSEd Schouten 		free(temp_buff);
85872fcea8cSEd Schouten 		temp_buff = curr_line;
85972fcea8cSEd Schouten 		temp_vert = scr_vert;
86072fcea8cSEd Schouten 		scr_pos = scr_horz;
86172fcea8cSEd Schouten 		if (scr_vert < last_line)
86272fcea8cSEd Schouten 		{
86372fcea8cSEd Schouten 			wmove(text_win, scr_vert + 1, 0);
86472fcea8cSEd Schouten 			wdeleteln(text_win);
86572fcea8cSEd Schouten 		}
86672fcea8cSEd Schouten 		while ((temp_buff != NULL) && (temp_vert < last_line))
86772fcea8cSEd Schouten 		{
86872fcea8cSEd Schouten 			temp_buff = temp_buff->next_line;
86972fcea8cSEd Schouten 			temp_vert++;
87072fcea8cSEd Schouten 		}
87172fcea8cSEd Schouten 		if ((temp_vert == last_line) && (temp_buff != NULL))
87272fcea8cSEd Schouten 		{
87372fcea8cSEd Schouten 			tp = temp_buff->line;
87472fcea8cSEd Schouten 			wmove(text_win, last_line,0);
87572fcea8cSEd Schouten 			wclrtobot(text_win);
87672fcea8cSEd Schouten 			draw_line(last_line, 0, tp, 1, temp_buff->line_length);
87772fcea8cSEd Schouten 			wmove(text_win, scr_vert, (scr_horz - horiz_offset));
87872fcea8cSEd Schouten 		}
87972fcea8cSEd Schouten 	}
88072fcea8cSEd Schouten 	draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
88172fcea8cSEd Schouten 	formatted = FALSE;
88272fcea8cSEd Schouten }
88372fcea8cSEd Schouten 
88472fcea8cSEd Schouten void
88572fcea8cSEd Schouten scanline(pos)	/* find the proper horizontal position for the pointer	*/
88672fcea8cSEd Schouten unsigned char *pos;
88772fcea8cSEd Schouten {
88872fcea8cSEd Schouten 	int temp;
88972fcea8cSEd Schouten 	unsigned char *ptr;
89072fcea8cSEd Schouten 
89172fcea8cSEd Schouten 	ptr = curr_line->line;
89272fcea8cSEd Schouten 	temp = 0;
89372fcea8cSEd Schouten 	while (ptr < pos)
89472fcea8cSEd Schouten 	{
89572fcea8cSEd Schouten 		if (*ptr <= 8)
89672fcea8cSEd Schouten 			temp += 2;
89772fcea8cSEd Schouten 		else if (*ptr == 9)
89872fcea8cSEd Schouten 			temp += tabshift(temp);
89972fcea8cSEd Schouten 		else if ((*ptr >= 10) && (*ptr <= 31))
90072fcea8cSEd Schouten 			temp += 2;
90172fcea8cSEd Schouten 		else if ((*ptr >= 32) && (*ptr < 127))
90272fcea8cSEd Schouten 			temp++;
90372fcea8cSEd Schouten 		else if (*ptr == 127)
90472fcea8cSEd Schouten 			temp += 2;
90572fcea8cSEd Schouten 		else if (!eightbit)
90672fcea8cSEd Schouten 			temp += 5;
90772fcea8cSEd Schouten 		else
90872fcea8cSEd Schouten 			temp++;
90972fcea8cSEd Schouten 		ptr++;
91072fcea8cSEd Schouten 	}
91172fcea8cSEd Schouten 	scr_horz = temp;
91272fcea8cSEd Schouten 	if ((scr_horz - horiz_offset) > last_col)
91372fcea8cSEd Schouten 	{
91472fcea8cSEd Schouten 		horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
91572fcea8cSEd Schouten 		midscreen(scr_vert, point);
91672fcea8cSEd Schouten 	}
91772fcea8cSEd Schouten 	else if (scr_horz < horiz_offset)
91872fcea8cSEd Schouten 	{
91972fcea8cSEd Schouten 		horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
92072fcea8cSEd Schouten 		midscreen(scr_vert, point);
92172fcea8cSEd Schouten 	}
92272fcea8cSEd Schouten }
92372fcea8cSEd Schouten 
92472fcea8cSEd Schouten int
92572fcea8cSEd Schouten tabshift(temp_int)		/* give the number of spaces to shift	*/
92672fcea8cSEd Schouten int temp_int;
92772fcea8cSEd Schouten {
92872fcea8cSEd Schouten 	int leftover;
92972fcea8cSEd Schouten 
93072fcea8cSEd Schouten 	leftover = ((temp_int + 1) % 8);
93172fcea8cSEd Schouten 	if (leftover == 0)
93272fcea8cSEd Schouten 		return (1);
93372fcea8cSEd Schouten 	else
93472fcea8cSEd Schouten 		return (9 - leftover);
93572fcea8cSEd Schouten }
93672fcea8cSEd Schouten 
93772fcea8cSEd Schouten int
93872fcea8cSEd Schouten out_char(window, character, column)	/* output non-printing character */
93972fcea8cSEd Schouten WINDOW *window;
94072fcea8cSEd Schouten char character;
94172fcea8cSEd Schouten int column;
94272fcea8cSEd Schouten {
94372fcea8cSEd Schouten 	int i1, i2;
94496b676e9SEd Schouten 	char *string;
94572fcea8cSEd Schouten 	char string2[8];
94672fcea8cSEd Schouten 
94772fcea8cSEd Schouten 	if (character == TAB)
94872fcea8cSEd Schouten 	{
94972fcea8cSEd Schouten 		i1 = tabshift(column);
95072fcea8cSEd Schouten 		for (i2 = 0;
95172fcea8cSEd Schouten 		  (i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
95272fcea8cSEd Schouten 		{
95372fcea8cSEd Schouten 			waddch(window, ' ');
95472fcea8cSEd Schouten 		}
95572fcea8cSEd Schouten 		return(i1);
95672fcea8cSEd Schouten 	}
95772fcea8cSEd Schouten 	else if ((character >= '\0') && (character < ' '))
95872fcea8cSEd Schouten 	{
95972fcea8cSEd Schouten 		string = table[(int) character];
96072fcea8cSEd Schouten 	}
96172fcea8cSEd Schouten 	else if ((character < 0) || (character >= 127))
96272fcea8cSEd Schouten 	{
96372fcea8cSEd Schouten 		if (character == 127)
96472fcea8cSEd Schouten 			string = "^?";
96572fcea8cSEd Schouten 		else if (!eightbit)
96672fcea8cSEd Schouten 		{
96772fcea8cSEd Schouten 			sprintf(string2, "<%d>", (character < 0) ? (character + 256) : character);
96872fcea8cSEd Schouten 			string = string2;
96972fcea8cSEd Schouten 		}
97072fcea8cSEd Schouten 		else
97172fcea8cSEd Schouten 		{
97296b676e9SEd Schouten 			waddch(window, (char)character );
97372fcea8cSEd Schouten 			return(1);
97472fcea8cSEd Schouten 		}
97572fcea8cSEd Schouten 	}
97672fcea8cSEd Schouten 	else
97772fcea8cSEd Schouten 	{
97896b676e9SEd Schouten 		waddch(window, (char)character);
97972fcea8cSEd Schouten 		return(1);
98072fcea8cSEd Schouten 	}
98196b676e9SEd Schouten 	for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
98272fcea8cSEd Schouten 		waddch(window, string[i2]);
98372fcea8cSEd Schouten 	return(strlen(string));
98472fcea8cSEd Schouten }
98572fcea8cSEd Schouten 
98672fcea8cSEd Schouten int
98772fcea8cSEd Schouten len_char(character, column)	/* return the length of the character	*/
98872fcea8cSEd Schouten char character;
98972fcea8cSEd Schouten int column;	/* the column must be known to provide spacing for tabs	*/
99072fcea8cSEd Schouten {
99172fcea8cSEd Schouten 	int length;
99272fcea8cSEd Schouten 
99372fcea8cSEd Schouten 	if (character == '\t')
99472fcea8cSEd Schouten 		length = tabshift(column);
99572fcea8cSEd Schouten 	else if ((character >= 0) && (character < 32))
99672fcea8cSEd Schouten 		length = 2;
99772fcea8cSEd Schouten 	else if ((character >= 32) && (character <= 126))
99872fcea8cSEd Schouten 		length = 1;
99972fcea8cSEd Schouten 	else if (character == 127)
100072fcea8cSEd Schouten 		length = 2;
100172fcea8cSEd Schouten 	else if (((character > 126) || (character < 0)) && (!eightbit))
100272fcea8cSEd Schouten 		length = 5;
100372fcea8cSEd Schouten 	else
100472fcea8cSEd Schouten 		length = 1;
100572fcea8cSEd Schouten 
100672fcea8cSEd Schouten 	return(length);
100772fcea8cSEd Schouten }
100872fcea8cSEd Schouten 
100972fcea8cSEd Schouten void
101072fcea8cSEd Schouten draw_line(vertical, horiz, ptr, t_pos, length)	/* redraw line from current position */
101172fcea8cSEd Schouten int vertical;	/* current vertical position on screen		*/
101272fcea8cSEd Schouten int horiz;	/* current horizontal position on screen	*/
101372fcea8cSEd Schouten unsigned char *ptr;	/* pointer to line				*/
101472fcea8cSEd Schouten int t_pos;	/* current position (offset in bytes) from bol	*/
101572fcea8cSEd Schouten int length;	/* length (in bytes) of line			*/
101672fcea8cSEd Schouten {
101772fcea8cSEd Schouten 	int d;		/* partial length of special or tab char to display  */
101872fcea8cSEd Schouten 	unsigned char *temp;	/* temporary pointer to position in line	     */
101972fcea8cSEd Schouten 	int abs_column;	/* offset in screen units from begin of line	     */
102072fcea8cSEd Schouten 	int column;	/* horizontal position on screen		     */
102172fcea8cSEd Schouten 	int row;	/* vertical position on screen			     */
102272fcea8cSEd Schouten 	int posit;	/* temporary position indicator within line	     */
102372fcea8cSEd Schouten 
102472fcea8cSEd Schouten 	abs_column = horiz;
102572fcea8cSEd Schouten 	column = horiz - horiz_offset;
102672fcea8cSEd Schouten 	row = vertical;
102772fcea8cSEd Schouten 	temp = ptr;
102872fcea8cSEd Schouten 	d = 0;
102972fcea8cSEd Schouten 	posit = t_pos;
103072fcea8cSEd Schouten 	if (column < 0)
103172fcea8cSEd Schouten 	{
103272fcea8cSEd Schouten 		wmove(text_win, row, 0);
103372fcea8cSEd Schouten 		wclrtoeol(text_win);
103472fcea8cSEd Schouten 	}
103572fcea8cSEd Schouten 	while (column < 0)
103672fcea8cSEd Schouten 	{
103772fcea8cSEd Schouten 		d = len_char(*temp, abs_column);
103872fcea8cSEd Schouten 		abs_column += d;
103972fcea8cSEd Schouten 		column += d;
104072fcea8cSEd Schouten 		posit++;
104172fcea8cSEd Schouten 		temp++;
104272fcea8cSEd Schouten 	}
104372fcea8cSEd Schouten 	wmove(text_win, row, column);
104472fcea8cSEd Schouten 	wclrtoeol(text_win);
104572fcea8cSEd Schouten 	while ((posit < length) && (column <= last_col))
104672fcea8cSEd Schouten 	{
104772fcea8cSEd Schouten 		if ((*temp < 32) || (*temp >= 127))
104872fcea8cSEd Schouten 		{
104972fcea8cSEd Schouten 			column += len_char(*temp, abs_column);
105072fcea8cSEd Schouten 			abs_column += out_char(text_win, *temp, abs_column);
105172fcea8cSEd Schouten 		}
105272fcea8cSEd Schouten 		else
105372fcea8cSEd Schouten 		{
105472fcea8cSEd Schouten 			abs_column++;
105572fcea8cSEd Schouten 			column++;
105672fcea8cSEd Schouten 			waddch(text_win, *temp);
105772fcea8cSEd Schouten 		}
105872fcea8cSEd Schouten 		posit++;
105972fcea8cSEd Schouten 		temp++;
106072fcea8cSEd Schouten 	}
106172fcea8cSEd Schouten 	if (column < last_col)
106272fcea8cSEd Schouten 		wclrtoeol(text_win);
106372fcea8cSEd Schouten 	wmove(text_win, vertical, (horiz - horiz_offset));
106472fcea8cSEd Schouten }
106572fcea8cSEd Schouten 
106672fcea8cSEd Schouten void
106772fcea8cSEd Schouten insert_line(disp)			/* insert new line		*/
106872fcea8cSEd Schouten int disp;
106972fcea8cSEd Schouten {
107072fcea8cSEd Schouten 	int temp_pos;
107172fcea8cSEd Schouten 	int temp_pos2;
107272fcea8cSEd Schouten 	unsigned char *temp;
107372fcea8cSEd Schouten 	unsigned char *extra;
107472fcea8cSEd Schouten 	struct text *temp_nod;
107572fcea8cSEd Schouten 
107672fcea8cSEd Schouten 	text_changes = TRUE;
107772fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
107872fcea8cSEd Schouten 	wclrtoeol(text_win);
107972fcea8cSEd Schouten 	temp_nod= txtalloc();
108072fcea8cSEd Schouten 	temp_nod->line = extra= malloc(10);
108172fcea8cSEd Schouten 	temp_nod->line_length = 1;
108272fcea8cSEd Schouten 	temp_nod->max_length = 10;
108396b676e9SEd Schouten 	temp_nod->line_number = curr_line->line_number + 1;
108472fcea8cSEd Schouten 	temp_nod->next_line = curr_line->next_line;
108572fcea8cSEd Schouten 	if (temp_nod->next_line != NULL)
108672fcea8cSEd Schouten 		temp_nod->next_line->prev_line = temp_nod;
108772fcea8cSEd Schouten 	temp_nod->prev_line = curr_line;
108872fcea8cSEd Schouten 	curr_line->next_line = temp_nod;
108972fcea8cSEd Schouten 	temp_pos2 = position;
109072fcea8cSEd Schouten 	temp = point;
109172fcea8cSEd Schouten 	if (temp_pos2 < curr_line->line_length)
109272fcea8cSEd Schouten 	{
109372fcea8cSEd Schouten 		temp_pos = 1;
109472fcea8cSEd Schouten 		while (temp_pos2 < curr_line->line_length)
109572fcea8cSEd Schouten 		{
109672fcea8cSEd Schouten 			if ((temp_nod->max_length - temp_nod->line_length)< 5)
109772fcea8cSEd Schouten 				extra = resiz_line(10, temp_nod, temp_pos);
109872fcea8cSEd Schouten 			temp_nod->line_length++;
109972fcea8cSEd Schouten 			temp_pos++;
110072fcea8cSEd Schouten 			temp_pos2++;
110172fcea8cSEd Schouten 			*extra= *temp;
110272fcea8cSEd Schouten 			extra++;
110372fcea8cSEd Schouten 			temp++;
110472fcea8cSEd Schouten 		}
110572fcea8cSEd Schouten 		temp=point;
110696b676e9SEd Schouten 		*temp = '\0';
110772fcea8cSEd Schouten 		temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
110872fcea8cSEd Schouten 		curr_line->line_length = 1 + temp - curr_line->line;
110972fcea8cSEd Schouten 	}
111072fcea8cSEd Schouten 	curr_line->line_length = position;
111196b676e9SEd Schouten 	absolute_lin++;
111272fcea8cSEd Schouten 	curr_line = temp_nod;
111396b676e9SEd Schouten 	*extra = '\0';
111472fcea8cSEd Schouten 	position = 1;
111572fcea8cSEd Schouten 	point= curr_line->line;
111672fcea8cSEd Schouten 	if (disp)
111772fcea8cSEd Schouten 	{
111872fcea8cSEd Schouten 		if (scr_vert < last_line)
111972fcea8cSEd Schouten 		{
112072fcea8cSEd Schouten 			scr_vert++;
112172fcea8cSEd Schouten 			wclrtoeol(text_win);
112272fcea8cSEd Schouten 			wmove(text_win, scr_vert, 0);
112372fcea8cSEd Schouten 			winsertln(text_win);
112472fcea8cSEd Schouten 		}
112572fcea8cSEd Schouten 		else
112672fcea8cSEd Schouten 		{
112772fcea8cSEd Schouten 			wmove(text_win, 0,0);
112872fcea8cSEd Schouten 			wdeleteln(text_win);
112972fcea8cSEd Schouten 			wmove(text_win, last_line,0);
113072fcea8cSEd Schouten 			wclrtobot(text_win);
113172fcea8cSEd Schouten 		}
113272fcea8cSEd Schouten 		scr_pos = scr_horz = 0;
113372fcea8cSEd Schouten 		if (horiz_offset)
113472fcea8cSEd Schouten 		{
113572fcea8cSEd Schouten 			horiz_offset = 0;
113672fcea8cSEd Schouten 			midscreen(scr_vert, point);
113772fcea8cSEd Schouten 		}
113872fcea8cSEd Schouten 		draw_line(scr_vert, scr_horz, point, position,
113972fcea8cSEd Schouten 			curr_line->line_length);
114072fcea8cSEd Schouten 	}
114172fcea8cSEd Schouten }
114272fcea8cSEd Schouten 
114372fcea8cSEd Schouten struct text *txtalloc()		/* allocate space for line structure	*/
114472fcea8cSEd Schouten {
114572fcea8cSEd Schouten 	return((struct text *) malloc(sizeof( struct text)));
114672fcea8cSEd Schouten }
114772fcea8cSEd Schouten 
114872fcea8cSEd Schouten struct files *name_alloc()	/* allocate space for file name list node */
114972fcea8cSEd Schouten {
115072fcea8cSEd Schouten 	return((struct files *) malloc(sizeof( struct files)));
115172fcea8cSEd Schouten }
115272fcea8cSEd Schouten 
115372fcea8cSEd Schouten unsigned char *next_word(string)		/* move to next word in string		*/
115472fcea8cSEd Schouten unsigned char *string;
115572fcea8cSEd Schouten {
115696b676e9SEd Schouten 	while ((*string != '\0') && ((*string != 32) && (*string != 9)))
115772fcea8cSEd Schouten 		string++;
115896b676e9SEd Schouten 	while ((*string != '\0') && ((*string == 32) || (*string == 9)))
115972fcea8cSEd Schouten 		string++;
116072fcea8cSEd Schouten 	return(string);
116172fcea8cSEd Schouten }
116272fcea8cSEd Schouten 
116372fcea8cSEd Schouten void
116472fcea8cSEd Schouten prev_word()	/* move to start of previous word in text	*/
116572fcea8cSEd Schouten {
116672fcea8cSEd Schouten 	if (position != 1)
116772fcea8cSEd Schouten 	{
116872fcea8cSEd Schouten 		if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
116972fcea8cSEd Schouten 		{	/* if at the start of a word	*/
117072fcea8cSEd Schouten 			while ((position != 1) && ((*point != ' ') && (*point != '\t')))
117172fcea8cSEd Schouten 				left(TRUE);
117272fcea8cSEd Schouten 		}
117372fcea8cSEd Schouten 		while ((position != 1) && ((*point == ' ') || (*point == '\t')))
117472fcea8cSEd Schouten 			left(TRUE);
117572fcea8cSEd Schouten 		while ((position != 1) && ((*point != ' ') && (*point != '\t')))
117672fcea8cSEd Schouten 			left(TRUE);
117772fcea8cSEd Schouten 		if ((position != 1) && ((*point == ' ') || (*point == '\t')))
117872fcea8cSEd Schouten 			right(TRUE);
117972fcea8cSEd Schouten 	}
118072fcea8cSEd Schouten 	else
118172fcea8cSEd Schouten 		left(TRUE);
118272fcea8cSEd Schouten }
118372fcea8cSEd Schouten 
118472fcea8cSEd Schouten void
118572fcea8cSEd Schouten control()			/* use control for commands		*/
118672fcea8cSEd Schouten {
118772fcea8cSEd Schouten 	char *string;
118872fcea8cSEd Schouten 
118972fcea8cSEd Schouten 	if (in == 1)		/* control a	*/
119072fcea8cSEd Schouten 	{
119172fcea8cSEd Schouten 		string = get_string(ascii_code_str, TRUE);
119296b676e9SEd Schouten 		if (*string != '\0')
119372fcea8cSEd Schouten 		{
119472fcea8cSEd Schouten 			in = atoi(string);
119572fcea8cSEd Schouten 			wmove(text_win, scr_vert, (scr_horz - horiz_offset));
119672fcea8cSEd Schouten 			insert(in);
119772fcea8cSEd Schouten 		}
119872fcea8cSEd Schouten 		free(string);
119972fcea8cSEd Schouten 	}
120072fcea8cSEd Schouten 	else if (in == 2)	/* control b	*/
120172fcea8cSEd Schouten 		bottom();
120272fcea8cSEd Schouten 	else if (in == 3)	/* control c	*/
120372fcea8cSEd Schouten 	{
120472fcea8cSEd Schouten 		command_prompt();
120572fcea8cSEd Schouten 	}
120672fcea8cSEd Schouten 	else if (in == 4)	/* control d	*/
120772fcea8cSEd Schouten 		down();
120872fcea8cSEd Schouten 	else if (in == 5)	/* control e	*/
120972fcea8cSEd Schouten 		search_prompt();
121072fcea8cSEd Schouten 	else if (in == 6)	/* control f	*/
121172fcea8cSEd Schouten 		undel_char();
121272fcea8cSEd Schouten 	else if (in == 7)	/* control g	*/
121372fcea8cSEd Schouten 		bol();
121472fcea8cSEd Schouten 	else if (in == 8)	/* control h	*/
121572fcea8cSEd Schouten 		delete(TRUE);
121672fcea8cSEd Schouten 	else if (in == 9)	/* control i	*/
121772fcea8cSEd Schouten 		;
121872fcea8cSEd Schouten 	else if (in == 10)	/* control j	*/
121972fcea8cSEd Schouten 		insert_line(TRUE);
122072fcea8cSEd Schouten 	else if (in == 11)	/* control k	*/
122172fcea8cSEd Schouten 		del_char();
122272fcea8cSEd Schouten 	else if (in == 12)	/* control l	*/
122372fcea8cSEd Schouten 		left(TRUE);
122472fcea8cSEd Schouten 	else if (in == 13)	/* control m	*/
122572fcea8cSEd Schouten 		insert_line(TRUE);
122672fcea8cSEd Schouten 	else if (in == 14)	/* control n	*/
122772fcea8cSEd Schouten 		move_rel("d", max(5, (last_line - 5)));
122872fcea8cSEd Schouten 	else if (in == 15)	/* control o	*/
122972fcea8cSEd Schouten 		eol();
123072fcea8cSEd Schouten 	else if (in == 16)	/* control p	*/
123172fcea8cSEd Schouten 		move_rel("u", max(5, (last_line - 5)));
123272fcea8cSEd Schouten 	else if (in == 17)	/* control q	*/
123372fcea8cSEd Schouten 		;
123472fcea8cSEd Schouten 	else if (in == 18)	/* control r	*/
123572fcea8cSEd Schouten 		right(TRUE);
123672fcea8cSEd Schouten 	else if (in == 19)	/* control s	*/
123772fcea8cSEd Schouten 		;
123872fcea8cSEd Schouten 	else if (in == 20)	/* control t	*/
123972fcea8cSEd Schouten 		top();
124072fcea8cSEd Schouten 	else if (in == 21)	/* control u	*/
124172fcea8cSEd Schouten 		up();
124272fcea8cSEd Schouten 	else if (in == 22)	/* control v	*/
124372fcea8cSEd Schouten 		undel_word();
124472fcea8cSEd Schouten 	else if (in == 23)	/* control w	*/
124572fcea8cSEd Schouten 		del_word();
124672fcea8cSEd Schouten 	else if (in == 24)	/* control x	*/
124772fcea8cSEd Schouten 		search(TRUE);
124872fcea8cSEd Schouten 	else if (in == 25)	/* control y	*/
124972fcea8cSEd Schouten 		del_line();
125072fcea8cSEd Schouten 	else if (in == 26)	/* control z	*/
125172fcea8cSEd Schouten 		undel_line();
125272fcea8cSEd Schouten 	else if (in == 27)	/* control [ (escape)	*/
125372fcea8cSEd Schouten 	{
125472fcea8cSEd Schouten 		menu_op(main_menu);
125572fcea8cSEd Schouten 	}
125672fcea8cSEd Schouten }
125772fcea8cSEd Schouten 
125872fcea8cSEd Schouten /*
125972fcea8cSEd Schouten  |	Emacs control-key bindings
126072fcea8cSEd Schouten  */
126172fcea8cSEd Schouten 
126272fcea8cSEd Schouten void
126372fcea8cSEd Schouten emacs_control()
126472fcea8cSEd Schouten {
126572fcea8cSEd Schouten 	char *string;
126672fcea8cSEd Schouten 
126772fcea8cSEd Schouten 	if (in == 1)		/* control a	*/
126872fcea8cSEd Schouten 		bol();
126972fcea8cSEd Schouten 	else if (in == 2)	/* control b	*/
127072fcea8cSEd Schouten 		left(TRUE);
127172fcea8cSEd Schouten 	else if (in == 3)	/* control c	*/
127272fcea8cSEd Schouten 	{
127372fcea8cSEd Schouten 		command_prompt();
127472fcea8cSEd Schouten 	}
127572fcea8cSEd Schouten 	else if (in == 4)	/* control d	*/
127672fcea8cSEd Schouten 		del_char();
127772fcea8cSEd Schouten 	else if (in == 5)	/* control e	*/
127872fcea8cSEd Schouten 		eol();
127972fcea8cSEd Schouten 	else if (in == 6)	/* control f	*/
128072fcea8cSEd Schouten 		right(TRUE);
128172fcea8cSEd Schouten 	else if (in == 7)	/* control g	*/
128272fcea8cSEd Schouten 		move_rel("u", max(5, (last_line - 5)));
128372fcea8cSEd Schouten 	else if (in == 8)	/* control h	*/
128472fcea8cSEd Schouten 		delete(TRUE);
128572fcea8cSEd Schouten 	else if (in == 9)	/* control i	*/
128672fcea8cSEd Schouten 		;
128772fcea8cSEd Schouten 	else if (in == 10)	/* control j	*/
128872fcea8cSEd Schouten 		undel_char();
128972fcea8cSEd Schouten 	else if (in == 11)	/* control k	*/
129072fcea8cSEd Schouten 		del_line();
129172fcea8cSEd Schouten 	else if (in == 12)	/* control l	*/
129272fcea8cSEd Schouten 		undel_line();
129372fcea8cSEd Schouten 	else if (in == 13)	/* control m	*/
129472fcea8cSEd Schouten 		insert_line(TRUE);
129572fcea8cSEd Schouten 	else if (in == 14)	/* control n	*/
129672fcea8cSEd Schouten 		down();
129772fcea8cSEd Schouten 	else if (in == 15)	/* control o	*/
129872fcea8cSEd Schouten 	{
129972fcea8cSEd Schouten 		string = get_string(ascii_code_str, TRUE);
130096b676e9SEd Schouten 		if (*string != '\0')
130172fcea8cSEd Schouten 		{
130272fcea8cSEd Schouten 			in = atoi(string);
130372fcea8cSEd Schouten 			wmove(text_win, scr_vert, (scr_horz - horiz_offset));
130472fcea8cSEd Schouten 			insert(in);
130572fcea8cSEd Schouten 		}
130672fcea8cSEd Schouten 		free(string);
130772fcea8cSEd Schouten 	}
130872fcea8cSEd Schouten 	else if (in == 16)	/* control p	*/
130972fcea8cSEd Schouten 		up();
131072fcea8cSEd Schouten 	else if (in == 17)	/* control q	*/
131172fcea8cSEd Schouten 		;
131272fcea8cSEd Schouten 	else if (in == 18)	/* control r	*/
131372fcea8cSEd Schouten 		undel_word();
131472fcea8cSEd Schouten 	else if (in == 19)	/* control s	*/
131572fcea8cSEd Schouten 		;
131672fcea8cSEd Schouten 	else if (in == 20)	/* control t	*/
131772fcea8cSEd Schouten 		top();
131872fcea8cSEd Schouten 	else if (in == 21)	/* control u	*/
131972fcea8cSEd Schouten 		bottom();
132072fcea8cSEd Schouten 	else if (in == 22)	/* control v	*/
132172fcea8cSEd Schouten 		move_rel("d", max(5, (last_line - 5)));
132272fcea8cSEd Schouten 	else if (in == 23)	/* control w	*/
132372fcea8cSEd Schouten 		del_word();
132472fcea8cSEd Schouten 	else if (in == 24)	/* control x	*/
132572fcea8cSEd Schouten 		search(TRUE);
132672fcea8cSEd Schouten 	else if (in == 25)	/* control y	*/
132772fcea8cSEd Schouten 		search_prompt();
132872fcea8cSEd Schouten 	else if (in == 26)	/* control z	*/
132972fcea8cSEd Schouten 		adv_word();
133072fcea8cSEd Schouten 	else if (in == 27)	/* control [ (escape)	*/
133172fcea8cSEd Schouten 	{
133272fcea8cSEd Schouten 		menu_op(main_menu);
133372fcea8cSEd Schouten 	}
133472fcea8cSEd Schouten }
133572fcea8cSEd Schouten 
133672fcea8cSEd Schouten void
133772fcea8cSEd Schouten bottom()			/* go to bottom of file			*/
133872fcea8cSEd Schouten {
133972fcea8cSEd Schouten 	while (curr_line->next_line != NULL)
134096b676e9SEd Schouten 	{
134172fcea8cSEd Schouten 		curr_line = curr_line->next_line;
134296b676e9SEd Schouten 		absolute_lin++;
134396b676e9SEd Schouten 	}
134472fcea8cSEd Schouten 	point = curr_line->line;
134572fcea8cSEd Schouten 	if (horiz_offset)
134672fcea8cSEd Schouten 		horiz_offset = 0;
134772fcea8cSEd Schouten 	position = 1;
134872fcea8cSEd Schouten 	midscreen(last_line, point);
134972fcea8cSEd Schouten 	scr_pos = scr_horz;
135072fcea8cSEd Schouten }
135172fcea8cSEd Schouten 
135272fcea8cSEd Schouten void
135372fcea8cSEd Schouten top()				/* go to top of file			*/
135472fcea8cSEd Schouten {
135572fcea8cSEd Schouten 	while (curr_line->prev_line != NULL)
135696b676e9SEd Schouten 	{
135772fcea8cSEd Schouten 		curr_line = curr_line->prev_line;
135896b676e9SEd Schouten 		absolute_lin--;
135996b676e9SEd Schouten 	}
136072fcea8cSEd Schouten 	point = curr_line->line;
136172fcea8cSEd Schouten 	if (horiz_offset)
136272fcea8cSEd Schouten 		horiz_offset = 0;
136372fcea8cSEd Schouten 	position = 1;
136472fcea8cSEd Schouten 	midscreen(0, point);
136572fcea8cSEd Schouten 	scr_pos = scr_horz;
136672fcea8cSEd Schouten }
136772fcea8cSEd Schouten 
136872fcea8cSEd Schouten void
136972fcea8cSEd Schouten nextline()			/* move pointers to start of next line	*/
137072fcea8cSEd Schouten {
137172fcea8cSEd Schouten 	curr_line = curr_line->next_line;
137296b676e9SEd Schouten 	absolute_lin++;
137372fcea8cSEd Schouten 	point = curr_line->line;
137472fcea8cSEd Schouten 	position = 1;
137572fcea8cSEd Schouten 	if (scr_vert == last_line)
137672fcea8cSEd Schouten 	{
137772fcea8cSEd Schouten 		wmove(text_win, 0,0);
137872fcea8cSEd Schouten 		wdeleteln(text_win);
137972fcea8cSEd Schouten 		wmove(text_win, last_line,0);
138072fcea8cSEd Schouten 		wclrtobot(text_win);
138172fcea8cSEd Schouten 		draw_line(last_line,0,point,1,curr_line->line_length);
138272fcea8cSEd Schouten 	}
138372fcea8cSEd Schouten 	else
138472fcea8cSEd Schouten 		scr_vert++;
138572fcea8cSEd Schouten }
138672fcea8cSEd Schouten 
138772fcea8cSEd Schouten void
138872fcea8cSEd Schouten prevline()			/* move pointers to start of previous line*/
138972fcea8cSEd Schouten {
139072fcea8cSEd Schouten 	curr_line = curr_line->prev_line;
139196b676e9SEd Schouten 	absolute_lin--;
139272fcea8cSEd Schouten 	point = curr_line->line;
139372fcea8cSEd Schouten 	position = 1;
139472fcea8cSEd Schouten 	if (scr_vert == 0)
139572fcea8cSEd Schouten 	{
139672fcea8cSEd Schouten 		winsertln(text_win);
139772fcea8cSEd Schouten 		draw_line(0,0,point,1,curr_line->line_length);
139872fcea8cSEd Schouten 	}
139972fcea8cSEd Schouten 	else
140072fcea8cSEd Schouten 		scr_vert--;
140172fcea8cSEd Schouten 	while (position < curr_line->line_length)
140272fcea8cSEd Schouten 	{
140372fcea8cSEd Schouten 		position++;
140472fcea8cSEd Schouten 		point++;
140572fcea8cSEd Schouten 	}
140672fcea8cSEd Schouten }
140772fcea8cSEd Schouten 
140872fcea8cSEd Schouten void
140972fcea8cSEd Schouten left(disp)				/* move left one character	*/
141072fcea8cSEd Schouten int disp;
141172fcea8cSEd Schouten {
141272fcea8cSEd Schouten 	if (point != curr_line->line)	/* if not at begin of line	*/
141372fcea8cSEd Schouten 	{
141472fcea8cSEd Schouten 		if ((ee_chinese) && (position >= 2) && (*(point - 2) > 127))
141572fcea8cSEd Schouten 		{
141672fcea8cSEd Schouten 			point--;
141772fcea8cSEd Schouten 			position--;
141872fcea8cSEd Schouten 		}
141972fcea8cSEd Schouten 		point--;
142072fcea8cSEd Schouten 		position--;
142172fcea8cSEd Schouten 		scanline(point);
142272fcea8cSEd Schouten 		wmove(text_win, scr_vert, (scr_horz - horiz_offset));
142372fcea8cSEd Schouten 		scr_pos = scr_horz;
142472fcea8cSEd Schouten 	}
142572fcea8cSEd Schouten 	else if (curr_line->prev_line != NULL)
142672fcea8cSEd Schouten 	{
142772fcea8cSEd Schouten 		if (!disp)
142872fcea8cSEd Schouten 		{
142996b676e9SEd Schouten 			absolute_lin--;
143072fcea8cSEd Schouten 			curr_line = curr_line->prev_line;
143172fcea8cSEd Schouten 			point = curr_line->line + curr_line->line_length;
143272fcea8cSEd Schouten 			position = curr_line->line_length;
143372fcea8cSEd Schouten 			return;
143472fcea8cSEd Schouten 		}
143572fcea8cSEd Schouten 		position = 1;
143672fcea8cSEd Schouten 		prevline();
143772fcea8cSEd Schouten 		scanline(point);
143872fcea8cSEd Schouten 		scr_pos = scr_horz;
143972fcea8cSEd Schouten 		wmove(text_win, scr_vert, (scr_horz - horiz_offset));
144072fcea8cSEd Schouten 	}
144172fcea8cSEd Schouten }
144272fcea8cSEd Schouten 
144372fcea8cSEd Schouten void
144472fcea8cSEd Schouten right(disp)				/* move right one character	*/
144572fcea8cSEd Schouten int disp;
144672fcea8cSEd Schouten {
144772fcea8cSEd Schouten 	if (position < curr_line->line_length)
144872fcea8cSEd Schouten 	{
144972fcea8cSEd Schouten 		if ((ee_chinese) && (*point > 127) &&
145072fcea8cSEd Schouten 		    ((curr_line->line_length - position) >= 2))
145172fcea8cSEd Schouten 		{
145272fcea8cSEd Schouten 			point++;
145372fcea8cSEd Schouten 			position++;
145472fcea8cSEd Schouten 		}
145572fcea8cSEd Schouten 		point++;
145672fcea8cSEd Schouten 		position++;
145772fcea8cSEd Schouten 		scanline(point);
145872fcea8cSEd Schouten 		wmove(text_win, scr_vert, (scr_horz - horiz_offset));
145972fcea8cSEd Schouten 		scr_pos = scr_horz;
146072fcea8cSEd Schouten 	}
146172fcea8cSEd Schouten 	else if (curr_line->next_line != NULL)
146272fcea8cSEd Schouten 	{
146372fcea8cSEd Schouten 		if (!disp)
146472fcea8cSEd Schouten 		{
146596b676e9SEd Schouten 			absolute_lin++;
146672fcea8cSEd Schouten 			curr_line = curr_line->next_line;
146772fcea8cSEd Schouten 			point = curr_line->line;
146872fcea8cSEd Schouten 			position = 1;
146972fcea8cSEd Schouten 			return;
147072fcea8cSEd Schouten 		}
147172fcea8cSEd Schouten 		nextline();
147272fcea8cSEd Schouten 		scr_pos = scr_horz = 0;
147372fcea8cSEd Schouten 		if (horiz_offset)
147472fcea8cSEd Schouten 		{
147572fcea8cSEd Schouten 			horiz_offset = 0;
147672fcea8cSEd Schouten 			midscreen(scr_vert, point);
147772fcea8cSEd Schouten 		}
147872fcea8cSEd Schouten 		wmove(text_win, scr_vert, (scr_horz - horiz_offset));
147972fcea8cSEd Schouten 		position = 1;
148072fcea8cSEd Schouten 	}
148172fcea8cSEd Schouten }
148272fcea8cSEd Schouten 
148372fcea8cSEd Schouten void
148472fcea8cSEd Schouten find_pos()		/* move to the same column as on other line	*/
148572fcea8cSEd Schouten {
148672fcea8cSEd Schouten 	scr_horz = 0;
148772fcea8cSEd Schouten 	position = 1;
148872fcea8cSEd Schouten 	while ((scr_horz < scr_pos) && (position < curr_line->line_length))
148972fcea8cSEd Schouten 	{
149072fcea8cSEd Schouten 		if (*point == 9)
149172fcea8cSEd Schouten 			scr_horz += tabshift(scr_horz);
149272fcea8cSEd Schouten 		else if (*point < ' ')
149372fcea8cSEd Schouten 			scr_horz += 2;
149472fcea8cSEd Schouten 		else if ((ee_chinese) && (*point > 127) &&
149572fcea8cSEd Schouten 		    ((curr_line->line_length - position) >= 2))
149672fcea8cSEd Schouten 		{
149772fcea8cSEd Schouten 			scr_horz += 2;
149872fcea8cSEd Schouten 			point++;
149972fcea8cSEd Schouten 			position++;
150072fcea8cSEd Schouten 		}
150172fcea8cSEd Schouten 		else
150272fcea8cSEd Schouten 			scr_horz++;
150372fcea8cSEd Schouten 		position++;
150472fcea8cSEd Schouten 		point++;
150572fcea8cSEd Schouten 	}
150672fcea8cSEd Schouten 	if ((scr_horz - horiz_offset) > last_col)
150772fcea8cSEd Schouten 	{
150872fcea8cSEd Schouten 		horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
150972fcea8cSEd Schouten 		midscreen(scr_vert, point);
151072fcea8cSEd Schouten 	}
151172fcea8cSEd Schouten 	else if (scr_horz < horiz_offset)
151272fcea8cSEd Schouten 	{
151372fcea8cSEd Schouten 		horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
151472fcea8cSEd Schouten 		midscreen(scr_vert, point);
151572fcea8cSEd Schouten 	}
151672fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
151772fcea8cSEd Schouten }
151872fcea8cSEd Schouten 
151972fcea8cSEd Schouten void
152072fcea8cSEd Schouten up()					/* move up one line		*/
152172fcea8cSEd Schouten {
152272fcea8cSEd Schouten 	if (curr_line->prev_line != NULL)
152372fcea8cSEd Schouten 	{
152472fcea8cSEd Schouten 		prevline();
152572fcea8cSEd Schouten 		point = curr_line->line;
152672fcea8cSEd Schouten 		find_pos();
152772fcea8cSEd Schouten 	}
152872fcea8cSEd Schouten }
152972fcea8cSEd Schouten 
153072fcea8cSEd Schouten void
153172fcea8cSEd Schouten down()					/* move down one line		*/
153272fcea8cSEd Schouten {
153372fcea8cSEd Schouten 	if (curr_line->next_line != NULL)
153472fcea8cSEd Schouten 	{
153572fcea8cSEd Schouten 		nextline();
153672fcea8cSEd Schouten 		find_pos();
153772fcea8cSEd Schouten 	}
153872fcea8cSEd Schouten }
153972fcea8cSEd Schouten 
154072fcea8cSEd Schouten void
154172fcea8cSEd Schouten function_key()				/* process function key		*/
154272fcea8cSEd Schouten {
154372fcea8cSEd Schouten 	if (in == KEY_LEFT)
154472fcea8cSEd Schouten 		left(TRUE);
154572fcea8cSEd Schouten 	else if (in == KEY_RIGHT)
154672fcea8cSEd Schouten 		right(TRUE);
154772fcea8cSEd Schouten 	else if (in == KEY_HOME)
1548cfe04e82SEd Schouten 		bol();
1549cfe04e82SEd Schouten 	else if (in == KEY_END)
1550cfe04e82SEd Schouten 		eol();
155172fcea8cSEd Schouten 	else if (in == KEY_UP)
155272fcea8cSEd Schouten 		up();
155372fcea8cSEd Schouten 	else if (in == KEY_DOWN)
155472fcea8cSEd Schouten 		down();
155572fcea8cSEd Schouten 	else if (in == KEY_NPAGE)
155672fcea8cSEd Schouten 		move_rel("d", max( 5, (last_line - 5)));
155772fcea8cSEd Schouten 	else if (in == KEY_PPAGE)
155872fcea8cSEd Schouten 		move_rel("u", max(5, (last_line - 5)));
155972fcea8cSEd Schouten 	else if (in == KEY_DL)
156072fcea8cSEd Schouten 		del_line();
156172fcea8cSEd Schouten 	else if (in == KEY_DC)
156272fcea8cSEd Schouten 		del_char();
156372fcea8cSEd Schouten 	else if (in == KEY_BACKSPACE)
156472fcea8cSEd Schouten 		delete(TRUE);
156572fcea8cSEd Schouten 	else if (in == KEY_IL)
156672fcea8cSEd Schouten 	{		/* insert a line before current line	*/
156772fcea8cSEd Schouten 		insert_line(TRUE);
156872fcea8cSEd Schouten 		left(TRUE);
156972fcea8cSEd Schouten 	}
157072fcea8cSEd Schouten 	else if (in == KEY_F(1))
157172fcea8cSEd Schouten 		gold = !gold;
157272fcea8cSEd Schouten 	else if (in == KEY_F(2))
157372fcea8cSEd Schouten 	{
157472fcea8cSEd Schouten 		if (gold)
157572fcea8cSEd Schouten 		{
157672fcea8cSEd Schouten 			gold = FALSE;
157772fcea8cSEd Schouten 			undel_line();
157872fcea8cSEd Schouten 		}
157972fcea8cSEd Schouten 		else
158072fcea8cSEd Schouten 			undel_char();
158172fcea8cSEd Schouten 	}
158272fcea8cSEd Schouten 	else if (in == KEY_F(3))
158372fcea8cSEd Schouten 	{
158472fcea8cSEd Schouten 		if (gold)
158572fcea8cSEd Schouten 		{
158672fcea8cSEd Schouten 			gold = FALSE;
158772fcea8cSEd Schouten 			undel_word();
158872fcea8cSEd Schouten 		}
158972fcea8cSEd Schouten 		else
159072fcea8cSEd Schouten 			del_word();
159172fcea8cSEd Schouten 	}
159272fcea8cSEd Schouten 	else if (in == KEY_F(4))
159372fcea8cSEd Schouten 	{
159472fcea8cSEd Schouten 		if (gold)
159572fcea8cSEd Schouten 		{
159672fcea8cSEd Schouten 			gold = FALSE;
159772fcea8cSEd Schouten 			paint_info_win();
159872fcea8cSEd Schouten 			midscreen(scr_vert, point);
159972fcea8cSEd Schouten 		}
160072fcea8cSEd Schouten 		else
160172fcea8cSEd Schouten 			adv_word();
160272fcea8cSEd Schouten 	}
160372fcea8cSEd Schouten 	else if (in == KEY_F(5))
160472fcea8cSEd Schouten 	{
160572fcea8cSEd Schouten 		if (gold)
160672fcea8cSEd Schouten 		{
160772fcea8cSEd Schouten 			gold = FALSE;
160872fcea8cSEd Schouten 			search_prompt();
160972fcea8cSEd Schouten 		}
161072fcea8cSEd Schouten 		else
161172fcea8cSEd Schouten 			search(TRUE);
161272fcea8cSEd Schouten 	}
161372fcea8cSEd Schouten 	else if (in == KEY_F(6))
161472fcea8cSEd Schouten 	{
161572fcea8cSEd Schouten 		if (gold)
161672fcea8cSEd Schouten 		{
161772fcea8cSEd Schouten 			gold = FALSE;
161872fcea8cSEd Schouten 			bottom();
161972fcea8cSEd Schouten 		}
162072fcea8cSEd Schouten 		else
162172fcea8cSEd Schouten 			top();
162272fcea8cSEd Schouten 	}
162372fcea8cSEd Schouten 	else if (in == KEY_F(7))
162472fcea8cSEd Schouten 	{
162572fcea8cSEd Schouten 		if (gold)
162672fcea8cSEd Schouten 		{
162772fcea8cSEd Schouten 			gold = FALSE;
162872fcea8cSEd Schouten 			eol();
162972fcea8cSEd Schouten 		}
163072fcea8cSEd Schouten 		else
163172fcea8cSEd Schouten 			bol();
163272fcea8cSEd Schouten 	}
163372fcea8cSEd Schouten 	else if (in == KEY_F(8))
163472fcea8cSEd Schouten 	{
163572fcea8cSEd Schouten 		if (gold)
163672fcea8cSEd Schouten 		{
163772fcea8cSEd Schouten 			gold = FALSE;
163872fcea8cSEd Schouten 			command_prompt();
163972fcea8cSEd Schouten 		}
164072fcea8cSEd Schouten 		else
164172fcea8cSEd Schouten 			adv_line();
164272fcea8cSEd Schouten 	}
164372fcea8cSEd Schouten }
164472fcea8cSEd Schouten 
164572fcea8cSEd Schouten void
164672fcea8cSEd Schouten print_buffer()
164772fcea8cSEd Schouten {
164872fcea8cSEd Schouten 	char buffer[256];
164972fcea8cSEd Schouten 
165072fcea8cSEd Schouten 	sprintf(buffer, ">!%s", print_command);
165172fcea8cSEd Schouten 	wmove(com_win, 0, 0);
165272fcea8cSEd Schouten 	wclrtoeol(com_win);
165372fcea8cSEd Schouten 	wprintw(com_win, printer_msg_str, print_command);
165472fcea8cSEd Schouten 	wrefresh(com_win);
165572fcea8cSEd Schouten 	command(buffer);
165672fcea8cSEd Schouten }
165772fcea8cSEd Schouten 
165872fcea8cSEd Schouten void
165972fcea8cSEd Schouten command_prompt()
166072fcea8cSEd Schouten {
166172fcea8cSEd Schouten 	char *cmd_str;
166272fcea8cSEd Schouten 	int result;
166372fcea8cSEd Schouten 
166472fcea8cSEd Schouten 	info_type = COMMANDS;
166572fcea8cSEd Schouten 	paint_info_win();
166672fcea8cSEd Schouten 	cmd_str = get_string(command_str, TRUE);
166772fcea8cSEd Schouten 	if ((result = unique_test(cmd_str, commands)) != 1)
166872fcea8cSEd Schouten 	{
166972fcea8cSEd Schouten 		werase(com_win);
167072fcea8cSEd Schouten 		wmove(com_win, 0, 0);
167172fcea8cSEd Schouten 		if (result == 0)
167272fcea8cSEd Schouten 			wprintw(com_win, unkn_cmd_str, cmd_str);
167372fcea8cSEd Schouten 		else
167472fcea8cSEd Schouten 			wprintw(com_win, non_unique_cmd_msg);
167572fcea8cSEd Schouten 
167672fcea8cSEd Schouten 		wrefresh(com_win);
167772fcea8cSEd Schouten 
167872fcea8cSEd Schouten 		info_type = CONTROL_KEYS;
167972fcea8cSEd Schouten 		paint_info_win();
168072fcea8cSEd Schouten 
168172fcea8cSEd Schouten 		if (cmd_str != NULL)
168272fcea8cSEd Schouten 			free(cmd_str);
168372fcea8cSEd Schouten 		return;
168472fcea8cSEd Schouten 	}
168572fcea8cSEd Schouten 	command(cmd_str);
168672fcea8cSEd Schouten 	wrefresh(com_win);
168772fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
168872fcea8cSEd Schouten 	info_type = CONTROL_KEYS;
168972fcea8cSEd Schouten 	paint_info_win();
169072fcea8cSEd Schouten 	if (cmd_str != NULL)
169172fcea8cSEd Schouten 		free(cmd_str);
169272fcea8cSEd Schouten }
169372fcea8cSEd Schouten 
169472fcea8cSEd Schouten void
169572fcea8cSEd Schouten command(cmd_str1)		/* process commands from keyboard	*/
169672fcea8cSEd Schouten char *cmd_str1;
169772fcea8cSEd Schouten {
169872fcea8cSEd Schouten 	char *cmd_str2 = NULL;
169972fcea8cSEd Schouten 	char *cmd_str = cmd_str1;
170072fcea8cSEd Schouten 
170172fcea8cSEd Schouten 	clear_com_win = TRUE;
170272fcea8cSEd Schouten 	if (compare(cmd_str, HELP, FALSE))
170372fcea8cSEd Schouten 		help();
170472fcea8cSEd Schouten 	else if (compare(cmd_str, WRITE, FALSE))
170572fcea8cSEd Schouten 	{
170672fcea8cSEd Schouten 		if (restrict_mode())
170772fcea8cSEd Schouten 		{
170872fcea8cSEd Schouten 			return;
170972fcea8cSEd Schouten 		}
171072fcea8cSEd Schouten 		cmd_str = next_word(cmd_str);
171196b676e9SEd Schouten 		if (*cmd_str == '\0')
171272fcea8cSEd Schouten 		{
171372fcea8cSEd Schouten 			cmd_str = cmd_str2 = get_string(file_write_prompt_str, TRUE);
171472fcea8cSEd Schouten 		}
171572fcea8cSEd Schouten 		tmp_file = resolve_name(cmd_str);
1716cfe04e82SEd Schouten 		write_file(tmp_file, 1);
171772fcea8cSEd Schouten 		if (tmp_file != cmd_str)
171872fcea8cSEd Schouten 			free(tmp_file);
171972fcea8cSEd Schouten 	}
172072fcea8cSEd Schouten 	else if (compare(cmd_str, READ, FALSE))
172172fcea8cSEd Schouten 	{
172272fcea8cSEd Schouten 		if (restrict_mode())
172372fcea8cSEd Schouten 		{
172472fcea8cSEd Schouten 			return;
172572fcea8cSEd Schouten 		}
172672fcea8cSEd Schouten 		cmd_str = next_word(cmd_str);
172796b676e9SEd Schouten 		if (*cmd_str == '\0')
172872fcea8cSEd Schouten 		{
172972fcea8cSEd Schouten 			cmd_str = cmd_str2 = get_string(file_read_prompt_str, TRUE);
173072fcea8cSEd Schouten 		}
173172fcea8cSEd Schouten 		tmp_file = cmd_str;
173272fcea8cSEd Schouten 		recv_file = TRUE;
173372fcea8cSEd Schouten 		tmp_file = resolve_name(cmd_str);
173472fcea8cSEd Schouten 		check_fp();
173572fcea8cSEd Schouten 		if (tmp_file != cmd_str)
173672fcea8cSEd Schouten 			free(tmp_file);
173772fcea8cSEd Schouten 	}
173872fcea8cSEd Schouten 	else if (compare(cmd_str, LINE, FALSE))
173972fcea8cSEd Schouten 	{
174072fcea8cSEd Schouten 		wmove(com_win, 0, 0);
174172fcea8cSEd Schouten 		wclrtoeol(com_win);
174272fcea8cSEd Schouten 		wprintw(com_win, line_num_str, curr_line->line_number);
174372fcea8cSEd Schouten 		wprintw(com_win, line_len_str, curr_line->line_length);
174472fcea8cSEd Schouten 	}
174572fcea8cSEd Schouten 	else if (compare(cmd_str, FILE_str, FALSE))
174672fcea8cSEd Schouten 	{
174772fcea8cSEd Schouten 		wmove(com_win, 0, 0);
174872fcea8cSEd Schouten 		wclrtoeol(com_win);
174972fcea8cSEd Schouten 		if (in_file_name == NULL)
175072fcea8cSEd Schouten 			wprintw(com_win, no_file_string);
175172fcea8cSEd Schouten 		else
175272fcea8cSEd Schouten 			wprintw(com_win, current_file_str, in_file_name);
175372fcea8cSEd Schouten 	}
175472fcea8cSEd Schouten 	else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
175572fcea8cSEd Schouten 		goto_line(cmd_str);
175672fcea8cSEd Schouten 	else if (compare(cmd_str, CHARACTER, FALSE))
175772fcea8cSEd Schouten 	{
175872fcea8cSEd Schouten 		wmove(com_win, 0, 0);
175972fcea8cSEd Schouten 		wclrtoeol(com_win);
176072fcea8cSEd Schouten 		wprintw(com_win, char_str, *point);
176172fcea8cSEd Schouten 	}
176272fcea8cSEd Schouten 	else if (compare(cmd_str, REDRAW, FALSE))
176372fcea8cSEd Schouten 		redraw();
176472fcea8cSEd Schouten 	else if (compare(cmd_str, RESEQUENCE, FALSE))
176572fcea8cSEd Schouten 	{
176672fcea8cSEd Schouten 		tmp_line = first_line->next_line;
176772fcea8cSEd Schouten 		while (tmp_line != NULL)
176872fcea8cSEd Schouten 		{
176972fcea8cSEd Schouten 		tmp_line->line_number = tmp_line->prev_line->line_number + 1;
177072fcea8cSEd Schouten 			tmp_line = tmp_line->next_line;
177172fcea8cSEd Schouten 		}
177272fcea8cSEd Schouten 	}
177372fcea8cSEd Schouten 	else if (compare(cmd_str, AUTHOR, FALSE))
177472fcea8cSEd Schouten 	{
177572fcea8cSEd Schouten 		wmove(com_win, 0, 0);
177672fcea8cSEd Schouten 		wclrtoeol(com_win);
177772fcea8cSEd Schouten 		wprintw(com_win, "written by Hugh Mahon");
177872fcea8cSEd Schouten 	}
177972fcea8cSEd Schouten 	else if (compare(cmd_str, VERSION, FALSE))
178072fcea8cSEd Schouten 	{
178172fcea8cSEd Schouten 		wmove(com_win, 0, 0);
178272fcea8cSEd Schouten 		wclrtoeol(com_win);
178372fcea8cSEd Schouten 		wprintw(com_win, "%s", version);
178472fcea8cSEd Schouten 	}
178572fcea8cSEd Schouten 	else if (compare(cmd_str, CASE, FALSE))
178672fcea8cSEd Schouten 		case_sen = TRUE;
178772fcea8cSEd Schouten 	else if (compare(cmd_str, NOCASE, FALSE))
178872fcea8cSEd Schouten 		case_sen = FALSE;
178972fcea8cSEd Schouten 	else if (compare(cmd_str, EXPAND, FALSE))
179072fcea8cSEd Schouten 		expand_tabs = TRUE;
179172fcea8cSEd Schouten 	else if (compare(cmd_str, NOEXPAND, FALSE))
179272fcea8cSEd Schouten 		expand_tabs = FALSE;
179372fcea8cSEd Schouten 	else if (compare(cmd_str, Exit_string, FALSE))
179472fcea8cSEd Schouten 		finish();
179572fcea8cSEd Schouten 	else if (compare(cmd_str, chinese_cmd, FALSE))
179672fcea8cSEd Schouten 	{
179772fcea8cSEd Schouten 		ee_chinese = TRUE;
179872fcea8cSEd Schouten #ifdef NCURSE
179972fcea8cSEd Schouten 		nc_setattrib(A_NC_BIG5);
180072fcea8cSEd Schouten #endif /* NCURSE */
180172fcea8cSEd Schouten 	}
180272fcea8cSEd Schouten 	else if (compare(cmd_str, nochinese_cmd, FALSE))
180372fcea8cSEd Schouten 	{
180472fcea8cSEd Schouten 		ee_chinese = FALSE;
180572fcea8cSEd Schouten #ifdef NCURSE
180672fcea8cSEd Schouten 		nc_clearattrib(A_NC_BIG5);
180772fcea8cSEd Schouten #endif /* NCURSE */
180872fcea8cSEd Schouten 	}
180972fcea8cSEd Schouten 	else if (compare(cmd_str, QUIT_string, FALSE))
181072fcea8cSEd Schouten 		quit(0);
181172fcea8cSEd Schouten 	else if (*cmd_str == '!')
181272fcea8cSEd Schouten 	{
181372fcea8cSEd Schouten 		cmd_str++;
181472fcea8cSEd Schouten 		if ((*cmd_str == ' ') || (*cmd_str == 9))
181572fcea8cSEd Schouten 			cmd_str = next_word(cmd_str);
181672fcea8cSEd Schouten 		sh_command(cmd_str);
181772fcea8cSEd Schouten 	}
181872fcea8cSEd Schouten 	else if ((*cmd_str == '<') && (!in_pipe))
181972fcea8cSEd Schouten 	{
182072fcea8cSEd Schouten 		in_pipe = TRUE;
182172fcea8cSEd Schouten 		shell_fork = FALSE;
182272fcea8cSEd Schouten 		cmd_str++;
182372fcea8cSEd Schouten 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
182472fcea8cSEd Schouten 			cmd_str = next_word(cmd_str);
182572fcea8cSEd Schouten 		command(cmd_str);
182672fcea8cSEd Schouten 		in_pipe = FALSE;
182772fcea8cSEd Schouten 		shell_fork = TRUE;
182872fcea8cSEd Schouten 	}
182972fcea8cSEd Schouten 	else if ((*cmd_str == '>') && (!out_pipe))
183072fcea8cSEd Schouten 	{
183172fcea8cSEd Schouten 		out_pipe = TRUE;
183272fcea8cSEd Schouten 		cmd_str++;
183372fcea8cSEd Schouten 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
183472fcea8cSEd Schouten 			cmd_str = next_word(cmd_str);
183572fcea8cSEd Schouten 		command(cmd_str);
183672fcea8cSEd Schouten 		out_pipe = FALSE;
183772fcea8cSEd Schouten 	}
183872fcea8cSEd Schouten 	else
183972fcea8cSEd Schouten 	{
184072fcea8cSEd Schouten 		wmove(com_win, 0, 0);
184172fcea8cSEd Schouten 		wclrtoeol(com_win);
184272fcea8cSEd Schouten 		wprintw(com_win, unkn_cmd_str, cmd_str);
184372fcea8cSEd Schouten 	}
184472fcea8cSEd Schouten 	if (cmd_str2 != NULL)
184572fcea8cSEd Schouten 		free(cmd_str2);
184672fcea8cSEd Schouten }
184772fcea8cSEd Schouten 
184872fcea8cSEd Schouten int
184972fcea8cSEd Schouten scan(line, offset, column)	/* determine horizontal position for get_string	*/
185072fcea8cSEd Schouten char *line;
185172fcea8cSEd Schouten int offset;
185272fcea8cSEd Schouten int column;
185372fcea8cSEd Schouten {
185472fcea8cSEd Schouten 	char *stemp;
185572fcea8cSEd Schouten 	int i;
185672fcea8cSEd Schouten 	int j;
185772fcea8cSEd Schouten 
185872fcea8cSEd Schouten 	stemp = line;
185972fcea8cSEd Schouten 	i = 0;
186072fcea8cSEd Schouten 	j = column;
186172fcea8cSEd Schouten 	while (i < offset)
186272fcea8cSEd Schouten 	{
186372fcea8cSEd Schouten 		i++;
186472fcea8cSEd Schouten 		j += len_char(*stemp, j);
186572fcea8cSEd Schouten 		stemp++;
186672fcea8cSEd Schouten 	}
186772fcea8cSEd Schouten 	return(j);
186872fcea8cSEd Schouten }
186972fcea8cSEd Schouten 
187072fcea8cSEd Schouten char *
187172fcea8cSEd Schouten get_string(prompt, advance)	/* read string from input on command line */
187272fcea8cSEd Schouten char *prompt;		/* string containing user prompt message	*/
187372fcea8cSEd Schouten int advance;		/* if true, skip leading spaces and tabs	*/
187472fcea8cSEd Schouten {
187572fcea8cSEd Schouten 	char *string;
187672fcea8cSEd Schouten 	char *tmp_string;
187772fcea8cSEd Schouten 	char *nam_str;
187872fcea8cSEd Schouten 	char *g_point;
187972fcea8cSEd Schouten 	int tmp_int;
188072fcea8cSEd Schouten 	int g_horz, g_position, g_pos;
188172fcea8cSEd Schouten 	int esc_flag;
188272fcea8cSEd Schouten 
188372fcea8cSEd Schouten 	g_point = tmp_string = malloc(512);
188472fcea8cSEd Schouten 	wmove(com_win,0,0);
188572fcea8cSEd Schouten 	wclrtoeol(com_win);
188672fcea8cSEd Schouten 	waddstr(com_win, prompt);
188772fcea8cSEd Schouten 	wrefresh(com_win);
188872fcea8cSEd Schouten 	nam_str = tmp_string;
188972fcea8cSEd Schouten 	clear_com_win = TRUE;
189072fcea8cSEd Schouten 	g_horz = g_position = scan(prompt, strlen(prompt), 0);
189172fcea8cSEd Schouten 	g_pos = 0;
189272fcea8cSEd Schouten 	do
189372fcea8cSEd Schouten 	{
189472fcea8cSEd Schouten 		esc_flag = FALSE;
189572fcea8cSEd Schouten 		in = wgetch(com_win);
189672fcea8cSEd Schouten 		if (in == -1)
189796b676e9SEd Schouten 			exit(0);
189872fcea8cSEd Schouten 		if (((in == 8) || (in == 127) || (in == KEY_BACKSPACE)) && (g_pos > 0))
189972fcea8cSEd Schouten 		{
190072fcea8cSEd Schouten 			tmp_int = g_horz;
190172fcea8cSEd Schouten 			g_pos--;
190272fcea8cSEd Schouten 			g_horz = scan(g_point, g_pos, g_position);
190372fcea8cSEd Schouten 			tmp_int = tmp_int - g_horz;
190472fcea8cSEd Schouten 			for (; 0 < tmp_int; tmp_int--)
190572fcea8cSEd Schouten 			{
190672fcea8cSEd Schouten 				if ((g_horz+tmp_int) < (last_col - 1))
190772fcea8cSEd Schouten 				{
190872fcea8cSEd Schouten 					waddch(com_win, '\010');
190972fcea8cSEd Schouten 					waddch(com_win, ' ');
191072fcea8cSEd Schouten 					waddch(com_win, '\010');
191172fcea8cSEd Schouten 				}
191272fcea8cSEd Schouten 			}
191372fcea8cSEd Schouten 			nam_str--;
191472fcea8cSEd Schouten 		}
191572fcea8cSEd Schouten 		else if ((in != 8) && (in != 127) && (in != '\n') && (in != '\r') && (in < 256))
191672fcea8cSEd Schouten 		{
191772fcea8cSEd Schouten 			if (in == '\026')	/* control-v, accept next character verbatim	*/
191872fcea8cSEd Schouten 			{			/* allows entry of ^m, ^j, and ^h	*/
191972fcea8cSEd Schouten 				esc_flag = TRUE;
192072fcea8cSEd Schouten 				in = wgetch(com_win);
192172fcea8cSEd Schouten 				if (in == -1)
192296b676e9SEd Schouten 					exit(0);
192372fcea8cSEd Schouten 			}
192472fcea8cSEd Schouten 			*nam_str = in;
192572fcea8cSEd Schouten 			g_pos++;
192672fcea8cSEd Schouten 			if (((in < ' ') || (in > 126)) && (g_horz < (last_col - 1)))
192772fcea8cSEd Schouten 				g_horz += out_char(com_win, in, g_horz);
192872fcea8cSEd Schouten 			else
192972fcea8cSEd Schouten 			{
193072fcea8cSEd Schouten 				g_horz++;
193172fcea8cSEd Schouten 				if (g_horz < (last_col - 1))
193272fcea8cSEd Schouten 					waddch(com_win, in);
193372fcea8cSEd Schouten 			}
193472fcea8cSEd Schouten 			nam_str++;
193572fcea8cSEd Schouten 		}
193672fcea8cSEd Schouten 		wrefresh(com_win);
193772fcea8cSEd Schouten 		if (esc_flag)
193896b676e9SEd Schouten 			in = '\0';
193972fcea8cSEd Schouten 	} while ((in != '\n') && (in != '\r'));
194096b676e9SEd Schouten 	*nam_str = '\0';
194172fcea8cSEd Schouten 	nam_str = tmp_string;
194272fcea8cSEd Schouten 	if (((*nam_str == ' ') || (*nam_str == 9)) && (advance))
194372fcea8cSEd Schouten 		nam_str = next_word(nam_str);
194472fcea8cSEd Schouten 	string = malloc(strlen(nam_str) + 1);
194572fcea8cSEd Schouten 	strcpy(string, nam_str);
194672fcea8cSEd Schouten 	free(tmp_string);
194772fcea8cSEd Schouten 	wrefresh(com_win);
194872fcea8cSEd Schouten 	return(string);
194972fcea8cSEd Schouten }
195072fcea8cSEd Schouten 
195172fcea8cSEd Schouten int
195272fcea8cSEd Schouten compare(string1, string2, sensitive)	/* compare two strings	*/
195372fcea8cSEd Schouten char *string1;
195472fcea8cSEd Schouten char *string2;
195572fcea8cSEd Schouten int sensitive;
195672fcea8cSEd Schouten {
195772fcea8cSEd Schouten 	char *strng1;
195872fcea8cSEd Schouten 	char *strng2;
195972fcea8cSEd Schouten 	int tmp;
196072fcea8cSEd Schouten 	int equal;
196172fcea8cSEd Schouten 
196272fcea8cSEd Schouten 	strng1 = string1;
196372fcea8cSEd Schouten 	strng2 = string2;
196472fcea8cSEd Schouten 	tmp = 0;
196596b676e9SEd Schouten 	if ((strng1 == NULL) || (strng2 == NULL) || (*strng1 == '\0') || (*strng2 == '\0'))
196672fcea8cSEd Schouten 		return(FALSE);
196772fcea8cSEd Schouten 	equal = TRUE;
196872fcea8cSEd Schouten 	while (equal)
196972fcea8cSEd Schouten 	{
197072fcea8cSEd Schouten 		if (sensitive)
197172fcea8cSEd Schouten 		{
197272fcea8cSEd Schouten 			if (*strng1 != *strng2)
197372fcea8cSEd Schouten 				equal = FALSE;
197472fcea8cSEd Schouten 		}
197572fcea8cSEd Schouten 		else
197672fcea8cSEd Schouten 		{
197772fcea8cSEd Schouten 			if (toupper(*strng1) != toupper(*strng2))
197872fcea8cSEd Schouten 				equal = FALSE;
197972fcea8cSEd Schouten 		}
198072fcea8cSEd Schouten 		strng1++;
198172fcea8cSEd Schouten 		strng2++;
198296b676e9SEd Schouten 		if ((*strng1 == '\0') || (*strng2 == '\0') || (*strng1 == ' ') || (*strng2 == ' '))
198372fcea8cSEd Schouten 			break;
198472fcea8cSEd Schouten 		tmp++;
198572fcea8cSEd Schouten 	}
198672fcea8cSEd Schouten 	return(equal);
198772fcea8cSEd Schouten }
198872fcea8cSEd Schouten 
198972fcea8cSEd Schouten void
199072fcea8cSEd Schouten goto_line(cmd_str)
199172fcea8cSEd Schouten char *cmd_str;
199272fcea8cSEd Schouten {
199372fcea8cSEd Schouten 	int number;
199472fcea8cSEd Schouten 	int i;
199572fcea8cSEd Schouten 	char *ptr;
1996cfe04e82SEd Schouten 	char *direction = NULL;
199772fcea8cSEd Schouten 	struct text *t_line;
199872fcea8cSEd Schouten 
199972fcea8cSEd Schouten 	ptr = cmd_str;
200072fcea8cSEd Schouten 	i= 0;
200172fcea8cSEd Schouten 	while ((*ptr >='0') && (*ptr <= '9'))
200272fcea8cSEd Schouten 	{
200372fcea8cSEd Schouten 		i= i * 10 + (*ptr - '0');
200472fcea8cSEd Schouten 		ptr++;
200572fcea8cSEd Schouten 	}
200672fcea8cSEd Schouten 	number = i;
200772fcea8cSEd Schouten 	i = 0;
200872fcea8cSEd Schouten 	t_line = curr_line;
200972fcea8cSEd Schouten 	while ((t_line->line_number > number) && (t_line->prev_line != NULL))
201072fcea8cSEd Schouten 	{
201172fcea8cSEd Schouten 		i++;
201272fcea8cSEd Schouten 		t_line = t_line->prev_line;
201372fcea8cSEd Schouten 		direction = "u";
201472fcea8cSEd Schouten 	}
201572fcea8cSEd Schouten 	while ((t_line->line_number < number) && (t_line->next_line != NULL))
201672fcea8cSEd Schouten 	{
201772fcea8cSEd Schouten 		i++;
201872fcea8cSEd Schouten 		direction = "d";
201972fcea8cSEd Schouten 		t_line = t_line->next_line;
202072fcea8cSEd Schouten 	}
202172fcea8cSEd Schouten 	if ((i < 30) && (i > 0))
202272fcea8cSEd Schouten 	{
202372fcea8cSEd Schouten 		move_rel(direction, i);
202472fcea8cSEd Schouten 	}
202572fcea8cSEd Schouten 	else
202672fcea8cSEd Schouten 	{
202796b676e9SEd Schouten 		if (!strcmp(direction, "d"))
202896b676e9SEd Schouten 		{
202996b676e9SEd Schouten 			absolute_lin += i;
203096b676e9SEd Schouten 		}
203196b676e9SEd Schouten 		else
203296b676e9SEd Schouten 		{
203396b676e9SEd Schouten 			absolute_lin -= i;
203496b676e9SEd Schouten 		}
203572fcea8cSEd Schouten 		curr_line = t_line;
203672fcea8cSEd Schouten 		point = curr_line->line;
203772fcea8cSEd Schouten 		position = 1;
203872fcea8cSEd Schouten 		midscreen((last_line / 2), point);
203972fcea8cSEd Schouten 		scr_pos = scr_horz;
204072fcea8cSEd Schouten 	}
204172fcea8cSEd Schouten 	wmove(com_win, 0, 0);
204272fcea8cSEd Schouten 	wclrtoeol(com_win);
204372fcea8cSEd Schouten 	wprintw(com_win, line_num_str, curr_line->line_number);
204472fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
204572fcea8cSEd Schouten }
204672fcea8cSEd Schouten 
204772fcea8cSEd Schouten void
204872fcea8cSEd Schouten midscreen(line, pnt)	/* put current line in middle of screen	*/
204972fcea8cSEd Schouten int line;
205072fcea8cSEd Schouten unsigned char *pnt;
205172fcea8cSEd Schouten {
205272fcea8cSEd Schouten 	struct text *mid_line;
205372fcea8cSEd Schouten 	int i;
205472fcea8cSEd Schouten 
205572fcea8cSEd Schouten 	line = min(line, last_line);
205672fcea8cSEd Schouten 	mid_line = curr_line;
205772fcea8cSEd Schouten 	for (i = 0; ((i < line) && (curr_line->prev_line != NULL)); i++)
205872fcea8cSEd Schouten 		curr_line = curr_line->prev_line;
205972fcea8cSEd Schouten 	scr_vert = scr_horz = 0;
206072fcea8cSEd Schouten 	wmove(text_win, 0, 0);
206172fcea8cSEd Schouten 	draw_screen();
206272fcea8cSEd Schouten 	scr_vert = i;
206372fcea8cSEd Schouten 	curr_line = mid_line;
206472fcea8cSEd Schouten 	scanline(pnt);
206572fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
206672fcea8cSEd Schouten }
206772fcea8cSEd Schouten 
206872fcea8cSEd Schouten void
206972fcea8cSEd Schouten get_options(numargs, arguments)	/* get arguments from command line	*/
207072fcea8cSEd Schouten int numargs;
207172fcea8cSEd Schouten char *arguments[];
207272fcea8cSEd Schouten {
207372fcea8cSEd Schouten 	char *buff;
207472fcea8cSEd Schouten 	int count;
2075cfe04e82SEd Schouten 	struct files *temp_names = NULL;
207672fcea8cSEd Schouten 	char *name;
207772fcea8cSEd Schouten 	char *ptr;
2078cfe04e82SEd Schouten 	int no_more_opts = FALSE;
207972fcea8cSEd Schouten 
208072fcea8cSEd Schouten 	/*
208172fcea8cSEd Schouten 	 |	see if editor was invoked as 'ree' (restricted mode)
208272fcea8cSEd Schouten 	 */
208372fcea8cSEd Schouten 
208472fcea8cSEd Schouten 	if (!(name = strrchr(arguments[0], '/')))
208572fcea8cSEd Schouten 		name = arguments[0];
208672fcea8cSEd Schouten 	else
208772fcea8cSEd Schouten 		name++;
208872fcea8cSEd Schouten 	if (!strcmp(name, "ree"))
208972fcea8cSEd Schouten 		restricted = TRUE;
209072fcea8cSEd Schouten 
209172fcea8cSEd Schouten 	top_of_stack = NULL;
209272fcea8cSEd Schouten 	input_file = FALSE;
209372fcea8cSEd Schouten 	recv_file = FALSE;
209472fcea8cSEd Schouten 	count = 1;
2095cfe04e82SEd Schouten 	while ((count < numargs)&& (!no_more_opts))
209672fcea8cSEd Schouten 	{
209772fcea8cSEd Schouten 		buff = arguments[count];
209872fcea8cSEd Schouten 		if (!strcmp("-i", buff))
209972fcea8cSEd Schouten 		{
210072fcea8cSEd Schouten 			info_window = FALSE;
210172fcea8cSEd Schouten 		}
210272fcea8cSEd Schouten 		else if (!strcmp("-e", buff))
210372fcea8cSEd Schouten 		{
210472fcea8cSEd Schouten 			expand_tabs = FALSE;
210572fcea8cSEd Schouten 		}
210672fcea8cSEd Schouten 		else if (!strcmp("-h", buff))
210772fcea8cSEd Schouten 		{
210872fcea8cSEd Schouten 			nohighlight = TRUE;
210972fcea8cSEd Schouten 		}
211072fcea8cSEd Schouten 		else if (!strcmp("-?", buff))
211172fcea8cSEd Schouten 		{
211272fcea8cSEd Schouten 			fprintf(stderr, usage0, arguments[0]);
211372fcea8cSEd Schouten 			fprintf(stderr, usage1);
211472fcea8cSEd Schouten 			fprintf(stderr, usage2);
211572fcea8cSEd Schouten 			fprintf(stderr, usage3);
211672fcea8cSEd Schouten 			fprintf(stderr, usage4);
211772fcea8cSEd Schouten 			exit(1);
211872fcea8cSEd Schouten 		}
211996b676e9SEd Schouten 		else if ((*buff == '+') && (start_at_line == NULL))
212072fcea8cSEd Schouten 		{
212172fcea8cSEd Schouten 			buff++;
212272fcea8cSEd Schouten 			start_at_line = buff;
212372fcea8cSEd Schouten 		}
2124cfe04e82SEd Schouten 		else if (!(strcmp("--", buff)))
2125cfe04e82SEd Schouten 			no_more_opts = TRUE;
212672fcea8cSEd Schouten 		else
212772fcea8cSEd Schouten 		{
2128cfe04e82SEd Schouten 			count--;
2129cfe04e82SEd Schouten 			no_more_opts = TRUE;
2130cfe04e82SEd Schouten 		}
2131cfe04e82SEd Schouten 		count++;
2132cfe04e82SEd Schouten 	}
2133cfe04e82SEd Schouten 	while (count < numargs)
2134cfe04e82SEd Schouten 	{
2135cfe04e82SEd Schouten 		buff = arguments[count];
213672fcea8cSEd Schouten 		if (top_of_stack == NULL)
213772fcea8cSEd Schouten 		{
213872fcea8cSEd Schouten 			temp_names = top_of_stack = name_alloc();
213972fcea8cSEd Schouten 		}
214072fcea8cSEd Schouten 		else
214172fcea8cSEd Schouten 		{
214272fcea8cSEd Schouten 			temp_names->next_name = name_alloc();
214372fcea8cSEd Schouten 			temp_names = temp_names->next_name;
214472fcea8cSEd Schouten 		}
214572fcea8cSEd Schouten 		ptr = temp_names->name = malloc(strlen(buff) + 1);
214696b676e9SEd Schouten 		while (*buff != '\0')
214772fcea8cSEd Schouten 		{
214872fcea8cSEd Schouten 			*ptr = *buff;
214972fcea8cSEd Schouten 			buff++;
215072fcea8cSEd Schouten 			ptr++;
215172fcea8cSEd Schouten 		}
215296b676e9SEd Schouten 		*ptr = '\0';
215372fcea8cSEd Schouten 		temp_names->next_name = NULL;
215472fcea8cSEd Schouten 		input_file = TRUE;
215572fcea8cSEd Schouten 		recv_file = TRUE;
215672fcea8cSEd Schouten 		count++;
215772fcea8cSEd Schouten 	}
215872fcea8cSEd Schouten }
215972fcea8cSEd Schouten 
216072fcea8cSEd Schouten void
216172fcea8cSEd Schouten check_fp()		/* open or close files according to flags */
216272fcea8cSEd Schouten {
216372fcea8cSEd Schouten 	int line_num;
216472fcea8cSEd Schouten 	int temp;
216572fcea8cSEd Schouten 	struct stat buf;
216672fcea8cSEd Schouten 
216772fcea8cSEd Schouten 	clear_com_win = TRUE;
216872fcea8cSEd Schouten 	tmp_vert = scr_vert;
216972fcea8cSEd Schouten 	tmp_horz = scr_horz;
217072fcea8cSEd Schouten 	tmp_line = curr_line;
217172fcea8cSEd Schouten 	if (input_file)
217272fcea8cSEd Schouten 	{
217372fcea8cSEd Schouten 		in_file_name = tmp_file = top_of_stack->name;
217472fcea8cSEd Schouten 		top_of_stack = top_of_stack->next_name;
217572fcea8cSEd Schouten 	}
217672fcea8cSEd Schouten 	temp = stat(tmp_file, &buf);
217772fcea8cSEd Schouten 	buf.st_mode &= ~07777;
217872fcea8cSEd Schouten 	if ((temp != -1) && (buf.st_mode != 0100000) && (buf.st_mode != 0))
217972fcea8cSEd Schouten 	{
218072fcea8cSEd Schouten 		wprintw(com_win, file_is_dir_msg, tmp_file);
218172fcea8cSEd Schouten 		wrefresh(com_win);
218272fcea8cSEd Schouten 		if (input_file)
218372fcea8cSEd Schouten 		{
218472fcea8cSEd Schouten 			quit(0);
218572fcea8cSEd Schouten 			return;
218672fcea8cSEd Schouten 		}
218772fcea8cSEd Schouten 		else
218872fcea8cSEd Schouten 			return;
218972fcea8cSEd Schouten 	}
219072fcea8cSEd Schouten 	if ((get_fd = open(tmp_file, O_RDONLY)) == -1)
219172fcea8cSEd Schouten 	{
219272fcea8cSEd Schouten 		wmove(com_win, 0, 0);
219372fcea8cSEd Schouten 		wclrtoeol(com_win);
219472fcea8cSEd Schouten 		if (input_file)
219572fcea8cSEd Schouten 			wprintw(com_win, new_file_msg, tmp_file);
219672fcea8cSEd Schouten 		else
219772fcea8cSEd Schouten 			wprintw(com_win, cant_open_msg, tmp_file);
219872fcea8cSEd Schouten 		wrefresh(com_win);
219972fcea8cSEd Schouten 		wmove(text_win, scr_vert, (scr_horz - horiz_offset));
220072fcea8cSEd Schouten 		wrefresh(text_win);
220172fcea8cSEd Schouten 		recv_file = FALSE;
220272fcea8cSEd Schouten 		input_file = FALSE;
220372fcea8cSEd Schouten 		return;
220472fcea8cSEd Schouten 	}
220572fcea8cSEd Schouten 	else
220672fcea8cSEd Schouten 		get_file(tmp_file);
220772fcea8cSEd Schouten 
220872fcea8cSEd Schouten 	recv_file = FALSE;
220972fcea8cSEd Schouten 	line_num = curr_line->line_number;
221072fcea8cSEd Schouten 	scr_vert = tmp_vert;
221172fcea8cSEd Schouten 	scr_horz = tmp_horz;
221272fcea8cSEd Schouten 	if (input_file)
221372fcea8cSEd Schouten 		curr_line= first_line;
221472fcea8cSEd Schouten 	else
221572fcea8cSEd Schouten 		curr_line = tmp_line;
221672fcea8cSEd Schouten 	point = curr_line->line;
221772fcea8cSEd Schouten 	draw_screen();
221872fcea8cSEd Schouten 	if (input_file)
221972fcea8cSEd Schouten 	{
222072fcea8cSEd Schouten 		input_file = FALSE;
222172fcea8cSEd Schouten 		if (start_at_line != NULL)
222272fcea8cSEd Schouten 		{
222372fcea8cSEd Schouten 			line_num = atoi(start_at_line) - 1;
222472fcea8cSEd Schouten 			move_rel("d", line_num);
222572fcea8cSEd Schouten 			line_num = 0;
222672fcea8cSEd Schouten 			start_at_line = NULL;
222772fcea8cSEd Schouten 		}
222872fcea8cSEd Schouten 	}
222972fcea8cSEd Schouten 	else
223072fcea8cSEd Schouten 	{
223172fcea8cSEd Schouten 		wmove(com_win, 0, 0);
223272fcea8cSEd Schouten 		wclrtoeol(com_win);
223372fcea8cSEd Schouten 		text_changes = TRUE;
223496b676e9SEd Schouten 		if ((tmp_file != NULL) && (*tmp_file != '\0'))
223572fcea8cSEd Schouten 			wprintw(com_win, file_read_fin_msg, tmp_file);
223672fcea8cSEd Schouten 	}
223772fcea8cSEd Schouten 	wrefresh(com_win);
223872fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
223972fcea8cSEd Schouten 	wrefresh(text_win);
224072fcea8cSEd Schouten }
224172fcea8cSEd Schouten 
224272fcea8cSEd Schouten void
224372fcea8cSEd Schouten get_file(file_name)	/* read specified file into current buffer	*/
224472fcea8cSEd Schouten char *file_name;
224572fcea8cSEd Schouten {
224672fcea8cSEd Schouten 	int can_read;		/* file has at least one character	*/
224772fcea8cSEd Schouten 	int length;		/* length of line read by read		*/
224872fcea8cSEd Schouten 	int append;		/* should text be appended to current line */
224972fcea8cSEd Schouten 	struct text *temp_line;
225072fcea8cSEd Schouten 	char ro_flag = FALSE;
225172fcea8cSEd Schouten 
225272fcea8cSEd Schouten 	if (recv_file)		/* if reading a file			*/
225372fcea8cSEd Schouten 	{
225472fcea8cSEd Schouten 		wmove(com_win, 0, 0);
225572fcea8cSEd Schouten 		wclrtoeol(com_win);
225672fcea8cSEd Schouten 		wprintw(com_win, reading_file_msg, file_name);
225772fcea8cSEd Schouten 		if (access(file_name, 2))	/* check permission to write */
225872fcea8cSEd Schouten 		{
225972fcea8cSEd Schouten 			if ((errno == ENOTDIR) || (errno == EACCES) || (errno == EROFS) || (errno == ETXTBSY) || (errno == EFAULT))
226072fcea8cSEd Schouten 			{
226172fcea8cSEd Schouten 				wprintw(com_win, read_only_msg);
226272fcea8cSEd Schouten 				ro_flag = TRUE;
226372fcea8cSEd Schouten 			}
226472fcea8cSEd Schouten 		}
226572fcea8cSEd Schouten 		wrefresh(com_win);
226672fcea8cSEd Schouten 	}
226772fcea8cSEd Schouten 	if (curr_line->line_length > 1)	/* if current line is not blank	*/
226872fcea8cSEd Schouten 	{
226972fcea8cSEd Schouten 		insert_line(FALSE);
227072fcea8cSEd Schouten 		left(FALSE);
227172fcea8cSEd Schouten 		append = FALSE;
227272fcea8cSEd Schouten 	}
227372fcea8cSEd Schouten 	else
227472fcea8cSEd Schouten 		append = TRUE;
227572fcea8cSEd Schouten 	can_read = FALSE;		/* test if file has any characters  */
227672fcea8cSEd Schouten 	while (((length = read(get_fd, in_string, 512)) != 0) && (length != -1))
227772fcea8cSEd Schouten 	{
227872fcea8cSEd Schouten 		can_read = TRUE;  /* if set file has at least 1 character   */
227972fcea8cSEd Schouten 		get_line(length, in_string, &append);
228072fcea8cSEd Schouten 	}
228172fcea8cSEd Schouten 	if ((can_read) && (curr_line->line_length == 1))
228272fcea8cSEd Schouten 	{
228372fcea8cSEd Schouten 		temp_line = curr_line->prev_line;
228472fcea8cSEd Schouten 		temp_line->next_line = curr_line->next_line;
228572fcea8cSEd Schouten 		if (temp_line->next_line != NULL)
228672fcea8cSEd Schouten 			temp_line->next_line->prev_line = temp_line;
228772fcea8cSEd Schouten 		if (curr_line->line != NULL)
228872fcea8cSEd Schouten 			free(curr_line->line);
228972fcea8cSEd Schouten 		free(curr_line);
229072fcea8cSEd Schouten 		curr_line = temp_line;
229172fcea8cSEd Schouten 	}
229272fcea8cSEd Schouten 	if (input_file)	/* if this is the file to be edited display number of lines	*/
229372fcea8cSEd Schouten 	{
229472fcea8cSEd Schouten 		wmove(com_win, 0, 0);
229572fcea8cSEd Schouten 		wclrtoeol(com_win);
229672fcea8cSEd Schouten 		wprintw(com_win, file_read_lines_msg, in_file_name, curr_line->line_number);
229772fcea8cSEd Schouten 		if (ro_flag)
229872fcea8cSEd Schouten 			wprintw(com_win, read_only_msg);
229972fcea8cSEd Schouten 		wrefresh(com_win);
230072fcea8cSEd Schouten 	}
230172fcea8cSEd Schouten 	else if (can_read)	/* not input_file and file is non-zero size */
230272fcea8cSEd Schouten 		text_changes = TRUE;
230372fcea8cSEd Schouten 
230472fcea8cSEd Schouten 	if (recv_file)		/* if reading a file			*/
230572fcea8cSEd Schouten 	{
230672fcea8cSEd Schouten 		in = EOF;
230772fcea8cSEd Schouten 	}
230872fcea8cSEd Schouten }
230972fcea8cSEd Schouten 
231072fcea8cSEd Schouten void
231172fcea8cSEd Schouten get_line(length, in_string, append)	/* read string and split into lines */
231272fcea8cSEd Schouten int length;		/* length of string read by read		*/
231372fcea8cSEd Schouten unsigned char *in_string;	/* string read by read				*/
231472fcea8cSEd Schouten int *append;	/* TRUE if must append more text to end of current line	*/
231572fcea8cSEd Schouten {
231672fcea8cSEd Schouten 	unsigned char *str1;
231772fcea8cSEd Schouten 	unsigned char *str2;
231872fcea8cSEd Schouten 	int num;		/* offset from start of string		*/
231972fcea8cSEd Schouten 	int char_count;		/* length of new line (or added portion	*/
232072fcea8cSEd Schouten 	int temp_counter;	/* temporary counter value		*/
232172fcea8cSEd Schouten 	struct text *tline;	/* temporary pointer to new line	*/
232272fcea8cSEd Schouten 	int first_time;		/* if TRUE, the first time through the loop */
232372fcea8cSEd Schouten 
232472fcea8cSEd Schouten 	str2 = in_string;
232572fcea8cSEd Schouten 	num = 0;
232672fcea8cSEd Schouten 	first_time = TRUE;
232772fcea8cSEd Schouten 	while (num < length)
232872fcea8cSEd Schouten 	{
232972fcea8cSEd Schouten 		if (!first_time)
233072fcea8cSEd Schouten 		{
233172fcea8cSEd Schouten 			if (num < length)
233272fcea8cSEd Schouten 			{
233372fcea8cSEd Schouten 				str2++;
233472fcea8cSEd Schouten 				num++;
233572fcea8cSEd Schouten 			}
233672fcea8cSEd Schouten 		}
233772fcea8cSEd Schouten 		else
233872fcea8cSEd Schouten 			first_time = FALSE;
233972fcea8cSEd Schouten 		str1 = str2;
234072fcea8cSEd Schouten 		char_count = 1;
234172fcea8cSEd Schouten 		/* find end of line	*/
234272fcea8cSEd Schouten 		while ((*str2 != '\n') && (num < length))
234372fcea8cSEd Schouten 		{
234472fcea8cSEd Schouten 			str2++;
234572fcea8cSEd Schouten 			num++;
234672fcea8cSEd Schouten 			char_count++;
234772fcea8cSEd Schouten 		}
234872fcea8cSEd Schouten 		if (!(*append))	/* if not append to current line, insert new one */
234972fcea8cSEd Schouten 		{
235072fcea8cSEd Schouten 			tline = txtalloc();	/* allocate data structure for next line */
235196b676e9SEd Schouten 			tline->line_number = curr_line->line_number + 1;
235272fcea8cSEd Schouten 			tline->next_line = curr_line->next_line;
235372fcea8cSEd Schouten 			tline->prev_line = curr_line;
235472fcea8cSEd Schouten 			curr_line->next_line = tline;
235572fcea8cSEd Schouten 			if (tline->next_line != NULL)
235672fcea8cSEd Schouten 				tline->next_line->prev_line = tline;
235772fcea8cSEd Schouten 			curr_line = tline;
235872fcea8cSEd Schouten 			curr_line->line = point = (unsigned char *) malloc(char_count);
235972fcea8cSEd Schouten 			curr_line->line_length = char_count;
236072fcea8cSEd Schouten 			curr_line->max_length = char_count;
236172fcea8cSEd Schouten 		}
236272fcea8cSEd Schouten 		else
236372fcea8cSEd Schouten 		{
236472fcea8cSEd Schouten 			point = resiz_line(char_count, curr_line, curr_line->line_length);
236572fcea8cSEd Schouten 			curr_line->line_length += (char_count - 1);
236672fcea8cSEd Schouten 		}
236772fcea8cSEd Schouten 		for (temp_counter = 1; temp_counter < char_count; temp_counter++)
236872fcea8cSEd Schouten 		{
236972fcea8cSEd Schouten 			*point = *str1;
237072fcea8cSEd Schouten 			point++;
237172fcea8cSEd Schouten 			str1++;
237272fcea8cSEd Schouten 		}
237396b676e9SEd Schouten 		*point = '\0';
237472fcea8cSEd Schouten 		*append = FALSE;
237572fcea8cSEd Schouten 		if ((num == length) && (*str2 != '\n'))
237672fcea8cSEd Schouten 			*append = TRUE;
237772fcea8cSEd Schouten 	}
237872fcea8cSEd Schouten }
237972fcea8cSEd Schouten 
238072fcea8cSEd Schouten void
238172fcea8cSEd Schouten draw_screen()		/* redraw the screen from current postion	*/
238272fcea8cSEd Schouten {
238372fcea8cSEd Schouten 	struct text *temp_line;
238472fcea8cSEd Schouten 	unsigned char *line_out;
238572fcea8cSEd Schouten 	int temp_vert;
238672fcea8cSEd Schouten 
238772fcea8cSEd Schouten 	temp_line = curr_line;
238872fcea8cSEd Schouten 	temp_vert = scr_vert;
238972fcea8cSEd Schouten 	wclrtobot(text_win);
239072fcea8cSEd Schouten 	while ((temp_line != NULL) && (temp_vert <= last_line))
239172fcea8cSEd Schouten 	{
239272fcea8cSEd Schouten 		line_out = temp_line->line;
239372fcea8cSEd Schouten 		draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
239472fcea8cSEd Schouten 		temp_vert++;
239572fcea8cSEd Schouten 		temp_line = temp_line->next_line;
239672fcea8cSEd Schouten 	}
239772fcea8cSEd Schouten 	wmove(text_win, temp_vert, 0);
239872fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
239972fcea8cSEd Schouten }
240072fcea8cSEd Schouten 
240172fcea8cSEd Schouten void
240272fcea8cSEd Schouten finish()	/* prepare to exit edit session	*/
240372fcea8cSEd Schouten {
240472fcea8cSEd Schouten 	char *file_name = in_file_name;
240572fcea8cSEd Schouten 
240672fcea8cSEd Schouten 	/*
240772fcea8cSEd Schouten 	 |	changes made here should be reflected in the 'save'
240872fcea8cSEd Schouten 	 |	portion of file_op()
240972fcea8cSEd Schouten 	 */
241072fcea8cSEd Schouten 
241196b676e9SEd Schouten 	if ((file_name == NULL) || (*file_name == '\0'))
241272fcea8cSEd Schouten 		file_name = get_string(save_file_name_prompt, TRUE);
241372fcea8cSEd Schouten 
241496b676e9SEd Schouten 	if ((file_name == NULL) || (*file_name == '\0'))
241572fcea8cSEd Schouten 	{
241672fcea8cSEd Schouten 		wmove(com_win, 0, 0);
241772fcea8cSEd Schouten 		wprintw(com_win, file_not_saved_msg);
241872fcea8cSEd Schouten 		wclrtoeol(com_win);
241972fcea8cSEd Schouten 		wrefresh(com_win);
242072fcea8cSEd Schouten 		clear_com_win = TRUE;
242172fcea8cSEd Schouten 		return;
242272fcea8cSEd Schouten 	}
242372fcea8cSEd Schouten 
242472fcea8cSEd Schouten 	tmp_file = resolve_name(file_name);
242572fcea8cSEd Schouten 	if (tmp_file != file_name)
242672fcea8cSEd Schouten 	{
242772fcea8cSEd Schouten 		free(file_name);
242872fcea8cSEd Schouten 		file_name = tmp_file;
242972fcea8cSEd Schouten 	}
243072fcea8cSEd Schouten 
2431cfe04e82SEd Schouten 	if (write_file(file_name, 1))
243272fcea8cSEd Schouten 	{
243372fcea8cSEd Schouten 		text_changes = FALSE;
243472fcea8cSEd Schouten 		quit(0);
243572fcea8cSEd Schouten 	}
243672fcea8cSEd Schouten }
243772fcea8cSEd Schouten 
243872fcea8cSEd Schouten int
243972fcea8cSEd Schouten quit(noverify)		/* exit editor			*/
244072fcea8cSEd Schouten int noverify;
244172fcea8cSEd Schouten {
244272fcea8cSEd Schouten 	char *ans;
244372fcea8cSEd Schouten 
244472fcea8cSEd Schouten 	touchwin(text_win);
244572fcea8cSEd Schouten 	wrefresh(text_win);
244672fcea8cSEd Schouten 	if ((text_changes) && (!noverify))
244772fcea8cSEd Schouten 	{
244872fcea8cSEd Schouten 		ans = get_string(changes_made_prompt, TRUE);
244972fcea8cSEd Schouten 		if (toupper(*ans) == toupper(*yes_char))
245072fcea8cSEd Schouten 			text_changes = FALSE;
245172fcea8cSEd Schouten 		else
245272fcea8cSEd Schouten 			return(0);
245372fcea8cSEd Schouten 		free(ans);
245472fcea8cSEd Schouten 	}
245572fcea8cSEd Schouten 	if (top_of_stack == NULL)
245672fcea8cSEd Schouten 	{
245772fcea8cSEd Schouten 		if (info_window)
245872fcea8cSEd Schouten 			wrefresh(info_win);
245972fcea8cSEd Schouten 		wrefresh(com_win);
246072fcea8cSEd Schouten 		resetty();
246172fcea8cSEd Schouten 		endwin();
246272fcea8cSEd Schouten 		putchar('\n');
246372fcea8cSEd Schouten 		exit(0);
246472fcea8cSEd Schouten 	}
246572fcea8cSEd Schouten 	else
246672fcea8cSEd Schouten 	{
246772fcea8cSEd Schouten 		delete_text();
246872fcea8cSEd Schouten 		recv_file = TRUE;
246972fcea8cSEd Schouten 		input_file = TRUE;
247072fcea8cSEd Schouten 		check_fp();
247172fcea8cSEd Schouten 	}
247272fcea8cSEd Schouten 	return(0);
247372fcea8cSEd Schouten }
247472fcea8cSEd Schouten 
247572fcea8cSEd Schouten void
247672fcea8cSEd Schouten edit_abort(arg)
247772fcea8cSEd Schouten int arg;
247872fcea8cSEd Schouten {
247972fcea8cSEd Schouten 	wrefresh(com_win);
248072fcea8cSEd Schouten 	resetty();
248172fcea8cSEd Schouten 	endwin();
248272fcea8cSEd Schouten 	putchar('\n');
248372fcea8cSEd Schouten 	exit(1);
248472fcea8cSEd Schouten }
248572fcea8cSEd Schouten 
248672fcea8cSEd Schouten void
248772fcea8cSEd Schouten delete_text()
248872fcea8cSEd Schouten {
248972fcea8cSEd Schouten 	while (curr_line->next_line != NULL)
249072fcea8cSEd Schouten 		curr_line = curr_line->next_line;
249172fcea8cSEd Schouten 	while (curr_line != first_line)
249272fcea8cSEd Schouten 	{
249372fcea8cSEd Schouten 		free(curr_line->line);
249472fcea8cSEd Schouten 		curr_line = curr_line->prev_line;
249596b676e9SEd Schouten 		absolute_lin--;
249672fcea8cSEd Schouten 		free(curr_line->next_line);
249772fcea8cSEd Schouten 	}
249872fcea8cSEd Schouten 	curr_line->next_line = NULL;
249996b676e9SEd Schouten 	*curr_line->line = '\0';
250072fcea8cSEd Schouten 	curr_line->line_length = 1;
250172fcea8cSEd Schouten 	curr_line->line_number = 1;
250272fcea8cSEd Schouten 	point = curr_line->line;
250372fcea8cSEd Schouten 	scr_pos = scr_vert = scr_horz = 0;
250472fcea8cSEd Schouten 	position = 1;
250572fcea8cSEd Schouten }
250672fcea8cSEd Schouten 
250772fcea8cSEd Schouten int
2508cfe04e82SEd Schouten write_file(file_name, warn_if_exists)
250972fcea8cSEd Schouten char *file_name;
2510cfe04e82SEd Schouten int warn_if_exists;
251172fcea8cSEd Schouten {
251272fcea8cSEd Schouten 	char cr;
251372fcea8cSEd Schouten 	char *tmp_point;
251472fcea8cSEd Schouten 	struct text *out_line;
251572fcea8cSEd Schouten 	int lines, charac;
251672fcea8cSEd Schouten 	int temp_pos;
251772fcea8cSEd Schouten 	int write_flag = TRUE;
251872fcea8cSEd Schouten 
251972fcea8cSEd Schouten 	charac = lines = 0;
2520cfe04e82SEd Schouten 	if (warn_if_exists &&
2521cfe04e82SEd Schouten 	    ((in_file_name == NULL) || strcmp(in_file_name, file_name)))
252272fcea8cSEd Schouten 	{
252372fcea8cSEd Schouten 		if ((temp_fp = fopen(file_name, "r")))
252472fcea8cSEd Schouten 		{
252572fcea8cSEd Schouten 			tmp_point = get_string(file_exists_prompt, TRUE);
252672fcea8cSEd Schouten 			if (toupper(*tmp_point) == toupper(*yes_char))
252772fcea8cSEd Schouten 				write_flag = TRUE;
252872fcea8cSEd Schouten 			else
252972fcea8cSEd Schouten 				write_flag = FALSE;
253072fcea8cSEd Schouten 			fclose(temp_fp);
253172fcea8cSEd Schouten 			free(tmp_point);
253272fcea8cSEd Schouten 		}
253372fcea8cSEd Schouten 	}
253472fcea8cSEd Schouten 
253572fcea8cSEd Schouten 	clear_com_win = TRUE;
253672fcea8cSEd Schouten 
253772fcea8cSEd Schouten 	if (write_flag)
253872fcea8cSEd Schouten 	{
253972fcea8cSEd Schouten 		if ((temp_fp = fopen(file_name, "w")) == NULL)
254072fcea8cSEd Schouten 		{
254172fcea8cSEd Schouten 			clear_com_win = TRUE;
254272fcea8cSEd Schouten 			wmove(com_win,0,0);
254372fcea8cSEd Schouten 			wclrtoeol(com_win);
254472fcea8cSEd Schouten 			wprintw(com_win, create_file_fail_msg, file_name);
254572fcea8cSEd Schouten 			wrefresh(com_win);
254672fcea8cSEd Schouten 			return(FALSE);
254772fcea8cSEd Schouten 		}
254872fcea8cSEd Schouten 		else
254972fcea8cSEd Schouten 		{
255072fcea8cSEd Schouten 			wmove(com_win,0,0);
255172fcea8cSEd Schouten 			wclrtoeol(com_win);
255272fcea8cSEd Schouten 			wprintw(com_win, writing_file_msg, file_name);
255372fcea8cSEd Schouten 			wrefresh(com_win);
255472fcea8cSEd Schouten 			cr = '\n';
255572fcea8cSEd Schouten 			out_line = first_line;
255672fcea8cSEd Schouten 			while (out_line != NULL)
255772fcea8cSEd Schouten 			{
255872fcea8cSEd Schouten 				temp_pos = 1;
255972fcea8cSEd Schouten 				tmp_point= out_line->line;
256072fcea8cSEd Schouten 				while (temp_pos < out_line->line_length)
256172fcea8cSEd Schouten 				{
256272fcea8cSEd Schouten 					putc(*tmp_point, temp_fp);
256372fcea8cSEd Schouten 					tmp_point++;
256472fcea8cSEd Schouten 					temp_pos++;
256572fcea8cSEd Schouten 				}
256672fcea8cSEd Schouten 				charac += out_line->line_length;
256772fcea8cSEd Schouten 				out_line = out_line->next_line;
256872fcea8cSEd Schouten 				putc(cr, temp_fp);
256972fcea8cSEd Schouten 				lines++;
257072fcea8cSEd Schouten 			}
257172fcea8cSEd Schouten 			fclose(temp_fp);
257272fcea8cSEd Schouten 			wmove(com_win,0,0);
257372fcea8cSEd Schouten 			wclrtoeol(com_win);
257472fcea8cSEd Schouten 			wprintw(com_win, file_written_msg, file_name, lines, charac);
257572fcea8cSEd Schouten 			wrefresh(com_win);
257672fcea8cSEd Schouten 			return(TRUE);
257772fcea8cSEd Schouten 		}
257872fcea8cSEd Schouten 	}
257972fcea8cSEd Schouten 	else
258072fcea8cSEd Schouten 		return(FALSE);
258172fcea8cSEd Schouten }
258272fcea8cSEd Schouten 
258372fcea8cSEd Schouten int
258472fcea8cSEd Schouten search(display_message)		/* search for string in srch_str	*/
258572fcea8cSEd Schouten int display_message;
258672fcea8cSEd Schouten {
258772fcea8cSEd Schouten 	int lines_moved;
258872fcea8cSEd Schouten 	int iter;
258972fcea8cSEd Schouten 	int found;
259072fcea8cSEd Schouten 
259196b676e9SEd Schouten 	if ((srch_str == NULL) || (*srch_str == '\0'))
259272fcea8cSEd Schouten 		return(FALSE);
259372fcea8cSEd Schouten 	if (display_message)
259472fcea8cSEd Schouten 	{
259572fcea8cSEd Schouten 		wmove(com_win, 0, 0);
259672fcea8cSEd Schouten 		wclrtoeol(com_win);
259772fcea8cSEd Schouten 		wprintw(com_win, searching_msg);
259872fcea8cSEd Schouten 		wrefresh(com_win);
259972fcea8cSEd Schouten 		clear_com_win = TRUE;
260072fcea8cSEd Schouten 	}
260172fcea8cSEd Schouten 	lines_moved = 0;
260272fcea8cSEd Schouten 	found = FALSE;
260372fcea8cSEd Schouten 	srch_line = curr_line;
260472fcea8cSEd Schouten 	srch_1 = point;
260572fcea8cSEd Schouten 	if (position < curr_line->line_length)
260672fcea8cSEd Schouten 		srch_1++;
260772fcea8cSEd Schouten 	iter = position + 1;
260872fcea8cSEd Schouten 	while ((!found) && (srch_line != NULL))
260972fcea8cSEd Schouten 	{
261072fcea8cSEd Schouten 		while ((iter < srch_line->line_length) && (!found))
261172fcea8cSEd Schouten 		{
261272fcea8cSEd Schouten 			srch_2 = srch_1;
261372fcea8cSEd Schouten 			if (case_sen)	/* if case sensitive		*/
261472fcea8cSEd Schouten 			{
261572fcea8cSEd Schouten 				srch_3 = srch_str;
261696b676e9SEd Schouten 			while ((*srch_2 == *srch_3) && (*srch_3 != '\0'))
261772fcea8cSEd Schouten 				{
261872fcea8cSEd Schouten 					found = TRUE;
261972fcea8cSEd Schouten 					srch_2++;
262072fcea8cSEd Schouten 					srch_3++;
262172fcea8cSEd Schouten 				}	/* end while	*/
262272fcea8cSEd Schouten 			}
262372fcea8cSEd Schouten 			else		/* if not case sensitive	*/
262472fcea8cSEd Schouten 			{
262572fcea8cSEd Schouten 				srch_3 = u_srch_str;
262696b676e9SEd Schouten 			while ((toupper(*srch_2) == *srch_3) && (*srch_3 != '\0'))
262772fcea8cSEd Schouten 				{
262872fcea8cSEd Schouten 					found = TRUE;
262972fcea8cSEd Schouten 					srch_2++;
263072fcea8cSEd Schouten 					srch_3++;
263172fcea8cSEd Schouten 				}
263272fcea8cSEd Schouten 			}	/* end else	*/
263396b676e9SEd Schouten 			if (!((*srch_3 == '\0') && (found)))
263472fcea8cSEd Schouten 			{
263572fcea8cSEd Schouten 				found = FALSE;
263672fcea8cSEd Schouten 				if (iter < srch_line->line_length)
263772fcea8cSEd Schouten 					srch_1++;
263872fcea8cSEd Schouten 				iter++;
263972fcea8cSEd Schouten 			}
264072fcea8cSEd Schouten 		}
264172fcea8cSEd Schouten 		if (!found)
264272fcea8cSEd Schouten 		{
264372fcea8cSEd Schouten 			srch_line = srch_line->next_line;
264472fcea8cSEd Schouten 			if (srch_line != NULL)
264572fcea8cSEd Schouten 				srch_1 = srch_line->line;
264672fcea8cSEd Schouten 			iter = 1;
264772fcea8cSEd Schouten 			lines_moved++;
264872fcea8cSEd Schouten 		}
264972fcea8cSEd Schouten 	}
265072fcea8cSEd Schouten 	if (found)
265172fcea8cSEd Schouten 	{
265272fcea8cSEd Schouten 		if (display_message)
265372fcea8cSEd Schouten 		{
265472fcea8cSEd Schouten 			wmove(com_win, 0, 0);
265572fcea8cSEd Schouten 			wclrtoeol(com_win);
265672fcea8cSEd Schouten 			wrefresh(com_win);
265772fcea8cSEd Schouten 		}
265872fcea8cSEd Schouten 		if (lines_moved == 0)
265972fcea8cSEd Schouten 		{
266072fcea8cSEd Schouten 			while (position < iter)
266172fcea8cSEd Schouten 				right(TRUE);
266272fcea8cSEd Schouten 		}
266372fcea8cSEd Schouten 		else
266472fcea8cSEd Schouten 		{
266572fcea8cSEd Schouten 			if (lines_moved < 30)
266672fcea8cSEd Schouten 			{
266772fcea8cSEd Schouten 				move_rel("d", lines_moved);
266872fcea8cSEd Schouten 				while (position < iter)
266972fcea8cSEd Schouten 					right(TRUE);
267072fcea8cSEd Schouten 			}
267172fcea8cSEd Schouten 			else
267272fcea8cSEd Schouten 			{
267396b676e9SEd Schouten 				absolute_lin += lines_moved;
267472fcea8cSEd Schouten 				curr_line = srch_line;
267572fcea8cSEd Schouten 				point = srch_1;
267672fcea8cSEd Schouten 				position = iter;
267772fcea8cSEd Schouten 				scanline(point);
267872fcea8cSEd Schouten 				scr_pos = scr_horz;
267972fcea8cSEd Schouten 				midscreen((last_line / 2), point);
268072fcea8cSEd Schouten 			}
268172fcea8cSEd Schouten 		}
268272fcea8cSEd Schouten 	}
268372fcea8cSEd Schouten 	else
268472fcea8cSEd Schouten 	{
268572fcea8cSEd Schouten 		if (display_message)
268672fcea8cSEd Schouten 		{
268772fcea8cSEd Schouten 			wmove(com_win, 0, 0);
268872fcea8cSEd Schouten 			wclrtoeol(com_win);
268972fcea8cSEd Schouten 			wprintw(com_win, str_not_found_msg, srch_str);
269072fcea8cSEd Schouten 			wrefresh(com_win);
269172fcea8cSEd Schouten 		}
269272fcea8cSEd Schouten 		wmove(text_win, scr_vert,(scr_horz - horiz_offset));
269372fcea8cSEd Schouten 	}
269472fcea8cSEd Schouten 	return(found);
269572fcea8cSEd Schouten }
269672fcea8cSEd Schouten 
269772fcea8cSEd Schouten void
269872fcea8cSEd Schouten search_prompt()		/* prompt and read search string (srch_str)	*/
269972fcea8cSEd Schouten {
270072fcea8cSEd Schouten 	if (srch_str != NULL)
270172fcea8cSEd Schouten 		free(srch_str);
270296b676e9SEd Schouten 	if ((u_srch_str != NULL) && (*u_srch_str != '\0'))
270372fcea8cSEd Schouten 		free(u_srch_str);
270472fcea8cSEd Schouten 	srch_str = get_string(search_prompt_str, FALSE);
270572fcea8cSEd Schouten 	gold = FALSE;
270672fcea8cSEd Schouten 	srch_3 = srch_str;
270772fcea8cSEd Schouten 	srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
270896b676e9SEd Schouten 	while (*srch_3 != '\0')
270972fcea8cSEd Schouten 	{
271072fcea8cSEd Schouten 		*srch_1 = toupper(*srch_3);
271172fcea8cSEd Schouten 		srch_1++;
271272fcea8cSEd Schouten 		srch_3++;
271372fcea8cSEd Schouten 	}
271496b676e9SEd Schouten 	*srch_1 = '\0';
271572fcea8cSEd Schouten 	search(TRUE);
271672fcea8cSEd Schouten }
271772fcea8cSEd Schouten 
271872fcea8cSEd Schouten void
271972fcea8cSEd Schouten del_char()			/* delete current character	*/
272072fcea8cSEd Schouten {
272172fcea8cSEd Schouten 	in = 8;  /* backspace */
272272fcea8cSEd Schouten 	if (position < curr_line->line_length)	/* if not end of line	*/
272372fcea8cSEd Schouten 	{
272472fcea8cSEd Schouten 		if ((ee_chinese) && (*point > 127) &&
272572fcea8cSEd Schouten 		    ((curr_line->line_length - position) >= 2))
272672fcea8cSEd Schouten 		{
272772fcea8cSEd Schouten 			point++;
272872fcea8cSEd Schouten 			position++;
272972fcea8cSEd Schouten 		}
273072fcea8cSEd Schouten 		position++;
273172fcea8cSEd Schouten 		point++;
273272fcea8cSEd Schouten 		scanline(point);
273372fcea8cSEd Schouten 		delete(TRUE);
273472fcea8cSEd Schouten 	}
273572fcea8cSEd Schouten 	else
273672fcea8cSEd Schouten 	{
273772fcea8cSEd Schouten 		right(FALSE);
273872fcea8cSEd Schouten 		delete(FALSE);
273972fcea8cSEd Schouten 	}
274072fcea8cSEd Schouten }
274172fcea8cSEd Schouten 
274272fcea8cSEd Schouten void
274372fcea8cSEd Schouten undel_char()			/* undelete last deleted character	*/
274472fcea8cSEd Schouten {
274572fcea8cSEd Schouten 	if (d_char[0] == '\n')	/* insert line if last del_char deleted eol */
274672fcea8cSEd Schouten 		insert_line(TRUE);
274772fcea8cSEd Schouten 	else
274872fcea8cSEd Schouten 	{
274972fcea8cSEd Schouten 		in = d_char[0];
275072fcea8cSEd Schouten 		insert(in);
275196b676e9SEd Schouten 		if (d_char[1] != '\0')
275272fcea8cSEd Schouten 		{
275372fcea8cSEd Schouten 			in = d_char[1];
275472fcea8cSEd Schouten 			insert(in);
275572fcea8cSEd Schouten 		}
275672fcea8cSEd Schouten 	}
275772fcea8cSEd Schouten }
275872fcea8cSEd Schouten 
275972fcea8cSEd Schouten void
276072fcea8cSEd Schouten del_word()			/* delete word in front of cursor	*/
276172fcea8cSEd Schouten {
276272fcea8cSEd Schouten 	int tposit;
276372fcea8cSEd Schouten 	int difference;
276472fcea8cSEd Schouten 	unsigned char *d_word2;
276572fcea8cSEd Schouten 	unsigned char *d_word3;
276672fcea8cSEd Schouten 	unsigned char tmp_char[3];
276772fcea8cSEd Schouten 
276872fcea8cSEd Schouten 	if (d_word != NULL)
276972fcea8cSEd Schouten 		free(d_word);
277072fcea8cSEd Schouten 	d_word = malloc(curr_line->line_length);
277172fcea8cSEd Schouten 	tmp_char[0] = d_char[0];
277272fcea8cSEd Schouten 	tmp_char[1] = d_char[1];
277372fcea8cSEd Schouten 	tmp_char[2] = d_char[2];
277472fcea8cSEd Schouten 	d_word3 = point;
277572fcea8cSEd Schouten 	d_word2 = d_word;
277672fcea8cSEd Schouten 	tposit = position;
277772fcea8cSEd Schouten 	while ((tposit < curr_line->line_length) &&
277872fcea8cSEd Schouten 				((*d_word3 != ' ') && (*d_word3 != '\t')))
277972fcea8cSEd Schouten 	{
278072fcea8cSEd Schouten 		tposit++;
278172fcea8cSEd Schouten 		*d_word2 = *d_word3;
278272fcea8cSEd Schouten 		d_word2++;
278372fcea8cSEd Schouten 		d_word3++;
278472fcea8cSEd Schouten 	}
278572fcea8cSEd Schouten 	while ((tposit < curr_line->line_length) &&
278672fcea8cSEd Schouten 				((*d_word3 == ' ') || (*d_word3 == '\t')))
278772fcea8cSEd Schouten 	{
278872fcea8cSEd Schouten 		tposit++;
278972fcea8cSEd Schouten 		*d_word2 = *d_word3;
279072fcea8cSEd Schouten 		d_word2++;
279172fcea8cSEd Schouten 		d_word3++;
279272fcea8cSEd Schouten 	}
279396b676e9SEd Schouten 	*d_word2 = '\0';
279472fcea8cSEd Schouten 	d_wrd_len = difference = d_word2 - d_word;
279572fcea8cSEd Schouten 	d_word2 = point;
279672fcea8cSEd Schouten 	while (tposit < curr_line->line_length)
279772fcea8cSEd Schouten 	{
279872fcea8cSEd Schouten 		tposit++;
279972fcea8cSEd Schouten 		*d_word2 = *d_word3;
280072fcea8cSEd Schouten 		d_word2++;
280172fcea8cSEd Schouten 		d_word3++;
280272fcea8cSEd Schouten 	}
280372fcea8cSEd Schouten 	curr_line->line_length -= difference;
280496b676e9SEd Schouten 	*d_word2 = '\0';
280572fcea8cSEd Schouten 	draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
280672fcea8cSEd Schouten 	d_char[0] = tmp_char[0];
280772fcea8cSEd Schouten 	d_char[1] = tmp_char[1];
280872fcea8cSEd Schouten 	d_char[2] = tmp_char[2];
280972fcea8cSEd Schouten 	text_changes = TRUE;
281072fcea8cSEd Schouten 	formatted = FALSE;
281172fcea8cSEd Schouten }
281272fcea8cSEd Schouten 
281372fcea8cSEd Schouten void
281472fcea8cSEd Schouten undel_word()		/* undelete last deleted word		*/
281572fcea8cSEd Schouten {
281672fcea8cSEd Schouten 	int temp;
281772fcea8cSEd Schouten 	int tposit;
281872fcea8cSEd Schouten 	unsigned char *tmp_old_ptr;
281972fcea8cSEd Schouten 	unsigned char *tmp_space;
282072fcea8cSEd Schouten 	unsigned char *tmp_ptr;
282172fcea8cSEd Schouten 	unsigned char *d_word_ptr;
282272fcea8cSEd Schouten 
282372fcea8cSEd Schouten 	/*
282472fcea8cSEd Schouten 	 |	resize line to handle undeleted word
282572fcea8cSEd Schouten 	 */
282672fcea8cSEd Schouten 	if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
282772fcea8cSEd Schouten 		point = resiz_line(d_wrd_len, curr_line, position);
282872fcea8cSEd Schouten 	tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
282972fcea8cSEd Schouten 	d_word_ptr = d_word;
283072fcea8cSEd Schouten 	temp = 1;
283172fcea8cSEd Schouten 	/*
283272fcea8cSEd Schouten 	 |	copy d_word contents into temp space
283372fcea8cSEd Schouten 	 */
283472fcea8cSEd Schouten 	while (temp <= d_wrd_len)
283572fcea8cSEd Schouten 	{
283672fcea8cSEd Schouten 		temp++;
283772fcea8cSEd Schouten 		*tmp_ptr = *d_word_ptr;
283872fcea8cSEd Schouten 		tmp_ptr++;
283972fcea8cSEd Schouten 		d_word_ptr++;
284072fcea8cSEd Schouten 	}
284172fcea8cSEd Schouten 	tmp_old_ptr = point;
284272fcea8cSEd Schouten 	tposit = position;
284372fcea8cSEd Schouten 	/*
284472fcea8cSEd Schouten 	 |	copy contents of line from curent position to eol into
284572fcea8cSEd Schouten 	 |	temp space
284672fcea8cSEd Schouten 	 */
284772fcea8cSEd Schouten 	while (tposit < curr_line->line_length)
284872fcea8cSEd Schouten 	{
284972fcea8cSEd Schouten 		temp++;
285072fcea8cSEd Schouten 		tposit++;
285172fcea8cSEd Schouten 		*tmp_ptr = *tmp_old_ptr;
285272fcea8cSEd Schouten 		tmp_ptr++;
285372fcea8cSEd Schouten 		tmp_old_ptr++;
285472fcea8cSEd Schouten 	}
285572fcea8cSEd Schouten 	curr_line->line_length += d_wrd_len;
285672fcea8cSEd Schouten 	tmp_old_ptr = point;
285796b676e9SEd Schouten 	*tmp_ptr = '\0';
285872fcea8cSEd Schouten 	tmp_ptr = tmp_space;
285972fcea8cSEd Schouten 	tposit = 1;
286072fcea8cSEd Schouten 	/*
286172fcea8cSEd Schouten 	 |	now copy contents from temp space back to original line
286272fcea8cSEd Schouten 	 */
286372fcea8cSEd Schouten 	while (tposit < temp)
286472fcea8cSEd Schouten 	{
286572fcea8cSEd Schouten 		tposit++;
286672fcea8cSEd Schouten 		*tmp_old_ptr = *tmp_ptr;
286772fcea8cSEd Schouten 		tmp_ptr++;
286872fcea8cSEd Schouten 		tmp_old_ptr++;
286972fcea8cSEd Schouten 	}
287096b676e9SEd Schouten 	*tmp_old_ptr = '\0';
287172fcea8cSEd Schouten 	free(tmp_space);
287272fcea8cSEd Schouten 	draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
287372fcea8cSEd Schouten }
287472fcea8cSEd Schouten 
287572fcea8cSEd Schouten void
287672fcea8cSEd Schouten del_line()			/* delete from cursor to end of line	*/
287772fcea8cSEd Schouten {
287872fcea8cSEd Schouten 	unsigned char *dl1;
287972fcea8cSEd Schouten 	unsigned char *dl2;
288072fcea8cSEd Schouten 	int tposit;
288172fcea8cSEd Schouten 
288272fcea8cSEd Schouten 	if (d_line != NULL)
288372fcea8cSEd Schouten 		free(d_line);
288472fcea8cSEd Schouten 	d_line = malloc(curr_line->line_length);
288572fcea8cSEd Schouten 	dl1 = d_line;
288672fcea8cSEd Schouten 	dl2 = point;
288772fcea8cSEd Schouten 	tposit = position;
288872fcea8cSEd Schouten 	while (tposit < curr_line->line_length)
288972fcea8cSEd Schouten 	{
289072fcea8cSEd Schouten 		*dl1 = *dl2;
289172fcea8cSEd Schouten 		dl1++;
289272fcea8cSEd Schouten 		dl2++;
289372fcea8cSEd Schouten 		tposit++;
289472fcea8cSEd Schouten 	}
289572fcea8cSEd Schouten 	dlt_line->line_length = 1 + tposit - position;
289696b676e9SEd Schouten 	*dl1 = '\0';
289796b676e9SEd Schouten 	*point = '\0';
289872fcea8cSEd Schouten 	curr_line->line_length = position;
289972fcea8cSEd Schouten 	wclrtoeol(text_win);
290072fcea8cSEd Schouten 	if (curr_line->next_line != NULL)
290172fcea8cSEd Schouten 	{
290272fcea8cSEd Schouten 		right(FALSE);
290372fcea8cSEd Schouten 		delete(FALSE);
290472fcea8cSEd Schouten 	}
290572fcea8cSEd Schouten 	text_changes = TRUE;
290672fcea8cSEd Schouten }
290772fcea8cSEd Schouten 
290872fcea8cSEd Schouten void
290972fcea8cSEd Schouten undel_line()			/* undelete last deleted line		*/
291072fcea8cSEd Schouten {
291172fcea8cSEd Schouten 	unsigned char *ud1;
291272fcea8cSEd Schouten 	unsigned char *ud2;
291372fcea8cSEd Schouten 	int tposit;
291472fcea8cSEd Schouten 
291572fcea8cSEd Schouten 	if (dlt_line->line_length == 0)
291672fcea8cSEd Schouten 		return;
291772fcea8cSEd Schouten 
291872fcea8cSEd Schouten 	insert_line(TRUE);
291972fcea8cSEd Schouten 	left(TRUE);
292072fcea8cSEd Schouten 	point = resiz_line(dlt_line->line_length, curr_line, position);
292172fcea8cSEd Schouten 	curr_line->line_length += dlt_line->line_length - 1;
292272fcea8cSEd Schouten 	ud1 = point;
292372fcea8cSEd Schouten 	ud2 = d_line;
292472fcea8cSEd Schouten 	tposit = 1;
292572fcea8cSEd Schouten 	while (tposit < dlt_line->line_length)
292672fcea8cSEd Schouten 	{
292772fcea8cSEd Schouten 		tposit++;
292872fcea8cSEd Schouten 		*ud1 = *ud2;
292972fcea8cSEd Schouten 		ud1++;
293072fcea8cSEd Schouten 		ud2++;
293172fcea8cSEd Schouten 	}
293296b676e9SEd Schouten 	*ud1 = '\0';
293372fcea8cSEd Schouten 	draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
293472fcea8cSEd Schouten }
293572fcea8cSEd Schouten 
293672fcea8cSEd Schouten void
293772fcea8cSEd Schouten adv_word()			/* advance to next word		*/
293872fcea8cSEd Schouten {
293972fcea8cSEd Schouten while ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
294072fcea8cSEd Schouten 		right(TRUE);
294172fcea8cSEd Schouten while ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
294272fcea8cSEd Schouten 		right(TRUE);
294372fcea8cSEd Schouten }
294472fcea8cSEd Schouten 
294572fcea8cSEd Schouten void
294672fcea8cSEd Schouten move_rel(direction, lines)	/* move relative to current line	*/
294772fcea8cSEd Schouten char *direction;
294872fcea8cSEd Schouten int lines;
294972fcea8cSEd Schouten {
295072fcea8cSEd Schouten 	int i;
295172fcea8cSEd Schouten 	char *tmp;
295272fcea8cSEd Schouten 
295372fcea8cSEd Schouten 	if (*direction == 'u')
295472fcea8cSEd Schouten 	{
295572fcea8cSEd Schouten 		scr_pos = 0;
295672fcea8cSEd Schouten 		while (position > 1)
295772fcea8cSEd Schouten 			left(TRUE);
295872fcea8cSEd Schouten 		for (i = 0; i < lines; i++)
295972fcea8cSEd Schouten 		{
296072fcea8cSEd Schouten 			up();
296172fcea8cSEd Schouten 		}
296272fcea8cSEd Schouten 		if ((last_line > 5) && ( scr_vert < 4))
296372fcea8cSEd Schouten 		{
296472fcea8cSEd Schouten 			tmp = point;
296572fcea8cSEd Schouten 			tmp_line = curr_line;
296672fcea8cSEd Schouten 			for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
296772fcea8cSEd Schouten 			{
296872fcea8cSEd Schouten 				up();
296972fcea8cSEd Schouten 			}
297072fcea8cSEd Schouten 			scr_vert = scr_vert + i;
297172fcea8cSEd Schouten 			curr_line = tmp_line;
297296b676e9SEd Schouten 			absolute_lin += i;
297372fcea8cSEd Schouten 			point = tmp;
297472fcea8cSEd Schouten 			scanline(point);
297572fcea8cSEd Schouten 		}
297672fcea8cSEd Schouten 	}
297772fcea8cSEd Schouten 	else
297872fcea8cSEd Schouten 	{
297972fcea8cSEd Schouten 		if ((position != 1) && (curr_line->next_line != NULL))
298072fcea8cSEd Schouten 		{
298172fcea8cSEd Schouten 			nextline();
298272fcea8cSEd Schouten 			scr_pos = scr_horz = 0;
298372fcea8cSEd Schouten 			if (horiz_offset)
298472fcea8cSEd Schouten 			{
298572fcea8cSEd Schouten 				horiz_offset = 0;
298672fcea8cSEd Schouten 				midscreen(scr_vert, point);
298772fcea8cSEd Schouten 			}
298872fcea8cSEd Schouten 		}
298972fcea8cSEd Schouten 		else
299072fcea8cSEd Schouten 			adv_line();
299172fcea8cSEd Schouten 		for (i = 1; i < lines; i++)
299272fcea8cSEd Schouten 		{
299372fcea8cSEd Schouten 			down();
299472fcea8cSEd Schouten 		}
299572fcea8cSEd Schouten 		if ((last_line > 10) && (scr_vert > (last_line - 5)))
299672fcea8cSEd Schouten 		{
299772fcea8cSEd Schouten 			tmp = point;
299872fcea8cSEd Schouten 			tmp_line = curr_line;
299972fcea8cSEd Schouten 			for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
300072fcea8cSEd Schouten 			{
300172fcea8cSEd Schouten 				down();
300272fcea8cSEd Schouten 			}
300396b676e9SEd Schouten 			absolute_lin -= i;
300472fcea8cSEd Schouten 			scr_vert = scr_vert - i;
300572fcea8cSEd Schouten 			curr_line = tmp_line;
300672fcea8cSEd Schouten 			point = tmp;
300772fcea8cSEd Schouten 			scanline(point);
300872fcea8cSEd Schouten 		}
300972fcea8cSEd Schouten 	}
301072fcea8cSEd Schouten 	wmove(text_win, scr_vert, (scr_horz - horiz_offset));
301172fcea8cSEd Schouten }
301272fcea8cSEd Schouten 
301372fcea8cSEd Schouten void
301472fcea8cSEd Schouten eol()				/* go to end of line			*/
301572fcea8cSEd Schouten {
301672fcea8cSEd Schouten 	if (position < curr_line->line_length)
301772fcea8cSEd Schouten 	{
301872fcea8cSEd Schouten 		while (position < curr_line->line_length)
301972fcea8cSEd Schouten 			right(TRUE);
302072fcea8cSEd Schouten 	}
302172fcea8cSEd Schouten 	else if (curr_line->next_line != NULL)
302272fcea8cSEd Schouten 	{
302372fcea8cSEd Schouten 		right(TRUE);
302472fcea8cSEd Schouten 		while (position < curr_line->line_length)
302572fcea8cSEd Schouten 			right(TRUE);
302672fcea8cSEd Schouten 	}
302772fcea8cSEd Schouten }
302872fcea8cSEd Schouten 
302972fcea8cSEd Schouten void
303072fcea8cSEd Schouten bol()				/* move to beginning of line	*/
303172fcea8cSEd Schouten {
303272fcea8cSEd Schouten 	if (point != curr_line->line)
303372fcea8cSEd Schouten 	{
303472fcea8cSEd Schouten 		while (point != curr_line->line)
303572fcea8cSEd Schouten 			left(TRUE);
303672fcea8cSEd Schouten 	}
303772fcea8cSEd Schouten 	else if (curr_line->prev_line != NULL)
303872fcea8cSEd Schouten 	{
303972fcea8cSEd Schouten 		scr_pos = 0;
304072fcea8cSEd Schouten 		up();
304172fcea8cSEd Schouten 	}
304272fcea8cSEd Schouten }
304372fcea8cSEd Schouten 
304472fcea8cSEd Schouten void
304572fcea8cSEd Schouten adv_line()	/* advance to beginning of next line	*/
304672fcea8cSEd Schouten {
304772fcea8cSEd Schouten 	if ((point != curr_line->line) || (scr_pos > 0))
304872fcea8cSEd Schouten 	{
304972fcea8cSEd Schouten 		while (position < curr_line->line_length)
305072fcea8cSEd Schouten 			right(TRUE);
305172fcea8cSEd Schouten 		right(TRUE);
305272fcea8cSEd Schouten 	}
305372fcea8cSEd Schouten 	else if (curr_line->next_line != NULL)
305472fcea8cSEd Schouten 	{
305572fcea8cSEd Schouten 		scr_pos = 0;
305672fcea8cSEd Schouten 		down();
305772fcea8cSEd Schouten 	}
305872fcea8cSEd Schouten }
305972fcea8cSEd Schouten 
306072fcea8cSEd Schouten void
306196b676e9SEd Schouten from_top()
306296b676e9SEd Schouten {
306396b676e9SEd Schouten 	struct text *tmpline = first_line;
306496b676e9SEd Schouten 	int x = 1;
306596b676e9SEd Schouten 
306696b676e9SEd Schouten 	while ((tmpline != NULL) && (tmpline != curr_line))
306796b676e9SEd Schouten 	{
306896b676e9SEd Schouten 		x++;
306996b676e9SEd Schouten 		tmpline = tmpline->next_line;
307096b676e9SEd Schouten 	}
307196b676e9SEd Schouten 	absolute_lin = x;
307296b676e9SEd Schouten }
307396b676e9SEd Schouten 
307496b676e9SEd Schouten void
307572fcea8cSEd Schouten sh_command(string)	/* execute shell command			*/
307672fcea8cSEd Schouten char *string;		/* string containing user command		*/
307772fcea8cSEd Schouten {
307872fcea8cSEd Schouten 	char *temp_point;
307972fcea8cSEd Schouten 	char *last_slash;
308072fcea8cSEd Schouten 	char *path;		/* directory path to executable		*/
308172fcea8cSEd Schouten 	int parent;		/* zero if child, child's pid if parent	*/
308272fcea8cSEd Schouten 	int value;
308372fcea8cSEd Schouten 	int return_val;
308472fcea8cSEd Schouten 	struct text *line_holder;
308572fcea8cSEd Schouten 
308672fcea8cSEd Schouten 	if (restrict_mode())
308772fcea8cSEd Schouten 	{
308872fcea8cSEd Schouten 		return;
308972fcea8cSEd Schouten 	}
309072fcea8cSEd Schouten 
309172fcea8cSEd Schouten 	if (!(path = getenv("SHELL")))
309272fcea8cSEd Schouten 		path = "/bin/sh";
309372fcea8cSEd Schouten 	last_slash = temp_point = path;
309496b676e9SEd Schouten 	while (*temp_point != '\0')
309572fcea8cSEd Schouten 	{
309672fcea8cSEd Schouten 		if (*temp_point == '/')
309772fcea8cSEd Schouten 			last_slash = ++temp_point;
309872fcea8cSEd Schouten 		else
309972fcea8cSEd Schouten 			temp_point++;
310072fcea8cSEd Schouten 	}
310172fcea8cSEd Schouten 
310272fcea8cSEd Schouten 	/*
310372fcea8cSEd Schouten 	 |	if in_pipe is true, then output of the shell operation will be
310472fcea8cSEd Schouten 	 |	read by the editor, and curses doesn't need to be turned off
310572fcea8cSEd Schouten 	 */
310672fcea8cSEd Schouten 
310772fcea8cSEd Schouten 	if (!in_pipe)
310872fcea8cSEd Schouten 	{
310972fcea8cSEd Schouten 		keypad(com_win, FALSE);
311072fcea8cSEd Schouten 		keypad(text_win, FALSE);
311172fcea8cSEd Schouten 		echo();
311272fcea8cSEd Schouten 		nl();
311372fcea8cSEd Schouten 		noraw();
311472fcea8cSEd Schouten 		resetty();
311572fcea8cSEd Schouten 
311672fcea8cSEd Schouten #ifndef NCURSE
311772fcea8cSEd Schouten 		endwin();
311872fcea8cSEd Schouten #endif
311972fcea8cSEd Schouten 	}
312072fcea8cSEd Schouten 
312172fcea8cSEd Schouten 	if (in_pipe)
312272fcea8cSEd Schouten 	{
312372fcea8cSEd Schouten 		pipe(pipe_in);		/* create a pipe	*/
312472fcea8cSEd Schouten 		parent = fork();
312572fcea8cSEd Schouten 		if (!parent)		/* if the child		*/
312672fcea8cSEd Schouten 		{
312772fcea8cSEd Schouten /*
312872fcea8cSEd Schouten  |  child process which will fork and exec shell command (if shell output is
312972fcea8cSEd Schouten  |  to be read by editor)
313072fcea8cSEd Schouten  */
313172fcea8cSEd Schouten 			in_pipe = FALSE;
313272fcea8cSEd Schouten /*
313372fcea8cSEd Schouten  |  redirect stdout to pipe
313472fcea8cSEd Schouten  */
313572fcea8cSEd Schouten 			temp_stdout = dup(1);
313672fcea8cSEd Schouten 			close(1);
313772fcea8cSEd Schouten 			dup(pipe_in[1]);
313872fcea8cSEd Schouten /*
313972fcea8cSEd Schouten  |  redirect stderr to pipe
314072fcea8cSEd Schouten  */
314172fcea8cSEd Schouten 			temp_stderr = dup(2);
314272fcea8cSEd Schouten 			close(2);
314372fcea8cSEd Schouten 			dup(pipe_in[1]);
314472fcea8cSEd Schouten 			close(pipe_in[1]);
314572fcea8cSEd Schouten 			/*
314672fcea8cSEd Schouten 			 |	child will now continue down 'if (!in_pipe)'
314772fcea8cSEd Schouten 			 |	path below
314872fcea8cSEd Schouten 			 */
314972fcea8cSEd Schouten 		}
315072fcea8cSEd Schouten 		else  /* if the parent	*/
315172fcea8cSEd Schouten 		{
315272fcea8cSEd Schouten /*
315372fcea8cSEd Schouten  |  prepare editor to read from the pipe
315472fcea8cSEd Schouten  */
315572fcea8cSEd Schouten 			signal(SIGCHLD, SIG_IGN);
315672fcea8cSEd Schouten 			line_holder = curr_line;
315772fcea8cSEd Schouten 			tmp_vert = scr_vert;
315872fcea8cSEd Schouten 			close(pipe_in[1]);
315972fcea8cSEd Schouten 			get_fd = pipe_in[0];
316072fcea8cSEd Schouten 			get_file("");
316172fcea8cSEd Schouten 			close(pipe_in[0]);
316272fcea8cSEd Schouten 			scr_vert = tmp_vert;
316372fcea8cSEd Schouten 			scr_horz = scr_pos = 0;
316472fcea8cSEd Schouten 			position = 1;
316572fcea8cSEd Schouten 			curr_line = line_holder;
316696b676e9SEd Schouten 			from_top();
316772fcea8cSEd Schouten 			point = curr_line->line;
316872fcea8cSEd Schouten 			out_pipe = FALSE;
316972fcea8cSEd Schouten 			signal(SIGCHLD, SIG_DFL);
317072fcea8cSEd Schouten /*
317172fcea8cSEd Schouten  |  since flag "in_pipe" is still TRUE, the path which waits for the child
317272fcea8cSEd Schouten  |  process to die will be avoided.
317372fcea8cSEd Schouten  |  (the pipe is closed, no more output can be expected)
317472fcea8cSEd Schouten  */
317572fcea8cSEd Schouten 		}
317672fcea8cSEd Schouten 	}
317772fcea8cSEd Schouten 	if (!in_pipe)
317872fcea8cSEd Schouten 	{
317972fcea8cSEd Schouten 		signal(SIGINT, SIG_IGN);
318072fcea8cSEd Schouten 		if (out_pipe)
318172fcea8cSEd Schouten 		{
318272fcea8cSEd Schouten 			pipe(pipe_out);
318372fcea8cSEd Schouten 		}
318472fcea8cSEd Schouten /*
318572fcea8cSEd Schouten  |  fork process which will exec command
318672fcea8cSEd Schouten  */
318772fcea8cSEd Schouten 		parent = fork();
318872fcea8cSEd Schouten 		if (!parent)		/* if the child	*/
318972fcea8cSEd Schouten 		{
319072fcea8cSEd Schouten 			if (shell_fork)
319172fcea8cSEd Schouten 				putchar('\n');
319272fcea8cSEd Schouten 			if (out_pipe)
319372fcea8cSEd Schouten 			{
319472fcea8cSEd Schouten /*
319572fcea8cSEd Schouten  |  prepare the child process (soon to exec a shell command) to read from the
319672fcea8cSEd Schouten  |  pipe (which will be output from the editor's buffer)
319772fcea8cSEd Schouten  */
319872fcea8cSEd Schouten 				close(0);
319972fcea8cSEd Schouten 				dup(pipe_out[0]);
320072fcea8cSEd Schouten 				close(pipe_out[0]);
320172fcea8cSEd Schouten 				close(pipe_out[1]);
320272fcea8cSEd Schouten 			}
320372fcea8cSEd Schouten 			for (value = 1; value < 24; value++)
320472fcea8cSEd Schouten 				signal(value, SIG_DFL);
320596b676e9SEd Schouten 			execl(path, last_slash, "-c", string, NULL);
320696b676e9SEd Schouten 			fprintf(stderr, exec_err_msg, path);
320796b676e9SEd Schouten 			exit(-1);
320872fcea8cSEd Schouten 		}
320972fcea8cSEd Schouten 		else	/* if the parent	*/
321072fcea8cSEd Schouten 		{
321172fcea8cSEd Schouten 			if (out_pipe)
321272fcea8cSEd Schouten 			{
321372fcea8cSEd Schouten /*
321472fcea8cSEd Schouten  |  output the contents of the buffer to the pipe (to be read by the
321572fcea8cSEd Schouten  |  process forked and exec'd above as stdin)
321672fcea8cSEd Schouten  */
321772fcea8cSEd Schouten 				close(pipe_out[0]);
321872fcea8cSEd Schouten 				line_holder = first_line;
321972fcea8cSEd Schouten 				while (line_holder != NULL)
322072fcea8cSEd Schouten 				{
322172fcea8cSEd Schouten 					write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
322272fcea8cSEd Schouten 					write(pipe_out[1], "\n", 1);
322372fcea8cSEd Schouten 					line_holder = line_holder->next_line;
322472fcea8cSEd Schouten 				}
322572fcea8cSEd Schouten 				close(pipe_out[1]);
322672fcea8cSEd Schouten 				out_pipe = FALSE;
322772fcea8cSEd Schouten 			}
322872fcea8cSEd Schouten 			do
322972fcea8cSEd Schouten 			{
323072fcea8cSEd Schouten 				return_val = wait((int *) 0);
323172fcea8cSEd Schouten 			}
323272fcea8cSEd Schouten 			while ((return_val != parent) && (return_val != -1));
323372fcea8cSEd Schouten /*
323472fcea8cSEd Schouten  |  if this process is actually the child of the editor, exit.  Here's how it
323572fcea8cSEd Schouten  |  works:
323672fcea8cSEd Schouten  |  The editor forks a process.  If output must be sent to the command to be
323772fcea8cSEd Schouten  |  exec'd another process is forked, and that process (the child's child)
323872fcea8cSEd Schouten  |  will exec the command.  In this case, "shell_fork" will be FALSE.  If no
323972fcea8cSEd Schouten  |  output is to be performed to the shell command, "shell_fork" will be TRUE.
324072fcea8cSEd Schouten  |  If this is the editor process, shell_fork will be true, otherwise this is
324172fcea8cSEd Schouten  |  the child of the edit process.
324272fcea8cSEd Schouten  */
324372fcea8cSEd Schouten 			if (!shell_fork)
324472fcea8cSEd Schouten 				exit(0);
324572fcea8cSEd Schouten 		}
324672fcea8cSEd Schouten 		signal(SIGINT, edit_abort);
324772fcea8cSEd Schouten 	}
324872fcea8cSEd Schouten 	if (shell_fork)
324972fcea8cSEd Schouten 	{
325096b676e9SEd Schouten 		printf(continue_msg);
325172fcea8cSEd Schouten 		fflush(stdout);
325272fcea8cSEd Schouten 		while ((in = getchar()) != '\n')
325372fcea8cSEd Schouten 			;
325472fcea8cSEd Schouten 	}
325572fcea8cSEd Schouten 
325672fcea8cSEd Schouten 	if (!in_pipe)
325772fcea8cSEd Schouten 	{
325872fcea8cSEd Schouten 		fixterm();
325972fcea8cSEd Schouten 		noecho();
326072fcea8cSEd Schouten 		nonl();
326172fcea8cSEd Schouten 		raw();
326272fcea8cSEd Schouten 		keypad(text_win, TRUE);
326372fcea8cSEd Schouten 		keypad(com_win, TRUE);
326472fcea8cSEd Schouten 		if (info_window)
326572fcea8cSEd Schouten 			clearok(info_win, TRUE);
326672fcea8cSEd Schouten 	}
326772fcea8cSEd Schouten 
326872fcea8cSEd Schouten 	redraw();
326972fcea8cSEd Schouten }
327072fcea8cSEd Schouten 
327172fcea8cSEd Schouten void
327272fcea8cSEd Schouten set_up_term()		/* set up the terminal for operating with ae	*/
327372fcea8cSEd Schouten {
327472fcea8cSEd Schouten 	if (!curses_initialized)
327572fcea8cSEd Schouten 	{
327672fcea8cSEd Schouten 		initscr();
327772fcea8cSEd Schouten 		savetty();
327872fcea8cSEd Schouten 		noecho();
327972fcea8cSEd Schouten 		raw();
328072fcea8cSEd Schouten 		nonl();
328172fcea8cSEd Schouten 		curses_initialized = TRUE;
328272fcea8cSEd Schouten 	}
328372fcea8cSEd Schouten 
328472fcea8cSEd Schouten 	if (((LINES > 15) && (COLS >= 80)) && info_window)
328572fcea8cSEd Schouten 		last_line = LINES - 8;
328672fcea8cSEd Schouten 	else
328772fcea8cSEd Schouten 	{
328872fcea8cSEd Schouten 		info_window = FALSE;
328972fcea8cSEd Schouten 		last_line = LINES - 2;
329072fcea8cSEd Schouten 	}
329172fcea8cSEd Schouten 
329272fcea8cSEd Schouten 	idlok(stdscr, TRUE);
329372fcea8cSEd Schouten 	com_win = newwin(1, COLS, (LINES - 1), 0);
329472fcea8cSEd Schouten 	keypad(com_win, TRUE);
329572fcea8cSEd Schouten 	idlok(com_win, TRUE);
329672fcea8cSEd Schouten 	wrefresh(com_win);
329772fcea8cSEd Schouten 	if (!info_window)
329872fcea8cSEd Schouten 		text_win = newwin((LINES - 1), COLS, 0, 0);
329972fcea8cSEd Schouten 	else
330072fcea8cSEd Schouten 		text_win = newwin((LINES - 7), COLS, 6, 0);
330172fcea8cSEd Schouten 	keypad(text_win, TRUE);
330272fcea8cSEd Schouten 	idlok(text_win, TRUE);
330372fcea8cSEd Schouten 	wrefresh(text_win);
330472fcea8cSEd Schouten 	help_win = newwin((LINES - 1), COLS, 0, 0);
330572fcea8cSEd Schouten 	keypad(help_win, TRUE);
330672fcea8cSEd Schouten 	idlok(help_win, TRUE);
330772fcea8cSEd Schouten 	if (info_window)
330872fcea8cSEd Schouten 	{
330972fcea8cSEd Schouten 		info_type = CONTROL_KEYS;
331096b676e9SEd Schouten 		info_win = newwin(6, COLS, 0, 0);
331172fcea8cSEd Schouten 		werase(info_win);
331272fcea8cSEd Schouten 		paint_info_win();
331372fcea8cSEd Schouten 	}
331472fcea8cSEd Schouten 
331572fcea8cSEd Schouten 	last_col = COLS - 1;
331672fcea8cSEd Schouten 	local_LINES = LINES;
331772fcea8cSEd Schouten 	local_COLS = COLS;
331872fcea8cSEd Schouten 
331972fcea8cSEd Schouten #ifdef NCURSE
332072fcea8cSEd Schouten 	if (ee_chinese)
332172fcea8cSEd Schouten 		nc_setattrib(A_NC_BIG5);
332272fcea8cSEd Schouten #endif /* NCURSE */
332372fcea8cSEd Schouten 
332472fcea8cSEd Schouten }
332572fcea8cSEd Schouten 
332672fcea8cSEd Schouten void
332772fcea8cSEd Schouten resize_check()
332872fcea8cSEd Schouten {
332972fcea8cSEd Schouten 	if ((LINES == local_LINES) && (COLS == local_COLS))
333072fcea8cSEd Schouten 		return;
333172fcea8cSEd Schouten 
333272fcea8cSEd Schouten 	if (info_window)
333372fcea8cSEd Schouten 		delwin(info_win);
333472fcea8cSEd Schouten 	delwin(text_win);
333572fcea8cSEd Schouten 	delwin(com_win);
333672fcea8cSEd Schouten 	delwin(help_win);
333772fcea8cSEd Schouten 	set_up_term();
333872fcea8cSEd Schouten 	redraw();
333972fcea8cSEd Schouten 	wrefresh(text_win);
334072fcea8cSEd Schouten }
334172fcea8cSEd Schouten 
334272fcea8cSEd Schouten static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
334372fcea8cSEd Schouten 
334472fcea8cSEd Schouten int
334572fcea8cSEd Schouten menu_op(menu_list)
334672fcea8cSEd Schouten struct menu_entries menu_list[];
334772fcea8cSEd Schouten {
334872fcea8cSEd Schouten 	WINDOW *temp_win;
334972fcea8cSEd Schouten 	int max_width, max_height;
335072fcea8cSEd Schouten 	int x_off, y_off;
335172fcea8cSEd Schouten 	int counter;
335272fcea8cSEd Schouten 	int length;
335372fcea8cSEd Schouten 	int input;
335496b676e9SEd Schouten 	int temp;
335572fcea8cSEd Schouten 	int list_size;
335672fcea8cSEd Schouten 	int top_offset;		/* offset from top where menu items start */
335772fcea8cSEd Schouten 	int vert_pos;		/* vertical position			  */
335872fcea8cSEd Schouten 	int vert_size;		/* vertical size for menu list item display */
335972fcea8cSEd Schouten 	int off_start = 1;	/* offset from start of menu items to start display */
336072fcea8cSEd Schouten 
336172fcea8cSEd Schouten 
336272fcea8cSEd Schouten 	/*
336372fcea8cSEd Schouten 	 |	determine number and width of menu items
336472fcea8cSEd Schouten 	 */
336572fcea8cSEd Schouten 
336672fcea8cSEd Schouten 	list_size = 1;
336772fcea8cSEd Schouten 	while (menu_list[list_size + 1].item_string != NULL)
336872fcea8cSEd Schouten 		list_size++;
336972fcea8cSEd Schouten 	max_width = 0;
337072fcea8cSEd Schouten 	for (counter = 0; counter <= list_size; counter++)
337172fcea8cSEd Schouten 	{
337272fcea8cSEd Schouten 		if ((length = strlen(menu_list[counter].item_string)) > max_width)
337372fcea8cSEd Schouten 			max_width = length;
337472fcea8cSEd Schouten 	}
337572fcea8cSEd Schouten 	max_width += 3;
337672fcea8cSEd Schouten 	max_width = max(max_width, strlen(menu_cancel_msg));
337772fcea8cSEd Schouten 	max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
337872fcea8cSEd Schouten 	max_width += 6;
337972fcea8cSEd Schouten 
338072fcea8cSEd Schouten 	/*
338172fcea8cSEd Schouten 	 |	make sure that window is large enough to handle menu
338272fcea8cSEd Schouten 	 |	if not, print error message and return to calling function
338372fcea8cSEd Schouten 	 */
338472fcea8cSEd Schouten 
338572fcea8cSEd Schouten 	if (max_width > COLS)
338672fcea8cSEd Schouten 	{
338772fcea8cSEd Schouten 		wmove(com_win, 0, 0);
338872fcea8cSEd Schouten 		werase(com_win);
338972fcea8cSEd Schouten 		wprintw(com_win, menu_too_lrg_msg);
339072fcea8cSEd Schouten 		wrefresh(com_win);
339172fcea8cSEd Schouten 		clear_com_win = TRUE;
339272fcea8cSEd Schouten 		return(0);
339372fcea8cSEd Schouten 	}
339472fcea8cSEd Schouten 
339572fcea8cSEd Schouten 	top_offset = 0;
339672fcea8cSEd Schouten 
339772fcea8cSEd Schouten 	if (list_size > LINES)
339872fcea8cSEd Schouten 	{
339972fcea8cSEd Schouten 		max_height = LINES;
340072fcea8cSEd Schouten 		if (max_height > 11)
340172fcea8cSEd Schouten 			vert_size = max_height - 8;
340272fcea8cSEd Schouten 		else
340372fcea8cSEd Schouten 			vert_size = max_height;
340472fcea8cSEd Schouten 	}
340572fcea8cSEd Schouten 	else
340672fcea8cSEd Schouten 	{
340772fcea8cSEd Schouten 		vert_size = list_size;
340872fcea8cSEd Schouten 		max_height = list_size;
340972fcea8cSEd Schouten 	}
341072fcea8cSEd Schouten 
341172fcea8cSEd Schouten 	if (LINES >= (vert_size + 8))
341272fcea8cSEd Schouten 	{
341372fcea8cSEd Schouten 		if (menu_list[0].argument != MENU_WARN)
341472fcea8cSEd Schouten 			max_height = vert_size + 8;
341572fcea8cSEd Schouten 		else
341672fcea8cSEd Schouten 			max_height = vert_size + 7;
341772fcea8cSEd Schouten 		top_offset = 4;
341872fcea8cSEd Schouten 	}
341972fcea8cSEd Schouten 	x_off = (COLS - max_width) / 2;
342072fcea8cSEd Schouten 	y_off = (LINES - max_height - 1) / 2;
342172fcea8cSEd Schouten 	temp_win = newwin(max_height, max_width, y_off, x_off);
342272fcea8cSEd Schouten 	keypad(temp_win, TRUE);
342372fcea8cSEd Schouten 
342472fcea8cSEd Schouten 	paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
342572fcea8cSEd Schouten 
342672fcea8cSEd Schouten 	counter = 1;
342772fcea8cSEd Schouten 	vert_pos = 0;
342872fcea8cSEd Schouten 	do
342972fcea8cSEd Schouten 	{
343072fcea8cSEd Schouten 		if (off_start > 2)
343172fcea8cSEd Schouten 			wmove(temp_win, (1 + counter + top_offset - off_start), 3);
343272fcea8cSEd Schouten 		else
343372fcea8cSEd Schouten 			wmove(temp_win, (counter + top_offset - off_start), 3);
343472fcea8cSEd Schouten 
343572fcea8cSEd Schouten 		wrefresh(temp_win);
343696b676e9SEd Schouten 		in = wgetch(temp_win);
343796b676e9SEd Schouten 		input = in;
343896b676e9SEd Schouten 		if (input == -1)
343996b676e9SEd Schouten 			exit(0);
344072fcea8cSEd Schouten 
344172fcea8cSEd Schouten 		if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
344272fcea8cSEd Schouten 		    ((input >= '0') && (input <= '9')))
344372fcea8cSEd Schouten 		{
344472fcea8cSEd Schouten 			if ((tolower(input) >= 'a') && (tolower(input) <= 'z'))
344572fcea8cSEd Schouten 			{
344672fcea8cSEd Schouten 				temp = 1 + tolower(input) - 'a';
344772fcea8cSEd Schouten 			}
344872fcea8cSEd Schouten 			else if ((input >= '0') && (input <= '9'))
344972fcea8cSEd Schouten 			{
345072fcea8cSEd Schouten 				temp = (2 + 'z' - 'a') + (input - '0');
345172fcea8cSEd Schouten 			}
345272fcea8cSEd Schouten 
345372fcea8cSEd Schouten 			if (temp <= list_size)
345472fcea8cSEd Schouten 			{
345572fcea8cSEd Schouten 				input = '\n';
345672fcea8cSEd Schouten 				counter = temp;
345772fcea8cSEd Schouten 			}
345872fcea8cSEd Schouten 		}
345972fcea8cSEd Schouten 		else
346072fcea8cSEd Schouten 		{
346172fcea8cSEd Schouten 			switch (input)
346272fcea8cSEd Schouten 			{
346372fcea8cSEd Schouten 				case ' ':	/* space	*/
346472fcea8cSEd Schouten 				case '\004':	/* ^d, down	*/
346572fcea8cSEd Schouten 				case KEY_RIGHT:
346672fcea8cSEd Schouten 				case KEY_DOWN:
346772fcea8cSEd Schouten 					counter++;
346872fcea8cSEd Schouten 					if (counter > list_size)
346972fcea8cSEd Schouten 						counter = 1;
347072fcea8cSEd Schouten 					break;
347172fcea8cSEd Schouten 				case '\010':	/* ^h, backspace*/
347272fcea8cSEd Schouten 				case '\025':	/* ^u, up	*/
347372fcea8cSEd Schouten 				case 127:	/* ^?, delete	*/
347472fcea8cSEd Schouten 				case KEY_BACKSPACE:
347572fcea8cSEd Schouten 				case KEY_LEFT:
347672fcea8cSEd Schouten 				case KEY_UP:
347772fcea8cSEd Schouten 					counter--;
347872fcea8cSEd Schouten 					if (counter == 0)
347972fcea8cSEd Schouten 						counter = list_size;
348072fcea8cSEd Schouten 					break;
348172fcea8cSEd Schouten 				case '\033':	/* escape key	*/
348272fcea8cSEd Schouten 					if (menu_list[0].argument != MENU_WARN)
348372fcea8cSEd Schouten 						counter = 0;
348472fcea8cSEd Schouten 					break;
348572fcea8cSEd Schouten 				case '\014':	/* ^l       	*/
348672fcea8cSEd Schouten 				case '\022':	/* ^r, redraw	*/
348772fcea8cSEd Schouten 					paint_menu(menu_list, max_width, max_height,
348872fcea8cSEd Schouten 						list_size, top_offset, temp_win,
348972fcea8cSEd Schouten 						off_start, vert_size);
349072fcea8cSEd Schouten 					break;
349172fcea8cSEd Schouten 				default:
349272fcea8cSEd Schouten 					break;
349372fcea8cSEd Schouten 			}
349472fcea8cSEd Schouten 		}
349572fcea8cSEd Schouten 
349672fcea8cSEd Schouten 		if (((list_size - off_start) >= (vert_size - 1)) &&
349772fcea8cSEd Schouten 			(counter > (off_start + vert_size - 3)) &&
349872fcea8cSEd Schouten 				(off_start > 1))
349972fcea8cSEd Schouten 		{
350072fcea8cSEd Schouten 			if (counter == list_size)
350172fcea8cSEd Schouten 				off_start = (list_size - vert_size) + 2;
350272fcea8cSEd Schouten 			else
350372fcea8cSEd Schouten 				off_start++;
350472fcea8cSEd Schouten 
350572fcea8cSEd Schouten 			paint_menu(menu_list, max_width, max_height,
350672fcea8cSEd Schouten 				   list_size, top_offset, temp_win, off_start,
350772fcea8cSEd Schouten 				   vert_size);
350872fcea8cSEd Schouten 		}
350972fcea8cSEd Schouten 		else if ((list_size != vert_size) &&
351072fcea8cSEd Schouten 				(counter > (off_start + vert_size - 2)))
351172fcea8cSEd Schouten 		{
351272fcea8cSEd Schouten 			if (counter == list_size)
351372fcea8cSEd Schouten 				off_start = 2 + (list_size - vert_size);
351472fcea8cSEd Schouten 			else if (off_start == 1)
351572fcea8cSEd Schouten 				off_start = 3;
351672fcea8cSEd Schouten 			else
351772fcea8cSEd Schouten 				off_start++;
351872fcea8cSEd Schouten 
351972fcea8cSEd Schouten 			paint_menu(menu_list, max_width, max_height,
352072fcea8cSEd Schouten 				   list_size, top_offset, temp_win, off_start,
352172fcea8cSEd Schouten 				   vert_size);
352272fcea8cSEd Schouten 		}
352372fcea8cSEd Schouten 		else if (counter < off_start)
352472fcea8cSEd Schouten 		{
352572fcea8cSEd Schouten 			if (counter <= 2)
352672fcea8cSEd Schouten 				off_start = 1;
352772fcea8cSEd Schouten 			else
352872fcea8cSEd Schouten 				off_start = counter;
352972fcea8cSEd Schouten 
353072fcea8cSEd Schouten 			paint_menu(menu_list, max_width, max_height,
353172fcea8cSEd Schouten 				   list_size, top_offset, temp_win, off_start,
353272fcea8cSEd Schouten 				   vert_size);
353372fcea8cSEd Schouten 		}
353472fcea8cSEd Schouten 	}
353572fcea8cSEd Schouten 	while ((input != '\r') && (input != '\n') && (counter != 0));
353672fcea8cSEd Schouten 
353772fcea8cSEd Schouten 	werase(temp_win);
353872fcea8cSEd Schouten 	wrefresh(temp_win);
353972fcea8cSEd Schouten 	delwin(temp_win);
354072fcea8cSEd Schouten 
354172fcea8cSEd Schouten 	if ((menu_list[counter].procedure != NULL) ||
354272fcea8cSEd Schouten 	    (menu_list[counter].iprocedure != NULL) ||
354372fcea8cSEd Schouten 	    (menu_list[counter].nprocedure != NULL))
354472fcea8cSEd Schouten 	{
354572fcea8cSEd Schouten 		if (menu_list[counter].argument != -1)
354672fcea8cSEd Schouten 			(*menu_list[counter].iprocedure)(menu_list[counter].argument);
354772fcea8cSEd Schouten 		else if (menu_list[counter].ptr_argument != NULL)
354872fcea8cSEd Schouten 			(*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
354972fcea8cSEd Schouten 		else
355072fcea8cSEd Schouten 			(*menu_list[counter].nprocedure)();
355172fcea8cSEd Schouten 	}
355272fcea8cSEd Schouten 
355372fcea8cSEd Schouten 	if (info_window)
355472fcea8cSEd Schouten 		paint_info_win();
355572fcea8cSEd Schouten 	redraw();
355672fcea8cSEd Schouten 
355772fcea8cSEd Schouten 	return(counter);
355872fcea8cSEd Schouten }
355972fcea8cSEd Schouten 
356072fcea8cSEd Schouten void
356172fcea8cSEd Schouten paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
356272fcea8cSEd Schouten 	   off_start, vert_size)
356372fcea8cSEd Schouten struct menu_entries menu_list[];
356472fcea8cSEd Schouten int max_width, max_height, list_size, top_offset;
356572fcea8cSEd Schouten WINDOW *menu_win;
356672fcea8cSEd Schouten int off_start, vert_size;
356772fcea8cSEd Schouten {
356872fcea8cSEd Schouten 	int counter, temp_int;
356972fcea8cSEd Schouten 
357072fcea8cSEd Schouten 	werase(menu_win);
357172fcea8cSEd Schouten 
357272fcea8cSEd Schouten 	/*
357372fcea8cSEd Schouten 	 |	output top and bottom portions of menu box only if window
357472fcea8cSEd Schouten 	 |	large enough
357572fcea8cSEd Schouten 	 */
357672fcea8cSEd Schouten 
357772fcea8cSEd Schouten 	if (max_height > vert_size)
357872fcea8cSEd Schouten 	{
357972fcea8cSEd Schouten 		wmove(menu_win, 1, 1);
358072fcea8cSEd Schouten 		if (!nohighlight)
358172fcea8cSEd Schouten 			wstandout(menu_win);
358272fcea8cSEd Schouten 		waddch(menu_win, '+');
358372fcea8cSEd Schouten 		for (counter = 0; counter < (max_width - 4); counter++)
358472fcea8cSEd Schouten 			waddch(menu_win, '-');
358572fcea8cSEd Schouten 		waddch(menu_win, '+');
358672fcea8cSEd Schouten 
358772fcea8cSEd Schouten 		wmove(menu_win, (max_height - 2), 1);
358872fcea8cSEd Schouten 		waddch(menu_win, '+');
358972fcea8cSEd Schouten 		for (counter = 0; counter < (max_width - 4); counter++)
359072fcea8cSEd Schouten 			waddch(menu_win, '-');
359172fcea8cSEd Schouten 		waddch(menu_win, '+');
359272fcea8cSEd Schouten 		wstandend(menu_win);
359372fcea8cSEd Schouten 		wmove(menu_win, 2, 3);
359472fcea8cSEd Schouten 		waddstr(menu_win, menu_list[0].item_string);
359572fcea8cSEd Schouten 		wmove(menu_win, (max_height - 3), 3);
359672fcea8cSEd Schouten 		if (menu_list[0].argument != MENU_WARN)
359772fcea8cSEd Schouten 			waddstr(menu_win, menu_cancel_msg);
359872fcea8cSEd Schouten 	}
359972fcea8cSEd Schouten 	if (!nohighlight)
360072fcea8cSEd Schouten 		wstandout(menu_win);
360172fcea8cSEd Schouten 
360272fcea8cSEd Schouten 	for (counter = 0; counter < (vert_size + top_offset); counter++)
360372fcea8cSEd Schouten 	{
360472fcea8cSEd Schouten 		if (top_offset == 4)
360572fcea8cSEd Schouten 		{
360672fcea8cSEd Schouten 			temp_int = counter + 2;
360772fcea8cSEd Schouten 		}
360872fcea8cSEd Schouten 		else
360972fcea8cSEd Schouten 			temp_int = counter;
361072fcea8cSEd Schouten 
361172fcea8cSEd Schouten 		wmove(menu_win, temp_int, 1);
361272fcea8cSEd Schouten 		waddch(menu_win, '|');
361372fcea8cSEd Schouten 		wmove(menu_win, temp_int, (max_width - 2));
361472fcea8cSEd Schouten 		waddch(menu_win, '|');
361572fcea8cSEd Schouten 	}
361672fcea8cSEd Schouten 	wstandend(menu_win);
361772fcea8cSEd Schouten 
361872fcea8cSEd Schouten 	if (list_size > vert_size)
361972fcea8cSEd Schouten 	{
362072fcea8cSEd Schouten 		if (off_start >= 3)
362172fcea8cSEd Schouten 		{
362272fcea8cSEd Schouten 			temp_int = 1;
362372fcea8cSEd Schouten 			wmove(menu_win, top_offset, 3);
362472fcea8cSEd Schouten 			waddstr(menu_win, more_above_str);
362572fcea8cSEd Schouten 		}
362672fcea8cSEd Schouten 		else
362772fcea8cSEd Schouten 			temp_int = 0;
362872fcea8cSEd Schouten 
362972fcea8cSEd Schouten 		for (counter = off_start;
363072fcea8cSEd Schouten 			((temp_int + counter - off_start) < (vert_size - 1));
363172fcea8cSEd Schouten 				counter++)
363272fcea8cSEd Schouten 		{
363372fcea8cSEd Schouten 			wmove(menu_win, (top_offset + temp_int +
363472fcea8cSEd Schouten 						(counter - off_start)), 3);
363572fcea8cSEd Schouten 			if (list_size > 1)
363672fcea8cSEd Schouten 				wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
363772fcea8cSEd Schouten 			waddstr(menu_win, menu_list[counter].item_string);
363872fcea8cSEd Schouten 		}
363972fcea8cSEd Schouten 
364072fcea8cSEd Schouten 		wmove(menu_win, (top_offset + (vert_size - 1)), 3);
364172fcea8cSEd Schouten 
364272fcea8cSEd Schouten 		if (counter == list_size)
364372fcea8cSEd Schouten 		{
364472fcea8cSEd Schouten 			if (list_size > 1)
364572fcea8cSEd Schouten 				wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
364672fcea8cSEd Schouten 			wprintw(menu_win, menu_list[counter].item_string);
364772fcea8cSEd Schouten 		}
364872fcea8cSEd Schouten 		else
364972fcea8cSEd Schouten 			wprintw(menu_win, more_below_str);
365072fcea8cSEd Schouten 	}
365172fcea8cSEd Schouten 	else
365272fcea8cSEd Schouten 	{
365372fcea8cSEd Schouten 		for (counter = 1; counter <= list_size; counter++)
365472fcea8cSEd Schouten 		{
365572fcea8cSEd Schouten 			wmove(menu_win, (top_offset + counter - 1), 3);
365672fcea8cSEd Schouten 			if (list_size > 1)
365772fcea8cSEd Schouten 				wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
365872fcea8cSEd Schouten 			waddstr(menu_win, menu_list[counter].item_string);
365972fcea8cSEd Schouten 		}
366072fcea8cSEd Schouten 	}
366172fcea8cSEd Schouten }
366272fcea8cSEd Schouten 
366372fcea8cSEd Schouten void
366472fcea8cSEd Schouten help()
366572fcea8cSEd Schouten {
366672fcea8cSEd Schouten 	int counter;
366772fcea8cSEd Schouten 
366872fcea8cSEd Schouten 	werase(help_win);
366972fcea8cSEd Schouten 	clearok(help_win, TRUE);
367072fcea8cSEd Schouten 	for (counter = 0; counter < 22; counter++)
367172fcea8cSEd Schouten 	{
367272fcea8cSEd Schouten 		wmove(help_win, counter, 0);
367372fcea8cSEd Schouten 		waddstr(help_win, (emacs_keys_mode) ?
367472fcea8cSEd Schouten 			emacs_help_text[counter] : help_text[counter]);
367572fcea8cSEd Schouten 	}
367672fcea8cSEd Schouten 	wrefresh(help_win);
367772fcea8cSEd Schouten 	werase(com_win);
367872fcea8cSEd Schouten 	wmove(com_win, 0, 0);
367972fcea8cSEd Schouten 	wprintw(com_win, press_any_key_msg);
368072fcea8cSEd Schouten 	wrefresh(com_win);
368172fcea8cSEd Schouten 	counter = wgetch(com_win);
368296b676e9SEd Schouten 	if (counter == -1)
368396b676e9SEd Schouten 		exit(0);
368472fcea8cSEd Schouten 	werase(com_win);
368572fcea8cSEd Schouten 	wmove(com_win, 0, 0);
368672fcea8cSEd Schouten 	werase(help_win);
368772fcea8cSEd Schouten 	wrefresh(help_win);
368872fcea8cSEd Schouten 	wrefresh(com_win);
368972fcea8cSEd Schouten 	redraw();
369072fcea8cSEd Schouten }
369172fcea8cSEd Schouten 
369272fcea8cSEd Schouten void
369372fcea8cSEd Schouten paint_info_win()
369472fcea8cSEd Schouten {
369572fcea8cSEd Schouten 	int counter;
369672fcea8cSEd Schouten 
369772fcea8cSEd Schouten 	if (!info_window)
369872fcea8cSEd Schouten 		return;
369972fcea8cSEd Schouten 
370072fcea8cSEd Schouten 	werase(info_win);
370172fcea8cSEd Schouten 	for (counter = 0; counter < 5; counter++)
370272fcea8cSEd Schouten 	{
370372fcea8cSEd Schouten 		wmove(info_win, counter, 0);
370472fcea8cSEd Schouten 		wclrtoeol(info_win);
370572fcea8cSEd Schouten 		if (info_type == CONTROL_KEYS)
370672fcea8cSEd Schouten 			waddstr(info_win, (emacs_keys_mode) ?
370772fcea8cSEd Schouten 			  emacs_control_keys[counter] : control_keys[counter]);
370872fcea8cSEd Schouten 		else if (info_type == COMMANDS)
370972fcea8cSEd Schouten 			waddstr(info_win, command_strings[counter]);
371072fcea8cSEd Schouten 	}
371196b676e9SEd Schouten 	wmove(info_win, 5, 0);
371296b676e9SEd Schouten 	if (!nohighlight)
371396b676e9SEd Schouten 		wstandout(info_win);
371496b676e9SEd Schouten 	waddstr(info_win, separator);
371596b676e9SEd Schouten 	wstandend(info_win);
371672fcea8cSEd Schouten 	wrefresh(info_win);
371772fcea8cSEd Schouten }
371872fcea8cSEd Schouten 
371972fcea8cSEd Schouten void
372072fcea8cSEd Schouten no_info_window()
372172fcea8cSEd Schouten {
372272fcea8cSEd Schouten 	if (!info_window)
372372fcea8cSEd Schouten 		return;
372472fcea8cSEd Schouten 	delwin(info_win);
372572fcea8cSEd Schouten 	delwin(text_win);
372672fcea8cSEd Schouten 	info_window = FALSE;
372772fcea8cSEd Schouten 	last_line = LINES - 2;
372872fcea8cSEd Schouten 	text_win = newwin((LINES - 1), COLS, 0, 0);
372972fcea8cSEd Schouten 	keypad(text_win, TRUE);
373072fcea8cSEd Schouten 	idlok(text_win, TRUE);
373172fcea8cSEd Schouten 	clearok(text_win, TRUE);
373272fcea8cSEd Schouten 	midscreen(scr_vert, point);
373372fcea8cSEd Schouten 	wrefresh(text_win);
373472fcea8cSEd Schouten 	clear_com_win = TRUE;
373572fcea8cSEd Schouten }
373672fcea8cSEd Schouten 
373772fcea8cSEd Schouten void
373872fcea8cSEd Schouten create_info_window()
373972fcea8cSEd Schouten {
374072fcea8cSEd Schouten 	if (info_window)
374172fcea8cSEd Schouten 		return;
374272fcea8cSEd Schouten 	last_line = LINES - 8;
374372fcea8cSEd Schouten 	delwin(text_win);
374472fcea8cSEd Schouten 	text_win = newwin((LINES - 7), COLS, 6, 0);
374572fcea8cSEd Schouten 	keypad(text_win, TRUE);
374672fcea8cSEd Schouten 	idlok(text_win, TRUE);
374772fcea8cSEd Schouten 	werase(text_win);
374872fcea8cSEd Schouten 	info_window = TRUE;
374996b676e9SEd Schouten 	info_win = newwin(6, COLS, 0, 0);
375072fcea8cSEd Schouten 	werase(info_win);
375172fcea8cSEd Schouten 	info_type = CONTROL_KEYS;
375272fcea8cSEd Schouten 	midscreen(min(scr_vert, last_line), point);
375372fcea8cSEd Schouten 	clearok(info_win, TRUE);
375472fcea8cSEd Schouten 	paint_info_win();
375572fcea8cSEd Schouten 	wrefresh(text_win);
375672fcea8cSEd Schouten 	clear_com_win = TRUE;
375772fcea8cSEd Schouten }
375872fcea8cSEd Schouten 
375972fcea8cSEd Schouten int
376072fcea8cSEd Schouten file_op(arg)
376172fcea8cSEd Schouten int arg;
376272fcea8cSEd Schouten {
376372fcea8cSEd Schouten 	char *string;
376472fcea8cSEd Schouten 	int flag;
376572fcea8cSEd Schouten 
376672fcea8cSEd Schouten 	if (restrict_mode())
376772fcea8cSEd Schouten 	{
376872fcea8cSEd Schouten 		return(0);
376972fcea8cSEd Schouten 	}
377072fcea8cSEd Schouten 
377172fcea8cSEd Schouten 	if (arg == READ_FILE)
377272fcea8cSEd Schouten 	{
377372fcea8cSEd Schouten 		string = get_string(file_read_prompt_str, TRUE);
377472fcea8cSEd Schouten 		recv_file = TRUE;
377572fcea8cSEd Schouten 		tmp_file = resolve_name(string);
377672fcea8cSEd Schouten 		check_fp();
377772fcea8cSEd Schouten 		if (tmp_file != string)
377872fcea8cSEd Schouten 			free(tmp_file);
377972fcea8cSEd Schouten 		free(string);
378072fcea8cSEd Schouten 	}
378172fcea8cSEd Schouten 	else if (arg == WRITE_FILE)
378272fcea8cSEd Schouten 	{
378372fcea8cSEd Schouten 		string = get_string(file_write_prompt_str, TRUE);
378472fcea8cSEd Schouten 		tmp_file = resolve_name(string);
3785cfe04e82SEd Schouten 		write_file(tmp_file, 1);
378672fcea8cSEd Schouten 		if (tmp_file != string)
378772fcea8cSEd Schouten 			free(tmp_file);
378872fcea8cSEd Schouten 		free(string);
378972fcea8cSEd Schouten 	}
379072fcea8cSEd Schouten 	else if (arg == SAVE_FILE)
379172fcea8cSEd Schouten 	{
379272fcea8cSEd Schouten 	/*
379372fcea8cSEd Schouten 	 |	changes made here should be reflected in finish()
379472fcea8cSEd Schouten 	 */
379572fcea8cSEd Schouten 
379672fcea8cSEd Schouten 		if (in_file_name)
379772fcea8cSEd Schouten 			flag = TRUE;
379872fcea8cSEd Schouten 		else
379972fcea8cSEd Schouten 			flag = FALSE;
380072fcea8cSEd Schouten 
380172fcea8cSEd Schouten 		string = in_file_name;
380296b676e9SEd Schouten 		if ((string == NULL) || (*string == '\0'))
380372fcea8cSEd Schouten 			string = get_string(save_file_name_prompt, TRUE);
380496b676e9SEd Schouten 		if ((string == NULL) || (*string == '\0'))
380572fcea8cSEd Schouten 		{
380672fcea8cSEd Schouten 			wmove(com_win, 0, 0);
380772fcea8cSEd Schouten 			wprintw(com_win, file_not_saved_msg);
380872fcea8cSEd Schouten 			wclrtoeol(com_win);
380972fcea8cSEd Schouten 			wrefresh(com_win);
381072fcea8cSEd Schouten 			clear_com_win = TRUE;
381172fcea8cSEd Schouten 			return(0);
381272fcea8cSEd Schouten 		}
381372fcea8cSEd Schouten 		if (!flag)
381472fcea8cSEd Schouten 		{
381572fcea8cSEd Schouten 			tmp_file = resolve_name(string);
381672fcea8cSEd Schouten 			if (tmp_file != string)
381772fcea8cSEd Schouten 			{
381872fcea8cSEd Schouten 				free(string);
381972fcea8cSEd Schouten 				string = tmp_file;
382072fcea8cSEd Schouten 			}
382172fcea8cSEd Schouten 		}
3822cfe04e82SEd Schouten 		if (write_file(string, 1))
382372fcea8cSEd Schouten 		{
382472fcea8cSEd Schouten 			in_file_name = string;
382572fcea8cSEd Schouten 			text_changes = FALSE;
382672fcea8cSEd Schouten 		}
382772fcea8cSEd Schouten 		else if (!flag)
382872fcea8cSEd Schouten 			free(string);
382972fcea8cSEd Schouten 	}
383072fcea8cSEd Schouten 	return(0);
383172fcea8cSEd Schouten }
383272fcea8cSEd Schouten 
383372fcea8cSEd Schouten void
383472fcea8cSEd Schouten shell_op()
383572fcea8cSEd Schouten {
383672fcea8cSEd Schouten 	char *string;
383772fcea8cSEd Schouten 
383872fcea8cSEd Schouten 	if (((string = get_string(shell_prompt, TRUE)) != NULL) &&
383996b676e9SEd Schouten 			(*string != '\0'))
384072fcea8cSEd Schouten 	{
384172fcea8cSEd Schouten 		sh_command(string);
384272fcea8cSEd Schouten 		free(string);
384372fcea8cSEd Schouten 	}
384472fcea8cSEd Schouten }
384572fcea8cSEd Schouten 
384672fcea8cSEd Schouten void
384772fcea8cSEd Schouten leave_op()
384872fcea8cSEd Schouten {
384972fcea8cSEd Schouten 	if (text_changes)
385072fcea8cSEd Schouten 	{
385172fcea8cSEd Schouten 		menu_op(leave_menu);
385272fcea8cSEd Schouten 	}
385372fcea8cSEd Schouten 	else
385472fcea8cSEd Schouten 		quit(TRUE);
385572fcea8cSEd Schouten }
385672fcea8cSEd Schouten 
385772fcea8cSEd Schouten void
385872fcea8cSEd Schouten redraw()
385972fcea8cSEd Schouten {
386072fcea8cSEd Schouten 	if (info_window)
386172fcea8cSEd Schouten         {
386272fcea8cSEd Schouten                 clearok(info_win, TRUE);
386372fcea8cSEd Schouten         	paint_info_win();
386472fcea8cSEd Schouten         }
386572fcea8cSEd Schouten         else
386672fcea8cSEd Schouten 		clearok(text_win, TRUE);
386772fcea8cSEd Schouten 	midscreen(scr_vert, point);
386872fcea8cSEd Schouten }
386972fcea8cSEd Schouten 
387072fcea8cSEd Schouten /*
387172fcea8cSEd Schouten  |	The following routines will "format" a paragraph (as defined by a
387272fcea8cSEd Schouten  |	block of text with blank lines before and after the block).
387372fcea8cSEd Schouten  */
387472fcea8cSEd Schouten 
387572fcea8cSEd Schouten int
387672fcea8cSEd Schouten Blank_Line(test_line)	/* test if line has any non-space characters	*/
387772fcea8cSEd Schouten struct text *test_line;
387872fcea8cSEd Schouten {
387972fcea8cSEd Schouten 	unsigned char *line;
388072fcea8cSEd Schouten 	int length;
388172fcea8cSEd Schouten 
388272fcea8cSEd Schouten 	if (test_line == NULL)
388372fcea8cSEd Schouten 		return(TRUE);
388472fcea8cSEd Schouten 
388572fcea8cSEd Schouten 	length = 1;
388672fcea8cSEd Schouten 	line = test_line->line;
388772fcea8cSEd Schouten 
388872fcea8cSEd Schouten 	/*
388972fcea8cSEd Schouten 	 |	To handle troff/nroff documents, consider a line with a
389072fcea8cSEd Schouten 	 |	period ('.') in the first column to be blank.  To handle mail
389172fcea8cSEd Schouten 	 |	messages with included text, consider a line with a '>' blank.
389272fcea8cSEd Schouten 	 */
389372fcea8cSEd Schouten 
389472fcea8cSEd Schouten 	if ((*line == '.') || (*line == '>'))
389572fcea8cSEd Schouten 		return(TRUE);
389672fcea8cSEd Schouten 
389772fcea8cSEd Schouten 	while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
389872fcea8cSEd Schouten 	{
389972fcea8cSEd Schouten 		length++;
390072fcea8cSEd Schouten 		line++;
390172fcea8cSEd Schouten 	}
390272fcea8cSEd Schouten 	if (length != test_line->line_length)
390372fcea8cSEd Schouten 		return(FALSE);
390472fcea8cSEd Schouten 	else
390572fcea8cSEd Schouten 		return(TRUE);
390672fcea8cSEd Schouten }
390772fcea8cSEd Schouten 
390872fcea8cSEd Schouten void
390972fcea8cSEd Schouten Format()	/* format the paragraph according to set margins	*/
391072fcea8cSEd Schouten {
391172fcea8cSEd Schouten 	int string_count;
391272fcea8cSEd Schouten 	int offset;
391372fcea8cSEd Schouten 	int temp_case;
391472fcea8cSEd Schouten 	int status;
391572fcea8cSEd Schouten 	int tmp_af;
391672fcea8cSEd Schouten 	int counter;
391772fcea8cSEd Schouten 	unsigned char *line;
391872fcea8cSEd Schouten 	unsigned char *tmp_srchstr;
391972fcea8cSEd Schouten 	unsigned char *temp1, *temp2;
392072fcea8cSEd Schouten 	unsigned char *temp_dword;
392172fcea8cSEd Schouten 	unsigned char temp_d_char[3];
392272fcea8cSEd Schouten 
392372fcea8cSEd Schouten 	temp_d_char[0] = d_char[0];
392472fcea8cSEd Schouten 	temp_d_char[1] = d_char[1];
392572fcea8cSEd Schouten 	temp_d_char[2] = d_char[2];
392672fcea8cSEd Schouten 
392772fcea8cSEd Schouten /*
392872fcea8cSEd Schouten  |	if observ_margins is not set, or the current line is blank,
392972fcea8cSEd Schouten  |	do not format the current paragraph
393072fcea8cSEd Schouten  */
393172fcea8cSEd Schouten 
393272fcea8cSEd Schouten 	if ((!observ_margins) || (Blank_Line(curr_line)))
393372fcea8cSEd Schouten 		return;
393472fcea8cSEd Schouten 
393572fcea8cSEd Schouten /*
393672fcea8cSEd Schouten  |	save the currently set flags, and clear them
393772fcea8cSEd Schouten  */
393872fcea8cSEd Schouten 
393972fcea8cSEd Schouten 	wmove(com_win, 0, 0);
394072fcea8cSEd Schouten 	wclrtoeol(com_win);
394172fcea8cSEd Schouten 	wprintw(com_win, formatting_msg);
394272fcea8cSEd Schouten 	wrefresh(com_win);
394372fcea8cSEd Schouten 
394472fcea8cSEd Schouten /*
394572fcea8cSEd Schouten  |	get current position in paragraph, so after formatting, the cursor
394672fcea8cSEd Schouten  |	will be in the same relative position
394772fcea8cSEd Schouten  */
394872fcea8cSEd Schouten 
394972fcea8cSEd Schouten 	tmp_af = auto_format;
395072fcea8cSEd Schouten 	auto_format = FALSE;
395172fcea8cSEd Schouten 	offset = position;
395272fcea8cSEd Schouten 	if (position != 1)
395372fcea8cSEd Schouten 		prev_word();
395472fcea8cSEd Schouten 	temp_dword = d_word;
395572fcea8cSEd Schouten 	d_word = NULL;
395672fcea8cSEd Schouten 	temp_case = case_sen;
395772fcea8cSEd Schouten 	case_sen = TRUE;
395872fcea8cSEd Schouten 	tmp_srchstr = srch_str;
395972fcea8cSEd Schouten 	temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
396072fcea8cSEd Schouten 	if ((*point == ' ') || (*point == '\t'))
396172fcea8cSEd Schouten 		adv_word();
396272fcea8cSEd Schouten 	offset -= position;
396372fcea8cSEd Schouten 	counter = position;
396472fcea8cSEd Schouten 	line = temp1 = point;
396596b676e9SEd Schouten 	while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
396672fcea8cSEd Schouten 	{
396772fcea8cSEd Schouten 		*temp2 = *temp1;
396872fcea8cSEd Schouten 		temp2++;
396972fcea8cSEd Schouten 		temp1++;
397072fcea8cSEd Schouten 		counter++;
397172fcea8cSEd Schouten 	}
397296b676e9SEd Schouten 	*temp2 = '\0';
397372fcea8cSEd Schouten 	if (position != 1)
397472fcea8cSEd Schouten 		bol();
397572fcea8cSEd Schouten 	while (!Blank_Line(curr_line->prev_line))
397672fcea8cSEd Schouten 		bol();
397772fcea8cSEd Schouten 	string_count = 0;
397872fcea8cSEd Schouten 	status = TRUE;
397972fcea8cSEd Schouten 	while ((line != point) && (status))
398072fcea8cSEd Schouten 	{
398172fcea8cSEd Schouten 		status = search(FALSE);
398272fcea8cSEd Schouten 		string_count++;
398372fcea8cSEd Schouten 	}
398472fcea8cSEd Schouten 
398572fcea8cSEd Schouten 	wmove(com_win, 0, 0);
398672fcea8cSEd Schouten 	wclrtoeol(com_win);
398772fcea8cSEd Schouten 	wprintw(com_win, formatting_msg);
398872fcea8cSEd Schouten 	wrefresh(com_win);
398972fcea8cSEd Schouten 
399072fcea8cSEd Schouten /*
399172fcea8cSEd Schouten  |	now get back to the start of the paragraph to start formatting
399272fcea8cSEd Schouten  */
399372fcea8cSEd Schouten 
399472fcea8cSEd Schouten 	if (position != 1)
399572fcea8cSEd Schouten 		bol();
399672fcea8cSEd Schouten 	while (!Blank_Line(curr_line->prev_line))
399772fcea8cSEd Schouten 		bol();
399872fcea8cSEd Schouten 
399972fcea8cSEd Schouten 	observ_margins = FALSE;
400072fcea8cSEd Schouten 
400172fcea8cSEd Schouten /*
400272fcea8cSEd Schouten  |	Start going through lines, putting spaces at end of lines if they do
400372fcea8cSEd Schouten  |	not already exist.  Append lines together to get one long line, and
400472fcea8cSEd Schouten  |	eliminate spacing at begin of lines.
400572fcea8cSEd Schouten  */
400672fcea8cSEd Schouten 
400772fcea8cSEd Schouten 	while (!Blank_Line(curr_line->next_line))
400872fcea8cSEd Schouten 	{
400972fcea8cSEd Schouten 		eol();
401072fcea8cSEd Schouten 		left(TRUE);
401172fcea8cSEd Schouten 		if (*point != ' ')
401272fcea8cSEd Schouten 		{
401372fcea8cSEd Schouten 			right(TRUE);
401472fcea8cSEd Schouten 			insert(' ');
401572fcea8cSEd Schouten 		}
401672fcea8cSEd Schouten 		else
401772fcea8cSEd Schouten 			right(TRUE);
401872fcea8cSEd Schouten 		del_char();
401972fcea8cSEd Schouten 		if ((*point == ' ') || (*point == '\t'))
402072fcea8cSEd Schouten 			del_word();
402172fcea8cSEd Schouten 	}
402272fcea8cSEd Schouten 
402372fcea8cSEd Schouten /*
402472fcea8cSEd Schouten  |	Now there is one long line.  Eliminate extra spaces within the line
402572fcea8cSEd Schouten  |	after the first word (so as not to blow away any indenting the user
402672fcea8cSEd Schouten  |	may have put in).
402772fcea8cSEd Schouten  */
402872fcea8cSEd Schouten 
402972fcea8cSEd Schouten 	bol();
403072fcea8cSEd Schouten 	adv_word();
403172fcea8cSEd Schouten 	while (position < curr_line->line_length)
403272fcea8cSEd Schouten 	{
403372fcea8cSEd Schouten 		if ((*point == ' ') && (*(point + 1) == ' '))
403472fcea8cSEd Schouten 			del_char();
403572fcea8cSEd Schouten 		else
403672fcea8cSEd Schouten 			right(TRUE);
403772fcea8cSEd Schouten 	}
403872fcea8cSEd Schouten 
403972fcea8cSEd Schouten /*
404072fcea8cSEd Schouten  |	Now make sure there are two spaces after a '.'.
404172fcea8cSEd Schouten  */
404272fcea8cSEd Schouten 
404372fcea8cSEd Schouten 	bol();
404472fcea8cSEd Schouten 	while (position < curr_line->line_length)
404572fcea8cSEd Schouten 	{
404672fcea8cSEd Schouten 		if ((*point == '.') && (*(point + 1) == ' '))
404772fcea8cSEd Schouten 		{
404872fcea8cSEd Schouten 			right(TRUE);
404972fcea8cSEd Schouten 			insert(' ');
405072fcea8cSEd Schouten 			insert(' ');
405172fcea8cSEd Schouten 			while (*point == ' ')
405272fcea8cSEd Schouten 				del_char();
405372fcea8cSEd Schouten 		}
405472fcea8cSEd Schouten 		right(TRUE);
405572fcea8cSEd Schouten 	}
405672fcea8cSEd Schouten 
405772fcea8cSEd Schouten 	observ_margins = TRUE;
405872fcea8cSEd Schouten 	bol();
405972fcea8cSEd Schouten 
406072fcea8cSEd Schouten 	wmove(com_win, 0, 0);
406172fcea8cSEd Schouten 	wclrtoeol(com_win);
406272fcea8cSEd Schouten 	wprintw(com_win, formatting_msg);
406372fcea8cSEd Schouten 	wrefresh(com_win);
406472fcea8cSEd Schouten 
406572fcea8cSEd Schouten /*
406672fcea8cSEd Schouten  |	create lines between margins
406772fcea8cSEd Schouten  */
406872fcea8cSEd Schouten 
406972fcea8cSEd Schouten 	while (position < curr_line->line_length)
407072fcea8cSEd Schouten 	{
407172fcea8cSEd Schouten 		while ((scr_pos < right_margin) && (position < curr_line->line_length))
407272fcea8cSEd Schouten 			right(TRUE);
407372fcea8cSEd Schouten 		if (position < curr_line->line_length)
407472fcea8cSEd Schouten 		{
407572fcea8cSEd Schouten 			prev_word();
407672fcea8cSEd Schouten 			if (position == 1)
407772fcea8cSEd Schouten 				adv_word();
407872fcea8cSEd Schouten 			insert_line(TRUE);
407972fcea8cSEd Schouten 		}
408072fcea8cSEd Schouten 	}
408172fcea8cSEd Schouten 
408272fcea8cSEd Schouten /*
408372fcea8cSEd Schouten  |	go back to begin of paragraph, put cursor back to original position
408472fcea8cSEd Schouten  */
408572fcea8cSEd Schouten 
408672fcea8cSEd Schouten 	bol();
408772fcea8cSEd Schouten 	while (!Blank_Line(curr_line->prev_line))
408872fcea8cSEd Schouten 		bol();
408972fcea8cSEd Schouten 
409072fcea8cSEd Schouten /*
409172fcea8cSEd Schouten  |	find word cursor was in
409272fcea8cSEd Schouten  */
409372fcea8cSEd Schouten 
409472fcea8cSEd Schouten 	while ((status) && (string_count > 0))
409572fcea8cSEd Schouten 	{
409672fcea8cSEd Schouten 		search(FALSE);
409772fcea8cSEd Schouten 		string_count--;
409872fcea8cSEd Schouten 	}
409972fcea8cSEd Schouten 
410072fcea8cSEd Schouten /*
410172fcea8cSEd Schouten  |	offset the cursor to where it was before from the start of the word
410272fcea8cSEd Schouten  */
410372fcea8cSEd Schouten 
410472fcea8cSEd Schouten 	while (offset > 0)
410572fcea8cSEd Schouten 	{
410672fcea8cSEd Schouten 		offset--;
410772fcea8cSEd Schouten 		right(TRUE);
410872fcea8cSEd Schouten 	}
410972fcea8cSEd Schouten 
411072fcea8cSEd Schouten /*
411172fcea8cSEd Schouten  |	reset flags and strings to what they were before formatting
411272fcea8cSEd Schouten  */
411372fcea8cSEd Schouten 
411472fcea8cSEd Schouten 	if (d_word != NULL)
411572fcea8cSEd Schouten 		free(d_word);
411672fcea8cSEd Schouten 	d_word = temp_dword;
411772fcea8cSEd Schouten 	case_sen = temp_case;
411872fcea8cSEd Schouten 	free(srch_str);
411972fcea8cSEd Schouten 	srch_str = tmp_srchstr;
412072fcea8cSEd Schouten 	d_char[0] = temp_d_char[0];
412172fcea8cSEd Schouten 	d_char[1] = temp_d_char[1];
412272fcea8cSEd Schouten 	d_char[2] = temp_d_char[2];
412372fcea8cSEd Schouten 	auto_format = tmp_af;
412472fcea8cSEd Schouten 
412572fcea8cSEd Schouten 	midscreen(scr_vert, point);
412672fcea8cSEd Schouten 	werase(com_win);
412772fcea8cSEd Schouten 	wrefresh(com_win);
412872fcea8cSEd Schouten }
412972fcea8cSEd Schouten 
413072fcea8cSEd Schouten unsigned char *init_name[3] = {
4131cfe04e82SEd Schouten 	"/usr/share/misc/init.ee",
413272fcea8cSEd Schouten 	NULL,
413372fcea8cSEd Schouten 	".init.ee"
413472fcea8cSEd Schouten 	};
413572fcea8cSEd Schouten 
413672fcea8cSEd Schouten void
413772fcea8cSEd Schouten ee_init()	/* check for init file and read it if it exists	*/
413872fcea8cSEd Schouten {
413972fcea8cSEd Schouten 	FILE *init_file;
414072fcea8cSEd Schouten 	unsigned char *string;
414172fcea8cSEd Schouten 	unsigned char *str1;
414272fcea8cSEd Schouten 	unsigned char *str2;
414372fcea8cSEd Schouten 	char *home;
414472fcea8cSEd Schouten 	int counter;
414572fcea8cSEd Schouten 	int temp_int;
414672fcea8cSEd Schouten 
414772fcea8cSEd Schouten 	string = getenv("HOME");
414896b676e9SEd Schouten 	if (string == NULL)
414996b676e9SEd Schouten 		string = "/tmp";
415072fcea8cSEd Schouten 	str1 = home = malloc(strlen(string)+10);
415172fcea8cSEd Schouten 	strcpy(home, string);
415272fcea8cSEd Schouten 	strcat(home, "/.init.ee");
415372fcea8cSEd Schouten 	init_name[1] = home;
415472fcea8cSEd Schouten 	string = malloc(512);
415572fcea8cSEd Schouten 
415672fcea8cSEd Schouten 	for (counter = 0; counter < 3; counter++)
415772fcea8cSEd Schouten 	{
415872fcea8cSEd Schouten 		if (!(access(init_name[counter], 4)))
415972fcea8cSEd Schouten 		{
416072fcea8cSEd Schouten 			init_file = fopen(init_name[counter], "r");
416172fcea8cSEd Schouten 			while ((str2 = fgets(string, 512, init_file)) != NULL)
416272fcea8cSEd Schouten 			{
416372fcea8cSEd Schouten 				str1 = str2 = string;
416472fcea8cSEd Schouten 				while (*str2 != '\n')
416572fcea8cSEd Schouten 					str2++;
416696b676e9SEd Schouten 				*str2 = '\0';
416772fcea8cSEd Schouten 
416872fcea8cSEd Schouten 				if (unique_test(string, init_strings) != 1)
416972fcea8cSEd Schouten 					continue;
417072fcea8cSEd Schouten 
417172fcea8cSEd Schouten 				if (compare(str1, CASE, FALSE))
417272fcea8cSEd Schouten 					case_sen = TRUE;
417372fcea8cSEd Schouten 				else if (compare(str1, NOCASE, FALSE))
417472fcea8cSEd Schouten 					case_sen = FALSE;
417572fcea8cSEd Schouten 				else if (compare(str1, EXPAND, FALSE))
417672fcea8cSEd Schouten 					expand_tabs = TRUE;
417772fcea8cSEd Schouten 				else if (compare(str1, NOEXPAND, FALSE))
417872fcea8cSEd Schouten 					expand_tabs = FALSE;
417972fcea8cSEd Schouten 				else if (compare(str1, INFO, FALSE))
418072fcea8cSEd Schouten 					info_window = TRUE;
418172fcea8cSEd Schouten 				else if (compare(str1, NOINFO, FALSE))
418272fcea8cSEd Schouten 					info_window = FALSE;
418372fcea8cSEd Schouten 				else if (compare(str1, MARGINS, FALSE))
418472fcea8cSEd Schouten 					observ_margins = TRUE;
418572fcea8cSEd Schouten 				else if (compare(str1, NOMARGINS, FALSE))
418672fcea8cSEd Schouten 					observ_margins = FALSE;
418772fcea8cSEd Schouten 				else if (compare(str1, AUTOFORMAT, FALSE))
418872fcea8cSEd Schouten 				{
418972fcea8cSEd Schouten 					auto_format = TRUE;
419072fcea8cSEd Schouten 					observ_margins = TRUE;
419172fcea8cSEd Schouten 				}
419272fcea8cSEd Schouten 				else if (compare(str1, NOAUTOFORMAT, FALSE))
419372fcea8cSEd Schouten 					auto_format = FALSE;
419472fcea8cSEd Schouten 				else if (compare(str1, Echo, FALSE))
419572fcea8cSEd Schouten 				{
419672fcea8cSEd Schouten 					str1 = next_word(str1);
419796b676e9SEd Schouten 					if (*str1 != '\0')
419872fcea8cSEd Schouten 						echo_string(str1);
419972fcea8cSEd Schouten 				}
420072fcea8cSEd Schouten 				else if (compare(str1, PRINTCOMMAND, FALSE))
420172fcea8cSEd Schouten 				{
420272fcea8cSEd Schouten 					str1 = next_word(str1);
420372fcea8cSEd Schouten 					print_command = malloc(strlen(str1)+1);
420472fcea8cSEd Schouten 					strcpy(print_command, str1);
420572fcea8cSEd Schouten 				}
420672fcea8cSEd Schouten 				else if (compare(str1, RIGHTMARGIN, FALSE))
420772fcea8cSEd Schouten 				{
420872fcea8cSEd Schouten 					str1 = next_word(str1);
420972fcea8cSEd Schouten 					if ((*str1 >= '0') && (*str1 <= '9'))
421072fcea8cSEd Schouten 					{
421172fcea8cSEd Schouten 						temp_int = atoi(str1);
421272fcea8cSEd Schouten 						if (temp_int > 0)
421372fcea8cSEd Schouten 							right_margin = temp_int;
421472fcea8cSEd Schouten 					}
421572fcea8cSEd Schouten 				}
421672fcea8cSEd Schouten 				else if (compare(str1, HIGHLIGHT, FALSE))
421772fcea8cSEd Schouten 					nohighlight = FALSE;
421872fcea8cSEd Schouten 				else if (compare(str1, NOHIGHLIGHT, FALSE))
421972fcea8cSEd Schouten 					nohighlight = TRUE;
422072fcea8cSEd Schouten 				else if (compare(str1, EIGHTBIT, FALSE))
422172fcea8cSEd Schouten 					eightbit = TRUE;
422272fcea8cSEd Schouten 				else if (compare(str1, NOEIGHTBIT, FALSE))
422372fcea8cSEd Schouten 				{
422472fcea8cSEd Schouten 					eightbit = FALSE;
422572fcea8cSEd Schouten 					ee_chinese = FALSE;
422672fcea8cSEd Schouten 				}
422772fcea8cSEd Schouten 				else if (compare(str1, EMACS_string, FALSE))
422872fcea8cSEd Schouten 					emacs_keys_mode = TRUE;
422972fcea8cSEd Schouten 				else if (compare(str1, NOEMACS_string, FALSE))
423072fcea8cSEd Schouten 					emacs_keys_mode = FALSE;
423172fcea8cSEd Schouten 				else if (compare(str1, chinese_cmd, FALSE))
423272fcea8cSEd Schouten 				{
423372fcea8cSEd Schouten 					ee_chinese = TRUE;
423472fcea8cSEd Schouten 					eightbit = TRUE;
423572fcea8cSEd Schouten 				}
423672fcea8cSEd Schouten 				else if (compare(str1, nochinese_cmd, FALSE))
423772fcea8cSEd Schouten 					ee_chinese = FALSE;
423872fcea8cSEd Schouten 			}
423972fcea8cSEd Schouten 			fclose(init_file);
424072fcea8cSEd Schouten 		}
424172fcea8cSEd Schouten 	}
424272fcea8cSEd Schouten 	free(string);
424372fcea8cSEd Schouten 	free(home);
424472fcea8cSEd Schouten 
424572fcea8cSEd Schouten 	string = getenv("LANG");
424672fcea8cSEd Schouten 	if (string != NULL)
424772fcea8cSEd Schouten 	{
424872fcea8cSEd Schouten 		if (strcmp(string, "zh_TW.big5") == 0)
424972fcea8cSEd Schouten 		{
425072fcea8cSEd Schouten 			ee_chinese = TRUE;
425172fcea8cSEd Schouten 			eightbit = TRUE;
425272fcea8cSEd Schouten 		}
425372fcea8cSEd Schouten 	}
425472fcea8cSEd Schouten }
425572fcea8cSEd Schouten 
425672fcea8cSEd Schouten /*
425772fcea8cSEd Schouten  |	Save current configuration to .init.ee file in the current directory.
425872fcea8cSEd Schouten  */
425972fcea8cSEd Schouten 
426072fcea8cSEd Schouten void
426172fcea8cSEd Schouten dump_ee_conf()
426272fcea8cSEd Schouten {
426372fcea8cSEd Schouten 	FILE *init_file;
426472fcea8cSEd Schouten 	FILE *old_init_file = NULL;
426572fcea8cSEd Schouten 	char *file_name = ".init.ee";
426672fcea8cSEd Schouten 	char *home_dir =  "~/.init.ee";
426772fcea8cSEd Schouten 	char buffer[512];
426872fcea8cSEd Schouten 	struct stat buf;
426972fcea8cSEd Schouten 	char *string;
427072fcea8cSEd Schouten 	int length;
427172fcea8cSEd Schouten 	int option = 0;
427272fcea8cSEd Schouten 
427372fcea8cSEd Schouten 	if (restrict_mode())
427472fcea8cSEd Schouten 	{
427572fcea8cSEd Schouten 		return;
427672fcea8cSEd Schouten 	}
427772fcea8cSEd Schouten 
427872fcea8cSEd Schouten 	option = menu_op(config_dump_menu);
427972fcea8cSEd Schouten 
428072fcea8cSEd Schouten 	werase(com_win);
428172fcea8cSEd Schouten 	wmove(com_win, 0, 0);
428272fcea8cSEd Schouten 
428372fcea8cSEd Schouten 	if (option == 0)
428472fcea8cSEd Schouten 	{
428572fcea8cSEd Schouten 		wprintw(com_win, conf_not_saved_msg);
428672fcea8cSEd Schouten 		wrefresh(com_win);
428772fcea8cSEd Schouten 		return;
428872fcea8cSEd Schouten 	}
428972fcea8cSEd Schouten 	else if (option == 2)
429072fcea8cSEd Schouten 		file_name = resolve_name(home_dir);
429172fcea8cSEd Schouten 
429272fcea8cSEd Schouten 	/*
429372fcea8cSEd Schouten 	 |	If a .init.ee file exists, move it to .init.ee.old.
429472fcea8cSEd Schouten 	 */
429572fcea8cSEd Schouten 
429672fcea8cSEd Schouten 	if (stat(file_name, &buf) != -1)
429772fcea8cSEd Schouten 	{
429872fcea8cSEd Schouten 		sprintf(buffer, "%s.old", file_name);
429972fcea8cSEd Schouten 		unlink(buffer);
430072fcea8cSEd Schouten 		link(file_name, buffer);
430172fcea8cSEd Schouten 		unlink(file_name);
430272fcea8cSEd Schouten 		old_init_file = fopen(buffer, "r");
430372fcea8cSEd Schouten 	}
430472fcea8cSEd Schouten 
430572fcea8cSEd Schouten 	init_file = fopen(file_name, "w");
430672fcea8cSEd Schouten 	if (init_file == NULL)
430772fcea8cSEd Schouten 	{
430872fcea8cSEd Schouten 		wprintw(com_win, conf_dump_err_msg);
430972fcea8cSEd Schouten 		wrefresh(com_win);
431072fcea8cSEd Schouten 		return;
431172fcea8cSEd Schouten 	}
431272fcea8cSEd Schouten 
431372fcea8cSEd Schouten 	if (old_init_file != NULL)
431472fcea8cSEd Schouten 	{
431572fcea8cSEd Schouten 		/*
431672fcea8cSEd Schouten 		 |	Copy non-configuration info into new .init.ee file.
431772fcea8cSEd Schouten 		 */
431872fcea8cSEd Schouten 		while ((string = fgets(buffer, 512, old_init_file)) != NULL)
431972fcea8cSEd Schouten 		{
432072fcea8cSEd Schouten 			length = strlen(string);
432196b676e9SEd Schouten 			string[length - 1] = '\0';
432272fcea8cSEd Schouten 
432372fcea8cSEd Schouten 			if (unique_test(string, init_strings) == 1)
432472fcea8cSEd Schouten 			{
432572fcea8cSEd Schouten 				if (compare(string, Echo, FALSE))
432672fcea8cSEd Schouten 				{
432772fcea8cSEd Schouten 					fprintf(init_file, "%s\n", string);
432872fcea8cSEd Schouten 				}
432972fcea8cSEd Schouten 			}
433072fcea8cSEd Schouten 			else
433172fcea8cSEd Schouten 				fprintf(init_file, "%s\n", string);
433272fcea8cSEd Schouten 		}
433372fcea8cSEd Schouten 
433472fcea8cSEd Schouten 		fclose(old_init_file);
433572fcea8cSEd Schouten 	}
433672fcea8cSEd Schouten 
433772fcea8cSEd Schouten 	fprintf(init_file, "%s\n", case_sen ? CASE : NOCASE);
433872fcea8cSEd Schouten 	fprintf(init_file, "%s\n", expand_tabs ? EXPAND : NOEXPAND);
433972fcea8cSEd Schouten 	fprintf(init_file, "%s\n", info_window ? INFO : NOINFO );
434072fcea8cSEd Schouten 	fprintf(init_file, "%s\n", observ_margins ? MARGINS : NOMARGINS );
434172fcea8cSEd Schouten 	fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT : NOAUTOFORMAT );
434272fcea8cSEd Schouten 	fprintf(init_file, "%s %s\n", PRINTCOMMAND, print_command);
434372fcea8cSEd Schouten 	fprintf(init_file, "%s %d\n", RIGHTMARGIN, right_margin);
434472fcea8cSEd Schouten 	fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT : HIGHLIGHT );
434572fcea8cSEd Schouten 	fprintf(init_file, "%s\n", eightbit ? EIGHTBIT : NOEIGHTBIT );
434672fcea8cSEd Schouten 	fprintf(init_file, "%s\n", emacs_keys_mode ? EMACS_string : NOEMACS_string );
434772fcea8cSEd Schouten 	fprintf(init_file, "%s\n", ee_chinese ? chinese_cmd : nochinese_cmd );
434872fcea8cSEd Schouten 
434972fcea8cSEd Schouten 	fclose(init_file);
435072fcea8cSEd Schouten 
435172fcea8cSEd Schouten 	wprintw(com_win, conf_dump_success_msg, file_name);
435272fcea8cSEd Schouten 	wrefresh(com_win);
435372fcea8cSEd Schouten 
435472fcea8cSEd Schouten 	if ((option == 2) && (file_name != home_dir))
435572fcea8cSEd Schouten 	{
435672fcea8cSEd Schouten 		free(file_name);
435772fcea8cSEd Schouten 	}
435872fcea8cSEd Schouten }
435972fcea8cSEd Schouten 
436072fcea8cSEd Schouten void
436172fcea8cSEd Schouten echo_string(string)	/* echo the given string	*/
436272fcea8cSEd Schouten char *string;
436372fcea8cSEd Schouten {
436472fcea8cSEd Schouten 	char *temp;
436572fcea8cSEd Schouten 	int Counter;
436672fcea8cSEd Schouten 
436772fcea8cSEd Schouten 		temp = string;
436896b676e9SEd Schouten 		while (*temp != '\0')
436972fcea8cSEd Schouten 		{
437072fcea8cSEd Schouten 			if (*temp == '\\')
437172fcea8cSEd Schouten 			{
437272fcea8cSEd Schouten 				temp++;
437372fcea8cSEd Schouten 				if (*temp == 'n')
437472fcea8cSEd Schouten 					putchar('\n');
437572fcea8cSEd Schouten 				else if (*temp == 't')
437672fcea8cSEd Schouten 					putchar('\t');
437772fcea8cSEd Schouten 				else if (*temp == 'b')
437872fcea8cSEd Schouten 					putchar('\b');
437972fcea8cSEd Schouten 				else if (*temp == 'r')
438072fcea8cSEd Schouten 					putchar('\r');
438172fcea8cSEd Schouten 				else if (*temp == 'f')
438272fcea8cSEd Schouten 					putchar('\f');
438372fcea8cSEd Schouten 				else if ((*temp == 'e') || (*temp == 'E'))
438472fcea8cSEd Schouten 					putchar('\033');	/* escape */
438572fcea8cSEd Schouten 				else if (*temp == '\\')
438672fcea8cSEd Schouten 					putchar('\\');
438772fcea8cSEd Schouten 				else if (*temp == '\'')
438872fcea8cSEd Schouten 					putchar('\'');
438972fcea8cSEd Schouten 				else if ((*temp >= '0') && (*temp <= '9'))
439072fcea8cSEd Schouten 				{
439172fcea8cSEd Schouten 					Counter = 0;
439272fcea8cSEd Schouten 					while ((*temp >= '0') && (*temp <= '9'))
439372fcea8cSEd Schouten 					{
439472fcea8cSEd Schouten 						Counter = (8 * Counter) + (*temp - '0');
439572fcea8cSEd Schouten 						temp++;
439672fcea8cSEd Schouten 					}
439772fcea8cSEd Schouten 					putchar(Counter);
439872fcea8cSEd Schouten 					temp--;
439972fcea8cSEd Schouten 				}
440072fcea8cSEd Schouten 				temp++;
440172fcea8cSEd Schouten 			}
440272fcea8cSEd Schouten 			else
440372fcea8cSEd Schouten 			{
440472fcea8cSEd Schouten 				putchar(*temp);
440572fcea8cSEd Schouten 				temp++;
440672fcea8cSEd Schouten 			}
440772fcea8cSEd Schouten 		}
440872fcea8cSEd Schouten 
440972fcea8cSEd Schouten 	fflush(stdout);
441072fcea8cSEd Schouten }
441172fcea8cSEd Schouten 
441272fcea8cSEd Schouten void
441372fcea8cSEd Schouten spell_op()	/* check spelling of words in the editor	*/
441472fcea8cSEd Schouten {
441572fcea8cSEd Schouten 	if (restrict_mode())
441672fcea8cSEd Schouten 	{
441772fcea8cSEd Schouten 		return;
441872fcea8cSEd Schouten 	}
441972fcea8cSEd Schouten 	top();			/* go to top of file		*/
442072fcea8cSEd Schouten 	insert_line(FALSE);	/* create two blank lines	*/
442172fcea8cSEd Schouten 	insert_line(FALSE);
442272fcea8cSEd Schouten 	top();
442372fcea8cSEd Schouten 	command(shell_echo_msg);
442472fcea8cSEd Schouten 	adv_line();
442572fcea8cSEd Schouten 	wmove(com_win, 0, 0);
442672fcea8cSEd Schouten 	wprintw(com_win, spell_in_prog_msg);
442772fcea8cSEd Schouten 	wrefresh(com_win);
442872fcea8cSEd Schouten 	command("<>!spell");	/* send contents of buffer to command 'spell'
442972fcea8cSEd Schouten 				   and read the results back into the editor */
443072fcea8cSEd Schouten }
443172fcea8cSEd Schouten 
443272fcea8cSEd Schouten void
443372fcea8cSEd Schouten ispell_op()
443472fcea8cSEd Schouten {
4435cfe04e82SEd Schouten 	char template[128], *name;
443672fcea8cSEd Schouten 	char string[256];
4437cfe04e82SEd Schouten 	int fd;
443872fcea8cSEd Schouten 
443972fcea8cSEd Schouten 	if (restrict_mode())
444072fcea8cSEd Schouten 	{
444172fcea8cSEd Schouten 		return;
444272fcea8cSEd Schouten 	}
4443cfe04e82SEd Schouten 	(void)sprintf(template, "/tmp/ee.XXXXXXXX");
444496b676e9SEd Schouten 	fd = mkstemp(template);
4445cfe04e82SEd Schouten 	if (fd < 0) {
4446cfe04e82SEd Schouten 		wmove(com_win, 0, 0);
4447cfe04e82SEd Schouten 		wprintw(com_win, create_file_fail_msg, name);
4448cfe04e82SEd Schouten 		wrefresh(com_win);
4449cfe04e82SEd Schouten 		return;
4450cfe04e82SEd Schouten 	}
4451cfe04e82SEd Schouten 	close(fd);
4452cfe04e82SEd Schouten 	if (write_file(name, 0))
445372fcea8cSEd Schouten 	{
445472fcea8cSEd Schouten 		sprintf(string, "ispell %s", name);
445572fcea8cSEd Schouten 		sh_command(string);
445672fcea8cSEd Schouten 		delete_text();
445772fcea8cSEd Schouten 		tmp_file = name;
445872fcea8cSEd Schouten 		recv_file = TRUE;
445972fcea8cSEd Schouten 		check_fp();
446072fcea8cSEd Schouten 		unlink(name);
446172fcea8cSEd Schouten 	}
446272fcea8cSEd Schouten }
446372fcea8cSEd Schouten 
446472fcea8cSEd Schouten int
446572fcea8cSEd Schouten first_word_len(test_line)
446672fcea8cSEd Schouten struct text *test_line;
446772fcea8cSEd Schouten {
446872fcea8cSEd Schouten 	int counter;
446972fcea8cSEd Schouten 	unsigned char *pnt;
447072fcea8cSEd Schouten 
447172fcea8cSEd Schouten 	if (test_line == NULL)
447272fcea8cSEd Schouten 		return(0);
447372fcea8cSEd Schouten 
447472fcea8cSEd Schouten 	pnt = test_line->line;
447596b676e9SEd Schouten 	if ((pnt == NULL) || (*pnt == '\0') ||
447672fcea8cSEd Schouten 	    (*pnt == '.') || (*pnt == '>'))
447772fcea8cSEd Schouten 		return(0);
447872fcea8cSEd Schouten 
447972fcea8cSEd Schouten 	if ((*pnt == ' ') || (*pnt == '\t'))
448072fcea8cSEd Schouten 	{
448172fcea8cSEd Schouten 		pnt = next_word(pnt);
448272fcea8cSEd Schouten 	}
448372fcea8cSEd Schouten 
448496b676e9SEd Schouten 	if (*pnt == '\0')
448572fcea8cSEd Schouten 		return(0);
448672fcea8cSEd Schouten 
448772fcea8cSEd Schouten 	counter = 0;
448896b676e9SEd Schouten 	while ((*pnt != '\0') && ((*pnt != ' ') && (*pnt != '\t')))
448972fcea8cSEd Schouten 	{
449072fcea8cSEd Schouten 		pnt++;
449172fcea8cSEd Schouten 		counter++;
449272fcea8cSEd Schouten 	}
449396b676e9SEd Schouten 	while ((*pnt != '\0') && ((*pnt == ' ') || (*pnt == '\t')))
449472fcea8cSEd Schouten 	{
449572fcea8cSEd Schouten 		pnt++;
449672fcea8cSEd Schouten 		counter++;
449772fcea8cSEd Schouten 	}
449872fcea8cSEd Schouten 	return(counter);
449972fcea8cSEd Schouten }
450072fcea8cSEd Schouten 
450172fcea8cSEd Schouten void
450272fcea8cSEd Schouten Auto_Format()	/* format the paragraph according to set margins	*/
450372fcea8cSEd Schouten {
450472fcea8cSEd Schouten 	int string_count;
450572fcea8cSEd Schouten 	int offset;
450672fcea8cSEd Schouten 	int temp_case;
450772fcea8cSEd Schouten 	int word_len;
450872fcea8cSEd Schouten 	int temp_dwl;
450972fcea8cSEd Schouten 	int tmp_d_line_length;
451072fcea8cSEd Schouten 	int leave_loop = FALSE;
451172fcea8cSEd Schouten 	int status;
451272fcea8cSEd Schouten 	int counter;
451372fcea8cSEd Schouten 	char not_blank;
451472fcea8cSEd Schouten 	unsigned char *line;
451572fcea8cSEd Schouten 	unsigned char *tmp_srchstr;
451672fcea8cSEd Schouten 	unsigned char *temp1, *temp2;
451772fcea8cSEd Schouten 	unsigned char *temp_dword;
451872fcea8cSEd Schouten 	unsigned char temp_d_char[3];
451972fcea8cSEd Schouten 	unsigned char *tmp_d_line;
452072fcea8cSEd Schouten 
452172fcea8cSEd Schouten 
452272fcea8cSEd Schouten 	temp_d_char[0] = d_char[0];
452372fcea8cSEd Schouten 	temp_d_char[1] = d_char[1];
452472fcea8cSEd Schouten 	temp_d_char[2] = d_char[2];
452572fcea8cSEd Schouten 
452672fcea8cSEd Schouten /*
452772fcea8cSEd Schouten  |	if observ_margins is not set, or the current line is blank,
452872fcea8cSEd Schouten  |	do not format the current paragraph
452972fcea8cSEd Schouten  */
453072fcea8cSEd Schouten 
453172fcea8cSEd Schouten 	if ((!observ_margins) || (Blank_Line(curr_line)))
453272fcea8cSEd Schouten 		return;
453372fcea8cSEd Schouten 
453472fcea8cSEd Schouten /*
453572fcea8cSEd Schouten  |	get current position in paragraph, so after formatting, the cursor
453672fcea8cSEd Schouten  |	will be in the same relative position
453772fcea8cSEd Schouten  */
453872fcea8cSEd Schouten 
453972fcea8cSEd Schouten 	tmp_d_line = d_line;
454072fcea8cSEd Schouten 	tmp_d_line_length = dlt_line->line_length;
454172fcea8cSEd Schouten 	d_line = NULL;
454272fcea8cSEd Schouten 	auto_format = FALSE;
454372fcea8cSEd Schouten 	offset = position;
454496b676e9SEd Schouten 	if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == '\0')))
454572fcea8cSEd Schouten 		prev_word();
454672fcea8cSEd Schouten 	temp_dword = d_word;
454772fcea8cSEd Schouten 	temp_dwl = d_wrd_len;
454872fcea8cSEd Schouten 	d_wrd_len = 0;
454972fcea8cSEd Schouten 	d_word = NULL;
455072fcea8cSEd Schouten 	temp_case = case_sen;
455172fcea8cSEd Schouten 	case_sen = TRUE;
455272fcea8cSEd Schouten 	tmp_srchstr = srch_str;
455372fcea8cSEd Schouten 	temp2 = srch_str = (unsigned char *) malloc(1 + curr_line->line_length - position);
455472fcea8cSEd Schouten 	if ((*point == ' ') || (*point == '\t'))
455572fcea8cSEd Schouten 		adv_word();
455672fcea8cSEd Schouten 	offset -= position;
455772fcea8cSEd Schouten 	counter = position;
455872fcea8cSEd Schouten 	line = temp1 = point;
455996b676e9SEd Schouten 	while ((*temp1 != '\0') && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
456072fcea8cSEd Schouten 	{
456172fcea8cSEd Schouten 		*temp2 = *temp1;
456272fcea8cSEd Schouten 		temp2++;
456372fcea8cSEd Schouten 		temp1++;
456472fcea8cSEd Schouten 		counter++;
456572fcea8cSEd Schouten 	}
456696b676e9SEd Schouten 	*temp2 = '\0';
456772fcea8cSEd Schouten 	if (position != 1)
456872fcea8cSEd Schouten 		bol();
456972fcea8cSEd Schouten 	while (!Blank_Line(curr_line->prev_line))
457072fcea8cSEd Schouten 		bol();
457172fcea8cSEd Schouten 	string_count = 0;
457272fcea8cSEd Schouten 	status = TRUE;
457372fcea8cSEd Schouten 	while ((line != point) && (status))
457472fcea8cSEd Schouten 	{
457572fcea8cSEd Schouten 		status = search(FALSE);
457672fcea8cSEd Schouten 		string_count++;
457772fcea8cSEd Schouten 	}
457872fcea8cSEd Schouten 
457972fcea8cSEd Schouten /*
458072fcea8cSEd Schouten  |	now get back to the start of the paragraph to start checking
458172fcea8cSEd Schouten  */
458272fcea8cSEd Schouten 
458372fcea8cSEd Schouten 	if (position != 1)
458472fcea8cSEd Schouten 		bol();
458572fcea8cSEd Schouten 	while (!Blank_Line(curr_line->prev_line))
458672fcea8cSEd Schouten 		bol();
458772fcea8cSEd Schouten 
458872fcea8cSEd Schouten /*
458972fcea8cSEd Schouten  |	Start going through lines, putting spaces at end of lines if they do
459072fcea8cSEd Schouten  |	not already exist.  Check line length, and move words to the next line
459172fcea8cSEd Schouten  |	if they cross the margin.  Then get words from the next line if they
459272fcea8cSEd Schouten  |	will fit in before the margin.
459372fcea8cSEd Schouten  */
459472fcea8cSEd Schouten 
459572fcea8cSEd Schouten 	counter = 0;
459672fcea8cSEd Schouten 
459772fcea8cSEd Schouten 	while (!leave_loop)
459872fcea8cSEd Schouten 	{
459972fcea8cSEd Schouten 		if (position != curr_line->line_length)
460072fcea8cSEd Schouten 			eol();
460172fcea8cSEd Schouten 		left(TRUE);
460272fcea8cSEd Schouten 		if (*point != ' ')
460372fcea8cSEd Schouten 		{
460472fcea8cSEd Schouten 			right(TRUE);
460572fcea8cSEd Schouten 			insert(' ');
460672fcea8cSEd Schouten 		}
460772fcea8cSEd Schouten 		else
460872fcea8cSEd Schouten 			right(TRUE);
460972fcea8cSEd Schouten 
461072fcea8cSEd Schouten 		not_blank = FALSE;
461172fcea8cSEd Schouten 
461272fcea8cSEd Schouten 		/*
461372fcea8cSEd Schouten 		 |	fill line if first word on next line will fit
461472fcea8cSEd Schouten 		 |	in the line without crossing the margin
461572fcea8cSEd Schouten 		 */
461672fcea8cSEd Schouten 
461772fcea8cSEd Schouten 		while ((curr_line->next_line != NULL) &&
461872fcea8cSEd Schouten 		       ((word_len = first_word_len(curr_line->next_line)) > 0)
461972fcea8cSEd Schouten 			&& ((scr_pos + word_len) < right_margin))
462072fcea8cSEd Schouten 		{
462172fcea8cSEd Schouten 			adv_line();
462272fcea8cSEd Schouten 			if ((*point == ' ') || (*point == '\t'))
462372fcea8cSEd Schouten 				adv_word();
462472fcea8cSEd Schouten 			del_word();
462572fcea8cSEd Schouten 			if (position != 1)
462672fcea8cSEd Schouten 				bol();
462772fcea8cSEd Schouten 
462872fcea8cSEd Schouten 			/*
462972fcea8cSEd Schouten 			 |	We know this line was not blank before, so
463072fcea8cSEd Schouten 			 |	make sure that it doesn't have one of the
463172fcea8cSEd Schouten 			 |	leading characters that indicate the line
463272fcea8cSEd Schouten 			 |	should not be modified.
463372fcea8cSEd Schouten 			 |
463472fcea8cSEd Schouten 			 |	We also know that this character should not
463572fcea8cSEd Schouten 			 |	be left as the first character of this line.
463672fcea8cSEd Schouten 			 */
463772fcea8cSEd Schouten 
463872fcea8cSEd Schouten 			if ((Blank_Line(curr_line)) &&
463972fcea8cSEd Schouten 			    (curr_line->line[0] != '.') &&
464072fcea8cSEd Schouten 			    (curr_line->line[0] != '>'))
464172fcea8cSEd Schouten 			{
464272fcea8cSEd Schouten 				del_line();
464372fcea8cSEd Schouten 				not_blank = FALSE;
464472fcea8cSEd Schouten 			}
464572fcea8cSEd Schouten 			else
464672fcea8cSEd Schouten 				not_blank = TRUE;
464772fcea8cSEd Schouten 
464872fcea8cSEd Schouten 			/*
464972fcea8cSEd Schouten 			 |   go to end of previous line
465072fcea8cSEd Schouten 			 */
465172fcea8cSEd Schouten 			left(TRUE);
465272fcea8cSEd Schouten 			undel_word();
465372fcea8cSEd Schouten 			eol();
465472fcea8cSEd Schouten 			/*
465572fcea8cSEd Schouten 			 |   make sure there's a space at the end of the line
465672fcea8cSEd Schouten 			 */
465772fcea8cSEd Schouten 			left(TRUE);
465872fcea8cSEd Schouten 			if (*point != ' ')
465972fcea8cSEd Schouten 			{
466072fcea8cSEd Schouten 				right(TRUE);
466172fcea8cSEd Schouten 				insert(' ');
466272fcea8cSEd Schouten 			}
466372fcea8cSEd Schouten 			else
466472fcea8cSEd Schouten 				right(TRUE);
466572fcea8cSEd Schouten 		}
466672fcea8cSEd Schouten 
466772fcea8cSEd Schouten 		/*
466872fcea8cSEd Schouten 		 |	make sure line does not cross right margin
466972fcea8cSEd Schouten 		 */
467072fcea8cSEd Schouten 
467172fcea8cSEd Schouten 		while (right_margin <= scr_pos)
467272fcea8cSEd Schouten 		{
467372fcea8cSEd Schouten 			prev_word();
467472fcea8cSEd Schouten 			if (position != 1)
467572fcea8cSEd Schouten 			{
467672fcea8cSEd Schouten 				del_word();
467772fcea8cSEd Schouten 				if (Blank_Line(curr_line->next_line))
467872fcea8cSEd Schouten 					insert_line(TRUE);
467972fcea8cSEd Schouten 				else
468072fcea8cSEd Schouten 					adv_line();
468172fcea8cSEd Schouten 				if ((*point == ' ') || (*point == '\t'))
468272fcea8cSEd Schouten 					adv_word();
468372fcea8cSEd Schouten 				undel_word();
468472fcea8cSEd Schouten 				not_blank = TRUE;
468572fcea8cSEd Schouten 				if (position != 1)
468672fcea8cSEd Schouten 					bol();
468772fcea8cSEd Schouten 				left(TRUE);
468872fcea8cSEd Schouten 			}
468972fcea8cSEd Schouten 		}
469072fcea8cSEd Schouten 
469172fcea8cSEd Schouten 		if ((!Blank_Line(curr_line->next_line)) || (not_blank))
469272fcea8cSEd Schouten 		{
469372fcea8cSEd Schouten 			adv_line();
469472fcea8cSEd Schouten 			counter++;
469572fcea8cSEd Schouten 		}
469672fcea8cSEd Schouten 		else
469772fcea8cSEd Schouten 			leave_loop = TRUE;
469872fcea8cSEd Schouten 	}
469972fcea8cSEd Schouten 
470072fcea8cSEd Schouten /*
470172fcea8cSEd Schouten  |	go back to begin of paragraph, put cursor back to original position
470272fcea8cSEd Schouten  */
470372fcea8cSEd Schouten 
470472fcea8cSEd Schouten 	if (position != 1)
470572fcea8cSEd Schouten 		bol();
470672fcea8cSEd Schouten 	while ((counter-- > 0) || (!Blank_Line(curr_line->prev_line)))
470772fcea8cSEd Schouten 		bol();
470872fcea8cSEd Schouten 
470972fcea8cSEd Schouten /*
471072fcea8cSEd Schouten  |	find word cursor was in
471172fcea8cSEd Schouten  */
471272fcea8cSEd Schouten 
471372fcea8cSEd Schouten 	status = TRUE;
471472fcea8cSEd Schouten 	while ((status) && (string_count > 0))
471572fcea8cSEd Schouten 	{
471672fcea8cSEd Schouten 		status = search(FALSE);
471772fcea8cSEd Schouten 		string_count--;
471872fcea8cSEd Schouten 	}
471972fcea8cSEd Schouten 
472072fcea8cSEd Schouten /*
472172fcea8cSEd Schouten  |	offset the cursor to where it was before from the start of the word
472272fcea8cSEd Schouten  */
472372fcea8cSEd Schouten 
472472fcea8cSEd Schouten 	while (offset > 0)
472572fcea8cSEd Schouten 	{
472672fcea8cSEd Schouten 		offset--;
472772fcea8cSEd Schouten 		right(TRUE);
472872fcea8cSEd Schouten 	}
472972fcea8cSEd Schouten 
473072fcea8cSEd Schouten 	if ((string_count > 0) && (offset < 0))
473172fcea8cSEd Schouten 	{
473272fcea8cSEd Schouten 		while (offset < 0)
473372fcea8cSEd Schouten 		{
473472fcea8cSEd Schouten 			offset++;
473572fcea8cSEd Schouten 			left(TRUE);
473672fcea8cSEd Schouten 		}
473772fcea8cSEd Schouten 	}
473872fcea8cSEd Schouten 
473972fcea8cSEd Schouten /*
474072fcea8cSEd Schouten  |	reset flags and strings to what they were before formatting
474172fcea8cSEd Schouten  */
474272fcea8cSEd Schouten 
474372fcea8cSEd Schouten 	if (d_word != NULL)
474472fcea8cSEd Schouten 		free(d_word);
474572fcea8cSEd Schouten 	d_word = temp_dword;
474672fcea8cSEd Schouten 	d_wrd_len = temp_dwl;
474772fcea8cSEd Schouten 	case_sen = temp_case;
474872fcea8cSEd Schouten 	free(srch_str);
474972fcea8cSEd Schouten 	srch_str = tmp_srchstr;
475072fcea8cSEd Schouten 	d_char[0] = temp_d_char[0];
475172fcea8cSEd Schouten 	d_char[1] = temp_d_char[1];
475272fcea8cSEd Schouten 	d_char[2] = temp_d_char[2];
475372fcea8cSEd Schouten 	auto_format = TRUE;
475472fcea8cSEd Schouten 	dlt_line->line_length = tmp_d_line_length;
475572fcea8cSEd Schouten 	d_line = tmp_d_line;
475672fcea8cSEd Schouten 
475772fcea8cSEd Schouten 	formatted = TRUE;
475872fcea8cSEd Schouten 	midscreen(scr_vert, point);
475972fcea8cSEd Schouten }
476072fcea8cSEd Schouten 
476172fcea8cSEd Schouten void
476272fcea8cSEd Schouten modes_op()
476372fcea8cSEd Schouten {
476472fcea8cSEd Schouten 	int ret_value;
476572fcea8cSEd Schouten 	int counter;
476672fcea8cSEd Schouten 	char *string;
476772fcea8cSEd Schouten 
476872fcea8cSEd Schouten 	do
476972fcea8cSEd Schouten 	{
477072fcea8cSEd Schouten 		sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
477172fcea8cSEd Schouten 					(expand_tabs ? ON : OFF));
477272fcea8cSEd Schouten 		sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
477372fcea8cSEd Schouten 					(case_sen ? ON : OFF));
477472fcea8cSEd Schouten 		sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
477572fcea8cSEd Schouten 					(observ_margins ? ON : OFF));
477672fcea8cSEd Schouten 		sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
477772fcea8cSEd Schouten 					(auto_format ? ON : OFF));
477872fcea8cSEd Schouten 		sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
477972fcea8cSEd Schouten 					(eightbit ? ON : OFF));
478072fcea8cSEd Schouten 		sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
478172fcea8cSEd Schouten 					(info_window ? ON : OFF));
478272fcea8cSEd Schouten 		sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
478372fcea8cSEd Schouten 					(emacs_keys_mode ? ON : OFF));
478472fcea8cSEd Schouten 		sprintf(modes_menu[8].item_string, "%s %d", mode_strings[8],
478572fcea8cSEd Schouten 					right_margin);
478672fcea8cSEd Schouten 		sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
478772fcea8cSEd Schouten 					(ee_chinese ? ON : OFF));
478872fcea8cSEd Schouten 
478972fcea8cSEd Schouten 		ret_value = menu_op(modes_menu);
479072fcea8cSEd Schouten 
479172fcea8cSEd Schouten 		switch (ret_value)
479272fcea8cSEd Schouten 		{
479372fcea8cSEd Schouten 			case 1:
479472fcea8cSEd Schouten 				expand_tabs = !expand_tabs;
479572fcea8cSEd Schouten 				break;
479672fcea8cSEd Schouten 			case 2:
479772fcea8cSEd Schouten 				case_sen = !case_sen;
479872fcea8cSEd Schouten 				break;
479972fcea8cSEd Schouten 			case 3:
480072fcea8cSEd Schouten 				observ_margins = !observ_margins;
480172fcea8cSEd Schouten 				break;
480272fcea8cSEd Schouten 			case 4:
480372fcea8cSEd Schouten 				auto_format = !auto_format;
480472fcea8cSEd Schouten 				if (auto_format)
480572fcea8cSEd Schouten 					observ_margins = TRUE;
480672fcea8cSEd Schouten 				break;
480772fcea8cSEd Schouten 			case 5:
480872fcea8cSEd Schouten 				eightbit = !eightbit;
480972fcea8cSEd Schouten 				if (!eightbit)
481072fcea8cSEd Schouten 					ee_chinese = FALSE;
481172fcea8cSEd Schouten #ifdef NCURSE
481272fcea8cSEd Schouten 				if (ee_chinese)
481372fcea8cSEd Schouten 					nc_setattrib(A_NC_BIG5);
481472fcea8cSEd Schouten 				else
481572fcea8cSEd Schouten 					nc_clearattrib(A_NC_BIG5);
481672fcea8cSEd Schouten #endif /* NCURSE */
481772fcea8cSEd Schouten 
481872fcea8cSEd Schouten 				redraw();
481972fcea8cSEd Schouten 				wnoutrefresh(text_win);
482072fcea8cSEd Schouten 				break;
482172fcea8cSEd Schouten 			case 6:
482272fcea8cSEd Schouten 				if (info_window)
482372fcea8cSEd Schouten 					no_info_window();
482472fcea8cSEd Schouten 				else
482572fcea8cSEd Schouten 					create_info_window();
482672fcea8cSEd Schouten 				break;
482772fcea8cSEd Schouten 			case 7:
482872fcea8cSEd Schouten 				emacs_keys_mode = !emacs_keys_mode;
482972fcea8cSEd Schouten 				if (info_window)
483072fcea8cSEd Schouten 					paint_info_win();
483172fcea8cSEd Schouten 				break;
483272fcea8cSEd Schouten 			case 8:
483372fcea8cSEd Schouten 				string = get_string(margin_prompt, TRUE);
483472fcea8cSEd Schouten 				if (string != NULL)
483572fcea8cSEd Schouten 				{
483672fcea8cSEd Schouten 					counter = atoi(string);
483772fcea8cSEd Schouten 					if (counter > 0)
483872fcea8cSEd Schouten 						right_margin = counter;
483972fcea8cSEd Schouten 					free(string);
484072fcea8cSEd Schouten 				}
484172fcea8cSEd Schouten 				break;
484272fcea8cSEd Schouten 			case 9:
484372fcea8cSEd Schouten 				ee_chinese = !ee_chinese;
484472fcea8cSEd Schouten 				if (ee_chinese != FALSE)
484572fcea8cSEd Schouten 					eightbit = TRUE;
484672fcea8cSEd Schouten #ifdef NCURSE
484772fcea8cSEd Schouten 				if (ee_chinese)
484872fcea8cSEd Schouten 					nc_setattrib(A_NC_BIG5);
484972fcea8cSEd Schouten 				else
485072fcea8cSEd Schouten 					nc_clearattrib(A_NC_BIG5);
485172fcea8cSEd Schouten #endif /* NCURSE */
485272fcea8cSEd Schouten 				redraw();
485372fcea8cSEd Schouten 				break;
485472fcea8cSEd Schouten 			default:
485572fcea8cSEd Schouten 				break;
485672fcea8cSEd Schouten 		}
485772fcea8cSEd Schouten 	}
485872fcea8cSEd Schouten 	while (ret_value != 0);
485972fcea8cSEd Schouten }
486072fcea8cSEd Schouten 
486172fcea8cSEd Schouten char *
486272fcea8cSEd Schouten is_in_string(string, substring)	/* a strchr() look-alike for systems without
486372fcea8cSEd Schouten 				   strchr() */
486472fcea8cSEd Schouten char * string, *substring;
486572fcea8cSEd Schouten {
486672fcea8cSEd Schouten 	char *full, *sub;
486772fcea8cSEd Schouten 
486896b676e9SEd Schouten 	for (sub = substring; (sub != NULL) && (*sub != '\0'); sub++)
486972fcea8cSEd Schouten 	{
487096b676e9SEd Schouten 		for (full = string; (full != NULL) && (*full != '\0');
487172fcea8cSEd Schouten 				full++)
487272fcea8cSEd Schouten 		{
487372fcea8cSEd Schouten 			if (*sub == *full)
487472fcea8cSEd Schouten 				return(full);
487572fcea8cSEd Schouten 		}
487672fcea8cSEd Schouten 	}
487772fcea8cSEd Schouten 	return(NULL);
487872fcea8cSEd Schouten }
487972fcea8cSEd Schouten 
488072fcea8cSEd Schouten /*
488172fcea8cSEd Schouten  |	handle names of the form "~/file", "~user/file",
488272fcea8cSEd Schouten  |	"$HOME/foo", "~/$FOO", etc.
488372fcea8cSEd Schouten  */
488472fcea8cSEd Schouten 
488572fcea8cSEd Schouten char *
488672fcea8cSEd Schouten resolve_name(name)
488772fcea8cSEd Schouten char *name;
488872fcea8cSEd Schouten {
488972fcea8cSEd Schouten 	char long_buffer[1024];
489072fcea8cSEd Schouten 	char short_buffer[128];
489172fcea8cSEd Schouten 	char *buffer;
489272fcea8cSEd Schouten 	char *slash;
489372fcea8cSEd Schouten 	char *tmp;
489472fcea8cSEd Schouten 	char *start_of_var;
489572fcea8cSEd Schouten 	int offset;
489672fcea8cSEd Schouten 	int index;
489772fcea8cSEd Schouten 	int counter;
489872fcea8cSEd Schouten 	struct passwd *user;
489972fcea8cSEd Schouten 
490072fcea8cSEd Schouten 	if (name[0] == '~')
490172fcea8cSEd Schouten 	{
490272fcea8cSEd Schouten 		if (name[1] == '/')
490372fcea8cSEd Schouten 		{
490472fcea8cSEd Schouten 			index = getuid();
490572fcea8cSEd Schouten 			user = (struct passwd *) getpwuid(index);
490672fcea8cSEd Schouten 			slash = name + 1;
490772fcea8cSEd Schouten 		}
490872fcea8cSEd Schouten 		else
490972fcea8cSEd Schouten 		{
491072fcea8cSEd Schouten 			slash = strchr(name, '/');
491172fcea8cSEd Schouten 			if (slash == NULL)
491272fcea8cSEd Schouten 				return(name);
491396b676e9SEd Schouten 			*slash = '\0';
491472fcea8cSEd Schouten 			user = (struct passwd *) getpwnam((name + 1));
491572fcea8cSEd Schouten 			*slash = '/';
491672fcea8cSEd Schouten 		}
491772fcea8cSEd Schouten 		if (user == NULL)
491872fcea8cSEd Schouten 		{
491972fcea8cSEd Schouten 			return(name);
492072fcea8cSEd Schouten 		}
492172fcea8cSEd Schouten 		buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
492272fcea8cSEd Schouten 		strcpy(buffer, user->pw_dir);
492372fcea8cSEd Schouten 		strcat(buffer, slash);
492472fcea8cSEd Schouten 	}
492572fcea8cSEd Schouten 	else
492672fcea8cSEd Schouten 		buffer = name;
492772fcea8cSEd Schouten 
492872fcea8cSEd Schouten 	if (is_in_string(buffer, "$"))
492972fcea8cSEd Schouten 	{
493072fcea8cSEd Schouten 		tmp = buffer;
493172fcea8cSEd Schouten 		index = 0;
493272fcea8cSEd Schouten 
493396b676e9SEd Schouten 		while ((*tmp != '\0') && (index < 1024))
493472fcea8cSEd Schouten 		{
493572fcea8cSEd Schouten 
493696b676e9SEd Schouten 			while ((*tmp != '\0') && (*tmp != '$') &&
493772fcea8cSEd Schouten 				(index < 1024))
493872fcea8cSEd Schouten 			{
493972fcea8cSEd Schouten 				long_buffer[index] = *tmp;
494072fcea8cSEd Schouten 				tmp++;
494172fcea8cSEd Schouten 				index++;
494272fcea8cSEd Schouten 			}
494372fcea8cSEd Schouten 
494472fcea8cSEd Schouten 			if ((*tmp == '$') && (index < 1024))
494572fcea8cSEd Schouten 			{
494672fcea8cSEd Schouten 				counter = 0;
494772fcea8cSEd Schouten 				start_of_var = tmp;
494872fcea8cSEd Schouten 				tmp++;
494972fcea8cSEd Schouten 				if (*tmp == '{') /* } */	/* bracketed variable name */
495072fcea8cSEd Schouten 				{
495172fcea8cSEd Schouten 					tmp++;				/* { */
495296b676e9SEd Schouten 					while ((*tmp != '\0') &&
495372fcea8cSEd Schouten 						(*tmp != '}') &&
495472fcea8cSEd Schouten 						(counter < 128))
495572fcea8cSEd Schouten 					{
495672fcea8cSEd Schouten 						short_buffer[counter] = *tmp;
495772fcea8cSEd Schouten 						counter++;
495872fcea8cSEd Schouten 						tmp++;
495972fcea8cSEd Schouten 					}			/* { */
496072fcea8cSEd Schouten 					if (*tmp == '}')
496172fcea8cSEd Schouten 						tmp++;
496272fcea8cSEd Schouten 				}
496372fcea8cSEd Schouten 				else
496472fcea8cSEd Schouten 				{
496596b676e9SEd Schouten 					while ((*tmp != '\0') &&
496672fcea8cSEd Schouten 					       (*tmp != '/') &&
496772fcea8cSEd Schouten 					       (*tmp != '$') &&
496872fcea8cSEd Schouten 					       (counter < 128))
496972fcea8cSEd Schouten 					{
497072fcea8cSEd Schouten 						short_buffer[counter] = *tmp;
497172fcea8cSEd Schouten 						counter++;
497272fcea8cSEd Schouten 						tmp++;
497372fcea8cSEd Schouten 					}
497472fcea8cSEd Schouten 				}
497596b676e9SEd Schouten 				short_buffer[counter] = '\0';
497672fcea8cSEd Schouten 				if ((slash = getenv(short_buffer)) != NULL)
497772fcea8cSEd Schouten 				{
497872fcea8cSEd Schouten 					offset = strlen(slash);
497972fcea8cSEd Schouten 					if ((offset + index) < 1024)
498072fcea8cSEd Schouten 						strcpy(&long_buffer[index], slash);
498172fcea8cSEd Schouten 					index += offset;
498272fcea8cSEd Schouten 				}
498372fcea8cSEd Schouten 				else
498472fcea8cSEd Schouten 				{
498572fcea8cSEd Schouten 					while ((start_of_var != tmp) && (index < 1024))
498672fcea8cSEd Schouten 					{
498772fcea8cSEd Schouten 						long_buffer[index] = *start_of_var;
498872fcea8cSEd Schouten 						start_of_var++;
498972fcea8cSEd Schouten 						index++;
499072fcea8cSEd Schouten 					}
499172fcea8cSEd Schouten 				}
499272fcea8cSEd Schouten 			}
499372fcea8cSEd Schouten 		}
499472fcea8cSEd Schouten 
499572fcea8cSEd Schouten 		if (index == 1024)
499672fcea8cSEd Schouten 			return(buffer);
499772fcea8cSEd Schouten 		else
499896b676e9SEd Schouten 			long_buffer[index] = '\0';
499972fcea8cSEd Schouten 
500072fcea8cSEd Schouten 		if (name != buffer)
500172fcea8cSEd Schouten 			free(buffer);
500272fcea8cSEd Schouten 		buffer = malloc(index + 1);
500372fcea8cSEd Schouten 		strcpy(buffer, long_buffer);
500472fcea8cSEd Schouten 	}
500572fcea8cSEd Schouten 
500672fcea8cSEd Schouten 	return(buffer);
500772fcea8cSEd Schouten }
500872fcea8cSEd Schouten 
500972fcea8cSEd Schouten int
501072fcea8cSEd Schouten restrict_mode()
501172fcea8cSEd Schouten {
501272fcea8cSEd Schouten 	if (!restricted)
501372fcea8cSEd Schouten 		return(FALSE);
501472fcea8cSEd Schouten 
501572fcea8cSEd Schouten 	wmove(com_win, 0, 0);
501672fcea8cSEd Schouten 	wprintw(com_win, restricted_msg);
501772fcea8cSEd Schouten 	wclrtoeol(com_win);
501872fcea8cSEd Schouten 	wrefresh(com_win);
501972fcea8cSEd Schouten 	clear_com_win = TRUE;
502072fcea8cSEd Schouten 	return(TRUE);
502172fcea8cSEd Schouten }
502272fcea8cSEd Schouten 
502372fcea8cSEd Schouten /*
502472fcea8cSEd Schouten  |	The following routine tests the input string against the list of
502572fcea8cSEd Schouten  |	strings, to determine if the string is a unique match with one of the
502672fcea8cSEd Schouten  |	valid values.
502772fcea8cSEd Schouten  */
502872fcea8cSEd Schouten 
502972fcea8cSEd Schouten int
503072fcea8cSEd Schouten unique_test(string, list)
503172fcea8cSEd Schouten char *string;
503272fcea8cSEd Schouten char *list[];
503372fcea8cSEd Schouten {
503472fcea8cSEd Schouten 	int counter;
503572fcea8cSEd Schouten 	int num_match;
503672fcea8cSEd Schouten 	int result;
503772fcea8cSEd Schouten 
503872fcea8cSEd Schouten 	num_match = 0;
503972fcea8cSEd Schouten 	counter = 0;
504072fcea8cSEd Schouten 	while (list[counter] != NULL)
504172fcea8cSEd Schouten 	{
504272fcea8cSEd Schouten 		result = compare(string, list[counter], FALSE);
504372fcea8cSEd Schouten 		if (result)
504472fcea8cSEd Schouten 			num_match++;
504572fcea8cSEd Schouten 		counter++;
504672fcea8cSEd Schouten 	}
504772fcea8cSEd Schouten 	return(num_match);
504872fcea8cSEd Schouten }
504972fcea8cSEd Schouten 
505072fcea8cSEd Schouten #ifndef NO_CATGETS
505172fcea8cSEd Schouten /*
505272fcea8cSEd Schouten  |	Get the catalog entry, and if it got it from the catalog,
505372fcea8cSEd Schouten  |	make a copy, since the buffer will be overwritten by the
505472fcea8cSEd Schouten  |	next call to catgets().
505572fcea8cSEd Schouten  */
505672fcea8cSEd Schouten 
505772fcea8cSEd Schouten char *
505872fcea8cSEd Schouten catgetlocal(number, string)
505972fcea8cSEd Schouten int number;
506072fcea8cSEd Schouten char *string;
506172fcea8cSEd Schouten {
506272fcea8cSEd Schouten 	char *temp1;
506372fcea8cSEd Schouten 	char *temp2;
506472fcea8cSEd Schouten 
506572fcea8cSEd Schouten 	temp1 = catgets(catalog, 1, number, string);
506672fcea8cSEd Schouten 	if (temp1 != string)
506772fcea8cSEd Schouten 	{
506872fcea8cSEd Schouten 		temp2 = malloc(strlen(temp1) + 1);
506972fcea8cSEd Schouten 		strcpy(temp2, temp1);
507072fcea8cSEd Schouten 		temp1 = temp2;
507172fcea8cSEd Schouten 	}
507272fcea8cSEd Schouten 	return(temp1);
507372fcea8cSEd Schouten }
507472fcea8cSEd Schouten #endif /* NO_CATGETS */
507572fcea8cSEd Schouten 
507672fcea8cSEd Schouten /*
507772fcea8cSEd Schouten  |	The following is to allow for using message catalogs which allow
507872fcea8cSEd Schouten  |	the software to be 'localized', that is, to use different languages
507972fcea8cSEd Schouten  |	all with the same binary.  For more information, see your system
508072fcea8cSEd Schouten  |	documentation, or the X/Open Internationalization Guide.
508172fcea8cSEd Schouten  */
508272fcea8cSEd Schouten 
508372fcea8cSEd Schouten void
508472fcea8cSEd Schouten strings_init()
508572fcea8cSEd Schouten {
508672fcea8cSEd Schouten 	int counter;
508772fcea8cSEd Schouten 
508872fcea8cSEd Schouten #ifndef NO_CATGETS
508972fcea8cSEd Schouten 	setlocale(LC_ALL, "");
5090cfe04e82SEd Schouten 	catalog = catopen("ee", NL_CAT_LOCALE);
509172fcea8cSEd Schouten #endif /* NO_CATGETS */
509272fcea8cSEd Schouten 
509372fcea8cSEd Schouten 	modes_menu[0].item_string = catgetlocal( 1, "modes menu");
509472fcea8cSEd Schouten 	mode_strings[1]  = catgetlocal( 2, "tabs to spaces       ");
509572fcea8cSEd Schouten 	mode_strings[2]  = catgetlocal( 3, "case sensitive search");
509672fcea8cSEd Schouten 	mode_strings[3]  = catgetlocal( 4, "margins observed     ");
509772fcea8cSEd Schouten 	mode_strings[4]  = catgetlocal( 5, "auto-paragraph format");
509872fcea8cSEd Schouten 	mode_strings[5]  = catgetlocal( 6, "eightbit characters  ");
509972fcea8cSEd Schouten 	mode_strings[6]  = catgetlocal( 7, "info window          ");
510072fcea8cSEd Schouten 	mode_strings[8]  = catgetlocal( 8, "right margin         ");
510172fcea8cSEd Schouten 	leave_menu[0].item_string  = catgetlocal( 9, "leave menu");
510272fcea8cSEd Schouten 	leave_menu[1].item_string  = catgetlocal( 10, "save changes");
510372fcea8cSEd Schouten 	leave_menu[2].item_string  = catgetlocal( 11, "no save");
510472fcea8cSEd Schouten 	file_menu[0].item_string  = catgetlocal( 12, "file menu");
510572fcea8cSEd Schouten 	file_menu[1].item_string  = catgetlocal( 13, "read a file");
510672fcea8cSEd Schouten 	file_menu[2].item_string  = catgetlocal( 14, "write a file");
510772fcea8cSEd Schouten 	file_menu[3].item_string  = catgetlocal( 15, "save file");
510872fcea8cSEd Schouten 	file_menu[4].item_string  = catgetlocal( 16, "print editor contents");
510972fcea8cSEd Schouten 	search_menu[0].item_string = catgetlocal( 17, "search menu");
511072fcea8cSEd Schouten 	search_menu[1].item_string = catgetlocal( 18, "search for ...");
511172fcea8cSEd Schouten 	search_menu[2].item_string = catgetlocal( 19, "search");
511272fcea8cSEd Schouten 	spell_menu[0].item_string = catgetlocal( 20, "spell menu");
511372fcea8cSEd Schouten 	spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
511472fcea8cSEd Schouten 	spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
511572fcea8cSEd Schouten 	misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
511672fcea8cSEd Schouten 	misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
511772fcea8cSEd Schouten 	misc_menu[2].item_string = catgetlocal( 25, "shell command");
511872fcea8cSEd Schouten 	misc_menu[3].item_string = catgetlocal( 26, "check spelling");
511972fcea8cSEd Schouten 	main_menu[0].item_string  = catgetlocal( 27, "main menu");
512072fcea8cSEd Schouten 	main_menu[1].item_string  = catgetlocal( 28, "leave editor");
512172fcea8cSEd Schouten 	main_menu[2].item_string  = catgetlocal( 29, "help");
512272fcea8cSEd Schouten 	main_menu[3].item_string  = catgetlocal( 30, "file operations");
512372fcea8cSEd Schouten 	main_menu[4].item_string  = catgetlocal( 31, "redraw screen");
512472fcea8cSEd Schouten 	main_menu[5].item_string  = catgetlocal( 32, "settings");
512572fcea8cSEd Schouten 	main_menu[6].item_string  = catgetlocal( 33, "search");
512672fcea8cSEd Schouten 	main_menu[7].item_string  = catgetlocal( 34, "miscellaneous");
512772fcea8cSEd Schouten 	help_text[0] = catgetlocal( 35, "Control keys:                                                              ");
512872fcea8cSEd Schouten 	help_text[1] = catgetlocal( 36, "^a ascii code           ^i tab                  ^r right                   ");
512972fcea8cSEd Schouten 	help_text[2] = catgetlocal( 37, "^b bottom of text       ^j newline              ^t top of text             ");
513072fcea8cSEd Schouten 	help_text[3] = catgetlocal( 38, "^c command              ^k delete char          ^u up                      ");
513172fcea8cSEd Schouten 	help_text[4] = catgetlocal( 39, "^d down                 ^l left                 ^v undelete word           ");
513272fcea8cSEd Schouten 	help_text[5] = catgetlocal( 40, "^e search prompt        ^m newline              ^w delete word             ");
513372fcea8cSEd Schouten 	help_text[6] = catgetlocal( 41, "^f undelete char        ^n next page            ^x search                  ");
513472fcea8cSEd Schouten 	help_text[7] = catgetlocal( 42, "^g begin of line        ^o end of line          ^y delete line             ");
513572fcea8cSEd Schouten 	help_text[8] = catgetlocal( 43, "^h backspace            ^p prev page            ^z undelete line           ");
5136cfe04e82SEd Schouten 	help_text[9] = catgetlocal( 44, "^[ (escape) menu        ESC-Enter: exit ee                                 ");
513772fcea8cSEd Schouten 	help_text[10] = catgetlocal( 45, "                                                                           ");
513872fcea8cSEd Schouten 	help_text[11] = catgetlocal( 46, "Commands:                                                                  ");
513972fcea8cSEd Schouten 	help_text[12] = catgetlocal( 47, "help    : get this info                 file    : print file name          ");
514072fcea8cSEd Schouten 	help_text[13] = catgetlocal( 48, "read    : read a file                   char    : ascii code of char       ");
514172fcea8cSEd Schouten 	help_text[14] = catgetlocal( 49, "write   : write a file                  case    : case sensitive search    ");
514272fcea8cSEd Schouten 	help_text[15] = catgetlocal( 50, "exit    : leave and save                nocase  : case insensitive search  ");
514372fcea8cSEd Schouten 	help_text[16] = catgetlocal( 51, "quit    : leave, no save                !cmd    : execute \"cmd\" in shell   ");
514472fcea8cSEd Schouten 	help_text[17] = catgetlocal( 52, "line    : display line #                0-9     : go to line \"#\"           ");
514572fcea8cSEd Schouten 	help_text[18] = catgetlocal( 53, "expand  : expand tabs                   noexpand: do not expand tabs         ");
514672fcea8cSEd Schouten 	help_text[19] = catgetlocal( 54, "                                                                             ");
514772fcea8cSEd Schouten 	help_text[20] = catgetlocal( 55, "  ee [+#] [-i] [-e] [-h] [file(s)]                                            ");
514872fcea8cSEd Schouten 	help_text[21] = catgetlocal( 56, "+# :go to line #  -i :no info window  -e : don't expand tabs  -h :no highlight");
514972fcea8cSEd Schouten 	control_keys[0] = catgetlocal( 57, "^[ (escape) menu  ^e search prompt  ^y delete line    ^u up     ^p prev page  ");
515072fcea8cSEd Schouten 	control_keys[1] = catgetlocal( 58, "^a ascii code     ^x search         ^z undelete line  ^d down   ^n next page  ");
515172fcea8cSEd Schouten 	control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line  ^w delete word    ^l left                 ");
515272fcea8cSEd Schouten 	control_keys[3] = catgetlocal( 60, "^t top of text    ^o end of line    ^v undelete word  ^r right                ");
5153cfe04e82SEd Schouten 	control_keys[4] = catgetlocal( 61, "^c command        ^k delete char    ^f undelete char      ESC-Enter: exit ee  ");
515472fcea8cSEd Schouten 	command_strings[0] = catgetlocal( 62, "help : get help info  |file  : print file name         |line : print line # ");
515572fcea8cSEd Schouten 	command_strings[1] = catgetlocal( 63, "read : read a file    |char  : ascii code of char      |0-9 : go to line \"#\"");
515672fcea8cSEd Schouten 	command_strings[2] = catgetlocal( 64, "write: write a file   |case  : case sensitive search   |exit : leave and save ");
515772fcea8cSEd Schouten 	command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\"    |nocase: ignore case in search   |quit : leave, no save");
515872fcea8cSEd Schouten 	command_strings[4] = catgetlocal( 66, "expand: expand tabs   |noexpand: do not expand tabs                           ");
515972fcea8cSEd Schouten 	com_win_message = catgetlocal( 67, "    press Escape (^[) for menu");
516072fcea8cSEd Schouten 	no_file_string = catgetlocal( 68, "no file");
516172fcea8cSEd Schouten 	ascii_code_str = catgetlocal( 69, "ascii code: ");
516272fcea8cSEd Schouten 	printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
516372fcea8cSEd Schouten 	command_str = catgetlocal( 71, "command: ");
516472fcea8cSEd Schouten 	file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
516572fcea8cSEd Schouten 	file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
516672fcea8cSEd Schouten 	char_str = catgetlocal( 74, "character = %d");
516772fcea8cSEd Schouten 	unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
516872fcea8cSEd Schouten 	non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
516972fcea8cSEd Schouten 	line_num_str = catgetlocal( 77, "line %d  ");
517072fcea8cSEd Schouten 	line_len_str = catgetlocal( 78, "length = %d");
517172fcea8cSEd Schouten 	current_file_str = catgetlocal( 79, "current file is \"%s\" ");
517272fcea8cSEd Schouten 	usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [+line_number] [file(s)]\n");
517372fcea8cSEd Schouten 	usage1 = catgetlocal( 81, "       -i   turn off info window\n");
517472fcea8cSEd Schouten 	usage2 = catgetlocal( 82, "       -e   do not convert tabs to spaces\n");
517572fcea8cSEd Schouten 	usage3 = catgetlocal( 83, "       -h   do not use highlighting\n");
517672fcea8cSEd Schouten 	file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
517772fcea8cSEd Schouten 	new_file_msg = catgetlocal( 85, "new file \"%s\"");
517872fcea8cSEd Schouten 	cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
517972fcea8cSEd Schouten 	open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
518072fcea8cSEd Schouten 	file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
518172fcea8cSEd Schouten 	reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
518272fcea8cSEd Schouten 	read_only_msg = catgetlocal( 90, ", read only");
518372fcea8cSEd Schouten 	file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
518472fcea8cSEd Schouten 	save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
518572fcea8cSEd Schouten 	file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
518672fcea8cSEd Schouten 	changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
518772fcea8cSEd Schouten 	yes_char = catgetlocal( 95, "y");
518872fcea8cSEd Schouten 	file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
518972fcea8cSEd Schouten 	create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
519072fcea8cSEd Schouten 	writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
519172fcea8cSEd Schouten 	file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
519272fcea8cSEd Schouten 	searching_msg = catgetlocal( 100, "           ...searching");
519372fcea8cSEd Schouten 	str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
519472fcea8cSEd Schouten 	search_prompt_str = catgetlocal( 102, "search for: ");
519596b676e9SEd Schouten 	exec_err_msg = catgetlocal( 103, "could not exec %s\n");
519672fcea8cSEd Schouten 	continue_msg = catgetlocal( 104, "press return to continue ");
519772fcea8cSEd Schouten 	menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
519872fcea8cSEd Schouten 	menu_size_err_msg = catgetlocal( 106, "menu too large for window");
519972fcea8cSEd Schouten 	press_any_key_msg = catgetlocal( 107, "press any key to continue ");
520072fcea8cSEd Schouten 	shell_prompt = catgetlocal( 108, "shell command: ");
520172fcea8cSEd Schouten 	formatting_msg = catgetlocal( 109, "...formatting paragraph...");
520272fcea8cSEd Schouten 	shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
520372fcea8cSEd Schouten 	spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
520472fcea8cSEd Schouten 	margin_prompt = catgetlocal( 112, "right margin is: ");
520572fcea8cSEd Schouten 	restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
520672fcea8cSEd Schouten 	ON = catgetlocal( 114, "ON");
520772fcea8cSEd Schouten 	OFF = catgetlocal( 115, "OFF");
520872fcea8cSEd Schouten 	HELP = catgetlocal( 116, "HELP");
520972fcea8cSEd Schouten 	WRITE = catgetlocal( 117, "WRITE");
521072fcea8cSEd Schouten 	READ = catgetlocal( 118, "READ");
521172fcea8cSEd Schouten 	LINE = catgetlocal( 119, "LINE");
521272fcea8cSEd Schouten 	FILE_str = catgetlocal( 120, "FILE");
521372fcea8cSEd Schouten 	CHARACTER = catgetlocal( 121, "CHARACTER");
521472fcea8cSEd Schouten 	REDRAW = catgetlocal( 122, "REDRAW");
521572fcea8cSEd Schouten 	RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
521672fcea8cSEd Schouten 	AUTHOR = catgetlocal( 124, "AUTHOR");
521772fcea8cSEd Schouten 	VERSION = catgetlocal( 125, "VERSION");
521872fcea8cSEd Schouten 	CASE = catgetlocal( 126, "CASE");
521972fcea8cSEd Schouten 	NOCASE = catgetlocal( 127, "NOCASE");
522072fcea8cSEd Schouten 	EXPAND = catgetlocal( 128, "EXPAND");
522172fcea8cSEd Schouten 	NOEXPAND = catgetlocal( 129, "NOEXPAND");
522272fcea8cSEd Schouten 	Exit_string = catgetlocal( 130, "EXIT");
522372fcea8cSEd Schouten 	QUIT_string = catgetlocal( 131, "QUIT");
522472fcea8cSEd Schouten 	INFO = catgetlocal( 132, "INFO");
522572fcea8cSEd Schouten 	NOINFO = catgetlocal( 133, "NOINFO");
522672fcea8cSEd Schouten 	MARGINS = catgetlocal( 134, "MARGINS");
522772fcea8cSEd Schouten 	NOMARGINS = catgetlocal( 135, "NOMARGINS");
522872fcea8cSEd Schouten 	AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
522972fcea8cSEd Schouten 	NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
523072fcea8cSEd Schouten 	Echo = catgetlocal( 138, "ECHO");
523172fcea8cSEd Schouten 	PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
523272fcea8cSEd Schouten 	RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
523372fcea8cSEd Schouten 	HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
523472fcea8cSEd Schouten 	NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
523572fcea8cSEd Schouten 	EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
523672fcea8cSEd Schouten 	NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
523772fcea8cSEd Schouten 	/*
523872fcea8cSEd Schouten 	 |	additions
523972fcea8cSEd Schouten 	 */
524072fcea8cSEd Schouten 	mode_strings[7] = catgetlocal( 145, "emacs key bindings   ");
524172fcea8cSEd Schouten 	emacs_help_text[0] = help_text[0];
524272fcea8cSEd Schouten 	emacs_help_text[1] = catgetlocal( 146, "^a beginning of line    ^i tab                  ^r restore word            ");
524396b676e9SEd Schouten 	emacs_help_text[2] = catgetlocal( 147, "^b back 1 char          ^j undel char           ^t top of text             ");
524496b676e9SEd Schouten 	emacs_help_text[3] = catgetlocal( 148, "^c command              ^k delete line          ^u bottom of text          ");
524572fcea8cSEd Schouten 	emacs_help_text[4] = catgetlocal( 149, "^d delete char          ^l undelete line        ^v next page               ");
524672fcea8cSEd Schouten 	emacs_help_text[5] = catgetlocal( 150, "^e end of line          ^m newline              ^w delete word             ");
524772fcea8cSEd Schouten 	emacs_help_text[6] = catgetlocal( 151, "^f forward 1 char       ^n next line            ^x search                  ");
524872fcea8cSEd Schouten 	emacs_help_text[7] = catgetlocal( 152, "^g go back 1 page       ^o ascii char insert    ^y search prompt           ");
524972fcea8cSEd Schouten 	emacs_help_text[8] = catgetlocal( 153, "^h backspace            ^p prev line            ^z next word               ");
525072fcea8cSEd Schouten 	emacs_help_text[9] = help_text[9];
525172fcea8cSEd Schouten 	emacs_help_text[10] = help_text[10];
525272fcea8cSEd Schouten 	emacs_help_text[11] = help_text[11];
525372fcea8cSEd Schouten 	emacs_help_text[12] = help_text[12];
525472fcea8cSEd Schouten 	emacs_help_text[13] = help_text[13];
525572fcea8cSEd Schouten 	emacs_help_text[14] = help_text[14];
525672fcea8cSEd Schouten 	emacs_help_text[15] = help_text[15];
525772fcea8cSEd Schouten 	emacs_help_text[16] = help_text[16];
525872fcea8cSEd Schouten 	emacs_help_text[17] = help_text[17];
525972fcea8cSEd Schouten 	emacs_help_text[18] = help_text[18];
526072fcea8cSEd Schouten 	emacs_help_text[19] = help_text[19];
526172fcea8cSEd Schouten 	emacs_help_text[20] = help_text[20];
526272fcea8cSEd Schouten 	emacs_help_text[21] = help_text[21];
526396b676e9SEd Schouten 	emacs_control_keys[0] = catgetlocal( 154, "^[ (escape) menu ^y search prompt ^k delete line   ^p prev li     ^g prev page");
526496b676e9SEd Schouten 	emacs_control_keys[1] = catgetlocal( 155, "^o ascii code    ^x search        ^l undelete line ^n next li     ^v next page");
526596b676e9SEd Schouten 	emacs_control_keys[2] = catgetlocal( 156, "^u end of file   ^a begin of line ^w delete word   ^b back 1 char ^z next word");
526696b676e9SEd Schouten 	emacs_control_keys[3] = catgetlocal( 157, "^t top of text   ^e end of line   ^r restore word  ^f forward char            ");
5267cfe04e82SEd Schouten 	emacs_control_keys[4] = catgetlocal( 158, "^c command       ^d delete char   ^j undelete char              ESC-Enter: exit");
526872fcea8cSEd Schouten 	EMACS_string = catgetlocal( 159, "EMACS");
526972fcea8cSEd Schouten 	NOEMACS_string = catgetlocal( 160, "NOEMACS");
527072fcea8cSEd Schouten 	usage4 = catgetlocal( 161, "       +#   put cursor at line #\n");
527172fcea8cSEd Schouten 	conf_dump_err_msg = catgetlocal( 162, "unable to open .init.ee for writing, no configuration saved!");
527272fcea8cSEd Schouten 	conf_dump_success_msg = catgetlocal( 163, "ee configuration saved in file %s");
527372fcea8cSEd Schouten 	modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
527472fcea8cSEd Schouten 	config_dump_menu[0].item_string = catgetlocal( 165, "save ee configuration");
527572fcea8cSEd Schouten 	config_dump_menu[1].item_string = catgetlocal( 166, "save in current directory");
527672fcea8cSEd Schouten 	config_dump_menu[2].item_string = catgetlocal( 167, "save in home directory");
527772fcea8cSEd Schouten 	conf_not_saved_msg = catgetlocal( 168, "ee configuration not saved");
527872fcea8cSEd Schouten 	ree_no_file_msg = catgetlocal( 169, "must specify a file when invoking ree");
527972fcea8cSEd Schouten 	menu_too_lrg_msg = catgetlocal( 180, "menu too large for window");
528072fcea8cSEd Schouten 	more_above_str = catgetlocal( 181, "^^more^^");
528172fcea8cSEd Schouten 	more_below_str = catgetlocal( 182, "VVmoreVV");
528272fcea8cSEd Schouten 	mode_strings[9] = catgetlocal( 183, "16 bit characters    ");
528372fcea8cSEd Schouten 	chinese_cmd = catgetlocal( 184, "16BIT");
528472fcea8cSEd Schouten 	nochinese_cmd = catgetlocal( 185, "NO16BIT");
528572fcea8cSEd Schouten 
528672fcea8cSEd Schouten 	commands[0] = HELP;
528772fcea8cSEd Schouten 	commands[1] = WRITE;
528872fcea8cSEd Schouten 	commands[2] = READ;
528972fcea8cSEd Schouten 	commands[3] = LINE;
529072fcea8cSEd Schouten 	commands[4] = FILE_str;
529172fcea8cSEd Schouten 	commands[5] = REDRAW;
529272fcea8cSEd Schouten 	commands[6] = RESEQUENCE;
529372fcea8cSEd Schouten 	commands[7] = AUTHOR;
529472fcea8cSEd Schouten 	commands[8] = VERSION;
529572fcea8cSEd Schouten 	commands[9] = CASE;
529672fcea8cSEd Schouten 	commands[10] = NOCASE;
529772fcea8cSEd Schouten 	commands[11] = EXPAND;
529872fcea8cSEd Schouten 	commands[12] = NOEXPAND;
529972fcea8cSEd Schouten 	commands[13] = Exit_string;
530072fcea8cSEd Schouten 	commands[14] = QUIT_string;
530172fcea8cSEd Schouten 	commands[15] = "<";
530272fcea8cSEd Schouten 	commands[16] = ">";
530372fcea8cSEd Schouten 	commands[17] = "!";
530472fcea8cSEd Schouten 	commands[18] = "0";
530572fcea8cSEd Schouten 	commands[19] = "1";
530672fcea8cSEd Schouten 	commands[20] = "2";
530772fcea8cSEd Schouten 	commands[21] = "3";
530872fcea8cSEd Schouten 	commands[22] = "4";
530972fcea8cSEd Schouten 	commands[23] = "5";
531072fcea8cSEd Schouten 	commands[24] = "6";
531172fcea8cSEd Schouten 	commands[25] = "7";
531272fcea8cSEd Schouten 	commands[26] = "8";
531372fcea8cSEd Schouten 	commands[27] = "9";
531472fcea8cSEd Schouten 	commands[28] = CHARACTER;
531572fcea8cSEd Schouten 	commands[29] = chinese_cmd;
531672fcea8cSEd Schouten 	commands[30] = nochinese_cmd;
531772fcea8cSEd Schouten 	commands[31] = NULL;
531872fcea8cSEd Schouten 	init_strings[0] = CASE;
531972fcea8cSEd Schouten 	init_strings[1] = NOCASE;
532072fcea8cSEd Schouten 	init_strings[2] = EXPAND;
532172fcea8cSEd Schouten 	init_strings[3] = NOEXPAND;
532272fcea8cSEd Schouten 	init_strings[4] = INFO;
532372fcea8cSEd Schouten 	init_strings[5] = NOINFO;
532472fcea8cSEd Schouten 	init_strings[6] = MARGINS;
532572fcea8cSEd Schouten 	init_strings[7] = NOMARGINS;
532672fcea8cSEd Schouten 	init_strings[8] = AUTOFORMAT;
532772fcea8cSEd Schouten 	init_strings[9] = NOAUTOFORMAT;
532872fcea8cSEd Schouten 	init_strings[10] = Echo;
532972fcea8cSEd Schouten 	init_strings[11] = PRINTCOMMAND;
533072fcea8cSEd Schouten 	init_strings[12] = RIGHTMARGIN;
533172fcea8cSEd Schouten 	init_strings[13] = HIGHLIGHT;
533272fcea8cSEd Schouten 	init_strings[14] = NOHIGHLIGHT;
533372fcea8cSEd Schouten 	init_strings[15] = EIGHTBIT;
533472fcea8cSEd Schouten 	init_strings[16] = NOEIGHTBIT;
533572fcea8cSEd Schouten 	init_strings[17] = EMACS_string;
533672fcea8cSEd Schouten 	init_strings[18] = NOEMACS_string;
533772fcea8cSEd Schouten 	init_strings[19] = chinese_cmd;
533872fcea8cSEd Schouten 	init_strings[20] = nochinese_cmd;
533972fcea8cSEd Schouten 	init_strings[21] = NULL;
534072fcea8cSEd Schouten 
534172fcea8cSEd Schouten 	/*
534272fcea8cSEd Schouten 	 |	allocate space for strings here for settings menu
534372fcea8cSEd Schouten 	 */
534472fcea8cSEd Schouten 
534572fcea8cSEd Schouten 	for (counter = 1; counter < NUM_MODES_ITEMS; counter++)
534672fcea8cSEd Schouten 	{
534772fcea8cSEd Schouten 		modes_menu[counter].item_string = malloc(80);
534872fcea8cSEd Schouten 	}
534972fcea8cSEd Schouten 
535072fcea8cSEd Schouten #ifndef NO_CATGETS
535172fcea8cSEd Schouten 	catclose(catalog);
535272fcea8cSEd Schouten #endif /* NO_CATGETS */
535372fcea8cSEd Schouten }
535472fcea8cSEd Schouten 
5355