예제 #1
0
파일: m-x.c 프로젝트: mwcampbell/texinfo
/* Read the name of an Info function in the echo area and return the
   name.  A return value of NULL indicates that no function name could
   be read. */
char *
read_function_name (const char *prompt, WINDOW *window)
{
  register int i;
  char *line;
  REFERENCE **array = NULL;
  size_t array_index = 0, array_slots = 0;

  /* Make an array of REFERENCE which actually contains the names of
     the functions available in Info. */
  for (i = 0; function_doc_array[i].func; i++)
    {
      REFERENCE *entry;

      entry = xmalloc (sizeof (REFERENCE));
      entry->label = xstrdup (function_doc_array[i].func_name);
      entry->nodename = NULL;
      entry->filename = NULL;

      add_pointer_to_array (entry, array_index, array, array_slots, 200);
    }

  line = info_read_completing_in_echo_area (window, prompt, array);

  info_free_references (array);

  if (!echo_area_is_active)
    window_clear_echo_area ();

  return line;
}
예제 #2
0
/* Manufacture a node containing the footnotes of this node, and
   return the manufactured node.  If NODE has no footnotes, return a 
   NULL pointer. */
NODE *
make_footnotes_node (NODE *node)
{
  NODE *fn_node, *result = (NODE *)NULL;
  long fn_start;

  /* Make the initial assumption that the footnotes appear as simple
     text within this windows node. */
  fn_node = node;

  /* See if this node contains the magic footnote label. */
  fn_start =
    info_search_in_node (FOOTNOTE_LABEL, node, 0, (WINDOW *)NULL, 1, 0);

  /* If it doesn't, check to see if it has an associated footnotes node. */
  if (fn_start == -1)
    {
      REFERENCE **refs;

      refs = info_xrefs_of_node (node);

      if (refs)
        {
          register int i;
          char *refname;
          int reflen = strlen ("-Footnotes") + strlen (node->nodename);

          refname = (char *)xmalloc (reflen + 1);

          strcpy (refname, node->nodename);
          strcat (refname, "-Footnotes");

          for (i = 0; refs[i]; i++)
            if ((refs[i]->nodename != (char *)NULL) &&
                /* Support both the older "foo-Footnotes" and the new
                   style "foo-Footnote-NN" references.  */
                (strcmp (refs[i]->nodename, refname) == 0 ||
                 (strncmp (refs[i]->nodename, refname, reflen - 1) == 0 &&
                  refs[i]->nodename[reflen - 1] == '-' &&
                  isdigit (refs[i]->nodename[reflen]))))
              {
                char *filename;

                filename = node->parent;
                if (!filename)
                  filename = node->filename;

                fn_node = info_get_node (filename, refname);

                if (fn_node)
                  fn_start = 0;

                break;
              }

          free (refname);
          info_free_references (refs);
        }
    }

  /* If we never found the start of a footnotes area, quit now. */
  if (fn_start == -1)
    return ((NODE *)NULL);

  /* Make the new node. */
  result = (NODE *)xmalloc (sizeof (NODE));
  result->flags = 0;
  result->display_pos = 0;

  /* Get the size of the footnotes appearing within this node. */
  {
    char *header;
    long text_start = fn_start;

    header = (char *)xmalloc
      (1 + strlen (node->nodename) + strlen (FOOTNOTE_HEADER_FORMAT));
    sprintf (header, FOOTNOTE_HEADER_FORMAT, node->nodename);

    /* Move the start of the displayed text to right after the first line.
       This effectively skips either "---- footno...", or "File: foo...". */
    while (text_start < fn_node->nodelen)
      if (fn_node->contents[text_start++] == '\n')
        break;
  
    result->nodelen = strlen (header) + fn_node->nodelen - text_start;

    /* Set the contents of this node. */
    result->contents = (char *)xmalloc (1 + result->nodelen);
    sprintf (result->contents, "%s", header);
    memcpy (result->contents + strlen (header),
            fn_node->contents + text_start, fn_node->nodelen - text_start);

    name_internal_node (result, footnote_nodename);
    free (header);
  }

#if defined (NOTDEF)
  /* If the footnotes were gleaned from the node that we were called with,
     shorten the calling node's display length. */
  if (fn_node == node)
    narrow_node (node, 0, fn_start);
#endif /* NOTDEF */

  return (result);
}