From 14d02fe692cedeb82cc5184bf47c8fcae839f105 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 17 Dec 2022 23:07:13 -0500 Subject: [PATCH 01/23] better release profile --- Cargo.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Cargo.toml diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ead9c5d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "tomcat" +version = "0.0.1" +edition = "2021" +license = "AGPL-3.0-or-later" +authors = [ "Emma Tebibyte " ] + +[dependencies] +toml = "0.5.9" + +[profile.release] +strip = true # strip symbols from the binary +opt-level = "z" # optimize for size +lto = true # link time optimization +codegen-units = 1 # decrease parallelization +panic = "abort" From 471161c1a366b769f145fc5e535c0c32388f9fd8 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 18 Dec 2022 00:37:13 -0500 Subject: [PATCH 02/23] initial commit: reads table-less keys from argument only --- Cargo.lock | 25 ++++++++++++++++++ src/main.rs | 45 +++++++++++++++++++++++++++++++++ tomcat | 73 ----------------------------------------------------- 3 files changed, 70 insertions(+), 73 deletions(-) create mode 100644 Cargo.lock create mode 100644 src/main.rs delete mode 100755 tomcat diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4fd7cf7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "serde" +version = "1.0.148" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" + +[[package]] +name = "tomcat" +version = "0.0.1" +dependencies = [ + "toml", +] + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1ae6881 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +// Copyright (c) 2022 Emma Tebibyte +// SPDX-License-Identifier: AGPL-3.0-or-later + +/* Tomcat is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Tomcat is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +use std::env; +use std::fs::File; +use std::io::Read; +use std::path::Path; + +use toml::Value; + +fn main() { + let arguments: Vec = env::args().collect(); + let argv0 = &arguments[0]; + let input = &arguments[2]; + let mut content = String::new(); + + let file = Path::new(&input); + if file.is_file() { + let mut content = String::new(); + File::open(file).expect("").read_to_string(&mut content).unwrap(); + println!("{}", content); + } else { content = input.to_string(); } + + let keyval: Vec<&str> = arguments[1].split(".").collect(); + let mut toml = content.parse::().unwrap(); + + match toml.get(keyval[1]) { + Some(value) => println!("{}", value), + None => println!("{}: {}: No such table or key.", argv0, arguments[1]), + }; +} diff --git a/tomcat b/tomcat deleted file mode 100755 index f59bac2..0000000 --- a/tomcat +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh - -set -e - -argv0="$0" -argv1="$1" -argv2="$2" - -# check usage -if ! test -n "$1"; then - printf "Usage: %s [OPTIONS] [TABLE.KEY[INDEX]] [FILE]\n" "$0" 1>&2 - exit 64 # sysexits(3) EX_USAGE -fi - -# test if input has a period -if test -n "$(printf "%s\n" "$argv1" | sed -n '/.*\..*/p')"; then - # cut out everything beyond the first period for TABLE - TABLE=$(printf "%s\n" "$argv1" | sed -n 's/\..*//p') - - # cut out everything before the first period for KEY - KEY=$(printf "%s\n" "$argv1" | sed -n 's/^[^.]*\.//p') - ! test -n "$KEY" &&\ - printf "%s: No key specified\n" "$argv0" 1>&2 &&\ - exit 65 # sysexits(3) EX_DATAERR -else - printf "%s: No key specified\n" "$argv0" 1>&2 - exit 65 # sysexits(3) EX_DATAERR -fi - -# remove array index from KEY -KEY=$(printf "%s\n" "$KEY" | sed 's/\[.*\]//g') -# set ARR to the array index -ARR=$(printf "%s\n" "$argv1" | sed -n 's/.\+\[//p' | tr -d ']') - -# test if argument 2 is a file or not -if test -e "$argv2"; then - # set TOML to the text from the file - TOML=$(sed 's/[^"#]#\+.*//g' <"$argv2" | sed 's/^#.*//g' ) -else - # set TOML to the text from stdin - TOML=$(printf "%s\n" "$argv2" | sed 's/[^"#]#\+.*//g') -fi - -if test -n "$TABLE"; then - KEYS=$(printf "%s\n" "$TOML" |\ - # output only lines between TABLE and the next table - awk "/^\[$TABLE\]/{flag=1; next} /^\[/{flag=0} flag" - ) -else - KEYS=$(printf "%s\n" "$TOML" |\ - # output only lines before the first table - awk '1;/^\[/{exit}' - | sed -n '/^[^[]/p') -fi - -# set VAL to the parsed KEYS list -VAL=$(printf "%s\n" "$KEYS" |\ - # remove the key from the string and delineate arrays, removing - # brackets, trailing commas, and leading spaces - sed -n "s/$KEY *= *//p" | sed 's/", "/ /g' | tr -d '[]"' |\ - sed 's/, *$//g' | sed 's/^ \+//g' | sed 's/ \+$//g') - -# test if ARR is set; if it is, then we have an array index to grab -if test -n "$ARR"; then - # change the line delineator to newlines for parsing and output the result - printf "%s\n" "$VAL" | sed 's/ /\n/g' | head -n "$ARR" |\ - tail -n 1 -elif ! test -n "$VAL"; then - printf "%s: %s: No such key or table\n" "$argv0" "$argv1" 1>&2 - exit 65 # sysexits(3) EX_DATAERR -else - printf "%s\n" "$VAL" -fi - -exit 0 From a8a1284ae1942326fc59d7192935c588975a044d Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 18 Dec 2022 00:39:14 -0500 Subject: [PATCH 03/23] i am silly --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1ae6881..fb00f65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,13 +30,11 @@ fn main() { let file = Path::new(&input); if file.is_file() { - let mut content = String::new(); File::open(file).expect("").read_to_string(&mut content).unwrap(); - println!("{}", content); } else { content = input.to_string(); } let keyval: Vec<&str> = arguments[1].split(".").collect(); - let mut toml = content.parse::().unwrap(); + let toml = content.parse::().unwrap(); match toml.get(keyval[1]) { Some(value) => println!("{}", value), From f4f972c5d6cba7019e28648f6332b0bc1d96b1dc Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 18 Dec 2022 14:39:56 -0500 Subject: [PATCH 04/23] works now, but doesnt like when i use "table." syntax --- src/main.rs | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index fb00f65..23b9cdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,27 +17,54 @@ use std::env; use std::fs::File; +use std::io; use std::io::Read; use std::path::Path; +use std::process; use toml::Value; fn main() { - let arguments: Vec = env::args().collect(); - let argv0 = &arguments[0]; - let input = &arguments[2]; + let mut arguments: Vec = env::args().collect(); + let argv0 = arguments.remove(0); + let input = &arguments[1]; let mut content = String::new(); - let file = Path::new(&input); + let mut file = Path::new(&input); if file.is_file() { - File::open(file).expect("").read_to_string(&mut content).unwrap(); + File::open(file).unwrap().read_to_string(&mut content).unwrap(); } else { content = input.to_string(); } - let keyval: Vec<&str> = arguments[1].split(".").collect(); + let keyval: Vec<&str> = arguments[0].split(".").collect(); let toml = content.parse::().unwrap(); - - match toml.get(keyval[1]) { - Some(value) => println!("{}", value), - None => println!("{}: {}: No such table or key.", argv0, arguments[1]), - }; + + let mut table = &toml; + if ! keyval[0].is_empty() { + match toml.get(keyval[0]) { + Some(table) => { + if keyval[1].is_empty() { + println!("{}", table.as_str().unwrap()); + } else { + match table.get(keyval[1]) { + Some(value) => { + let out = value + .as_str() + .unwrap() + .trim_start_matches('"') + .trim_end_matches('"'); + println!("{}", out); + }, + None => { + eprintln!("{}: {}: No such key.", argv0, keyval[1]); + process::exit(1); + }, + }; + } + }, + None => { + eprintln!("{}: {}: No such table.", argv0, keyval[0]); + process::exit(1); + }, + }; + } } From eaff71e7213ad6dba4caf9038c5ca351d87a42ed Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 00:41:14 -0500 Subject: [PATCH 05/23] better & faster parsing of toml --- src/main.rs | 63 +++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23b9cdd..269691b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ use std::env; use std::fs::File; -use std::io; use std::io::Read; use std::path::Path; use std::process; @@ -27,44 +26,52 @@ use toml::Value; fn main() { let mut arguments: Vec = env::args().collect(); let argv0 = arguments.remove(0); + if arguments[1].is_empty() { + println!("Usage: {} [table...].[value] [file...]", argv0); + process::exit(64); // sysexits(3) EX_USAGE + } let input = &arguments[1]; let mut content = String::new(); - let mut file = Path::new(&input); + let file = Path::new(&input); if file.is_file() { File::open(file).unwrap().read_to_string(&mut content).unwrap(); } else { content = input.to_string(); } - let keyval: Vec<&str> = arguments[0].split(".").collect(); - let toml = content.parse::().unwrap(); + let tabkey: Vec<&str> = arguments[0].split(".").collect(); + let mut root = content.parse::().unwrap(); - let mut table = &toml; - if ! keyval[0].is_empty() { - match toml.get(keyval[0]) { - Some(table) => { - if keyval[1].is_empty() { - println!("{}", table.as_str().unwrap()); - } else { - match table.get(keyval[1]) { - Some(value) => { - let out = value - .as_str() - .unwrap() - .trim_start_matches('"') - .trim_end_matches('"'); - println!("{}", out); - }, - None => { - eprintln!("{}: {}: No such key.", argv0, keyval[1]); - process::exit(1); - }, - }; - } + let mut out = String::new(); + let mut valiter = tabkey.iter().peekable(); + + while let Some(item) = valiter.next() { + match root.get(item) { + Some(value) => { + match value { + // TODO: Implement other type parsing + Value::Array(_array) => {}, + Value::Boolean(_boolean) => {}, + Value::Datetime(_datetime) => {}, + Value::Float(_float) => {}, + Value::Integer(_int) => {}, + Value::String(string) => { + match valiter.peek() { + Some(next) => { + println!("{}: {}: Not a table.", argv0, item); + process::exit(65); // sysexits(3) EX_DATAERR + }, + None => out.push_str(string.as_str()), + }; + break + } + Value::Table(table) => root = toml::Value::Table(table.to_owned()), + }; }, None => { - eprintln!("{}: {}: No such table.", argv0, keyval[0]); - process::exit(1); + println!("{}: {}: No such table or key.", argv0, item); + process::exit(65); // sysexits(3) EX_DATAERR }, }; } + println!("{}", out); } From eb76b0b30d632d19de8a63623aadf945af0cfc09 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 00:46:16 -0500 Subject: [PATCH 06/23] update README --- README.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0e8f751..0b5d398 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,23 @@ -`tomcat` – a [TOML](https://toml.io) parser in POSIX shell +`tomcat` – a minimal [TOML](https://toml.io) parser for the command line. ## Installation ### From Source -Clone this repository and move the `tomcat` binary wherever your operating -system stores locally-installed binaries. This is usually `/usr/local/bin` or -`$HOME/.local/bin` for your user. Make sure the installation location is in your -`$PATH`. +1. Run `cargo --install --git https://git.tebibyte.media/emma/tomcat.git` +2. ??? +3. Profit + +## Usage + +To get the value of `key` from the `main` table in `file.toml`: + +`tomcat main.key file.toml` + +To get the top-level key `notable` from `file.toml`: + +`tomcat notable file.toml` + +To get index `3` in array `arr` inside the `main` table in `file.toml`: + +`tomcat main.arr[3] file.toml` From 3ec60dbc04fcf4e64ccc545f1aeb3aaac78de30c Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 13:51:28 -0500 Subject: [PATCH 07/23] arrays!!!!! --- src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 269691b..1ea05ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ use std::fs::File; use std::io::Read; use std::path::Path; use std::process; +use std::str::FromStr; use toml::Value; @@ -27,7 +28,7 @@ fn main() { let mut arguments: Vec = env::args().collect(); let argv0 = arguments.remove(0); if arguments[1].is_empty() { - println!("Usage: {} [table...].[value] [file...]", argv0); + eprintln!("Usage: {} [table...].[value] [file...]", argv0); process::exit(64); // sysexits(3) EX_USAGE } let input = &arguments[1]; @@ -38,7 +39,22 @@ fn main() { File::open(file).unwrap().read_to_string(&mut content).unwrap(); } else { content = input.to_string(); } - let tabkey: Vec<&str> = arguments[0].split(".").collect(); + let mut tabkey: Vec<&str> = arguments[0].split(".").collect(); + let mut indexvec: Vec<&str> = tabkey[1].split(&['[', ']'][..]).collect(); + + tabkey[1] = indexvec.remove(0); + let mut index: usize = 0; + if ! indexvec.is_empty() { + let istr = indexvec.remove(0); + match usize::from_str(istr) { + Ok(i) => index = i, + Err(_) => { + eprintln!("{}: {}: Cannot index by given value.", argv0, istr); + process::exit(65); // sysexits(3) EX_DATAERR + }, + }; + } + let mut root = content.parse::().unwrap(); let mut out = String::new(); @@ -49,26 +65,60 @@ fn main() { Some(value) => { match value { // TODO: Implement other type parsing - Value::Array(_array) => {}, + Value::Array(array) => { + match valiter.peek() { + Some(_) => { + eprintln!("{}: {}: Not a table.", argv0, item); + process::exit(65); // sysexits(3) EX_DATAERR + }, + None => { + match array.get(index) { + Some(element) => { + match element.as_str() { + Some(val) => out.push_str(val), + None => { + eprintln!( + "{}: {:?}: No value at given index.", argv0, index + ); + process::exit(65); // sysexits(3) EX_DATAERR + }, + }; + }, + None => { + eprintln!( + "{}: {:?}: No value at given index.", argv0, index + ); + process::exit(65); // sysexits(3) EX_DATAERR + }, + }; + }, + }; + }, Value::Boolean(_boolean) => {}, Value::Datetime(_datetime) => {}, Value::Float(_float) => {}, Value::Integer(_int) => {}, Value::String(string) => { match valiter.peek() { - Some(next) => { - println!("{}: {}: Not a table.", argv0, item); + Some(_) => { + eprintln!("{}: {}: Not a table.", argv0, item); process::exit(65); // sysexits(3) EX_DATAERR }, None => out.push_str(string.as_str()), }; - break - } - Value::Table(table) => root = toml::Value::Table(table.to_owned()), + }, + Value::Table(table) => { + match valiter.peek() { + Some(_) => { + root = toml::Value::Table(table.to_owned()); + }, + None => {}, // out.push_str(table.as_str()), + }; + }, }; }, None => { - println!("{}: {}: No such table or key.", argv0, item); + eprintln!("{}: {}: No such table or key.", argv0, item); process::exit(65); // sysexits(3) EX_DATAERR }, }; From f404de7a2ddf646684428eabc1911741d132fba7 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 14:01:28 -0500 Subject: [PATCH 08/23] updated README to latest featureset --- README.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0b5d398..37199b7 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,26 @@ 2. ??? 3. Profit +Also make sure that your cargo `bin` directory (by default in +`"$CARGO_HOME"/bin`) is in your `$PATH`; I recommend symlinking the folder to +`"$HOME/.local/bin` and adding that to your user `$PATH`. + ## Usage -To get the value of `key` from the `main` table in `file.toml`: +Assuming the TOML file being parsed is `file.toml`: -`tomcat main.key file.toml` - -To get the top-level key `notable` from `file.toml`: +To get the value of top-level key `notable`: `tomcat notable file.toml` -To get index `3` in array `arr` inside the `main` table in `file.toml`: +To get the value of `key` from the `main` table: + +`tomcat main.key file.toml` + +To get the value of `key` from the subtable `subtab` in table `main`: + +`tomcat main.subtab.key file.toml` + +To get the value of index `3` in array `arr` in table `main`: `tomcat main.arr[3] file.toml` From 4e3c5e21f53184c2b4f55a33d5fc8ab7b0fe05fe Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 14:19:08 -0500 Subject: [PATCH 09/23] fixed top-level keys --- src/main.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1ea05ac..fc449f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,20 +40,26 @@ fn main() { } else { content = input.to_string(); } let mut tabkey: Vec<&str> = arguments[0].split(".").collect(); - let mut indexvec: Vec<&str> = tabkey[1].split(&['[', ']'][..]).collect(); - - tabkey[1] = indexvec.remove(0); + let mut indexvec = Vec::new(); let mut index: usize = 0; - if ! indexvec.is_empty() { - let istr = indexvec.remove(0); - match usize::from_str(istr) { - Ok(i) => index = i, - Err(_) => { - eprintln!("{}: {}: Cannot index by given value.", argv0, istr); - process::exit(65); // sysexits(3) EX_DATAERR - }, - }; - } + + match tabkey.iter().skip(1).peekable().peek() { + Some(_) => { + indexvec = tabkey[1].split(&['[', ']'][..]).collect(); + tabkey[1] = indexvec.remove(0); + if ! indexvec.is_empty() { + let istr = indexvec.remove(0); + match usize::from_str(istr) { + Ok(i) => index = i, + Err(_) => { + eprintln!("{}: {}: Cannot index by given value.", argv0, istr); + process::exit(65); // sysexits(3) EX_DATAERR + }, + }; + } + }, + None => {}, + }; let mut root = content.parse::().unwrap(); From a74b0fede24c70d4305b9a6ccd7a487c4fdbbd41 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 14:28:28 -0500 Subject: [PATCH 10/23] added more usage info --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fc449f7..364704c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ fn main() { let mut arguments: Vec = env::args().collect(); let argv0 = arguments.remove(0); if arguments[1].is_empty() { - eprintln!("Usage: {} [table...].[value] [file...]", argv0); + eprintln!("Usage: {} [table...].[value[index]] [file...]", argv0); process::exit(64); // sysexits(3) EX_USAGE } let input = &arguments[1]; From 7128f8d6731d998e36d48de2ef3a975265d92424 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 20:55:48 -0500 Subject: [PATCH 11/23] added exit_no_std and better builds --- .cargo/config.toml | 10 ++++++++++ Cargo.lock | 46 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 +------- rust-toolchain.toml | 2 ++ src/main.rs | 16 ++++++++-------- 5 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 rust-toolchain.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..10b6ce8 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,10 @@ +[unstable] +build-std = [ "std", "panic_abort" ] +build-std-features = [ "panic_immediate_abort" ] + +[profile.release] +strip = true # strip symbols from the binary +opt-level = "z" # optimize for size +lto = true # link time optimization +codegen-units = 1 # decrease parallelization +panic = "abort" diff --git a/Cargo.lock b/Cargo.lock index 4fd7cf7..b5ed577 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,29 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "exit-no-std" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a608ccc67fac78c1916aa88ad75d6f6a3e353521844abce906c22a45d161d99" +dependencies = [ + "libc", + "pc-ints", + "winapi", +] + +[[package]] +name = "libc" +version = "0.2.138" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" + +[[package]] +name = "pc-ints" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "422b0cc3a966f6e0987d2f948c234585bd917a1f16df1470e60c56ad6de2c085" + [[package]] name = "serde" version = "1.0.148" @@ -12,6 +35,7 @@ checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" name = "tomcat" version = "0.0.1" dependencies = [ + "exit-no-std", "toml", ] @@ -23,3 +47,25 @@ checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index ead9c5d..35b6c44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,5 @@ license = "AGPL-3.0-or-later" authors = [ "Emma Tebibyte " ] [dependencies] +exit-no-std = "0.1.3" toml = "0.5.9" - -[profile.release] -strip = true # strip symbols from the binary -opt-level = "z" # optimize for size -lto = true # link time optimization -codegen-units = 1 # decrease parallelization -panic = "abort" diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" diff --git a/src/main.rs b/src/main.rs index 364704c..68c0c18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use std::env; use std::fs::File; use std::io::Read; use std::path::Path; -use std::process; +use exit_no_std::exit; use std::str::FromStr; use toml::Value; @@ -29,7 +29,7 @@ fn main() { let argv0 = arguments.remove(0); if arguments[1].is_empty() { eprintln!("Usage: {} [table...].[value[index]] [file...]", argv0); - process::exit(64); // sysexits(3) EX_USAGE + exit(64); // sysexits(3) EX_USAGE } let input = &arguments[1]; let mut content = String::new(); @@ -53,7 +53,7 @@ fn main() { Ok(i) => index = i, Err(_) => { eprintln!("{}: {}: Cannot index by given value.", argv0, istr); - process::exit(65); // sysexits(3) EX_DATAERR + exit(64); // sysexits(3) EX_USAGE }, }; } @@ -75,7 +75,7 @@ fn main() { match valiter.peek() { Some(_) => { eprintln!("{}: {}: Not a table.", argv0, item); - process::exit(65); // sysexits(3) EX_DATAERR + exit(65); // sysexits(3) EX_DATAERR }, None => { match array.get(index) { @@ -86,7 +86,7 @@ fn main() { eprintln!( "{}: {:?}: No value at given index.", argv0, index ); - process::exit(65); // sysexits(3) EX_DATAERR + exit(65); // sysexits(3) EX_DATAERR }, }; }, @@ -94,7 +94,7 @@ fn main() { eprintln!( "{}: {:?}: No value at given index.", argv0, index ); - process::exit(65); // sysexits(3) EX_DATAERR + exit(65); // sysexits(3) EX_DATAERR }, }; }, @@ -108,7 +108,7 @@ fn main() { match valiter.peek() { Some(_) => { eprintln!("{}: {}: Not a table.", argv0, item); - process::exit(65); // sysexits(3) EX_DATAERR + exit(65); // sysexits(3) EX_DATAERR }, None => out.push_str(string.as_str()), }; @@ -125,7 +125,7 @@ fn main() { }, None => { eprintln!("{}: {}: No such table or key.", argv0, item); - process::exit(65); // sysexits(3) EX_DATAERR + exit(65); // sysexits(3) EX_DATAERR }, }; } From 35401c4bbc8eb3195a7da43f2f9295fd52534443 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 19 Dec 2022 22:58:38 -0500 Subject: [PATCH 12/23] fixed usage detection --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 68c0c18..d6827d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ use toml::Value; fn main() { let mut arguments: Vec = env::args().collect(); let argv0 = arguments.remove(0); - if arguments[1].is_empty() { + if arguments.is_empty() { eprintln!("Usage: {} [table...].[value[index]] [file...]", argv0); exit(64); // sysexits(3) EX_USAGE } From 7157c70b1f870b6df928d0472ce7ff0f4e16e216 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 25 Feb 2023 21:00:36 -0500 Subject: [PATCH 13/23] made the code so much more readable --- .cargo/config.toml | 10 -- Cargo.lock | 217 +++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- rust-toolchain.toml | 2 - src/main.rs | 257 +++++++++++++++++++++++++++----------------- 5 files changed, 364 insertions(+), 124 deletions(-) delete mode 100644 .cargo/config.toml delete mode 100644 rust-toolchain.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 10b6ce8..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,10 +0,0 @@ -[unstable] -build-std = [ "std", "panic_abort" ] -build-std-features = [ "panic_immediate_abort" ] - -[profile.release] -strip = true # strip symbols from the binary -opt-level = "z" # optimize for size -lto = true # link time optimization -codegen-units = 1 # decrease parallelization -panic = "abort" diff --git a/Cargo.lock b/Cargo.lock index b5ed577..2eb7e70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,16 +3,83 @@ version = 3 [[package]] -name = "exit-no-std" -version = "0.1.3" +name = "bindgen" +version = "0.63.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a608ccc67fac78c1916aa88ad75d6f6a3e353521844abce906c22a45d161d99" +checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885" dependencies = [ - "libc", - "pc-ints", - "winapi", + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", ] +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.138" @@ -20,10 +87,96 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] -name = "pc-ints" -version = "0.1.4" +name = "libloading" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422b0cc3a966f6e0987d2f948c234585bd917a1f16df1470e60c56ad6de2c085" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "proc-macro2" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "serde" @@ -31,12 +184,29 @@ version = "1.0.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tomcat" version = "0.0.1" dependencies = [ - "exit-no-std", "toml", + "yacexits", ] [[package]] @@ -48,6 +218,23 @@ dependencies = [ "serde", ] +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "which" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +dependencies = [ + "either", + "libc", + "once_cell", +] + [[package]] name = "winapi" version = "0.3.9" @@ -69,3 +256,13 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yacexits" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3afbe270dff95fe94b3a55c7e2dce91457a89b2b0dc6013814bba9806d099be" +dependencies = [ + "bindgen", + "libc", +] diff --git a/Cargo.toml b/Cargo.toml index 35b6c44..fbd6f01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,5 @@ license = "AGPL-3.0-or-later" authors = [ "Emma Tebibyte " ] [dependencies] -exit-no-std = "0.1.3" toml = "0.5.9" +yacexits = "0.1.2" diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 5d56faf..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "nightly" diff --git a/src/main.rs b/src/main.rs index d6827d6..5aea5a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,13 @@ -// Copyright (c) 2022 Emma Tebibyte -// SPDX-License-Identifier: AGPL-3.0-or-later - -/* Tomcat is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. +/* + * Copyright (c) 2022 Emma Tebibyte + * SPDX-License-Identifier: AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. * - * Tomcat is distributed in the hope that it will be useful, but WITHOUT + * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. @@ -15,119 +16,173 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -use std::env; -use std::fs::File; -use std::io::Read; -use std::path::Path; -use exit_no_std::exit; -use std::str::FromStr; +use std::{ + env, + fs::File, + io::{ + Read, + stdin, + }, + iter::Peekable, + path::Path, + str::FromStr, +}; use toml::Value; +use yacexits::*; + +fn parse_toml( + mut root: Value, + mut tabkey: Peekable>, + index: Option, +) -> Result { + let mut out = String::new(); + + while let Some(item) = tabkey.next() { + let value = match root.get(item) { + Some(val) => val, + None => { + return Err((format!("{}: No such table or key.", item), EX_DATAERR)); + }, + }; + + match value { + Value::Table(table) => { + match tabkey.peek() { + Some(_) => { + root = toml::Value::Table(table.to_owned()); + continue; + }, + None => {}, // out.push_str(table.as_str()), + }; + }, + _ => { + match tabkey.peek() { + Some(_) => { + return Err((format!("{}: Not a table.", item), EX_DATAERR)); + }, + None => {}, + }; + }, + }; + + match value { + // TODO: Implement other type parsing + Value::Array(array) => { + let element: String; + match index { + Some(i) => { + element = match array.get(i) { + Some(element) => { + match element.as_str() { + Some(val) => val.to_owned(), + None => { + return Err(( + format!("{:?}: No value at given key.", index), + EX_DATAERR + )); + }, + } + }, + None => { + return Err( + (format!("{:?}: No value at given index.", i), EX_DATAERR) + ); + }, + }; + }, + None => element = format!("{:?}", array), + }; + out.push_str(&element); + }, + Value::Boolean(_boolean) => {}, + Value::Datetime(_datetime) => {}, + Value::Float(_float) => {}, + Value::Integer(_int) => {}, + Value::String(string) => out.push_str(string.as_str()), + _ => return Err((format!("{:?}: No such key.", item), EX_DATAERR)), + }; + } + Ok(out) +} fn main() { - let mut arguments: Vec = env::args().collect(); - let argv0 = arguments.remove(0); - if arguments.is_empty() { - eprintln!("Usage: {} [table...].[value[index]] [file...]", argv0); + let argv: Vec = env::args().collect(); + + if argv.len() <= 1 { + eprintln!("Usage: {} [table...].[value[index]] [file...]", argv[0]); exit(64); // sysexits(3) EX_USAGE } - let input = &arguments[1]; - let mut content = String::new(); + + let input = match argv.get(2) { + Some(val) => val, + None => { + eprintln!("Usage: {} [table...].[value[index]] [file...]", argv[0]); + exit(EX_USAGE); + }, + }; + let mut content = Vec::new(); let file = Path::new(&input); - if file.is_file() { - File::open(file).unwrap().read_to_string(&mut content).unwrap(); - } else { content = input.to_string(); } - let mut tabkey: Vec<&str> = arguments[0].split(".").collect(); + if input == &"-" { + match stdin().lock().read_to_end(&mut content) { + Ok(_) => {}, + Err(_) => { + eprintln!("{}: Could not read from standard input.", argv[0]); + exit(EX_OSERR); + }, + }; + } else { + match File::open(file).unwrap().read_to_end(&mut content) { + Ok(_) => {}, + Err(_) => { + eprintln!("{}: {:?}: No such file or directory.", argv[0], file); + exit(EX_UNAVAILABLE); + }, + }; + } + + let mut tabkey: Vec<&str> = argv[1].split(".").collect(); let mut indexvec = Vec::new(); - let mut index: usize = 0; + let mut index: Option = None; match tabkey.iter().skip(1).peekable().peek() { Some(_) => { indexvec = tabkey[1].split(&['[', ']'][..]).collect(); tabkey[1] = indexvec.remove(0); - if ! indexvec.is_empty() { - let istr = indexvec.remove(0); - match usize::from_str(istr) { - Ok(i) => index = i, - Err(_) => { - eprintln!("{}: {}: Cannot index by given value.", argv0, istr); - exit(64); // sysexits(3) EX_USAGE - }, - }; - } }, None => {}, }; - let mut root = content.parse::().unwrap(); - - let mut out = String::new(); - let mut valiter = tabkey.iter().peekable(); - - while let Some(item) = valiter.next() { - match root.get(item) { - Some(value) => { - match value { - // TODO: Implement other type parsing - Value::Array(array) => { - match valiter.peek() { - Some(_) => { - eprintln!("{}: {}: Not a table.", argv0, item); - exit(65); // sysexits(3) EX_DATAERR - }, - None => { - match array.get(index) { - Some(element) => { - match element.as_str() { - Some(val) => out.push_str(val), - None => { - eprintln!( - "{}: {:?}: No value at given index.", argv0, index - ); - exit(65); // sysexits(3) EX_DATAERR - }, - }; - }, - None => { - eprintln!( - "{}: {:?}: No value at given index.", argv0, index - ); - exit(65); // sysexits(3) EX_DATAERR - }, - }; - }, - }; - }, - Value::Boolean(_boolean) => {}, - Value::Datetime(_datetime) => {}, - Value::Float(_float) => {}, - Value::Integer(_int) => {}, - Value::String(string) => { - match valiter.peek() { - Some(_) => { - eprintln!("{}: {}: Not a table.", argv0, item); - exit(65); // sysexits(3) EX_DATAERR - }, - None => out.push_str(string.as_str()), - }; - }, - Value::Table(table) => { - match valiter.peek() { - Some(_) => { - root = toml::Value::Table(table.to_owned()); - }, - None => {}, // out.push_str(table.as_str()), - }; - }, - }; - }, - None => { - eprintln!("{}: {}: No such table or key.", argv0, item); - exit(65); // sysexits(3) EX_DATAERR + if ! indexvec.is_empty() { + let istr = indexvec.remove(0); + match usize::from_str(istr) { + Ok(i) => index = Some(i), + Err(_) => { + eprintln!("{}: {}: Cannot index by given value.", argv[0], istr); + exit(EX_USAGE); }, }; } - println!("{}", out); + + let root = match String::from_utf8(content).unwrap().parse::() { + Ok(toml) => toml, + Err(_) => { + eprintln!("{}: Unable to parse TOML.", argv[0]); + exit(EX_DATAERR); + }, + }; + + let valiter = tabkey.iter().peekable(); + println!( + "{}", + match parse_toml(root, valiter, index) { + Ok(val) => val, + Err((err, code)) => { + eprintln!("{}: {}", argv[0], err); + exit(code); + }, + }, + ); } From 87822e53527203ca4e4a1807cf297d30c2bea90a Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 25 Feb 2023 21:01:11 -0500 Subject: [PATCH 14/23] moved LICENSE to COPYING --- LICENSE => COPYING | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE => COPYING (100%) diff --git a/LICENSE b/COPYING similarity index 100% rename from LICENSE rename to COPYING From 088824efdf8c7cb90a3ac3703d894e89081d1303 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 20 Mar 2023 16:40:43 -0400 Subject: [PATCH 15/23] added other toml value types --- src/main.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5aea5a1..a5d12b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Emma Tebibyte + * Copyright (c) 2022–2023 Emma Tebibyte * SPDX-License-Identifier: AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify it under @@ -67,8 +67,7 @@ fn parse_toml( }; match value { - // TODO: Implement other type parsing - Value::Array(array) => { + Value::Array(array) => { // TODO: Split Array logic into separate function let element: String; match index { Some(i) => { @@ -78,7 +77,7 @@ fn parse_toml( Some(val) => val.to_owned(), None => { return Err(( - format!("{:?}: No value at given key.", index), + format!("{:?}: No value at given key.", i), EX_DATAERR )); }, @@ -95,10 +94,10 @@ fn parse_toml( }; out.push_str(&element); }, - Value::Boolean(_boolean) => {}, - Value::Datetime(_datetime) => {}, - Value::Float(_float) => {}, - Value::Integer(_int) => {}, + Value::Boolean(boolean) => out.push_str(&format!("{:?}", boolean)), + Value::Datetime(datetime) => out.push_str(&format!("{:?}", datetime)), + Value::Float(float) => out.push_str(&format!("{:?}", float)), + Value::Integer(int) => out.push_str(&format!("{:?}", int)), Value::String(string) => out.push_str(string.as_str()), _ => return Err((format!("{:?}: No such key.", item), EX_DATAERR)), }; From 7fc82adc1cf8b5b6e1c748cc89eacaa1f2879e8a Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 Mar 2023 19:42:34 -0400 Subject: [PATCH 16/23] fixed usage information --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a5d12b0..b2fd80a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,16 +107,17 @@ fn parse_toml( fn main() { let argv: Vec = env::args().collect(); + let usage_info = format!("Usage: {} [table.]key[[index]] [file...]", argv[0]); if argv.len() <= 1 { - eprintln!("Usage: {} [table...].[value[index]] [file...]", argv[0]); + eprintln!(, argv[0]); exit(64); // sysexits(3) EX_USAGE } let input = match argv.get(2) { Some(val) => val, None => { - eprintln!("Usage: {} [table...].[value[index]] [file...]", argv[0]); + eprintln!("{}", usage_info); exit(EX_USAGE); }, }; From 152348a17aab5616c17770133e17a79c54f037d6 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 Mar 2023 19:44:17 -0400 Subject: [PATCH 17/23] updated deps --- Cargo.lock | 36 ++++++++++++++++++------------------ src/main.rs | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2eb7e70..4be7ee1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,9 +82,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.138" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libloading" @@ -141,36 +141,36 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" dependencies = [ "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "rustc-hash" @@ -180,9 +180,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "serde" -version = "1.0.148" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" [[package]] name = "shlex" @@ -211,18 +211,18 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "which" @@ -259,9 +259,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "yacexits" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3afbe270dff95fe94b3a55c7e2dce91457a89b2b0dc6013814bba9806d099be" +checksum = "53fe740dd05c1bbc919431e842e6c1bea30195e0518ae99cae35b7f0730ddc18" dependencies = [ "bindgen", "libc", diff --git a/src/main.rs b/src/main.rs index b2fd80a..3ef065c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,7 @@ fn main() { let usage_info = format!("Usage: {} [table.]key[[index]] [file...]", argv[0]); if argv.len() <= 1 { - eprintln!(, argv[0]); + eprintln!("{}", usage_info); exit(64); // sysexits(3) EX_USAGE } From 03e02b9882d620e89ab6f6641b8002e7a2984da9 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 25 Mar 2023 00:40:00 -0400 Subject: [PATCH 18/23] code cleanup --- cargo | 0 src/main.rs | 90 ++++++++++++++++++++++++----------------------------- 2 files changed, 40 insertions(+), 50 deletions(-) create mode 100644 cargo diff --git a/cargo b/cargo new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 3ef065c..921577a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,11 +19,9 @@ use std::{ env, fs::File, - io::{ - Read, - stdin, - }, + io::Read, iter::Peekable, + os::fd::{ FromRawFd }, path::Path, str::FromStr, }; @@ -48,21 +46,15 @@ fn parse_toml( match value { Value::Table(table) => { - match tabkey.peek() { - Some(_) => { + if tabkey.peek().is_some() { root = toml::Value::Table(table.to_owned()); continue; - }, - None => {}, // out.push_str(table.as_str()), }; }, _ => { - match tabkey.peek() { - Some(_) => { - return Err((format!("{}: Not a table.", item), EX_DATAERR)); - }, - None => {}, - }; + if tabkey.peek().is_some() { + return Err((format!("{}: Not a table.", item), EX_DATAERR)); + } }, }; @@ -111,48 +103,43 @@ fn main() { if argv.len() <= 1 { eprintln!("{}", usage_info); - exit(64); // sysexits(3) EX_USAGE + exit(EX_USAGE); } - - let input = match argv.get(2) { - Some(val) => val, - None => { - eprintln!("{}", usage_info); - exit(EX_USAGE); - }, - }; + + let input: &str; + + if let Some(arg) = argv.get(2) { + input = arg; + } else { input = &""; } + let mut content = Vec::new(); - let file = Path::new(&input); - - if input == &"-" { - match stdin().lock().read_to_end(&mut content) { - Ok(_) => {}, - Err(_) => { - eprintln!("{}: Could not read from standard input.", argv[0]); - exit(EX_OSERR); - }, - }; - } else { - match File::open(file).unwrap().read_to_end(&mut content) { - Ok(_) => {}, - Err(_) => { - eprintln!("{}: {:?}: No such file or directory.", argv[0], file); + match input { + "-" | "" => unsafe { File::from_raw_fd(0) }, + _ => { + File::open(Path::new(&input)).unwrap_or_else(|_| { + eprintln!( + "{}: {}: No such file or directory.", + argv[0], + &input + ); exit(EX_UNAVAILABLE); - }, - }; - } + }) + }, + }.read_to_end(&mut content) + .unwrap_or_else(|_| { + eprintln!("{}: Could not read input.", argv[0]); + exit(EX_OSERR); + }); + let mut tabkey: Vec<&str> = argv[1].split(".").collect(); let mut indexvec = Vec::new(); let mut index: Option = None; - match tabkey.iter().skip(1).peekable().peek() { - Some(_) => { + if tabkey.iter().skip(1).peekable().peek().is_some() { indexvec = tabkey[1].split(&['[', ']'][..]).collect(); tabkey[1] = indexvec.remove(0); - }, - None => {}, }; if ! indexvec.is_empty() { @@ -166,13 +153,16 @@ fn main() { }; } - let root = match String::from_utf8(content).unwrap().parse::() { - Ok(toml) => toml, - Err(_) => { + let root = String::from_utf8(content) + .unwrap_or_else(|_| { + eprintln!("{}: Input is not valid UTF-8.", argv[0]); + exit(EX_DATAERR); + }) + .parse::() + .unwrap_or_else(|_| { eprintln!("{}: Unable to parse TOML.", argv[0]); exit(EX_DATAERR); - }, - }; + }); let valiter = tabkey.iter().peekable(); println!( From 19e5f4e2f4a0681b38da29d4d975b1b1d9c82b96 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 25 Mar 2023 00:46:37 -0400 Subject: [PATCH 19/23] added c-main dependency --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 17 ++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4be7ee1..25a32a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "c-main" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "797bbff8bd2bcddb7f0ee638b55398686adac15174689a86da5ffc0f51219f75" +dependencies = [ + "libc", +] + [[package]] name = "cexpr" version = "0.6.0" @@ -205,6 +214,7 @@ dependencies = [ name = "tomcat" version = "0.0.1" dependencies = [ + "c-main", "toml", "yacexits", ] diff --git a/Cargo.toml b/Cargo.toml index fbd6f01..6e47e4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,6 @@ license = "AGPL-3.0-or-later" authors = [ "Emma Tebibyte " ] [dependencies] +c-main = "1.0.1" toml = "0.5.9" yacexits = "0.1.2" diff --git a/src/main.rs b/src/main.rs index 921577a..77758ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,9 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ +#![no_main] + use std::{ - env, fs::File, io::Read, iter::Peekable, @@ -26,6 +27,7 @@ use std::{ str::FromStr, }; +use c_main::Args; use toml::Value; use yacexits::*; @@ -97,8 +99,9 @@ fn parse_toml( Ok(out) } -fn main() { - let argv: Vec = env::args().collect(); +#[no_mangle] +fn rust_main(args: Args) { + let argv: Vec<&str> = args.into_iter().collect(); let usage_info = format!("Usage: {} [table.]key[[index]] [file...]", argv[0]); if argv.len() <= 1 { @@ -106,15 +109,11 @@ fn main() { exit(EX_USAGE); } - let input: &str; - - if let Some(arg) = argv.get(2) { - input = arg; - } else { input = &""; } + let input = argv.get(2).unwrap_or(&""); let mut content = Vec::new(); - match input { + match input.to_owned() { "-" | "" => unsafe { File::from_raw_fd(0) }, _ => { File::open(Path::new(&input)).unwrap_or_else(|_| { From de4b897aa8676c0b34ca6f16a4be1399354f0ce3 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 25 Mar 2023 00:47:30 -0400 Subject: [PATCH 20/23] removed accidental file --- cargo | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 cargo diff --git a/cargo b/cargo deleted file mode 100644 index e69de29..0000000 From e3e180765689e60584dd9b50c73a1828784fd8c5 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 25 Mar 2023 02:36:38 -0400 Subject: [PATCH 21/23] fixed array matching and printing --- src/main.rs | 73 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/src/main.rs b/src/main.rs index 77758ea..19733a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ fn parse_toml( let mut out = String::new(); while let Some(item) = tabkey.next() { - let value = match root.get(item) { + let mut value = match root.get(item) { Some(val) => val, None => { return Err((format!("{}: No such table or key.", item), EX_DATAERR)); @@ -47,6 +47,24 @@ fn parse_toml( }; match value { + Value::Array(array) => { + let i = match index { + Some(i) => i, + None => { + for v in array.iter() { + out.push_str(&format!("{}\n", v.to_string())); + } + continue; + }, + }; + + match array.get(i) { + Some(val) => value = val, + None => { + return Err((format!("No value at index {}.", i), EX_DATAERR)); + }, + }; + }, Value::Table(table) => { if tabkey.peek().is_some() { root = toml::Value::Table(table.to_owned()); @@ -61,38 +79,20 @@ fn parse_toml( }; match value { - Value::Array(array) => { // TODO: Split Array logic into separate function - let element: String; - match index { - Some(i) => { - element = match array.get(i) { - Some(element) => { - match element.as_str() { - Some(val) => val.to_owned(), - None => { - return Err(( - format!("{:?}: No value at given key.", i), - EX_DATAERR - )); - }, - } - }, - None => { - return Err( - (format!("{:?}: No value at given index.", i), EX_DATAERR) - ); - }, - }; - }, - None => element = format!("{:?}", array), - }; - out.push_str(&element); - }, - Value::Boolean(boolean) => out.push_str(&format!("{:?}", boolean)), - Value::Datetime(datetime) => out.push_str(&format!("{:?}", datetime)), - Value::Float(float) => out.push_str(&format!("{:?}", float)), - Value::Integer(int) => out.push_str(&format!("{:?}", int)), - Value::String(string) => out.push_str(string.as_str()), + Value::Array(array) => { + for v in array.iter() { out.push_str(&format!("{}\n", v.to_string())); } + }, + Value::Boolean(boolean) => out.push_str(&format!("{:?}\n", boolean)), + Value::Datetime(datetime) => out.push_str(&format!("{:?}\n", datetime)), + Value::Float(float) => out.push_str(&format!("{:?}\n", float)), + Value::Integer(int) => out.push_str(&format!("{:?}\n", int)), + Value::String(string) => { + let contents = string.to_owned(); + let mut lines: Vec<&str> = contents.lines().collect(); + if lines.last().unwrap().is_empty() { _ = lines.pop(); } + + for line in lines.iter() { out.push_str(&format!("{}\n", line)); } + }, _ => return Err((format!("{:?}: No such key.", item), EX_DATAERR)), }; } @@ -125,11 +125,10 @@ fn rust_main(args: Args) { exit(EX_UNAVAILABLE); }) }, - }.read_to_end(&mut content) - .unwrap_or_else(|_| { + }.read_to_end(&mut content).unwrap_or_else(|_| { eprintln!("{}: Could not read input.", argv[0]); exit(EX_OSERR); - }); + }); let mut tabkey: Vec<&str> = argv[1].split(".").collect(); @@ -164,7 +163,7 @@ fn rust_main(args: Args) { }); let valiter = tabkey.iter().peekable(); - println!( + print!( "{}", match parse_toml(root, valiter, index) { Ok(val) => val, From f33c18a2b3e25ddc73c213159296e0319207bbeb Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 9 Apr 2023 22:05:31 -0400 Subject: [PATCH 22/23] removed c-main dep --- Cargo.lock | 10 ---------- Cargo.toml | 1 - src/main.rs | 17 +++++++---------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25a32a9..4be7ee1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,15 +30,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "c-main" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797bbff8bd2bcddb7f0ee638b55398686adac15174689a86da5ffc0f51219f75" -dependencies = [ - "libc", -] - [[package]] name = "cexpr" version = "0.6.0" @@ -214,7 +205,6 @@ dependencies = [ name = "tomcat" version = "0.0.1" dependencies = [ - "c-main", "toml", "yacexits", ] diff --git a/Cargo.toml b/Cargo.toml index 6e47e4d..fbd6f01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,5 @@ license = "AGPL-3.0-or-later" authors = [ "Emma Tebibyte " ] [dependencies] -c-main = "1.0.1" toml = "0.5.9" yacexits = "0.1.2" diff --git a/src/main.rs b/src/main.rs index 19733a8..50fa9aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,9 +16,8 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -#![no_main] - use std::{ + env::args, fs::File, io::Read, iter::Peekable, @@ -27,7 +26,6 @@ use std::{ str::FromStr, }; -use c_main::Args; use toml::Value; use yacexits::*; @@ -67,8 +65,8 @@ fn parse_toml( }, Value::Table(table) => { if tabkey.peek().is_some() { - root = toml::Value::Table(table.to_owned()); - continue; + root = toml::Value::Table(table.to_owned()); + continue; }; }, _ => { @@ -99,9 +97,8 @@ fn parse_toml( Ok(out) } -#[no_mangle] -fn rust_main(args: Args) { - let argv: Vec<&str> = args.into_iter().collect(); +fn main() { + let argv: Vec = args().collect(); let usage_info = format!("Usage: {} [table.]key[[index]] [file...]", argv[0]); if argv.len() <= 1 { @@ -109,11 +106,11 @@ fn rust_main(args: Args) { exit(EX_USAGE); } - let input = argv.get(2).unwrap_or(&""); + let input = argv.get(2).unwrap_or(&"".to_owned()).to_owned(); let mut content = Vec::new(); - match input.to_owned() { + match input.as_str() { "-" | "" => unsafe { File::from_raw_fd(0) }, _ => { File::open(Path::new(&input)).unwrap_or_else(|_| { From 0fbe8f773395377f6e2229385a7e11c3638ae731 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 13 Jul 2023 12:29:40 -0600 Subject: [PATCH 23/23] removed redundant array code --- .gitignore | 1 + Cargo.lock | 68 ++++++++++++++++++++++++++++++++++------------------- Cargo.toml | 2 +- src/main.rs | 4 +--- 4 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/Cargo.lock b/Cargo.lock index 4be7ee1..d57070b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + [[package]] name = "bindgen" version = "0.63.0" @@ -47,9 +56,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" dependencies = [ "glob", "libc", @@ -82,9 +91,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" @@ -98,12 +107,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "memchr" @@ -129,9 +135,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "peeking_take_while" @@ -141,36 +147,50 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.7.2" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "rustc-hash" @@ -180,9 +200,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "serde" -version = "1.0.158" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" [[package]] name = "shlex" @@ -203,7 +223,7 @@ dependencies = [ [[package]] name = "tomcat" -version = "0.0.1" +version = "0.1.0" dependencies = [ "toml", "yacexits", @@ -220,9 +240,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" [[package]] name = "which" diff --git a/Cargo.toml b/Cargo.toml index fbd6f01..3684870 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tomcat" -version = "0.0.1" +version = "0.1.0" edition = "2021" license = "AGPL-3.0-or-later" authors = [ "Emma Tebibyte " ] diff --git a/src/main.rs b/src/main.rs index 50fa9aa..a5cee39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,9 +77,7 @@ fn parse_toml( }; match value { - Value::Array(array) => { - for v in array.iter() { out.push_str(&format!("{}\n", v.to_string())); } - }, + Value::Array(_) => {}, Value::Boolean(boolean) => out.push_str(&format!("{:?}\n", boolean)), Value::Datetime(datetime) => out.push_str(&format!("{:?}\n", datetime)), Value::Float(float) => out.push_str(&format!("{:?}\n", float)),