Skip to content

Commit

Permalink
chore: apply v fmt to wc/
Browse files Browse the repository at this point in the history
  • Loading branch information
igrekus committed Dec 22, 2023
1 parent c36e12d commit 0852435
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/wc/wc.v
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ fn get_count(chunk FileChunk, last_line_length u32) (Count, u32) {

for b in chunk.buffer {
match b {
`\r` { continue } // TODO handle windows \r\n
`\r` {
continue
} // TODO handle windows \r\n
new_line {
count.line_count++
prev_char_is_space = true
Expand Down Expand Up @@ -160,26 +162,23 @@ fn get_files(args []string) []Pair {
} else {
mut files := []Pair{}
for file_path in args {
files << Pair{
file_path,
os.open(file_path) or {
eprintln('${application_name}: ${file_path}: No such file or directory')
exit(1)
}
}
files << Pair{file_path, os.open(file_path) or {
eprintln('${application_name}: ${file_path}: No such file or directory')
exit(1)
}}
}
return files
}
}

fn get_file_names_from_list_file(list_file string) []string {
return (os.read_file(list_file) or {
eprintln('${application_name}: ${list_file}: error reading file - $err')
eprintln('${application_name}: ${list_file}: error reading file - ${err}')
exit(1)
}).split(file_list_sep)
}

fn get_file_names_from_stdin_stream() [] string {
fn get_file_names_from_stdin_stream() []string {
return os.get_line().split(file_list_sep)
}

Expand All @@ -206,7 +205,9 @@ fn main() {
mut lines_opt := fp.bool('lines', `l`, false, 'print the newline counts')
mut words_opt := fp.bool('words', `w`, false, 'print the words counts')
maxline_opt := fp.bool('max-line-length', `L`, false, 'print the maximum display width')
list_file := fp.string_opt('files0-from', 0, 'read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input') or { '' }
list_file := fp.string_opt('files0-from', 0, 'read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input') or {
''
}

mut args := fp.finalize() or {
eprintln(err)
Expand Down Expand Up @@ -274,9 +275,8 @@ fn main() {
}
}

min_col_size := arrays.max(
[total_line_count_len, total_word_count_len, total_byte_count_len, total_char_count_len, max_line_length_len]
) or { panic(err) }
min_col_size := arrays.max([total_line_count_len, total_word_count_len, total_byte_count_len,
total_char_count_len, max_line_length_len]) or { panic(err) }
if results.len > 1 && col_size < min_col_size {
col_size = min_col_size
}
Expand Down
2 changes: 0 additions & 2 deletions src/wc/wc_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ fn test_words_count() {
assert res.output == '5 ${test1_txt_path}${eol}'
}


fn test_one_file_all_flags() {
res := os.execute('${executable_under_test} -cmwlL ${test1_txt_path}')

Expand Down Expand Up @@ -171,4 +170,3 @@ fn test_under_16k_line_counts_max_line() {
assert res.exit_code == 0
assert res.output.trim_space() == '1 2 16401 16401 16383 ${long_under_16k}'
}

0 comments on commit 0852435

Please sign in to comment.