Back to index

tetex-bin  3.0
Defines | Functions | Variables
echo-area.c File Reference
#include "info.h"

Go to the source code of this file.

Defines

#define alphabetic(c)   (islower (c) || isupper (c) || isdigit (c))

Functions

static void echo_area_initialize_node (void)
static void push_echo_area (void)
static void pop_echo_area (void)
static int echo_area_stack_contains_completions_p (void)
static void ea_kill_text (int from, int to)
static int completions_window_p (WINDOW *window)
static void remember_calling_window (WINDOW *window)
static void restore_calling_window (void)
static void initialize_input_line (char *prompt)
static char * echo_area_after_read (void)
char * info_read_in_echo_area (WINDOW *window, char *prompt)
void echo_area_prep_read (void)
 if ()
static void build_completions (void)
static void completions_must_be_rebuilt (void)
char * info_read_completing_internal (WINDOW *window, char *prompt, REFERENCE **completions, int force)
char * info_read_completing_in_echo_area (WINDOW *window, char *prompt, REFERENCE **completions)
char * info_read_maybe_completing (WINDOW *window, char *prompt, REFERENCE **completions)
static void remove_completion_duplicates (void)
static int compare_references (const void *entry1, const void *entry2)
static void pause_or_input (void)
void inform_in_echo_area (const char *message)

Variables

int info_aborted_echo_area = 0
int echo_area_is_active = 0
VFunctionea_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
static int echo_area_must_complete_p = 0
static WINDOWecho_area_completions_window = (WINDOW *)NULL
static WINDOWcalling_window = (WINDOW *)NULL
static NODEcalling_window_node = (NODE *)NULL
static long calling_window_point = 0
static long calling_window_pagetop = 0
static int kill_ring_index = 0
static int kill_ring_slots = 0
static int kill_ring_loc = 0
static int max_retained_kills = 15
static REFERENCE ** completions_found = (REFERENCE **)NULL
static int completions_found_index = 0
static int completions_found_slots = 0
static REFERENCELCD_completion
static NODEpossible_completions_output_node = (NODE *)NULL
static char * compwin_name = "*Completions*"
static char * last_completion_request = (char *)NULL
static REFERENCE ** last_completion_items = (REFERENCE **)NULL
static PUSHED_EA ** pushed_echo_areas = (PUSHED_EA **)NULL
static int pushed_echo_areas_index = 0
static int pushed_echo_areas_slots = 0

Define Documentation

#define alphabetic (   c)    (islower (c) || isupper (c) || isdigit (c))

Function Documentation

static void build_completions ( void  ) [static]

Definition at line 1172 of file echo-area.c.

{
  register int i, len;
  register REFERENCE *entry;
  char *request;
  int informed_of_lengthy_job = 0;

  /* If there are no items to complete over, exit immediately. */
  if (!echo_area_completion_items)
    {
      completions_found_index = 0;
      LCD_completion = (REFERENCE *)NULL;
      return;
    }

  /* Check to see if this call to build completions is the same as the last
     call to build completions. */
  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;

  /* Always start at the beginning of the list. */
  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 ((char *) _("Building completions..."),
              NULL, NULL);
        }
    }

  if (!completions_found_index)
    return;

  /* Sort and prune duplicate entries from the completions array. */
  remove_completion_duplicates ();

  /* If there is only one completion, just return that. */
  if (completions_found_index == 1)
    {
      LCD_completion = completions_found[0];
      return;
    }

  /* Find the least common denominator. */
  {
    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);
    /* Since both the sorting done inside remove_completion_duplicates
       and all the comparisons above are case-insensitive, it's
       possible that the completion we are going to return is
       identical to what the user typed but for the letter-case.  This
       is confusing, since the user could type FOOBAR<TAB> and get her
       string change letter-case for no good reason.  So try to find a
       possible completion whose letter-case is identical, and if so,
       use that.  */
    if (completions_found_index > 1)
      {
       int req_len = strlen (request);

        for (i = 0; i < completions_found_index; i++)
          if (strncmp (request, completions_found[i]->label, req_len) == 0)
            break;
        /* If none of the candidates match exactly, use the first one.  */
        if (i >= completions_found_index)
          i = 0;
      }
    strncpy (LCD_reference.label, completions_found[i]->label, shortest);
    LCD_reference.label[shortest] = '\0';
    LCD_completion = &LCD_reference;
  }

  if (informed_of_lengthy_job)
    echo_area_initialize_node ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int compare_references ( const void entry1,
const void entry2 
) [static]

Definition at line 1290 of file echo-area.c.

{
  REFERENCE **e1 = (REFERENCE **) entry1;
  REFERENCE **e2 = (REFERENCE **) entry2;

  return (strcasecmp ((*e1)->label, (*e2)->label));
}

Here is the caller graph for this function:

Definition at line 1162 of file echo-area.c.

Here is the caller graph for this function:

static int completions_window_p ( WINDOW window) [static]

Definition at line 788 of file echo-area.c.

{
  int result = 0;

  if (internal_info_node_p (window->node) &&
      (strcmp (window->node->nodename, compwin_name) == 0))
    result = 1;

  return (result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ea_kill_text ( int  from,
int  to 
) [static]
static char* echo_area_after_read ( void  ) [static]

Definition at line 175 of file echo-area.c.

{
  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 = xstrdup ("");
      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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void echo_area_initialize_node ( void  ) [static]

Definition at line 250 of file echo-area.c.

{
  register int i;

  for (i = input_line_end; (unsigned int) 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';
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 266 of file echo-area.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1460 of file echo-area.c.

{
  register int i;

  for (i = 0; i < pushed_echo_areas_index; i++)
    if (pushed_echo_areas[i]->compwin)
      return (1);

  return (0);
}

Here is the caller graph for this function:

if ( )
char* info_read_completing_in_echo_area ( WINDOW window,
char *  prompt,
REFERENCE **  completions 
)

Definition at line 896 of file echo-area.c.

{
  return (info_read_completing_internal (window, prompt, completions, 1));
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* info_read_completing_internal ( WINDOW window,
char *  prompt,
REFERENCE **  completions,
int  force 
)

Definition at line 802 of file echo-area.c.

{
  char *line;

  /* If the echo area is already active, remember the current state. */
  if (echo_area_is_active)
    push_echo_area ();

  echo_area_must_complete_p = force;

  /* Initialize our local variables. */
  initialize_input_line (prompt);

  /* Initialize the echo area for the first (but maybe not the last) time. */
  echo_area_initialize_node ();

  /* Save away the original node of this window, and the window itself,
     so echo area commands can temporarily use this window. */
  remember_calling_window (window);

  /* Save away the list of items to complete over. */
  echo_area_completion_items = completions;
  completions_must_be_rebuilt ();

  active_window = the_echo_area;
  echo_area_is_active++;

  /* Read characters in the echo area. */
  while (1)
    {
      info_read_and_dispatch ();

      line = echo_area_after_read ();

      /* Force the completion to take place if the user hasn't accepted
         a default or aborted, and if FORCE is active. */
      if (force && line && *line && completions)
        {
          register int i;

          build_completions ();

          /* If there is only one completion, then make the line be that
             completion. */
          if (completions_found_index == 1)
            {
              free (line);
              line = xstrdup (completions_found[0]->label);
              break;
            }

          /* If one of the completions matches exactly, then that is okay, so
             return the current line. */
          for (i = 0; i < completions_found_index; i++)
            if (strcasecmp (completions_found[i]->label, line) == 0)
              {
                free (line);
                line = xstrdup (completions_found[i]->label);
                break;
              }

          /* If no match, go back and try again. */
          if (i == completions_found_index)
            {
              if (!completions_found_index)
                inform_in_echo_area ((char *) _("No completions"));
              else
                inform_in_echo_area ((char *) _("Not complete"));
              continue;
            }
        }
      break;
    }
  echo_area_is_active--;

  /* Restore the original active window and show point in it. */
  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 there is a previous loop waiting for us, restore it now. */
  if (echo_area_is_active)
    pop_echo_area ();

  return (line);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* info_read_in_echo_area ( WINDOW window,
char *  prompt 
)

Definition at line 204 of file echo-area.c.

{
  char *line;

  /* If the echo area is already active, remember the current state. */
  if (echo_area_is_active)
    push_echo_area ();

  /* Initialize our local variables. */
  initialize_input_line (prompt);

  /* Initialize the echo area for the first (but maybe not the last) time. */
  echo_area_initialize_node ();

  /* Save away the original node of this window, and the window itself,
     so echo area commands can temporarily use this window. */
  remember_calling_window (window);

  /* Let the rest of Info know that the echo area is active. */
  echo_area_is_active++;
  active_window = the_echo_area;

  /* Read characters in the echo area. */
  info_read_and_dispatch ();

  echo_area_is_active--;

  /* Restore the original active window and show point in it. */
  active_window = calling_window;
  restore_calling_window ();
  display_cursor_at_point (active_window);
  fflush (stdout);

  /* Get the value of the line. */
  line = echo_area_after_read ();

  /* If there is a previous loop waiting for us, restore it now. */
  if (echo_area_is_active)
    pop_echo_area ();

  /* Return the results to the caller. */
  return (line);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* info_read_maybe_completing ( WINDOW window,
char *  prompt,
REFERENCE **  completions 
)

Definition at line 905 of file echo-area.c.

{
  return (info_read_completing_internal (window, prompt, completions, 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void inform_in_echo_area ( const char *  message)

Definition at line 1503 of file echo-area.c.

{
  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 < avail; 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 ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void initialize_input_line ( char *  prompt) [static]

Definition at line 163 of file echo-area.c.

{
  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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pause_or_input ( void  ) [static]

Definition at line 1483 of file echo-area.c.

{
#ifdef 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 = 0;
  ready = select (fileno (stdin) + 1, &readfds, (fd_set *) NULL,
                  (fd_set *) NULL, &timer);
#endif /* FD_SET */
}

Here is the caller graph for this function:

static void pop_echo_area ( void  )

Definition at line 1422 of file echo-area.c.

{
  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 the completion window no longer exists, forget about it. */
  if (echo_area_completions_window)
    {
      register WINDOW *win;

      for (win = windows; win; win = win->next)
        if (echo_area_completions_window == win)
          break;

      /* If the window wasn't found, then it has already been deleted. */
      if (!win)
        echo_area_completions_window = (WINDOW *)NULL;
    }

  free (popped);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void push_echo_area ( void  ) [static]

Definition at line 1400 of file echo-area.c.

{
  PUSHED_EA *pushed;

  pushed = (PUSHED_EA *)xmalloc (sizeof (PUSHED_EA));
  pushed->line = xstrdup (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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void remember_calling_window ( WINDOW window) [static]

Definition at line 81 of file echo-area.c.

{
  /* 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. */
  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;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_completion_duplicates ( void  ) [static]

Definition at line 1300 of file echo-area.c.

{
  register int i, j;
  REFERENCE **temp;
  int newlen;

  if (!completions_found_index)
    return;

  /* Sort the items. */
  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++;
    }

  /* We have marked all the dead slots.  It is faster to copy the live slots
     twice than to prune the dead slots one by one. */
  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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void restore_calling_window ( void  ) [static]

Definition at line 98 of file echo-area.c.

{
  register WINDOW *win, *compwin = (WINDOW *)NULL;

  /* If the calling window is still visible, and it is the window that
     we used for completions output, then restore the calling window. */
  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;
        }
    }

  /* Delete the completions window if it is still present, it isn't the
     last window on the screen, and there aren't any prior echo area reads
     pending which created a completions window. */
  if (compwin)
    {
      if ((compwin != windows || windows->next) &&
          !echo_area_stack_contains_completions_p ())
        {
          WINDOW *next;
          int pagetop = 0;
          int start = 0;
          int end = 0;
          int amount = 0;

          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);

          /* This is not necessary because info_delete_window_internal ()
             calls echo_area_inform_of_deleted_window (), which does the
             right thing. */
#if defined (UNNECESSARY)
          echo_area_completions_window = (WINDOW *)NULL;
#endif /* UNNECESSARY */

          if (next)
            {
              display_scroll_display (start, end, amount);
              next->pagetop = pagetop;
              display_update_display (windows);
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

WINDOW* calling_window = (WINDOW *)NULL [static]

Definition at line 74 of file echo-area.c.

Definition at line 75 of file echo-area.c.

long calling_window_pagetop = 0 [static]

Definition at line 77 of file echo-area.c.

long calling_window_point = 0 [static]

Definition at line 76 of file echo-area.c.

Definition at line 771 of file echo-area.c.

Definition at line 772 of file echo-area.c.

Definition at line 773 of file echo-area.c.

char* compwin_name = "*Completions*" [static]

Definition at line 784 of file echo-area.c.

Definition at line 40 of file echo-area.c.

Definition at line 70 of file echo-area.c.

Definition at line 37 of file echo-area.c.

Definition at line 44 of file echo-area.c.

Definition at line 64 of file echo-area.c.

Definition at line 34 of file echo-area.c.

char input_line[1+EA_MAX_INPUT] [static]

Definition at line 47 of file echo-area.c.

int input_line_beg [static]

Definition at line 50 of file echo-area.c.

int input_line_end [static]

Definition at line 51 of file echo-area.c.

Initial value:
 {
  (char *)NULL, (char *)NULL, (char *)NULL, input_line,
  EA_MAX_INPUT, 0, N_IsInternal
}

Definition at line 52 of file echo-area.c.

Definition at line 49 of file echo-area.c.

char* input_line_prompt [static]

Definition at line 48 of file echo-area.c.

int kill_ring_index = 0 [static]

Definition at line 549 of file echo-area.c.

int kill_ring_loc = 0 [static]

Definition at line 551 of file echo-area.c.

int kill_ring_slots = 0 [static]

Definition at line 550 of file echo-area.c.

Definition at line 1158 of file echo-area.c.

char* last_completion_request = (char *)NULL [static]

Definition at line 1157 of file echo-area.c.

Definition at line 776 of file echo-area.c.

int max_retained_kills = 15 [static]

Definition at line 554 of file echo-area.c.

Definition at line 782 of file echo-area.c.

PUSHED_EA** pushed_echo_areas = (PUSHED_EA **)NULL [static]

Definition at line 1394 of file echo-area.c.

Definition at line 1395 of file echo-area.c.

Definition at line 1396 of file echo-area.c.