Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Dec 29, 2024
1 parent d72a500 commit f705ea7
Show file tree
Hide file tree
Showing 20 changed files with 773 additions and 70 deletions.
2 changes: 2 additions & 0 deletions platform/src/family/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod signals;
pub use signals::*;

pub mod properties;

use crate::macros::match_cfg_meta;

// `target_family` specific exports
Expand Down
115 changes: 115 additions & 0 deletions platform/src/family/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,123 @@

pub const CPU_ENDIAN: &str = if cfg!(target_endian = "big") { "big" } else { "little" };

// TODO: Document
// TODO: Probably make all fields `Option`, to avoid setting empty values at runtime
pub struct PropertySet {
pub display_country: String,
pub display_language: String,
pub display_script: String,
pub display_variant: String,
pub file_encoding: String,
pub file_separator: String,
pub format_country: String,
pub format_language: String,
pub format_script: String,
pub format_variant: String,
pub ftp_nonProxyHosts: Option<String>,
pub ftp_proxyHost: Option<String>,
pub ftp_proxyPort: Option<String>,
pub http_nonProxyHosts: Option<String>,
pub http_proxyHost: Option<String>,
pub http_proxyPort: Option<String>,
pub https_proxyHost: Option<String>,
pub https_proxyPort: Option<String>,
pub java_io_tmpdir: String,
pub line_separator: String,
pub os_arch: String,
pub os_name: String,
pub os_version: String,
pub path_separator: String,
pub socksNonProxyHosts: Option<String>,
pub socksProxyHost: Option<String>,
pub socksProxyPort: Option<String>,
pub stderr_encoding: Option<String>,
pub stdout_encoding: Option<String>,
pub sun_arch_abi: Option<String>,
pub sun_arch_data_model: String,
pub sun_cpu_endian: String,
pub sun_cpu_isalist: Option<String>,
pub sun_io_unicode_encoding: String,
pub sun_jnu_encoding: String,
pub sun_os_patch_level: String,
pub user_dir: String,
pub user_home: String,
pub user_name: String,
}

impl PropertySet {
pub fn fill(&mut self) -> Result<(), Error> {
fill_properties_impl(self)
}
}

impl Default for PropertySet {
fn default() -> Self {
PropertySet {
// Set the constant properties, exported below
file_separator: FILE_SEPARATOR.into(),
line_separator: LINE_SEPARATOR.into(),
os_arch: OS_ARCH.into(),
path_separator: PATH_SEPARATOR.into(),
sun_cpu_endian: CPU_ENDIAN.into(),
sun_io_unicode_encoding: UNICODE_ENCODING.into(),

// Others will need to be filled by their platform-specific implementations
display_country: String::new(),
display_language: String::new(),
display_script: String::new(),
display_variant: String::new(),
file_encoding: String::new(),
format_country: String::new(),
format_language: String::new(),
format_script: String::new(),
format_variant: String::new(),
ftp_nonProxyHosts: None,
ftp_proxyHost: None,
ftp_proxyPort: None,
http_nonProxyHosts: None,
http_proxyHost: None,
http_proxyPort: None,
https_proxyHost: None,
https_proxyPort: None,
java_io_tmpdir: String::new(),
os_name: String::new(),
os_version: String::new(),
socksNonProxyHosts: None,
socksProxyHost: None,
socksProxyPort: None,
stderr_encoding: None,
stdout_encoding: None,
sun_arch_abi: None,
sun_arch_data_model: String::new(),
sun_cpu_isalist: None,
sun_jnu_encoding: String::new(),
sun_os_patch_level: String::new(),
user_dir: String::new(),
user_home: String::new(),
user_name: String::new(),
}
}
}

#[derive(Debug)]
pub enum Error {
WorkingDir,
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::WorkingDir => f.write_str("Could not determine currenting working directory")
}
}
}

impl core::error::Error for Error {}

// Export family specific properties

use std::fmt::{Display, Formatter};
#[cfg(target_family = "unix")]
pub use super::unix::properties::*;
#[cfg(target_family = "windows")]
Expand Down
106 changes: 106 additions & 0 deletions platform/src/family/unix/linux/locale.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use core::ffi::CStr;

pub(super) fn locale_aliases() -> impl Iterator<Item = &'static (&'static CStr, &'static CStr)> {
const LINUX_LOCALE_ALIASES: &[(&CStr, &CStr)] = &[
(c"hs", c"en_US"), // used on Linux, not clear what it stands for
(c"ua", c"en_US"), // used on Linux, not clear what it stands for
(c"bokmal", c"nb_NO"),
(c"bokm\xE5cl", c"nb_NO"),
(c"catalan", c"ca_ES"),
(c"croatian", c"hr_HR"),
(c"czech", c"cs_CZ"),
(c"danish", c"da_DK"),
(c"dansk", c"da_DK"),
(c"deutsch", c"de_DE"),
(c"dutch", c"nl_NL"),
(c"eesti", c"et_EE"),
(c"estonian", c"et_EE"),
(c"finnish", c"fi_FI"),
(c"fran\xE7c\x61is", c"fr_FR"),
(c"french", c"fr_FR"),
(c"galego", c"gl_ES"),
(c"galician", c"gl_ES"),
(c"german", c"de_DE"),
(c"greek", c"el_GR"),
(c"hebrew", c"iw_IL"),
(c"hrvatski", c"hr_HR"),
(c"hungarian", c"hu_HU"),
(c"icelandic", c"is_IS"),
(c"italian", c"it_IT"),
(c"japanese", c"ja_JP"),
(c"korean", c"ko_KR"),
(c"lithuanian", c"lt_LT"),
(c"norwegian", c"no_NO"),
(c"nynorsk", c"nn_NO"),
(c"polish", c"pl_PL"),
(c"portuguese", c"pt_PT"),
(c"romanian", c"ro_RO"),
(c"russian", c"ru_RU"),
(c"slovak", c"sk_SK"),
(c"slovene", c"sl_SI"),
(c"slovenian", c"sl_SI"),
(c"spanish", c"es_ES"),
(c"swedish", c"sv_SE"),
(c"thai", c"th_TH"),
(c"turkish", c"tr_TR"),
];

crate::locale::base_locale_aliases().chain(LINUX_LOCALE_ALIASES.into_iter())
}

pub(super) fn language_names() -> impl Iterator<Item = &'static (&'static CStr, &'static CStr)> {
const LINUX_LANGUAGE_NAMES: &[(&CStr, &CStr)] = &[
(c"hs", c"en"), // used on Linux, not clear what it stands for
(c"ua", c"en"), // used on Linux, not clear what it stands for
(c"catalan", c"ca"),
(c"croatian", c"hr"),
(c"czech", c"cs"),
(c"danish", c"da"),
(c"dansk", c"da"),
(c"deutsch", c"de"),
(c"dutch", c"nl"),
(c"finnish", c"fi"),
(c"fran\xE7c\x61is", c"fr"),
(c"french", c"fr"),
(c"german", c"de"),
(c"greek", c"el"),
(c"hebrew", c"he"),
(c"hrvatski", c"hr"),
(c"hungarian", c"hu"),
(c"icelandic", c"is"),
(c"italian", c"it"),
(c"japanese", c"ja"),
(c"norwegian", c"no"),
(c"polish", c"pl"),
(c"portuguese", c"pt"),
(c"romanian", c"ro"),
(c"russian", c"ru"),
(c"slovak", c"sk"),
(c"slovene", c"sl"),
(c"slovenian", c"sl"),
(c"spanish", c"es"),
(c"swedish", c"sv"),
(c"turkish", c"tr"),
];

crate::locale::base_language_names().chain(LINUX_LANGUAGE_NAMES.into_iter())
}

pub(super) fn script_names() -> impl Iterator<Item = &'static (&'static CStr, &'static CStr)> {
const LINUX_SCRIPT_NAMES: &[(&CStr, &CStr)] = &[
(c"cyrillic", c"Cyrl"),
(c"devanagari", c"Deva"),
(c"iqtelif", c"Latn"),
(c"latin", c"Latn"),
];

crate::locale::base_script_names().chain(LINUX_SCRIPT_NAMES.into_iter())
}

pub(super) fn country_names() -> impl Iterator<Item = &'static (&'static CStr, &'static CStr)> {
const LINUX_COUNTRY_NAMES: &[(&CStr, &CStr)] = &[
(c"RN", c"US"), // used on Linux, not clear what it stands for
];

crate::locale::base_country_names().chain(LINUX_COUNTRY_NAMES.into_iter())
}
1 change: 1 addition & 0 deletions platform/src/family/unix/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod locale;
pub mod properties;
Loading

0 comments on commit f705ea7

Please sign in to comment.