diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ae2f155 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby +install: + - sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig + - gem install test-unit diff --git a/README.md b/README.md index 4e00596..5954312 100644 --- a/README.md +++ b/README.md @@ -45,39 +45,55 @@ System Requirements ------------------- -Ohcount is supported on Ubuntu 14.04 LTS. Other Linux -environments should also work, but your mileage may vary. +Ohcount is supported on Ubuntu 18.04 LTS. It has also been tested on Fedora 29. +Other unix-like environments should also work, but your mileage may vary. Ohcount does not support Windows. -Ohcount targets Ruby 2.2.3. The build script requires a bash shell. You -also need a C compiler to build the native extensions. +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 ----------- Ohcount source code is available as a Git repository: - git clone git://github.com/blackducksw/ohcount.git + git clone git://github.com/blackducksoftware/ohcount.git Building Ohcount ---------------- -> Last updated: 2018-05-10 +> Last updated: 2019-01-28 -You will need ragel 6.8 or higher, bash, gperf, libpcre3-dev, libmagic-dev, gcc (version 4.8.2 or greater) -and SWIG (2.0.11). To get these dependencies on Ubuntu/Debian you can run this command: +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). - sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig - -There is a Ruby dependency of 'test-unit' gem for Ruby 2.2.3. You will need to run this command: - - gem install test-unit - -Once you have them, go to the top directory of ohcount and run +#### Ubuntu/Debian ``` -./build +$ sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig +$ ./build +``` + +### Fedora + +``` +$ sudo dnf install gcc file-devel gperf ragel swig pcre-devel +$ ./build +``` + +#### OSx + +``` +$ brew install libmagic pcre ragel swig +$ ./build +``` + +For the ruby bindings, there is a dependency for the 'test-unit' gem: + +``` +$ gem install test-unit ``` Using Ohcount @@ -86,7 +102,7 @@ Once you've built ohcount, the executable program will be at bin/ohcount. The most basic use is to count lines of code in a directory tree. run: ``` -bin/ohcount +$ bin/ohcount ``` Ohcount support several options. Run `ohcount --help` for more information. @@ -97,14 +113,14 @@ To build the ruby wrapper: ``` -./build ruby +$ ./build ruby ``` To build the python wrapper, run ``` -python python/setup.py build -python python/setup.py install +$ python python/setup.py build +$ python python/setup.py install ``` The python wrapper is currently unsupported. diff --git a/ruby/print_arch b/ruby/print_arch index c42e70a..2767169 100755 --- a/ruby/print_arch +++ b/ruby/print_arch @@ -3,13 +3,13 @@ arch = RbConfig::expand(CONFIG["arch"]) -distro = if File.exist?("/etc/issue") +distro = if File.exist?("/etc/os-release") # this is "", "CentOS" or "Ubuntu" - `cat /etc/issue`.split.first.downcase + `egrep "^ID=.*" /etc/os-release`.split("=")[1].downcase end -unless ["centos", nil, "ubuntu"].include? distro - STDERR.puts "unhandled /etc/issue result: #{distro}" +unless %w[centos ubuntu fedora].include?(distro.to_s.chomp) + STDERR.puts "unhandled /etc/os-release result: #{distro}" end # either or _ if distro is non-null diff --git a/ruby/x86_64-linux_ubuntu/ohcount.so b/ruby/x86_64-linux_ubuntu/ohcount.so index 6c650da..d4ee7dd 100755 Binary files a/ruby/x86_64-linux_ubuntu/ohcount.so and b/ruby/x86_64-linux_ubuntu/ohcount.so differ diff --git a/src/diff.c b/src/diff.c index 019a119..bbb96ab 100644 --- a/src/diff.c +++ b/src/diff.c @@ -648,7 +648,7 @@ char *to_tmp = tmp_file_from_buf(to); char command[1000]; - sprintf(command, "diff -d --normal --suppress-common-lines --new-file '%s' '%s'", from_tmp, to_tmp); + sprintf(command, "diff --normal --suppress-common-lines --new-file '%s' '%s'", from_tmp, to_tmp); FILE *f = popen(command, "r"); if (f) { char line[10000]; diff --git a/src/hash/extensions.gperf b/src/hash/extensions.gperf index bc014c9..c264648 100755 --- a/src/hash/extensions.gperf +++ b/src/hash/extensions.gperf @@ -151,6 +151,7 @@ obn, LANG_OBERON ogg, BINARY p6, LANG_PERL +p8, LANG_LUA pas, LANG_PASCAL perl, LANG_PERL pdf, BINARY @@ -209,6 +210,8 @@ svn, BINARY swf, BINARY t, LANG_PERL +tac, LANG_PYTHON +tap, LANG_PYTHON tar, BINARY tcl, LANG_TCL tex, LANG_TEX @@ -233,6 +236,7 @@ wl, LANG_MATHEMATICA wlt, LANG_MATHEMATICA xaml, LANG_XAML +xhtml, LANG_HTML xls, BINARY xlw, BINARY xml, LANG_XML @@ -241,3 +245,4 @@ xsl, LANG_XSLT z80, LANG_ASSEMBLER zip, BINARY +zpt, LANG_HTML diff --git a/src/languages.h b/src/languages.h index 69506e8..0df901e 100755 --- a/src/languages.h +++ b/src/languages.h @@ -126,6 +126,6 @@ // For gperf. struct LanguageMap { const char *key; const char *name; const char *nice_name; int category; }; -struct LanguageMap *ohcount_hash_language_from_name(register const char *str, register unsigned int len); +struct LanguageMap *ohcount_hash_language_from_name(register const char *str, register size_t len); #endif diff --git a/src/parser.c b/src/parser.c index d362acf..358113e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -7,7 +7,7 @@ #include "log.h" #include "hash/parser_hash.h" -struct ParserMap * ohcount_hash_parser_from_language (register const char *str, register unsigned int len); +struct ParserMap * ohcount_hash_parser_from_language (register const char *str, register size_t len); int ohcount_parse(SourceFile *sourcefile, int count, void (*callback) (const char *, const char *, int, int, diff --git a/src/parsers/modelica.rl b/src/parsers/modelica.rl index 49432f3..f6c5cd2 100644 --- a/src/parsers/modelica.rl +++ b/src/parsers/modelica.rl @@ -56,7 +56,7 @@ )* :>> '*/'; modelica_comment = modelica_line_comment | modelica_block_comment; - identifier = '\'' (([^'] - ws + ' ')*|'\\\'') '\'' @code; + identifier = (alpha | '_') (alnum | '_')*; string = '\"' @code (newline %{ entity = INTERNAL_NL; } %modelica_ccallback |ws diff --git a/src/parsers/php.rl b/src/parsers/php.rl index 89f116b..e949794 100644 --- a/src/parsers/php.rl +++ b/src/parsers/php.rl @@ -41,6 +41,10 @@ break; case NEWLINE: std_newline(PHP_LANG) + break; + case CHECK_BLANK_ENTRY: + check_blank_entry(PHP_LANG) + break; } } diff --git a/src/parsers/phphtml.rl b/src/parsers/phphtml.rl index f27da2e..9dfe21e 100644 --- a/src/parsers/phphtml.rl +++ b/src/parsers/phphtml.rl @@ -124,7 +124,7 @@ phtml_php_entry = ('' @check_blank_outry @code; phtml_php_line := |* - phtml_php_outry @{ p = ts; fret; }; + phtml_php_outry ${ p = ts; fret; }; # unmodified PHP patterns spaces ${ entity = PHP_SPACE; } => php_ccallback; php_comment; @@ -138,7 +138,7 @@ @{ saw(CSS_LANG); } => { fcall phtml_css_line; }; phtml_js_entry @{ entity = CHECK_BLANK_ENTRY; } @phtml_ccallback @{ saw(JS_LANG); } => { fcall phtml_js_line; }; - phtml_php_entry @{ entity = CHECK_BLANK_ENTRY; } @phtml_ccallback + phtml_php_entry @{ entity = CHECK_BLANK_ENTRY; } @php_ccallback @{ saw(PHP_LANG); } => { fcall phtml_php_line; }; # standard PHTML patterns spaces ${ entity = PHTML_SPACE; } => phtml_ccallback; diff --git a/test/expected_dir/php1.php b/test/expected_dir/php1.php index a9d85ec..81fb2f1 100644 --- a/test/expected_dir/php1.php +++ b/test/expected_dir/php1.php @@ -22,7 +22,7 @@ html code html code html blank -html code +php code > html blank html code php code @@ -51,9 +51,9 @@ html code html code html blank -html code +php code > html blank html code diff --git a/test/src_dir/php1.php b/test/src_dir/php1.php index 43b4182..0c4b40e 100644 --- a/test/src_dir/php1.php +++ b/test/src_dir/php1.php @@ -22,7 +22,7 @@ - optimer, :filenames => nil, :filenames => ["optimer"]) + new = Ohcount::SourceFile.new("optimer", :contents => optimer, :filenames => ["optimer"]) old = Ohcount::SourceFile.new("optimer", :contents => "", :filenames => ["optimer"]) assert_equal optimer, new.contents deltas = old.diff(new).loc_deltas @@ -15,8 +15,8 @@ def test_empty_diff filename = "mysql-stale-table-sniper" c = File.open(File.dirname(__FILE__) + "/../../src_dir/#{filename}").read - new = Ohcount::SourceFile.new(filename, :contents => c, :filenames => nil, :filenames => [filename]) - old = Ohcount::SourceFile.new(filename, :contents => "", :filenames => nil, :filenames => [filename]) + new = Ohcount::SourceFile.new(filename, :contents => c, :filenames => [filename]) + old = Ohcount::SourceFile.new(filename, :contents => "", :filenames => [filename]) assert_equal c, new.contents deltas = old.diff(new).loc_deltas assert_not_nil deltas