bool getSavedGamesStack (stackHandler * sH, char * ext) { char * pattern = joinStrings ("*", ext); if (! pattern) return false; variable newName; newName.varType = SVT_NULL; #ifdef _WIN32 WCHAR *w_pattern = ConvertToUTF16(pattern); WIN32_FIND_DATA theData; HANDLE handle = FindFirstFile (w_pattern, & theData); delete w_pattern; if (handle != INVALID_HANDLE_VALUE) { bool keepGoing; do { theData.cFileName[lstrlen (theData.cFileName) - strlen (ext)] = TEXT('\0'); char * fileName = ConvertFromUTF16(theData.cFileName); char * decoded = decodeFilename (fileName); makeTextVar (newName, decoded); delete fileName; delete decoded; if (! addVarToStack (newName, sH -> first)) return false; if (sH -> last == NULL) sH -> last = sH -> first; keepGoing = FindNextFile (handle, & theData); } while (keepGoing); FindClose (handle); } #else DIR * dir = opendir ("."); if (! dir) return false; struct dirent *d = readdir (dir); while (d != NULL) { if (! strcmp(d->d_name + strlen (d->d_name) - strlen (ext), ext)) { d->d_name[strlen (d->d_name) - strlen (ext)] = 0; char * decoded = decodeFilename (d->d_name); makeTextVar (newName, decoded); delete[] decoded; if (! addVarToStack (newName, sH -> first)) return false; if (sH -> last == NULL) sH -> last = sH -> first; } d = readdir (dir); } closedir (dir); #endif delete[] pattern; pattern = NULL; return true; }
nsresult nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest, nsIStreamLoader* aLoader, nsresult aStatus, PRUint32 aStringLen, const PRUint8* aString) { if (NS_FAILED(aStatus)) { return aStatus; } // If we don't have a document, then we need to abort further // evaluation. if (!mDocument) { return NS_ERROR_NOT_AVAILABLE; } // If the load returned an error page, then we need to abort nsCOMPtr<nsIRequest> req; nsresult rv = aLoader->GetRequest(getter_AddRefs(req)); NS_ASSERTION(req, "StreamLoader's request went away prematurely"); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(req); if (httpChannel) { PRBool requestSucceeded; rv = httpChannel->GetRequestSucceeded(&requestSucceeded); if (NS_SUCCEEDED(rv) && !requestSucceeded) { return NS_ERROR_NOT_AVAILABLE; } } nsCOMPtr<nsIChannel> channel = do_QueryInterface(req); NS_GetFinalChannelURI(channel, getter_AddRefs(aRequest->mFinalURI)); if (aStringLen) { // Check the charset attribute to determine script charset. nsAutoString hintCharset; aRequest->mElement->GetScriptCharset(hintCharset); rv = ConvertToUTF16(channel, aString, aStringLen, hintCharset, mDocument, aRequest->mScriptText); NS_ASSERTION(NS_SUCCEEDED(rv), "Could not convert external JavaScript to Unicode!"); NS_ENSURE_SUCCESS(rv, rv); if (!ShouldExecuteScript(mDocument, channel)) { return NS_ERROR_NOT_AVAILABLE; } } // This assertion could fire errorously if we ran out of memory when // inserting the request in the array. However it's an unlikely case // so if you see this assertion it is likely something else that is // wrong, especially if you see it more than once. NS_ASSERTION(mPendingRequests.IndexOf(aRequest) >= 0, "aRequest should be pending!"); // Mark this as loaded aRequest->mLoading = PR_FALSE; return NS_OK; }
//---------------------------------------------------------------------- // //---------------------------------------------------------------------- bool UTF16Encoding::ConvertFromUTF16(const byte_t* pInBuffer, size_t uInByteCount, byte_t* pOutBuffer, size_t uOutBufferByteCount, size_t* pBytesUsed, size_t* pCharsUsed, bool* pUsedDefaultChar) const { *pUsedDefaultChar = false; // 単なるコピーなのでデフォルト文字はありえない return ConvertToUTF16(pInBuffer, uInByteCount, pOutBuffer, uOutBufferByteCount, pBytesUsed, pCharsUsed); }