Version 4.1.0

This commit is contained in:
Aaron Power 2016-08-08 09:18:32 +01:00
parent e44a0c7ce7
commit d5fa7da937
9 changed files with 118 additions and 72 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ target
src/test
.settings
.commit_message
*.bk
*.bk
*.rustfmt

View File

@ -1,3 +1,13 @@
# 4.1.0
Tokei is now **~40%** faster.
**Added languages**
- Ada
- Forth
# 4.0.0
Tokei now has a minimal version without `serde` for faster compilation.

20
Cargo.lock generated
View File

@ -23,7 +23,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "aster"
version = "0.22.0"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syntex_syntax 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -51,7 +51,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"term_size 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -93,7 +93,7 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -116,7 +116,7 @@ name = "num_cpus"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -133,7 +133,7 @@ name = "quasi_codegen"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"aster 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_errors 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_syntax 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -144,7 +144,7 @@ name = "rand"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -186,7 +186,7 @@ name = "serde_codegen"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"aster 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen_internals 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -242,7 +242,7 @@ name = "syntex_errors"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_pos 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -264,7 +264,7 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex_errors 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -287,7 +287,7 @@ name = "term_size"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View File

@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
name = "tokei"
readme = "README.md"
repository = "https://github.com/Aaronepower/tokei.git"
version = "4.0.0"
version = "4.1.0"
[[bin]]
doc = false

View File

@ -5,7 +5,7 @@ about: Count Code, Quickly.
author: Aaron P. <theaaronepower@gmail.com>
bin_name: Tokei
name: Tokei
version: 4.0.0
version: 4.1.0
args:
- exclude:
help: Ignore all files & directories containing the word.

View File

@ -15,6 +15,8 @@ use self::LanguageType::*;
pub enum LanguageType {
/// ActionScript
ActionScript,
/// Ada
Ada,
/// Assembly
Assembly,
/// Autoconf
@ -55,6 +57,8 @@ pub enum LanguageType {
DeviceTree,
/// Erlang
Erlang,
/// Forth
Forth,
/// FortranLegacy
FortranLegacy,
/// FortranModern
@ -177,6 +181,7 @@ impl LanguageType {
pub fn name(&self) -> &'static str {
match *self {
ActionScript => "ActionScript",
Ada => "Ada",
Assembly => "Assembly",
Autoconf => "Autoconf",
Bash => "BASH",
@ -197,6 +202,7 @@ impl LanguageType {
Dart => "Dart",
DeviceTree => "Device Tree",
Erlang => "Erlang",
Forth => "Forth",
FortranLegacy => "FORTRAN Legacy",
FortranModern => "FORTRAN Modern",
Go => "Go",
@ -266,6 +272,7 @@ impl LanguageType {
if let Some(extension) = get_extension(entry) {
match &*extension {
"as" => Some(ActionScript),
"ada" | "adb" | "ads" => Some(Ada),
"bash" | "sh" => Some(Bash),
"bat" | "btm" | "cmd" => Some(Batch),
"c" | "ec" | "pgc" => Some(C),
@ -282,6 +289,7 @@ impl LanguageType {
"dts" | "dtsi" => Some(DeviceTree),
"el" | "lisp" | "lsp" => Some(Lisp),
"erl" | "hrl" => Some(Erlang),
"4th" | "forth" | "fr" | "frt" | "fth" | "f83" | "fb" | "fpm" | "e4" | "rx" | "ft" => Some(Forth),
"f" | "for" | "ftn" | "f77" | "pfo" => Some(FortranLegacy),
"f03" | "f08" | "f90" | "f95" => Some(FortranModern),
"go" => Some(Go),
@ -352,6 +360,7 @@ impl From<String> for LanguageType {
fn from(from: String) -> Self {
match &*from {
"ActionScript" => ActionScript,
"Ada" => Ada,
"Assembly" => Assembly,
"Autoconf" => Autoconf,
"Bash" => Bash,
@ -372,6 +381,7 @@ impl From<String> for LanguageType {
"Dart" => Dart,
"DeviceTree" => DeviceTree,
"Erlang" => Erlang,
"Forth" => Forth,
"FortranLegacy" => FortranLegacy,
"FortranModern" => FortranModern,
"Go" => Go,

View File

@ -274,6 +274,7 @@ impl Languages {
use super::LanguageType::*;
let map = btreemap! {
ActionScript => Language::new_c(),
Ada => Language::new_single(vec!["--"]),
Assembly => Language::new_single(vec![";"]),
Autoconf => Language::new_single(vec!["#", "dnl"]),
Bash => Language::new_hash(),
@ -294,6 +295,7 @@ impl Languages {
Dart => Language::new_c(),
DeviceTree => Language::new_c(),
Erlang => Language::new_single(vec!["%"]),
Forth => Language::new(vec!["\\"], vec![("(", ")")]),
FortranLegacy => Language::new_single(vec!["c","C","!","*"]),
FortranModern => Language::new_single(vec!["!"]),
Go => Language::new_c(),

View File

@ -1,9 +1,9 @@
#[macro_use]
mod utils;
mod language;
mod stats;
mod sort;
pub use language::{LanguageType, Languages, Language};
pub use stats::Stats;
pub use sort::Sort;
#[macro_use]
mod utils;
mod language;
mod stats;
mod sort;
pub use language::{LanguageType, Languages, Language};
pub use stats::Stats;
pub use sort::Sort;

View File

@ -20,41 +20,63 @@ pub fn has_trailing_comments(line: &str,
comment_end: &'static str,
nested: bool)
-> bool {
let mut in_comments: usize = 0;
for chars in line.chars().collect::<Vec<char>>().windows(comment.len()) {
let window = {
let mut window = String::new();
for ch in chars {
window.push(*ch);
}
window
};
let mut is_in_comments: u8 = 0;
if window == comment {
if nested {
in_comments += 1;
if let Some(start) = line.find(comment) {
if let Some(end) = line.rfind(comment_end) {
let section = &line[start..end + comment_end.len()];
let length = if comment.len() > comment_end.len() {
comment.len()
} else {
in_comments = 1;
comment_end.len()
};
let vec = section.chars().collect::<Vec<char>>();
for chars in vec.windows(length) {
let window = {
let mut window = String::new();
for ch in chars {
window.push(*ch);
}
window
};
if window.contains(comment) {
if nested {
is_in_comments += 1;
} else {
is_in_comments = 1;
}
continue;
} else if window.contains(comment_end) {
if nested && is_in_comments != 0 {
is_in_comments -= 1;
} else {
is_in_comments = 0;
}
continue;
}
}
continue;
} else if window == comment_end {
if nested && in_comments != 0 {
in_comments -= 1;
} else {
in_comments = 0;
}
continue;
} else {
is_in_comments = 1;
}
}
in_comments != 0
is_in_comments != 0
}
pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
ignored_directories: Cow<'a, [&'a str]>,
languages: &mut BTreeMap<LanguageType, Language>) {
for path in &*paths {
// A small metadata check to check if the file actually exists, this is used over calling
// File::open because we're going to be passing the path to either glob() or WalkDir::new()
// A small metadata check to check if the file actually exists,
// this is used over calling File::open because we're going to be
// passing the path to either glob() or WalkDir::new()
if let Err(_) = Path::new(path).metadata() {
if let Ok(paths) = glob(path) {
'path: for path in paths {
@ -68,8 +90,9 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
let mut language = if opt_or_cont!(path.to_str()).contains("Makefile") {
languages.get_mut(&Makefile).unwrap()
} else {
opt_or_cont!(
languages.get_mut(&opt_or_cont!(LanguageType::from_extension(&path))))
opt_or_cont!(
languages.get_mut(
&opt_or_cont!(LanguageType::from_extension(&path))))
};
language.files.push(path.to_owned());
@ -91,8 +114,8 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
let mut language = if opt_or_cont!(entry.path().to_str()).contains("Makefile") {
languages.get_mut(&Makefile).unwrap()
} else {
opt_or_cont!(
languages.get_mut(&opt_or_cont!(LanguageType::from_extension(entry.path())))
opt_or_cont!(
languages.get_mut(&opt_or_cont!(LanguageType::from_extension(entry.path())))
)
};
@ -104,47 +127,47 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
pub fn get_extension<P: AsRef<Path>>(path: P) -> Option<String> {
let path = path.as_ref();
match path.extension() {
match path.extension() {
Some(extension_os) => {
match extension_os.to_str() {
Some(extension) => Some(extension.to_lowercase()),
None => None,
match extension_os.to_str() {
Some(extension) => Some(extension.to_lowercase()),
None => None,
}
}
}
None => {
match get_filetype_from_shebang(path) {
match get_filetype_from_shebang(path) {
// Using String::from here because all file extensions from
// get_filetype_from_shebang are guaranteed to be lowercase.
Some(extension) => Some(String::from(extension)),
None => None,
Some(extension) => Some(String::from(extension)),
None => None,
}
}
}
}
}
/// This is for getting the file type from the first line of a file
pub fn get_filetype_from_shebang<P: AsRef<Path>>(file: P) -> Option<&'static str> {
let file = match File::open(file) {
Ok(file) => file,
_ => return None,
let file = match File::open(file) {
Ok(file) => file,
_ => return None,
};
let mut buf = BufReader::new(file);
let mut line = String::new();
let _ = buf.read_line(&mut line);
let mut words = line.split_whitespace();
match words.next() {
Some("#!/bin/sh") => Some("sh"),
Some("#!/bin/csh") => Some("csh"),
Some("#!/usr/bin/perl") => Some("pl"),
match words.next() {
Some("#!/bin/sh") => Some("sh"),
Some("#!/bin/csh") => Some("csh"),
Some("#!/usr/bin/perl") => Some("pl"),
Some("#!/usr/bin/env") => {
match words.next() {
Some("python") | Some("python2") | Some("python3") => Some("py"),
Some("sh") => Some("sh"),
_ => None,
match words.next() {
Some("python") | Some("python2") | Some("python3") => Some("py"),
Some("sh") => Some("sh"),
_ => None,
}
}
_ => None,
}
_ => None,
}
}