diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-22 23:33:33 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-22 23:33:33 +0100 |
| commit | 4115d83eb537ffbd81e2fd8d12790a8fad769199 (patch) | |
| tree | b55c6b73a488d6dab7631463ec22cb575c7e29b9 /lib/xixanta/src | |
| parent | 4628873cfc53d3bdc7a0834b3edbb02b0b9cf4a7 (diff) | |
| download | tools.nes-4115d83eb537ffbd81e2fd8d12790a8fad769199.tar.gz tools.nes-4115d83eb537ffbd81e2fd8d12790a8fad769199.zip | |
nasm: Allow file paths for the configuration
This opens up the door for developers to pass their own configuration
files.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src')
| -rw-r--r-- | lib/xixanta/src/mapping.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs index a196c8e..12b64c8 100644 --- a/lib/xixanta/src/mapping.rs +++ b/lib/xixanta/src/mapping.rs @@ -97,18 +97,26 @@ pub struct Mapping { } /// Returns a vector corresponding to the configuration of mappings that is -/// expected for the given `name`. Returns an error if the configuration cannot -/// be parsed or there's something wrong about it. +/// expected for the given `name`. This `name` can either be an already known +/// identifier (e.g. "nrom"), or a file path. Returns an error if the +/// configuration cannot be parsed or there's something wrong about it. pub fn get_mapping_configuration(name: &str) -> Result<Vec<Mapping>, String> { - let text = match name.to_lowercase().as_str() { - "empty" => EMPTY_CONFIG, - "nrom" => NROM_CONFIG, - "nrom65" => NROM65_CONFIG, - "uxrom" | "unrom" => UXROM_CONFIG, - _ => return Err("mapper configuration is not known".to_string()), + let configuration = if std::fs::exists(name).unwrap_or(false) { + match std::fs::read_to_string(name) { + Ok(contents) => load_configuration_for(contents.as_str())?, + Err(_) => return Err(format!("could not read '{}'", name)), + } + } else { + let text = match name.to_lowercase().as_str() { + "empty" => EMPTY_CONFIG, + "nrom" => NROM_CONFIG, + "nrom65" => NROM65_CONFIG, + "uxrom" | "unrom" => UXROM_CONFIG, + _ => return Err("mapper configuration is not known".to_string()), + }; + load_configuration_for(text)? }; - let configuration = load_configuration_for(text)?; validate_configuration(&configuration)?; Ok(configuration) |
