#include "info.h"
#if defined (FD_SET)
# if defined (hpux)
# define fd_set_cast(x) (int *)(x)
# else
# define fd_set_cast(x) (fd_set *)(x)
# endif
#endif
int info_aborted_echo_area = 0;
int echo_area_is_active = 0;
VFunction *ea_last_executed_command = (VFunction *)NULL;
int echo_area_last_command_was_kill = 0;
static char input_line[1 + EA_MAX_INPUT];
static char *input_line_prompt;
static int input_line_point;
static int input_line_beg;
static int input_line_end;
static NODE input_line_node = {
(char *)NULL, (char *)NULL, (char *)NULL, input_line, EA_MAX_INPUT, 0
};
static void echo_area_initialize_node ();
static void push_echo_area (), pop_echo_area ();
static int echo_area_stack_depth (), echo_area_stack_contains_completions_p ();
static void ea_kill_text ();
static int echo_area_must_complete_p = 0;
static int completions_window_p ();
static WINDOW *echo_area_completions_window = (WINDOW *)NULL;
static WINDOW *calling_window = (WINDOW *)NULL;
static NODE *calling_window_node = (NODE *)NULL;
static long calling_window_point = 0;
static long calling_window_pagetop = 0;
static void
remember_calling_window (window)
WINDOW *window;
{
if (!completions_window_p (window) ||
((window == windows) && !(window->next)))
{
calling_window = window;
calling_window_node = window->node;
calling_window_point = window->point;
calling_window_pagetop = window->pagetop;
}
}
static void
restore_calling_window ()
{
register WINDOW *win, *compwin = (WINDOW *)NULL;
for (win = windows; win; win = win->next)
{
if (completions_window_p (win))
compwin = win;
if (win == calling_window && win == compwin)
{
window_set_node_of_window (calling_window, calling_window_node);
calling_window->point = calling_window_point;
calling_window->pagetop = calling_window_pagetop;
compwin = (WINDOW *)NULL;
break;
}
}
if (compwin)
{
if ((compwin != windows || windows->next) &&
!echo_area_stack_contains_completions_p ())
{
WINDOW *next;
int pagetop, start, end, amount;
next = compwin->next;
if (next)
{
start = next->first_row;
end = start + next->height;
amount = - (compwin->height + 1);
pagetop = next->pagetop;
}
info_delete_window_internal (compwin);
#if defined (UNNECESSARY)
echo_area_completions_window = (WINDOW *)NULL;
#endif
if (next)
{
display_scroll_display (start, end, amount);
next->pagetop = pagetop;
display_update_display (windows);
}
}
}
}
static void
initialize_input_line (prompt)
char *prompt;
{
input_line_prompt = prompt;
if (prompt)
strcpy (input_line, prompt);
else
input_line[0] = '\0';
input_line_beg = input_line_end = input_line_point = strlen (prompt);
}
static char *
echo_area_after_read ()
{
char *return_value;
if (info_aborted_echo_area)
{
info_aborted_echo_area = 0;
return_value = (char *)NULL;
}
else
{
if (input_line_beg == input_line_end)
return_value = strdup ("");
else
{
int line_len = input_line_end - input_line_beg;
return_value = (char *) xmalloc (1 + line_len);
strncpy (return_value, &input_line[input_line_beg], line_len);
return_value[line_len] = '\0';
}
}
return (return_value);
}
char *
info_read_in_echo_area (window, prompt)
WINDOW *window;
char *prompt;
{
char *line;
if (echo_area_is_active)
push_echo_area ();
initialize_input_line (prompt);
echo_area_initialize_node ();
remember_calling_window (window);
echo_area_is_active++;
active_window = the_echo_area;
info_read_and_dispatch ();
echo_area_is_active--;
active_window = calling_window;
restore_calling_window ();
display_cursor_at_point (active_window);
fflush (stdout);
line = echo_area_after_read ();
if (echo_area_is_active)
pop_echo_area ();
return (line);
}
static void
echo_area_initialize_node ()
{
register int i;
for (i = input_line_end; i < sizeof (input_line); i++)
input_line[i] = ' ';
input_line[i - 1] = '\n';
window_set_node_of_window (the_echo_area, &input_line_node);
input_line[input_line_end] = '\n';
}
void
echo_area_prep_read ()
{
if (the_echo_area->node != &input_line_node)
echo_area_initialize_node ();
the_echo_area->point = input_line_point;
input_line[input_line_end] = '\n';
display_update_one_window (the_echo_area);
display_cursor_at_point (active_window);
}
DECLARE_INFO_COMMAND (ea_forward, "Move forward a character")
{
if (count < 0)
ea_backward (window, -count, key);
else
{
input_line_point += count;
if (input_line_point > input_line_end)
input_line_point = input_line_end;
}
}
DECLARE_INFO_COMMAND (ea_backward, "Move backward a character")
{
if (count < 0)
ea_forward (window, -count, key);
else
{
input_line_point -= count;
if (input_line_point < input_line_beg)
input_line_point = input_line_beg;
}
}
DECLARE_INFO_COMMAND (ea_beg_of_line, "Move to the start of this line")
{
input_line_point = input_line_beg;
}
DECLARE_INFO_COMMAND (ea_end_of_line, "Move to the end of this line")
{
input_line_point = input_line_end;
}
#define alphabetic(c) (islower (c) || isupper (c) || isdigit (c))
DECLARE_INFO_COMMAND (ea_forward_word, "Move forward a word")
{
int c;
if (count < 0)
ea_backward_word (window, -count, key);
else
{
while (count--)
{
if (input_line_point == input_line_end)
return;
c = input_line[input_line_point];
if (!alphabetic (c))
{
while (++input_line_point < input_line_end)
{
c = input_line[input_line_point];
if (alphabetic (c))
break;
}
}
if (input_line_point == input_line_end)
return;
while (++input_line_point < input_line_end)
{
c = input_line[input_line_point];
if (!alphabetic (c))
break;
}
}
}
}
DECLARE_INFO_COMMAND (ea_backward_word, "Move backward a word")
{
int c;
if (count < 0)
ea_forward_word (window, -count, key);
else
{
while (count--)
{
if (input_line_point == input_line_beg)
return;
c = input_line[input_line_point - 1];
if (!alphabetic (c))
{
while ((--input_line_point) != input_line_beg)
{
c = input_line[input_line_point - 1];
if (alphabetic (c))
break;
}
}
while (input_line_point != input_line_beg)
{
c = input_line[input_line_point - 1];
if (!alphabetic (c))
break;
else
--input_line_point;
}
}
}
}
DECLARE_INFO_COMMAND (ea_delete, "Delete the character under the cursor")
{
register int i;
if (count < 0)
ea_rubout (window, -count, key);
else
{
if (input_line_point == input_line_end)
return;
if (info_explicit_arg || count > 1)
{
int orig_point;
orig_point = input_line_point;
ea_forward (window, count, key);
ea_kill_text (orig_point, input_line_point);
input_line_point = orig_point;
}
else
{
for (i = input_line_point; i < input_line_end; i++)
input_line[i] = input_line[i + 1];
input_line_end--;
}
}
}
DECLARE_INFO_COMMAND (ea_rubout, "Delete the character behind the cursor")
{
if (count < 0)
ea_delete (window, -count, key);
else
{
int start;
if (input_line_point == input_line_beg)
return;
start = input_line_point;
ea_backward (window, count, key);
if (info_explicit_arg || count > 1)
ea_kill_text (start, input_line_point);
else
ea_delete (window, count, key);
}
}
DECLARE_INFO_COMMAND (ea_abort, "Cancel or quit operation")
{
if (input_line_end != input_line_beg)
{
terminal_ring_bell ();
input_line_end = input_line_point = input_line_beg;
if (calling_window->node != calling_window_node)
restore_calling_window ();
}
else
info_aborted_echo_area = 1;
}
DECLARE_INFO_COMMAND (ea_newline, "Accept (or force completion of) this line")
{
}
DECLARE_INFO_COMMAND (ea_quoted_insert, "Insert next character verbatim")
{
unsigned char character;
character = info_get_another_input_char ();
ea_insert (window, count, character);
}
DECLARE_INFO_COMMAND (ea_insert, "Insert this character")
{
register int i;
if ((input_line_end + 1) == EA_MAX_INPUT)
{
terminal_ring_bell ();
return;
}
for (i = input_line_end + 1; i != input_line_point; i--)
input_line[i] = input_line[i - 1];
input_line[input_line_point] = key;
input_line_point++;
input_line_end++;
}
DECLARE_INFO_COMMAND (ea_tab_insert, "Insert a TAB character")
{
ea_insert (window, count, '\t');
}
DECLARE_INFO_COMMAND (ea_transpose_chars, "Transpose characters at point")
{
if (!count || !input_line_point || (input_line_end - input_line_beg) < 2)
return;
while (count)
{
int t;
if (input_line_point == input_line_end)
{
t = input_line[input_line_point - 1];
input_line[input_line_point - 1] = input_line[input_line_point - 2];
input_line[input_line_point - 2] = t;
}
else
{
t = input_line[input_line_point];
input_line[input_line_point] = input_line[input_line_point - 1];
input_line[input_line_point - 1] = t;
if (count < 0 && input_line_point != input_line_beg)
input_line_point--;
else
input_line_point++;
}
if (count < 0)
count++;
else
count--;
}
}
static char **kill_ring = (char **)NULL;
static int kill_ring_index = 0;
static int kill_ring_slots = 0;
static int kill_ring_loc = 0;
static int max_retained_kills = 15;
DECLARE_INFO_COMMAND (ea_yank, "Yank back the contents of the last kill")
{
register int i;
register char *text;
if (!kill_ring_index)
{
inform_in_echo_area ("Kill ring is empty");
return;
}
text = kill_ring[kill_ring_loc];
for (i = 0; text[i]; i++)
ea_insert (window, 1, text[i]);
}
DECLARE_INFO_COMMAND (ea_yank_pop, "Yank back a previous kill")
{
register int len;
if (((ea_last_executed_command != ea_yank) &&
(ea_last_executed_command != ea_yank_pop)) ||
(kill_ring_index == 0))
return;
len = strlen (kill_ring[kill_ring_loc]);
{
register int i, counter;
counter = input_line_end - input_line_point;
for (i = input_line_point - len; counter; i++, counter--)
input_line[i] = input_line[i + len];
input_line_end -= len;
input_line_point -= len;
}
kill_ring_loc--;
if (kill_ring_loc < 0)
kill_ring_loc = kill_ring_index - 1;
ea_yank (window, count, key);
}
DECLARE_INFO_COMMAND (ea_kill_line, "Kill to the end of the line")
{
if (count < 0)
{
ea_kill_text (input_line_point, input_line_beg);
input_line_point = input_line_beg;
}
else
ea_kill_text (input_line_point, input_line_end);
}
DECLARE_INFO_COMMAND (ea_backward_kill_line,
"Kill to the beginning of the line")
{
if (count < 0)
ea_kill_text (input_line_point, input_line_end);
else
{
ea_kill_text (input_line_point, input_line_beg);
input_line_point = input_line_beg;
}
}
DECLARE_INFO_COMMAND (ea_kill_word, "Kill the word following the cursor")
{
int orig_point = input_line_point;
if (count < 0)
ea_backward_kill_word (window, -count, key);
else
{
ea_forward_word (window, count, key);
if (input_line_point != orig_point)
ea_kill_text (orig_point, input_line_point);
input_line_point = orig_point;
}
}
DECLARE_INFO_COMMAND (ea_backward_kill_word,
"Kill the word preceding the cursor")
{
int orig_point = input_line_point;
if (count < 0)
ea_kill_word (window, -count, key);
else
{
ea_backward_word (window, count, key);
if (input_line_point != orig_point)
ea_kill_text (orig_point, input_line_point);
}
}
static void
ea_kill_text (from, to)
int from, to;
{
register int i, counter, distance;
int killing_backwards, slot;
char *killed_text;
killing_backwards = (from > to);
if (killing_backwards)
{
int temp = from;
from = to;
to = temp;
}
distance = to - from;
killed_text = (char *)xmalloc (1 + distance);
strncpy (killed_text, &input_line[from], distance);
killed_text[distance] = '\0';
counter = input_line_end - to;
for (i = from; counter; i++, counter--)
input_line[i] = input_line[i + distance];
input_line_end -= distance;
if (echo_area_last_command_was_kill)
{
char *old, *new;
slot = kill_ring_loc;
old = kill_ring[slot];
new = (char *)xmalloc (1 + strlen (old) + strlen (killed_text));
if (killing_backwards)
{
strcpy (new, killed_text);
strcat (new, old);
}
else
{
strcpy (new, old);
strcat (new, killed_text);
}
free (old);
free (killed_text);
kill_ring[slot] = new;
}
else
{
slot = kill_ring_index;
if (slot == max_retained_kills)
slot = 0;
if (slot + 1 > kill_ring_slots)
kill_ring = (char **) xrealloc
(kill_ring,
(kill_ring_slots += max_retained_kills) * sizeof (char *));
if (slot != kill_ring_index)
free (kill_ring[slot]);
else
kill_ring_index++;
kill_ring[slot] = killed_text;
kill_ring_loc = slot;
}
echo_area_last_command_was_kill++;
}
static REFERENCE **echo_area_completion_items = (REFERENCE **)NULL;
static REFERENCE **completions_found = (REFERENCE **)NULL;
static int completions_found_index = 0;
static int completions_found_slots = 0;
static REFERENCE *LCD_completion;
static void build_completions (), completions_must_be_rebuilt ();
static NODE *possible_completions_output_node = (NODE *)NULL;
static char *compwin_name = "*Completions*";
static int
completions_window_p (window)
WINDOW *window;
{
int result = 0;
if (internal_info_node_p (window->node) &&
(strcmp (window->node->nodename, compwin_name) == 0))
result = 1;
return (result);
}
char *
info_read_completing_internal (window, prompt, completions, force)
WINDOW *window;
char *prompt;
REFERENCE **completions;
int force;
{
char *line;
if (echo_area_is_active)
push_echo_area ();
echo_area_must_complete_p = force;
initialize_input_line (prompt);
echo_area_initialize_node ();
remember_calling_window (window);
echo_area_completion_items = completions;
completions_must_be_rebuilt ();
active_window = the_echo_area;
echo_area_is_active++;
while (1)
{
info_read_and_dispatch ();
line = echo_area_after_read ();
if (force && line && *line && completions)
{
register int i;
build_completions ();
if (completions_found_index == 1)
{
free (line);
line = strdup (completions_found[0]->label);
break;
}
for (i = 0; i < completions_found_index; i++)
if (strcasecmp (completions_found[i]->label, line) == 0)
{
free (line);
line = strdup (completions_found[i]->label);
break;
}
if (i == completions_found_index)
{
inform_in_echo_area ("Not complete");
continue;
}
}
break;
}
echo_area_is_active--;
active_window = calling_window;
restore_calling_window ();
display_cursor_at_point (active_window);
fflush (stdout);
echo_area_completion_items = (REFERENCE **)NULL;
completions_must_be_rebuilt ();
if (echo_area_is_active)
pop_echo_area ();
return (line);
}
char *
info_read_completing_in_echo_area (window, prompt, completions)
WINDOW *window;
char *prompt;
REFERENCE **completions;
{
return (info_read_completing_internal (window, prompt, completions, 1));
}
char *
info_read_maybe_completing (window, prompt, completions)
WINDOW *window;
char *prompt;
REFERENCE **completions;
{
return (info_read_completing_internal (window, prompt, completions, 0));
}
DECLARE_INFO_COMMAND (ea_possible_completions, "List possible completions")
{
if (!echo_area_completion_items)
{
ea_insert (window, count, key);
return;
}
build_completions ();
if (!completions_found_index)
{
terminal_ring_bell ();
inform_in_echo_area ("No completions");
}
else if ((completions_found_index == 1) && (key != '?'))
{
inform_in_echo_area ("Sole completion");
}
else
{
register int i, l;
int limit, count, max_label = 0;
initialize_message_buffer ();
printf_to_message_buffer
("There %s %d ", completions_found_index == 1 ? "is" : "are",
completions_found_index);
printf_to_message_buffer
("completion%s:\n", completions_found_index == 1 ? "" : "s");
for (i = 0; i < completions_found_index; i++)
{
int len = strlen (completions_found[i]->label);
if (len > max_label)
max_label = len;
}
max_label += 4;
limit = calling_window->width / max_label;
if (limit != 1 && (limit * max_label == calling_window->width))
limit--;
if (limit == 0)
limit = 1;
count = (completions_found_index + (limit - 1)) / limit;
if (completions_found_index < limit)
count = 1;
for (i = 0; i < count; i++)
{
register int j;
for (j = 0, l = i; j < limit; j++)
{
if (l >= completions_found_index)
break;
else
{
char *label;
int printed_length, k;
label = completions_found[l]->label;
printed_length = strlen (label);
printf_to_message_buffer ("%s", label);
if (j + 1 < limit)
{
for (k = 0; k < max_label - printed_length; k++)
printf_to_message_buffer (" ");
}
}
l += count;
}
printf_to_message_buffer ("\n");
}
{
NODE *temp;
temp = message_buffer_to_node ();
add_gcable_pointer (temp->contents);
name_internal_node (temp, compwin_name);
possible_completions_output_node = temp;
}
{
WINDOW *compwin;
compwin = get_internal_info_window (compwin_name);
if (!compwin)
{
if (calling_window->height > (count * 2))
{
int start, end, pagetop;
active_window = calling_window;
start = calling_window->first_row;
pagetop = calling_window->pagetop;
compwin =
window_make_window (possible_completions_output_node);
active_window = the_echo_area;
window_change_window_height
(compwin, -(compwin->height - (count + 2)));
window_adjust_pagetop (calling_window);
remember_calling_window (calling_window);
#if defined (SPLIT_BEFORE_ACTIVE)
if (pagetop == calling_window->pagetop)
{
end = start + calling_window->height;
display_scroll_display
(start, end, calling_window->prev->height + 1);
}
#else
if (pagetop != calling_window->pagetop)
{
int newtop = calling_window->pagetop;
calling_window->pagetop = pagetop;
set_window_pagetop (calling_window, newtop);
}
#endif
echo_area_completions_window = compwin;
remember_window_and_node (compwin, compwin->node);
}
else
compwin = calling_window;
}
if (compwin->node != possible_completions_output_node)
{
window_set_node_of_window
(compwin, possible_completions_output_node);
remember_window_and_node (compwin, compwin->node);
}
display_update_display (windows);
}
}
}
DECLARE_INFO_COMMAND (ea_complete, "Insert completion")
{
if (!echo_area_completion_items)
{
ea_insert (window, count, key);
return;
}
if (!echo_area_must_complete_p && key == SPC)
{
ea_insert (window, count, key);
return;
}
if (ea_last_executed_command == ea_complete)
{
if (key == SPC && completions_found_index > 1)
{
register int i, offset;
offset = input_line_end - input_line_beg;
for (i = 0; i < completions_found_index; i++)
if (completions_found[i]->label[offset] == ' ')
break;
if (completions_found[i])
ea_insert (window, 1, ' ');
else
{
ea_possible_completions (window, count, key);
return;
}
}
else
{
ea_possible_completions (window, count, key);
return;
}
}
input_line_point = input_line_end;
build_completions ();
if (!completions_found_index)
terminal_ring_bell ();
else if (LCD_completion->label[0] == '\0')
ea_possible_completions (window, count, key);
else
{
register int i;
input_line_point = input_line_end = input_line_beg;
for (i = 0; LCD_completion->label[i]; i++)
ea_insert (window, 1, LCD_completion->label[i]);
}
}
static REFERENCE LCD_reference = { (char *)NULL, (char *)NULL, (char *)NULL };
static void remove_completion_duplicates ();
static char *last_completion_request = (char *)NULL;
static REFERENCE **last_completion_items = (REFERENCE **)NULL;
static void
completions_must_be_rebuilt ()
{
maybe_free (last_completion_request);
last_completion_request = (char *)NULL;
last_completion_items = (REFERENCE **)NULL;
}
static void
build_completions ()
{
register int i, len;
register REFERENCE *entry;
char *request;
int informed_of_lengthy_job = 0;
if (!echo_area_completion_items)
{
completions_found_index = 0;
LCD_completion = (REFERENCE *)NULL;
return;
}
len = input_line_end - input_line_beg;
request = (char *)xmalloc (1 + len);
strncpy (request, &input_line[input_line_beg], len);
request[len] = '\0';
if (last_completion_request && last_completion_items &&
last_completion_items == echo_area_completion_items &&
(strcmp (last_completion_request, request) == 0))
{
free (request);
return;
}
maybe_free (last_completion_request);
last_completion_request = request;
last_completion_items = echo_area_completion_items;
completions_found_index = 0;
LCD_completion = (REFERENCE *)NULL;
for (i = 0; entry = echo_area_completion_items[i]; i++)
{
if (strncasecmp (request, entry->label, len) == 0)
add_pointer_to_array (entry, completions_found_index,
completions_found, completions_found_slots,
20, REFERENCE *);
if (!informed_of_lengthy_job && completions_found_index > 100)
{
informed_of_lengthy_job = 1;
window_message_in_echo_area ("Building completions...");
}
}
if (!completions_found_index)
return;
remove_completion_duplicates ();
if (completions_found_index == 1)
{
LCD_completion = completions_found[0];
return;
}
{
long shortest = 100000;
for (i = 1; i < completions_found_index; i++)
{
register int j;
int c1, c2;
for (j = 0;
(c1 = info_tolower (completions_found[i - 1]->label[j])) &&
(c2 = info_tolower (completions_found[i]->label[j]));
j++)
if (c1 != c2)
break;
if (shortest > j)
shortest = j;
}
maybe_free (LCD_reference.label);
LCD_reference.label = (char *)xmalloc (1 + shortest);
strncpy (LCD_reference.label, completions_found[0]->label, shortest);
LCD_reference.label[shortest] = '\0';
LCD_completion = &LCD_reference;
}
if (informed_of_lengthy_job)
echo_area_initialize_node ();
}
static int
compare_references (entry1, entry2)
REFERENCE **entry1, **entry2;
{
return (strcasecmp ((*entry1)->label, (*entry2)->label));
}
static void
remove_completion_duplicates ()
{
register int i, j;
REFERENCE **temp;
int newlen;
if (!completions_found_index)
return;
qsort (completions_found, completions_found_index, sizeof (REFERENCE *),
compare_references);
for (i = 0, newlen = 1; i < completions_found_index - 1; i++)
{
if (strcmp (completions_found[i]->label,
completions_found[i + 1]->label) == 0)
completions_found[i] = (REFERENCE *)NULL;
else
newlen++;
}
temp = (REFERENCE **)xmalloc ((1 + newlen) * sizeof (REFERENCE *));
for (i = 0, j = 0; i < completions_found_index; i++)
if (completions_found[i])
temp[j++] = completions_found[i];
for (i = 0; i < newlen; i++)
completions_found[i] = temp[i];
completions_found[i] = (REFERENCE *)NULL;
completions_found_index = newlen;
free (temp);
}
DECLARE_INFO_COMMAND (ea_scroll_completions_window, "Scroll the completions window")
{
WINDOW *compwin;
int old_pagetop;
compwin = get_internal_info_window (compwin_name);
if (!compwin)
compwin = calling_window;
old_pagetop = compwin->pagetop;
info_scroll_forward (compwin, count, key);
}
void
echo_area_inform_of_deleted_window (window)
WINDOW *window;
{
if (window == calling_window)
{
if (active_window != the_echo_area)
remember_calling_window (active_window);
else
remember_calling_window (windows);
}
if (window == echo_area_completions_window)
echo_area_completions_window = (WINDOW *)NULL;
}
typedef struct {
char *line;
char *prompt;
REFERENCE **comp_items;
int point, beg, end;
int must_complete;
NODE node;
WINDOW *compwin;
} PUSHED_EA;
static PUSHED_EA **pushed_echo_areas = (PUSHED_EA **)NULL;
static int pushed_echo_areas_index = 0;
static int pushed_echo_areas_slots = 0;
static void
push_echo_area ()
{
PUSHED_EA *pushed;
pushed = (PUSHED_EA *)xmalloc (sizeof (PUSHED_EA));
pushed->line = strdup (input_line);
pushed->prompt = input_line_prompt;
pushed->point = input_line_point;
pushed->beg = input_line_beg;
pushed->end = input_line_end;
pushed->node = input_line_node;
pushed->comp_items = echo_area_completion_items;
pushed->must_complete = echo_area_must_complete_p;
pushed->compwin = echo_area_completions_window;
add_pointer_to_array (pushed, pushed_echo_areas_index, pushed_echo_areas,
pushed_echo_areas_slots, 4, PUSHED_EA *);
echo_area_completion_items = (REFERENCE **)NULL;
}
static void
pop_echo_area ()
{
PUSHED_EA *popped;
popped = pushed_echo_areas[--pushed_echo_areas_index];
strcpy (input_line, popped->line);
free (popped->line);
input_line_prompt = popped->prompt;
input_line_point = popped->point;
input_line_beg = popped->beg;
input_line_end = popped->end;
input_line_node = popped->node;
echo_area_completion_items = popped->comp_items;
echo_area_must_complete_p = popped->must_complete;
echo_area_completions_window = popped->compwin;
completions_must_be_rebuilt ();
if (echo_area_completions_window)
{
register WINDOW *win;
for (win = windows; win; win = win->next)
if (echo_area_completions_window == win)
break;
if (!win)
echo_area_completions_window = (WINDOW *)NULL;
}
free (popped);
}
static int
echo_area_stack_depth ()
{
return (pushed_echo_areas_index);
}
static int
echo_area_stack_contains_completions_p ()
{
register int i;
for (i = 0; i < pushed_echo_areas_index; i++)
if (pushed_echo_areas[i]->compwin)
return (1);
return (0);
}
#if defined (HAVE_SYS_TIME_H)
# include <sys/time.h>
# define HAVE_STRUCT_TIMEVAL
#endif
static void
pause_or_input ()
{
#if defined (FD_SET)
struct timeval timer;
fd_set readfds;
int ready;
FD_ZERO (&readfds);
FD_SET (fileno (stdin), &readfds);
timer.tv_sec = 2;
timer.tv_usec = 750;
ready = select (1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timer);
#endif
}
void
inform_in_echo_area (message)
char *message;
{
register int i;
char *text;
text = strdup (message);
for (i = 0; text[i] && text[i] != '\n'; i++);
text[i] = '\0';
echo_area_initialize_node ();
sprintf (&input_line[input_line_end], "%s[%s]\n",
echo_area_is_active ? " ": "", text);
free (text);
the_echo_area->point = input_line_point;
display_update_one_window (the_echo_area);
display_cursor_at_point (active_window);
fflush (stdout);
pause_or_input ();
echo_area_initialize_node ();
}