Debian Codegraph @

libidu/idfile.h

raw symbols SCIP
1 /* idfile.h -- decls for ID file header and constituent file names
2 Copyright (C) 1986-2020 Free Software Foundation, Inc.
3 Written by Greg McGary <[email protected]>
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, or (at your option)
8 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
19 #ifndef _idfile_h_
20 #define _idfile_h_ 1
21
22 #include <config.h>
23 #include <sys/types.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "obstack.h"
27 #include "idu-hash.h"
28 #include "dynvec.h"
29 #include "tokflags.h"
30
31
32 /****************************************************************************/
33
34 /* The ID file header is the nexus of all ID file information. This
35 is an in-core structure, only some of which is read/written to disk. */
36
37 struct idhead
38 {
39 unsigned char idh_magic[2];
40 #define IDH_MAGIC_0 ('I'|0x80)
41 #define IDH_MAGIC_1 ('D'|0x80)
42 unsigned char idh_version;
43 #define IDH_VERSION 4
44 unsigned short idh_flags;
45 #define IDH_COUNTS (1<<0) /* include occurrence counts for each token */
46 #define IDH_FOLLOW_SL (1<<1) /* follow symlinks to directories */
47 #define IDH_COMMENTS (1<<2) /* include tokens found in comments */
48 #define IDH_LOCALS (1<<3) /* include names of formal params & local vars */
49 #define IDH_DECL_DEFN_USE (1<<4) /* include decl/defn/use info */
50 #define IDH_L_R_VALUE (1<<5) /* include lvalue/rvalue info */
51 #define IDH_CALL_ER_EE (1<<6) /* include caller/callee relationship info */
52 unsigned long idh_file_links; /* total # of file links */
53 unsigned long idh_files; /* total # of constituent source files */
54 unsigned long idh_tokens; /* total # of constituent tokens */
55 /* idh_*_size: max buffer-sizes for ID file reading programs */
56 unsigned long idh_buf_size; /* # of bytes in longest entry */
57 unsigned long idh_vec_size; /* # of hits in longest entry */
58 /* idh_*_offset: ID file offsets for start of various sections */
59 long idh_tokens_offset; /* constituent tokens section */
60 long idh_flinks_offset; /* constituent file & directory names section */
61 long idh_end_offset; /* end of tokens section */
62 unsigned short idh_max_link; /* longest file name component */
63 unsigned short idh_max_path; /* largest # of file name components */
64
65 /* The following are run-time variables and are not stored on disk */
66 char const *idh_file_name;
67 struct hash_table idh_member_file_table;
68 struct hash_table idh_file_link_table;
69 struct obstack idh_member_file_obstack;
70 struct obstack idh_file_link_obstack;
71 #if HAVE_LINK
72 struct hash_table idh_dev_ino_table; /* for detecting file name aliases */
73 struct obstack idh_dev_ino_obstack;
74 #endif
75 FILE *idh_FILE;
76 };
77
78 /* idhead input/output definitions */
79
80 #define IO_TYPE_INT 0 /* integer */
81 #define IO_TYPE_STR 1 /* NUL terminated string */
82 #define IO_TYPE_FIX 2 /* fix-sized */
83
84
85 /****************************************************************************/
86
87 /* A file_link represents a single component (file or directory) in a
88 file name. It has a name, a parent file_link and some flags. */
89
90 struct file_link
91 {
92 union {
93 struct file_link *u_parent;
94 #define fl_parent fl_u.u_parent
95 unsigned long u_index;
96 #define fl_index fl_u.u_index
97 #define FL_PARENT_INDEX_BYTES 3
98 #define IS_ROOT_FILE_LINK(flink) ((flink)->fl_parent == (flink))
99 } fl_u;
100 unsigned char fl_flags;
101 #define FL_CMD_LINE_ARG (1<<0)
102 #define FL_USED (1<<1)
103 #define FL_MEMBER (1<<2) /* has a corresponding member_file entry */
104 #define FL_SCAN_ME (1<<3)
105 #define FL_SYM_LINK (1<<4)
106 #define FL_TYPE_MASK (FL_TYPE_DIR|FL_TYPE_FILE)
107 # define FL_TYPE_DIR (1<<5)
108 # define FL_IS_DIR(_f_) (((_f_) & FL_TYPE_MASK) == FL_TYPE_DIR)
109 # define FL_TYPE_FILE (1<<6)
110 # define FL_IS_FILE(_f_) (((_f_) & FL_TYPE_MASK) == FL_TYPE_FILE)
111 #define FL_PRUNE (1<<7)
112 char fl_name[1];
113 };
114
115 /* A member_file represents a source file that is treated by mkid. */
116
117 struct member_file
118 {
119 struct file_link *mf_link;
120 struct lang_args const *mf_lang_args;
121 long mf_index; /* order in ID file */
122 };
123
124 #if HAVE_LINK
125
126 /* On systems that support multiple names for a single file (via hard
127 and/or soft links), dev_ino records information needed to detect
128 such aliasing. */
129
130 struct dev_ino
131 {
132 dev_t di_dev;
133 ino_t di_ino;
134 struct file_link *di_link;
135 };
136
137 extern struct hash_table dev_ino_table;
138
139 #endif /* HAVE_LINK */
140
141
142 /******************************************************************************/
143 /* token flags (struct token is defined in scanners.h) */
144
145 #define token_string(buf) (buf)
146 extern unsigned int token_flags (char const *buf) _GL_ATTRIBUTE_PURE;
147 extern unsigned short token_count (char const *buf) _GL_ATTRIBUTE_PURE;
148 extern unsigned char const *token_hits_addr (char const *buf)
149 _GL_ATTRIBUTE_PURE;
150
151 #define MAYBE_RETURN_PREFIX_MATCH(arg, str, val) do { \
152 char const *_s_ = (str); \
153 if (strstr (_s_, (arg)) == _s_) \
154 return (val); \
155 } while (0)
156
157 enum separator_style
158 {
159 ss_bogus,
160 ss_contextual,
161 ss_braces,
162 ss_space,
163 ss_newline
164 };
165
166 #ifndef DEFAULT_SEPARATOR_STYLE
167 #define DEFAULT_SEPARATOR_STYLE ss_braces
168 #endif
169
170 typedef int (*io_func_t) (FILE *, void *, unsigned int, int);
171
172 extern struct file_link **read_id_file (char const *id_file_name, struct idhead *idhp);
173 extern struct file_link **maybe_read_id_file (char const *id_file_name, struct idhead *idhp);
174 extern int read_idhead (struct idhead *idhp);
175 extern int write_idhead (struct idhead *idhp);
176 extern int sizeof_idhead (void);
177 extern struct file_link *init_walker (struct idhead *idhp);
178 extern void init_idh_obstacks (struct idhead *idhp);
179 extern void init_idh_tables (struct idhead *idhp);
180
181 extern int io_write (FILE *output_FILE, void *addr, unsigned int size, int io_type);
182 extern int io_read (FILE *input_FILE, void *addr, unsigned int size, int io_type);
183 extern int io_idhead (FILE *fp, io_func_t iof, struct idhead *idhp);
184
185 extern struct file_link *get_current_dir_link (void);
186 extern struct file_link **deserialize_file_links (struct idhead *idhp);
187 extern void serialize_file_links (struct idhead *idhp);
188
189 extern void mark_member_file_links (struct idhead *idhp);
190 extern int member_file_qsort_compare (void const *x, void const *y)
191 _GL_ATTRIBUTE_PURE;
192 extern struct file_link *parse_file_name (char *file_name, struct file_link *relative_dir_link);
193 extern void print_filenames (struct file_link **flinkv, enum separator_style separator_style);
194 extern enum separator_style parse_separator_style (char const *arg);
195
196 extern void walk_flink (struct file_link *flink, struct dynvec *sub_dirs_vec);
197 extern int chdir_to_link (struct file_link* dir_link);
198 extern void prune_file_names (char *str, struct file_link *from_link);
199 extern void include_languages (char *lang_names);
200 extern void exclude_languages (char *lang_names);
201
202 extern char *absolute_file_name (char *buffer, struct file_link const *flink);
203 extern char *maybe_relative_file_name (char *buffer, struct file_link const *to_link, struct file_link const *from_link);
204 extern char const *locate_id_file_name (char const *arg);
205
206 extern int tree8_count_levels (unsigned int cardinality) _GL_ATTRIBUTE_CONST;
207 extern int gets_past_00 (char *tok, FILE *input_FILE);
208 extern int skip_past_00 (FILE *input_FILE);
209
210 extern int links_depth (struct file_link const *flink) _GL_ATTRIBUTE_PURE;
211
212 #if HAVE_LINK
213
214 extern struct member_file *find_member_file (struct file_link const *flink);
215
216 #endif
217
218 extern struct idhead idh;
219
220 extern int walker_verbose_flag;
221
222 extern off_t largest_member_file;
223 #define MAX_LARGEST_MEMBER_FILE (2*1024*1024-1)
224
225 #define DEFAULT_ID_FILE_NAME "ID"
226
227 /* Like stpncpy, but do ensure that the result is NUL-terminated,
228 and do not NUL-pad out to LEN. I.e., when strnlen (src, len) == len,
229 this function writes a NUL byte into dest[len]. Thus, the length
230 of the destination buffer must be at least LEN + 1.
231 The DEST and SRC buffers must not overlap. */
232 static inline char *
233 stzncpy (char *restrict dest, char const *restrict src, size_t len)
234 {
235 char const *src_end = src + len;
236 while (src < src_end && *src)
237 *dest++ = *src++;
238 *dest = 0;
239 return dest;
240 }
241
242 #endif /* not _idfile_h_ */