commit 2810642c0dac1c9b21c5a7198f6976e11016bb0a Author: deadvey Date: Sun Nov 16 11:31:41 2025 +0000 Initial push diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9721049 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/root +*.swp diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..d9eb09a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "npons" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7f4901c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "npons" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/encode.rs b/src/encode.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/files.rs b/src/files.rs new file mode 100644 index 0000000..78afa43 --- /dev/null +++ b/src/files.rs @@ -0,0 +1,139 @@ +use std::fs; +pub fn read_file(file_name: &str, depth: u8) -> Vec +{ + if let Ok(file_contents) = fs::read_to_string(format!("root/{}",file_name)) + { + let bytes = encode_npon(&file_contents, depth); + return bytes + } + return vec![] + +} + +fn encode_npon(file_contents: &String, depth: u8) -> Vec +{ + let mut bytes: Vec = vec![]; + if depth > 63 { + println!("Depth level safety reached (63), recursion error suspected"); + return vec![]; + } + if depth == 0 { + bytes.push(01); + } + + // flag + // 0 = nothing + // 1 = in a string + // 2 = in a name + // 3 = in import + let mut index_flag: usize = 0; + let mut flag: u8 = 0; + let mut backslash_flag: bool = false; + for (index, character) in file_contents.bytes().enumerate() + { + if backslash_flag + { + match character + { + 110 => // newline + { + bytes.push(14); + }, + 116 => // tab + { + bytes.push(15); + }, + _ => bytes.push(character), // Otherwise just push the character + } + backslash_flag = false; + continue + } + backslash_flag = false; + //print!("{} ", character); + match flag + { + 0 => + { + match character + { + 40 => + { + bytes.push(03); // ( for name start + flag = 2; + } + 123 => bytes.push(05), + 125 => bytes.push(06), + 58 => + { + index_flag = index + 1; + flag = 3; + }, + 39 | 34 => + { + bytes.push(07); + flag = 1; + }, + _ => (), + } + continue + }, + 1 => // in a string + { + match character + { + 39 | 34 => + { + bytes.push(08); + flag = 0; + }, + 92 => + { + backslash_flag = true; + }, + _ => bytes.push(character), + } + continue + }, + 2 => // in a name + { + match character + { + 41 => + { + bytes.push(04); // ) for name end + flag = 0; + }, + 92 => + { + backslash_flag = true; + }, + _ => bytes.push(character), + } + continue + }, + 3 => // in import + { + match character + { + 58 => + { + let new_bytes = read_file(&file_contents[index_flag..index], depth+1); + for byte in new_bytes.iter() + { + bytes.push(*byte); + } + flag = 0; + } + _ => (), + } + continue + }, + _ => println!("ERROR: Invalid flag code or 'null'"), + } + } + if depth == 0 { + bytes.push(02); + } + + return bytes +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..79911f3 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,32 @@ +use std::io; +use std:: +{ + io::{BufReader, prelude::*}, + net::{TcpListener, TcpStream}, +}; + +mod files; + +fn main() -> io::Result<()> +{ + let bind_address: &str = "127.0.0.1:2025"; + let listener = TcpListener::bind(bind_address).unwrap(); + println!("Listening at {}", bind_address); + + for stream in listener.incoming() { + let stream = stream.unwrap(); + handle_connection(stream); + } + + Ok(()) +} + +fn handle_connection(mut stream: TcpStream) +{ + let buf_reader = BufReader::new(&stream); + println!("CONNECTION: {buf_reader:#?}"); + let bytes = files::read_file("index.npon", 0); + stream.write_all(bytes.as_slice()).unwrap(); +} + +