From 917fd957706e830b2ab20ed72243c122eeba8b4f Mon Sep 17 00:00:00 2001 From: spiders Date: Fri, 6 May 2022 21:28:33 -0700 Subject: [PATCH] worked on adding path --- src/critters.rs | 79 +++++++++++++++++++++++++++++++++++++------------ yupekosi | 13 ++++++++ 2 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 yupekosi diff --git a/src/critters.rs b/src/critters.rs index d2101c8..0b63151 100644 --- a/src/critters.rs +++ b/src/critters.rs @@ -1,4 +1,5 @@ use super::kule::*; +use std::env; use std::fs; use std::io; use voca_rs::*; @@ -158,7 +159,7 @@ $8 |||| $9$0" "kijetesantakalu" => (), "lili" => config.template = kijetesantakalu_little, "soweli" => config.template = soweli, - name => config.template = template_from_file(&name)?, + name => config.template = CritterConfig::template_from_file(&name)?, } } @@ -181,25 +182,65 @@ $8 |||| $9$0" .replace("$9", &reset()) .replace("$0", &self.object); } -} + // attempts to interpret file as a path, and if this fails, tries appending it to every location in the kijepath environment variable. + fn template_from_file(name: &str) -> Result { + let file = fs::read_to_string(name) + .map_err(|_| "mi ken ala lukin e lipu kije\ncouldn't find/read kijefile")?; + let mut lines = file.lines().skip_while(|l| l.starts_with('#')); // skips comments -// attempts to interpret file as a path, and if this fails, tries appending it to every location in the kijepath environment variable. -pub fn template_from_file(name: &str) -> Result { - let file = fs::read_to_string(name) - .map_err(|_| "mi ken ala lukin e lipu kije\ncouldn't find/read kijefile")?; - let mut lines = file.lines().skip_while(|l| l.starts_with('#')); // skips comments + let anchor: usize; + if let Some(anchor_line) = lines.next() { + anchor = anchor_line + .trim() + .parse() + .map_err(|_| "nanpa li nasa\ncouldn't parse anchor as number")?; + } else { + return Err("ale li weka tan lipu kije\nkijefile missing content"); + } + let mut critter = String::new(); + lines.for_each(|l| critter.push_str(&format!("{}\n", l))); - let anchor: usize; - if let Some(anchor_line) = lines.next() { - anchor = anchor_line - .trim() - .parse() - .map_err(|_| "nanpa li nasa\ncouldn't parse anchor as number")?; - } else { - return Err("ale li weka tan lipu kije\nkijefile missing content"); + Ok(CritterTemplate { anchor, critter }) } - let mut critter = String::new(); - lines.for_each(|l| critter.push_str(&format!("{}\n", l))); - - Ok(CritterTemplate { anchor, critter }) +} + +fn path() -> Vec { + match env::var("NASINKIJE") { + Err(_) => Vec::new(), + Ok(s) => s.split(":").map(|s| s.to_string()).collect(), + } +} + +fn list_files() -> Result, String> { + let mut files = Vec::new(); + + for i in path() { + match fs::read_dir(&i) { + Err(e) => match e.kind() { + io::ErrorKind::PermissionDenied => { + return Err( + format!("mi ken ala lukin e poki ni: {}\npermission denied", i).to_string(), + ) + } + io::ErrorKind::NotFound => { + return Err(format!( + "poki ni li lon ala: {}\ndirectory not found", + i.to_string() + )) + } + _ => return Err(format!("ijo li pakala lon ni: {}\n{:?}", i, e.kind()).to_string()), + }, + Ok(entries) => { + for read in entries { + let filename = read + .map_err(|e|format!("mi ken ala lukin e lipu lon ni: {}\n{}", i, e.to_string()).to_string())? + .file_name() + .into_string() + .map_err(|_|format!("mi ken ala sitelen UTF-8 e nimi lipu lon ni: {}\ncould not display file name as utf-8", i).to_string())?; + files.push(filename); + } + } + } + } + return Ok(files); } diff --git a/yupekosi b/yupekosi new file mode 100644 index 0000000..70b7d12 --- /dev/null +++ b/yupekosi @@ -0,0 +1,13 @@ +# yupekosi +# tan kulupu lintukamakaki +20 + $9$7 +$8 ////\|///\ $9$5 +$8 ///\\\||///\ $9$7 +$8 // _ _ \\ $9$6 +$8 _||-($1)--($2)-||_ $9$5 +$8( || () || ) + \ \\ ///\\\ // / + -// ||$3$4|| \\- + \\///||\\\// + \\\\||////$9 $0 \ No newline at end of file