Back to index

tetex-bin  3.0
nodes.h
Go to the documentation of this file.
00001 /* nodes.h -- How we represent nodes internally.
00002    $Id: nodes.h,v 1.3 2004/04/11 17:56:46 karl Exp $
00003 
00004    Copyright (C) 1993, 1997, 1998, 2002, 2004 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 
00020    Written by Brian Fox (bfox@ai.mit.edu). */
00021 
00022 #ifndef NODES_H
00023 #define NODES_H
00024 
00025 #include "info.h"
00026 
00027 /* User code interface.  */
00028 
00029 /* Callers generally only want the node itself.  This structure is used
00030    to pass node information around.  None of the information in this
00031    structure should ever be directly freed.  The structure itself can
00032    be passed to free ().  Note that NODE->parent is non-null if this
00033    node's file is a subfile.  In that case, NODE->parent is the logical
00034    name of the file containing this node.  Both names are given as full
00035    paths, so you might have: node->filename = "/usr/gnu/info/emacs-1",
00036    with node->parent = "/usr/gnu/info/emacs". */
00037 typedef struct {
00038   char *filename;               /* The physical file containing this node. */
00039   char *parent;                 /* Non-null is the logical file name. */
00040   char *nodename;               /* The name of this node. */
00041   char *contents;               /* Characters appearing in this node. */
00042   long nodelen;                 /* The length of the CONTENTS member. */
00043   unsigned long display_pos;    /* Where to display at, if nonzero.  */
00044   int flags;                    /* See immediately below. */
00045 } NODE;
00046 
00047 /* Defines that can appear in NODE->flags.  All informative. */
00048 #define N_HasTagsTable 0x01     /* This node was found through a tags table. */
00049 #define N_TagsIndirect 0x02     /* The tags table was an indirect one. */
00050 #define N_UpdateTags   0x04     /* The tags table is out of date. */
00051 #define N_IsCompressed 0x08     /* The file is compressed on disk. */
00052 #define N_IsInternal   0x10     /* This node was made by Info. */
00053 #define N_CannotGC     0x20     /* File buffer cannot be gc'ed. */
00054 #define N_IsManPage    0x40     /* This node is a manpage. */
00055 #define N_FromAnchor   0x80     /* Synthesized for an anchor reference. */
00056 
00057 /* Internal data structures.  */
00058 
00059 /* String constants. */
00060 #define INFO_FILE_LABEL                 "File:"
00061 #define INFO_REF_LABEL                  "Ref:"
00062 #define INFO_NODE_LABEL                 "Node:"
00063 #define INFO_PREV_LABEL                 "Prev:"
00064 #define INFO_ALTPREV_LABEL              "Previous:"
00065 #define INFO_NEXT_LABEL                 "Next:"
00066 #define INFO_UP_LABEL                   "Up:"
00067 #define INFO_MENU_LABEL                 "\n* Menu:"
00068 #define INFO_MENU_ENTRY_LABEL           "\n* "
00069 #define INFO_XREF_LABEL                 "*Note"
00070 #define TAGS_TABLE_END_LABEL            "\nEnd Tag Table"
00071 #define TAGS_TABLE_BEG_LABEL            "Tag Table:\n"
00072 #define INDIRECT_TAGS_TABLE_LABEL       "Indirect:\n"
00073 #define TAGS_TABLE_IS_INDIRECT_LABEL    "(Indirect)"
00074 
00075 /* Character constants. */
00076 #define INFO_COOKIE '\037'
00077 #define INFO_FF     '\014'
00078 #define INFO_TAGSEP '\177'
00079 
00080 /* For each logical file that we have loaded, we keep a list of the names
00081    of the nodes that are found in that file.  A pointer to a node in an
00082    info file is called a "tag".  For split files, the tag pointer is
00083    "indirect"; that is, the pointer also contains the name of the split
00084    file where the node can be found.  For non-split files, the filename
00085    member in the structure below simply contains the name of the current
00086    file.  The following structure describes a single node within a file. */
00087 typedef struct {
00088   char *filename;               /* The file where this node can be found. */
00089   char *nodename;               /* The node pointed to by this tag. */
00090   long nodestart;               /* The offset of the start of this node. */
00091   long nodelen;                 /* The length of this node. */
00092 } TAG;
00093 
00094 /* The following structure is used to remember information about the contents
00095    of Info files that we have loaded at least once before.  The FINFO member
00096    is present so that we can reload the file if it has been modified since
00097    last being loaded.  All of the arrays appearing within this structure
00098    are NULL terminated, and each array which can change size has a
00099    corresponding SLOTS member which says how many slots have been allocated
00100    (with malloc ()) for this array. */
00101 typedef struct {
00102   char *filename;               /* The filename used to find this file. */
00103   char *fullpath;               /* The full pathname of this info file. */
00104   struct stat finfo;            /* Information about this file. */
00105   char *contents;               /* The contents of this particular file. */
00106   long filesize;                /* The number of bytes this file expands to. */
00107   char **subfiles;              /* If non-null, the list of subfiles. */
00108   TAG **tags;                   /* If non-null, the indirect tags table. */
00109   int tags_slots;               /* Number of slots allocated for TAGS. */
00110   int flags;                    /* Various flags.  Mimics of N_* flags. */
00111 } FILE_BUFFER;
00112 
00113 /* Externally visible functions.  */
00114 
00115 /* Array of FILE_BUFFER * which represents the currently loaded info files. */
00116 extern FILE_BUFFER **info_loaded_files;
00117 
00118 /* The number of slots currently allocated to INFO_LOADED_FILES. */
00119 extern int info_loaded_files_slots;
00120 
00121 /* Locate the file named by FILENAME, and return the information structure
00122    describing this file.  The file may appear in our list of loaded files
00123    already, or it may not.  If it does not already appear, find the file,
00124    and add it to the list of loaded files.  If the file cannot be found,
00125    return a NULL FILE_BUFFER *. */
00126 extern FILE_BUFFER *info_find_file (char *filename);
00127 
00128 /* Force load the file named FILENAME, and return the information structure
00129    describing this file.  Even if the file was already loaded, this loads
00130    a new buffer, rebuilds tags and nodes, and returns a new FILE_BUFFER *. */
00131 extern FILE_BUFFER *info_load_file (char *filename);
00132 
00133 /* Return a pointer to a NODE structure for the Info node (FILENAME)NODENAME.
00134    FILENAME can be passed as NULL, in which case the filename of "dir" is used.
00135    NODENAME can be passed as NULL, in which case the nodename of "Top" is used.
00136    If the node cannot be found, return a NULL pointer. */
00137 extern NODE *info_get_node (char *filename, char *nodename);
00138 
00139 /* Return a pointer to a NODE structure for the Info node NODENAME in
00140    FILE_BUFFER.  NODENAME can be passed as NULL, in which case the
00141    nodename of "Top" is used.  If the node cannot be found, return a
00142    NULL pointer. */
00143 extern NODE *info_get_node_of_file_buffer (char *nodename,
00144     FILE_BUFFER *file_buffer);
00145 
00146 /* Grovel FILE_BUFFER->contents finding tags and nodes, and filling in the
00147    various slots.  This can also be used to rebuild a tag or node table. */
00148 extern void build_tags_and_nodes (FILE_BUFFER *file_buffer);
00149 
00150 /* When non-zero, this is a string describing the most recent file error. */
00151 extern char *info_recent_file_error;
00152 
00153 /* Create a new, empty file buffer. */
00154 extern FILE_BUFFER *make_file_buffer (void);
00155 
00156 #endif /* not NODES_H */