Skip to content

Commit e7844ab

Browse files
committed
Change to support running cloc with provided binary path
1 parent 9c3b1cd commit e7844ab

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

src/main/rascal/lang/php/util/CLOC.rsc

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,26 @@ import IO;
1717
import String;
1818
import List;
1919

20-
import lang::php::ast::System;
2120
import lang::php::util::Corpus;
2221
import lang::php::util::Utils;
2322

24-
public int phpLinesOfCode(loc l) {
25-
pid = createProcess("/cwi/bin/perl", args = ["/ufs/hills/project/cloc/cloc-1.53.pl", "--read-lang-def=/ufs/hills/project/cloc/ld.txt", "<l.path>"]);
23+
data ClocResult
24+
= clocResult(int files, int blankLines, int commentLines, int sourceLines)
25+
| noResult()
26+
;
27+
28+
@doc{
29+
Compute the source lines of code for a given location. This location
30+
could be a single file or a directory.
31+
}
32+
public ClocResult phpLinesOfCode(loc l, loc clocPath) {
33+
pid = createProcess(clocPath.path, args = [l.path]);
2634
res = readEntireStream(pid);
2735
killProcess(pid);
2836
if(/PHP\s+<n1:\d+>\s+<n2:\d+>\s+<n3:\d+>\s+<n4:\d+>/ := res) {
29-
return toInt(n4);
37+
return clocResult(toInt(n1), toInt(n2), toInt(n3), toInt(n4));
3038
} else {
3139
println("Odd, no PHP code found in file <l.path>");
32-
return 0;
40+
return noResult();
3341
}
3442
}
35-
36-
public map[loc,int] locsForProduct(str p, str v) {
37-
System s = loadBinary(p,v);
38-
return ( l : phpLinesOfCode(l) | l <- s.files );
39-
}
40-
41-
public void locsForProducts() {
42-
lv = getLatestVersions();
43-
map[loc,int] res = ( );
44-
45-
str header = "product, version, file, phplines\n";
46-
writeFile(|rascal://src/lang/php/extract/csvs/linesPerFile.csv|, header);
47-
48-
for (p <- lv) {
49-
res = locsForProduct(p,lv[p]);
50-
appendToFile(|rascal://src/lang/php/extract/csvs/linesPerFile.csv|, intercalate("\n",["<p>,<lv[p]>,<l.path>,<res[l]>" | l <- res]) + "\n");
51-
}
52-
53-
}

0 commit comments

Comments
 (0)