diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5324d58 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +license.html -linguist-detectable \ No newline at end of file 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 new file mode 100644 index 0000000..fe240c7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,313 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "clap" +version = "4.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_complete" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2020fa13af48afc65a9a87335bda648309ab3d154cd03c7ff95b378c7ed39c4" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" + +[[package]] +name = "cmbr" +version = "0.0.0" +dependencies = [ + "clap", + "clap_complete", + "exec", +] + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "exec" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "886b70328cba8871bfc025858e1de4be16b1d5088f2ba50b57816f4210672615" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[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" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..38b0e50 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "cmbr" +version = "0.0.0" +edition = "2021" +license = "GPL-3.0" + +[dependencies] +clap = { version = "4.5.7", features = ["derive"] } +clap_complete = "4.5.5" +exec = "0.3.1" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9057a42 --- /dev/null +++ b/LICENSE @@ -0,0 +1,4 @@ +libcmbr, cmbrcc Copyright (C) 2024 datawater +This program comes with ABSOLUTELY NO WARRANTY; +This is free software, and you are welcome to redistribute it +under the conditions of the GPL-3.0 License; \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d2e91e4 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +push: commit + git push origin main + +commit: pre-commit + git add . + git commit + +pre-commit: + cargo fmt + cargo test + cargo deny check + cargo about generate about.hbs > license.html \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..cf67f5a --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# CMBR +CMBR - Chess Move Binary Representation (WIP) + +### Building +For release builds + +```bash +cargo build --release +``` + +For development builds +```bash +cargo build +``` + +### Usage +For usage run +```bash +cmbrcc help +``` + +or + +```bash +cargo run -- help +``` + +### License +The software is distributed under the GPL-3.0 License + +### Authors +- [datawater](https://github.com/datawater) \ No newline at end of file diff --git a/about.hbs b/about.hbs new file mode 100644 index 0000000..208fe12 --- /dev/null +++ b/about.hbs @@ -0,0 +1,70 @@ + + + + + + + +
+
+

Third Party Licenses

+

This page lists the licenses of the projects used in cmbr.

+
+ +

Overview of licenses:

+ + +

All license text:

+ +
+ + + diff --git a/about.toml b/about.toml new file mode 100644 index 0000000..75c034a --- /dev/null +++ b/about.toml @@ -0,0 +1,6 @@ +accepted = [ + "Apache-2.0", + "MIT", + "Unicode-DFS-2016", + "GPL-3.0" +] diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..ebe1e3f --- /dev/null +++ b/deny.toml @@ -0,0 +1,49 @@ +[graph] +targets = [ + "x86_64-unknown-linux-musl", + "x86_64-unknown-linux-gnu", +] +all-features = false + +[output] +feature-depth = 1 + +[advisories] +ignore = [] + +[licenses] +allow = [ + "MIT", + "Apache-2.0", + "Unicode-DFS-2016" +] +confidence-threshold = 0.8 +exceptions = [ + { allow = ["GPL-3.0"], crate = "cmbr" } +] + +[licenses.private] +ignore = false +registries = [] + +[bans] +multiple-versions = "warn" +wildcards = "allow" +highlight = "all" +workspace-default-features = "allow" +external-default-features = "allow" +deny = [ + { crate = "git2", use-instead = "gix" }, + { crate = "openssl", use-instead = "rustls" }, + { crate = "openssl-sys", use-instead = "rustls" }, + { crate = "cmake", use-instead = "cc" }, + { crate = "windows", reason = "bloated and unnecessary", use-instead = "ideally inline bindings, practically, windows-sys" }, +] +skip = [] +skip-tree = [] + +[sources] +unknown-registry = "warn" +unknown-git = "warn" +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +allow-git = [] diff --git a/license.html b/license.html new file mode 100644 index 0000000..f497a8d --- /dev/null +++ b/license.html @@ -0,0 +1,1742 @@ + + + + + + + +
+
+

Third Party Licenses

+

This page lists the licenses of the projects used in cmbr.

+
+ +

Overview of licenses:

+ + +

All license text:

+ +
+ + + + diff --git a/src/eval_args.rs b/src/eval_args.rs new file mode 100644 index 0000000..495fdf9 --- /dev/null +++ b/src/eval_args.rs @@ -0,0 +1,23 @@ +pub use super::Cli; + +pub fn eval_args(cli: &Cli) { + match cli.command.as_ref().unwrap() { + crate::CommandE::Cmbr2pgn(_args) => { + // TODO: Implement CMBR2PGN + } + + crate::CommandE::Pgn2cmbr(_args) => { + // TODO: Implement PGN2CMBR + } + + crate::CommandE::License => { + println!("libcmbr, cmbrcc Copyright (C) 2024 datawater"); + println!("This program comes with ABSOLUTELY NO WARRANTY;"); + println!("This is free software, and you are welcome to redistribute it"); + println!("under the conditions of the GPL-3.0 License;"); + println!("\nsee https://github.com/datawater/cmbr"); + + std::process::exit(0); + } + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e421c21 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,125 @@ +mod eval_args; + +use clap::{Args, Command, CommandFactory, Parser, Subcommand}; +use clap_complete::{generate, Generator, Shell}; +use std::io::IsTerminal; +use std::process::exit; +use std::thread::available_parallelism; + +#[derive(Subcommand, Clone, Debug, PartialEq, Eq)] +pub enum CommandE { + Cmbr2pgn(Cmbr2PgnArgs), + Pgn2cmbr(Pgn2CmbrArgs), + License, +} + +#[derive(Args, Debug, Clone, PartialEq, Eq)] +pub struct Cmbr2PgnArgs { + input_file: String, + + #[arg(short, long)] + output: String, + + #[arg( + short = 'T', + default_value = "1", + help = "Uses # threads. Pass 0 to use all" + )] + threads_n: u16, +} + +#[derive(Args, Debug, Clone, PartialEq, Eq)] +pub struct Pgn2CmbrArgs { + input: String, + + #[arg(short, long)] + output: String, + + #[arg( + short = 'c', + long, + default_value = "false", + help = "Enable Zstandard compression." + )] + enable_compression: bool, + + #[arg( + long, + default_value = "9", + help = "Specifies Zstandard compression level. (Ranges 1 to 22)", + required = false + )] + zstd_compression_level: u8, + + #[arg( + short = 'T', + default_value = "1", + help = "Uses threads. Pass 0 to use all", + required = false + )] + threads_n: u16, +} + +#[derive(Parser, Debug, Clone, PartialEq, Eq)] +#[command(author, version, about, long_about = None, name="cmbrcc")] +pub struct Cli { + #[arg(long = "generate", value_enum)] + generator: Option, + + #[command(subcommand)] + command: Option, +} + +fn print_completions(gen: G, cmd: &mut Command) { + generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); +} + +fn validate_args(cli: &mut Cli) { + match cli.command.as_mut().unwrap() { + CommandE::Pgn2cmbr(args) => { + if args.zstd_compression_level < 1 || args.zstd_compression_level > 22 { + eprintln!("[ERROR] Zstd compression level should be between 1 and 22. Provided value is {}", args.zstd_compression_level); + exit(1); + } + + if args.threads_n == 0 { + args.threads_n = available_parallelism().unwrap().get().try_into().unwrap(); + } + } + + CommandE::Cmbr2pgn(args) => { + if args.threads_n == 0 { + args.threads_n = available_parallelism().unwrap().get().try_into().unwrap(); + } + } + + #[allow(unreachable_patterns)] + _ => {} + } +} + +fn main() { + let mut cli = Cli::parse(); + + if let Some(generator) = cli.generator { + let mut cmd = Cli::command(); + + eprintln!("Generating completion file for {generator:?}..."); + print_completions(generator, &mut cmd); + + return; + } + + if cli.command == None { + if std::io::stdin().is_terminal() { + let _ = exec::Command::new(std::env::args().next().unwrap()) + .arg("--help") + .exec(); + } + + return; + } + + validate_args(&mut cli); + eval_args::eval_args(&cli); +}