diff options
author | Hubert Figuière <hub@figuiere.net> | 2024-01-09 20:20:19 -0500 |
---|---|---|
committer | Hubert Figuière <hub@figuiere.net> | 2024-01-20 23:28:42 -0500 |
commit | 64006d7c509ae91d59f7fcc38864cf4081cf28c4 (patch) | |
tree | b3cd0e8e2a08d2faa762940b2f4d985e55f392bf | |
parent | 589550797b1c1d6351d3394a3ddf96f34ae7f30b (diff) |
api: Added the extensions API call
Signed-off-by: Hubert Figuière <hub@figuiere.net>
-rw-r--r-- | examples/extensions.rs | 28 | ||||
-rw-r--r-- | src/capi.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 20 |
3 files changed, 51 insertions, 3 deletions
diff --git a/examples/extensions.rs b/examples/extensions.rs new file mode 100644 index 0000000..3d0c829 --- /dev/null +++ b/examples/extensions.rs @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +/* + * libopenraw - examples/extensions.rs + * + * Copyright (C) 2024 Hubert Figuière + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +fn main() { + let exts = libopenraw::extensions(); + println!("Extensions supported"); + for ext in exts { + println!("{ext}"); + } +} diff --git a/src/capi.rs b/src/capi.rs index 4901470..bedcf6e 100644 --- a/src/capi.rs +++ b/src/capi.rs @@ -366,9 +366,9 @@ unsafe extern "C" fn or_get_extract_rawdata( /// The storage for the static strings. The CString array /// is just used to keep the pointers valid. static STATIC_EXTS: Lazy<Vec<CString>> = Lazy::new(|| { - crate::identify::EXT_TO_TYPE - .keys() - .map(|e| CString::new(*e).expect("static C string failed")) + crate::extensions() + .iter() + .map(|e| CString::new(e.as_bytes()).expect("static C string failed")) .collect() }); @@ -23,6 +23,8 @@ #[macro_use] extern crate log; +use once_cell::sync::Lazy; + #[macro_use] mod dump; #[macro_use] @@ -320,6 +322,24 @@ impl From<TypeId> for u32 { } } +static EXTENSIONS: Lazy<Vec<String>> = Lazy::new(|| { + crate::identify::EXT_TO_TYPE + .iter() + .filter_map(|(e, t)| { + if *t != Type::Jpeg { + Some(String::from(*e)) + } else { + None + } + }) + .collect() +}); + +/// Return the extensions for raw files (in lowercase). +pub fn extensions() -> &'static [String] { + &EXTENSIONS +} + #[cfg(test)] mod test { use super::TypeId; |