Skip to content

Commit

Permalink
Improve help some more
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphoseer committed Feb 18, 2021
1 parent f8f80ec commit 69efa5a
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 102 deletions.
72 changes: 18 additions & 54 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
if: matrix.os == 'windows'
with:
name: sdo-tool-windows.exe
path: target/release/sdo-tool.exe
- name: Upload sdo-tool
uses: actions/[email protected]
if: matrix.os != 'windows'
with:
name: sdo-tool-${{ matrix.os }}
path: target/release/sdo-tool
- name: Upload signum-file.exe
uses: actions/[email protected]
if: matrix.os == 'windows'
with:
name: signum-file-windows.exe
path: target/release/signum-file.exe
- name: Upload signum-file
uses: actions/[email protected]
if: matrix.os != 'windows'
with:
name: signum-file-${{ matrix.os }}
path: target/release/signum-file
- name: Upload sdo-batch.exe
uses: actions/[email protected]
if: matrix.os == 'windows'
with:
name: sdo-batch-windows.exe
path: target/release/sdo-batch.exe
- name: Upload sdo-batch
uses: actions/[email protected]
if: matrix.os != 'windows'
with:
name: sdo-batch-${{ matrix.os }}
path: target/release/sdo-batch
- name: Upload chset-kb.exe
uses: actions/[email protected]
if: matrix.os == 'windows'
with:
name: chset-kb-windows.exe
path: target/release/chset-kb.exe
- name: Upload chset-kb
uses: actions/[email protected]
if: matrix.os != 'windows'
with:
name: chset-kb-${{ matrix.os }}
path: target/release/chset-kb
- name: Upload st-decode.exe
uses: actions/[email protected]
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/[email protected]
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sdo-tool"
version = "0.1.0"
version = "0.2.0"
authors = ["daniel"]
edition = "2018"

Expand Down
5 changes: 3 additions & 2 deletions src/bin/sdo-batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/bin/signum-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") => {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/font/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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(());
}

Expand Down
7 changes: 3 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>) -> 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();
Expand Down
5 changes: 3 additions & 2 deletions src/cli/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// If specified, extract all embedded images to that folder
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sdoc/imgseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
12 changes: 5 additions & 7 deletions src/cli/sdoc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use signum::{
raster::Page,
util::Buf,
};
use std::path::Path;
use util::to_err_tree;

use super::{
Expand Down Expand Up @@ -51,7 +50,7 @@ pub struct Document<'a> {
// Configuration
print_driver: Option<FontKind>,
opt: &'a Options,
file: &'a Path,
//file: &'a Path,
// cset
pub cset: [Option<String>; 8],
pub chsets: [Option<usize>; 8],
Expand Down Expand Up @@ -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![],
Expand Down Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/cli/sdoc/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn doc_meta<'a>(doc: &'a Document) -> eyre::Result<Cow<'a, Meta>> {
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"))?;
Expand Down Expand Up @@ -230,7 +230,7 @@ pub fn process_doc<'a>(doc: &'a Document, fc: &'a FontCache) -> eyre::Result<Han

pub fn output_pdf(doc: &Document, fc: &FontCache) -> 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(())
}

Expand Down
6 changes: 3 additions & 3 deletions src/cli/sdoc/ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
Expand Down Expand Up @@ -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");
Expand Down
24 changes: 6 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, || {
Expand All @@ -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")),
}
Expand Down

0 comments on commit 69efa5a

Please sign in to comment.