From 52d911a25a6f0232c40e8e2371213aef9cbc93ae Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Tue, 12 Sep 2023 19:28:13 -0700
Subject: [PATCH] implement Exit/Delete

---
 src/main.rs | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 5ab8fc8..e3bf209 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -328,10 +328,13 @@ enum ScriptAction {
     Replace(u32),
     Flag,
     Block,
+    Delete,
 }
 enum ScriptActionParseResult {
     Pass,
     Block,
+    Exit,
+    Delete,
 }
 struct ParseScriptActionErr;
 impl std::str::FromStr for ScriptActionParseResult {
@@ -341,6 +344,10 @@ impl std::str::FromStr for ScriptActionParseResult {
             Ok(Self::Pass)
         }else if s=="block\n"{
             Ok(Self::Block)
+        }else if s=="exit\n"{
+            Ok(Self::Exit)
+        }else if s=="delete\n"{
+            Ok(Self::Delete)
         }else{
             Err(ParseScriptActionErr)
         }
@@ -355,7 +362,7 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
     let mut replace_map=get_replace_map()?;
     let mut blocked = get_blocked()?;
 
-    for entry in std::fs::read_dir("maps/unprocessed")? {
+    'map_loop: for entry in std::fs::read_dir("maps/unprocessed")? {
         let file_thing=entry?;
         println!("processing map={:?}",file_thing.file_name());
         let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
@@ -436,6 +443,8 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
                                 id+=1;
                                 ScriptAction::Block
                             },
+                            ScriptActionParseResult::Exit => break 'map_loop,
+                            ScriptActionParseResult::Delete => ScriptAction::Delete,
                         }
                     };
                     
@@ -451,7 +460,12 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
                             }else{
                                 panic!("failed to get replacement source id={} location={}",replace_id,location);
                             }
-                        }
+                        },
+                        ScriptAction::Delete => {
+                            println!("deleted source location={}",get_full_name(&dom, script));
+                            replace_count+=1;
+                            dom.destroy(script.referent());
+                        },
                         ScriptAction::Flag => {
                             println!("flagged source location={}",get_full_name(&dom, script));
                             fail_type=Interactive::Flagged;