From eb2a8c1ac8db20d176b1af6a2ea26a5b27b996d9 Mon Sep 17 00:00:00 2001 From: Qrius Date: Thu, 26 Sep 2024 00:11:05 +0200 Subject: Add function for including a file, without doing any macro processing on it --- src/macro_processor/macro_processor.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs index 68347d0..3164aa6 100644 --- a/src/macro_processor/macro_processor.rs +++ b/src/macro_processor/macro_processor.rs @@ -152,6 +152,19 @@ fn smp_builtin_include( return smp.process_input(&input_file); } +/// Include a new file verbatum, don't do ANY additional processing +fn smp_builtin_include_verbatum( + smp: &mut MacroProcessor, + macro_name: &str, + args: &mut [String], +) -> Result { + if args.len() < 1 { + return Ok(macro_name.to_string()); + } + let arg0 = smp.process_input(&args[0])?; + fs::read_to_string(&arg0).map_err(|e| SMPError::IncludeError(2, e, arg0)) +} + /// Simply execute argument as shell command fn smp_builtin_shell( smp: &mut MacroProcessor, @@ -257,6 +270,10 @@ impl MacroProcessor { String::from("include"), MacroType::Function(smp_builtin_include), ); + self.define_macro( + String::from("include_verbatum"), + MacroType::Function(smp_builtin_include_verbatum), + ); self.define_macro( String::from("shell"), MacroType::Function(smp_builtin_shell), -- cgit v1.2.3