int hbb::extractSmdhData(smdh_s* s, char* name, char* desc, char* auth, u8* iconData) { if(!s)return -1; if(s->header.magic!=0x48444D53)return -2; if(name)unicodeToChar(name, s->applicationTitles[1].shortDescription, 0x40); if(desc)unicodeToChar(desc, s->applicationTitles[1].longDescription, 0x80); if(auth)unicodeToChar(auth, s->applicationTitles[1].publisher, 0x40); if(iconData) { u16* data=s->bigIconData; //convert RGB565 to RGB24 int i, j, k; for(j=0; j<48; j+=8) { for(i=0; i<48; i+=8) { //parse tiling... for(k=0; k<8*8; k++) { u8 x=tileOrder[k]&0x7; u8 y=tileOrder[k]>>3; putPixel565(iconData, i+x, j+y, *data++); } } } } return 0; }
void scanHomebrewDirectory(menu_s* m, char* path) { if(!path)return; Handle dirHandle; FS_path dirPath=FS_makePath(PATH_CHAR, path); FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath); static char fullPath[1024]; u32 entriesRead; do { static FS_dirent entry; memset(&entry,0,sizeof(FS_dirent)); entriesRead=0; FSDIR_Read(dirHandle, &entriesRead, 1, &entry); if(entriesRead) { strncpy(fullPath, path, 1024); int n=strlen(fullPath); unicodeToChar(&fullPath[n], entry.name, 1024-n); if(entry.isDirectory) //directories { addDirectoryToMenu(m, fullPath); }else{ //stray executables n=strlen(fullPath); if(n>5 && !strcmp(".3dsx", &fullPath[n-5]))addFileToMenu(m, fullPath); } } }while(entriesRead); FSDIR_Close(dirHandle); }
void scanHomebrewDirectory(menu_s* m, char* path) { if(!path)return; Handle dirHandle; FS_path dirPath=FS_makePath(PATH_CHAR, path); FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); static char fullPath[1024][1024]; u32 entriesRead; int totalentries = 0; do { static FS_dirent entry; memset(&entry,0,sizeof(FS_dirent)); entriesRead=0; FSDIR_Read(dirHandle, &entriesRead, 1, &entry); if(entriesRead) { strncpy(fullPath[totalentries], path, 1024); int n=strlen(fullPath[totalentries]); unicodeToChar(&fullPath[totalentries][n], entry.name, 1024-n); if(entry.isDirectory) //directories { //addDirectoryToMenu(m, fullPath[totalentries]); totalentries++; }else{ //stray executables n=strlen(fullPath[totalentries]); if(n>5 && !strcmp(".3dsx", &fullPath[totalentries][n-5])){ //addFileToMenu(m, fullPath[totalentries]); totalentries++; } if(n>4 && !strcmp(".xml", &fullPath[totalentries][n-4])) { //addFileToMenu(m, fullPath[totalentries]); totalentries++; } } } }while(entriesRead); FSDIR_Close(dirHandle); bool sortAlpha = getConfigBoolForKey("sortAlpha", false, configTypeMain); addMenuEntries(fullPath, totalentries, strlen(path), m, sortAlpha); updateMenuIconPositions(m); }
void dumpFolder(char *path, u32 lowpath_id, char *dumpfolder, u8 *filebuffer, size_t bufsize) { Handle extdata_dir; Result ret = FSUSER_OpenDirectory(NULL, &extdata_dir, extdata_archive, FS_makePath(PATH_CHAR, path)); if (ret!=0) { printf("could not open dir\n"); gfxFlushBuffers(); gfxSwapBuffers(); return; } char dirname[0x120]; sprintf(dirname, "%s/%08x%s", dumpfolder, (unsigned int) lowpath_id, path); mkdir(dirname, 0777); FS_dirent dirStruct; char fileName[0x106] = ""; int cont = 0; while(1) { u32 dataRead = 0; FSDIR_Read(extdata_dir, &dataRead, 1, &dirStruct); if(dataRead == 0) break; unicodeToChar(fileName, dirStruct.name); printf("name: %s%s%s\n", path, fileName, dirStruct.isDirectory ? " (DIRECTORY)" : ""); gfxFlushBuffers(); gfxSwapBuffers(); cont++; if (dirStruct.isDirectory) { char newpath[0x120]; sprintf(newpath, "%s%s/", path, fileName); dumpFolder(newpath, lowpath_id, dumpfolder, filebuffer, bufsize); } else { char file_inpath[0x120]; char file_outpath[0x120]; char file_display_path[0x120]; sprintf(file_inpath, "%s%s", path, fileName); sprintf(file_outpath, "%s/%08x%s%s", dumpfolder, (unsigned int) lowpath_id, path, fileName); sprintf(file_display_path, "%08x%s%s", (unsigned int) lowpath_id, path, fileName); archive_copyfile(Extdata_Archive, SDArchive, file_inpath, file_outpath, filebuffer, 0, bufsize, file_display_path); } } printf("total files in 0x%08x%s: %d\n", (unsigned int) lowpath_id, path, (unsigned int) cont); gfxFlushBuffers(); gfxSwapBuffers(); FSDIR_Close(extdata_dir); }
// ----------------------------------------------------------------------- // Translate ANSI SQL names from UCS-2/UTF-16 encoding values to // the Default ANSI SQL Name character set. // ----------------------------------------------------------------------- void CmAnsiNameToUTF8(const NAWString &inWcs, NAString &outMbs) { outMbs.remove(0); // set to an empty string if (inWcs.length() <= 0) { return; } NAString *pConvStr = unicodeToChar ( inWcs.data() // in - const char * str , (Int32)inWcs.length() // in - Int32 len , (Lng32)ComGetNameInterfaceCharSet() // in - Lng32 strCharSet , (NAMemory *)STMTHEAP // in - NAMemory * h , FALSE // in - NABoolean allowInvalidChar ); if (pConvStr != NULL AND pConvStr->length() > 0) { outMbs = *pConvStr; } delete pConvStr; }
directoryContents * contentsOfDirectoryAtPath(char * path, bool dirsOnly) { directoryContents * contents = malloc(sizeof(directoryContents)); int numPaths = 0; Handle dirHandle; FS_path dirPath=FS_makePath(PATH_CHAR, path); FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); u32 entriesRead; do { static FS_dirent entry; memset(&entry,0,sizeof(FS_dirent)); entriesRead=0; FSDIR_Read(dirHandle, &entriesRead, 1, &entry); if(entriesRead) { if(!dirsOnly || (dirsOnly && entry.isDirectory)) { char fullPath[1024]; strncpy(fullPath, path, 1024); int n=strlen(path); unicodeToChar(&fullPath[n], entry.name, 1024-n); strcpy(contents->paths[numPaths], fullPath); numPaths++; } } }while(entriesRead); FSDIR_Close(dirHandle); // qsort(contents->paths, numPaths, 1024, compareStrings); contents->numPaths = numPaths; return contents; }
NAString *charToChar(Lng32 targetCS, const char *s, Int32 sLenInBytes, Lng32 sourceCS, NAMemory *h /* = NULL */, NABoolean allowInvalidChar /* = FALSE */) { NAString *res = NULL; if (s == NULL || sourceCS == (Lng32)CharInfo::UnknownCharSet || targetCS == (Lng32)CharInfo::UnknownCharSet) { return NULL; // error } if (sLenInBytes == 0) { if (h) res = new (h) NAString(h); // empty string else res = new NAString; return res; } if (targetCS == sourceCS) { if (h) res = new (h) NAString(s, sLenInBytes, h); // deep copy else res = new NAString(s, sLenInBytes); // deep copy return res; } // targetCS != sourceCS if ((CharInfo::CharSet)sourceCS == CharInfo::UCS2) { res = unicodeToChar ( (const NAWchar *)s // source string , sLenInBytes / BYTES_PER_NAWCHAR // src len in NAWchars , targetCS , h , allowInvalidChar ); return res; } // sourceCS != CharInfo::UCS2 NAWString * wstr = charToUnicode ( sourceCS // src char set , s // src str , sLenInBytes // src str len in bytes , h // heap for allocated target str ); if (wstr == NULL) // conversion failed { return NULL; // error } if ((CharInfo::CharSet)targetCS == CharInfo::UCS2) { if (h) res = new (h) NAString ( (const char *)wstr->data() // source string , wstr->length() * BYTES_PER_NAWCHAR // source len in bytes , h ); else res = new NAString ( (const char *)wstr->data() // source string , wstr->length() * BYTES_PER_NAWCHAR // source len in bytes ); delete wstr; return res; } // targetCS != CharInfo::UCS2 res = unicodeToChar ( wstr->data() , wstr->length() // in NAWchars , targetCS , h , allowInvalidChar ); delete wstr; return res; }
short Param::convertValue(SqlciEnv * sqlci_env, short targetType, Lng32 &targetLen, Lng32 targetPrecision, Lng32 targetScale, Lng32 vcIndLen, ComDiagsArea* diags) { // get rid of the old converted value if (converted_value) { delete [] converted_value; converted_value = 0; }; short sourceType; Lng32 sourceLen; // set up the source and its length based on the how the value is passed-in. if ( isInSingleByteForm() == FALSE ) { sourceLen = (Lng32)(NAWstrlen((NAWchar*)value) * BYTES_PER_NAWCHAR); switch (getCharSet()) { case CharInfo::UNICODE: sourceType = REC_NCHAR_F_UNICODE; break; case CharInfo::KANJI_MP: case CharInfo::KSC5601_MP: sourceType = REC_BYTE_F_ASCII; // KANJI/KSC passed in as NAWchar* break; default: return SQL_Error; // error case } } else { sourceLen = (Lng32)strlen(value); // for any source in single-byte format sourceType = REC_BYTE_F_ASCII; } char * pParamValue = value; if ( DFS2REC::isAnyCharacter(targetType) ) { if (termCS_ == CharInfo::UnknownCharSet) termCS_ = sqlci_env->getTerminalCharset(); if (cs == CharInfo::UnknownCharSet) { isQuotedStrWithoutCharSetPrefix_ = TRUE; cs = termCS_; } // If the target is CHARACTER and param is set as [_cs_prefix]'...', then // make sure the source is assignment compatible with the target. CharInfo::CharSet targetCharSet = (CharInfo::CharSet)targetScale; if ( targetCharSet == CharInfo::UNICODE ) { if (getUTF16StrLit() == (NAWchar*)NULL) { utf16StrLit_ = new NAWchar [ sourceLen * 2 + 1 ]; // plenty of room Lng32 utf16StrLenInNAWchars = LocaleStringToUnicode(cs/*sourceCS*/, /*sourceStr*/value, sourceLen, utf16StrLit_/*outputBuf*/, sourceLen+1/*outputBufSizeInNAWchars*/, TRUE /* in - NABoolean addNullAtEnd*/); if (sourceLen > 0 && utf16StrLenInNAWchars == 0) return SQL_Error; // ComASSERT(utf16StrLenInNAWchars == NAWstrlen(getUTF16StrLit())); // Resize the NAWchar buffer to save space NAWchar *pNAWcharBuf = new NAWchar [ utf16StrLenInNAWchars + 1 ]; NAWstrncpy (pNAWcharBuf, utf16StrLit_, utf16StrLenInNAWchars + 1); pNAWcharBuf[utf16StrLenInNAWchars] = NAWCHR('\0'); // play it safe delete [] utf16StrLit_; utf16StrLit_ = pNAWcharBuf; // do not deallocate pNAWcharBuf } sourceLen = (Lng32)(NAWstrlen(getUTF16StrLit()) * BYTES_PER_NAWCHAR); // check to see if the parameter utf16 string fits in the target if ( sourceLen > targetLen ) return SQL_Error; pParamValue = (char *)getUTF16StrLit(); sourceType = REC_NCHAR_F_UNICODE; } } else { // MP NCHAR (KANJI/KSC) can not be converted to non-character objects if ( CharInfo::is_NCHAR_MP(cs) ) return SQL_Error; } switch(targetType) { case REC_BIN16_SIGNED: case REC_BIN16_UNSIGNED: case REC_BPINT_UNSIGNED: case REC_BIN32_SIGNED: case REC_BIN32_UNSIGNED: case REC_BIN64_SIGNED: case REC_DECIMAL_UNSIGNED: case REC_DECIMAL_LSE: case REC_FLOAT32: case REC_FLOAT64: case REC_TDM_FLOAT32: case REC_TDM_FLOAT64: case REC_BYTE_F_ASCII: case REC_BYTE_V_ASCII: case REC_BYTE_V_ASCII_LONG: case REC_NCHAR_F_UNICODE: case REC_NCHAR_V_UNICODE: { char *VCLen = NULL; short VCLenSize = 0; // 5/27/98: added VARNCHAR cases if ((targetType == REC_BYTE_V_ASCII) || (targetType == REC_BYTE_V_ASCII_LONG) || (targetType == REC_NCHAR_V_UNICODE)) { // add bytes for variable length field VCLenSize = vcIndLen; //sizeof(short); VCLen = converted_value = new char[targetLen + VCLenSize]; } else converted_value = new char[targetLen]; #pragma nowarn(1506) // warning elimination ex_expr::exp_return_type ok; CharInfo::CharSet TCS = sqlci_env->getTerminalCharset(); CharInfo::CharSet ISOMAPCS = sqlci_env->getIsoMappingCharset(); NAString* tempstr; if ( DFS2REC::isAnyCharacter(sourceType) && DFS2REC::isAnyCharacter(targetType) && !(getUTF16StrLit() != NULL && sourceType == REC_NCHAR_F_UNICODE && targetScale == CharInfo::UCS2) && /*source*/cs != targetScale/*i.e., targetCharSet*/ ) { charBuf cbuf((unsigned char*)pParamValue, sourceLen); NAWcharBuf* wcbuf = 0; Int32 errorcode = 0; wcbuf = csetToUnicode(cbuf, 0, wcbuf, cs/*sourceCharSet*/ , errorcode); if (errorcode != 0) return SQL_Error; tempstr = unicodeToChar(wcbuf->data(),wcbuf->getStrLen(), targetScale/*i.e., targetCharSet*/ ); if (tempstr == NULL) return SQL_Error; //Avoid NULL ptr reference if conversion error sourceType = targetType; // we just converted it to the target type sourceLen = tempstr->length(); pParamValue = (char *)tempstr->data(); if ( sourceLen > targetLen ) return SQL_Error; } ok = convDoIt(pParamValue, sourceLen, sourceType, 0, // source Precision targetScale, // new charset we converted to &converted_value[VCLenSize], targetLen, targetType, targetPrecision, targetScale, VCLen, VCLenSize, 0, &diags); if ( ok != ex_expr::EXPR_OK) { // No need to delete allocated memory before return because class member // converted_value still points to allocated memory that is deleted in // desctructor. return SQL_Error; // error case } #pragma warn(1506) // warning elimination }; break; case REC_DATETIME: { char *VCLen = NULL; short VCLenSize = 0; converted_value = new char[targetLen + 1]; #pragma nowarn(1506) // warning elimination ex_expr::exp_return_type ok = convDoIt(value, sourceLen, sourceType, 0, // source Precision 0, // source Scale converted_value, targetLen, targetType, targetPrecision, targetScale, VCLen, VCLenSize, 0, &diags); if ( ok != ex_expr::EXPR_OK) { return SQL_Error; // error case } #pragma warn(1506) // warning elimination }; break; case REC_INT_YEAR: case REC_INT_MONTH: case REC_INT_YEAR_MONTH: case REC_INT_DAY: case REC_INT_HOUR: case REC_INT_DAY_HOUR: case REC_INT_MINUTE: case REC_INT_HOUR_MINUTE: case REC_INT_DAY_MINUTE: case REC_INT_SECOND: case REC_INT_MINUTE_SECOND: case REC_INT_HOUR_SECOND: case REC_INT_DAY_SECOND: { // convert target back to string. converted_value = new char[targetLen]; Lng32 convFlags = CONV_ALLOW_SIGN_IN_INTERVAL; #pragma nowarn(1506) // warning elimination short ok = convDoItMxcs(value, sourceLen, sourceType, 0, // source Precision 0, // source Scale converted_value, targetLen, targetType, targetPrecision, targetScale, convFlags); if ( ok != 0 ) { // No need to delete allocated memory before return because class member // converted_value still points to allocated memory that is deleted in // desctructor. return SQL_Error; // error case } #pragma warn(1506) // warning elimination }; break; case REC_NUM_BIG_UNSIGNED: case REC_NUM_BIG_SIGNED: { converted_value = new char[targetLen]; #pragma nowarn(1506) // warning elimination short ok = convDoItMxcs(value, sourceLen, sourceType, 0, // source Precision 0, // source Scale converted_value, targetLen, targetType, targetPrecision, targetScale, 0); if ( ok != 0 ) { // No need to delete allocated memory before return because class member // converted_value still points to allocated memory that is deleted in // desctructor. return SQL_Error; // error case } #pragma warn(1506) // warning elimination }; break; default: break; }; return 0; }
short Env::process(SqlciEnv *sqlci_env) { // ## Should any of this text come from the message file, // ## i.e. from a translatable file for I18N? // When adding new variables, please keep the information in // alphabetic order Logfile *log = sqlci_env->get_logfile(); log->WriteAll("----------------------------------"); log->WriteAll("Current Environment"); log->WriteAll("----------------------------------"); bool authenticationEnabled = false; bool authorizationEnabled = false; bool authorizationReady = false; bool auditingEnabled = false; Int32 rc = sqlci_env->getAuthState(authenticationEnabled, authorizationEnabled, authorizationReady, auditingEnabled); // TDB: add auditing state log->WriteAllWithoutEOL("AUTHENTICATION "); if (authenticationEnabled) log->WriteAll("enabled"); else log->WriteAll("disabled"); log->WriteAllWithoutEOL("AUTHORIZATION "); if (authorizationEnabled) log->WriteAll("enabled"); else log->WriteAll("disabled"); log->WriteAllWithoutEOL("CURRENT DIRECTORY "); // NT_PORT (bv 10/24/96) Added NA_MAX_PATH here and in common/Platform.h log->WriteAll(getcwd((char *)NULL, NA_MAX_PATH)); log->WriteAllWithoutEOL("LIST_COUNT "); char buf[100]; Int32 len = sprintf(buf, "%u", sqlci_env->getListCount()); if (len-- > 0) if (buf[len] == 'L' || buf[len] == 'l') buf[len] = '\0'; log->WriteAll(buf); if (log->IsOpen()) { log->WriteAllWithoutEOL("LOG FILE "); log->WriteAll(log->Logname()); } else { log->WriteAll("LOG FILE"); } log->WriteAllWithoutEOL("MESSAGEFILE "); const char *mf = GetErrorMessageFileName(); log->WriteAll(mf ? mf : ""); #if 0 log->WriteAllWithoutEOL("ISO88591 MAPPING "); log->WriteAll(CharInfo::getCharSetName(sqlci_env->getIsoMappingCharset())); log->WriteAllWithoutEOL("DEFAULT CHARSET "); log->WriteAll(CharInfo::getCharSetName(sqlci_env->getDefaultCharset())); log->WriteAllWithoutEOL("INFER CHARSET "); log->WriteAll((sqlci_env->getInferCharset())?"ON":"OFF"); #endif // ## These need to have real values detected from the env and written out: // "US English" is more "politically correct" than "American English". // log->WriteAllWithoutEOL("MESSAGEFILE LANG US English\n"); log->WriteAllWithoutEOL("MESSAGEFILE VRSN "); char vmsgcode[10]; sprintf(vmsgcode, "%d", SQLERRORS_MSGFILE_VERSION_INFO); #pragma nowarn(1506) // warning elimination Error vmsg(vmsgcode, strlen(vmsgcode), Error::ENVCMD_); #pragma warn(1506) // warning elimination vmsg.process(sqlci_env); ComAnsiNamePart defaultCat; ComAnsiNamePart defaultSch; sqlci_env->getDefaultCatAndSch (defaultCat, defaultSch); CharInfo::CharSet TCS = sqlci_env->getTerminalCharset(); CharInfo::CharSet ISOMAPCS = sqlci_env->getIsoMappingCharset(); if(TCS != CharInfo::UTF8 ) { NAString dCat = defaultCat.getExternalName(); NAString dSch = defaultSch.getExternalName(); charBuf cbufCat((unsigned char*)dCat.data(), dCat.length()); charBuf cbufSch((unsigned char*)dSch.data(), dSch.length()); NAWcharBuf* wcbuf = 0; Int32 errorcode = 0; wcbuf = csetToUnicode(cbufCat, 0, wcbuf, CharInfo::UTF8, errorcode); NAString* tempstr; if (errorcode != 0){ tempstr = new NAString(defaultCat.getExternalName().data()); } else { tempstr = unicodeToChar(wcbuf->data(),wcbuf->getStrLen(), TCS, NULL, TRUE); TrimNAStringSpace(*tempstr, FALSE, TRUE); // trim trailing blanks } log->WriteAllWithoutEOL("SQL CATALOG "); log->WriteAll(tempstr->data()); // Default Schema wcbuf = 0; // must 0 out to get next call to allocate memory. wcbuf = csetToUnicode(cbufSch, 0, wcbuf, CharInfo::UTF8, errorcode); if (errorcode != 0){ tempstr = new NAString(defaultSch.getExternalName().data()); } else { tempstr = unicodeToChar(wcbuf->data(),wcbuf->getStrLen(), TCS, NULL, TRUE); TrimNAStringSpace(*tempstr, FALSE, TRUE); // trim trailing blanks } log->WriteAllWithoutEOL("SQL SCHEMA "); log->WriteAll(tempstr->data()); } else { log->WriteAllWithoutEOL("SQL CATALOG "); log->WriteAll(defaultCat.getExternalName()); log->WriteAllWithoutEOL("SQL SCHEMA "); log->WriteAll(defaultSch.getExternalName()); } // On Linux we include the database user name and user ID in the // command output NAString username; rc = sqlci_env->getExternalUserName(username); log->WriteAllWithoutEOL("SQL USER CONNECTED "); if (rc >= 0) log->WriteAll(username.data()); else log->WriteAll("?"); rc = sqlci_env->getDatabaseUserName(username); log->WriteAllWithoutEOL("SQL USER DB NAME "); if (rc >= 0) log->WriteAll(username.data()); else log->WriteAll("?"); Int32 uid = 0; rc = sqlci_env->getDatabaseUserID(uid); log->WriteAllWithoutEOL("SQL USER ID "); if (rc >= 0) sprintf(buf, "%d", (int) uid); else strcpy(buf, "?"); log->WriteAll(buf); log->WriteAllWithoutEOL("TERMINAL CHARSET "); log->WriteAll(CharInfo::getCharSetName(sqlci_env->getTerminalCharset())); Int64 transid; if (sqlci_env->statusTransaction(&transid)) { // transaction is active. char transid_str[20]; convertInt64ToAscii(transid, transid_str); log->WriteAllWithoutEOL("TRANSACTION ID "); log->WriteAll(transid_str); log->WriteAll("TRANSACTION STATE in progress"); } else { log->WriteAll("TRANSACTION ID "); log->WriteAll("TRANSACTION STATE not in progress"); } if (log->isVerbose()) log->WriteAll("WARNINGS on"); else log->WriteAll("WARNINGS off"); return 0; }