1
use std::ffi::OsStr;
2
use std::path::Path;
3

            
4
/// Specify the parity game file format.
5
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
7
pub enum ParityGameFormat {
8
    PG,
9
    VPG,
10
}
11

            
12
/// Guesses the parity game file format from the file extension, or uses a fixed format if provided.
13
pub fn guess_format_from_extension(path: &Path, format: Option<ParityGameFormat>) -> Option<ParityGameFormat> {
14
    if let Some(format) = format {
15
        return Some(format);
16
    }
17

            
18
    if path.extension() == Some(OsStr::new("pg")) {
19
        Some(ParityGameFormat::PG)
20
    } else if path.extension() == Some(OsStr::new("vpg")) || path.extension() == Some(OsStr::new("svpg")) {
21
        Some(ParityGameFormat::VPG)
22
    } else {
23
        None
24
    }
25
}