(root)/
texinfo-7.1/
info/
nodes.h
       1  /* nodes.h -- How we represent nodes internally.
       2  
       3     Copyright 1993-2023 Free Software Foundation, Inc.
       4  
       5     This program is free software: you can redistribute it and/or modify
       6     it under the terms of the GNU General Public License as published by
       7     the Free Software Foundation, either version 3 of the License, or
       8     (at your option) any later version.
       9  
      10     This program is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU General Public License for more details.
      14  
      15     You should have received a copy of the GNU General Public License
      16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17  
      18     Originally written by Brian Fox. */
      19  
      20  #ifndef NODES_H
      21  #define NODES_H
      22  
      23  #include "info.h"
      24  
      25  /* Structure which describes a node reference, such as a menu entry or
      26     cross reference. */
      27  typedef struct {
      28    char *label;          /* User Label. */
      29    char *filename;       /* File where this node can be found. */
      30    char *nodename;       /* Name of the node. */
      31    int start, end;       /* Offsets within the containing node of LABEL. */
      32    long line_number;     /* Specific line number a menu item points to.  */
      33    int type;             /* Whether reference is a xref or a menu item */
      34  } REFERENCE;
      35  
      36  /* Possible values of REFERENCE.type */
      37  #define REFERENCE_XREF 0
      38  #define REFERENCE_MENU_ITEM 1
      39  
      40  typedef struct {
      41    char *fullpath;               /* Non-null is the logical file name. */
      42    char *subfile;                /* File containing node for split files. */
      43    char *nodename;               /* The name of this node. */
      44    char *contents;               /* Characters appearing in this node. */
      45    long nodelen;                 /* The length of the CONTENTS member. */
      46    long display_pos;             /* Where to display at, if nonzero.  */
      47    long body_start;              /* Offset of the actual node body */
      48    int flags;                    /* See immediately below. */
      49    REFERENCE **references;       /* Cross-references or menu items in node.
      50                                     Null-terminated.  references == 0 implies 
      51                                     uninitialized, not empty */
      52    char *up, *prev, *next;       /* Names of nearby nodes. */
      53    int active_menu;              /* Used for subnodes search. */
      54  } NODE;
      55  
      56  /* Values for NODE.flags or FILE_BUFFER.flags. */
      57  #define N_HasTagsTable 0x01     /* This node was found through a tags table. */
      58  #define N_TagsIndirect 0x02     /* The tags table was an indirect one. */
      59  #define N_UpdateTags   0x04     /* The tags table is out of date. */
      60  #define N_IsCompressed 0x08     /* The file is compressed on disk. */
      61  #define N_IsInternal   0x10     /* This node was made by Info. */
      62  #define N_CannotGC     0x20     /* File buffer cannot be gc'ed. */
      63  #define N_IsManPage    0x40     /* This node is a manpage. */
      64  #define N_WasRewritten 0x100    /* NODE->contents can be passed to free(). */ 
      65  #define N_IsIndex      0x200    /* An index node. */
      66  #define N_IsDir        0x400    /* A dir node. */
      67  #define N_Subfile      0x800    /* File buffer is a subfile of a split file. */
      68  #define N_Gone         0x1000   /* File is no more. */
      69  #define N_Simple       0x2000   /* Data about cross-references is missing. */
      70  #define N_SeenBySearch 0x4000   /* Node has already been seen in a search. */
      71  
      72  /* String constants. */
      73  #define INFO_FILE_LABEL                 "File:"
      74  #define INFO_REF_LABEL                  "Ref:"
      75  #define INFO_NODE_LABEL                 "Node:"
      76  #define INFO_PREV_LABEL                 "Prev:"
      77  #define INFO_ALTPREV_LABEL              "Previous:"
      78  #define INFO_NEXT_LABEL                 "Next:"
      79  #define INFO_UP_LABEL                   "Up:"
      80  #define INFO_MENU_LABEL                 "\n* Menu:"
      81  #define INFO_MENU_ENTRY_LABEL           "\n* "
      82  #define INFO_XREF_LABEL                 "*Note"
      83  #define TAGS_TABLE_END_LABEL            "End Tag Table"
      84  #define TAGS_TABLE_BEG_LABEL            "Tag Table:"
      85  #define INDIRECT_TABLE_LABEL            "Indirect:"
      86  #define TAGS_TABLE_IS_INDIRECT_LABEL    "(Indirect)"
      87  #define LOCAL_VARIABLES_LABEL           "Local Variables"
      88  #define CHARACTER_ENCODING_LABEL        "coding:"
      89  
      90  /* Character constants. */
      91  #define INFO_COOKIE '\037'
      92  #define INFO_FF     '\014'
      93  #define INFO_TAGSEP '\177'
      94  
      95  /* For each logical file that we have loaded, we keep a list of
      96     the names of the nodes that are found in that file.  A pointer to
      97     a node in an info file is called a "tag".  For split files, the
      98     tag pointer is "indirect"; that is, the pointer also contains the
      99     name of the split file where the node can be found.  For non-split
     100     files, the filename member simply contains the name of the
     101     current file. */
     102  typedef struct {
     103    char *filename;               /* The file where this node can be found. */
     104    char *nodename;               /* The node pointed to by this tag. */
     105    long nodestart;               /* The value read from the tag table. */
     106    long nodestart_adjusted;      /* Where the node or anchor actually is. */
     107    int flags;                    /* Same as NODE.flags. */
     108    NODE cache;                   /* Saved information about pointed-to node. */
     109  } TAG;
     110  
     111  /* The following structure is used to remember information about the contents
     112     of Info files that we have loaded at least once before.  The FINFO member
     113     is present so that we can reload the file if it has been modified since
     114     last being loaded.  All of the arrays appearing within this structure
     115     are NULL terminated. */
     116  typedef struct {
     117    char *filename;               /* The filename used to find this file. */
     118    char *fullpath;               /* The full pathname of this info file. */
     119    struct stat finfo;            /* Information about this file. */
     120    char *contents;               /* The contents of this particular file. */
     121    size_t filesize;              /* The number of bytes this file expands to. */
     122    char **subfiles;              /* If non-null, the list of subfiles. */
     123    TAG **tags;                   /* If non-null, the tags table. */
     124    size_t tags_slots;            /* Number of slots allocated for TAGS. */
     125    int flags;                    /* Various flags.  Mimics of N_* flags. */
     126    char *encoding;               /* Name of character encoding of file. */
     127  } FILE_BUFFER;
     128  
     129  /* Array of FILE_BUFFER * which represents the currently loaded info files. */
     130  extern FILE_BUFFER **info_loaded_files;
     131  extern size_t info_loaded_files_index;
     132  extern size_t info_loaded_files_slots;
     133  
     134  /* Locate the file named by FILENAME, and return the information structure
     135     describing this file.  The file may appear in our list of loaded files
     136     already, or it may not.  If it does not already appear, find the file,
     137     and add it to the list of loaded files.  If the file cannot be found,
     138     return a NULL FILE_BUFFER *. */
     139  FILE_BUFFER *info_find_file (char *filename);
     140  
     141  FILE_BUFFER *check_loaded_file (char *filename);
     142  
     143  FILE_BUFFER *info_find_subfile (char *filename);
     144  
     145  TAG *info_create_tag (void);
     146  
     147  /* Return a pointer to a new NODE structure. */
     148  NODE *info_create_node (void);
     149  
     150  /* Return a pointer to a NODE structure for the Info node (FILENAME)NODENAME.
     151     FILENAME can be passed as NULL, in which case the filename of "dir" is used.
     152     NODENAME can be passed as NULL, in which case the nodename of "Top" is used.
     153     
     154     If the node cannot be found, return a NULL pointer. */
     155  NODE *info_get_node (char *filename, char *nodename);
     156  
     157  NODE *info_get_node_with_defaults (char *filename, char *nodename,
     158                                            NODE *defaults);
     159  
     160  NODE *info_node_of_tag (FILE_BUFFER *fb, TAG **tag_ptr);
     161  NODE *info_node_of_tag_fast (FILE_BUFFER *fb, TAG **tag_ptr);
     162  
     163  /* Return a pointer to a NODE structure for the Info node NODENAME in
     164     FILE_BUFFER.  NODENAME can be passed as NULL, in which case the
     165     nodename of "Top" is used.  If the node cannot be found, return a
     166     NULL pointer. */
     167  NODE *info_get_node_of_file_buffer (FILE_BUFFER *file_buffer,
     168                                             char *nodename);
     169  
     170  /* Grovel FILE_BUFFER->contents finding tags and nodes, and filling in the
     171     various slots.  This can also be used to rebuild a tag or node table. */
     172  void build_tags_and_nodes (FILE_BUFFER *file_buffer);
     173  
     174  void free_history_node (NODE *n);
     175  
     176  /* When non-zero, this is a string describing the most recent file error. */
     177  extern char *info_recent_file_error;
     178  
     179  /* Create a new, empty file buffer. */
     180  FILE_BUFFER *make_file_buffer (void);
     181  
     182  /* Non-zero means don't try to be smart when searching for nodes.  */
     183  extern int strict_node_location_p;
     184  
     185  
     186  /* Found in dir.c */
     187  NODE *get_dir_node (void);
     188  REFERENCE *lookup_dir_entry (char *label, int sloppy);
     189  REFERENCE *dir_entry_of_infodir (char *label, char *searchdir);
     190  
     191  #endif /* not NODES_H */