| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 35 |
|
| 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) |
| 46 |
#define IDH_FOLLOW_SL (1<<1) |
| 47 |
#define IDH_COMMENTS (1<<2) |
| 48 |
#define IDH_LOCALS (1<<3) |
| 49 |
#define IDH_DECL_DEFN_USE (1<<4) |
| 50 |
#define IDH_L_R_VALUE (1<<5) |
| 51 |
#define IDH_CALL_ER_EE (1<<6) |
| 52 |
unsigned long idh_file_links; |
| 53 |
unsigned long idh_files; |
| 54 |
unsigned long idh_tokens; |
| 55 |
|
| 56 |
unsigned long idh_buf_size; |
| 57 |
unsigned long idh_vec_size; |
| 58 |
|
| 59 |
long idh_tokens_offset; |
| 60 |
long idh_flinks_offset; |
| 61 |
long idh_end_offset; |
| 62 |
unsigned short idh_max_link; |
| 63 |
unsigned short idh_max_path; |
| 64 |
|
| 65 |
|
| 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; |
| 73 |
struct obstack idh_dev_ino_obstack; |
| 74 |
#endif |
| 75 |
FILE *idh_FILE; |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
#define IO_TYPE_INT 0 |
| 81 |
#define IO_TYPE_STR 1 |
| 82 |
#define IO_TYPE_FIX 2 |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 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) |
| 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 |
|
| 116 |
|
| 117 |
struct member_file |
| 118 |
{ |
| 119 |
struct file_link *mf_link; |
| 120 |
struct lang_args const *mf_lang_args; |
| 121 |
long mf_index; |
| 122 |
}; |
| 123 |
|
| 124 |
#if HAVE_LINK |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 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 |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 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 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 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 |