From 313e059f367f2ac291cd409e77d22673f9595848 Mon Sep 17 00:00:00 2001 From: Qrius Date: Wed, 5 Mar 2025 08:41:05 +0100 Subject: First iteration of py skaldpress version --- skaldpress_main.rs | 324 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 324 insertions(+) create mode 100644 skaldpress_main.rs (limited to 'skaldpress_main.rs') diff --git a/skaldpress_main.rs b/skaldpress_main.rs new file mode 100644 index 0000000..5e6530c --- /dev/null +++ b/skaldpress_main.rs @@ -0,0 +1,324 @@ +use skaldpress::macro_processor::error::SMPError; +use skaldpress::macro_processor::macro_processor::{MacroProcessorWarning, MacroType}; +use skaldpress::skaldpress::filelists::{make_filelist, FileList, FileListFileTargetAction}; +use skaldpress::skaldpress::parseopts::{parseopts, Opts}; +use std::cmp::Ordering; +use std::collections::HashMap; +use std::collections::VecDeque; +use std::fs; +use std::path::Path; +use std::time::Instant; + +use skaldpress::macro_processor::MacroProcessor; +use skaldpress::skaldpress::error::SkaldpressError; +use skaldpress::skaldpress::error::{ + SP_COMPILE_FILE_EXTENSION_ERROR_2, SP_COMPILE_FILE_MACRO_PROCESS_ERROR, + SP_COMPILE_FILE_TEMPLATE_READ_ERROR, SP_COMPILE_TEMPLATE_MACRO_PROCESS_ERROR, + SP_GEN_DEST_STRIP_PREFIX_ERROR, +}; +use skaldpress::skaldpress::metadata_parser::extract_parse_yaml_metadata; +use skaldpress::skaldpress::metadata_parser::YamlValue; + +/// Convenience function for doing cmp on a metadata key of two arbitrary indexes +/// This takes a macro_processor as input, so that it can emit warnings if the ordering failed in +/// any way. +fn order_index_by_cached_data( + smp: &mut MacroProcessor, + key: &str, + a: &usize, + b: &usize, +) -> Ordering { + let compiled_files: &Vec; + unsafe { + compiled_files = COMPILED_FILES.as_ref(); + } + if *a >= compiled_files.len() { + smp.warnings.push(MacroProcessorWarning::new(format!( + "\"a\" is not a cached file {} >= {}", + *a, + compiled_files.len() + ))); + return Ordering::Equal; + } + if *b >= compiled_files.len() { + smp.warnings.push(MacroProcessorWarning::new(format!( + "\"b\" is not a cached file {} >= {}", + *b, + compiled_files.len() + ))); + return Ordering::Equal; + } + let Some(a) = &compiled_files[*a].metadata.get(key) else { + smp.warnings.push(MacroProcessorWarning::new(format!( + "Key {:?} not found for ordering data in {:?}", + key, compiled_files[*a].source_path + ))); + return Ordering::Equal; + }; + let Some(b) = &compiled_files[*b].metadata.get(key) else { + smp.warnings.push(MacroProcessorWarning::new(format!( + "Key {:?} not found for ordering data in {:?}", + key, compiled_files[*b].source_path + ))); + return Ordering::Equal; + }; + a.cmp(b) +} + +/// SMP Macro for getting all files with specific tag, this is only _really_ effective the second run +/// +/// Usage in files: +/// all_tagged_by(,