Skip to content

Commit

Permalink
engines/mod: Make format_to_extension return Vec
Browse files Browse the repository at this point in the history
* Make `format_to_extension` return a Vector of strings.

* Make use of `set_extension` function of PathBuf instead of creating an
  OsString.

* Add multiple vectorized values as results of `format_to_extension`.

* Fixes #78

Signed-off-by: mr.Shu <mr@shu.io>
  • Loading branch information
mrshu committed Jun 11, 2017
1 parent 1cf8f65 commit 7c2e4e6
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,23 @@ impl<'a, I: 'a + IoProvider> ExecutionState<'a, I> {
return r;
}

// Maybe there's a nicer way to alter the extension without turning
// `name` into a Path?

let mut ext = PathBuf::from(name);
let mut ename = OsString::from(match ext.file_name() {
Some(s) => s,
None => return OpenResult::NotAvailable
});
ename.push(format_to_extension(format));
ext.set_file_name(ename);

if let FileFormat::Format = format {
self.io.input_open_format(&ext.into_os_string(), self.status)
} else {
self.io.input_open_name(&ext.into_os_string(), self.status)
for e in format_to_extension(format) {
let mut ext = PathBuf::from(name);
if !ext.set_extension(e) {
return OpenResult::NotAvailable
}

if let FileFormat::Format = format {
if let r @ OpenResult::Ok(_) = self.io.input_open_format(&ext.into_os_string(), self.status) {
return r
}
} else {
if let r @ OpenResult::Ok(_) = self.io.input_open_name(&ext.into_os_string(), self.status) {
return r
}
}
}
OpenResult::NotAvailable
}

fn input_open_name_format_gz(&mut self, name: &OsStr, format: FileFormat,
Expand Down Expand Up @@ -703,29 +704,29 @@ enum FileFormat {
Vf,
}

fn format_to_extension (format: FileFormat) -> &'static str {
fn format_to_extension (format: FileFormat) -> Vec<&'static str> {
match format {
FileFormat::AFM => ".afm",
FileFormat::Bib => ".bib",
FileFormat::Bst => ".bst",
FileFormat::Cmap => ".cmap", /* XXX: kpathsea doesn't define any suffixes for this */
FileFormat::Enc => ".enc",
FileFormat::Format => ".fmt.gz",
FileFormat::FontMap => ".map",
FileFormat::MiscFonts => ".miscfonts", /* XXX: no kpathsea suffixes */
FileFormat::Ofm => ".ofm", /* XXX: also .tfm */
FileFormat::OpenType => ".otf", /* XXX: also OTF */
FileFormat::Ovf => ".ovf", /* XXX: also .vf */
FileFormat::Pict => ".pdf", /* XXX: also .eps, .epsi, ... */
FileFormat::Pk => ".pk",
FileFormat::ProgramData => ".programdata", /* XXX no suffixes */
FileFormat::Sfd => ".sfd",
FileFormat::Tex => ".tex", /* also .{sty,cls,fd,aux,bbl,def,clo,ldf} */
FileFormat::TexPsHeader => ".pro",
FileFormat::TFM => ".tfm",
FileFormat::TrueType => ".ttf", /* XXX: also .ttc, .TTF, .TTC, .dfont */
FileFormat::Type1 => ".pfa", /* XXX: also .pfb */
FileFormat::Vf => ".vf",
FileFormat::AFM => vec!["afm"],
FileFormat::Bib => vec!["bib"],
FileFormat::Bst => vec!["bst"],
FileFormat::Cmap => vec!["cmap"], /* XXX: kpathsea doesn't define any suffixes for this */
FileFormat::Enc => vec!["enc"],
FileFormat::Format => vec!["fmt.gz"],
FileFormat::FontMap => vec!["map"],
FileFormat::MiscFonts => vec!["miscfonts"], /* XXX: no kpathsea suffixes */
FileFormat::Ofm => vec!["ofm"], /* XXX: also .tfm */
FileFormat::OpenType => vec!["otf", "OTF"],
FileFormat::Ovf => vec!["ovf", "vf"],
FileFormat::Pict => vec!["pdf", "jpg", "eps", "epsi"], /* XXX: also .eps, .epsi, ... */
FileFormat::Pk => vec!["pk"],
FileFormat::ProgramData => vec!["programdata"], /* XXX no suffixes */
FileFormat::Sfd => vec!["sfd"],
FileFormat::Tex => vec!["tex", "sty", "cls", "fd", "aux", "bbl", "def", "clo", "ldf"],
FileFormat::TexPsHeader => vec!["pro"],
FileFormat::TFM => vec!["tfm"],
FileFormat::TrueType => vec!["ttf", "ttc", "TTF", "TTC", "dfont"],
FileFormat::Type1 => vec!["pfa", "pfb"],
FileFormat::Vf => vec!["vf"],
}
}

Expand Down

0 comments on commit 7c2e4e6

Please sign in to comment.