void DtMail::Session::DtXlateMimeToIconv( const char *mimeId, const char *defaultCommonCS, const char *defaultIconvCS, char **ret_commonCS, char **ret_platformIconv) { int exists = -1; this->OpenLcxDb(); exists = _DtLcxXlateOpToStd( MyDb, MyPlatform, CompVer, DtLCX_OPER_MIME, mimeId, NULL, NULL, ret_commonCS, NULL); if (exists == -1) { exists = _DtLcxXlateOpToStd( MyDb, "CDE", 0, DtLCX_OPER_MIME, mimeId, NULL, NULL, ret_commonCS, NULL); if (exists == -1) *ret_commonCS = (char *)strdup(defaultCommonCS); } exists = _DtLcxXlateStdToOp( MyDb, MyPlatform, CompVer, DtLCX_OPER_ICONV3, NULL, NULL, *ret_commonCS, NULL, ret_platformIconv); if (exists == -1) *ret_platformIconv = (char *)strdup(defaultIconvCS); }
// Return iconv name of the given codeset. // If iconv name does not exist, return NULL. char * DtMail::Session::csToConvName(char *cs) { int exists = -1; char *commonCS = NULL; char *convName = NULL; char *ret_target = NULL; this->OpenLcxDb(); // Convert charset to upper case first because charset table is // case sensitive. if (cs) { int len_cs = strlen(cs); for ( int num_cs = 0; num_cs < len_cs; num_cs++ ) *(cs+num_cs) = toupper(*(cs+num_cs)); } exists = _DtLcxXlateOpToStd( MyDb, MyPlatform, CompVer, DtLCX_OPER_MIME, cs, NULL, NULL, &commonCS, NULL); if (exists == -1) { exists = _DtLcxXlateOpToStd( MyDb, "CDE", 0, DtLCX_OPER_MIME, cs, NULL, NULL, &commonCS, NULL); if (exists == -1) return NULL; } DtXlateStdToOpCodeset(DtLCX_OPER_INTERCHANGE_CODESET, commonCS, NULL, &ret_target); DtXlateStdToOpCodeset(DtLCX_OPER_ICONV3, ret_target, NULL, &convName); if ( ret_target ) free( ret_target ); if ( commonCS ) free( commonCS ); // Workaround for libDtHelp // Case of no iconv name for a particular locale, eg. C, // check for empty string. if ( convName != NULL ) { if ( strlen(convName) > 0 ) return convName; else free( convName ); } return NULL; }
/****************************************************************************** * Function: int DtXlateOpToStdLocale(char *operation, char *opLocale, * char **ret_stdLocale, * char **ret_stdLang, * char **ret_stdSet) * * Parameters: * operation Operation associated with the locale value * opLocale An operation-specific locale string * ret_locale Returns the std locale * Caller must free this string. * ret_stdLang Returns the std language & territory string. * Caller must free this string. * ret_stdSet Returns the std code set string. * Caller must free this string. * * Return Value: * * Purpose: Gets the standard locale given an operation and its locale * *****************************************************************************/ void DtMail::Session::DtXlateOpToStdLocale ( char *operation, char *opLocale, char **ret_stdLocale, char **ret_stdLang, char **ret_stdSet) { int result = OpenLcxDb(); if (result == 0) { (void) _DtLcxXlateOpToStd( MyDb, MyPlatform, CompVer, operation, opLocale, ret_stdLocale, ret_stdLang, ret_stdSet, NULL); } /* if failed, give default values */ if (ret_stdLocale != NULL && (result != 0 || *ret_stdLocale == NULL)) { *ret_stdLocale = (char *)malloc(strlen(DfltStdLang)+strlen(DfltStdCharset)+3); sprintf(*ret_stdLocale,"%s.%s",DfltStdLang,DfltStdCharset); } if (ret_stdLang != NULL && (result != 0 || *ret_stdLang == NULL)) *ret_stdLang = (char *)strdup(DfltStdLang); if (ret_stdSet != NULL && (result != 0 || *ret_stdSet == NULL)) *ret_stdSet = (char *)strdup(DfltStdCharset); }
int find_CDE_locale_name() { UserEnv *uenv = &userEnv; _DtXlateDb db = NULL; int ret = NoError; char plat[_DtPLATFORM_MAX_LEN]; int execver; int compver; static bool first = True; if (first) { uenv->CDE_locale = NULL; ret = _DtLcxOpenAllDbs(&db); if (ret == NoError) ret = _DtXlateGetXlateEnv(db, plat, &execver, &compver); if (ret == NoError) ret = _DtLcxXlateOpToStd(db, plat, compver, DtLCX_OPER_SETLOCALE, uenv->locale, &uenv->CDE_locale, NULL, NULL, NULL); if (ret == NoError) ret = _DtLcxCloseDb(&db); first = False; } return ret; }
void DtMail::Session::DtXlateLocaleToMime( const char * locale, const char * defaultCommonCS, const char * defaultMimeCS, char ** ret_mimeCS) { char * commonCS = NULL; this->OpenLcxDb(); /* look for platform-specific locale to CDE translation */ _DtLcxXlateOpToStd( MyDb, MyPlatform, CompVer, DtLCX_OPER_SETLOCALE, locale, NULL, NULL, &commonCS, NULL); if (!commonCS) commonCS = (char *)strdup(defaultCommonCS); /* look for platform-specific MIME types; by default, there is none */ _DtLcxXlateStdToOp( MyDb, MyPlatform, CompVer, DtLCX_OPER_MIME, NULL, NULL, commonCS, NULL, ret_mimeCS); if (!(*ret_mimeCS)) { _DtLcxXlateStdToOp( MyDb, "CDE", 0, DtLCX_OPER_MIME, NULL, NULL, commonCS, NULL, ret_mimeCS); if (!(*ret_mimeCS)) *ret_mimeCS = (char *)strdup(defaultMimeCS); } if (commonCS) free(commonCS); }
Boolean info_lib::define_info_base( char* base_name, char* base_desc, char* spec_file_path ) { //MESSAGE(cerr, "define_info_base()"); //debug(cerr, base_name); //debug(cerr, base_desc); //debug(cerr, spec_file_path); char new_db_path[PATHSIZ]; char f_name[PATHSIZ]; char base_uid[UIDSIZ]; strcpy(new_db_path, form("%s/%s", info_lib_path, base_name)); strcpy(base_uid, unique_id()); g_mode_8_3 = 1; info_base* base = get_info_base(base_name) ; /* no checking here. DDK assures unique base name case if ( base == 0 ) { */ ////////////////////////// // check info base path ////////////////////////// if ( check_and_create_dir(new_db_path) == false ) { throw(stringException(form("bad base bath %s", new_db_path))); } ////////////////////////// // remove any old files ////////////////////////// strcpy(f_name, form("%s.%s", base_name, DATA_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); strcpy(f_name, form("%s.%s", base_name, INDEX_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); strcpy(f_name, form("%s.%s", base_name, SCHEMA_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); f_obj_dict -> init_a_base(spec_file_path, new_db_path, base_name); const char* lang; if ((lang = getenv("LC_ALL")) == NULL) if ((lang = getenv("LC_CTYPE")) == NULL) if ((lang = getenv("LANG")) == NULL) lang = "C"; #ifdef DtinfoClient _DtXlateDb db = NULL; char* std_locale = NULL; if (_DtLcxOpenAllDbs(&db) == 0) { char platform[_DtPLATFORM_MAX_LEN + 1]; int execver, compver; if (_DtXlateGetXlateEnv(db, platform, &execver, &compver) == 0) { _DtLcxXlateOpToStd(db, platform, compver, DtLCX_OPER_SETLOCALE, lang, &std_locale, NULL, NULL, NULL); } _DtLcxCloseDb(&db); db = NULL; } #endif base = new info_base(*f_obj_dict, set_nm_list, list_nm_list, new_db_path, base_name, base_desc, base_uid, #ifdef DtinfoClient std_locale ? std_locale : lang, #else lang, #endif mm_version(MAJOR, MINOR) ); info_base_list.insert_as_tail(new dlist_void_ptr_cell(base)); /*************************************/ // add the base name and description // to the names file /*************************************/ char* lib_nm = form("%s/%s", info_lib_path, MAP_FILE_8_3); fstream nm_out(lib_nm, ios::app, open_file_prot()); if ( !nm_out ) { MESSAGE(cerr, form("can't open %s/%s for append", info_lib_path, MAP_FILE_8_3) ); throw(streamException(nm_out.rdstate())); } if ( bytes(nm_out) == 0 ) { char* lib_entry = form("%s\t%s\n", info_lib_name, unique_id()); if ( !(nm_out << lib_entry) ) { MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } } char* base_entry = form("%s\t%s\t%s\t%s\t%d\t%d\n", base_name, base_desc, base_uid, #ifdef DtinfoClient std_locale ? std_locale: lang, #else lang, #endif MAJOR, MINOR ); #ifdef DtinfoClient if (std_locale) free(std_locale); #endif if ( !(nm_out << base_entry) ) { MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } nm_out.close(); if ( nm_out.fail() ) { MESSAGE(cerr, form("close %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } //} //MESSAGE(cerr, "define() done"); return true; }