summaryrefslogtreecommitdiff
path: root/tools/utils.c
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2021-12-20 20:33:42 -0700
committerGitHub <noreply@github.com>2021-12-20 20:33:42 -0700
commit48a06f2fa5bf1ece94095980f1fef4f306accbeb (patch)
tree3cfe6446bd41c885c0f92a158500702044c8157d /tools/utils.c
parentcdb3ca63aa6170fa82c2e708dde6380f2204d067 (diff)
Add MSYS2 MinGW x64 Support (#108)
* Added MSYS2 MinGW x64 Support * Updated recomp * Updated tools
Diffstat (limited to 'tools/utils.c')
-rw-r--r--tools/utils.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/tools/utils.c b/tools/utils.c
index e9974a1c0..ccf462b8e 100644
--- a/tools/utils.c
+++ b/tools/utils.c
@@ -61,24 +61,48 @@ int fprint_write_output(FILE *fp, write_encoding encoding, const uint8_t *raw, i
int flength = 0;
const encoding_format *fmt = &enc_fmt[encoding];
switch (encoding) {
- case ENCODING_RAW:
- flength = fwrite(raw, 1, length, fp);
- break;
- case ENCODING_U8:
- case ENCODING_U16:
- case ENCODING_U32:
- case ENCODING_U64:
+ case ENCODING_RAW:
+ flength = fwrite(raw, 1, length, fp);
+ break;
+ case ENCODING_U8:
+ case ENCODING_U16:
+ case ENCODING_U32:
+ case ENCODING_U64:
for (int w = 0; w < length; w += fmt->bytes_per_val) {
flength += fprintf(fp, "0x");
for (int b = 0; b < fmt->bytes_per_val; b++) {
- int off = w + b;
- flength += fprintf(fp, "%02x", off < length ? raw[off] : 0x00);
+ int off = w + b;
+ flength += fprintf(fp, "%02x", off < length ? raw[off] : 0x00);
}
flength += fprintf(fp, "%s%c", fmt->suffix, (w < length - fmt->bytes_per_val) ? ',' : '\n');
- }
- break;
+ }
+ break;
+ }
+ return flength;
+}
+
+void fprint_hex(FILE *fp, const unsigned char *buf, int length)
+{
+ int i;
+ for (i = 0; i < length; i++) {
+ fprint_byte(fp, buf[i]);
+ fputc(' ', fp);
+ }
+}
+
+void fprint_hex_source(FILE *fp, const unsigned char *buf, int length)
+{
+ int i;
+ for (i = 0; i < length; i++) {
+ if (i > 0) fputs(", ", fp);
+ fputs("0x", fp);
+ fprint_byte(fp, buf[i]);
}
- return flength;
+}
+
+void print_hex(const unsigned char *buf, int length)
+{
+ fprint_hex(stdout, buf, length);
}
void swap_bytes(unsigned char *data, long length)