/** * Helper function for formatting the opcode bytes. * * @returns The number of output bytes. * * @param pDis Pointer to the disassembler state. * @param pszDst The output buffer. * @param cchDst The size of the output buffer. * @param fFlags The flags passed to the formatter. */ size_t disFormatBytes(PCDISSTATE pDis, char *pszDst, size_t cchDst, uint32_t fFlags) { size_t cchOutput = 0; uint32_t cb = pDis->cbInstr; AssertStmt(cb <= 16, cb = 16); #define PUT_C(ch) \ do { \ cchOutput++; \ if (cchDst > 1) \ { \ cchDst--; \ *pszDst++ = (ch); \ } \ } while (0) #define PUT_NUM(cch, fmt, num) \ do { \ cchOutput += (cch); \ if (cchDst > 1) \ { \ const size_t cchTmp = RTStrPrintf(pszDst, cchDst, fmt, (num)); \ pszDst += cchTmp; \ cchDst -= cchTmp; \ } \ } while (0) if (fFlags & DIS_FMT_FLAGS_BYTES_BRACKETS) PUT_C('['); for (uint32_t i = 0; i < cb; i++) { if (i != 0 && (fFlags & DIS_FMT_FLAGS_BYTES_SPACED)) PUT_NUM(3, " %02x", pDis->abInstr[i]); else PUT_NUM(2, "%02x", pDis->abInstr[i]); } if (fFlags & DIS_FMT_FLAGS_BYTES_BRACKETS) PUT_C(']'); /* Terminate it just in case. */ if (cchDst >= 1) *pszDst = '\0'; #undef PUT_C #undef PUT_NUM return cchOutput; }
/* Parses command line, looking at each option and doing the right thing. */ Local void GET_PARAMS(struct LOC_START *LINK) { struct LOC_GET_PARAMS V; Char Buffer[256], Current[256]; boolean Bad_Params; Char STR1[256]; Char STR2[256]; V.LINK = LINK; __Group_Not_Running = true; #if 0 sprintf(__File_Name, "%s.LOG", GET_PROG_NAME(STR1, &V)); #endif *__Command_Line = '\0'; LINK->I = 1; Bad_Params = false; while (LINK->I < P_argc && !Bad_Params) { strcpy(Buffer, P_argv[LINK->I]); if ((char) Buffer[0] != '-' || (int) strlen(Buffer) < 2) { Bad_Params = true; break; } switch (toupper(Buffer[1])) { case 'T': if (!PUT_NUM(&__default_test_term, Buffer, &V)) Bad_Params = true; break; case 'R': if (!PUT_NUM(&__default_ref_term, Buffer, &V)) Bad_Params = true; break; case 'A': if (!PUT_NUM(&__default_aux_a, Buffer, &V)) Bad_Params = true; break; case 'B': if (!PUT_NUM(&__default_aux_b, Buffer, &V)) Bad_Params = true; break; case 'C': GET_COMMAND_LINE(&LINK->I, P_argv[LINK->I], &V); break; case 'M': if (strlen(Buffer) == 4) { if (toupper(Buffer[3]) == 'Y') { __Manual = true; } else if (toupper(Buffer[3]) != 'Y') Bad_Params = true; } else { Bad_Params = true; } break; case 'E': __Log_Every_Thing = true; __Log_Msg = true; break; case 'L': __Log_Msg = true; if ((int) strlen(Buffer) > 3) strsub(__File_Name, Buffer, 4, strlen(Buffer)); break; case 'D': /* __Group_Not_Running = false; */ /* Option 'D' is being switched to debug mode. */ __DEBUG = 1; break; default: Bad_Params = true; break; } LINK->I++; } if (Bad_Params) MODULE_ERR("Bad parameter line. Please see manual for information"); if (!PORT_ASSIGNMENTS_OK(__default_test_term, __default_ref_term, __default_aux_a, __default_aux_b)) MODULE_ERR("Bad Port assignments in command line. See manual"); sprintf(__Command_Line, "NM%s", strcpy(STR2, __Command_Line)); if (!__Manual) __Command_Line[1] = 'A'; if (__Refpres) __Command_Line[0] = 'R'; }