1 /*
2  |	control.c
3  |
4  |	$Header: /home/hugh/sources/aee/RCS/control.c,v 1.50 2010/07/18 00:56:20 hugh Exp hugh $
5  */
6 
7 /*
8  |	Copyright (c) 1986 - 1988, 1991 - 2000 - 2002, 2009, 2010 Hugh Mahon.
9  */
10 
11 #include "aee.h"
12 
13 static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";
14 
15 #define max_alpha_char 36
16 
17 int
menu_op(menu_list)18 menu_op(menu_list)
19 struct menu_entries menu_list[];
20 {
21 	WINDOW *temp_win;
22 	int max_width, max_height;
23 	int x_off, y_off;
24 	int counter;
25 	int length;
26 	int input;
27 	int temp;
28 	int list_size;
29 	int top_offset;		/* offset from top where menu items start */
30 	int vert_pos;		/* vertical position			  */
31 	int vert_size;		/* vertical size for menu list item display */
32 	int off_start = 1;	/* offset from start of menu items to start display */
33 
34 
35 	/*
36 	 |	determine number and width of menu items
37 	 */
38 
39 	list_size = 1;
40 	while (menu_list[list_size + 1].item_string != NULL)
41 		list_size++;
42 	max_width = 0;
43 	for (counter = 0; counter <= list_size; counter++)
44 	{
45 		if ((length = strlen(menu_list[counter].item_string)) > max_width)
46 			max_width = length;
47 	}
48 	max_width += 3;
49 	max_width = max(max_width, strlen(cancel_string));
50 	max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str)));
51 	max_width += 6;
52 
53 	/*
54 	 |	make sure that window is large enough to handle menu
55 	 |	if not, print error message and return to calling function
56 	 */
57 
58 	if ((max_width > COLS) || ((list_size > LINES) && (LINES < 3)))
59 	{
60 		wmove(com_win, 0, 0);
61 		werase(com_win);
62 		wprintw(com_win, menu_too_lrg_msg);
63 		wrefresh(com_win);
64 		clr_cmd_line = TRUE;
65 		return(0);
66 	}
67 
68 	top_offset = 0;
69 
70 	if (list_size > LINES)
71 	{
72 		max_height = LINES;
73 		if (max_height > 11)
74 			vert_size = max_height - 8;
75 		else
76 			vert_size = max_height;
77 	}
78 	else
79 	{
80 		vert_size = list_size;
81 		max_height = list_size;
82 	}
83 
84 	if (LINES >= (vert_size + 8))
85 	{
86 		if (menu_list[0].argument != MENU_WARN)
87 			max_height = vert_size + 8;
88 		else
89 			max_height = vert_size + 7;
90 		top_offset = 4;
91 	}
92 	x_off = (COLS - max_width) / 2;
93 	y_off = (LINES - max_height - 1) / 2;
94 	temp_win = newwin(max_height, max_width, y_off, x_off);
95 	keypad(temp_win, TRUE);
96 
97 	paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size);
98 
99 	counter = 1;
100 	vert_pos = 0;
101 	do
102 	{
103 		if (off_start > 2)
104 			wmove(temp_win, (1 + counter + top_offset - off_start), 3);
105 		else
106 			wmove(temp_win, (counter + top_offset - off_start), 3);
107 
108 		wrefresh(temp_win);
109 		get_input(temp_win);
110 		input = in;
111 		if (input == -1)
112 			exit(0);
113 
114 		if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) ||
115 		    ((input >= '0') && (input <= '9')))
116 		{
117 			if ((tolower(input) >= 'a') && (tolower(input) <= 'z'))
118 			{
119 				temp = 1 + tolower(input) - 'a';
120 			}
121 			else if ((input >= '0') && (input <= '9'))
122 			{
123 				temp = (2 + 'z' - 'a') + (input - '0');
124 			}
125 
126 			if (temp <= list_size)
127 			{
128 				input = '\n';
129 				counter = temp;
130 			}
131 		}
132 		else
133 		{
134 			switch (input)
135 			{
136 				case ' ':	/* space	*/
137 				case '\004':	/* ^d, down	*/
138 				case KEY_RIGHT:
139 				case KEY_DOWN:
140 					counter++;
141 					if (counter > list_size)
142 						counter = 1;
143 					break;
144 				case '\010':	/* ^h, backspace*/
145 				case '\025':	/* ^u, up	*/
146 				case 127:	/* ^?, delete	*/
147 				case KEY_BACKSPACE:
148 				case KEY_LEFT:
149 				case KEY_UP:
150 					counter--;
151 					if (counter == 0)
152 						counter = list_size;
153 					break;
154 				case '\033':	/* escape key	*/
155 					if (menu_list[0].argument != MENU_WARN)
156 						counter = 0;
157 					break;
158 				case '\014':	/* ^l       	*/
159 				case '\022':	/* ^r, redraw	*/
160 					paint_menu(menu_list, max_width, max_height,
161 						list_size, top_offset, temp_win,
162 						off_start, vert_size);
163 					break;
164 				default:
165 					break;
166 			}
167 		}
168 
169 		if (((list_size - off_start) >= (vert_size - 1)) &&
170 			(counter > (off_start + vert_size - 3)) &&
171 				(off_start > 1))
172 		{
173 			if (counter == list_size)
174 				off_start = (list_size - vert_size) + 2;
175 			else
176 				off_start++;
177 
178 			paint_menu(menu_list, max_width, max_height,
179 				   list_size, top_offset, temp_win, off_start,
180 				   vert_size);
181 		}
182 		else if ((list_size != vert_size) &&
183 				(counter > (off_start + vert_size - 2)))
184 		{
185 			if (counter == list_size)
186 				off_start = 2 + (list_size - vert_size);
187 			else if (off_start == 1)
188 				off_start = 3;
189 			else
190 				off_start++;
191 
192 			paint_menu(menu_list, max_width, max_height,
193 				   list_size, top_offset, temp_win, off_start,
194 				   vert_size);
195 		}
196 		else if (counter < off_start)
197 		{
198 			if (counter <= 2)
199 				off_start = 1;
200 			else
201 				off_start = counter;
202 
203 			paint_menu(menu_list, max_width, max_height,
204 				   list_size, top_offset, temp_win, off_start,
205 				   vert_size);
206 		}
207 	}
208 	while ((input != '\r') && (input != '\n') && (counter != 0));
209 
210 	werase(temp_win);
211 	wrefresh(temp_win);
212 	delwin(temp_win);
213 
214 	if ((menu_list[counter].procedure != NULL) ||
215 	    (menu_list[counter].iprocedure != NULL) ||
216 	    (menu_list[counter].nprocedure != NULL))
217 	{
218 		if (menu_list[counter].argument != -1)
219 			(*menu_list[counter].iprocedure)(menu_list[counter].argument);
220 		else if (menu_list[counter].ptr_argument != NULL)
221 			(*menu_list[counter].procedure)(menu_list[counter].ptr_argument);
222 		else
223 			(*menu_list[counter].nprocedure)();
224 	}
225 
226 	if (info_window)
227 		paint_info_win();
228 	redraw();
229 
230 	return(counter);
231 }
232 
233 void
paint_menu(menu_list,max_width,max_height,list_size,top_offset,menu_win,off_start,vert_size)234 paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win,
235 	   off_start, vert_size)
236 struct menu_entries menu_list[];
237 int max_width, max_height, list_size, top_offset;
238 WINDOW *menu_win;
239 int off_start, vert_size;
240 {
241 	int counter, temp_int;
242 
243 	werase(menu_win);
244 
245 	/*
246 	 |	output top and bottom portions of menu box only if window
247 	 |	large enough
248 	 */
249 
250 	if (max_height > vert_size)
251 	{
252 		wmove(menu_win, 1, 1);
253 		if (!nohighlight)
254 			wstandout(menu_win);
255 		waddch(menu_win, '+');
256 		for (counter = 0; counter < (max_width - 4); counter++)
257 			waddch(menu_win, '-');
258 		waddch(menu_win, '+');
259 
260 		wmove(menu_win, (max_height - 2), 1);
261 		waddch(menu_win, '+');
262 		for (counter = 0; counter < (max_width - 4); counter++)
263 			waddch(menu_win, '-');
264 		waddch(menu_win, '+');
265 		wstandend(menu_win);
266 		wmove(menu_win, 2, 3);
267 		waddstr(menu_win, menu_list[0].item_string);
268 		wmove(menu_win, (max_height - 3), 3);
269 		if (menu_list[0].argument != MENU_WARN)
270 			waddstr(menu_win, cancel_string);
271 	}
272 	if (!nohighlight)
273 		wstandout(menu_win);
274 
275 	for (counter = 0; counter < (vert_size + top_offset); counter++)
276 	{
277 		if (top_offset == 4)
278 		{
279 			temp_int = counter + 2;
280 		}
281 		else
282 			temp_int = counter;
283 
284 		wmove(menu_win, temp_int, 1);
285 		waddch(menu_win, '|');
286 		wmove(menu_win, temp_int, (max_width - 2));
287 		waddch(menu_win, '|');
288 	}
289 	wstandend(menu_win);
290 
291 	if (list_size > vert_size)
292 	{
293 		if (off_start >= 3)
294 		{
295 			temp_int = 1;
296 			wmove(menu_win, top_offset, 3);
297 			waddstr(menu_win, more_above_str);
298 		}
299 		else
300 			temp_int = 0;
301 
302 		for (counter = off_start;
303 			((temp_int + counter - off_start) < (vert_size - 1));
304 				counter++)
305 		{
306 			wmove(menu_win, (top_offset + temp_int +
307 						(counter - off_start)), 3);
308 			if (list_size > 1)
309 				wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
310 			waddstr(menu_win, menu_list[counter].item_string);
311 		}
312 
313 		wmove(menu_win, (top_offset + (vert_size - 1)), 3);
314 
315 		if (counter == list_size)
316 		{
317 			if (list_size > 1)
318 				wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
319 			wprintw(menu_win, menu_list[counter].item_string);
320 		}
321 		else
322 			wprintw(menu_win, more_below_str);
323 	}
324 	else
325 	{
326 		for (counter = 1; counter <= list_size; counter++)
327 		{
328 			wmove(menu_win, (top_offset + counter - 1), 3);
329 			if (list_size > 1)
330 				wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]);
331 			waddstr(menu_win, menu_list[counter].item_string);
332 		}
333 	}
334 }
335 
336 void
shell_op()337 shell_op()
338 {
339 	char *string;
340 
341 	if (((string = get_string(shell_cmd_prompt, TRUE)) != NULL) &&
342 			(*string != '\0'))
343 	{
344 		sh_command(string);
345 		free(string);
346 	}
347 }
348 
349 void
leave_op()350 leave_op()
351 {
352 	int index;
353 
354 	if ((num_of_bufs > 1) && (top_of_stack == NULL))
355 	{
356 		index = menu_op(leave_menu_2);
357 		switch(index)
358 		{
359 			case 2:	index = delete_all_buffers();
360 				if (index == FALSE)
361 					return;
362 				break;
363 			case 1:
364 			default:
365 				repaint_screen();
366 				return;
367 		}
368 	}
369 	if (first_buff->changed)
370 	{
371 		index = menu_op(leave_menu);
372 		repaint_screen();
373 		switch (index)
374 		{
375 			case 1:	finish(EXIT_str);
376 				break;
377 			case 2:	first_buff->changed = FALSE;
378 				quit(QUIT_str);
379 				break;
380 			default: return;
381 		}
382 	}
383 	else
384 	{
385 		repaint_screen();
386 		quit(QUIT_str);
387 	}
388 }
389 
390 void
spell_op()391 spell_op()	/* check spelling of words in the editor	*/
392 {
393 	if (restrict_mode())
394 	{
395 		return;
396 	}
397 
398 	top();			/* go to top of file		*/
399 	insert_line(FALSE);	/* create two blank lines	*/
400 	insert_line(FALSE);
401 	top();
402 	command(shell_echo_msg);
403 	adv_line();
404 	wmove(com_win, 0, 0);
405 	wprintw(com_win, spell_in_prog_msg);
406 	wrefresh(com_win);
407 	command("<>!spell");	/* send contents of buffer to command 'spell'
408 				   and read the results back into the editor */
409 }
410 
411 void
ispell_op()412 ispell_op()
413 {
414 	char name[128];
415 	char string[256];
416 	int pid;
417 
418 	if (restrict_mode())
419 	{
420 		return;
421 	}
422 
423 	pid = getpid();
424 	sprintf(name, "/tmp/ae.%d", pid);
425 	if (write_file(name))
426 	{
427 		sprintf(string, "ispell %s", name);
428 		sh_command(string);
429 		delete_text();
430 		tmp_file = name;
431 		recv_file = TRUE;
432 		check_fp();
433 		unlink(name);
434 	}
435 }
436 
437 void
modes_op()438 modes_op()
439 {
440 	int ret_value;
441 	int counter;
442 	char *string;
443 	int temp_int;
444 
445 	modes_menu[17].item_string = mode_strings[17];
446 
447 	do
448 	{
449 		sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1],
450 					(expand ? ON : OFF));
451 		sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2],
452 					(case_sen ? ON : OFF));
453 		sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3],
454 					( literal ? ON : OFF));
455 		sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4],
456 					(forward ? "forward" : "reverse"));
457 		sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5],
458 					(observ_margins ? ON : OFF));
459 		sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6],
460 					( info_window ? ON : OFF));
461 		sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7],
462 					( status_line ? ON : OFF));
463 		sprintf(modes_menu[8].item_string, "%s %s", mode_strings[8],
464 					( indent ? ON : OFF));
465 		sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
466 					( overstrike ? ON : OFF));
467 		sprintf(modes_menu[10].item_string, "%s %s", mode_strings[10],
468 					( auto_format ? ON : OFF));
469 		sprintf(modes_menu[11].item_string, "%s %s", mode_strings[11],
470 					( windows ? ON : OFF));
471 		sprintf(modes_menu[12].item_string, "%s %3d", mode_strings[12],
472 					left_margin);
473 		sprintf(modes_menu[13].item_string, "%s %3d", mode_strings[13],
474 					right_margin);
475 		sprintf(modes_menu[14].item_string, "%s %3d", mode_strings[14],
476 					(info_win_height - 1));
477 		sprintf(modes_menu[15].item_string, "%s %s", mode_strings[15],
478 					(text_only ? text_msg : binary_msg ));
479 		sprintf(modes_menu[16].item_string, "%s %s", mode_strings[16],
480 					(curr_buff->dos_file ? dos_msg : unix_msg ));
481 
482 		ret_value = menu_op(modes_menu);
483 
484 		switch (ret_value)
485 		{
486 			case 1:
487 				expand = !expand;
488 				break;
489 			case 2:
490 				case_sen = !case_sen;
491 				break;
492 			case 3:
493 				literal = !literal;
494 				break;
495 			case 4:
496 				forward = !forward;
497 				break;
498 			case 5:
499 				observ_margins = !observ_margins;
500 				break;
501 			case 6:
502 				info_op();
503 				break;
504 			case 7:
505 				status_line = !status_line;
506 				break;
507 			case 8:
508 				indent = !indent;
509 				break;
510 			case 9:
511 				overstrike = !overstrike;
512 				break;
513 			case 10:
514 				auto_format = !auto_format;
515 				if (auto_format)
516 				{
517 					observ_margins = TRUE;
518 					indent = FALSE;
519 				}
520 				break;
521 			case 11:
522 				if (!windows)
523 					make_win();
524 				else
525 					no_windows();
526 				break;
527 			case 12:
528 				string = get_string(left_marg_prompt, TRUE);
529 				if (string != NULL)
530 				{
531 					counter = atoi(string);
532 					if (counter < right_margin)
533 						left_margin = counter;
534 					else
535 					{
536 						wmove(com_win, 0, 0);
537 						werase(com_win);
538 						wprintw(com_win, left_mrgn_err_msg);
539 						wrefresh(com_win);
540 					}
541 					free(string);
542 				}
543 				break;
544 			case 13:
545 				string = get_string(right_mrgn_prompt, TRUE);
546 				if (string != NULL)
547 				{
548 					counter = atoi(string);
549 					if (counter > left_margin)
550 						right_margin = counter;
551 					else
552 					{
553 						wmove(com_win, 0, 0);
554 						werase(com_win);
555 						wprintw(com_win, right_mrgn_err_msg);
556 						wrefresh(com_win);
557 					}
558 					free(string);
559 				}
560 				break;
561 			case 14:
562 				temp_int = info_win_height;
563 				string = get_string(info_win_height_prompt, TRUE);
564 				if (string != NULL)
565 				{
566 					counter = atoi(string);
567 					if ((counter > 0) && (counter <= MAX_HELP_LINES))
568 						info_win_height = counter + 1;
569 					else
570 					{
571 						wmove(com_win, 0, 0);
572 						werase(com_win);
573 						wprintw(com_win, info_win_height_err);
574 						wrefresh(com_win);
575 					}
576 					free(string);
577 					if ((info_win_height != temp_int) && (info_window))
578 					{
579 						redo_win();
580 						curr_buff->last_line = curr_buff->lines - 1;
581 						new_screen();
582 						paint_info_win();
583 						redraw();
584 					}
585 				}
586 				break;
587 			case 15:
588 				text_only = !text_only;
589 				break;
590 			case 16:
591 				if (text_only)
592 					curr_buff->dos_file = !curr_buff->dos_file;
593 				break;
594 			case 17:
595 				dump_aee_conf();
596 				break;
597 			default:
598 				break;
599 		}
600 	}
601 	while (ret_value != 0);
602 }
603 
604 void
search_op()605 search_op()
606 {
607 	search(TRUE, curr_buff->curr_line, curr_buff->position, curr_buff->pointer, 0, FALSE, TRUE);
608 }
609 
610 
611 int
file_op(arg)612 file_op(arg)
613 int arg;
614 {
615 	char *string;
616 	int flag;
617 
618 	if (arg == READ_FILE)
619 	{
620 		if (restrict_mode())
621 		{
622 			return(1);
623 		}
624 
625 		string = get_string(file_read_prompt_str, TRUE);
626 		recv_file = TRUE;
627 		tmp_file = resolve_name(string);
628 		check_fp();
629 		if (tmp_file != string)
630 			free(tmp_file);
631 		free(string);
632 	}
633 	else if (arg == WRITE_FILE)
634 	{
635 		if (restrict_mode())
636 		{
637 			return(1);
638 		}
639 
640 		string = get_string(file_write_prompt_str, TRUE);
641 		tmp_file = resolve_name(string);
642 		write_file(tmp_file);
643 		if (tmp_file != string)
644 			free(tmp_file);
645 		free(string);
646 	}
647 	else if (arg == SAVE_FILE)
648 	{
649 	/*
650 	 |	changes made here should be reflected in finish() and
651 	 |	in command() where SAVE_str is handled.
652 	 */
653 
654 		if (!curr_buff->edit_buffer)
655 			chng_buf(main_buffer_name);
656 
657 		if (!curr_buff->changed)
658 		{
659 			wmove(com_win, 0, 0);
660 			wprintw(com_win, no_chng_no_save );
661 			wclrtoeol(com_win);
662 			wrefresh(com_win);
663 			return(0);
664 		}
665 
666 		string = curr_buff->full_name;
667 
668 		if ((string != NULL) && (*string != '\0'))
669 			flag = TRUE;
670 		else
671 			flag = FALSE;
672 
673 		if ((string == NULL) || (*string == '\0'))
674 		{
675 			if (restrict_mode())
676 			{
677 				return(1);
678 			}
679 
680 			string = get_string(save_file_name_prompt, TRUE);
681 		}
682 		if ((string == NULL) || (*string == '\0'))
683 		{
684 			wmove(com_win, 0, 0);
685 			wprintw(com_win, file_not_saved_msg );
686 			wclrtoeol(com_win);
687 			wrefresh(com_win);
688 			clr_cmd_line = TRUE;
689 			return(0);
690 		}
691 
692 		if (!flag)
693 		{
694 			tmp_file = resolve_name(string);
695 			if (tmp_file != string)
696 			{
697 				free(string);
698 				string = tmp_file;
699 			}
700 		}
701 
702 		if (write_file(string))
703 		{
704 			if (curr_buff->file_name == NULL)
705 			{
706 				curr_buff->full_name = get_full_path(string,
707 							NULL);
708 				curr_buff->file_name =
709 					ae_basename(curr_buff->full_name);
710 			}
711 			curr_buff->changed = FALSE;
712 			change = FALSE;
713 		}
714 		else
715 		{
716 			if (!flag)
717 				free(string);
718 			return(1);
719 		}
720 	}
721 	return(0);
722 }
723 
724 void
info_op()725 info_op()
726 {
727 	info_window = !info_window;
728 	redo_win();
729 	curr_buff->last_line = curr_buff->lines - 1;
730 	new_screen();
731 	if (info_window)
732 		paint_info_win();
733 	redraw();
734 }
735 
736 int
macro_assign(keys,macro_string)737 macro_assign(keys, macro_string)
738 char *keys[];
739 char *macro_string;
740 {
741 	int counter;
742 	char *temp;
743 
744 	for (counter = 0; counter < 32; counter++)
745 	{
746 		temp = keys[counter];
747 		if (compare(temp, macro_string, FALSE))
748 		{
749 			temp = next_word(temp);
750 			if (*temp == '\0')
751 				return(counter);
752 		}
753 	}
754 	return(-1);
755 }
756 
757 void
get_key_assgn()758 get_key_assgn()
759 {
760 	int counter;
761 	int local_index;
762 
763 	assignment[gold_key_index].ckey = 0;
764 	if ((local_index = macro_assign(ctr, assignment[gold_key_index].macro)) != -1)
765 	{
766 		assignment[gold_key_index].ckey = local_index;
767 	}
768 	for (counter = 1; counter < gold_key_index; counter++)
769 	{
770 		assignment[counter].ckey = -1;
771 		assignment[counter].gckey = -1;
772 		if ((local_index = macro_assign(ctr, assignment[counter].macro)) != -1)
773 		{
774 			assignment[counter].ckey = local_index;
775 		}
776 		if (((local_index = macro_assign(g_ctr, assignment[counter].macro)) != -1) && (assignment[gold_key_index].ckey))
777 		{
778 			assignment[counter].gckey = local_index;
779 		}
780 	}
781 	paint_information();
782 }
783 
784 void
paint_information()785 paint_information()
786 {
787 	int counter;
788 	int local_index;
789 	int line_index;
790 	int column, width;
791 	char buffer[64];
792 
793 	for (counter = 0; counter < (info_win_height - 1); counter++)
794 	{
795 		info_data[counter][0] = '\0';
796 	}
797 
798 	width = 0;
799 	column = 0;
800 	for (counter = 0, local_index = 1;
801 		((width + column) <= min(COLS, MAX_HELP_COLS)) &&
802 			(local_index < (gold_key_index + 1)) &&
803 			(assignment[local_index].macro != NULL);
804 						counter++, local_index++)
805 	{
806 		line_index = counter % (info_win_height - 1);
807 		if (line_index == 0)
808 			column += width;
809 		while ((assignment[local_index].ckey < 0) &&
810 				(assignment[local_index].gckey < 0) &&
811 				(assignment[local_index].macro != NULL))
812 			local_index++;
813 		if (local_index > gold_key_index)
814 			break;
815 		if (assignment[local_index].ckey >= 0)
816 		{
817 			if (assignment[local_index].ckey  == 26)
818 						/* corresponds with Escape */
819 				sprintf(buffer, "Esc  %s ",
820 					assignment[local_index].description);
821 			else
822 				sprintf(buffer, "^%c   %s ",
823 					(assignment[local_index].ckey + 'A'),
824 					assignment[local_index].description);
825 		}
826 		else if (assignment[local_index].gckey > 0)
827 			sprintf(buffer, "^%c^%c %s ",
828 				(assignment[gold_key_index].ckey + 'A'),
829 				(assignment[local_index].gckey + 'A'),
830 				assignment[local_index].description);
831 
832 		width = max(width, strlen(buffer));
833 		if ((width + column) <= min(COLS, MAX_HELP_COLS))
834 			strcat(info_data[line_index], buffer);
835 	}
836 }
837 
838 void
paint_info_win()839 paint_info_win()
840 {
841 	int counter;
842 	int width, column;
843 	int index;
844 
845 	if ((!info_window) || (info_win == 0))
846 		return;
847 
848         werase(info_win);
849 
850 	if (info_type == COMMANDS)
851 	{
852 		index = 0;
853 		for (column = 0; column < COLS && (commands[index] != NULL);
854 							  column += width + 1)
855 		{
856 			width = 0;
857 			for (counter = 0;
858 				counter < (info_win_height - 1) &&
859 					(commands[index] != NULL);
860 								counter++)
861 			{
862 				width = max(width, strlen(commands[index]));
863 				if ((width + column) < COLS)
864 				{
865 					wmove(info_win, counter, column);
866 					waddstr(info_win, commands[index]);
867 				}
868 				index++;
869 			}
870 		}
871 	}
872 	else if (info_type == CONTROL_KEYS)
873 	{
874 		for (counter = 0; counter < (info_win_height - 1); counter++)
875 		{
876 			wmove(info_win, counter, 0);
877 			wclrtoeol(info_win);
878 			waddstr(info_win, info_data[counter]);
879 		}
880 	}
881 	wmove(info_win, (info_win_height - 1), 0);
882 	if (!nohighlight)
883 		wstandout(info_win);
884 
885 	wprintw(info_win, info_help_msg);
886 
887 	for (counter = strlen(info_help_msg); counter < COLS; counter++)
888 		waddch(info_win, '=');
889 
890 	wstandend(info_win);
891 	wrefresh(info_win);
892 }
893 
894 /*
895  |	The following routine tests the input string against the list of
896  |	strings, to determine if the string is a unique match with one of the
897  |	valid values.
898  */
899 
900 int
unique_test(string,list)901 unique_test(string, list)
902 char *string;
903 char *list[];
904 {
905 	int counter;
906 	int num_match;
907 	int result;
908 
909 	num_match = 0;
910 	counter = 0;
911 	while (list[counter] != NULL)
912 	{
913 		result = compare(string, list[counter], FALSE);
914 		if (result)
915 			num_match++;
916 		counter++;
917 	}
918 	return(num_match);
919 }
920 
921 void
command_prompt()922 command_prompt()
923 {
924 	char *cmd_str;
925 	int result;
926 
927 	info_type = COMMANDS;
928 	paint_info_win();
929 	cmd_str = get_string(cmd_prompt, TRUE);
930 	if ((result = unique_test(cmd_str, commands)) != 1)
931 	{
932 		werase(com_win);
933 		wmove(com_win, 0, 0);
934 		if (result == 0)
935 			wprintw(com_win, unkn_cmd_msg, cmd_str);
936 		else
937 			wprintw(com_win, non_unique_cmd_msg);
938 
939 		wrefresh(com_win);
940 
941 		info_type = CONTROL_KEYS;
942 		paint_info_win();
943 
944 		if (cmd_str != NULL)
945 			free(cmd_str);
946 		return;
947 	}
948 	command(cmd_str);
949 	wrefresh(com_win);
950 	info_type = CONTROL_KEYS;
951 	paint_info_win();
952 	if (cmd_str != NULL)
953 		free(cmd_str);
954 }
955 
956 /*
957  |	after changing the tab spacing, or inserting or deleting tab stops,
958  |	re-calculate the vertical length of lines in buffers to ensure
959  |	proper drawing of lines.
960  */
961 
962 void
tab_resize()963 tab_resize()
964 {
965 	struct bufr *tt;		/* temporary pointer		*/
966 	struct text *tmp_tx;		/* temporary text pointer	*/
967 
968 	tt = first_buff;
969 	while (tt != NULL)
970 	{
971 		for (tmp_tx = tt->first_line; tmp_tx != NULL;
972 		        tmp_tx = tmp_tx->next_line)
973 		{
974 			tmp_tx->vert_len = (scanline(tmp_tx,
975 			     tmp_tx->line_length) / COLS) + 1;
976 		}
977 		tt->window_top = first_buff->window_top;
978 		tt = tt->next_buff;
979 	}
980 }
981 
982 void
command(cmd_str)983 command(cmd_str)	/* process commands from command line	*/
984 char *cmd_str;
985 {
986 	char *cmd_str2;
987 	char *c_temp;
988 	char *name;
989 	char *tmp;
990 	char dir;
991 	int alloc_space;	/* have we allocated more space ?	*/
992 	int c_int;
993 	int retval;
994 	int gold_flag;
995 	int temp_int;
996 	struct tab_stops *temp_stack;
997 
998 	clr_cmd_line = TRUE;
999 	alloc_space = FALSE;
1000 	cmd_str2 = cmd_str;
1001 	if (compare(cmd_str, EXPAND_str, FALSE))
1002 		expand = TRUE;
1003 	else if (compare(cmd_str, NOEXPAND_str, FALSE))
1004 		expand = FALSE;
1005 	else if (compare(cmd_str, NOJUSTIFY_str, FALSE))
1006 		right_justify = FALSE;
1007 	else if (compare(cmd_str, JUSTIFY_str, FALSE))
1008 		right_justify = TRUE;
1009 	else if (compare(cmd_str, EXIT_str, FALSE))
1010 		finish(cmd_str);
1011 	else if (compare(cmd_str, QUIT_str, FALSE))
1012 		quit(cmd_str);
1013 	else if (compare(cmd_str, AUTOFORMAT_str, FALSE))
1014 	{
1015 		auto_format = TRUE;
1016 		observ_margins = TRUE;
1017 		indent = FALSE;
1018 	}
1019 	else if (compare(cmd_str, NOAUTOFORMAT_str, FALSE))
1020 		auto_format = FALSE;
1021 	else if (compare(cmd_str, INFO_str, FALSE))
1022 	{
1023 		if (info_window == FALSE)
1024 			info_op();
1025 	}
1026 	else if (compare(cmd_str, NOINFO_str, FALSE))
1027 	{
1028 		if (info_window == TRUE)
1029 			info_op();
1030 	}
1031 	else if (compare(cmd_str, TABS_str, FALSE))
1032 	{
1033 		cmd_str = next_word(cmd_str);
1034 		if (*cmd_str != '\0')
1035 		{
1036 			tab_set(cmd_str);
1037 			tab_resize();
1038 			new_screen();
1039 		}
1040 		else
1041 		{
1042 			temp_stack = tabs->next_stop;
1043 			werase(com_win);
1044 			wmove(com_win, 0, 0);
1045 			wprintw(com_win, tab_msg);
1046 			while (temp_stack != NULL)
1047 			{
1048 				wprintw(com_win, "%d ", temp_stack->column);
1049 				temp_stack = temp_stack->next_stop;
1050 			}
1051 		}
1052 	}
1053 	else if (compare(cmd_str, UNTABS_str, FALSE))
1054 	{
1055 		unset_tab(cmd_str);
1056 		tab_resize();
1057 		new_screen();
1058 	}
1059 	else if (compare(cmd_str, SPACING_str, FALSE))
1060 	{
1061 		cmd_str2 = next_word(cmd_str);
1062 		if (*cmd_str2 != '\0')
1063 		{
1064 			tab_spacing = atoi(cmd_str2);
1065 			tab_resize();
1066 			midscreen(curr_buff->scr_vert, curr_buff->position);
1067 		}
1068 		else
1069 		{
1070 			werase(com_win);
1071 			wmove(com_win, 0, 0);
1072 			wprintw(com_win, SPACING_msg, tab_spacing);
1073 		}
1074 	}
1075 	else if (compare(cmd_str, WRITE_str, FALSE))
1076 	{
1077 		if (restrict_mode())
1078 		{
1079 			return;
1080 		}
1081 		cmd_str2 = next_word(cmd_str);
1082 		if (*cmd_str2 == '\0')
1083 		{
1084 			alloc_space = TRUE;
1085 			cmd_str2 = get_string(file_write_prompt_str, TRUE);
1086 		}
1087 		tmp = cmd_str2;
1088 		while ((*tmp != ' ') && (*tmp != '\t') && (*tmp != '\0'))
1089 			tmp++;
1090 		*tmp = '\0';
1091 		tmp_file = resolve_name(cmd_str2);
1092 		write_file(tmp_file);
1093 		if (tmp_file != cmd_str2)
1094 			free(tmp_file);
1095 		if (alloc_space)
1096 			free(cmd_str2);
1097 	}
1098 	else if (compare(cmd_str, READ_str, FALSE))
1099 	{
1100 		if (restrict_mode())
1101 		{
1102 			return;
1103 		}
1104 		cmd_str2 = next_word(cmd_str);
1105 		if (*cmd_str2 == '\0')
1106 		{
1107 			alloc_space = TRUE;
1108 			cmd_str2 = get_string(file_read_prompt_str, TRUE);
1109 		}
1110 		tmp = cmd_str2;
1111 		while ((*tmp != ' ') && (*tmp != '\t') && (*tmp != '\0'))
1112 			tmp++;
1113 		*tmp = '\0';
1114 		tmp_file = resolve_name(cmd_str2);
1115 		recv_file = TRUE;
1116 		value = check_fp();
1117 		if (tmp_file != cmd_str2)
1118 			free(tmp_file);
1119 		if (alloc_space)
1120 			free(cmd_str2);
1121 	}
1122 	else if (compare(cmd_str, SAVE_str, FALSE))
1123 	{
1124 		/*
1125 		 |	Should reflect changes made here in file_op()
1126 		 |	where 'save' command is handled.
1127 		 */
1128 
1129 		cmd_str2 = next_word(cmd_str);
1130 		if (!curr_buff->edit_buffer)
1131 			file_op(SAVE_FILE);
1132 		else if ((*cmd_str2 != '\0') && (curr_buff->file_name == NULL))
1133 		{
1134 			tmp_file = resolve_name(cmd_str2);
1135 			if (tmp_file != cmd_str2)
1136 			{
1137 				alloc_space = TRUE;
1138 				cmd_str2 = tmp_file;
1139 			}
1140 
1141 			if (write_file(cmd_str2))
1142 			{
1143 				if (curr_buff->file_name == NULL)
1144 				{
1145 					curr_buff->full_name = get_full_path(cmd_str2,
1146 								NULL);
1147 					curr_buff->file_name =
1148 						ae_basename(curr_buff->full_name);
1149 				}
1150 				curr_buff->changed = FALSE;
1151 				change = FALSE;
1152 				if (alloc_space)
1153 					free(cmd_str2);
1154 			}
1155 			else
1156 			{
1157 				if (alloc_space)
1158 					free(cmd_str2);
1159 				return;
1160 			}
1161 		}
1162 		else
1163 		{
1164 			file_op(SAVE_FILE);
1165 		}
1166 
1167 	}
1168 	else if (compare(cmd_str, LITERAL_str, FALSE))
1169 		literal = TRUE;
1170 	else if (compare(cmd_str, NOLITERAL_str, FALSE))
1171 		literal = FALSE;
1172 	else if (compare(cmd_str, STATUS_str, FALSE))
1173 		status_line = TRUE;
1174 	else if (compare(cmd_str, NOSTATUS_str, FALSE))
1175 		status_line = FALSE;
1176 	else if (compare(cmd_str, MARGINS_str, FALSE))
1177 		observ_margins = TRUE;
1178 	else if (compare(cmd_str, NOMARGINS_str, FALSE))
1179 		observ_margins = FALSE;
1180 	else if (compare(cmd_str, INDENT_str, FALSE))
1181 		indent = TRUE;
1182 	else if (compare(cmd_str, NOINDENT_str, FALSE))
1183 		indent = FALSE;
1184 	else if (compare(cmd_str, OVERSTRIKE_str, FALSE))
1185 		overstrike = TRUE;
1186 	else if (compare(cmd_str, NOOVERSTRIKE_str, FALSE))
1187 		overstrike = FALSE;
1188 	else if (compare(cmd_str, text_cmd, FALSE))
1189 		text_only = TRUE;
1190 	else if (compare(cmd_str, binary_cmd, FALSE))
1191 		text_only = FALSE;
1192 	else if (compare(cmd_str, info_win_height_cmd_str,  FALSE))
1193 	{
1194 		temp_int = info_win_height;
1195 		tmp = next_word(cmd_str);
1196 		if ((*tmp >= '0') && (*tmp <= '9'))
1197 		{
1198 			c_int = atoi(tmp);
1199 			if ((c_int > 0) && (c_int <= MAX_HELP_LINES))
1200 				info_win_height = c_int + 1;
1201 			else
1202 			{
1203 				wmove(com_win, 0, 0);
1204 				werase(com_win);
1205 				wprintw(com_win, info_win_height_err);
1206 				wrefresh(com_win);
1207 			}
1208 			if ((info_win_height != temp_int) && (info_window))
1209 			{
1210 				redo_win();
1211 				curr_buff->last_line = curr_buff->lines - 1;
1212 				new_screen();
1213 				paint_info_win();
1214 				redraw();
1215 			}
1216 		}
1217 		else
1218 		{
1219 			werase(com_win);
1220 			wmove(com_win, 0, 0);
1221 			wprintw(com_win, "%s %d", info_win_height_msg_str, (info_win_height - 1));
1222 			wrefresh(com_win);
1223 		}
1224 	}
1225 	else if ((compare(cmd_str, LEFTMARGIN_str, FALSE)) || (compare(cmd_str, RIGHTMARGIN_str, FALSE)))
1226 	{
1227 		tmp = next_word(cmd_str);
1228 		if ((*tmp >= '0') && (*tmp <= '9'))
1229 		{
1230 			c_int = atoi(tmp);
1231 			if (compare(cmd_str, LEFTMARGIN_str, FALSE))
1232 			{
1233 				if (c_int > right_margin)
1234 				{
1235 					wmove(com_win, 0, 0);
1236 					wclrtoeol(com_win);
1237 					wprintw(com_win, left_mrg_err_msg);
1238 				}
1239 				else
1240 					left_margin = c_int;
1241 			}
1242 			else if (compare(cmd_str, RIGHTMARGIN_str, FALSE))
1243 			{
1244 				if (c_int < left_margin)
1245 				{
1246 					wmove(com_win, 0, 0);
1247 					wclrtoeol(com_win);
1248 					wprintw(com_win, right_mrg_err_msg);
1249 				}
1250 				else
1251 					right_margin = c_int;
1252 			}
1253 		}
1254 		else
1255 		{
1256 			wmove(com_win, 0, 0);
1257 			wclrtoeol(com_win);
1258 			if (compare(cmd_str, LEFTMARGIN_str, FALSE))
1259 				wprintw(com_win, left_mrg_setting, left_margin);
1260 			else if (compare(cmd_str, RIGHTMARGIN_str, FALSE))
1261 				wprintw(com_win, right_mrg_setting, right_margin);
1262 		}
1263 	}
1264 	else if (compare(cmd_str, LINE_str, FALSE))
1265 	{
1266 		wmove(com_win,0,0);
1267 		wclrtoeol(com_win);
1268 		wprintw(com_win, line_num_str, curr_buff->curr_line->line_number);
1269 		wprintw(com_win, lines_from_top, curr_buff->absolute_lin);
1270 		wprintw(com_win, total_lines_str, curr_buff->num_of_lines);
1271 	}
1272 	else if (compare(cmd_str, FILE_str, FALSE))
1273 	{
1274 		wmove(com_win,0,0);
1275 		wclrtoeol(com_win);
1276 		if (curr_buff->edit_buffer)
1277 		{
1278 			if (curr_buff->file_name != NULL)
1279 			{
1280 				wprintw(com_win, current_file_str, curr_buff->full_name);
1281 			}
1282 			else
1283 			{
1284 				wprintw(com_win, current_file_str, no_file_string );
1285 			}
1286 		}
1287 		else
1288 		{
1289 			if (first_buff->file_name != NULL)
1290 			{
1291 				wprintw(com_win, current_file_str, first_buff->full_name);
1292 			}
1293 			else
1294 			{
1295 				wprintw(com_win, current_file_str, no_file_string );
1296 			}
1297 		}
1298 	}
1299 	else if (compare(cmd_str, COPYRIGHT_str, FALSE))
1300 	{
1301 		wmove(com_win,0,0);
1302 		wclrtoeol(com_win);
1303 		wprintw(com_win, "%s", copyright_notice);
1304 	}
1305 	else if ((*cmd_str >= '0') && (*cmd_str <= '9'))
1306 		goto_line(cmd_str);
1307 	else if ((*cmd_str == '+') || (*cmd_str == '-'))
1308 	{
1309 		if (*cmd_str == '+')
1310 			dir = 'd';
1311 		else
1312 			dir = 'u';
1313 		cmd_str++;
1314 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1315 			cmd_str = next_word(cmd_str);
1316 		value = 0;
1317 		while ((*cmd_str >='0') && (*cmd_str <= '9'))
1318 		{
1319 			value = value * 10 + (*cmd_str - '0');
1320 			cmd_str++;
1321 		}
1322 		move_rel(&dir, value);
1323 		werase(com_win);
1324 		wmove(com_win, 0,0);
1325 		wprintw(com_win, line_num_str, curr_buff->curr_line->line_number);
1326 		wrefresh(com_win);
1327 	}
1328 	else if (compare(cmd_str, CHARACTER_str, FALSE))
1329 	{
1330 		wmove(com_win,0,0);
1331 		wclrtoeol(com_win);
1332 		if (*curr_buff->pointer >= 0)
1333 			wprintw(com_win, char_str, *curr_buff->pointer);
1334 		else
1335 			wprintw(com_win, char_str, (*curr_buff->pointer+256));
1336 	}
1337 	else if (compare(cmd_str, REDRAW_str, FALSE))
1338 	{
1339 		clearok(curr_buff->win, TRUE);
1340 		redraw();
1341 	}
1342 	else if (compare(cmd_str, RESEQUENCE_str, FALSE))
1343 	{
1344 		tmp_line = curr_buff->first_line->next_line;
1345 		while (tmp_line != NULL)
1346 		{
1347 			tmp_line->line_number = tmp_line->prev_line->line_number + 1;
1348 			tmp_line = tmp_line->next_line;
1349 		}
1350 	}
1351 	else if (compare(cmd_str, AUTHOR_str, FALSE))
1352 	{
1353 		wmove(com_win,0,0);
1354 		wclrtoeol(com_win);
1355 		wprintw(com_win, "written by Hugh Mahon");
1356 	}
1357 	else if (compare(cmd_str, VERSION_str, FALSE))
1358 	{
1359 		wmove(com_win,0,0);
1360 		wclrtoeol(com_win);
1361 		wprintw(com_win, version_string);
1362 	}
1363 	else if (compare(cmd_str, CASE_str, FALSE))
1364 		case_sen = TRUE;
1365 	else if (compare(cmd_str, NOCASE_str, FALSE))
1366 		case_sen = FALSE;
1367 	else if (compare(cmd_str, EIGHT_str, FALSE))
1368 	{
1369 		eightbit = TRUE;
1370 		new_screen();
1371 	}
1372 	else if (compare(cmd_str, NOEIGHT_str, FALSE))
1373 	{
1374 		eightbit = FALSE;
1375 		new_screen();
1376 	}
1377 	else if (compare(cmd_str, WINDOWS_str, FALSE))
1378 		make_win();
1379 	else if (compare(cmd_str, NOWINDOWS_str, FALSE))
1380 		no_windows();
1381 	else if (compare(cmd_str, DEFINE_str, FALSE))
1382 	{
1383 		cmd_str = next_word(cmd_str);
1384 		def_key(cmd_str);
1385 	}
1386 	else if (compare(cmd_str, SHOW_str, FALSE))
1387 	{
1388 		cmd_str = next_word(cmd_str);
1389 		if (compare(cmd_str, GOLD_str, FALSE))
1390 		{
1391 			cmd_str = next_word(cmd_str);
1392 			gold_flag = TRUE;
1393 		}
1394 		else
1395 			gold_flag = FALSE;
1396 		if (toupper(*cmd_str) == 'F')
1397 		{
1398 			cmd_str++;
1399 			c_int = 0;
1400 			while ((*cmd_str >= '0') && (*cmd_str <= '9'))
1401 			{
1402 				c_int = c_int * 10 + (*cmd_str - '0');
1403 				cmd_str++;
1404 			}
1405 			if (c_int < 65)
1406 			{
1407 				if (gold_flag)
1408 					c_temp = g_f[c_int];
1409 				else
1410 					c_temp = f[c_int];
1411 				werase(com_win);
1412 				wmove(com_win, 0,0);
1413 				wprintw(com_win, key_def_msg, c_temp);
1414 			}
1415 			else
1416 			{
1417 				wmove(com_win,0,0);
1418 				wclrtoeol(com_win);
1419 				wprintw(com_win, unkn_syntax_msg, cmd_str);
1420 			}
1421 		}
1422 		if (toupper(*cmd_str) == 'K')
1423 		{
1424 			cmd_str++;
1425 			c_int = 0;
1426 			while ((*cmd_str >= '0') && (*cmd_str <= '9'))
1427 			{
1428 				c_int = c_int * 10 + (*cmd_str - '0');
1429 				cmd_str++;
1430 			}
1431 			if (c_int < 5)
1432 			{
1433 				if (gold_flag)
1434 					c_temp = g_keypads[c_int];
1435 				else
1436 					c_temp = keypads[c_int];
1437 				werase(com_win);
1438 				wmove(com_win, 0,0);
1439 				wprintw(com_win, key_def_msg, c_temp);
1440 			}
1441 			else
1442 			{
1443 				wmove(com_win,0,0);
1444 				wclrtoeol(com_win);
1445 				wprintw(com_win, unkn_syntax_msg, cmd_str);
1446 			}
1447 		}
1448 		else if (*cmd_str == '^')
1449 		{
1450 			cmd_str++;
1451 			if (*cmd_str == '?')
1452 				c_int = 31;
1453 			else
1454 				c_int = toupper(*cmd_str) - 'A';
1455 			if ((c_int != 8)&& (c_int != 16) && (c_int != 18) && ((c_int >= 0) && (c_int < 32)))
1456 			{
1457 				if (gold_flag)
1458 					c_temp = g_ctr[c_int];
1459 				else
1460 					c_temp = ctr[c_int];
1461 				werase(com_win);
1462 				wmove(com_win, 0,0);
1463 				wprintw(com_win, key_def_msg, c_temp);
1464 			}
1465 			else
1466 			{
1467 				wmove(com_win,0,0);
1468 				wclrtoeol(com_win);
1469 				wprintw(com_win, unkn_syntax_msg, cmd_str);
1470 			}
1471 		}
1472 		wrefresh(com_win);
1473 	}
1474 	else if (compare(cmd_str, HELP_str, FALSE))
1475 		help();
1476 	else if (compare(cmd_str, PRINT_str, FALSE))
1477 	{
1478 		print_buffer();
1479 	}
1480 	else if ((*cmd_str == '<') && (!in_pipe))
1481 	{
1482 		in_pipe = TRUE;
1483 		shell_fork = FALSE;
1484 		cmd_str++;
1485 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1486 			cmd_str = next_word(cmd_str);
1487 		c_int = 0;
1488 		in_buff_name[c_int] = '\0';
1489 		while ((*cmd_str != '!') && (*cmd_str != '>') && (*cmd_str != '<') && (*cmd_str != ' ') && (*cmd_str != '\t') && (*cmd_str != '\0'))
1490 		{
1491 			in_buff_name[c_int] = *cmd_str;
1492 			cmd_str++;
1493 			c_int++;
1494 		}
1495 		if (c_int == 0)
1496 		{
1497 			copy_str(curr_buff->name, in_buff_name);
1498 		}
1499 		else
1500 			in_buff_name[c_int] = '\0';
1501 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1502 			cmd_str = next_word(cmd_str);
1503 		command(cmd_str);
1504 		in_pipe = FALSE;
1505 		shell_fork = TRUE;
1506 	}
1507 	else if ((*cmd_str == '>') && (!out_pipe))
1508 	{
1509 		out_pipe = TRUE;
1510 		cmd_str++;
1511 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1512 			cmd_str = next_word(cmd_str);
1513 		c_int = 0;
1514 		out_buff_name[c_int] = '\0';
1515 		while ((*cmd_str != '!') && (*cmd_str != '>') && (*cmd_str != '<') && (*cmd_str != ' ') && (*cmd_str != '\t') && (*cmd_str != '\0'))
1516 		{
1517 			out_buff_name[c_int] = *cmd_str;
1518 			cmd_str++;
1519 			c_int++;
1520 		}
1521 		if (c_int == 0)
1522 		{
1523 			copy_str(curr_buff->name, out_buff_name);
1524 		}
1525 		else
1526 			out_buff_name[c_int] = '\0';
1527 		if ((*cmd_str == ' ') || (*cmd_str == '\t'))
1528 			cmd_str = next_word(cmd_str);
1529 		command(cmd_str);
1530 		out_pipe = FALSE;
1531 	}
1532 	else if (*cmd_str == '!')
1533 	{
1534 		cmd_str++;
1535 		if ((*cmd_str == ' ') || (*cmd_str == 9))
1536 			cmd_str = next_word(cmd_str);
1537 		sh_command(cmd_str);
1538 	}
1539 	else if (compare(cmd_str, BUFFER_str, FALSE))
1540 	{
1541 		cmd_str = next_word(cmd_str);
1542 		if (*cmd_str == '\0')
1543 		{
1544 			wmove(com_win,0,0);
1545 			wclrtoeol(com_win);
1546 			wprintw(com_win, current_buff_msg, curr_buff->name);
1547 		}
1548 		else
1549 		{
1550 			tmp = cmd_str;
1551 			while ((*tmp != ' ') && (*tmp != '\t') && (*tmp != '\0'))
1552 				tmp++;
1553 			*tmp = '\0';
1554 			chng_buf(cmd_str);
1555 		}
1556 	}
1557 	else if (compare(cmd_str, DELETE_str, FALSE))
1558 	{
1559 		if (!strcmp(curr_buff->name, main_buffer_name))
1560 		{
1561 			wmove(com_win,0,0);
1562 			wclrtoeol(com_win);
1563 			wprintw(com_win, cant_del_buf_msg, main_buffer_name);
1564 		}
1565 		else
1566 			del_buf();
1567 	}
1568 	else if (compare(cmd_str, CD_str, FALSE))
1569 	{
1570 		if (restrict_mode())
1571 		{
1572 			return;
1573 		}
1574 
1575 		cmd_str = next_word(cmd_str);
1576 		if (change_dir_allowed != TRUE)
1577 		{
1578 			wmove(com_win,0,0);
1579 			wclrtoeol(com_win);
1580 			wprintw(com_win, no_chng_dir_msg);
1581 		}
1582 		else if ((curr_buff->orig_dir == NULL) && (*cmd_str == '\0'))
1583 		{
1584 			wmove(com_win,0,0);
1585 			wclrtoeol(com_win);
1586 			wprintw(com_win, no_dir_entered_msg);
1587 		}
1588 		else
1589 		{
1590 			if (*cmd_str != '\0')
1591 				c_temp = cmd_str;
1592 			else
1593 				c_temp = curr_buff->orig_dir;
1594 			tmp = c_temp;
1595 			while ((*tmp != ' ') && (*tmp != '\t') && (*tmp != '\0'))
1596 				tmp++;
1597 			*tmp = '\0';
1598 			name = resolve_name(c_temp);
1599 			retval = chdir(name);
1600 			if (name != c_temp)
1601 				free(name);
1602 			if (retval == -1)
1603 			{
1604 				werase(com_win);
1605 				wmove(com_win, 0, 0);
1606 				if (errno == ENOTDIR)
1607 					wprintw(com_win, path_not_dir_msg);
1608 				else if (errno == EACCES)
1609 					wprintw(com_win, path_not_permitted_msg);
1610 				else
1611 					wprintw(com_win, path_chng_failed_msg);
1612 			}
1613 		}
1614 	}
1615 	else if (compare(cmd_str, edit_cmd_str, FALSE))
1616 	{
1617 		cmd_str2 = next_word(cmd_str);
1618 		if (cmd_str2 != NULL)
1619 		{
1620 			if (*cmd_str != '\0')
1621 				c_temp = cmd_str2;
1622 			tmp = c_temp;
1623 			while ((*tmp != ' ') && (*tmp != '\t') && (*tmp != '\0'))
1624 				tmp++;
1625 			*tmp = '\0';
1626 			if (*c_temp != '\0')
1627 				name = resolve_name(c_temp);
1628 			else
1629 				name = c_temp;
1630 			retval = open_for_edit(name);
1631 			if (name != c_temp)
1632 				free(name);
1633 		}
1634 	}
1635 	else if (compare(cmd_str, pwd_cmd_str, FALSE))
1636 	{
1637 		show_pwd();
1638 	}
1639 	else if (compare(cmd_str, DIFF_str, FALSE))
1640 	{
1641 		diff_file();
1642 	}
1643 	else if (compare(cmd_str, journal_str, FALSE))
1644 	{
1645 		wmove(com_win,0,0);
1646 		wclrtoeol(com_win);
1647 		wprintw(com_win, "journal file is %s", curr_buff->journal_file);
1648 	}
1649 	else
1650 	{
1651 		wmove(com_win,0,0);
1652 		wclrtoeol(com_win);
1653 		wprintw(com_win, unkn_cmd_msg, cmd_str2);
1654 	}
1655 }
1656 
1657 
1658 void
init_keys()1659 init_keys()		/* initialize control keys and function keys	*/
1660 {
1661 	int counter;
1662 
1663 	ctr[0] = fn_AC_str;	/* control a */
1664 	ctr[1] = fn_EOT_str;	/* control b */
1665 	ctr[2] = fn_COPY_str;	/* control c */
1666 	ctr[3] = fn_BOL_str; 	/* control d */
1667 	ctr[4] = fn_CMD_str; 	/* control e */
1668 	ctr[5] = fn_SRCH_str;	/* control f */
1669 	ctr[6] = fn_GOLD_str;	/* control g */
1670 	ctr[7] = fn_BCK_str;	/* control h */	/* backspace	*/
1671 	ctr[8] = "";		/* control i */	/* tab		*/
1672 	ctr[9] = fn_CR_str;	/* control j */	/* new-line	*/
1673 	ctr[10] = fn_DC_str; 	/* control k */
1674 	ctr[11] = fn_DL_str; 	/* control l */
1675 	ctr[12] = fn_CR_str;	/* control m */	/* carriage-return	*/
1676 	ctr[13] = fn_NP_str; 	/* control n */
1677 	ctr[14] = fn_EOL_str;	/* control o */
1678 	ctr[15] = fn_PP_str; 	/* control p */
1679 	ctr[16] = "";		/* control q */
1680 	ctr[17] = fn_RD_str; 	/* control r */
1681 	ctr[18] = "";		/* control s */
1682 	ctr[19] = fn_BOT_str;	/* control t */
1683 	ctr[20] = fn_MARK_str;	/* control u */
1684 	ctr[21] = fn_PST_str;	/* control v */
1685 	ctr[22] = fn_DW_str; 	/* control w */
1686 	ctr[23] = fn_CUT_str;	/* control x */
1687 	ctr[24] = fn_AW_str; 	/* control y */
1688 	ctr[25] = fn_RP_str; 	/* control z */
1689 	ctr[26] = fn_MENU_str; 	/* control [ */
1690 	ctr[27] = ""; 		/* control \\ */
1691 	ctr[28] = ""; 		/* control ] */
1692 	ctr[29] = ""; 		/* control ^ */
1693 	ctr[30] = ""; 		/* control _ */
1694 	ctr[31] = fn_BCK_str;	/* control ?*/	/* delete key	*/
1695 	g_ctr[0] = fn_MC_str;		/* gold control a */
1696 	g_ctr[1] = fn_APPEND_str;	/* gold control b */
1697 	g_ctr[2] = fn_CL_str;		/* gold control c */
1698 	g_ctr[3] = fn_PREFIX_str;	/* gold control c */
1699 	g_ctr[4] = "";			/* gold control e */
1700 	g_ctr[5] = fn_PSRCH_str;	/* gold control f */
1701 	g_ctr[6] = fn_GOLD_str;		/* gold control g */
1702 	g_ctr[7] = "";			/* gold control h */
1703 	g_ctr[8] = "";			/* gold control i */
1704 	g_ctr[9] = "";			/* gold control j */
1705 	g_ctr[10] = fn_UDC_str;		/* gold control k */
1706 	g_ctr[11] = fn_UDL_str;		/* gold control l */
1707 	g_ctr[12] = ""; 		/* gold control m */
1708 	g_ctr[13] = fn_NB_str;		/* gold control n */
1709 	g_ctr[14] = ""; 		/* gold control o */
1710 	g_ctr[15] = fn_PB_str;		/* gold control p */
1711 	g_ctr[16] = "";			/* gold control q */
1712 	g_ctr[17] = fn_REV_str;		/* gold control r */
1713 	g_ctr[18] = "";			/* gold control s */
1714 	g_ctr[19] = "";			/* gold control t */
1715 	g_ctr[20] = "";			/* gold control u */
1716 	g_ctr[21] = fn_FWD_str;		/* gold control v */
1717 	g_ctr[22] = fn_UDW_str;		/* gold control w */
1718 	g_ctr[23] = fn_FORMAT_str;	/* gold control x */
1719 	g_ctr[24] = fn_PW_str;		/* gold control y */
1720 	g_ctr[25] = fn_PRP_str;		/* gold control z */
1721 	g_ctr[26] = ""; 		/* control [ */
1722 	g_ctr[27] = ""; 		/* control \\ */
1723 	g_ctr[28] = ""; 		/* control ] */
1724 	g_ctr[29] = ""; 		/* control ^ */
1725 	g_ctr[30] = ""; 		/* control _ */
1726 	g_ctr[31] = ""; 		/* control ? */
1727 	f[0] = "";
1728 	f[1] = fn_GOLD_str;
1729 	f[2] = fn_UDC_str;
1730 	f[3] = fn_DW_str;
1731 	f[4] = fn_AW_str;
1732 	f[5] = fn_SRCH_str;
1733 	f[6] = fn_MARK_str;
1734 	f[7] = fn_CUT_str;
1735 	f[8] = fn_AL_str;
1736 	g_f[0] = "";
1737 	g_f[1] = fn_GOLD_str;
1738 	g_f[2] = fn_UDL_str;
1739 	g_f[3] = fn_UDW_str;
1740 	g_f[4] = fn_BOL_str;
1741 	g_f[5] = fn_PSRCH_str;
1742 	g_f[6] = fn_COPY_str;
1743 	g_f[7] = fn_PST_str;
1744 	g_f[8] = fn_CMD_str;
1745 
1746 	for (counter = 0; counter < 9; counter++)
1747 	{
1748 		g_f_changed[counter] = FALSE;
1749 		f_changed[counter] = FALSE;
1750 	}
1751 
1752 
1753 	counter = 9;
1754 	while (counter < 64)
1755 	{
1756 		f[counter] = "";
1757 		g_f[counter] = "";
1758 		g_f_changed[counter] = FALSE;
1759 		f_changed[counter] = FALSE;
1760 		counter++;
1761 	}
1762 
1763 	keypads[0] = "";
1764 	keypads[1] = "";
1765 	keypads[2] = "";
1766 	keypads[3] = "";
1767 	keypads[4] = "";
1768 	g_keypads[0] = "";
1769 	g_keypads[1] = "";
1770 	g_keypads[2] = "";
1771 	g_keypads[3] = "";
1772 	g_keypads[4] = "";
1773 
1774 	for (counter = 0; counter < 32; counter++)
1775 	{
1776 		g_ctr_changed[counter] = FALSE;
1777 		ctr_changed[counter] = FALSE;
1778 	}
1779 
1780 }
1781 
1782 void
parse(string)1783 parse(string)		/* parse commands in string		*/
1784 char *string;
1785 {
1786 	char *temp;
1787 	char dir;
1788 	int valid_flag; /* try to keep GOLD from being executed within multiple definition	*/
1789 	int delim;	/* delimiter for inserting a string	*/
1790 
1791 	temp = string;
1792 	if ((*temp == ' ') || (*temp == '\t'))
1793 		temp = next_word(temp);
1794 	valid_flag = FALSE;
1795 	while (*temp != '\0')
1796 	{
1797 		if ((!compare(temp, fn_GOLD_str, FALSE)) && (!valid_flag))
1798 			valid_flag = TRUE;
1799 		if (compare(temp, fn_DL_str, FALSE))
1800 			del_line(TRUE);
1801 		else if (compare(temp, fn_DC_str, FALSE))
1802 			del_char(TRUE);
1803 		else if (compare(temp, fn_CL_str, FALSE))
1804 			Clear_line(TRUE);
1805 		else if (compare(temp, fn_NP_str, FALSE))
1806 		{
1807 			next_page();
1808 		}
1809 		else if (compare(temp, fn_PP_str, FALSE))
1810 		{
1811 			prev_page();
1812 		}
1813 		else if (compare(temp, fn_NB_str, FALSE))
1814 		{
1815 			if (curr_buff->next_buff == NULL)
1816 				t_buff = first_buff;
1817 			else
1818 				t_buff = curr_buff->next_buff;
1819 			chng_buf(t_buff->name);
1820 		}
1821 		else if (compare(temp, fn_PB_str, FALSE))
1822 		{
1823 			t_buff = first_buff;
1824 			while ((t_buff->next_buff != curr_buff) && (t_buff->next_buff != NULL))
1825 				t_buff = t_buff->next_buff;
1826 			chng_buf(t_buff->name);
1827 		}
1828 		else if (compare(temp, fn_UDL_str, FALSE))
1829 			undel_line();
1830 		else if (compare(temp, fn_UDC_str, FALSE))
1831 			undel_char();
1832 		else if (compare(temp, fn_DW_str, FALSE))
1833 			del_word(TRUE);
1834 		else if (compare(temp, fn_UDW_str, FALSE))
1835 			undel_word();
1836 		else if (compare(temp, fn_UND_str, FALSE))
1837 			undel_last();
1838 		else if (compare(temp, fn_EOL_str, FALSE))
1839 			eol();
1840 		else if (compare(temp, fn_BOL_str, FALSE))
1841 			bol();
1842 		else if (compare(temp, fn_BOT_str, FALSE))
1843 			top();
1844 		else if (compare(temp, fn_EOT_str, FALSE))
1845 			bottom();
1846 		else if (compare(temp, fn_FORMAT_str,  FALSE))
1847 			Format();
1848 		else if ((compare(temp, fn_GOLD_str, FALSE)) && (!valid_flag) && (*(next_word(temp)) == '\0'))
1849 			gold_func();
1850 		else if (compare(temp, fn_MARGINS_str, FALSE))
1851 			observ_margins = TRUE;
1852 		else if (compare(temp, fn_NOMARGINS_str, FALSE))
1853 			observ_margins = FALSE;
1854 		else if (compare(temp, fn_IL_str, FALSE))
1855 		{
1856 			insert_line(TRUE);
1857 			if (curr_buff->position != 1)
1858 				bol();
1859 			left(TRUE);
1860 		}
1861 		else if (compare(temp, fn_PRP_str, FALSE))
1862 			repl_prompt(TRUE);
1863 		else if (compare(temp, fn_RP_str, FALSE))
1864 			replace();
1865 		else if (compare(temp, fn_MC_str, FALSE))
1866 			match();
1867 		else if (compare(temp, fn_PSRCH_str, FALSE))
1868 			search_prompt(TRUE);
1869 		else if (compare(temp, fn_SRCH_str, FALSE))
1870 			value = search(TRUE, curr_buff->curr_line, curr_buff->position, curr_buff->pointer, 0, FALSE, TRUE);
1871 		else if (compare(temp, fn_AL_str, FALSE))
1872 			adv_line();
1873 		else if (compare(temp, fn_AW_str, FALSE))
1874 			adv_word();
1875 		else if (compare(temp, fn_AC_str, FALSE))
1876 			ascii();
1877 		else if (compare(temp, fn_PW_str, FALSE))
1878 			prev_word();
1879 		else if (compare(temp, fn_CUT_str, FALSE))
1880 			cut();
1881 		else if (compare(temp, fn_FWD_str, FALSE))
1882 		{
1883 			forward = TRUE;
1884 			wmove(com_win, 0,0);
1885 			wclrtoeol(com_win);
1886 			wprintw(com_win, fwd_mode_str);
1887 			wrefresh(com_win);
1888 			clr_cmd_line = TRUE;
1889 		}
1890 		else if (compare(temp, fn_REV_str, FALSE))
1891 		{
1892 			forward = FALSE;
1893 			wmove(com_win, 0,0);
1894 			wclrtoeol(com_win);
1895 			wprintw(com_win, rev_mode_str);
1896 			wrefresh(com_win);
1897 			clr_cmd_line = TRUE;
1898 		}
1899 		else if (compare(temp, fn_MARK_str, FALSE))
1900 			slct(Mark);
1901 		else if (compare(temp, fn_UNMARK_str, FALSE))
1902 			unmark_text();
1903 		else if (compare(temp, fn_APPEND_str, FALSE))
1904 			slct(Append);
1905 		else if (compare(temp, fn_PREFIX_str, FALSE))
1906 			slct(Prefix);
1907 		else if (compare(temp, fn_COPY_str, FALSE))
1908 		{
1909 			copy();
1910 		}
1911 		else if (compare(temp, fn_CMD_str, FALSE))
1912 		{
1913 			command_prompt();
1914 		}
1915 		else if (compare(temp, fn_PST_str, FALSE))
1916 			paste();
1917 		else if (compare(temp, fn_RD_str, FALSE))
1918 		{
1919 			clearok(curr_buff->win, TRUE);
1920 			redraw();
1921 		}
1922 		else if (compare(temp, fn_UP_str,  FALSE))
1923 			up();
1924 		else if (compare(temp, fn_DOWN_str,  FALSE))
1925 			down();
1926 		else if (compare(temp, fn_LEFT_str,  FALSE))
1927 			left(TRUE);
1928 		else if (compare(temp, fn_RIGHT_str,  FALSE))
1929 			right(TRUE);
1930 		else if (compare(temp, fn_BCK_str,  FALSE))
1931 		{
1932 			if (overstrike)
1933 			{
1934 				if (curr_buff->position > 1)
1935 				{
1936 					if ((!observ_margins) ||
1937 					    ((observ_margins) &&
1938 					    (curr_buff->scr_pos > left_margin)))
1939 					{
1940 						left(TRUE);
1941 						/*
1942 						 |	save the deleted character
1943 						 */
1944 						if (in == 8)
1945 							d_char = *curr_buff->pointer;
1946 						insert(' ');
1947 						left(TRUE);
1948 						last_deleted(CHAR_BACKSPACE, 1, &d_char);
1949 					}
1950 				}
1951 				/*
1952 				 |	if at begin of line, do nothing
1953 				 */
1954 			}
1955 			else
1956 			{
1957 				if (delete(TRUE))
1958 					last_deleted(CHAR_BACKSPACE, 1, &d_char);
1959 			}
1960 		}
1961 		else if (compare(temp, fn_CR_str,  FALSE))
1962 			insert_line(TRUE);
1963 		else if (compare(temp, fn_EXPAND_str,  FALSE))
1964 			expand = TRUE;
1965 		else if (compare(temp, fn_NOEXPAND_str,  FALSE))
1966 			expand = FALSE;
1967 		else if (compare(temp, fn_EXIT_str,  FALSE))
1968 			finish(temp);
1969 		else if (compare(temp, fn_QUIT_str,  FALSE))
1970 			quit(temp);
1971 		else if (compare(temp, fn_LITERAL_str,  FALSE))
1972 			literal = TRUE;
1973 		else if (compare(temp, fn_NOLITERAL_str,  FALSE))
1974 			literal = FALSE;
1975 		else if (compare(temp, fn_STATUS_str,  FALSE))
1976 			status_line = TRUE;
1977 		else if (compare(temp, fn_NOSTATUS_str,  FALSE))
1978 			status_line = FALSE;
1979 		else if (compare(temp, fn_INDENT_str,  FALSE))
1980 			indent = TRUE;
1981 		else if (compare(temp, fn_NOINDENT_str,  FALSE))
1982 			indent = FALSE;
1983 		else if (compare(temp, fn_OVERSTRIKE_str,  FALSE))
1984 			overstrike = TRUE;
1985 		else if (compare(temp, fn_NOOVERSTRIKE_str,  FALSE))
1986 			overstrike = FALSE;
1987 		else if (compare(temp, fn_CASE_str,  FALSE))
1988 			case_sen = TRUE;
1989 		else if (compare(temp, fn_NOCASE_str,  FALSE))
1990 			case_sen = FALSE;
1991 		else if (compare(temp, fn_WINDOWS_str,  FALSE))
1992 			make_win();
1993 		else if (compare(temp, fn_NOWINDOWS_str,  FALSE))
1994 			no_windows();
1995 		else if (compare(temp, fn_HELP_str,  FALSE))
1996 			help();
1997 		else if ((*temp == '+') || (*temp == '-'))
1998 		{
1999 			if (*temp == '+')
2000 				dir = 'd';
2001 			else
2002 				dir = 'u';
2003 			temp++;
2004 			if ((*temp == ' ') || (*temp == '\t'))
2005 				temp = next_word(temp);
2006 			value = 0;
2007 			while ((*temp >='0') && (*temp <= '9'))
2008 			{
2009 				value = value * 10 + (*temp - '0');
2010 				temp++;
2011 			}
2012 			move_rel(&dir, value);
2013 			if (!status_line)
2014 			{
2015 				clr_cmd_line = TRUE;
2016 				werase(com_win);
2017 				wmove(com_win, 0,0);
2018 				wprintw(com_win, line_num_str, curr_buff->curr_line->line_number);
2019 				wrefresh(com_win);
2020 			}
2021 		}
2022 		else if ( ! (((*temp >= 'a') && (*temp <= 'z')) ||
2023 			     ((*temp >= 'A') && (*temp <= 'Z')) ||
2024 			     ((*temp >= '0') && (*temp <= '9'))) )
2025 		{
2026 			delim = *temp;
2027 			temp++;
2028 			while ((*temp != delim) && (*temp != '\0'))
2029 			{
2030 				insert(*temp);
2031 				temp++;
2032 			}
2033 		}
2034 		else if (compare(temp, fn_MENU_str,  FALSE))
2035 			menu_op(main_menu);
2036 		else
2037 		{
2038 			wmove(com_win,0,0);
2039 			wclrtoeol(com_win);
2040 			wprintw(com_win, unkn_syntax_msg, temp);
2041 			wrefresh(com_win);
2042 			clr_cmd_line = TRUE;
2043 		}
2044 		temp = next_word(temp);
2045 	}
2046 }
2047 
2048 int
restrict_mode()2049 restrict_mode()
2050 {
2051 	if (!restricted)
2052 		return(FALSE);
2053 
2054 	wmove(com_win, 0, 0);
2055 	wprintw(com_win, restricted_msg);
2056 	wclrtoeol(com_win);
2057 	wrefresh(com_win);
2058 	clr_cmd_line = TRUE;
2059 	return(TRUE);
2060 }
2061 
2062 /*
2063  |	Save current configuration to .init.ee file in the current directory.
2064  */
2065 
2066 void
dump_aee_conf()2067 dump_aee_conf()
2068 {
2069 	FILE *init_file;
2070 	FILE *old_init_file = NULL;
2071 	char *file_name = ".init.ae";
2072 	char *home_dir =  "~/.init.ae";
2073 	char buffer[512];
2074 	struct stat buf;
2075 	char *string;
2076 	int length;
2077 	int counter;
2078 	int option = 0;
2079 	struct tab_stops *stack_point;
2080 
2081 	if (restrict_mode())
2082 	{
2083 		return;
2084 	}
2085 
2086 	option = menu_op(config_dump_menu);
2087 
2088 	werase(com_win);
2089 	wmove(com_win, 0, 0);
2090 
2091 	if (option == 0)
2092 	{
2093 		wprintw(com_win, conf_not_saved_msg);
2094 		wrefresh(com_win);
2095 		return;
2096 	}
2097 	else if (option == 2)
2098 		file_name = resolve_name(home_dir);
2099 
2100 	/*
2101 	 |	If a .init.ae file exists, move it to .init.ae.old.
2102 	 */
2103 
2104 	if (stat(file_name, &buf) != -1)
2105 	{
2106 		sprintf(buffer, "%s.old", file_name);
2107 		unlink(buffer);
2108 		link(file_name, buffer);
2109 		unlink(file_name);
2110 		old_init_file = fopen(buffer, "r");
2111 	}
2112 
2113 	init_file = fopen(file_name, "w");
2114 	if (init_file == NULL)
2115 	{
2116 		wprintw(com_win, conf_dump_err_msg);
2117 		wrefresh(com_win);
2118 		return;
2119 	}
2120 
2121 	if (old_init_file != NULL)
2122 	{
2123 		/*
2124 		 |	Copy non-configuration info into new .init.ae file.
2125 		 */
2126 		while ((string = fgets(buffer, 512, old_init_file)) != NULL)
2127 		{
2128 			length = strlen(string);
2129 			string[length - 1] = '\0';
2130 
2131 			if (unique_test(string, init_strings) == 1)
2132 			{
2133 				if (compare(string, ECHO_str, FALSE))
2134 				{
2135 					fprintf(init_file, "%s\n", string);
2136 				}
2137 			}
2138 			else
2139 				fprintf(init_file, "%s\n", string);
2140 		}
2141 
2142 		fclose(old_init_file);
2143 	}
2144 
2145 	fprintf(init_file, "%s\n", case_sen ? CASE_str : NOCASE_str);
2146 	fprintf(init_file, "%s\n", expand ? EXPAND_str : NOEXPAND_str);
2147 	fprintf(init_file, "%s\n", info_window ? INFO_str : NOINFO_str );
2148 	fprintf(init_file, "%s\n", observ_margins ? MARGINS_str : NOMARGINS_str );
2149 	fprintf(init_file, "%s\n", auto_format ? AUTOFORMAT_str : NOAUTOFORMAT_str );
2150 	fprintf(init_file, "%s %s\n", PRINTCOMMAND_str, print_command);
2151 	fprintf(init_file, "%s %d\n", RIGHTMARGIN_str, right_margin);
2152 	fprintf(init_file, "%s %d\n", LEFTMARGIN_str, left_margin);
2153 	fprintf(init_file, "%s\n", nohighlight ? NOHIGHLIGHT_str : HIGHLIGHT_str );
2154 	fprintf(init_file, "%s\n", eightbit ? EIGHT_str : NOEIGHT_str );
2155 	fprintf(init_file, "%s\n", literal ? LITERAL_str : NOLITERAL_str );
2156 	fprintf(init_file, "%s\n", observ_margins ? MARGINS_str : NOMARGINS_str );
2157 	fprintf(init_file, "%s\n", status_line ? STATUS_str : NOSTATUS_str );
2158 	fprintf(init_file, "%s\n", indent ? INDENT_str : NOINDENT_str );
2159 	fprintf(init_file, "%s\n", overstrike ? OVERSTRIKE_str : NOOVERSTRIKE_str );
2160 	fprintf(init_file, "%s\n", windows ? WINDOWS_str : NOWINDOWS_str );
2161 	fprintf(init_file, "%s\n", text_only ? text_cmd : binary_cmd );
2162 
2163 	if (info_win_height != INFO_WIN_HEIGHT_DEF)
2164 	{
2165 		fprintf(init_file, "%s %d\n", info_win_height_cmd_str, (info_win_height - 1));
2166 	}
2167 
2168 	for (counter = 0; counter < 64; counter++)
2169 	{
2170 		if (f_changed[counter])
2171 			fprintf(init_file, "%s f%d %s\n", DEFINE_str, counter, f[counter]);
2172 	}
2173 
2174 	for (counter = 0; counter < 64; counter++)
2175 	{
2176 		if (g_f_changed[counter])
2177 			fprintf(init_file, "%s %s f%d %s\n", DEFINE_str, GOLD_str, counter, g_f[counter]);
2178 	}
2179 
2180 	for (counter = 0; counter < 32; counter++)
2181 	{
2182 		if (ctr_changed[counter])
2183 			fprintf(init_file, "%s %s %s\n", DEFINE_str, ctrl_table[counter + 1], ctr[counter]);
2184 	}
2185 
2186 	for (counter = 0; counter < 32; counter++)
2187 	{
2188 		if (g_ctr_changed[counter])
2189 			fprintf(init_file, "%s %s %s %s\n", DEFINE_str, GOLD_str, ctrl_table[counter + 1], g_ctr[counter]);
2190 	}
2191 
2192 	if (tabs->next_stop != NULL)
2193 	{
2194 		stack_point = tabs->next_stop;
2195 		fprintf(init_file, "%s ", TABS_str);
2196 		while (stack_point != NULL)
2197 		{
2198 			fprintf(init_file, " %d", stack_point->column);
2199 			stack_point = stack_point->next_stop;
2200 		}
2201 		fprintf(init_file, "\n");
2202 	}
2203 	if (tab_spacing != 8)
2204 	{
2205 		fprintf(init_file, "%s %d\n", SPACING_str, tab_spacing);
2206 	}
2207 
2208 	fclose(init_file);
2209 
2210 	wprintw(com_win, conf_dump_success_msg, file_name);
2211 	wrefresh(com_win);
2212 	clr_cmd_line = TRUE;
2213 
2214 	if ((option == 2) && (file_name != home_dir))
2215 	{
2216 		free(file_name);
2217 	}
2218 }
2219 
2220