Back to index

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

Go to the source code of this file.

Defines

#define HELP_NODE_GETS_REGENERATED   1
#define HELP_SPLIT_SIZE   24

Functions

static char * where_is_internal (Keymap map, InfoCommand *cmd)
void dump_map_to_message_buffer (char *prefix, Keymap map)
static void create_internal_info_help_node (int help_is_only_window_p)
static WINDOWinfo_find_or_create_help_window (void)
char * pretty_keyseq (char *keyseq)
static void pretty_keyseq_internal (char *keyseq, char *rep)
static char * strrpbrk (const char *s, const char *f)
char * replace_in_documentation (char *string, int help_is_only_window_p)
char * where_is (Keymap map, InfoCommand *cmd)
 DECLARE_INFO_COMMAND (info_where_is, _("Show what to type to execute a given command"))

Variables

static char * info_help_nodename = "*Info Help*"
static NODEinternal_info_help_node = (NODE *)NULL
static char * internal_info_help_node_contents = (char *)NULL
static char * info_internal_help_text []
static char * where_is_rep = (char *)NULL
static int where_is_rep_index = 0
static int where_is_rep_size = 0

Define Documentation

Definition at line 28 of file infodoc.c.

#define HELP_SPLIT_SIZE   24

Definition at line 412 of file infodoc.c.


Function Documentation

static void create_internal_info_help_node ( int  help_is_only_window_p) [static]

Definition at line 274 of file infodoc.c.

{
  register int i;
  NODE *node;
  char *contents = NULL;
  char *exec_keys;

#ifndef HELP_NODE_GETS_REGENERATED
  if (internal_info_help_node_contents)
    contents = internal_info_help_node_contents;
#endif /* !HELP_NODE_GETS_REGENERATED */

  if (!contents)
    {
      int printed_one_mx = 0;

      initialize_message_buffer ();

      for (i = 0; info_internal_help_text[i]; i++)
        {
#ifdef INFOKEY
          printf_to_message_buffer (replace_in_documentation
              ((char *) _(info_internal_help_text[i]), help_is_only_window_p),
              NULL, NULL, NULL);
#else
          /* Don't translate blank lines, gettext outputs the po file
             header in that case.  We want a blank line.  */
          char *msg = *(info_internal_help_text[i])
                      ? _(info_internal_help_text[i])
                      : info_internal_help_text[i];
          char *key = info_help_keys_text[i][vi_keys_p];

          /* If we have only one window (because the window size was too
             small to split it), CTRL-x 0 doesn't work to `quit' help.  */
          if (STREQ (key, "CTRL-x 0") && help_is_only_window_p)
            key = "l";

          printf_to_message_buffer (msg, key, NULL, NULL);
#endif /* !INFOKEY */
        }

      printf_to_message_buffer ("---------------------\n\n", NULL, NULL, NULL);
      printf_to_message_buffer ((char *) _("The current search path is:\n"),
          NULL, NULL, NULL);
      printf_to_message_buffer ("  %s\n", infopath, NULL, NULL);
      printf_to_message_buffer ("---------------------\n\n", NULL, NULL, NULL);
      printf_to_message_buffer ((char *) _("Commands available in Info windows:\n\n"),
          NULL, NULL, NULL);
      dump_map_to_message_buffer ("", info_keymap);
      printf_to_message_buffer ("---------------------\n\n", NULL, NULL, NULL);
      printf_to_message_buffer ((char *) _("Commands available in the echo area:\n\n"),
          NULL, NULL, NULL);
      dump_map_to_message_buffer ("", echo_area_keymap);

#if defined (NAMED_FUNCTIONS)
      /* Get a list of commands which have no keystroke equivs. */
      exec_keys = where_is (info_keymap, InfoCmd(info_execute_command));
      if (exec_keys)
        exec_keys = xstrdup (exec_keys);
      for (i = 0; function_doc_array[i].func; i++)
        {
          InfoCommand *cmd = DocInfoCmd(&function_doc_array[i]);

          if (InfoFunction(cmd) != (VFunction *) info_do_lowercase_version
              && !where_is_internal (info_keymap, cmd)
              && !where_is_internal (echo_area_keymap, cmd))
            {
              if (!printed_one_mx)
                {
                  printf_to_message_buffer ("---------------------\n\n",
                      NULL, NULL, NULL);
                  if (exec_keys && exec_keys[0])
                      printf_to_message_buffer
                        ((char *) _("The following commands can only be invoked via %s:\n\n"),
                         exec_keys, NULL, NULL);
                  else
                      printf_to_message_buffer
                        ((char *) _("The following commands cannot be invoked at all:\n\n"),
                         NULL, NULL, NULL);
                  printed_one_mx = 1;
                }

              printf_to_message_buffer
                ("%s %s\n     %s\n",
                 exec_keys,
                 function_doc_array[i].func_name,
                 replace_in_documentation (strlen (function_doc_array[i].doc)
                   ? (char *) _(function_doc_array[i].doc) : "", 0)
                );

            }
        }

      if (printed_one_mx)
        printf_to_message_buffer ("\n", NULL, NULL, NULL);

      maybe_free (exec_keys);
#endif /* NAMED_FUNCTIONS */

      printf_to_message_buffer
        ("%s", replace_in_documentation
         ((char *) _("--- Use `\\[history-node]' or `\\[kill-node]' to exit ---\n"), 0),
         NULL, NULL);
      node = message_buffer_to_node ();
      internal_info_help_node_contents = node->contents;
    }
  else
    {
      /* We already had the right contents, so simply use them. */
      node = build_message_node ("", 0, 0);
      free (node->contents);
      node->contents = contents;
      node->nodelen = 1 + strlen (contents);
    }

  internal_info_help_node = node;

  /* Do not GC this node's contents.  It never changes, and we never need
     to delete it once it is made.  If you change some things (such as
     placing information about dynamic variables in the help text) then
     you will need to allow the contents to be gc'd, and you will have to
     arrange to always regenerate the help node. */
#if defined (HELP_NODE_GETS_REGENERATED)
  add_gcable_pointer (internal_info_help_node->contents);
#endif

  name_internal_node (internal_info_help_node, info_help_nodename);

  /* Even though this is an internal node, we don't want the window
     system to treat it specially.  So we turn off the internalness
     of it here. */
  internal_info_help_node->flags &= ~N_IsInternal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

DECLARE_INFO_COMMAND ( info_where_is  ,
_("Show what to type to execute a given command")   
)

Definition at line 1152 of file infodoc.c.

{
  char *command_name;

  command_name = read_function_name ((char *) _("Where is command: "), window);

  if (!command_name)
    {
      info_abort_key (active_window, count, key);
      return;
    }

  if (*command_name)
    {
      InfoCommand *command;

      command = named_function (command_name);

      if (command)
        {
          char *location;

          location = where_is (active_window->keymap, command);

          if (!location || !location[0])
            {
              info_error ((char *) _("`%s' is not on any keys"),
                  command_name, NULL);
            }
          else
            {
              if (strstr (location, function_name (command)))
                window_message_in_echo_area
                  ((char *) _("%s can only be invoked via %s."),
                   command_name, location);
              else
                window_message_in_echo_area
                  ((char *) _("%s can be invoked via %s."),
                   command_name, location);
            }
        }
      else
        info_error ((char *) _("There is no function named `%s'"),
            command_name, NULL);
    }

  free (command_name);
}

Here is the call graph for this function:

void dump_map_to_message_buffer ( char *  prefix,
Keymap  map 
)

Definition at line 191 of file infodoc.c.

{
  register int i;
  unsigned prefix_len = strlen (prefix);
  char *new_prefix = (char *)xmalloc (prefix_len + 2);

  strncpy (new_prefix, prefix, prefix_len);
  new_prefix[prefix_len + 1] = '\0';

  for (i = 0; i < 256; i++)
    {
      new_prefix[prefix_len] = i;
      if (map[i].type == ISKMAP)
        {
          dump_map_to_message_buffer (new_prefix, (Keymap)map[i].function);
        }
      else if (map[i].function)
        {
          register int last;
          char *doc, *name;

          doc = function_documentation (map[i].function);
          name = function_name (map[i].function);

          if (!*doc)
            continue;

          /* Find out if there is a series of identical functions, as in
             ea_insert (). */
          for (last = i + 1; last < 256; last++)
            if ((map[last].type != ISFUNC) ||
                (map[last].function != map[i].function))
              break;

          if (last - 1 != i)
            {
              printf_to_message_buffer ("%s .. ", pretty_keyseq (new_prefix),
                  NULL, NULL);
              new_prefix[prefix_len] = last - 1;
              printf_to_message_buffer ("%s\t", pretty_keyseq (new_prefix),
                  NULL, NULL);
              i = last - 1;
            }
          else
            printf_to_message_buffer ("%s\t", pretty_keyseq (new_prefix),
                NULL, NULL);

#if defined (NAMED_FUNCTIONS)
          /* Print the name of the function, and some padding before the
             documentation string is printed. */
          {
            int length_so_far;
            int desired_doc_start = 40; /* Must be multiple of 8. */

            printf_to_message_buffer ("(%s)", name, NULL, NULL);
            length_so_far = message_buffer_length_this_line ();

            if ((desired_doc_start + strlen (doc))
                >= (unsigned int) the_screen->width)
              printf_to_message_buffer ("\n     ", NULL, NULL, NULL);
            else
              {
                while (length_so_far < desired_doc_start)
                  {
                    printf_to_message_buffer ("\t", NULL, NULL, NULL);
                    length_so_far += character_width ('\t', length_so_far);
                  }
              }
          }
#endif /* NAMED_FUNCTIONS */
          printf_to_message_buffer ("%s\n", doc, NULL, NULL);
        }
    }
  free (new_prefix);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 415 of file infodoc.c.

{
  int help_is_only_window_p;
  WINDOW *eligible = NULL;
  WINDOW *help_window = get_window_of_node (internal_info_help_node);

  /* If we couldn't find the help window, then make it. */
  if (!help_window)
    {
      WINDOW *window;
      int max = 0;

      for (window = windows; window; window = window->next)
        {
          if (window->height > max)
            {
              max = window->height;
              eligible = window;
            }
        }

      if (!eligible)
        return NULL;
    }
#ifndef HELP_NODE_GETS_REGENERATED
  else
    /* help window is static, just return it.  */
    return help_window;
#endif /* not HELP_NODE_GETS_REGENERATED */

  /* Make sure that we have a node containing the help text.  The
     argument is false if help will be the only window (so l must be used
     to quit help), true if help will be one of several visible windows
     (so CTRL-x 0 must be used to quit help).  */
  help_is_only_window_p = ((help_window && !windows->next)
        || (!help_window && eligible->height < HELP_SPLIT_SIZE));
  create_internal_info_help_node (help_is_only_window_p);

  /* Either use the existing window to display the help node, or create
     a new window if there was no existing help window. */
  if (!help_window)
    { /* Split the largest window into 2 windows, and show the help text
         in that window. */
      if (eligible->height >= HELP_SPLIT_SIZE)
        {
          active_window = eligible;
          help_window = window_make_window (internal_info_help_node);
        }
      else
        {
          set_remembered_pagetop_and_point (active_window);
          window_set_node_of_window (active_window, internal_info_help_node);
          help_window = active_window;
        }
    }
  else
    { /* Case where help node always gets regenerated, and we have an
         existing window in which to place the node. */
      if (active_window != help_window)
        {
          set_remembered_pagetop_and_point (active_window);
          active_window = help_window;
        }
      window_set_node_of_window (active_window, internal_info_help_node);
    }
  remember_window_and_node (help_window, help_window->node);
  return help_window;
}

Here is the call graph for this function:

char* pretty_keyseq ( char *  keyseq)

Definition at line 795 of file infodoc.c.

{
  static char keyseq_rep[200];

  keyseq_rep[0] = '\0';
  if (*keyseq)
    pretty_keyseq_internal (keyseq, keyseq_rep);
  return (keyseq_rep);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pretty_keyseq_internal ( char *  keyseq,
char *  rep 
) [static]

Definition at line 806 of file infodoc.c.

{
  if (term_kP && strncmp(keyseq, term_kP, strlen(term_kP)) == 0)
    {
      strcpy(rep, "PgUp");
      keyseq += strlen(term_kP);
    }
  else if (term_kN && strncmp(keyseq, term_kN, strlen(term_kN)) == 0)
    {
      strcpy(rep, "PgDn");
      keyseq += strlen(term_kN);
    }
#if defined(INFOKEY)
  else if (term_kh && strncmp(keyseq, term_kh, strlen(term_kh)) == 0)
    {
      strcpy(rep, "Home");
      keyseq += strlen(term_kh);
    }
  else if (term_ke && strncmp(keyseq, term_ke, strlen(term_ke)) == 0)
    {
      strcpy(rep, "End");
      keyseq += strlen(term_ke);
    }
  else if (term_ki && strncmp(keyseq, term_ki, strlen(term_ki)) == 0)
    {
      strcpy(rep, "INS");
      keyseq += strlen(term_ki);
    }
  else if (term_kx && strncmp(keyseq, term_kx, strlen(term_kx)) == 0)
    {
      strcpy(rep, "DEL");
      keyseq += strlen(term_kx);
    }
#endif /* INFOKEY */
  else if (term_ku && strncmp(keyseq, term_ku, strlen(term_ku)) == 0)
    {
      strcpy(rep, "Up");
      keyseq += strlen(term_ku);
    }
  else if (term_kd && strncmp(keyseq, term_kd, strlen(term_kd)) == 0)
    {
      strcpy(rep, "Down");
      keyseq += strlen(term_kd);
    }
  else if (term_kl && strncmp(keyseq, term_kl, strlen(term_kl)) == 0)
    {
      strcpy(rep, "Left");
      keyseq += strlen(term_kl);
    }
  else if (term_kr && strncmp(keyseq, term_kr, strlen(term_kr)) == 0)
    {
      strcpy(rep, "Right");
      keyseq += strlen(term_kr);
    }
  else
    {
      strcpy (rep, pretty_keyname (keyseq[0]));
      keyseq++;
    }
  if (*keyseq)
    {
      strcat (rep, " ");
      pretty_keyseq_internal (keyseq, rep + strlen(rep));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* replace_in_documentation ( char *  string,
int  help_is_only_window_p 
)

Definition at line 890 of file infodoc.c.

{
  unsigned reslen = strlen (string);
  register int i, start, next;
  static char *result = (char *)NULL;

  maybe_free (result);
  result = (char *)xmalloc (1 + reslen);

  i = next = start = 0;

  /* Skip to the beginning of a replaceable function. */
  for (i = start; string[i]; i++)
    {
      int j = i + 1;

      /* Is this the start of a replaceable function name? */
      if (string[i] == '\\')
        {
          char *fmt = NULL;
          unsigned min = 0;
          unsigned max = 0;

          if(string[j] == '%')
            {
              if (string[++j] == '-')
                j++;
              if (isdigit(string[j]))
                {
                  min = atoi(string + j);
                  while (isdigit(string[j]))
                    j++;
                  if (string[j] == '.' && isdigit(string[j + 1]))
                    {
                      j += 1;
                      max = atoi(string + j);
                      while (isdigit(string[j]))
                        j++;
                    }
                  fmt = (char *)xmalloc (j - i + 2);
                  strncpy (fmt, string + i + 1, j - i);
                  fmt[j - i - 1] = 's';
                  fmt[j - i] = '\0';
                }
              else
                j = i + 1;
            }
          if (string[j] == '[')
            {
              unsigned arg = 0;
              char *argstr = NULL;
              char *rep_name, *fun_name, *rep;
              InfoCommand *command;
              char *repstr = NULL;
              unsigned replen;

              /* Copy in the old text. */
              strncpy (result + next, string + start, i - start);
              next += (i - start);
              start = j + 1;

              /* Look for an optional numeric arg. */
              i = start;
              if (isdigit(string[i])
                  || (string[i] == '-' && isdigit(string[i + 1])) )
                {
                  arg = atoi(string + i);
                  if (string[i] == '-')
                    i++;
                  while (isdigit(string[i]))
                    i++;
                }
              start = i;

              /* Move to the end of the function name. */
              for (i = start; string[i] && (string[i] != ']'); i++);

              rep_name = (char *)xmalloc (1 + i - start);
              strncpy (rep_name, string + start, i - start);
              rep_name[i - start] = '\0';

            /* If we have only one window (because the window size was too
               small to split it), we have to quit help by going back one
               noew in the history list, not deleting the window.  */
              if (strcmp (rep_name, "quit-help") == 0)
                fun_name = help_is_only_window_p ? "history-node"
                                                 : "delete-window";
              else
                fun_name = rep_name;

              /* Find a key which invokes this function in the info_keymap. */
              command = named_function (fun_name);

              free (rep_name);

              /* If the internal documentation string fails, there is a
                 serious problem with the associated command's documentation.
                 We croak so that it can be fixed immediately. */
              if (!command)
                abort ();

              if (arg)
                {
                  char *argrep, *p;

                  argrep = where_is (info_keymap, InfoCmd(info_add_digit_to_numeric_arg));
                  p = argrep ? strrpbrk (argrep, "0123456789-") : NULL;
                  if (p)
                    {
                      argstr = (char *)xmalloc (p - argrep + 21);
                      strncpy (argstr, argrep, p - argrep);
                      sprintf (argstr + (p - argrep), "%d", arg);
                    }
                  else
                    command = NULL;
                }
              rep = command ? where_is (info_keymap, command) : NULL;
              if (!rep)
                rep = "N/A";
              replen = (argstr ? strlen (argstr) : 0) + strlen (rep) + 1;
              repstr = (char *)xmalloc (replen);
              repstr[0] = '\0';
              if (argstr)
                {
                  strcat(repstr, argstr);
                  strcat(repstr, " ");
                  free (argstr);
                }
              strcat(repstr, rep);

              if (fmt)
                {
                  if (replen > max)
                    replen = max;
                  if (replen < min)
                    replen = min;
                }
              if (next + replen > reslen)
                {
                  reslen = next + replen + 1;
                  result = (char *)xrealloc (result, reslen + 1);
                }

              if (fmt)
                  sprintf (result + next, fmt, repstr);
              else
                  strcpy (result + next, repstr);

              next = strlen (result);
              free (repstr);

              start = i;
              if (string[i])
                start++;
            }

          maybe_free (fmt);
        }
    }
  strcpy (result + next, string + start);
  return (result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* strrpbrk ( const char *  s,
const char *  f 
) [static]

Definition at line 874 of file infodoc.c.

{
  register const char *e = s + strlen(s);
  register const char *t;

  while (e-- != s)
    {
      for (t = f; *t; t++)
        if (*e == *t)
          return (char *)e;
    }
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* where_is ( Keymap  map,
InfoCommand cmd 
)

Definition at line 1060 of file infodoc.c.

{
  char *rep;

  if (!where_is_rep_size)
    where_is_rep = (char *)xmalloc (where_is_rep_size = 100);
  where_is_rep_index = 0;

  rep = where_is_internal (map, cmd);

  /* If it couldn't be found, return "M-x Foo" (or equivalent). */
  if (!rep)
    {
      char *name;

      name = function_name (cmd);
      if (!name)
        return NULL; /* no such function */

      rep = where_is_internal (map, InfoCmd(info_execute_command));
      if (!rep)
        return ""; /* function exists but can't be got to by user */

      sprintf (where_is_rep, "%s %s", rep, name);

      rep = where_is_rep;
    }
  return (rep);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * where_is_internal ( Keymap  map,
InfoCommand cmd 
) [static]

Definition at line 1093 of file infodoc.c.

{
#if defined(INFOKEY)

  register FUNCTION_KEYSEQ *k;

  for (k = cmd->keys; k; k = k->next)
    if (k->map == map)
      return pretty_keyseq (k->keyseq);

  return NULL;

#else /* !INFOKEY */
  /* There is a bug in that create_internal_info_help_node calls
     where_is_internal without setting where_is_rep_index to zero.  This
     was found by Mandrake and reported by Thierry Vignaud
     <tvignaud@mandrakesoft.com> around April 24, 2002.

     I think the best fix is to make where_is_rep_index another
     parameter to this recursively-called function, instead of a static
     variable.  But this [!INFOKEY] branch of the code is not enabled
     any more, so let's just skip the whole thing.  --karl, 28sep02.  */
  register int i;

  /* If the function is directly invokable in MAP, return the representation
     of that keystroke. */
  for (i = 0; i < 256; i++)
    if ((map[i].type == ISFUNC) && map[i].function == cmd)
      {
        sprintf (where_is_rep + where_is_rep_index, "%s", pretty_keyname (i));
        return (where_is_rep);
      }

  /* Okay, search subsequent maps for this function. */
  for (i = 0; i < 256; i++)
    {
      if (map[i].type == ISKMAP)
        {
          int saved_index = where_is_rep_index;
          char *rep;

          sprintf (where_is_rep + where_is_rep_index, "%s ",
                   pretty_keyname (i));

          where_is_rep_index = strlen (where_is_rep);
          rep = where_is_internal ((Keymap)map[i].function, cmd);

          if (rep)
            return (where_is_rep);

          where_is_rep_index = saved_index;
        }
    }

  return NULL;

#endif /* INFOKEY */
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* info_help_nodename = "*Info Help*" [static]

Definition at line 31 of file infodoc.c.

char* info_internal_help_text[] [static]

Definition at line 45 of file infodoc.c.

Definition at line 34 of file infodoc.c.

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

Definition at line 37 of file infodoc.c.

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

Definition at line 1055 of file infodoc.c.

int where_is_rep_index = 0 [static]

Definition at line 1056 of file infodoc.c.

int where_is_rep_size = 0 [static]

Definition at line 1057 of file infodoc.c.