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