Use of stat instead of d_type from dirent struct.
[ohcount] / src / parser.c
1 // parser.c written by Mitchell Foral. mitchell<att>caladbolg.net.
2 // See COPYING for license information.
3
4 #include <string.h>
5
6 #include "sourcefile.h"
7 #include "log.h"
8 #include "hash/parser_hash.h"
9
10 int ohcount_parse(SourceFile *sourcefile, int count,
11                   void (*callback) (const char *, const char *, int, int,
12                                     void *),
13                   void *userdata) {
14   const char *language = ohcount_sourcefile_get_language(sourcefile);
15   if (language) {
16     struct ParserMap *rp =
17       ohcount_hash_parser_from_language(language, strlen(language));
18     if (rp) {
19       char *buffer = ohcount_sourcefile_get_contents(sourcefile);
20       int buffer_len = ohcount_sourcefile_get_contents_size(sourcefile);
21       if (callback)
22         rp->parser(buffer, buffer_len, count, callback, userdata);
23       return 1;
24     }
25   }
26
27   return 0;
28 }