Last active
December 29, 2021 16:57
-
-
Save eschen42/3311774c5a7b93c767cee7d6b9cf4328 to your computer and use it in GitHub Desktop.
Count tabs per line; flag when number differs from number in first line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count tabs per line; flag when number differs from number in first line | |
# | |
# Execute with `icon tabCount.icn tsv_file -1` | |
# See [the Icon website](https://cs.arizona.edu/icon) for further info about the Icon programming language. | |
# | |
procedure main(args) | |
# args[1] = input file | |
# args[2] = number of lines (optional, default = 3) | |
local expected | |
local input_file | |
local line | |
local line_number | |
local lines_read | |
local num_lines | |
local result | |
local tab_count | |
input_file := open(args[1], "r") | | |
stop("usage: " || &progname || " input_file [numer_of_lines]") | |
num_lines := integer(args[2]) | 3 | |
result := 0 | |
line_number := 0 | |
while num_lines ~= 0 & line := read(input_file) do { | |
line_number +:= 1 | |
num_lines -:= 1 | |
tab_count := 0 | |
line ? while tab(upto('\t')) do { | |
tab_count +:= 1 | |
move(1) | |
} | |
if num_lines > -1 | |
then write(tab_count) | |
if /expected | |
then expected := tab_count | |
else if tab_count ~= expected | |
then { | |
result +:= 1 | |
write("For file '" || args[1] || | |
"', line number " || line_number || " has " || | |
tab_count || " tabs but " || expected || " were expected" | |
) | |
} | |
} | |
close(input_file) | |
exit(result) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute with
See the Icon website for further info about the Icon programming language.