home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / id-utils-3.2-src.tgz / tar.out / fsf / id-utils / libidu / idfile.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  8KB  |  225 lines

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