chiark / gitweb /
subst: Substitute x* variables into magic template
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 13:35:10 +0000 (14:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 17:00:02 +0000 (18:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/shapelib.rs

index 582ef22573032ea61341c61f5c49c0e4567edb70..6bf29ebfe99f15f89535da582015245dd775a5fb 100644 (file)
@@ -1331,6 +1331,16 @@ fn process_files_entry(
       PerhapsSubst::N(s) => Substituting::new(mformat, dollars, s),
       PerhapsSubst::Y(s) => s,
     } }
+    #[throws(SubstError)]
+    pub fn is_y(
+      self,
+    ) -> Substituting<'i> { match self {
+      PerhapsSubst::Y(s) => s,
+      PerhapsSubst::N(s) => throw!(SubstError {
+        kind: InternalLogicError::new("expected Y").into(),
+        input: s.into(),
+      })
+    } }
   }
 
   fn colour_subst_1<'s, S>(
@@ -1411,8 +1421,12 @@ fn process_files_entry(
 
       let spec = Substituting::new(mformat, Dollars::Text, &magic.template);
       let spec = substn(spec, "_image", &image_table)?;
-      let spec = c_colour_all(spec.into())?;
-
+      let mut spec = c_colour_all(spec.into())?.is_y()?;
+      for (k,v) in &fe.extra_fields {
+        if k.starts_with('x') {
+          spec = substn(spec, &format!("_{}", k), v)?;
+        }
+      }
       let spec = spec.finish()?;
       trace!("magic item {}\n\n{}\n", &item_name, &spec);