static void appendShortStringElement(const char *src, int32_t len, char *result, int32_t *resultSize, int32_t capacity, char arg) { if(len) { if(*resultSize) { if(*resultSize < capacity) { uprv_strcat(result, "_"); } (*resultSize)++; } *resultSize += len + 1; if(*resultSize < capacity) { uprv_strncat(result, &arg, 1); uprv_strncat(result, src, len); } } }
const char *pkg_writeCharListWrap(FileStream *s, CharList *l, const char *delim, const char *brk, int32_t quote) { int32_t ln = 0; char buffer[1024]; while(l != NULL) { if(l->str) { uprv_strncpy(buffer, l->str, 1020); buffer[1019]=0; if(quote < 0) { /* remove quotes */ if(buffer[uprv_strlen(buffer)-1] == '"') { buffer[uprv_strlen(buffer)-1] = '\0'; } if(buffer[0] == '"') { uprv_strcpy(buffer, buffer+1); } } else if(quote > 0) { /* add quotes */ if(l->str[0] != '"') { uprv_strcpy(buffer, "\""); uprv_strncat(buffer, l->str,1020); } if(l->str[uprv_strlen(l->str)-1] != '"') { uprv_strcat(buffer, "\""); } } T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer)); ln += (int32_t)uprv_strlen(l->str); } if(l->next && delim) { if(ln > 60 && brk) { ln = 0; T_FileStream_write(s, brk, (int32_t)uprv_strlen(brk)); } T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim)); } l = l->next; } return NULL; }
static void TinyString_appendn(TinyString *This, const char *what, int32_t n) { int32_t newLen; newLen = This->length + n; if (newLen >= This->fCapacity) { int32_t newCapacity = newLen * 2; char *newBuf = (char *)uprv_malloc(newCapacity+1); if (newBuf != NULL) { uprv_strcpy(newBuf, This->s); if (This->s != This->fStaticBuf) { uprv_free(This->s); } This->s = newBuf; This->fCapacity = newCapacity; } } if (newLen < This->fCapacity) { uprv_strncat(This->s+This->length, what, n); This->length = newLen; } }
TZEnumeration(const char* country) : map(NULL), len(0), pos(0) { if (!getOlsonMeta()) { return; } char key[] = {0, 0, 0, 0,0, 0, 0,0, 0, 0,0}; // e.g., "US", or "Default" for no country if (country) { uprv_strncat(key, country, 2); } else { uprv_strcpy(key, kDEFAULT); } UErrorCode ec = U_ZERO_ERROR; UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec); top = ures_getByKey(top, kREGIONS, top, &ec); // dereference 'Regions' section if (U_SUCCESS(ec)) { UResourceBundle res; ures_initStackObject(&res); ures_getByKey(top, key, &res, &ec); // The list of zones is a list of integers, from 0..n-1, // where n is the total number of system zones. const int32_t* v = ures_getIntVector(&res, &len, &ec); if (U_SUCCESS(ec)) { U_ASSERT(len > 0); map = (int32_t*)uprv_malloc(sizeof(int32_t) * len); if (map != 0) { for (uint16_t i=0; i<len; ++i) { U_ASSERT(v[i] >= 0 && v[i] < OLSON_ZONE_COUNT); map[i] = v[i]; } } } else { U_DEBUG_TZ_MSG(("Failed to load tz for region %s: %s\n", country, u_errorName(ec))); } ures_close(&res); } ures_close(top); }
static int32_t ucol_sit_dumpSpecs(CollatorSpec *s, char *destination, int32_t capacity, UErrorCode *status) { int32_t i = 0, j = 0; int32_t len = 0; char optName; if(U_SUCCESS(*status)) { for(i = 0; i < UCOL_SIT_ITEMS_COUNT; i++) { if(s->entries[i].start) { if(len) { if(len < capacity) { uprv_strcat(destination, "_"); } len++; } optName = *(s->entries[i].start); if(optName == languageArg || optName == regionArg || optName == variantArg || optName == keywordArg) { for(j = 0; j < s->entries[i].len; j++) { if(len + j < capacity) { destination[len+j] = uprv_toupper(*(s->entries[i].start+j)); } } len += s->entries[i].len; } else { len += s->entries[i].len; if(len < capacity) { uprv_strncat(destination,s->entries[i].start, s->entries[i].len); } } } } return len; } else { return 0; } }
static void ucol_sit_calculateWholeLocale(CollatorSpec *s) { // put the locale together, unless we have a done // locale if(s->locale[0] == 0) { // first the language uprv_strncat(s->locale, s->locElements[UCOL_SIT_LANGUAGE], loc3066Capacity-1); // then the script, if present if(*(s->locElements[UCOL_SIT_SCRIPT])) { uprv_strncat(s->locale, "_", loc3066Capacity-1); uprv_strncat(s->locale, s->locElements[UCOL_SIT_SCRIPT], loc3066Capacity-1); } // then the region, if present if(*(s->locElements[UCOL_SIT_REGION])) { uprv_strncat(s->locale, "_", loc3066Capacity-1); uprv_strncat(s->locale, s->locElements[UCOL_SIT_REGION], loc3066Capacity-1); } else if(*(s->locElements[UCOL_SIT_VARIANT])) { // if there is a variant, we need an underscore uprv_strncat(s->locale, "_", loc3066Capacity-1); } // add variant, if there if(*(s->locElements[UCOL_SIT_VARIANT])) { uprv_strncat(s->locale, "_", loc3066Capacity-1); uprv_strncat(s->locale, s->locElements[UCOL_SIT_VARIANT], loc3066Capacity-1); } // if there is a collation keyword, add that too if(*(s->locElements[UCOL_SIT_KEYWORD])) { uprv_strncat(s->locale, collationKeyword, loc3066Capacity-1); uprv_strncat(s->locale, s->locElements[UCOL_SIT_KEYWORD], loc3066Capacity-1); } // if there is a provider keyword, add that too if(*(s->locElements[UCOL_SIT_PROVIDER])) { uprv_strncat(s->locale, providerKeyword, loc3066Capacity-1); uprv_strncat(s->locale, s->locElements[UCOL_SIT_PROVIDER], loc3066Capacity-1); } } }
U_CAPI void U_EXPORT2 uplug_init(UErrorCode *status) { #if !U_ENABLE_DYLOAD (void)status; /* unused */ #else const char *plugin_dir; if(U_FAILURE(*status)) return; plugin_dir = getenv("ICU_PLUGINS"); #if defined(DEFAULT_ICU_PLUGINS) if(plugin_dir == NULL || !*plugin_dir) { plugin_dir = DEFAULT_ICU_PLUGINS; } #endif #if UPLUG_TRACE DBG((stderr, "ICU_PLUGINS=%s\n", plugin_dir)); #endif if(plugin_dir != NULL && *plugin_dir) { FILE *f; #ifdef OS390BATCH /* There are potentially a lot of ways to implement a plugin directory on OS390/zOS */ /* Keeping in mind that unauthorized file access is logged, monitored, and enforced */ /* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNIX */ /* System Services. Alternative techniques might be allocating a member in */ /* SYS1.PARMLIB or setting an environment variable "ICU_PLUGIN_PATH" (?). The */ /* DDNAME can be connected to a file in the HFS if need be. */ uprv_strncpy(plugin_file,"//DD:ICUPLUG", 2047); /* JAM 20 Oct 2011 */ #else uprv_strncpy(plugin_file, plugin_dir, 2047); uprv_strncat(plugin_file, U_FILE_SEP_STRING,2047); uprv_strncat(plugin_file, "icuplugins",2047); uprv_strncat(plugin_file, U_ICU_VERSION_SHORT ,2047); uprv_strncat(plugin_file, ".txt" ,2047); #endif #if UPLUG_TRACE DBG((stderr, "pluginfile= %s\n", plugin_file)); #endif #ifdef __MVS__ if (iscics()) /* 12 Nov 2011 JAM */ { f = NULL; } else #endif { f = fopen(plugin_file, "r"); } if(f != NULL) { char linebuf[1024]; char *p, *libName=NULL, *symName=NULL, *config=NULL; int32_t line = 0; while(fgets(linebuf,1023,f)) { line++; if(!*linebuf || *linebuf=='#') { continue; } else { p = linebuf; while(*p&&isspace((int)*p)) p++; if(!*p || *p=='#') continue; libName = p; while(*p&&!isspace((int)*p)) { p++; } if(!*p || *p=='#') continue; /* no tab after libname */ *p=0; /* end of libname */ p++; while(*p&&isspace((int)*p)) { p++; } if(!*p||*p=='#') continue; /* no symname after libname +tab */ symName = p; while(*p&&!isspace((int)*p)) { p++; } if(*p) { /* has config */ *p=0; ++p; while(*p&&isspace((int)*p)) { p++; } if(*p) { config = p; } } /* chop whitespace at the end of the config */ if(config!=NULL&&*config!=0) { p = config+strlen(config); while(p>config&&isspace((int)*(--p))) { *p=0; } } /* OK, we're good. */ { UErrorCode subStatus = U_ZERO_ERROR; UPlugData *plug = uplug_initPlugFromLibrary(libName, symName, config, &subStatus); if(U_FAILURE(subStatus) && U_SUCCESS(*status)) { *status = subStatus; } #if UPLUG_TRACE DBG((stderr, "PLUGIN libName=[%s], sym=[%s], config=[%s]\n", libName, symName, config)); DBG((stderr, " -> %p, %s\n", (void*)plug, u_errorName(subStatus))); #else (void)plug; /* unused */ #endif } } } fclose(f); } else { #if UPLUG_TRACE DBG((stderr, "Can't open plugin file %s\n", plugin_file)); #endif } } uplug_loadWaitingPlugs(status); #endif /* U_ENABLE_DYLOAD */ ucln_registerCleanup(UCLN_UPLUG, uplug_cleanup); }
/* NOTE: The caller should handle thread safety */ U_CAPI const char* U_EXPORT2 uprv_getDefaultLocaleID() { #if U_POSIX_LOCALE /* Note that: (a '!' means the ID is improper somehow) LC_ALL ----> default_loc codepage -------------------------------------------------------- ab.CD ab CD ab@CD ab__CD - [email protected] ab__CD EF ab_CD.EF@GH ab_CD_GH EF Some 'improper' ways to do the same as above: ! [email protected] ab_CD_GH EF ! [email protected] ab_CD_GH EF ! [email protected]@GH.IJ ab_CD_GH EF _CD@GH _CD_GH - _CD.EF@GH _CD_GH EF The variant cannot have dots in it. The 'rightmost' variant (@xxx) wins. The leftmost codepage (.xxx) wins. */ char *correctedPOSIXLocale = 0; const char* posixID = uprv_getPOSIXID(); const char *p; const char *q; int32_t len; /* Format: (no spaces) ll [ _CC ] [ . MM ] [ @ VV] l = lang, C = ctry, M = charmap, V = variant */ if (gCorrectedPOSIXLocale != NULL) { return gCorrectedPOSIXLocale; } if ((p = uprv_strchr(posixID, '.')) != NULL) { /* assume new locale can't be larger than old one? */ correctedPOSIXLocale = (char*) uprv_malloc(uprv_strlen(posixID)+1); uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID); correctedPOSIXLocale[p-posixID] = 0; /* do not copy after the @ */ if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) { correctedPOSIXLocale[p-correctedPOSIXLocale] = 0; } } /* Note that we scan the *uncorrected* ID. */ if ((p = uprv_strrchr(posixID, '@')) != NULL) { if (correctedPOSIXLocale == NULL) { correctedPOSIXLocale = (char*) uprv_malloc(uprv_strlen(posixID)+1); uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID); correctedPOSIXLocale[p-posixID] = 0; } p++; /* Take care of any special cases here.. */ if (!uprv_strcmp(p, "nynorsk")) { p = "NY"; /* Don't worry about no__NY. In practice, it won't appear. */ } if (uprv_strchr(correctedPOSIXLocale,'_') == NULL) { uprv_strcat(correctedPOSIXLocale, "__"); /* aa@b -> aa__b */ } else { uprv_strcat(correctedPOSIXLocale, "_"); /* aa_CC@b -> aa_CC_b */ } if ((q = uprv_strchr(p, '.')) != NULL) { /* How big will the resulting string be? */ len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p)); uprv_strncat(correctedPOSIXLocale, p, q-p); correctedPOSIXLocale[len] = 0; } else { /* Anything following the @ sign */ uprv_strcat(correctedPOSIXLocale, p); } /* Should there be a map from 'no@nynorsk' -> no_NO_NY here? * How about 'russian' -> 'ru'? * Many of the other locales using ISO codes will be handled by the * canonicalization functions in uloc_getDefault. */ } /* Was a correction made? */ if (correctedPOSIXLocale != NULL) { posixID = correctedPOSIXLocale; } else { /* copy it, just in case the original pointer goes away. See j2395 */ correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1); posixID = uprv_strcpy(correctedPOSIXLocale, posixID); } if (gCorrectedPOSIXLocale == NULL) { gCorrectedPOSIXLocale = correctedPOSIXLocale; ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup); correctedPOSIXLocale = NULL; } if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */ uprv_free(correctedPOSIXLocale); } return posixID; #elif defined(U_WINDOWS) UErrorCode status = U_ZERO_ERROR; LCID id = GetThreadLocale(); const char* locID = uprv_convertToPosix(id, &status); if (U_FAILURE(status)) { locID = "en_US"; } return locID; #elif defined(XP_MAC) int32_t script = MAC_LC_INIT_NUMBER; /* = IntlScript(); or GetScriptManagerVariable(smSysScript);*/ int32_t region = MAC_LC_INIT_NUMBER; /* = GetScriptManagerVariable(smRegionCode);*/ int32_t lang = MAC_LC_INIT_NUMBER; /* = GetScriptManagerVariable(smScriptLang);*/ int32_t date_region = MAC_LC_INIT_NUMBER; const char* posixID = 0; int32_t count = sizeof(mac_lc_recs) / sizeof(mac_lc_rec); int32_t i; Intl1Hndl ih; ih = (Intl1Hndl) GetIntlResource(1); if (ih) date_region = ((uint16_t)(*ih)->intl1Vers) >> 8; for (i = 0; i < count; i++) { if ( ((mac_lc_recs[i].script == MAC_LC_MAGIC_NUMBER) || (mac_lc_recs[i].script == script)) && ((mac_lc_recs[i].region == MAC_LC_MAGIC_NUMBER) || (mac_lc_recs[i].region == region)) && ((mac_lc_recs[i].lang == MAC_LC_MAGIC_NUMBER) || (mac_lc_recs[i].lang == lang)) && ((mac_lc_recs[i].date_region == MAC_LC_MAGIC_NUMBER) || (mac_lc_recs[i].date_region == date_region)) ) { posixID = mac_lc_recs[i].posixID; break; } } return posixID; #elif defined(OS400) /* locales are process scoped and are by definition thread safe */ static char correctedLocale[64]; const char *localeID = getenv("LC_ALL"); char *p; if (localeID == NULL) localeID = getenv("LANG"); if (localeID == NULL) localeID = setlocale(LC_ALL, NULL); /* Make sure we have something... */ if (localeID == NULL) return "en_US_POSIX"; /* Extract the locale name from the path. */ if((p = uprv_strrchr(localeID, '/')) != NULL) { /* Increment p to start of locale name. */ p++; localeID = p; } /* Copy to work location. */ uprv_strcpy(correctedLocale, localeID); /* Strip off the '.locale' extension. */ if((p = uprv_strchr(correctedLocale, '.')) != NULL) { *p = 0; } /* Upper case the locale name. */ T_CString_toUpperCase(correctedLocale); /* See if we are using the POSIX locale. Any of the * following are equivalent and use the same QLGPGCMA * (POSIX) locale. * QLGPGCMA2 means UCS2 * QLGPGCMA_4 means UTF-32 * QLGPGCMA_8 means UTF-8 */ if ((uprv_strcmp("C", correctedLocale) == 0) || (uprv_strcmp("POSIX", correctedLocale) == 0) || (uprv_strncmp("QLGPGCMA", correctedLocale, 8) == 0)) { uprv_strcpy(correctedLocale, "en_US_POSIX"); } else { int16_t LocaleLen; /* Lower case the lang portion. */ for(p = correctedLocale; *p != 0 && *p != '_'; p++) { *p = uprv_tolower(*p); } /* Adjust for Euro. After '_E' add 'URO'. */ LocaleLen = uprv_strlen(correctedLocale); if (correctedLocale[LocaleLen - 2] == '_' && correctedLocale[LocaleLen - 1] == 'E') { uprv_strcat(correctedLocale, "URO"); } /* If using Lotus-based locale then convert to * equivalent non Lotus. */ else if (correctedLocale[LocaleLen - 2] == '_' && correctedLocale[LocaleLen - 1] == 'L') { correctedLocale[LocaleLen - 2] = 0; } /* There are separate simplified and traditional * locales called zh_HK_S and zh_HK_T. */ else if (uprv_strncmp(correctedLocale, "zh_HK", 5) == 0) { uprv_strcpy(correctedLocale, "zh_HK"); } /* A special zh_CN_GBK locale... */ else if (uprv_strcmp(correctedLocale, "zh_CN_GBK") == 0) { uprv_strcpy(correctedLocale, "zh_CN"); } } return correctedLocale; #endif }