summaryrefslogtreecommitdiff
path: root/H64E-2/h64e.c
diff options
context:
space:
mode:
authorsystemcoder <systemcoder@protonmail.com>2020-03-21 15:57:41 +0000
committersystemcoder <systemcoder@protonmail.com>2020-03-21 15:57:41 +0000
commitb2911a60e257d493b9d5839f40e923f95df3b525 (patch)
treef3f5862c66196fc1573993886605e701f1edcb44 /H64E-2/h64e.c
parent6abd917945951cb1971fccdd649ee7f59050813c (diff)
downloadH64D-2-b2911a60e257d493b9d5839f40e923f95df3b525.tar.gz
H64D-2-b2911a60e257d493b9d5839f40e923f95df3b525.zip
making to work byte, offset, with no space, and hex output in any combination
Diffstat (limited to 'H64E-2/h64e.c')
-rw-r--r--H64E-2/h64e.c199
1 files changed, 157 insertions, 42 deletions
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c
index 35875a2..80b085d 100644
--- a/H64E-2/h64e.c
+++ b/H64E-2/h64e.c
@@ -11,13 +11,14 @@
int h64e_init(H64E_t *s)
{
printf("init structure\n");
- s->fmt.column_size = 16;
- s->fmt.offset_addr = 0;
- s->fmt.flag_offset = 0;
- s->fmt.flag_no_group = 0;
- s->fmt.group = H64E_G_BYTE;
+ s->fmt.column_size = 16;
+ s->fmt.offset_addr = 0;
+ s->fmt.flag_offset = 0;
+ s->fmt.flag_no_group = 0;
+ s->fmt.flag_hex = 1;
+ s->fmt.group = H64E_G_BYTE;
s->fmt.flag_output_types = 0;
- s->fmt.output_type = H64E_O_NONE;
+ s->fmt.output_type = H64E_O_NONE;
s->sin = NULL;
s->sout = NULL;
@@ -162,14 +163,20 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
*/
const int OUT_SZ=1024; //offset values in hex , spaces, number of hex values, second ascii characters
const int BUF_SZ=64;
+ uint8_t buf_offset[BUF_SZ+1];
uint8_t buf1[BUF_SZ+1];
uint8_t buf2[BUF_SZ+1];
+ uint8_t buf3[BUF_SZ+1];
uint8_t out_part1[OUT_SZ+1];
uint8_t out_part2[OUT_SZ+1];
+ uint8_t out_part3[OUT_SZ+1];
int out_part1_sz=0;
int out_part2_sz=0;
+ int out_part3_sz=0;
+ int buf_offset_sz=0;
int buf1_sz=0;
int buf2_sz=0;
+ int buf3_sz=0;
int loop_size=0;
int trail_size=0;
@@ -178,10 +185,7 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
{
//printf("Print offset\n");
int offset = fs->start_offset + fs->total_output;
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%08x: ",offset);
- //no error check
- memcpy(out_part1,buf1,buf1_sz);
- out_part1_sz += buf1_sz;
+ buf_offset_sz = snprintf((char *)&buf_offset[0], BUF_SZ, "%08x: ",offset);
}
if (in_size%fs->column_size != 0)
@@ -199,103 +203,214 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
{
if (i<in_size)
{
- //group byte output string
- if (((fs->group_fmt == H64E_G_BYTE)||(fs->group_fmt == H64E_G_NONE)) && (fs->output_fmt == H64E_O_STRING))
+
+
+
+ //group byte output
+ if (fs->f_hex)
+ {
+
+ buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%02x",in_data[i]);
+ }
+
+ //ascii output
+ if (fs->f_ascii)
{
if (isprint(in_data[i]))
{
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%c",(unsigned char)in_data[i]);
+ buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, "%c",(unsigned char)in_data[i]);
} else {
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, ".");
+ buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, ".");
}
- } else {
- //group byte output
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%02x",in_data[i]);
}
+
+
if (fs->f_space)
{
//printf("Space enabled\n");
- if (buf1_sz<BUF_SZ)
+ if (fs->f_ascii)
{
- buf1[buf1_sz] = ' ';
- buf1_sz += 1;
+ if (buf2_sz<BUF_SZ)
+ {
+ buf2[buf2_sz] = ' ';
+ buf2_sz += 1;
+ }
+ }
+ if (fs->f_hex)
+ {
+ if (buf1_sz<BUF_SZ)
+ {
+ buf1[buf1_sz] = ' ';
+ buf1_sz += 1;
+ }
+ }
+ }
+
+ /*
+ if (fs->f_output_types)
+ {
+ if (fs->output_fmt == H64E_O_INT8)
+ {
+ int ii = in_data[i];
+ buf3_sz = snprintf((char *)&buf3[0], BUF_SZ, "%4d ", (int8_t)ii);
+ } else if (fs->output_fmt == H64E_O_UINT8) {
+ unsigned int uu = in_data[i];
+ buf3_sz = snprintf((char *)&buf3[0], BUF_SZ, "%4u ", uu);
}
}
+ */
} else {
printf("Empty spaces\n");
//group byte output string
if (((fs->group_fmt == H64E_G_BYTE)||(fs->group_fmt == H64E_G_NONE)) && (fs->output_fmt == H64E_O_STRING))
{
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, " ");
+ buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, " ");
} else {
//group byte output
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, " ");
+ buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, " ");
}
if (fs->f_space)
{
- if (buf1_sz<BUF_SZ)
+ if (buf2_sz<BUF_SZ)
{
- buf1[buf1_sz] = ' ';
- buf1_sz += 1;
+ buf2[buf2_sz] = ' ';
+ buf2_sz += 1;
+ }
+ if (buf3_sz<BUF_SZ)
+ {
+ buf3[buf3_sz] = ' ';
+ buf3_sz += 1;
}
}
}
- //count converted chars per line
- fs->column_pos += 1;
- fs->total_output += 1;
+ //count converted chars per line
+ fs->column_pos += 1;
+ fs->total_output += 1;
- if (fs->column_pos == fs->column_size)
- {
- if (fs->f_new_line) {
- //set triger to newline
- fs->t_new_line = 1;
- fs->column_pos = 0;
- //set new line to buffer
+ if (fs->column_pos == fs->column_size)
+ {
+ if (fs->f_new_line) {
+ //set triger to newline
+ fs->t_new_line = 1;
+ fs->column_pos = 0;
+ //set new line to hex buffer
+ //printf("%d %d %d\n",fs->f_ascii,fs->f_hex,fs->f_output_types);
+ if ((fs->f_ascii==1) && (fs->f_output_types==0) )
+ {
+ if (buf2_sz+1<BUF_SZ)
+ {
+ buf2[buf2_sz] = '\n';
+ buf2_sz += 1;
+ }
+ }
+
+ if ((fs->f_hex==1) && (fs->f_ascii==0) && (fs->f_output_types==0) )
+ {
+ if (buf1_sz+1<BUF_SZ)
+ {
+ buf1[buf1_sz] = '\n';
+ buf1_sz += 1;
+ }
+ }
+
+ /*
+ if (fs->f_output_types)
+ {
+ if (buf2_sz+1<BUF_SZ)
+ {
+ buf2[buf2_sz] = '\n';
+ buf2_sz += 1;
+ }
+ } else {
if (buf1_sz+1<BUF_SZ)
{
buf1[buf1_sz] = '\n';
buf1_sz += 1;
}
}
+ */
}
+ }
-
//copy data to buffer after each iteration
for (j=0; j<buf1_sz; j++)
{
out_part1[out_part1_sz+j] = buf1[j];
}
out_part1_sz += buf1_sz;
+ buf1_sz = 0;
for (j=0; j<buf2_sz; j++)
{
out_part2[out_part2_sz+j] = buf2[j];
}
out_part2_sz += buf2_sz;
+ buf2_sz = 0;
+
+ for (j=0; j<buf3_sz; j++)
+ {
+ out_part3[out_part3_sz+j] = buf3[j];
+ }
+ out_part3_sz += buf3_sz;
+ buf3_sz = 0;
}
+ //printf("buf_offset_sz %d\n",buf_offset_sz);
//printf("out_part1_sz %d\n",out_part1_sz);
//printf("out_part2_sz %d\n",out_part2_sz);
+ //printf("out_part3_sz %d\n",out_part3_sz);
- //concat all data from 2 buffers
- for (i=0;i<out_part1_sz;i++)
+ //concat all data from 3 buffers
+ for (i=0;i<buf_offset_sz;i++)
{
if (i<out_size)
{
- out_data[i] = out_part1[i];
+ out_data[i] = buf_offset[i];
+ trail_size += 1;
+ }
+ }
+
+ for (i=0,j=trail_size;i<out_part1_sz;i++)
+ {
+ if (j+i<out_size)
+ {
+ out_data[j+i] = out_part1[i];
+ trail_size += 1;
+ }
+ }
+
+ //if space between sapce disabled then put one space between ascii&hex output
+ //printf("%d %d %d\n",fs->f_ascii,fs->f_hex,fs->f_space);
+ if ((fs->f_ascii==1) && (fs->f_hex==1) && (fs->f_space==0))
+ {
+ if (trail_size<out_size)
+ {
+ out_data[trail_size] = ' ';
+ trail_size += 1;
+ }
+ }
+
+ for (i=0,j=trail_size;i<out_part2_sz;i++)
+ {
+ if (j+i<out_size)
+ {
+ out_data[j+i] = out_part2[i];
trail_size += 1;
}
}
- for (i=0;i<out_part2_sz;i++)
+ /*
+ for (i=0;i<out_part3_sz;i++)
{
- if (out_part1_sz+i<out_size)
+ if (i<out_size)
{
- out_data[i] = out_part2[i];
+ out_data[j+i] = out_part3[i];
trail_size += 1;
}
}
+ */
+
ret = trail_size;
//printf("ret %d\n",ret);