Removed gestalt options from C ohcount (use ruby/gestalt.rb).
[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 "hash/parser_hash.h"
8
9 int ohcount_parse(SourceFile *sourcefile, int count,
10                   void (*callback) (const char *, const char *, int, int,
11                                     void *),
12                   void *userdata) {
13   const char *language = ohcount_sourcefile_get_language(sourcefile);
14   if (language) {
15     struct ParserMap *rp =
16       ohcount_hash_parser_from_language(language, strlen(language));
17     if (rp) {
18       char *buffer = ohcount_sourcefile_get_contents(sourcefile);
19       int buffer_len = ohcount_sourcefile_get_contents_size(sourcefile);
20       if (callback)
21         rp->parser(buffer, buffer_len, count, callback, userdata);
22       return 1;
23     }
24   }
25
26   return 0;
27 }