forked from Dhananjay-shrivastav/CxxPrimerPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countLine.R
44 lines (37 loc) · 1 KB
/
countLine.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
countLine <- function(sourcefile) {
## read source code
x <- readLines(sourcefile)
## remove blank line
x <- x[x!=""]
## remove comment line of start from //
idx <- grep("^\\s*//", x)
if(length(idx)) {
x <- x[-idx]
}
## counting c++ source code
## start from the first #include line.
start <- grep("#include", x)[1]
if (is.na(start)) {
## header file
return (length(x))
}
n <- length(x) - start + 1
return(n)
}
folders <- paste("chapter", c(2:18), sep="")
allLen <- rep(0, length(folders))
names(allLen) <- folders
for (i in seq_along(folders)) {
cpp_files <- list.files(folders[i], pattern=".cpp$")
header_files <- list.files(folders[i], pattern=".h$")
files <- c(cpp_files, header_files)
len <- 0
for (f in files) {
file <- paste(folders[i], "/", f, sep="")
len <- len + countLine(file)
}
allLen[i] <- len
}
barplot(allLen, las=2,
main=paste("Total Lines", sum(allLen)),
col=rainbow(length(allLen)))