[Locales::] Locales. Locales are what operating-system people call the text encodings used when interacting with them: in filenames, or when printing to the console. @ We will support two different locales: @e SHELL_LOCALE from 0 @e CONSOLE_LOCALE = char *Locales::name(int L) { switch (L) { case SHELL_LOCALE: return "shell"; case CONSOLE_LOCALE: return "console"; } return ""; } int Locales::parse_locale(char *name) { for (int i=0; i= NO_DEFINED_LOCALE_VALUES)) Errors::fatal("locale out of range"); if (locales_unset) return Locales::platform_locale(); if (locale_settings[L] >= 0) return locale_settings[L]; return Locales::platform_locale(); } void Locales::set(int L, int E) { if ((L < 0) || (L >= NO_DEFINED_LOCALE_VALUES)) Errors::fatal("locale out of range"); if (locales_unset) { for (int i=0; i 0) WRITE(", "); WRITE("%s = ", Locales::name(i)); Locales::write_locale(OUT, Locales::get(i)); } WRITE("\n"); } void Locales::write_locale(OUTPUT_STREAM, int L) { switch (L) { case -1: WRITE("platform (= "); Locales::write_locale(OUT, Locales::platform_locale()); WRITE(")"); break; case FILE_ENCODING_ISO_STRF: WRITE("iso-latin1"); break; case FILE_ENCODING_UTF8_STRF: WRITE("utf-8"); break; default: WRITE("?"); break; } } @ And this is how we determine the default; see //POSIX Platforms// and //Windows Platform// for these |LOCALE_IS_*| constants. = int Locales::platform_locale(void) { #ifdef LOCALE_IS_ISO return FILE_ENCODING_ISO_STRF; #endif #ifndef LOCALE_IS_ISO #ifdef LOCALE_IS_UTF8 return FILE_ENCODING_UTF8_STRF; #endif #ifndef LOCALE_IS_UTF8 Errors::fatal("built without either LOCALE_IS_ISO or LOCALE_IS_UTF8"); return FILE_ENCODING_UTF8_STRF; #endif #endif } @ This unlovely function parses a comma-separated list of assignments in the form |LOCALE=ENCODING|, returning |TRUE| if this was syntactically valid and |FALSE| if not. = int Locales::set_locales(char *text) { if (text == NULL) return FALSE; for (int at=0; ((at >= 0) && (text[at])); ) { int c = -1; for (int i=at; text[i]; i++) if (text[i] == '=') { c = i; break; } if (c == -1) return FALSE; if (c-at >= 16) return FALSE; char L1[16], L2[16]; for (int i=0; i<16; i++) { L1[i] = 0; L2[i] = 0; } for (int i=0; i= NO_DEFINED_LOCALE_VALUES)) return FALSE; if (E == 0) return FALSE; Locales::set(L, E); at = next_at; } return TRUE; }