summaryrefslogtreecommitdiff
path: root/H64E-2
diff options
context:
space:
mode:
authorsystemcoder <systemcoder@protonmail.com>2020-03-21 21:56:15 +0000
committersystemcoder <systemcoder@protonmail.com>2020-03-21 21:56:15 +0000
commit608dd9cbc015f4a30a76a7a5de8e0221da4db4e3 (patch)
tree3d75a0999b7ce89a4b40bfaa6952a847820a0f98 /H64E-2
parentdea754a95c639fa3142e1c1b1b60a9a6500377e5 (diff)
downloadH64D-2-608dd9cbc015f4a30a76a7a5de8e0221da4db4e3.tar.gz
H64D-2-608dd9cbc015f4a30a76a7a5de8e0221da4db4e3.zip
different size output works
Diffstat (limited to 'H64E-2')
-rw-r--r--H64E-2/h64e.c114
-rw-r--r--H64E-2/h64e.h1
2 files changed, 115 insertions, 0 deletions
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c
index 15b883e..39884ca 100644
--- a/H64E-2/h64e.c
+++ b/H64E-2/h64e.c
@@ -569,6 +569,7 @@ int h64e_fmt_align( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t
if (fs->f_output_types)
{
+ /*
if (fs->output_fmt == H64E_O_INT8)
{
int ii = in_data[i];
@@ -577,6 +578,9 @@ int h64e_fmt_align( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t
unsigned int uu = in_data[i];
buf3_sz = snprintf((char *)&buf3[0], BUF_SZ, "%4u ", uu);
}
+ */
+ buf3_sz = h64e_fmt_type(fs, &in_data[i], in_size-i, buf3, BUF_SZ);
+ //printf("buf3_sz %d\n",buf3_sz);
}
} else {
@@ -837,3 +841,113 @@ int h64e_fmt_hex(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *ou
return buf_sz;
}
+
+int h64e_fmt_type(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size)
+{
+ int buf_sz = -1;
+ int data_sz = -1;
+ int type = fs->output_fmt;
+
+ //printf("!!!type %d\n",type);
+ switch (type)
+ {
+ case H64E_O_UINT8:
+ case H64E_O_INT8:
+ //data_sz = 1;
+ data_sz = 3;
+ break;
+ case H64E_O_UINT16:
+ case H64E_O_INT16:
+ //data_sz = 2;
+ data_sz = 5;
+ break;
+ case H64E_O_UINT32:
+ case H64E_O_INT32:
+ //data_sz = 4;
+ data_sz = 10;
+ break;
+ case H64E_O_UINT64:
+ case H64E_O_INT64:
+ //data_sz = 8;
+ data_sz = 19;
+ break;
+ }
+
+ switch(type)
+ {
+ case H64E_O_INT8:
+ case H64E_O_INT16:
+ case H64E_O_INT32:
+ case H64E_O_INT64:
+ data_sz += 1;
+ break;
+ }
+
+ if (out_size < data_sz)
+ {
+ printf("Output buffer too small h64e_fmt_type\n");
+ return -1;
+ }
+
+ switch (type)
+ {
+ case H64E_O_UINT8:
+ {
+ //printf("H64E_O_UINT8\n");
+ uint8_t *u8 = (uint8_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%3u ", *u8);
+ break;
+ }
+ case H64E_O_INT8:
+ {
+ //printf("H64E_O_INT8\n");
+ int8_t *i8 = (int8_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%4i ", *i8);
+ break;
+ }
+ case H64E_O_UINT16:
+ {
+ //printf("H64E_O_UINT16\n");
+ uint16_t *u16 = (uint16_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%5hu ", *u16);
+ break;
+ }
+ case H64E_O_INT16:
+ {
+ //printf("H64E_O_INT16\n");
+ int16_t *i16 = (int16_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%6hd ", *i16);
+ break;
+ }
+ case H64E_O_UINT32:
+ {
+ //printf("H64E_O_UINT32\n");
+ uint32_t *u32 = (uint32_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%10u ", *u32);
+ break;
+ }
+ case H64E_O_INT32:
+ {
+ //printf("H64E_O_INT32\n");
+ int32_t *i32 = (int32_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%11d ", *i32);
+ break;
+ }
+ case H64E_O_UINT64:
+ {
+ //printf("H64E_O_UINT64\n");
+ uint64_t *u64 = (uint64_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%20llu ", *u64);
+ break;
+ }
+ case H64E_O_INT64:
+ {
+ //printf("H64E_O_INT64\n");
+ int64_t *i64 = (int64_t *)in_data;
+ buf_sz = snprintf((char *)out_data, out_size, "%20lld ", *i64);
+ break;
+ }
+ }
+
+ return buf_sz;
+}
diff --git a/H64E-2/h64e.h b/H64E-2/h64e.h
index e1446ee..d61f60b 100644
--- a/H64E-2/h64e.h
+++ b/H64E-2/h64e.h
@@ -104,5 +104,6 @@ int h64e_fmt_finish( H64E_format *fs);
int h64e_fmt_space(H64E_format *fs, uint8_t *out_data, int32_t out_size, int32_t data_sz, int32_t type);
int h64e_fmt_ascii(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size, int32_t data_sz);
int h64e_fmt_hex(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size, int32_t data_sz);
+int h64e_fmt_type(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size);
#endif /* h64e_h */