diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 07a9df6..3a79346 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -41,63 +41,27 @@ jobs: run: cargo test --verbose - name: Build run: cargo build --verbose --release - - name: Upload sdo-tool.exe + - name: Upload files (windows) uses: actions/upload-artifact@v2.1.4 if: matrix.os == 'windows' with: - name: sdo-tool-windows.exe - path: target/release/sdo-tool.exe - - name: Upload sdo-tool - uses: actions/upload-artifact@v2.1.4 - if: matrix.os != 'windows' - with: - name: sdo-tool-${{ matrix.os }} - path: target/release/sdo-tool - - name: Upload signum-file.exe - uses: actions/upload-artifact@v2.1.4 - if: matrix.os == 'windows' - with: - name: signum-file-windows.exe - path: target/release/signum-file.exe - - name: Upload signum-file - uses: actions/upload-artifact@v2.1.4 - if: matrix.os != 'windows' - with: - name: signum-file-${{ matrix.os }} - path: target/release/signum-file - - name: Upload sdo-batch.exe - uses: actions/upload-artifact@v2.1.4 - if: matrix.os == 'windows' - with: - name: sdo-batch-windows.exe - path: target/release/sdo-batch.exe - - name: Upload sdo-batch - uses: actions/upload-artifact@v2.1.4 - if: matrix.os != 'windows' - with: - name: sdo-batch-${{ matrix.os }} - path: target/release/sdo-batch - - name: Upload chset-kb.exe - uses: actions/upload-artifact@v2.1.4 - if: matrix.os == 'windows' - with: - name: chset-kb-windows.exe - path: target/release/chset-kb.exe - - name: Upload chset-kb - uses: actions/upload-artifact@v2.1.4 - if: matrix.os != 'windows' - with: - name: chset-kb-${{ matrix.os }} - path: target/release/chset-kb - - name: Upload st-decode.exe - uses: actions/upload-artifact@v2.1.4 - if: matrix.os == 'windows' - with: - name: st-decode-windows.exe - path: target/release/st-decode.exe - - name: Upload st-decode + name: sdo-toolbox-windows + path: | + target/release/sdo-tool.exe + target/release/chset-kb.exe + target/release/dvips-font.exe + target/release/sdo-batch.exe + target/release/signum-file.exe + target/release/st-decode.exe + - name: Upload files (*nix) uses: actions/upload-artifact@v2.1.4 if: matrix.os != 'windows' with: - name: st-decode-${{ matrix.os }} - path: target/release/st-decode + name: sdo-toolbox-${{ matrix.os }} + path: | + target/release/sdo-tool + target/release/chset-kb + target/release/dvips-font + target/release/sdo-batch + target/release/signum-file + target/release/st-decode \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 788499c..91cc1fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,7 +891,7 @@ dependencies = [ [[package]] name = "sdo-tool" -version = "0.1.0" +version = "0.2.0" dependencies = [ "bitflags", "ccitt-t4-t6", diff --git a/Cargo.toml b/Cargo.toml index d95a550..1b81bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sdo-tool" -version = "0.1.0" +version = "0.2.0" authors = ["daniel"] edition = "2018" diff --git a/src/bin/sdo-batch.rs b/src/bin/sdo-batch.rs index e9f064f..5085df4 100644 --- a/src/bin/sdo-batch.rs +++ b/src/bin/sdo-batch.rs @@ -51,6 +51,7 @@ pub fn run(buffer: &[u8], opt: RunOpts) -> eyre::Result<()> { println!("opt: {:?}", opt); let doc_opt = Options { + file: PathBuf::from("SDO-TOOL-BUG"), out: Some(opt.out.clone()), with_images: None, print_driver: None, @@ -94,8 +95,8 @@ pub fn run(buffer: &[u8], opt: RunOpts) -> eyre::Result<()> { } let mut documents = Vec::with_capacity(capacity); - for (doc_file, input) in &doc_files { - let mut document = Document::new(&doc_opt, doc_file); + for (_doc_file, input) in &doc_files { + let mut document = Document::new(&doc_opt); document.process_sdoc(&input, &mut fc)?; documents.push(document); diff --git a/src/bin/signum-file.rs b/src/bin/signum-file.rs index 2649964..2c2c269 100644 --- a/src/bin/signum-file.rs +++ b/src/bin/signum-file.rs @@ -19,27 +19,27 @@ fn info(buffer: &[u8], opt: Options) -> color_eyre::Result<()> { } Some(b"eset") => { println!("Signum!2 Editor Font"); - println!("Use `sdo-tool {} dump` to learn more", opt.file.display()); + println!("Use `sdo-tool {}` to learn more", opt.file.display()); Ok(()) } Some(b"bimc") => { println!("Signum!2 Compressed Image"); - println!("Use `sdo-tool {} dump` to learn more", opt.file.display()); + println!("Use `sdo-tool {}` to learn more", opt.file.display()); Ok(()) } Some(b"ls30") => { println!("Signum!2 30-Point Laser Printer Font"); - println!("Use `sdo-tool {} dump` to learn more", opt.file.display()); + println!("Use `sdo-tool {}` to learn more", opt.file.display()); Ok(()) } Some(b"ps24") => { println!("Signum!2 24-Needle Printer Font"); - println!("Use `sdo-tool {} dump` to learn more", opt.file.display()); + println!("Use `sdo-tool {}` to learn more", opt.file.display()); Ok(()) } Some(b"ps09") => { println!("Signum!2 9-Needle Printer Font"); - println!("Use `sdo-tool {} dump` to learn more", opt.file.display()); + println!("Use `sdo-tool {}` to learn more", opt.file.display()); Ok(()) } Some(b"cryp") => { diff --git a/src/cli/font/mod.rs b/src/cli/font/mod.rs index b3f119d..6bc27aa 100644 --- a/src/cli/font/mod.rs +++ b/src/cli/font/mod.rs @@ -153,7 +153,7 @@ pub fn process_ps24(buffer: &[u8], _opt: &Options) -> eyre::Result<()> { Ok(()) } -pub fn process_ls30(buffer: &[u8], file: &Path, opt: &Options) -> eyre::Result<()> { +pub fn process_ls30(buffer: &[u8], opt: &Options) -> eyre::Result<()> { let (rest, lset) = match parse_ls30(buffer) { Ok(result) => result, Err(e) => { @@ -170,7 +170,7 @@ pub fn process_ls30(buffer: &[u8], file: &Path, opt: &Options) -> eyre::Result<( write_ls30_ps_bitmap("Fa", "FONT", &mut writer, &lset, None)?; return Ok(()); } else if opt.format == Format::CCITTT6 { - save_as_ccitt(&lset, opt, file)?; + save_as_ccitt(&lset, opt, &opt.file)?; return Ok(()); } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index cfbc114..f82c11c 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,23 +1,22 @@ use color_eyre::eyre::{self, eyre}; use image::ImageFormat; use signum::{images::imc::parse_imc, raster::Page}; -use std::path::{Path, PathBuf}; pub mod font; pub mod opt; pub mod sdoc; mod util; -pub fn process_bimc(buffer: &[u8], file: &Path, out_path: Option) -> eyre::Result<()> { +pub fn process_bimc(buffer: &[u8], opt: opt::Options) -> eyre::Result<()> { let decoded = parse_imc(&buffer) // .map_err(|err| eyre!("Failed to parse: {}", err))?; let page = Page::from_screen(decoded); - let out_path = if let Some(path) = out_path { + let out_path = if let Some(path) = opt.out { path } else { - file.with_extension("png") + opt.file.with_extension("png") }; let image = page.to_image(); diff --git a/src/cli/opt/mod.rs b/src/cli/opt/mod.rs index f199f3a..e0ccf3b 100644 --- a/src/cli/opt/mod.rs +++ b/src/cli/opt/mod.rs @@ -82,10 +82,11 @@ impl fmt::Display for Format { } } } - -/// OPTIONS #[derive(StructOpt)] +/// Convert a Signum file to another format pub struct Options { + /// The file to be processed (e.g. *.SDO, *.E24, *.IMC) + pub file: PathBuf, /// Where to store the output pub out: Option, /// If specified, extract all embedded images to that folder diff --git a/src/cli/sdoc/imgseq.rs b/src/cli/sdoc/imgseq.rs index 9fe8cdc..d753863 100644 --- a/src/cli/sdoc/imgseq.rs +++ b/src/cli/sdoc/imgseq.rs @@ -73,7 +73,7 @@ pub fn output_print(doc: &Document, fc: &FontCache) -> eyre::Result<()> { let out_path: PathBuf = if let Some(path) = &doc.opt.out { path.clone() } else { - let dir = doc.file.with_extension("sdo.out"); + let dir = doc.opt.file.with_extension("sdo.out"); std::fs::create_dir(&dir)?; dir }; diff --git a/src/cli/sdoc/mod.rs b/src/cli/sdoc/mod.rs index 58a70da..db57473 100644 --- a/src/cli/sdoc/mod.rs +++ b/src/cli/sdoc/mod.rs @@ -21,7 +21,6 @@ use signum::{ raster::Page, util::Buf, }; -use std::path::Path; use util::to_err_tree; use super::{ @@ -51,7 +50,7 @@ pub struct Document<'a> { // Configuration print_driver: Option, opt: &'a Options, - file: &'a Path, + //file: &'a Path, // cset pub cset: [Option; 8], pub chsets: [Option; 8], @@ -99,10 +98,9 @@ impl<'a> Document<'a> { use_matrix } - pub fn new(opt: &'a Options, file: &'a Path) -> Self { + pub fn new(opt: &'a Options) -> Self { Document { opt, - file, cset: [None, None, None, None, None, None, None, None], chsets: [None; 8], pages: vec![], @@ -390,14 +388,14 @@ impl<'a> Document<'a> { } } -pub fn process_sdoc(input: &[u8], opt: Options, file: &Path) -> eyre::Result<()> { - let mut document = Document::new(&opt, file); +pub fn process_sdoc(input: &[u8], opt: Options) -> eyre::Result<()> { + let mut document = Document::new(&opt); /*if opt.out != Path::new("-") { std::fs::create_dir_all(&opt.out)?; }*/ - let folder = file.parent().unwrap(); + let folder = opt.file.parent().unwrap(); let chsets_folder = folder.join(&opt.chsets_path); let mut fc = FontCache::new(chsets_folder); document.process_sdoc(input, &mut fc)?; diff --git a/src/cli/sdoc/pdf.rs b/src/cli/sdoc/pdf.rs index c772994..2162ef1 100644 --- a/src/cli/sdoc/pdf.rs +++ b/src/cli/sdoc/pdf.rs @@ -184,7 +184,7 @@ fn doc_meta<'a>(doc: &'a Document) -> eyre::Result> { let meta = doc.opt.meta()?; if meta.title.is_none() { let mut meta = meta.into_owned(); - let file_name = doc.file.file_name().unwrap(); + let file_name = doc.opt.file.file_name().unwrap(); let title = file_name .to_str() .ok_or_else(|| eyre!("File name contains invalid characters"))?; @@ -230,7 +230,7 @@ pub fn process_doc<'a>(doc: &'a Document, fc: &'a FontCache) -> eyre::Result eyre::Result<()> { let hnd = process_doc(doc, fc)?; - handle_out(doc.opt.out.as_deref(), &doc.file, hnd)?; + handle_out(doc.opt.out.as_deref(), &doc.opt.file, hnd)?; Ok(()) } diff --git a/src/cli/sdoc/ps.rs b/src/cli/sdoc/ps.rs index e26f8ca..63853bc 100644 --- a/src/cli/sdoc/ps.rs +++ b/src/cli/sdoc/ps.rs @@ -20,7 +20,7 @@ fn output_ps_writer( pw.write_magic()?; pw.write_meta_field("Creator", "Signum! Document Toolbox v0.3")?; - let file_name = doc.file.file_name().unwrap().to_string_lossy(); + let file_name = doc.opt.file.file_name().unwrap().to_string_lossy(); pw.write_meta_field("Title", file_name.as_ref())?; //pw.write_meta_field("CreationDate", "Sun Sep 13 23:55:06 2020")?; pw.write_meta_field("Pages", &format!("{}", doc.page_count))?; @@ -183,8 +183,8 @@ pub fn output_postscript(doc: &Document, fc: &FontCache) -> eyre::Result<()> { .opt .out .as_deref() - .unwrap_or_else(|| doc.file.parent().unwrap()); - let file = doc.file.file_stem().unwrap(); + .unwrap_or_else(|| doc.opt.file.parent().unwrap()); + let file = doc.opt.file.file_stem().unwrap(); let out = { let mut buf = out.join(file); buf.set_extension("ps"); diff --git a/src/main.rs b/src/main.rs index 984a0e3..3226fc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,24 +11,12 @@ use sdo_tool::cli::{ use std::{ fs::File, io::{BufReader, Read}, - path::PathBuf, }; use structopt::StructOpt; -#[derive(StructOpt)] -/// The options for this CLI -pub struct CLI { - /// The file to be processed - file: PathBuf, - - /// How to process that file - #[structopt(flatten)] - dump_opt: Options, -} - fn main() -> eyre::Result<()> { color_eyre::install()?; - let opt = CLI::from_args(); + let opt = Options::from_args(); let file_res = File::open(&opt.file); let file = WrapErr::wrap_err_with(file_res, || { @@ -39,12 +27,12 @@ fn main() -> eyre::Result<()> { reader.read_to_end(&mut buffer)?; match buffer.get(..4) { - Some(b"sdoc") => process_sdoc(&buffer, opt.dump_opt, &opt.file), + Some(b"sdoc") => process_sdoc(&buffer, opt), Some(b"eset") => process_eset(&buffer, None, None), - Some(b"ps09") => process_ps09(&buffer, &opt.dump_opt), - Some(b"ps24") => process_ps24(&buffer, &opt.dump_opt), - Some(b"ls30") => process_ls30(&buffer, &opt.file, &opt.dump_opt), - Some(b"bimc") => process_bimc(&buffer, &opt.file, opt.dump_opt.out), + Some(b"ps09") => process_ps09(&buffer, &opt), + Some(b"ps24") => process_ps24(&buffer, &opt), + Some(b"ls30") => process_ls30(&buffer, &opt), + Some(b"bimc") => process_bimc(&buffer, opt), Some(t) => Err(eyre!("Unknown file type {:?}", t)), None => Err(eyre!("File has less than 4 bytes")), }