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@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". */
39typedef 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.  */
60
61/* String constants. */
62#define INFO_FILE_LABEL                 "File:"
63#define INFO_REF_LABEL                  "Ref:"
64#define INFO_NODE_LABEL                 "Node:"
65#define INFO_PREV_LABEL                 "Prev:"
66#define INFO_ALTPREV_LABEL              "Previous:"
67#define INFO_NEXT_LABEL                 "Next:"
68#define INFO_UP_LABEL                   "Up:"
69#define INFO_MENU_LABEL                 "\n* Menu:"
70#define INFO_MENU_ENTRY_LABEL           "\n* "
71#define INFO_XREF_LABEL                 "*Note"
72#define TAGS_TABLE_END_LABEL            "\nEnd Tag Table"
73#define TAGS_TABLE_BEG_LABEL            "Tag Table:\n"
74#define INDIRECT_TAGS_TABLE_LABEL       "Indirect:\n"
75#define TAGS_TABLE_IS_INDIRECT_LABEL    "(Indirect)"
76
77/* Character constants. */
78#define INFO_COOKIE '\037'
79#define INFO_FF     '\014'
80#define INFO_TAGSEP '\177'
81
82/* For each logical file that we have loaded, we keep a list of the names
83   of the nodes that are found in that file.  A pointer to a node in an
84   info file is called a "tag".  For split files, the tag pointer is
85   "indirect"; that is, the pointer also contains the name of the split
86   file where the node can be found.  For non-split files, the filename
87   member in the structure below simply contains the name of the current
88   file.  The following structure describes a single node within a file. */
89typedef struct {
90  char *filename;               /* The file where this node can be found. */
91  char *nodename;               /* The node pointed to by this tag. */
92  long nodestart;               /* The offset of the start of this node. */
93  long nodelen;                 /* The length of this node. */
94} TAG;
95
96/* The following structure is used to remember information about the contents
97   of Info files that we have loaded at least once before.  The FINFO member
98   is present so that we can reload the file if it has been modified since
99   last being loaded.  All of the arrays appearing within this structure
100   are NULL terminated, and each array which can change size has a
101   corresponding SLOTS member which says how many slots have been allocated
102   (with malloc ()) for this array. */
103typedef struct {
104  char *filename;               /* The filename used to find this file. */
105  char *fullpath;               /* The full pathname of this info file. */
106  struct stat finfo;            /* Information about this file. */
107  char *contents;               /* The contents of this particular file. */
108  long filesize;                /* The number of bytes this file expands to. */
109  char **subfiles;              /* If non-null, the list of subfiles. */
110  TAG **tags;                   /* If non-null, the indirect tags table. */
111  int tags_slots;               /* Number of slots allocated for TAGS. */
112  int flags;                    /* Various flags.  Mimics of N_* flags. */
113} FILE_BUFFER;
114
115/* Externally visible functions.  */
116
117/* Array of FILE_BUFFER * which represents the currently loaded info files. */
118extern FILE_BUFFER **info_loaded_files;
119
120/* The number of slots currently allocated to INFO_LOADED_FILES. */
121extern int info_loaded_files_slots;
122
123/* Locate the file named by FILENAME, and return the information structure
124   describing this file.  The file may appear in our list of loaded files
125   already, or it may not.  If it does not already appear, find the file,
126   and add it to the list of loaded files.  If the file cannot be found,
127   return a NULL FILE_BUFFER *. */
128extern FILE_BUFFER *info_find_file (char *filename);
129
130/* Force load the file named FILENAME, and return the information structure
131   describing this file.  Even if the file was already loaded, this loads
132   a new buffer, rebuilds tags and nodes, and returns a new FILE_BUFFER *. */
133extern FILE_BUFFER *info_load_file (char *filename);
134
135/* Return a pointer to a NODE structure for the Info node (FILENAME)NODENAME.
136   FILENAME can be passed as NULL, in which case the filename of "dir" is used.
137   NODENAME can be passed as NULL, in which case the nodename of "Top" is used.
138   If the node cannot be found, return a NULL pointer. */
139extern NODE *info_get_node (char *filename, char *nodename);
140
141/* Return a pointer to a NODE structure for the Info node NODENAME in
142   FILE_BUFFER.  NODENAME can be passed as NULL, in which case the
143   nodename of "Top" is used.  If the node cannot be found, return a
144   NULL pointer. */
145extern NODE *info_get_node_of_file_buffer (char *nodename,
146    FILE_BUFFER *file_buffer);
147
148/* Grovel FILE_BUFFER->contents finding tags and nodes, and filling in the
149   various slots.  This can also be used to rebuild a tag or node table. */
150extern void build_tags_and_nodes (FILE_BUFFER *file_buffer);
151
152/* When non-zero, this is a string describing the most recent file error. */
153extern char *info_recent_file_error;
154
155/* Create a new, empty file buffer. */
156extern FILE_BUFFER *make_file_buffer (void);
157
158#endif /* not NODES_H */
159