$ cd path/to/project/dir
$ numlines
If you want to filter out someone else's code (say you have code from the Growl framework) you run it like this:
$ numlines Growl
If "Growl" is in the filename (case-sensitive) then it won't be counted as part of the total.
Code: Select all
#!/usr/bin/newlisp
; numlines
(constant 'S_IFLNK 40960)
(constant 'SIGINT 2)
(constant 'extensions '(".h" ".cpp" ".c" ".cc" ".m" ".java" ".lsp" ".lisp" ".sh" ".py" ".rb"))
(set 'total 0)
(define (string-contains L str)
(!= '() (filter (fn (x) (find x str)) L))
)
(define (string-ends-with L str)
(!= '() (filter (fn (x) (ends-with str x)) L))
)
(define (ctrlC-handler)
(println "Total lines so far: " total)
(exit 1)
)
(define (num-lines-in-file file , (num 0) fd)
(if (string-ends-with extensions file)
(if (string-contains (2 (main-args)) file)
(if (> (length (2 (main-args))) 0)
(println "skipping file: " file)
)
(begin
(set 'fd (open file "r"))
(if fd
(begin
(while (read-line fd) (inc 'num))
(close fd)
(println num "\t\tlines in: " file)
)
(println "*** couldn't open: " file)
)
)
)
)
(inc 'total num)
)
(define (num-lines-in-dir dir)
(change-dir dir)
(dolist (e (directory))
(if (!= "." (e 0))
(if (directory? e)
(if (= 0 (& S_IFLNK (file-info e 1)))
(num-lines-in-dir e)
(println "skipping symbolic link: " e)
)
(num-lines-in-file e)
)
)
)
(change-dir "..")
)
; begin program
(signal SIGINT 'ctrlC-handler)
(num-lines-in-dir ".")
(println "Total: " total " lines")
(exit)