[CHANGE] Add support for FreeBSD (submitted by eg)
[ohcount] / src / structs.h
1 // structs.h written by Mitchell Foral. mitchell<att>caladbolg.net.
2 // See COPYING for license information.
3
4 #ifndef OHCOUNT_STRUCTS_H
5 #define OHCOUNT_STRUCTS_H
6
7 #include <pcre.h>
8
9 /**
10  * @struct License
11  * @brief Holds a license and its associated details and patterns.
12  */
13 typedef struct {
14   /** The ID name of the license. Should be in defined in licenses.h. */
15   const char *name;
16
17   /** The string URL to the license's website. */
18   const char *url;
19
20   /** A nice displayable name for the license. */
21   const char *nice_name;
22
23   /** A PCRE regular expression for text that matches this license. */
24   const char *re;
25
26   /** PCRE flags for re. (Typically PCRE_CASELESS or PCRE_MULTILINE). */
27   int re_flags;
28
29   /**
30    * A PCRE regular expression for text that matches re, but should not match
31    * this re in order to match this license.
32    */
33   const char *exclude_re;
34
35   /** PCRE flags for exclude_re. */
36   int exclude_re_flags;
37
38   /** The PCRE object for re. (This field is set automatically.) */
39   pcre *regexp;
40
41   /** The PCRE object for exclude_re. (This field is set automatically.) */
42   pcre *exclude_regexp;
43
44 } License;
45
46 /**
47  * @struct LicenseListItem
48  * @brief Holds a list of Licenses in a linked list.
49  */
50 typedef struct LicenseListItem {
51   /** The particular License in this linked list item. */
52   License *lic;
53
54   /** The next LicenseList in the linked list. */
55   struct LicenseListItem *next;
56
57   /**
58    * The head of the linked list this LicenseList item is part of.
59    * This field is only used for the list head.
60    */
61   struct LicenseListItem *head;
62
63   /**
64    * The head of the linked list this LicenseList item is part of.
65    * This field is only used for the list head.
66    */
67   struct LicenseListItem *tail;
68
69 } LicenseList;
70
71 /**
72  * @struct Loc
73  * @brief Tracks total lines of code, comments, and blanks for a single
74  *   language.
75  */
76 typedef struct {
77   /** The language associated with this Loc. */
78   const char *language;
79
80   /** The number of lines of code for this Loc. */
81   int code;
82
83   /** The number of lines of comments for this Loc. */
84   int comments;
85
86   /** The number of blank lines for this Loc. */
87   int blanks;
88
89   /** The number of parsed files associated with this Loc. */
90   int filecount;
91
92 } Loc;
93
94 /**
95  * @struct LocListItem
96  * @brief Tracks total lines of code, comments, and blanks for multiple
97  *   languages using a linked list.
98  */
99 typedef struct LocListItem {
100   /** The particular Loc in this linked list item. */
101   Loc *loc;
102
103   /** The next LocList item in the linked list. */
104   struct LocListItem *next;
105
106   /**
107    * The head of the linked list this LocList item is part of.
108    * This field is only used for the list head.
109    */
110   struct LocListItem *head;
111
112   /**
113    * The tail of the linked list this LocList item is part of.
114    * This field is only used for the list head.
115    */
116   struct LocListItem *tail;
117
118 } LocList;
119
120 /**
121  * @struct LocDelta
122  * @brief Tracks changes in lines of code, comments, and blank lines for a
123  *   single language.
124  */
125 typedef struct {
126   /** The language associated with this LocDelta. */
127   const char *language;
128
129   /** The number of lines of code added in this LocDelta. */
130   int code_added;
131
132   /** The number of lines of code removed in this LocDelta. */
133   int code_removed;
134
135   /** The number of lines of comments added in this LocDelta. */
136   int comments_added;
137
138   /** The number of lines of comments removed in this LocDelta. */
139   int comments_removed;
140
141   /** The number of blank lines added in this LocDelta. */
142   int blanks_added;
143
144   /** The number of blank lines removed in this LocDelta. */
145   int blanks_removed;
146
147 } LocDelta;
148
149 /**
150  * @struct LocDeltaListItem
151  * @brief Tracks changes in lines of code, comments, and blank lines for
152  *   multiple languages using a linked list.
153  */
154 typedef struct LocDeltaListItem {
155   /** The particular LocDelta in this linked list item. */
156   LocDelta *delta;
157
158   /** The next LocDeltaList item in the linked list. */
159   struct LocDeltaListItem *next;
160
161   /**
162    * The head of the linked list this item is part of.
163    * This field is only used for the list head.
164    */
165   struct LocDeltaListItem *head;
166
167   /**
168    * The tail of the linked list this item is part of.
169    * This field is only used for the list head.
170    */
171   struct LocDeltaListItem *tail;
172
173 } LocDeltaList;
174
175 /**
176  * @struct ParsedLanguage
177  * @brief Represents a single language parsed from a SourceFile.
178  */
179 typedef struct {
180   /** The parsed language. */
181   const char *name;
182
183   /** The size of the code and comments buffers. */
184   int buffer_size;
185
186   /** Buffer containing the code parsed out for this language. */
187   char *code;
188
189   /** Used for writing parsed code to the code buffer. */
190   char *code_p;
191
192   /** Number of lines of code for this language. */
193   int code_count;
194
195   /** Buffer containing the comments parsed out for this language. */
196   char *comments;
197
198   /** Used for writing parsed comments to the comment buffer. */
199   char *comments_p;
200
201   /** Number of lines of comments for this language. */
202   int comments_count;
203
204   /** Number of blank lines for this language. */
205   int blanks_count;
206
207 } ParsedLanguage;
208
209 /**
210  * @struct ParsedLanguageListItem
211  * @brief Holds a set of ParsedLanguages in a linked list.
212  */
213 typedef struct ParsedLanguageListItem {
214   /** The particular ParsedLanguage in this linked list item. */
215   ParsedLanguage *pl;
216
217   /** The next ParsedLanguageList item in the linked list. */
218   struct ParsedLanguageListItem *next;
219
220   /**
221    * The head of the linked list this ParsedLanguageList item is part of.
222    * This field is only used for the list head.
223    */
224   struct ParsedLanguageListItem *head;
225
226   /**
227    * The tail of the linked list this ParsedLanguageList item is part of.
228    * This field is only used for the list head.
229    */
230   struct ParsedLanguageListItem *tail;
231
232 } ParsedLanguageList;
233
234 /**
235  * @struct SourceFile
236  * @brief Represents a single source code file.
237  */
238 typedef struct {
239   /** The entire path to the file. */
240   char *filepath;
241
242   /**
243     The last character address considered to be part of the directory path in
244     filepath. This is an address in memory, not a length relative to filepath.
245   */
246   int dirpath;
247
248   /** The filepath's filename. */
249   char *filename;
250
251   /** The filepath's file extension. */
252   char *ext;
253
254   /**
255    * If filepath does not represent the real location of the file on disk, this
256    * field does.
257    */
258   char *diskpath;
259
260   // The following fields should not be accessed directly. Their accessor
261   // functions should be used instead as labeled.
262
263   /**
264    * The contents of the file.
265    * Do not use this field. Use ohcount_sourcefile_get_contents() instead.
266    */
267   char *contents;
268
269   /**
270    * The size of the file's contents in bytes.
271    * Do not use this field. Use ohcount_sourcefile_get_contents_size() instead.
272    */
273   int size;
274
275   /**
276    * The file's detected source code language.
277    * Do not use this field. Use ohcount_sourcefile_get_language() instead.
278    */
279   const char *language;
280
281   /**
282    * Flag used internally for keeping track of whether or not
283    * ohcount_sourcefile_get_language() has been called for this file.
284    */
285   int language_detected;
286
287   /**
288    * A ParsedLanguageList resulting from parsing the file.
289    * Do not use this field. Use ohcount_sourcefile_get_parsed_language_list()
290    * instead.
291    */
292   ParsedLanguageList *parsed_language_list;
293
294   /**
295    * A LicenseList of licenses detected.
296    * Do not use this field. Use ohcount_sourcefile_get_license_list() instead.
297    */
298   LicenseList *license_list;
299
300   /**
301    * A LocList of all lines of code in each language in the file.
302    * Do not use this field. Use ohcount_sourcefile_get_loc_list() instead.
303    */
304   LocList *loc_list;
305
306   /**
307    * A string array of all filenames in this file's directory.
308    * Do not use this field. Use ohcount_sourcefile_get_filenames() instead.
309    */
310   char **filenames;
311
312 } SourceFile;
313
314 /**
315  * @struct SourceFileListItem
316  * @brief Contains a set of SourceFiles.
317  */
318 typedef struct SourceFileListItem {
319   /** The particular SourceFile in this linked list item. */
320   SourceFile *sf;
321
322   /** The next SourceFileList item in the linked list. */
323   struct SourceFileListItem *next;
324
325   /**
326    * The head of the linked list this SourceFileList item is part of.
327    * This field is only used for the list head.
328    */
329   struct SourceFileListItem *head;
330
331   /**
332    * The tail of the linked list this SourceFileList item is part of.
333    * This field is only used for the list head.
334    */
335   struct SourceFileListItem *tail;
336
337 } SourceFileList;
338
339 #endif