Update upstream source from tag 'upstream/4.0.0'
Update to upstream version '4.0.0'
with Debian dir 09d727bbb190c41931fb9b2e8835b514801a5c9d
Sylvestre Ledru
4 years ago
0 | language: ruby | |
1 | install: | |
2 | - sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig | |
3 | - gem install test-unit |
44 | 44 | System Requirements |
45 | 45 | ------------------- |
46 | 46 | |
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. | |
49 | 49 | |
50 | 50 | Ohcount does not support Windows. |
51 | 51 | |
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. | |
54 | 55 | |
55 | 56 | Source Code |
56 | 57 | ----------- |
57 | 58 | |
58 | 59 | Ohcount source code is available as a Git repository: |
59 | 60 | |
60 | git clone git://github.com/blackducksw/ohcount.git | |
61 | git clone git://github.com/blackducksoftware/ohcount.git | |
61 | 62 | |
62 | 63 | Building Ohcount |
63 | 64 | ---------------- |
64 | 65 | |
65 | > Last updated: 2018-05-10 | |
66 | > Last updated: 2019-01-28 | |
66 | 67 | |
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). | |
69 | 70 | |
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 | |
77 | 72 | |
78 | 73 | ``` |
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 | |
80 | 96 | ``` |
81 | 97 | |
82 | 98 | Using Ohcount |
85 | 101 | 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: |
86 | 102 | |
87 | 103 | ``` |
88 | bin/ohcount | |
104 | $ bin/ohcount | |
89 | 105 | ``` |
90 | 106 | |
91 | 107 | Ohcount support several options. Run `ohcount --help` for more information. |
96 | 112 | To build the ruby wrapper: |
97 | 113 | |
98 | 114 | ``` |
99 | ./build ruby | |
115 | $ ./build ruby | |
100 | 116 | ``` |
101 | 117 | |
102 | 118 | To build the python wrapper, run |
103 | 119 | |
104 | 120 | ``` |
105 | python python/setup.py build | |
106 | python python/setup.py install | |
121 | $ python python/setup.py build | |
122 | $ python python/setup.py install | |
107 | 123 | ``` |
108 | 124 | |
109 | 125 | The python wrapper is currently unsupported. |
2 | 2 | |
3 | 3 | arch = RbConfig::expand(CONFIG["arch"]) |
4 | 4 | |
5 | distro = if File.exist?("/etc/issue") | |
5 | distro = if File.exist?("/etc/os-release") | |
6 | 6 | # this is "", "CentOS" or "Ubuntu" |
7 | `cat /etc/issue`.split.first.downcase | |
7 | `egrep "^ID=.*" /etc/os-release`.split("=")[1].downcase | |
8 | 8 | end |
9 | 9 | |
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}" | |
12 | 12 | end |
13 | 13 | |
14 | 14 | # either <arch> or <arch>_<distro> if distro is non-null |
Binary diff not shown
647 | 647 | char *to_tmp = tmp_file_from_buf(to); |
648 | 648 | |
649 | 649 | 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); | |
651 | 651 | FILE *f = popen(command, "r"); |
652 | 652 | if (f) { |
653 | 653 | char line[10000]; |
150 | 150 | obn, LANG_OBERON |
151 | 151 | ogg, BINARY |
152 | 152 | p6, LANG_PERL |
153 | p8, LANG_LUA | |
153 | 154 | pas, LANG_PASCAL |
154 | 155 | perl, LANG_PERL |
155 | 156 | pdf, BINARY |
208 | 209 | svn, BINARY |
209 | 210 | swf, BINARY |
210 | 211 | t, LANG_PERL |
212 | tac, LANG_PYTHON | |
213 | tap, LANG_PYTHON | |
211 | 214 | tar, BINARY |
212 | 215 | tcl, LANG_TCL |
213 | 216 | tex, LANG_TEX |
232 | 235 | wl, LANG_MATHEMATICA |
233 | 236 | wlt, LANG_MATHEMATICA |
234 | 237 | xaml, LANG_XAML |
238 | xhtml, LANG_HTML | |
235 | 239 | xls, BINARY |
236 | 240 | xlw, BINARY |
237 | 241 | xml, LANG_XML |
240 | 244 | xsl, LANG_XSLT |
241 | 245 | z80, LANG_ASSEMBLER |
242 | 246 | zip, BINARY |
247 | zpt, LANG_HTML |
125 | 125 | |
126 | 126 | // For gperf. |
127 | 127 | 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); | |
129 | 129 | |
130 | 130 | #endif |
6 | 6 | #include "log.h" |
7 | 7 | #include "hash/parser_hash.h" |
8 | 8 | |
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); | |
10 | 10 | |
11 | 11 | int ohcount_parse(SourceFile *sourcefile, int count, |
12 | 12 | void (*callback) (const char *, const char *, int, int, |
55 | 55 | )* :>> '*/'; |
56 | 56 | |
57 | 57 | modelica_comment = modelica_line_comment | modelica_block_comment; |
58 | identifier = '\'' (([^'] - ws + ' ')*|'\\\'') '\'' @code; | |
58 | identifier = (alpha | '_') (alnum | '_')*; | |
59 | 59 | string = '\"' @code |
60 | 60 | (newline %{ entity = INTERNAL_NL; } %modelica_ccallback |
61 | 61 | |ws |
40 | 40 | break; |
41 | 41 | case NEWLINE: |
42 | 42 | std_newline(PHP_LANG) |
43 | break; | |
44 | case CHECK_BLANK_ENTRY: | |
45 | check_blank_entry(PHP_LANG) | |
46 | break; | |
43 | 47 | } |
44 | 48 | } |
45 | 49 |
123 | 123 | phtml_php_entry = ('<?' 'php'?) @code; |
124 | 124 | phtml_php_outry = '?>' @check_blank_outry @code; |
125 | 125 | phtml_php_line := |* |
126 | phtml_php_outry @{ p = ts; fret; }; | |
126 | phtml_php_outry ${ p = ts; fret; }; | |
127 | 127 | # unmodified PHP patterns |
128 | 128 | spaces ${ entity = PHP_SPACE; } => php_ccallback; |
129 | 129 | php_comment; |
137 | 137 | @{ saw(CSS_LANG); } => { fcall phtml_css_line; }; |
138 | 138 | phtml_js_entry @{ entity = CHECK_BLANK_ENTRY; } @phtml_ccallback |
139 | 139 | @{ 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 | |
141 | 141 | @{ saw(PHP_LANG); } => { fcall phtml_php_line; }; |
142 | 142 | # standard PHTML patterns |
143 | 143 | spaces ${ entity = PHTML_SPACE; } => phtml_ccallback; |
21 | 21 | html code </tr> |
22 | 22 | html code </table> |
23 | 23 | html blank |
24 | html code <? | |
24 | php code <?php | |
25 | 25 | php comment ## Comment with a hash symbol ## |
26 | 26 | php code mysql_connect("localhost", "db user", "db pass") |
27 | 27 | php code or die("DB CONNECT ERROR: " . mysql_error()); |
41 | 41 | php code $email = $row['email']; |
42 | 42 | php blank |
43 | 43 | php comment // Spaghetti code starts....(slopping html code in) |
44 | html code ?> | |
44 | php code > | |
45 | 45 | html blank |
46 | 46 | html code <tr bgColor=white> |
47 | 47 | php code <td><?=$fname?></td> |
50 | 50 | html code </tr> |
51 | 51 | html code </table> |
52 | 52 | html blank |
53 | html code <? | |
53 | php code <? | |
54 | 54 | php code } // end while |
55 | 55 | php comment // Spaghetti code is both a source of praise and complaints |
56 | html code ?> | |
56 | php code > | |
57 | 57 | html blank |
58 | 58 | html code </body> |
21 | 21 | </tr> |
22 | 22 | </table> |
23 | 23 | |
24 | <? | |
24 | <?php | |
25 | 25 | ## Comment with a hash symbol ## |
26 | 26 | mysql_connect("localhost", "db user", "db pass") |
27 | 27 | or die("DB CONNECT ERROR: " . mysql_error()); |
3 | 3 | class SourceFileTest < Test::Unit::TestCase |
4 | 4 | def test_diff |
5 | 5 | 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"]) | |
7 | 7 | old = Ohcount::SourceFile.new("optimer", :contents => "", :filenames => ["optimer"]) |
8 | 8 | assert_equal optimer, new.contents |
9 | 9 | deltas = old.diff(new).loc_deltas |
14 | 14 | def test_empty_diff |
15 | 15 | filename = "mysql-stale-table-sniper" |
16 | 16 | 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]) | |
19 | 19 | assert_equal c, new.contents |
20 | 20 | deltas = old.diff(new).loc_deltas |
21 | 21 | assert_not_nil deltas |