Home | History | Annotate | Line # | Download | only in info
      1 /*	$NetBSD: nodes.h,v 1.1.1.1 2016/01/14 00:11:29 christos Exp $	*/
      2 
      3 /* nodes.h -- How we represent nodes internally.
      4    Id: nodes.h,v 1.3 2004/04/11 17:56:46 karl Exp
      5 
      6    Copyright (C) 1993, 1997, 1998, 2002, 2004 Free Software Foundation, Inc.
      7 
      8    This program is free software; you can redistribute it and/or modify
      9    it under the terms of the GNU General Public License as published by
     10    the Free Software Foundation; either version 2, or (at your option)
     11    any later version.
     12 
     13    This program is distributed in the hope that it will be useful,
     14    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16    GNU General Public License for more details.
     17 
     18    You should have received a copy of the GNU General Public License
     19    along with this program; if not, write to the Free Software
     20    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     21 
     22    Written by Brian Fox (bfox (at) ai.mit.edu). */
     23 
     24 #ifndef NODES_H
     25 #define NODES_H
     26 
     27 #include "info.h"
     28 
     29 /* User code interface.  */
     30 
     31 /* Callers generally only want the node itself.  This structure is used
     32    to pass node information around.  None of the information in this
     33    structure should ever be directly freed.  The structure itself can
     34    be passed to free ().  Note that NODE->parent is non-null if this
     35    node's file is a subfile.  In that case, NODE->parent is the logical
     36    name of the file containing this node.  Both names are given as full
     37    paths, so you might have: node->filename = "/usr/gnu/info/emacs-1",
     38    with node->parent = "/usr/gnu/info/emacs". */
     39 typedef struct {
     40   char *filename;               /* The physical file containing this node. */
     41   char *parent;                 /* Non-null is the logical file name. */
     42   char *nodename;               /* The name of this node. */
     43   char *contents;               /* Characters appearing in this node. */
     44   long nodelen;                 /* The length of the CONTENTS member. */
     45   unsigned long display_pos;    /* Where to display at, if nonzero.  */
     46   int flags;                    /* See immediately below. */
     47 } NODE;
     48 
     49 /* Defines that can appear in NODE->flags.  All informative. */
     50 #define N_HasTagsTable 0x01     /* This node was found through a tags table. */
     51 #define N_TagsIndirect 0x02     /* The tags table was an indirect one. */
     52 #define N_UpdateTags   0x04     /* The tags table is out of date. */
     53 #define N_IsCompressed 0x08     /* The file is compressed on disk. */
     54 #define N_IsInternal   0x10     /* This node was made by Info. */
     55 #define N_CannotGC     0x20     /* File buffer cannot be gc'ed. */
     56 #define N_IsManPage    0x40     /* This node is a manpage. */
     57 #define N_FromAnchor   0x80     /* Synthesized for an anchor reference. */
     58 
     59 /* Internal data structures.  */
     61 
     62 /* String constants. */
     63 #define INFO_FILE_LABEL                 "File:"
     64 #define INFO_REF_LABEL                  "Ref:"
     65 #define INFO_NODE_LABEL                 "Node:"
     66 #define INFO_PREV_LABEL                 "Prev:"
     67 #define INFO_ALTPREV_LABEL              "Previous:"
     68 #define INFO_NEXT_LABEL                 "Next:"
     69 #define INFO_UP_LABEL                   "Up:"
     70 #define INFO_MENU_LABEL                 "\n* Menu:"
     71 #define INFO_MENU_ENTRY_LABEL           "\n* "
     72 #define INFO_XREF_LABEL                 "*Note"
     73 #define TAGS_TABLE_END_LABEL            "\nEnd Tag Table"
     74 #define TAGS_TABLE_BEG_LABEL            "Tag Table:\n"
     75 #define INDIRECT_TAGS_TABLE_LABEL       "Indirect:\n"
     76 #define TAGS_TABLE_IS_INDIRECT_LABEL    "(Indirect)"
     77 
     78 /* Character constants. */
     79 #define INFO_COOKIE '\037'
     80 #define INFO_FF     '\014'
     81 #define INFO_TAGSEP '\177'
     82 
     83 /* For each logical file that we have loaded, we keep a list of the names
     84    of the nodes that are found in that file.  A pointer to a node in an
     85    info file is called a "tag".  For split files, the tag pointer is
     86    "indirect"; that is, the pointer also contains the name of the split
     87    file where the node can be found.  For non-split files, the filename
     88    member in the structure below simply contains the name of the current
     89    file.  The following structure describes a single node within a file. */
     90 typedef struct {
     91   char *filename;               /* The file where this node can be found. */
     92   char *nodename;               /* The node pointed to by this tag. */
     93   long nodestart;               /* The offset of the start of this node. */
     94   long nodelen;                 /* The length of this node. */
     95 } TAG;
     96 
     97 /* The following structure is used to remember information about the contents
     98    of Info files that we have loaded at least once before.  The FINFO member
     99    is present so that we can reload the file if it has been modified since
    100    last being loaded.  All of the arrays appearing within this structure
    101    are NULL terminated, and each array which can change size has a
    102    corresponding SLOTS member which says how many slots have been allocated
    103    (with malloc ()) for this array. */
    104 typedef struct {
    105   char *filename;               /* The filename used to find this file. */
    106   char *fullpath;               /* The full pathname of this info file. */
    107   struct stat finfo;            /* Information about this file. */
    108   char *contents;               /* The contents of this particular file. */
    109   long filesize;                /* The number of bytes this file expands to. */
    110   char **subfiles;              /* If non-null, the list of subfiles. */
    111   TAG **tags;                   /* If non-null, the indirect tags table. */
    112   int tags_slots;               /* Number of slots allocated for TAGS. */
    113   int flags;                    /* Various flags.  Mimics of N_* flags. */
    114 } FILE_BUFFER;
    115 
    116 /* Externally visible functions.  */
    118 
    119 /* Array of FILE_BUFFER * which represents the currently loaded info files. */
    120 extern FILE_BUFFER **info_loaded_files;
    121 
    122 /* The number of slots currently allocated to INFO_LOADED_FILES. */
    123 extern int info_loaded_files_slots;
    124 
    125 /* Locate the file named by FILENAME, and return the information structure
    126    describing this file.  The file may appear in our list of loaded files
    127    already, or it may not.  If it does not already appear, find the file,
    128    and add it to the list of loaded files.  If the file cannot be found,
    129    return a NULL FILE_BUFFER *. */
    130 extern FILE_BUFFER *info_find_file (char *filename);
    131 
    132 /* Force load the file named FILENAME, and return the information structure
    133    describing this file.  Even if the file was already loaded, this loads
    134    a new buffer, rebuilds tags and nodes, and returns a new FILE_BUFFER *. */
    135 extern FILE_BUFFER *info_load_file (char *filename);
    136 
    137 /* Return a pointer to a NODE structure for the Info node (FILENAME)NODENAME.
    138    FILENAME can be passed as NULL, in which case the filename of "dir" is used.
    139    NODENAME can be passed as NULL, in which case the nodename of "Top" is used.
    140    If the node cannot be found, return a NULL pointer. */
    141 extern NODE *info_get_node (char *filename, char *nodename);
    142 
    143 /* Return a pointer to a NODE structure for the Info node NODENAME in
    144    FILE_BUFFER.  NODENAME can be passed as NULL, in which case the
    145    nodename of "Top" is used.  If the node cannot be found, return a
    146    NULL pointer. */
    147 extern NODE *info_get_node_of_file_buffer (char *nodename,
    148     FILE_BUFFER *file_buffer);
    149 
    150 /* Grovel FILE_BUFFER->contents finding tags and nodes, and filling in the
    151    various slots.  This can also be used to rebuild a tag or node table. */
    152 extern void build_tags_and_nodes (FILE_BUFFER *file_buffer);
    153 
    154 /* When non-zero, this is a string describing the most recent file error. */
    155 extern char *info_recent_file_error;
    156 
    157 /* Create a new, empty file buffer. */
    158 extern FILE_BUFFER *make_file_buffer (void);
    159 
    160 #endif /* not NODES_H */
    161