hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/gils/wc.rv
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-09 11:08:09 +0200
committerhachem <im@hachem.wtf>2026-10-09 11:08:09 +0200
commite0572c37d970d601c17085bdb082cc6ef4356891 (patch)
treef0b4d71c92978e74d127d7090d3e11380378a8b3 /gils/wc.rv
parent8cb66100fe802c38d180ea29a11a902decf0fd8b (diff)
chore: fmt some revo code based on lung's example
Diffstat (limited to 'gils/wc.rv')
-rw-r--r--gils/wc.rv26
1 files changed, 18 insertions, 8 deletions
diff --git a/gils/wc.rv b/gils/wc.rv
index 1127299..75a3ed2 100644
--- a/gils/wc.rv
+++ b/gils/wc.rv
@@ -1,22 +1,32 @@
# word count
const context = env.ctx
-if context.argv:len() < 2 do fail("usage: wc <path>\n") end
-else do
+if context.argv:len() < 2 do
+ fail("usage: wc <path>\n")
+end else do
const path = expand_path(context.argv[1])
const size = fs:size(path)
- if size < 0 do fail("wc: #{path}: no such file\n") end
- else do
- const contents = if size > 0 fs:read_bytes(path, 0, size) else ""
+
+ if size < 0 do
+ fail("wc: #{path}: no such file\n")
+ end else do
+ const contents = if (size > 0) fs:read_bytes(path, 0, size) else ""
let line_count = 0
let word_count = 0
let in_word = :false
+
for index in 0..contents:len() do
const character = contents[index]
- if character == "\n" do line_count += 1 end
- if (character == " " or character == "\n" or character == "\t") do in_word = :false end
- else if in_word == :false do word_count += 1 in_word = :true end
+ if (character == "\n")
+ line_count += 1
+ if character == " " or character == "\n" or character == "\t" do
+ in_word = :false
+ end else if in_word == :false do
+ word_count += 1
+ in_word = :true
+ end
end
+
puts(" #{line_count} #{word_count} #{size} #{context.argv[1]}\n")
end
end