From 46fc01b80344fb81b5a5aa4a4a08c81b407316df Mon Sep 17 00:00:00 2001 From: specCon18 Date: Wed, 29 May 2024 19:14:26 -0400 Subject: [PATCH] implemented basic data extraction --- .direnv/flake-profile | 1 + .direnv/flake-profile-1-link | 1 + .envrc | 1 + .gitignore | 2 + Cargo.lock | 300 +++++++++++++++++++++++++++++++++++ Cargo.toml | 9 ++ flake.lock | 26 +++ flake.nix | 31 ++++ nix/default.nix | 11 ++ nix/devshell.nix | 16 ++ nix/flake.nix | 32 ++++ src/file_tree.rs | 56 +++++++ src/main.rs | 92 +++++++++++ 13 files changed, 578 insertions(+) create mode 120000 .direnv/flake-profile create mode 120000 .direnv/flake-profile-1-link create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/default.nix create mode 100644 nix/devshell.nix create mode 100644 nix/flake.nix create mode 100644 src/file_tree.rs create mode 100644 src/main.rs diff --git a/.direnv/flake-profile b/.direnv/flake-profile new file mode 120000 index 0000000..0c05709 --- /dev/null +++ b/.direnv/flake-profile @@ -0,0 +1 @@ +flake-profile-1-link \ No newline at end of file diff --git a/.direnv/flake-profile-1-link b/.direnv/flake-profile-1-link new file mode 120000 index 0000000..6418ed1 --- /dev/null +++ b/.direnv/flake-profile-1-link @@ -0,0 +1 @@ +/nix/store/i3rlyi8v4kyhgadm396y1cqv2grr7w14-nix-shell-env \ No newline at end of file diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3305dc8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/test_dir/* diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b69f57e --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,300 @@ +# 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.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +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.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[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.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +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 = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[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 = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[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" + +[[package]] +name = "yunodo" +version = "0.1.0" +dependencies = [ + "clap", + "ring", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..48a96f7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "yunodo" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = { version = "4.5.4", features = ["derive"] } +ring = "0.17.8" + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..259afea --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1715774670, + "narHash": "sha256-iJYnKMtLi5u6hZhJm94cRNSDG5Rz6ZzIkGbhPFtDRm0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b3fcfcfabd01b947a1e4f36622bbffa3985bdac6", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixpkgs-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..34b25d5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + description = "SunServer"; + + inputs={ + nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + }; + outputs = { self, nixpkgs }@inputs: + let + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + #v I improved how you call in packages + pkgs = forAllSystems (system: + import nixpkgs { + inherit system; + #v this can be adjusted to read args passed without impure later + # config = { allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [ + # ]; + # }; + } + ); + in { + packages = forAllSystems (system: { + default = pkgs.${system}.callPackage ./nix/default.nix { }; + }); + devShells = forAllSystems (system: { + default = pkgs.${system}.callPackage ./nix/devshell.nix { }; + }); + nixConfig = { + }; + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..9f0d7de --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { }, lib }: + +pkgs.rustPlatform.buildRustPackage rec { + pname = "algos-in-rust"; + version = "1.0.0"; + cargoLock.lockFile = ../Cargo.lock; + src = pkgs.lib.cleanSource ../.; + buildInputs = [ ]; + nativeBuildInputs = [ pkgs.pkg-config ]; + doCheck = false; +} diff --git a/nix/devshell.nix b/nix/devshell.nix new file mode 100644 index 0000000..a61223a --- /dev/null +++ b/nix/devshell.nix @@ -0,0 +1,16 @@ +{ pkgs ? import { } }: +pkgs.mkShell { + # Get dependencies from the main package + inputsFrom = [ (pkgs.callPackage ./default.nix { }) ]; + # Additional tooling + buildInputs = with pkgs; [ + cargo + cargo-watch + rustc + rustup + clippy + bacon + rust-analyzer + pkg-config + ]; +} diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 0000000..405b72b --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,32 @@ +{ + description = "SunServer"; + + inputs={ + nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + }; + outputs = { self, nixpkgs }@inputs: + let + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + #v I improved how you call in packages + pkgs = forAllSystems (system: + import nixpkgs { + inherit system; + #v this can be adjusted to read args passed without impure later + config = { allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [ + "unrar" + ]; + }; + } + ); + in { + packages = forAllSystems (system: { + default = pkgs.${system}.callPackage ./nix/default.nix { }; + }); + devShells = forAllSystems (system: { + default = pkgs.${system}.callPackage ./nix/devshell.nix { }; + }); + nixConfig = { + }; + }; +} diff --git a/src/file_tree.rs b/src/file_tree.rs new file mode 100644 index 0000000..60bd430 --- /dev/null +++ b/src/file_tree.rs @@ -0,0 +1,56 @@ +use std::collections::HashMap; +// Define the structure for a File +#[derive(Debug)] +struct File { + name: String, //TODO: make sha384 digest :ODOT// + path: String, +} + +// Define the structure for a Directory +#[derive(Debug)] +struct Directory { + parent:Box, + files: Vec, + subdirectories: HashMap, +} + +// Define a node of the B-tree +#[derive(Debug)] +enum Node { + File(File), + Directory(Box), +} + +// Define the B-tree structure +#[derive(Debug)] +struct BTree { + root: Node, +} + +// Implement methods for BTree +impl BTree { + fn new(root: Node) -> Self { + BTree { root } + } + + fn print(&self) { + self.print_recursive(&self.root, 0); + } + + fn print_recursive(&self, node: &Node, depth: usize) { + match node { + Node::File(file) => { + println!("{}{}", "-".repeat(depth), file.name); + } + Node::Directory(dir) => { + println!("{}{:#?}", "-".repeat(depth), dir.parent); + for file in &dir.files { + println!("{}{}", "-".repeat(depth + 1), file.name); + } + for (_, subdir) in &dir.subdirectories { + self.print_recursive(subdir, depth + 1); + } + } + } + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..90ba702 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,92 @@ +use clap::Parser; +use std::{io,fs,path::PathBuf}; +//TODO: implement mod file_tree; :ODOT// + +#[derive(Parser)] +#[command(name = "YUNODO")] +#[command(version = "0.1.0")] +#[command(about = "parse file tree for //TODO: comments", long_about = "parses a directory of files for substrings of //TODO: and outputs all instances in a parsable format")] +struct Cli { + /// Sets a custom config file + #[arg(short, long, value_name = "PATH")] + path: Option, + #[arg(short, long, value_name = "DEBUG")] + debug: Option, +} + +fn read_files_in_directory(dir_path: &str) -> io::Result)>> { + let mut files_content = Vec::new(); + let paths = fs::read_dir(dir_path)?; + + for path in paths { + let entry = path?; + let path = entry.path(); + if path.is_file() { + let filename = path.file_name().unwrap().to_string_lossy().into_owned(); + let content = fs::read_to_string(&path)?; + let lines: Vec = content.lines().map(|s| s.to_string()).collect(); + files_content.push((filename, lines)); + } else if path.is_dir() { + let subdir_path = path.to_string_lossy().into_owned(); + let subdir_content = read_files_in_directory(&subdir_path)?; + files_content.extend(subdir_content); + } + } + + Ok(files_content) +} + +fn main() { + let cli = Cli::parse(); + if let Some(path) = cli.path.as_deref() { + let path_string = path.display().to_string(); + match read_files_in_directory(&path_string.as_str()) { + Ok(files_content) => { + for (filename, lines) in files_content { + for (line_number, line) in lines.iter().enumerate() { + // Check if the line starts with "//" and not within strings or other signatures + if !line.contains("//") { + continue; + } + + let mut in_string = false; + let mut in_comment = false; + let mut in_signature = false; + + for (i, c) in line.chars().enumerate() { + match c { + '"' => in_string = !in_string, + '/' if !in_string => { + if i + 1 < line.len() && line.chars().nth(i + 1).unwrap() == '/' { + in_comment = true; + break; + } else if i + 1 < line.len() && line.chars().nth(i + 1).unwrap() == '*' { + in_comment = true; + } + } + '*' if i + 1 < line.len() && line.chars().nth(i + 1).unwrap() == '/' && in_comment => { + in_comment = false; + break; + } + _ => (), + } + } + + if in_comment { + let mut v: Vec<&str> = line.split("//TODO:").collect(); + if let Some(last_part) = v.last() { + if let Some(end_index) = last_part.find(":ODOT//") { + let extracted = &last_part[..end_index]; + println!("({})->({})->({}) |~| {}", path_string, filename, line_number + 1, extracted); + } + } + } + } + } + } + Err(err) => { + eprintln!("Error: {}", err); + } + } + } +}