static int EvalCompound(expressionADT exp) { char op; int lhs, rhs; op = ExpOperator(exp); if (op == '=') { rhs = EvalExp(ExpRHS(exp)); SetIdentifierValue(ExpIdentifier(ExpLHS(exp)), rhs); return (rhs); } lhs = EvalExp(ExpLHS(exp)); rhs = EvalExp(ExpRHS(exp)); switch (op) { case '+': return (lhs + rhs); case '-': return (lhs - rhs); case '*': return (lhs * rhs); case '/': return (lhs / rhs); default: Error("Illegal operator"); } }
PExpVal TExp::Eval( bool& Ok, TStr& MsgStr, const bool& DbgP, TStr& DbgStr, const PExpEnv& ExpEnv){ Ok=true; MsgStr="Ok"; PExpVal ExpVal; TChA DbgChA; if (DbgP){DbgChA+="Debug Expression: ";} try { ExpVal=EvalExp(ExpEnv, DbgP, DbgChA); } catch (PExcept E){ Ok=false; MsgStr=E->GetMsgStr(); } if (!Ok){return TExpVal::GetUndefExpVal();} if (DbgP){ DbgChA+='['; DbgChA+=GetStr(); DbgChA+=" -> "; DbgChA+=ExpVal->GetStr(); DbgChA+="] "; DbgChA+=MsgStr; DbgStr=DbgChA; } return ExpVal; }
/***************************************************************************\ * Idso * * !dso StructName [FieldName] [Address] * * 06/17/96 Created Gerardob \***************************************************************************/ BOOL Idso(DWORD opts, LPSTR pszCmdLine) { BOOL fOneField = FALSE; DWORD dwOptions; DWORD dwValue, dwSize, dwBytesRead, dwOffset, dwOffsetNext, dwFieldsPerRow, dwMoveSize; DWORD dwBuffer [20]; /* Make sure it has an even number of elemnts and at least 4*/ const DWORD *pcdwLimit = dwBuffer + (sizeof(dwBuffer) / sizeof(*dwBuffer)); DWORD *pdwValue; LPSTR pszField, pszAddress; PBYTE pBufferOffset; PSTRUCTURESTABLE pst; PSTRUCTUREOFFSETSTABLE psot; PVOID pAddress = NULL; if (pszCmdLine == NULL) { return FALSE; } /* * NULL terminate first argument and get a pointer to * second one (presumably the field name) */ /* * Get the options, if any */ if (*pszCmdLine == '-') { dwOptions = GetOpts(&pszCmdLine, NULL); } /* * Find the struct table */ pszField = dsoTerminateString(pszCmdLine, &dwSize); pst = dosGetStruct (pszCmdLine, dwSize); if (pst == NULL) { Print("Structure not found: %s\n", pszCmdLine); return TRUE; } /* * Got a table */ psot = pst->psot; /* * If there is another argument, let's assume a field name follows */ if (*pszField != 0) { /* * Find the field */ pszAddress = dsoTerminateString(pszField, &dwSize); psot = dosGetField (psot, pszField, dwSize); /* * If it didn't find the field and an address was provided, game over. * Otherwise, the second parameter might be the address */ if (psot == NULL) { if (*pszAddress != 0) { Print("Field not found: %s. Struct: %s\n", pszField, pst->pszName); return TRUE; } else { pszAddress = pszField; /* * Reset psot since this argument was not a field */ psot = pst->psot; } } else { fOneField = TRUE; } /* * Get the pointer to the struct */ if (*pszAddress != 0) { pAddress = EvalExp(pszAddress); if (pAddress == NULL) { /* * EvalExp displayed the error message, so return silently */ return TRUE; } } } /* if (*pszField != 0) */ /* * If a field name was specified, dump that field only * Otherwise, dump the whole table. */ if (fOneField) { /* * If no address available, just display the field name and offset */ dwOffset = dsoGetOffset(psot); Print ("Structure %s - Size: %#lx\n", pst->pszName, pst->dwSize); Print("Field: %s - Offset: %#lx\n", psot->pszField, dwOffset); if (pAddress == NULL) { return TRUE; } /* * Printing field value */ /*123456789 1*/ Print("Address Value\n"); dwBytesRead = 0; dwSize = dsoGetSize(psot, dwOffset); /* * Print 4 DWORDS per row; one row per loop */ do { /* while ((int)dwSize > 0) */ /* * Read values for next row */ if (4 * sizeof(DWORD) >= dwSize) { dwMoveSize = dwSize; } else { dwMoveSize = 4 * sizeof(DWORD); } moveBlock(dwBuffer, (PBYTE)pAddress + dwOffset + dwBytesRead, dwMoveSize); pBufferOffset = (PBYTE)dwBuffer; /* * Print the address */ Print("%08lx ", (DWORD)((PBYTE)pAddress + dwOffset + dwBytesRead)); /* * Keep track of bytes read (dwBytesRead) and bytes * remaining to be read (dwSize) */ dwBytesRead += dwMoveSize; dwSize -= dwMoveSize; /* * Print the values, one dword at the time */ while (dwMoveSize >= sizeof(DWORD)) { Print("%08lx ", *((DWORD *)pBufferOffset)); pBufferOffset += sizeof(DWORD); dwMoveSize -= sizeof(DWORD); } /* * If less than a DWORD left, zero extend and print a DWORD */ if (dwMoveSize > 0) { dwValue = 0; memcpy(&dwValue, pBufferOffset, dwMoveSize); Print("%0*lx", dwMoveSize * 2, dwValue); } Print("\n"); } while ((int)dwSize > 0); return TRUE; } /* if (fOneField) */ /* * Printing all the fields. */ Print ("Structure %s - Size: %#lx\n", pst->pszName, pst->dwSize); dwOffset = 0; pBufferOffset = NULL; /* Forces the local buffer to be loaded */ dwFieldsPerRow = 0; /* * Loop through all fields in the table. Print one field per loop */ while (psot->pszField != NULL) { /* * Print two fields per row */ if (dwFieldsPerRow == 2) { Print("\n"); dwFieldsPerRow = 1; } else { dwFieldsPerRow++; } /* * If no address provided, Print field name(s) and offset(s) only */ if (pAddress == NULL) { Print("%03lx %-34.33s", dsoGetOffset(psot), psot->pszField); } else { /* * Printing offsets and values. * * Get the size of the value and max it to one DWORD */ dwOffsetNext = dsoGetOffset(psot + 1); if (dwOffsetNext > dwOffset) { dwSize = dwOffsetNext - dwOffset; } else { dwSize = dsoGetSize(psot, dwOffset); } if (dwSize > sizeof(DWORD)) { dwSize = sizeof(DWORD); } /* * Get a pointer to the value in the local buffer * If the value is not in the buffer, load it */ pdwValue = (PDWORD)(pBufferOffset + dwOffset); if ((pdwValue < dwBuffer) || (pdwValue + dwSize > pcdwLimit)) { pBufferOffset = (PBYTE)dwBuffer - dwOffset; pdwValue = dwBuffer; if (sizeof(dwBuffer) >= pst->dwSize - dwOffset) { dwMoveSize = pst->dwSize - dwOffset; } else { dwMoveSize = sizeof(dwBuffer); } moveBlock((PBYTE)dwBuffer, (PBYTE)pAddress + dwOffset, dwMoveSize); } /* * Copy the value and print it */ dwValue = 0; /* in case size < sizeof(DWORD) */ memcpy(&dwValue, pdwValue, dwSize); Print("(%03lx) %08lx %-24.23s", dwOffset, dwValue, psot->pszField); } /* if (pAddress == NULL) */ dwOffset = dwOffsetNext; psot++; } /* while (psot->pszField != NULL) */ Print("\n"); return TRUE; }