nodes.h revision 21495
1231858Sbz/* nodes.h -- How we represent nodes internally. */ 2231858Sbz 3231858Sbz/* This file is part of GNU Info, a program for reading online documentation 4231858Sbz stored in Info format. 5231858Sbz 6231858Sbz Copyright (C) 1993 Free Software Foundation, Inc. 7231858Sbz 8231858Sbz This program is free software; you can redistribute it and/or modify 9231858Sbz it under the terms of the GNU General Public License as published by 10231858Sbz the Free Software Foundation; either version 2, or (at your option) 11231858Sbz any later version. 12231858Sbz 13231858Sbz This program is distributed in the hope that it will be useful, 14231858Sbz but WITHOUT ANY WARRANTY; without even the implied warranty of 15231858Sbz MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16231858Sbz GNU General Public License for more details. 17231858Sbz 18231858Sbz You should have received a copy of the GNU General Public License 19231858Sbz along with this program; if not, write to the Free Software 20231858Sbz Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21231858Sbz 22231858Sbz Written by Brian Fox (bfox@ai.mit.edu). */ 23231858Sbz 24231858Sbz#if !defined (_NODES_H_) 25231858Sbz#define _NODES_H_ 26231858Sbz 27231858Sbz#include "general.h" 28231858Sbz 29231858Sbz/* **************************************************************** */ 30231858Sbz/* */ 31231858Sbz/* User Code Interface */ 32231858Sbz/* */ 33231858Sbz/* **************************************************************** */ 34231858Sbz 35231858Sbz/* Callers generally only want the node itself. This structure is used 36231858Sbz to pass node information around. None of the information in this 37231858Sbz structure should ever be directly freed. The structure itself can 38231858Sbz be passed to free (). Note that NODE->parent is non-null if this 39231858Sbz node's file is a subfile. In that case, NODE->parent is the logical 40231858Sbz name of the file containing this node. Both names are given as full 41231858Sbz paths, so you might have: node->filename = "/usr/gnu/info/emacs-1", 42231858Sbz with node->parent = "/usr/gnu/info/emacs". */ 43231858Sbztypedef struct { 44231858Sbz char *filename; /* The physical file containing this node. */ 45231858Sbz char *parent; /* Non-null is the logical file name. */ 46231858Sbz char *nodename; /* The name of this node. */ 47231858Sbz char *contents; /* Characters appearing in this node. */ 48231858Sbz long nodelen; /* The length of the CONTENTS member. */ 49231858Sbz int flags; /* See immediately below. */ 50231858Sbz} NODE; 51231858Sbz 52231858Sbz/* Defines that can appear in NODE->flags. All informative. */ 53231858Sbz#define N_HasTagsTable 0x01 /* This node was found through a tags table. */ 54231858Sbz#define N_TagsIndirect 0x02 /* The tags table was an indirect one. */ 55231858Sbz#define N_UpdateTags 0x04 /* The tags table is out of date. */ 56231858Sbz#define N_IsCompressed 0x08 /* The file is compressed on disk. */ 57231858Sbz#define N_IsInternal 0x10 /* This node was made by Info. */ 58231858Sbz#define N_CannotGC 0x20 /* File buffer cannot be gc'ed. */ 59231858Sbz#define N_IsManPage 0x40 /* This node is a Un*x manpage. */ 60231858Sbz 61231858Sbz/* **************************************************************** */ 62231858Sbz/* */ 63231858Sbz/* Internal Data Structures */ 64231858Sbz/* */ 65231858Sbz/* **************************************************************** */ 66231858Sbz 67231858Sbz/* Some defines describing details about Info file contents. */ 68231858Sbz 69231858Sbz/* String Constants. */ 70231858Sbz#define INFO_FILE_LABEL "File:" 71231858Sbz#define INFO_NODE_LABEL "Node:" 72231858Sbz#define INFO_PREV_LABEL "Prev:" 73231858Sbz#define INFO_ALTPREV_LABEL "Previous:" 74231858Sbz#define INFO_NEXT_LABEL "Next:" 75231858Sbz#define INFO_UP_LABEL "Up:" 76231858Sbz#define INFO_MENU_LABEL "\n* Menu:" 77231858Sbz#define INFO_MENU_ENTRY_LABEL "\n* " 78231858Sbz#define INFO_XREF_LABEL "*Note" 79231858Sbz#define TAGS_TABLE_END_LABEL "\nEnd Tag Table" 80231858Sbz#define TAGS_TABLE_BEG_LABEL "Tag Table:\n" 81231858Sbz#define INDIRECT_TAGS_TABLE_LABEL "Indirect:\n" 82231858Sbz#define TAGS_TABLE_IS_INDIRECT_LABEL "(Indirect)" 83231858Sbz 84231858Sbz/* Character Constants. */ 85231858Sbz#define INFO_COOKIE '\037' 86231858Sbz#define INFO_FF '\014' 87231858Sbz#define INFO_TAGSEP '\177' 88231858Sbz 89231858Sbz/* For each logical file that we have loaded, we keep a list of the names 90231858Sbz of the nodes that are found in that file. A pointer to a node in an 91231858Sbz info file is called a "tag". For split files, the tag pointer is 92231858Sbz "indirect"; that is, the pointer also contains the name of the split 93231858Sbz file where the node can be found. For non-split files, the filename 94231858Sbz member in the structure below simply contains the name of the current 95231858Sbz file. The following structure describes a single node within a file. */ 96231858Sbztypedef struct { 97231858Sbz char *filename; /* The file where this node can be found. */ 98231858Sbz char *nodename; /* The node pointed to by this tag. */ 99231858Sbz long nodestart; /* The offset of the start of this node. */ 100231858Sbz long nodelen; /* The length of this node. */ 101231858Sbz} TAG; 102231858Sbz 103231858Sbz/* The following structure is used to remember information about the contents 104231858Sbz of Info files that we have loaded at least once before. The FINFO member 105231858Sbz is present so that we can reload the file if it has been modified since 106231858Sbz last being loaded. All of the arrays appearing within this structure 107231858Sbz are NULL terminated, and each array which can change size has a 108231858Sbz corresponding SLOTS member which says how many slots have been allocated 109231858Sbz (with malloc ()) for this array. */ 110231858Sbztypedef struct { 111231858Sbz char *filename; /* The filename used to find this file. */ 112231858Sbz char *fullpath; /* The full pathname of this info file. */ 113231858Sbz struct stat finfo; /* Information about this file. */ 114231858Sbz char *contents; /* The contents of this particular file. */ 115231858Sbz long filesize; /* The number of bytes this file expands to. */ 116231858Sbz char **subfiles; /* If non-null, the list of subfiles. */ 117231858Sbz TAG **tags; /* If non-null, the indirect tags table. */ 118231858Sbz int tags_slots; /* Number of slots allocated for TAGS. */ 119231858Sbz int flags; /* Various flags. Mimics of N_* flags. */ 120231858Sbz} FILE_BUFFER; 121231858Sbz 122231858Sbz/* **************************************************************** */ 123231858Sbz/* */ 124231858Sbz/* Externally Visible Functions */ 125231858Sbz/* */ 126231858Sbz/* **************************************************************** */ 127231858Sbz 128231858Sbz/* Array of FILE_BUFFER * which represents the currently loaded info files. */ 129231858Sbzextern FILE_BUFFER **info_loaded_files; 130231858Sbz 131231858Sbz/* The number of slots currently allocated to INFO_LOADED_FILES. */ 132231858Sbzextern int info_loaded_files_slots; 133231858Sbz 134231858Sbz/* Locate the file named by FILENAME, and return the information structure 135231858Sbz describing this file. The file may appear in our list of loaded files 136231858Sbz already, or it may not. If it does not already appear, find the file, 137231858Sbz and add it to the list of loaded files. If the file cannot be found, 138231858Sbz return a NULL FILE_BUFFER *. */ 139231858Sbzextern FILE_BUFFER *info_find_file (); 140231858Sbz 141231858Sbz/* Force load the file named FILENAME, and return the information structure 142231858Sbz describing this file. Even if the file was already loaded, this loads 143231858Sbz a new buffer, rebuilds tags and nodes, and returns a new FILE_BUFFER *. */ 144231858Sbzextern FILE_BUFFER *info_load_file (); 145231858Sbz 146231858Sbz/* Return a pointer to a NODE structure for the Info node (FILENAME)NODENAME. 147231858Sbz FILENAME can be passed as NULL, in which case the filename of "dir" is used. 148231858Sbz NODENAME can be passed as NULL, in which case the nodename of "Top" is used. 149231858Sbz If the node cannot be found, return a NULL pointer. */ 150231858Sbzextern NODE *info_get_node (); 151231858Sbz 152231858Sbz/* Return a pointer to a NODE structure for the Info node NODENAME in 153231858Sbz FILE_BUFFER. NODENAME can be passed as NULL, in which case the 154231858Sbz nodename of "Top" is used. If the node cannot be found, return a 155231858Sbz NULL pointer. */ 156231858Sbzextern NODE *info_get_node_of_file_buffer (); 157231858Sbz 158231858Sbz/* Grovel FILE_BUFFER->contents finding tags and nodes, and filling in the 159231858Sbz various slots. This can also be used to rebuild a tag or node table. */ 160231858Sbzextern void build_tags_and_nodes (); 161231858Sbz 162231858Sbz/* When non-zero, this is a string describing the most recent file error. */ 163231858Sbzextern char *info_recent_file_error; 164231858Sbz 165231858Sbz/* Create a new, empty file buffer. */ 166231858Sbzextern FILE_BUFFER *make_file_buffer (); 167231858Sbz 168231858Sbz#endif /* !_NODES_H_ */ 169231858Sbz