const Symbol* SymbolTable::operator[](const std::string& name) { const auto& entry = fSymbols.find(name); if (entry == fSymbols.end()) { if (fParent) { return (*fParent)[name]; } return nullptr; } if (fParent) { auto functions = GetFunctions(*entry->second); if (functions.size() > 0) { bool modified = false; const Symbol* previous = (*fParent)[name]; if (previous) { auto previousFunctions = GetFunctions(*previous); for (const FunctionDeclaration* prev : previousFunctions) { bool found = false; for (const FunctionDeclaration* current : functions) { if (current->matches(*prev)) { found = true; break; } } if (!found) { functions.push_back(prev); modified = true; } } if (modified) { ASSERT(functions.size() > 1); return this->takeOwnership(new UnresolvedFunction(functions)); } } } } return entry->second; }
/*************************************************************************************** Main (the main function) ***************************************************************************************/ int main(int argc, char* argv[]) { /////////////////////////////////////////////////////////////////////////////// // error check the command line parameters /////////////////////////////////////////////////////////////////////////////// if (argc != 2) { printf("~~~Improper Usage~~~\r\n\r\n"); printf("Usage Example: Sample 3.exe \"c:\\1.ape\"\r\n\r\n"); return 0; } /////////////////////////////////////////////////////////////////////////////// // variable declares /////////////////////////////////////////////////////////////////////////////// int nRetVal = 0; // generic holder for return values char * pFilename = argv[1]; // the file to open /////////////////////////////////////////////////////////////////////////////// // load MACDll.dll and get the functions /////////////////////////////////////////////////////////////////////////////// // load the DLL HMODULE hMACDll = LoadLibrary("MACDll.dll"); if (hMACDll == NULL) return -1; // always check the interface version (so we don't crash if something changed) if (VersionCheckInterface(hMACDll) != 0) { FreeLibrary(hMACDll); return -1; } // get the functions MAC_DLL MACDll; if (GetFunctions(hMACDll, &MACDll) != 0) { FreeLibrary(hMACDll); return -1; } /////////////////////////////////////////////////////////////////////////////// // create the APEDecompress object for the file /////////////////////////////////////////////////////////////////////////////// APE_DECOMPRESS_HANDLE hAPEDecompress = MACDll.Create(pFilename, &nRetVal); if (hAPEDecompress == NULL) { printf("Error opening APE file (error code: %d)\r\n", nRetVal); FreeLibrary(hMACDll); return -1; } /////////////////////////////////////////////////////////////////////////////// // calculate a byte-level checksum of the whole file /////////////////////////////////////////////////////////////////////////////// // make a buffer to hold 1024 blocks of audio data int nBlockAlign = MACDll.GetInfo(hAPEDecompress, APE_INFO_BLOCK_ALIGN, 0, 0); unsigned char * pBuffer = new unsigned char [1024 * nBlockAlign]; // loop through the whole file int nTotalBlocks = MACDll.GetInfo(hAPEDecompress, APE_DECOMPRESS_TOTAL_BLOCKS, 0, 0); int nBlocksRetrieved = 1; int nTotalBlocksRetrieved = 0; unsigned int nChecksum = 0; while (nBlocksRetrieved > 0) { // try to decompress 1024 blocks nRetVal = MACDll.GetData(hAPEDecompress, (char *) pBuffer, 1024, &nBlocksRetrieved); if (nRetVal != 0) printf("Decompression error (continuing with checksum, but file is probably corrupt)\r\n"); // calculate the sum (byte-by-byte) for (int z = 0; z < (nBlockAlign * nBlocksRetrieved); z++) { nChecksum += abs(int(pBuffer[z])); } nTotalBlocksRetrieved += nBlocksRetrieved; // output the progress printf("Progress: %.1f%% \r", (float(nTotalBlocksRetrieved) * float(100)) / float(max(nTotalBlocks, 1.0))); } delete [] pBuffer; // output the result printf("Progress: done. \r\n"); printf("Stupid-style Checksum: 0x%X\r\n", nChecksum); /////////////////////////////////////////////////////////////////////////////// // clean-up and quit /////////////////////////////////////////////////////////////////////////////// MACDll.Destroy(hAPEDecompress); FreeLibrary(hMACDll); return 0; }