/************************************************************************** Comparison function for qsort; i1 and i2 are pointers to an event (enum event_type). **************************************************************************/ static int compar_event_message_texts(const void *i1, const void *i2) { const enum event_type *j1 = i1; const enum event_type *j2 = i2; return fc_strcasecmp(get_event_message_text(*j1), get_event_message_text(*j2)); }
/************************************************************************** Returns base type matching rule name or NULL if there is no base type with such name. **************************************************************************/ struct base_type *base_type_by_rule_name(const char *name) { const char *qs = Qn_(name); base_type_iterate(pbase) { if (!fc_strcasecmp(base_rule_name(pbase), qs)) { return pbase; } } base_type_iterate_end; return NULL; }
/************************************************************************* Get trade route type by name. *************************************************************************/ enum trade_route_type trade_route_type_by_name(const char *name) { enum trade_route_type type; for (type = TRT_NATIONAL; type < TRT_LAST; type++) { if (!fc_strcasecmp(trade_route_type_names[type], name)) { return type; } } return TRT_LAST; }
/**************************************************************************** Return the specialist type with the given (untranslated!) rule name. Returns NULL if none match. ****************************************************************************/ struct specialist *specialist_by_rule_name(const char *name) { const char *qname = Qn_(name); specialist_type_iterate(i) { struct specialist *sp = specialist_by_number(i); if (0 == fc_strcasecmp(specialist_rule_name(sp), qname)) { return sp; } } specialist_type_iterate_end; return NULL; }
/*************************************************************************** Must be called during the initialization phase of server and client to initialize the character encodings to be used. Pass an internal encoding of NULL to use the local encoding internally. ***************************************************************************/ void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration) { #ifdef HAVE_ICONV if (my_use_transliteration) { transliteration_string = "//TRANSLIT"; } else { transliteration_string = ""; } /* Set the data encoding - first check $FREECIV_DATA_ENCODING, * then fall back to the default. */ data_encoding = getenv("FREECIV_DATA_ENCODING"); if (!data_encoding) { /* Currently the rulesets are in latin1 (ISO-8859-1). */ data_encoding = FC_DEFAULT_DATA_ENCODING; } /* Set the local encoding - first check $FREECIV_LOCAL_ENCODING, * then ask the system. */ local_encoding = getenv("FREECIV_LOCAL_ENCODING"); if (!local_encoding) { #ifdef HAVE_LIBCHARSET local_encoding = locale_charset(); #else #ifdef HAVE_LANGINFO_CODESET local_encoding = nl_langinfo(CODESET); #else local_encoding = ""; #endif #endif if (fc_strcasecmp(local_encoding, "ANSI_X3.4-1968") == 0 || fc_strcasecmp(local_encoding, "ASCII") == 0 || fc_strcasecmp(local_encoding, "US-ASCII") == 0) { /* HACK: use latin1 instead of ascii in typical cases when the * encoding is unconfigured. */ local_encoding = "ISO-8859-1"; } if (fc_strcasecmp(local_encoding, "646") == 0) { /* HACK: On Solaris the encoding always comes up as "646" (ascii), * which iconv doesn't understand. Work around it by using UTF-8 * instead. */ local_encoding = "UTF-8"; } } /* Set the internal encoding - first check $FREECIV_INTERNAL_ENCODING, * then check the passed-in default value, then fall back to the local * encoding. */ internal_encoding = getenv("FREECIV_INTERNAL_ENCODING"); if (!internal_encoding) { internal_encoding = my_internal_encoding; if (!internal_encoding) { internal_encoding = local_encoding; } } #ifdef ENABLE_NLS bind_textdomain_codeset(PACKAGE, internal_encoding); #endif #ifdef DEBUG fprintf(stderr, "Encodings: Data=%s, Local=%s, Internal=%s\n", data_encoding, local_encoding, internal_encoding); #endif #else /* log_* may not work at this point. */ #endif is_init = TRUE; }