From 49eaf55b95230a9359335dfa363eb697fbb2da27 Mon Sep 17 00:00:00 2001 From: osmarks Date: Sat, 30 Jan 2021 13:06:46 +0000 Subject: [PATCH] grep program --- manifest | 4 ++-- src/bin/grep.lua | 36 ++++++++++++++++++++++++++++++++++++ src/main.lua | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/bin/grep.lua diff --git a/manifest b/manifest index 00a76fe..2690ca5 100644 --- a/manifest +++ b/manifest @@ -1,2 +1,2 @@ -{"build":188,"description":"heavlisp stdlib bundling fix (throwerror should really throw an error)","files":{"LICENSES":"f3549d84d66eb53dd4a421a4341d77d3d217c1b117d67e3be8f5211adcda0952","autorun.lua":"af5c21733a989d61aaed06788d818bbc96a3f7e13e16c57c9bf4d833b6cc3848","bin/5rot26.lua":"91b66cd6d4b33081b25c456142dd7efcb894e819e842693c9e1e17ff48872ff5","bin/ccemux.lua":"239476f58835b86bbcac31ce8af3c3acd3d198a55ab9ada78c62fbf358625a98","bin/chronometer.lua":"db5363993a04382145aef7db2fbe262f0bf10697a589e1e2d2f9ce0f87430dd8","bin/kristminer.lua":"7e7f9fe2a6493d584ad6926cda915e02c1c3d800dc209680898ce930d0bb0e6f","bin/livegps.lua":"c3d17d495cda01aa1261e4c4fcd43439b29af422671972117ec34f68e32c5bba","bin/loading.lua":"c85f7aa1765170325155b921c1fceeb62643f552f12d41b529a22af3a67f5a97","bin/potatoflight.lua":"2fbb0b6f8d78728d8cb0ec64af1bc598bd00cb55f202378e7acdb86bba71efd1","bin/potatoplex.lua":"86c9e7597bbe23d7de7e7f1bfc976d0b94dcdf3af9e6c7c6c9b18b98596898c8","bin/relay.lua":"261ae6c220b83506e3326e8f2b091d246baae458ff0d2ee87512be2c4e35a75d","bin/tryhaskell.lua":"07810d85145da65a3e434154c79d5a9d72f2dcbe59c8d6829040fb925df878ec","potatobios.lua":"7593e0f9d0755eea05e3c0fff5c4c9e036745a8cbc20e9e19609d8743a77b87e","signing-key.tbl":"b32af5229c23af3bc03d538e42751b26044e404a7b1af064ed89894efe421607","startup":"f17bfb9b4322c4467dc9170d50827f2d75717e5c3125d734f21f3406657917bc","stdlib.hvl":"a6fd2620068f47794a9bbeed77bee3fd4962f848e6dd7c75137b30cd5665272e","update-key.hex":"8d8afb7a45833bb7d68f929421ad60a211d4d73e0ee03b24dc0106ba1de2e1a0","xlib/00_cbor.lua":"464b075e4f094b8db42506bd4bdaad0db87699ea7fbf80e5b87739b4aa9279af","xlib/01_skynet.lua":"9cb565d639a0acd7c763c3e7422482532cd0bda0cdfcc720089ab4a87e551339","xlib/03_heavlisp.lua":"82cdabd5286058c0ea4f27956f8c1144e198769c8b8ce9e91b26c930d711f710"},"sizes":{"LICENSES":4725,"autorun.lua":182346,"bin/5rot26.lua":914,"bin/ccemux.lua":1673,"bin/chronometer.lua":1152,"bin/kristminer.lua":5566,"bin/livegps.lua":980,"bin/loading.lua":7707,"bin/potatoflight.lua":3417,"bin/potatoplex.lua":6526,"bin/relay.lua":3075,"bin/tryhaskell.lua":1867,"potatobios.lua":71272,"signing-key.tbl":190,"startup":8313,"stdlib.hvl":851,"update-key.hex":44,"xlib/00_cbor.lua":15808,"xlib/01_skynet.lua":3286,"xlib/03_heavlisp.lua":15643},"timestamp":1611963170} -{"hash":"68bbb5e12a6d76f3a5d38ba953a0b921bb609747daf61d18b9742e3f84ed7e63","sig":"c19cad6e6cb04d899318a782861cb0c0a59012f517519c11413125f92e7317d1ba1f5406643ee18be41b"} \ No newline at end of file +{"build":189,"description":"grep program","files":{"LICENSES":"f3549d84d66eb53dd4a421a4341d77d3d217c1b117d67e3be8f5211adcda0952","autorun.lua":"b93bd7db544007665e23f7a9e3f5bdc3af1c7280db82d71a49ce77f25edb13ef","bin/5rot26.lua":"91b66cd6d4b33081b25c456142dd7efcb894e819e842693c9e1e17ff48872ff5","bin/ccemux.lua":"239476f58835b86bbcac31ce8af3c3acd3d198a55ab9ada78c62fbf358625a98","bin/chronometer.lua":"db5363993a04382145aef7db2fbe262f0bf10697a589e1e2d2f9ce0f87430dd8","bin/grep.lua":"1509bc267867b933e528ab74cfbc2a15fa2df0ec7389df4f9033194ab9037865","bin/kristminer.lua":"7e7f9fe2a6493d584ad6926cda915e02c1c3d800dc209680898ce930d0bb0e6f","bin/livegps.lua":"c3d17d495cda01aa1261e4c4fcd43439b29af422671972117ec34f68e32c5bba","bin/loading.lua":"c85f7aa1765170325155b921c1fceeb62643f552f12d41b529a22af3a67f5a97","bin/potatoflight.lua":"2fbb0b6f8d78728d8cb0ec64af1bc598bd00cb55f202378e7acdb86bba71efd1","bin/potatoplex.lua":"86c9e7597bbe23d7de7e7f1bfc976d0b94dcdf3af9e6c7c6c9b18b98596898c8","bin/relay.lua":"261ae6c220b83506e3326e8f2b091d246baae458ff0d2ee87512be2c4e35a75d","bin/tryhaskell.lua":"07810d85145da65a3e434154c79d5a9d72f2dcbe59c8d6829040fb925df878ec","potatobios.lua":"7593e0f9d0755eea05e3c0fff5c4c9e036745a8cbc20e9e19609d8743a77b87e","signing-key.tbl":"b32af5229c23af3bc03d538e42751b26044e404a7b1af064ed89894efe421607","startup":"f17bfb9b4322c4467dc9170d50827f2d75717e5c3125d734f21f3406657917bc","stdlib.hvl":"a6fd2620068f47794a9bbeed77bee3fd4962f848e6dd7c75137b30cd5665272e","update-key.hex":"8d8afb7a45833bb7d68f929421ad60a211d4d73e0ee03b24dc0106ba1de2e1a0","xlib/00_cbor.lua":"464b075e4f094b8db42506bd4bdaad0db87699ea7fbf80e5b87739b4aa9279af","xlib/01_skynet.lua":"9cb565d639a0acd7c763c3e7422482532cd0bda0cdfcc720089ab4a87e551339","xlib/03_heavlisp.lua":"82cdabd5286058c0ea4f27956f8c1144e198769c8b8ce9e91b26c930d711f710"},"sizes":{"LICENSES":4725,"autorun.lua":182345,"bin/5rot26.lua":914,"bin/ccemux.lua":1673,"bin/chronometer.lua":1152,"bin/grep.lua":1196,"bin/kristminer.lua":5566,"bin/livegps.lua":980,"bin/loading.lua":7707,"bin/potatoflight.lua":3417,"bin/potatoplex.lua":6526,"bin/relay.lua":3075,"bin/tryhaskell.lua":1867,"potatobios.lua":71272,"signing-key.tbl":190,"startup":8313,"stdlib.hvl":851,"update-key.hex":44,"xlib/00_cbor.lua":15808,"xlib/01_skynet.lua":3286,"xlib/03_heavlisp.lua":15643},"timestamp":1612011951} +{"hash":"ec458d2a2dc6d17253414d89071379e83a572194a4debfc17a6c6ec20735cc27","sig":"3046d409d01d8bc3a6958194ff70d771b35c3129130ef308f6d5b7d62ea19e209028819ec3af6cd88103"} \ No newline at end of file diff --git a/src/bin/grep.lua b/src/bin/grep.lua new file mode 100644 index 0000000..560d151 --- /dev/null +++ b/src/bin/grep.lua @@ -0,0 +1,36 @@ +local pattern, file = ... +if not pattern then error "At least a pattern is required" end +if file and not fs.exists(file) then error(("%s does not exist"):format(file)) end +if not file then file = "." end + +local function scan_file(filepath) + local filepath = fs.combine(filepath, "") + if fs.isDir(filepath) then + for _, basename in pairs(fs.list(filepath)) do + scan_file(fs.combine(filepath, basename)) + end + return + end + local fh = fs.open(filepath, "r") + local count = 1 + local has_printed_filename = false + while true do + local line = fh.readLine() + if line == nil then break end + if line:match(pattern) then + if not has_printed_filename then + if term.isColor() then term.setTextColor(colors.blue) end + print(filepath) + end + if term.isColor() then term.setTextColor(colors.lime) end + write(tostring(count) .. ": ") + if term.isColor() then term.setTextColor(colors.white) end + textutils.pagedPrint(line) + has_printed_filename = true + end + count = count + 1 + end + fh.close() +end + +scan_file(file) \ No newline at end of file diff --git a/src/main.lua b/src/main.lua index 7c08523..28ed71b 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1223,7 +1223,7 @@ if mfst then verified = ("false %s"):format(tostring(mfst.verification_error)) end end - print("Signature verified:", verified) + print("Signature verified", verified) else print "Manifest not found in registry. Extended data unavailable." end