diff options
Diffstat (limited to 'contrib/texinfo/info/echo-area.c')
-rw-r--r-- | contrib/texinfo/info/echo-area.c | 155 |
1 files changed, 76 insertions, 79 deletions
diff --git a/contrib/texinfo/info/echo-area.c b/contrib/texinfo/info/echo-area.c index 8954571..31385c8 100644 --- a/contrib/texinfo/info/echo-area.c +++ b/contrib/texinfo/info/echo-area.c @@ -1,7 +1,8 @@ /* echo-area.c -- how to read a line in the echo area. - $Id: echo-area.c,v 1.1 2002/08/25 23:38:38 karl Exp $ + $Id: echo-area.c,v 1.7 2004/12/14 00:15:36 karl Exp $ - Copyright (C) 1993, 1997, 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1993, 1997, 1998, 1999, 2001, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,18 +50,19 @@ 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 + (char *)NULL, (char *)NULL, (char *)NULL, input_line, + EA_MAX_INPUT, 0, N_IsInternal }; -static void echo_area_initialize_node (); -static void push_echo_area (), pop_echo_area (); -static int echo_area_stack_contains_completions_p (); +static void echo_area_initialize_node (void); +static void push_echo_area (void), pop_echo_area (void); +static int echo_area_stack_contains_completions_p (void); -static void ea_kill_text (); +static void ea_kill_text (int from, int to); /* Non-zero means we force the user to complete. */ static int echo_area_must_complete_p = 0; -static int completions_window_p (); +static int completions_window_p (WINDOW *window); /* If non-null, this is a window which was specifically created to display possible completions output. We remember it so we can delete it when @@ -76,8 +78,7 @@ static long calling_window_pagetop = 0; /* Remember the node and pertinent variables of the calling window. */ static void -remember_calling_window (window) - WINDOW *window; +remember_calling_window (WINDOW *window) { /* Only do this if the calling window is not the completions window, or, if it is the completions window and there is no other window. */ @@ -94,7 +95,7 @@ remember_calling_window (window) /* Restore the caller's window so that it shows the node that it was showing on entry to info_read_xxx_echo_area (). */ static void -restore_calling_window () +restore_calling_window (void) { register WINDOW *win, *compwin = (WINDOW *)NULL; @@ -124,7 +125,10 @@ restore_calling_window () !echo_area_stack_contains_completions_p ()) { WINDOW *next; - int pagetop, start, end, amount; + int pagetop = 0; + int start = 0; + int end = 0; + int amount = 0; next = compwin->next; if (next) @@ -156,8 +160,7 @@ restore_calling_window () /* Set up a new input line with PROMPT. */ static void -initialize_input_line (prompt) - char *prompt; +initialize_input_line (char *prompt) { input_line_prompt = prompt; if (prompt) @@ -169,7 +172,7 @@ initialize_input_line (prompt) } static char * -echo_area_after_read () +echo_area_after_read (void) { char *return_value; @@ -198,9 +201,7 @@ echo_area_after_read () active window, so that we can restore it when we need to. PROMPT, if non-null, is a prompt to print before reading the line. */ char * -info_read_in_echo_area (window, prompt) - WINDOW *window; - char *prompt; +info_read_in_echo_area (WINDOW *window, char *prompt) { char *line; @@ -246,11 +247,11 @@ info_read_in_echo_area (window, prompt) /* (re) Initialize the echo area node. */ static void -echo_area_initialize_node () +echo_area_initialize_node (void) { register int i; - for (i = input_line_end; i < sizeof (input_line); i++) + for (i = input_line_end; (unsigned int) i < sizeof (input_line); i++) input_line[i] = ' '; input_line[i - 1] = '\n'; @@ -262,7 +263,7 @@ echo_area_initialize_node () echo area node, but its primary purpose is to side effect the input line buffer contents. */ void -echo_area_prep_read () +echo_area_prep_read (void) { if (the_echo_area->node != &input_line_node) echo_area_initialize_node (); @@ -559,7 +560,7 @@ DECLARE_INFO_COMMAND (ea_yank, _("Yank back the contents of the last kill")) if (!kill_ring_index) { - inform_in_echo_area (_("Kill ring is empty")); + inform_in_echo_area ((char *) _("Kill ring is empty")); return; } @@ -576,8 +577,8 @@ 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)) || + if (((ea_last_executed_command != (VFunction *) ea_yank) && + (ea_last_executed_command != (VFunction *) ea_yank_pop)) || (kill_ring_index == 0)) return; @@ -670,8 +671,7 @@ DECLARE_INFO_COMMAND (ea_backward_kill_word, otherwise it is prepended. If the last command was not a kill command, then a new slot is made for this kill. */ static void -ea_kill_text (from, to) - int from, to; +ea_kill_text (int from, int to) { register int i, counter, distance; int killing_backwards, slot; @@ -776,7 +776,7 @@ static int completions_found_slots = 0; static REFERENCE *LCD_completion; /* Internal functions used by the user calls. */ -static void build_completions (), completions_must_be_rebuilt (); +static void build_completions (void), completions_must_be_rebuilt (void); /* Variable which holds the output of completions. */ static NODE *possible_completions_output_node = (NODE *)NULL; @@ -785,8 +785,7 @@ static char *compwin_name = "*Completions*"; /* Return non-zero if WINDOW is a window used for completions output. */ static int -completions_window_p (window) - WINDOW *window; +completions_window_p (WINDOW *window) { int result = 0; @@ -800,11 +799,8 @@ completions_window_p (window) /* Workhorse for completion readers. If FORCE is non-zero, the user cannot exit unless the line read completes, or is empty. */ char * -info_read_completing_internal (window, prompt, completions, force) - WINDOW *window; - char *prompt; - REFERENCE **completions; - int force; +info_read_completing_internal (WINDOW *window, char *prompt, + REFERENCE **completions, int force) { char *line; @@ -869,9 +865,9 @@ info_read_completing_internal (window, prompt, completions, force) if (i == completions_found_index) { if (!completions_found_index) - inform_in_echo_area (_("No completions")); + inform_in_echo_area ((char *) _("No completions")); else - inform_in_echo_area (_("Not complete")); + inform_in_echo_area ((char *) _("Not complete")); continue; } } @@ -897,10 +893,8 @@ info_read_completing_internal (window, prompt, completions, force) /* Read a line in the echo area with completion over COMPLETIONS. */ char * -info_read_completing_in_echo_area (window, prompt, completions) - WINDOW *window; - char *prompt; - REFERENCE **completions; +info_read_completing_in_echo_area (WINDOW *window, + char *prompt, REFERENCE **completions) { return (info_read_completing_internal (window, prompt, completions, 1)); } @@ -908,10 +902,8 @@ info_read_completing_in_echo_area (window, prompt, completions) /* Read a line in the echo area allowing completion over COMPLETIONS, but not requiring it. */ char * -info_read_maybe_completing (window, prompt, completions) - WINDOW *window; - char *prompt; - REFERENCE **completions; +info_read_maybe_completing (WINDOW *window, + char *prompt, REFERENCE **completions) { return (info_read_completing_internal (window, prompt, completions, 0)); } @@ -929,22 +921,23 @@ DECLARE_INFO_COMMAND (ea_possible_completions, _("List possible completions")) if (!completions_found_index) { terminal_ring_bell (); - inform_in_echo_area (_("No completions")); + inform_in_echo_area ((char *) _("No completions")); } else if ((completions_found_index == 1) && (key != '?')) { - inform_in_echo_area (_("Sole completion")); + inform_in_echo_area ((char *) _("Sole completion")); } else { register int i, l; - int limit, count, max_label = 0; + int limit, iterations, max_label = 0; initialize_message_buffer (); printf_to_message_buffer (completions_found_index == 1 - ? _("One completion:\n") - : _("%d completions:\n"), - completions_found_index); + ? (char *) _("One completion:\n") + : (char *) _("%d completions:\n"), + (void *) (long) completions_found_index, + NULL, NULL); /* Find the maximum length of a label. */ for (i = 0; i < completions_found_index; i++) @@ -967,15 +960,15 @@ DECLARE_INFO_COMMAND (ea_possible_completions, _("List possible completions")) limit = 1; /* How many iterations of the printing loop? */ - count = (completions_found_index + (limit - 1)) / limit; + iterations = (completions_found_index + (limit - 1)) / limit; /* Watch out for special case. If the number of completions is less than LIMIT, then just do the inner printing loop. */ if (completions_found_index < limit) - count = 1; + iterations = 1; /* Print the sorted items, up-and-down alphabetically. */ - for (i = 0; i < count; i++) + for (i = 0; i < iterations; i++) { register int j; @@ -990,17 +983,17 @@ DECLARE_INFO_COMMAND (ea_possible_completions, _("List possible completions")) label = completions_found[l]->label; printed_length = strlen (label); - printf_to_message_buffer ("%s", label); + printf_to_message_buffer ("%s", label, NULL, NULL); if (j + 1 < limit) { for (k = 0; k < max_label - printed_length; k++) - printf_to_message_buffer (" "); + printf_to_message_buffer (" ", NULL, NULL, NULL); } } - l += count; + l += iterations; } - printf_to_message_buffer ("\n"); + printf_to_message_buffer ("\n", NULL, NULL, NULL); } /* Make a new node to hold onto possible completions. Don't destroy @@ -1028,7 +1021,7 @@ DECLARE_INFO_COMMAND (ea_possible_completions, _("List possible completions")) { /* If we can split the window to display most of the completion items, then do so. */ - if (calling_window->height > (count * 2) + if (calling_window->height > (iterations * 2) && calling_window->height / 2 >= WINDOW_MIN_SIZE) { int start, pagetop; @@ -1046,7 +1039,7 @@ DECLARE_INFO_COMMAND (ea_possible_completions, _("List possible completions")) window_make_window (possible_completions_output_node); active_window = the_echo_area; window_change_window_height - (compwin, -(compwin->height - (count + 2))); + (compwin, -(compwin->height - (iterations + 2))); window_adjust_pagetop (calling_window); remember_calling_window (calling_window); @@ -1105,7 +1098,7 @@ DECLARE_INFO_COMMAND (ea_complete, _("Insert completion")) return; } - if (ea_last_executed_command == ea_complete) + if (ea_last_executed_command == (VFunction *) ea_complete) { /* If the keypress is a SPC character, and we have already tried completing once, and there are several completions, then check @@ -1153,9 +1146,11 @@ DECLARE_INFO_COMMAND (ea_complete, _("Insert completion")) } /* Utility REFERENCE used to store possible LCD. */ -static REFERENCE LCD_reference = { (char *)NULL, (char *)NULL, (char *)NULL }; +static REFERENCE LCD_reference = { + (char *)NULL, (char *)NULL, (char *)NULL, 0, 0, 0 +}; -static void remove_completion_duplicates (); +static void remove_completion_duplicates (void); /* Variables which remember the state of the most recent call to build_completions (). */ @@ -1164,7 +1159,7 @@ static REFERENCE **last_completion_items = (REFERENCE **)NULL; /* How to tell the completion builder to reset internal state. */ static void -completions_must_be_rebuilt () +completions_must_be_rebuilt (void) { maybe_free (last_completion_request); last_completion_request = (char *)NULL; @@ -1174,7 +1169,7 @@ completions_must_be_rebuilt () /* Build a list of possible completions from echo_area_completion_items, and the contents of input_line. */ static void -build_completions () +build_completions (void) { register int i, len; register REFERENCE *entry; @@ -1222,7 +1217,8 @@ build_completions () if (!informed_of_lengthy_job && completions_found_index > 100) { informed_of_lengthy_job = 1; - window_message_in_echo_area (_("Building completions...")); + window_message_in_echo_area ((char *) _("Building completions..."), + NULL, NULL); } } @@ -1291,15 +1287,17 @@ build_completions () /* Function called by qsort. */ static int -compare_references (entry1, entry2) - REFERENCE **entry1, **entry2; +compare_references (const void *entry1, const void *entry2) { - return (strcasecmp ((*entry1)->label, (*entry2)->label)); + REFERENCE **e1 = (REFERENCE **) entry1; + REFERENCE **e2 = (REFERENCE **) entry2; + + return (strcasecmp ((*e1)->label, (*e2)->label)); } /* Prune duplicate entries from COMPLETIONS_FOUND. */ static void -remove_completion_duplicates () +remove_completion_duplicates (void) { register int i, j; REFERENCE **temp; @@ -1359,8 +1357,7 @@ DECLARE_INFO_COMMAND (ea_scroll_completions_window, _("Scroll the completions wi /* Function which gets called when an Info window is deleted while the echo area is active. WINDOW is the window which has just been deleted. */ void -echo_area_inform_of_deleted_window (window) - WINDOW *window; +echo_area_inform_of_deleted_window (WINDOW *window) { /* If this is the calling_window, forget what we remembered about it. */ if (window == calling_window) @@ -1400,7 +1397,7 @@ static int pushed_echo_areas_slots = 0; /* Pushing the echo_area has a side effect of zeroing the completion_items. */ static void -push_echo_area () +push_echo_area (void) { PUSHED_EA *pushed; @@ -1422,7 +1419,7 @@ push_echo_area () } static void -pop_echo_area () +pop_echo_area (void) { PUSHED_EA *popped; @@ -1460,7 +1457,7 @@ pop_echo_area () /* Returns non-zero if any of the prior stacked calls to read in the echo area produced a completions window. */ static int -echo_area_stack_contains_completions_p () +echo_area_stack_contains_completions_p (void) { register int i; @@ -1483,7 +1480,7 @@ echo_area_stack_contains_completions_p () #endif /* HAVE_SYS_TIME_H */ static void -pause_or_input () +pause_or_input (void) { #ifdef FD_SET struct timeval timer; @@ -1503,14 +1500,14 @@ pause_or_input () for input or a couple of seconds, whichever comes first. Then flush the informational message that was printed. */ void -inform_in_echo_area (message) - char *message; +inform_in_echo_area (const char *message) { - register int i; + int i; char *text; + int avail = EA_MAX_INPUT + 1 - input_line_end; text = xstrdup (message); - for (i = 0; text[i] && text[i] != '\n'; i++) + for (i = 0; text[i] && text[i] != '\n' && i < avail; i++) ; text[i] = 0; |