Package list ohcount / a9d19c7
New upstream version 4.0.0 Sylvestre Ledru 2 years ago
14 changed file(s) with 67 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
0 language: ruby
1 install:
2 - sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig
3 - gem install test-unit
4444 System Requirements
4545 -------------------
4646
47 Ohcount is supported on Ubuntu 14.04 LTS. Other Linux
48 environments should also work, but your mileage may vary.
47 Ohcount is supported on Ubuntu 18.04 LTS. It has also been tested on Fedora 29.
48 Other unix-like environments should also work, but your mileage may vary.
4949
5050 Ohcount does not support Windows.
5151
52 Ohcount targets Ruby 2.2.3. The build script requires a bash shell. You
53 also need a C compiler to build the native extensions.
52 Ohcount targets Ruby 2.5.0. The ruby dev headers provided by Ubuntu/Fedora
53 package managers were found to be missing a *config.h* header file. Installing
54 ruby using brew/rbenv/rvm works better for compiling ohcount.
5455
5556 Source Code
5657 -----------
5758
5859 Ohcount source code is available as a Git repository:
5960
60 git clone git://github.com/blackducksw/ohcount.git
61 git clone git://github.com/blackducksoftware/ohcount.git
6162
6263 Building Ohcount
6364 ----------------
6465
65 > Last updated: 2018-05-10
66 > Last updated: 2019-01-28
6667
67 You will need ragel 6.8 or higher, bash, gperf, libpcre3-dev, libmagic-dev, gcc (version 4.8.2 or greater)
68 and SWIG (2.0.11). To get these dependencies on Ubuntu/Debian you can run this command:
68 You will need ragel 7.0 or higher, bash, gperf, libpcre3-dev, libmagic-dev,
69 gcc(version 7.3 or greater) and swig (>=3.0.0).
6970
70 sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig
71
72 There is a Ruby dependency of 'test-unit' gem for Ruby 2.2.3. You will need to run this command:
73
74 gem install test-unit
75
76 Once you have them, go to the top directory of ohcount and run
71 #### Ubuntu/Debian
7772
7873 ```
79 ./build
74 $ sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig
75 $ ./build
76 ```
77
78 ### Fedora
79
80 ```
81 $ sudo dnf install gcc file-devel gperf ragel swig pcre-devel
82 $ ./build
83 ```
84
85 #### OSx
86
87 ```
88 $ brew install libmagic pcre ragel swig
89 $ ./build
90 ```
91
92 For the ruby bindings, there is a dependency for the 'test-unit' gem:
93
94 ```
95 $ gem install test-unit
8096 ```
8197
8298 Using Ohcount
85101 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:
86102
87103 ```
88 bin/ohcount
104 $ bin/ohcount
89105 ```
90106
91107 Ohcount support several options. Run `ohcount --help` for more information.
96112 To build the ruby wrapper:
97113
98114 ```
99 ./build ruby
115 $ ./build ruby
100116 ```
101117
102118 To build the python wrapper, run
103119
104120 ```
105 python python/setup.py build
106 python python/setup.py install
121 $ python python/setup.py build
122 $ python python/setup.py install
107123 ```
108124
109125 The python wrapper is currently unsupported.
22
33 arch = RbConfig::expand(CONFIG["arch"])
44
5 distro = if File.exist?("/etc/issue")
5 distro = if File.exist?("/etc/os-release")
66 # this is "", "CentOS" or "Ubuntu"
7 `cat /etc/issue`.split.first.downcase
7 `egrep "^ID=.*" /etc/os-release`.split("=")[1].downcase
88 end
99
10 unless ["centos", nil, "ubuntu"].include? distro
11 STDERR.puts "unhandled /etc/issue result: #{distro}"
10 unless %w[centos ubuntu fedora].include?(distro.to_s.chomp)
11 STDERR.puts "unhandled /etc/os-release result: #{distro}"
1212 end
1313
1414 # either <arch> or <arch>_<distro> if distro is non-null
647647 char *to_tmp = tmp_file_from_buf(to);
648648
649649 char command[1000];
650 sprintf(command, "diff -d --normal --suppress-common-lines --new-file '%s' '%s'", from_tmp, to_tmp);
650 sprintf(command, "diff --normal --suppress-common-lines --new-file '%s' '%s'", from_tmp, to_tmp);
651651 FILE *f = popen(command, "r");
652652 if (f) {
653653 char line[10000];
150150 obn, LANG_OBERON
151151 ogg, BINARY
152152 p6, LANG_PERL
153 p8, LANG_LUA
153154 pas, LANG_PASCAL
154155 perl, LANG_PERL
155156 pdf, BINARY
208209 svn, BINARY
209210 swf, BINARY
210211 t, LANG_PERL
212 tac, LANG_PYTHON
213 tap, LANG_PYTHON
211214 tar, BINARY
212215 tcl, LANG_TCL
213216 tex, LANG_TEX
232235 wl, LANG_MATHEMATICA
233236 wlt, LANG_MATHEMATICA
234237 xaml, LANG_XAML
238 xhtml, LANG_HTML
235239 xls, BINARY
236240 xlw, BINARY
237241 xml, LANG_XML
240244 xsl, LANG_XSLT
241245 z80, LANG_ASSEMBLER
242246 zip, BINARY
247 zpt, LANG_HTML
125125
126126 // For gperf.
127127 struct LanguageMap { const char *key; const char *name; const char *nice_name; int category; };
128 struct LanguageMap *ohcount_hash_language_from_name(register const char *str, register unsigned int len);
128 struct LanguageMap *ohcount_hash_language_from_name(register const char *str, register size_t len);
129129
130130 #endif
66 #include "log.h"
77 #include "hash/parser_hash.h"
88
9 struct ParserMap * ohcount_hash_parser_from_language (register const char *str, register unsigned int len);
9 struct ParserMap * ohcount_hash_parser_from_language (register const char *str, register size_t len);
1010
1111 int ohcount_parse(SourceFile *sourcefile, int count,
1212 void (*callback) (const char *, const char *, int, int,
5555 )* :>> '*/';
5656
5757 modelica_comment = modelica_line_comment | modelica_block_comment;
58 identifier = '\'' (([^'] - ws + ' ')*|'\\\'') '\'' @code;
58 identifier = (alpha | '_') (alnum | '_')*;
5959 string = '\"' @code
6060 (newline %{ entity = INTERNAL_NL; } %modelica_ccallback
6161 |ws
4040 break;
4141 case NEWLINE:
4242 std_newline(PHP_LANG)
43 break;
44 case CHECK_BLANK_ENTRY:
45 check_blank_entry(PHP_LANG)
46 break;
4347 }
4448 }
4549
123123 phtml_php_entry = ('<?' 'php'?) @code;
124124 phtml_php_outry = '?>' @check_blank_outry @code;
125125 phtml_php_line := |*
126 phtml_php_outry @{ p = ts; fret; };
126 phtml_php_outry ${ p = ts; fret; };
127127 # unmodified PHP patterns
128128 spaces ${ entity = PHP_SPACE; } => php_ccallback;
129129 php_comment;
137137 @{ saw(CSS_LANG); } => { fcall phtml_css_line; };
138138 phtml_js_entry @{ entity = CHECK_BLANK_ENTRY; } @phtml_ccallback
139139 @{ saw(JS_LANG); } => { fcall phtml_js_line; };
140 phtml_php_entry @{ entity = CHECK_BLANK_ENTRY; } @phtml_ccallback
140 phtml_php_entry @{ entity = CHECK_BLANK_ENTRY; } @php_ccallback
141141 @{ saw(PHP_LANG); } => { fcall phtml_php_line; };
142142 # standard PHTML patterns
143143 spaces ${ entity = PHTML_SPACE; } => phtml_ccallback;
2121 html code </tr>
2222 html code </table>
2323 html blank
24 html code <?
24 php code <?php
2525 php comment ## Comment with a hash symbol ##
2626 php code mysql_connect("localhost", "db user", "db pass")
2727 php code or die("DB CONNECT ERROR: " . mysql_error());
4141 php code $email = $row['email'];
4242 php blank
4343 php comment // Spaghetti code starts....(slopping html code in)
44 html code ?>
44 php code >
4545 html blank
4646 html code <tr bgColor=white>
4747 php code <td><?=$fname?></td>
5050 html code </tr>
5151 html code </table>
5252 html blank
53 html code <?
53 php code <?
5454 php code } // end while
5555 php comment // Spaghetti code is both a source of praise and complaints
56 html code ?>
56 php code >
5757 html blank
5858 html code </body>
2121 </tr>
2222 </table>
2323
24 <?
24 <?php
2525 ## Comment with a hash symbol ##
2626 mysql_connect("localhost", "db user", "db pass")
2727 or die("DB CONNECT ERROR: " . mysql_error());
33 class SourceFileTest < Test::Unit::TestCase
44 def test_diff
55 optimer = File.open(File.dirname(__FILE__) + "/../../src_dir/optimer").read
6 new = Ohcount::SourceFile.new("optimer", :contents => optimer, :filenames => nil, :filenames => ["optimer"])
6 new = Ohcount::SourceFile.new("optimer", :contents => optimer, :filenames => ["optimer"])
77 old = Ohcount::SourceFile.new("optimer", :contents => "", :filenames => ["optimer"])
88 assert_equal optimer, new.contents
99 deltas = old.diff(new).loc_deltas
1414 def test_empty_diff
1515 filename = "mysql-stale-table-sniper"
1616 c = File.open(File.dirname(__FILE__) + "/../../src_dir/#{filename}").read
17 new = Ohcount::SourceFile.new(filename, :contents => c, :filenames => nil, :filenames => [filename])
18 old = Ohcount::SourceFile.new(filename, :contents => "", :filenames => nil, :filenames => [filename])
17 new = Ohcount::SourceFile.new(filename, :contents => c, :filenames => [filename])
18 old = Ohcount::SourceFile.new(filename, :contents => "", :filenames => [filename])
1919 assert_equal c, new.contents
2020 deltas = old.diff(new).loc_deltas
2121 assert_not_nil deltas