diff --git a/.travis.yml b/.travis.yml index ae2f155..4498759 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +arch: + - amd64 + - ppc64le language: ruby install: - sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig diff --git a/README.md b/README.md index 5954312..afcfc26 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,6 @@ Ohcount does not support Windows. -Ohcount targets Ruby 2.5.0. The ruby dev headers provided by Ubuntu/Fedora -package managers were found to be missing a *config.h* header file. Installing -ruby using brew/rbenv/rvm works better for compiling ohcount. - Source Code ----------- @@ -64,10 +60,26 @@ Building Ohcount ---------------- -> Last updated: 2019-01-28 +> Last updated: 2020-02-12 + +Ohcount targets `Ruby 2.*`. The ruby dev headers provided by Ubuntu/Fedora +package managers were found to be missing a `config.h` header file. If the +default ruby and ruby-dev packages do not work, install ruby using +brew/rbenv/asdf/rvm, which work reliably with ohcount. You will need ragel 7.0 or higher, bash, gperf, libpcre3-dev, libmagic-dev, gcc(version 7.3 or greater) and swig (>=3.0.0). +For older gcc versions one could try [this fix](https://github.com/blackducksoftware/ohcount/pull/70/commits/c7511b9810a8660a8268a958fee0e365fb9af18f). + +``` +$ git clone git://github.com/blackducksoftware/ohcount.git +$ cd ohcount +``` + +For the ruby bindings, there is a dependency for the 'test-unit' gem: +``` +$ gem install test-unit +``` #### Ubuntu/Debian @@ -90,11 +102,9 @@ $ ./build ``` -For the ruby bindings, there is a dependency for the 'test-unit' gem: +#### Other Unix systems -``` -$ gem install test-unit -``` +* If build fails with a missing `ohcount.so` error and any `ruby/x86.../` folder has the file, copy it to `ruby/` folder. Using Ohcount ------------- diff --git a/debian/changelog b/debian/changelog index ad3f67a..114d0e4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,10 @@ -ohcount (4.0.0-2) UNRELEASED; urgency=medium +ohcount (4.0.0+git20210223.6654d48-1) UNRELEASED; urgency=medium * Bump debhelper from old 9 to 12. * Set debhelper-compat version in Build-Depends. * Set upstream metadata fields: Repository, Repository-Browse. - -- Debian Janitor Thu, 21 Nov 2019 03:29:25 +0000 + -- Debian Janitor Fri, 26 Mar 2021 18:27:12 -0000 ohcount (4.0.0-1) unstable; urgency=medium diff --git a/src/hash/extensions.gperf b/src/hash/extensions.gperf index c264648..b2a31ff 100755 --- a/src/hash/extensions.gperf +++ b/src/hash/extensions.gperf @@ -51,6 +51,7 @@ cu, LANG_CUDA cxx, LANG_CPP d, LANG_DMD +dart, LANG_DART dat, DISAMBIGUATE("dat") def, DISAMBIGUATE("def") di, LANG_DMD @@ -198,6 +199,7 @@ sci, LANG_SCILAB scm, LANG_SCHEME sh, LANG_SHELL +sld, LANG_SCHEME sls, LANG_SCHEME sps, LANG_SCHEME sql, LANG_SQL diff --git a/src/hash/languages.gperf b/src/hash/languages.gperf index 7c70f95..2d24947 100755 --- a/src/hash/languages.gperf +++ b/src/hash/languages.gperf @@ -32,6 +32,7 @@ csharp, LANG_CSHARP, "C#", 0 css, LANG_CSS, "CSS", 1 cuda, LANG_CUDA, "CUDA", 0 +dart, LANG_DART, "Dart", 0 dcl, LANG_DCL, "DCL", 0 dmd, LANG_DMD, "D", 0 dtx, LANG_TEX_DTX, "DTX for TeX/LaTeX", 1 diff --git a/src/hash/parsers.gperf b/src/hash/parsers.gperf index 577002c..0dd4b55 100644 --- a/src/hash/parsers.gperf +++ b/src/hash/parsers.gperf @@ -25,6 +25,7 @@ #include "../parsers/css.h" #include "../parsers/d.h" #include "../parsers/dcl.h" +#include "../parsers/dart.h" #include "../parsers/dylan.h" #include "../parsers/ebuild.h" #include "../parsers/eiffel.h" @@ -135,6 +136,7 @@ csharp, parse_csharp css, parse_css cuda, parse_cuda +dart, parse_dart dcl, parse_dcl dmd, parse_d dylan, parse_dylan diff --git a/src/languages.h b/src/languages.h index 0df901e..0d7ee7e 100755 --- a/src/languages.h +++ b/src/languages.h @@ -34,6 +34,7 @@ #define LANG_CSHARP "csharp" #define LANG_CSS "css" #define LANG_CUDA "cuda" +#define LANG_DART "dart" #define LANG_DCL "dcl" #define LANG_DMD "dmd" #define LANG_DYLAN "dylan" diff --git a/src/parsers/dart.rl b/src/parsers/dart.rl new file mode 100755 index 0000000..9669564 --- /dev/null +++ b/src/parsers/dart.rl @@ -0,0 +1,118 @@ +/************************* Required for every parser *************************/ +#ifndef OHCOUNT_DART_PARSER_H +#define OHCOUNT_DART_PARSER_H + +#include "../parser_macros.h" + +// the name of the language +const char *DART_LANG = LANG_DART; + +// the languages entities +const char *dart_entities[] = { + "space", "comment", "any" +}; + +// constants associated with the entities +enum { + DART_SPACE = 0, DART_COMMENT, DART_ANY +}; + +/*****************************************************************************/ + +%%{ + machine dart; + write data; + include common "common.rl"; + + # Line counting machine + + action dart_ccallback { + switch(entity) { + case DART_SPACE: + ls + break; + case DART_ANY: + code + break; + case INTERNAL_NL: + std_internal_newline(DART_LANG) + break; + case NEWLINE: + std_newline(DART_LANG) + } + } + + dart_line_comment = + '//' @comment ( + escaped_newline %{ entity = INTERNAL_NL; } %dart_ccallback + | + ws + | + (nonnewline - ws) @comment + )*; + dart_block_comment = + '/*' @comment ( + newline %{ entity = INTERNAL_NL; } %dart_ccallback + | + ws + | + (nonnewline - ws) @comment + )* :>> '*/'; + dart_comment = dart_line_comment | dart_block_comment; + + dart_line := |* + spaces ${ entity = DART_SPACE; } => dart_ccallback; + dart_comment; + newline ${ entity = NEWLINE; } => dart_ccallback; + ^space ${ entity = DART_ANY; } => dart_ccallback; + *|; + + # Entity machine + # TODO: This is a placeholder and most entities are missing. + + action dart_ecallback { + callback(DART_LANG, dart_entities[entity], cint(ts), cint(te), userdata); + } + + dart_line_comment_entity = '//' (escaped_newline | nonnewline)*; + dart_block_comment_entity = '/*' any* :>> '*/'; + dart_comment_entity = dart_line_comment_entity | dart_block_comment_entity; + + dart_entity := |* + space+ ${ entity = DART_SPACE; } => dart_ecallback; + dart_comment_entity ${ entity = DART_COMMENT; } => dart_ecallback; + ^space; + *|; +}%% + +/************************* Required for every parser *************************/ + +/* Parses a string buffer with Dart code. + * + * @param *buffer The string to parse. + * @param length The length of the string to parse. + * @param count Integer flag specifying whether or not to count lines. If yes, + * uses the Ragel machine optimized for counting. Otherwise uses the Ragel + * machine optimized for returning entity positions. + * @param *callback Callback function. If count is set, callback is called for + * every line of code, comment, or blank with 'lcode', 'lcomment', and + * 'lblank' respectively. Otherwise callback is called for each entity found. + */ +void parse_dart(char *buffer, int length, int count, + void (*callback) (const char *lang, const char *entity, int s, + int e, void *udata), + void *userdata + ) { + init + + %% write init; + cs = (count) ? dart_en_dart_line : dart_en_dart_entity; + %% write exec; + + // if no newline at EOF; callback contents of last line + if (count) { process_last_line(DART_LANG) } +} + +#endif + +/*****************************************************************************/ \ No newline at end of file diff --git a/test/detect_files/foo.dart b/test/detect_files/foo.dart new file mode 100644 index 0000000..0f3009c --- /dev/null +++ b/test/detect_files/foo.dart @@ -0,0 +1,4 @@ +// Example Dart code +void main() { + print("Hello, World!"); +} \ No newline at end of file diff --git a/test/expected_dir/foo.dart b/test/expected_dir/foo.dart new file mode 100644 index 0000000..a8e6a77 --- /dev/null +++ b/test/expected_dir/foo.dart @@ -0,0 +1,9 @@ +dart code void main() { +dart comment // Line comment +dart blank +dart comment /* Block +dart comment comment */ +dart blank +dart code print("Hello!"); // Code with line comment +dart code print("World!"); /* Code with block comment */ +dart code } diff --git a/test/src_dir/foo.dart b/test/src_dir/foo.dart new file mode 100644 index 0000000..c560395 --- /dev/null +++ b/test/src_dir/foo.dart @@ -0,0 +1,9 @@ +void main() { + // Line comment + + /* Block + comment */ + + print("Hello!"); // Code with line comment + print("World!"); /* Code with block comment */ +} diff --git a/test/unit/detector_test.h b/test/unit/detector_test.h index ff544ff..fef3b46 100755 --- a/test/unit/detector_test.h +++ b/test/unit/detector_test.h @@ -221,6 +221,10 @@ ASSERT_DETECT(LANG_BFPP, "foo.bfpp"); } +void test_detector_dart() { + ASSERT_DETECT(LANG_DART, "foo.dart"); +} + void test_detector_emacs_mode() { ASSERT_DETECT(LANG_C, "emacs_mode_c"); } @@ -272,6 +276,7 @@ test_detector_basic(); test_detector_xml_with_custom_extension(); test_detector_brainfuck(); + test_detector_dart(); test_detector_emacs_mode(); test_detector_emacs_with_extension(); test_detector_puppet(); diff --git a/test/unit/parser_test.h b/test/unit/parser_test.h index 4c9c588..92c489d 100644 --- a/test/unit/parser_test.h +++ b/test/unit/parser_test.h @@ -98,6 +98,7 @@ #include "parsers/test_csharp.h" #include "parsers/test_css.h" #include "parsers/test_d.h" +#include "parsers/test_dart.h" #include "parsers/test_dcl.h" #include "parsers/test_dylan.h" #include "parsers/test_ebuild.h" @@ -288,6 +289,7 @@ all_cs_aspx_tests(); all_csharp_tests(); all_css_tests(); + all_dart_tests(); all_dmd_tests(); all_dcl_tests(); all_dylan_tests(); diff --git a/test/unit/parsers/test_dart.h b/test/unit/parsers/test_dart.h new file mode 100644 index 0000000..46275dc --- /dev/null +++ b/test/unit/parsers/test_dart.h @@ -0,0 +1,39 @@ + +void test_dart_comments() { + test_parser_verify_parse( + test_parser_sourcefile("dart", " //comment"), + "dart", "", "//comment", 0 + ); +} + +void test_dart_empty_comments() { + test_parser_verify_parse( + test_parser_sourcefile("dart", " //\n"), + "dart", "", "//\n", 0 + ); +} + +void test_dart_block_comment() { + test_parser_verify_parse( + test_parser_sourcefile("dart", "/*comment*/"), + "dart", "", "/*comment*/", 0 + ); +} + +void test_dart_comment_entities() { + test_parser_verify_entity( + test_parser_sourcefile("dart", " //comment"), + "comment", "//comment" + ); + test_parser_verify_entity( + test_parser_sourcefile("c", " /*comment*/"), + "comment", "/*comment*/" + ); +} + +void all_dart_tests() { + test_dart_comments(); + test_dart_empty_comments(); + test_dart_block_comment(); + test_dart_comment_entities(); +}