summaryrefslogtreecommitdiff
path: root/H64E-2
diff options
context:
space:
mode:
Diffstat (limited to 'H64E-2')
-rw-r--r--H64E-2/h64e.c56
-rw-r--r--H64E-2/main.c16
2 files changed, 45 insertions, 27 deletions
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c
index 8a1325a..35875a2 100644
--- a/H64E-2/h64e.c
+++ b/H64E-2/h64e.c
@@ -176,6 +176,7 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
//set offset to output
if (fs->f_offset)
{
+ //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
@@ -193,9 +194,10 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
//size shout be allways matching (size mod columnsize == 0)
//non matching size should be used at the end, on last line of output
+ //printf("Loop_size %d\n",loop_size);
for (i=0; i<loop_size; i++)
{
- if (i>in_size)
+ 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))
@@ -210,18 +212,38 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
//group byte output
buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%02x",in_data[i]);
}
- //count converted chars per line
- fs->column_pos += 1;
- fs->total_output += 1;
- //add space if configured
if (fs->f_space)
{
+ //printf("Space enabled\n");
if (buf1_sz<BUF_SZ)
{
buf1[buf1_sz] = ' ';
buf1_sz += 1;
}
}
+
+ } 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, " ");
+ } else {
+ //group byte output
+ buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, " ");
+ }
+ if (fs->f_space)
+ {
+ if (buf1_sz<BUF_SZ)
+ {
+ buf1[buf1_sz] = ' ';
+ buf1_sz += 1;
+ }
+ }
+ }
+ //count converted chars per line
+ fs->column_pos += 1;
+ fs->total_output += 1;
if (fs->column_pos == fs->column_size)
{
@@ -237,16 +259,7 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
}
}
}
- } else {
- //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, " ");
- } else {
- //group byte output
- buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, " ");
- }
- }
+
//copy data to buffer after each iteration
for (j=0; j<buf1_sz; j++)
@@ -262,28 +275,29 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui
out_part2_sz += buf2_sz;
}
+ //printf("out_part1_sz %d\n",out_part1_sz);
+ //printf("out_part2_sz %d\n",out_part2_sz);
//concat all data from 2 buffers
for (i=0;i<out_part1_sz;i++)
{
- if (out_size<i)
+ if (i<out_size)
{
out_data[i] = out_part1[i];
trail_size += 1;
- } else {
- ret = trail_size;
}
}
for (i=0;i<out_part2_sz;i++)
{
- if (out_size < out_part1_sz+i)
+ if (out_part1_sz+i<out_size)
{
out_data[i] = out_part2[i];
- } else {
- ret = trail_size+i;
+ trail_size += 1;
}
}
+ ret = trail_size;
+ //printf("ret %d\n",ret);
#if 0
printf("D:[");
diff --git a/H64E-2/main.c b/H64E-2/main.c
index 29184b7..791cc18 100644
--- a/H64E-2/main.c
+++ b/H64E-2/main.c
@@ -167,7 +167,7 @@ int main(int argc, const char * argv[]) {
int fd;
int in_bytes = 0, out_bytes=0, cnv_bytes=0;
int in_total = 0, out_total=0, cnv_total=0;
- uint8_t buf_in[128+1],buf_cnv_in[128+1],buf_cnv_out[256+1],buf_out[512+1];
+ uint8_t buf_in[128+1],buf_cnv_in[128+1],buf_cnv_out[2048+1],buf_out[2048+1];
int i=0;
printf("H64E-2 Project started 1\n");
@@ -176,21 +176,24 @@ int main(int argc, const char * argv[]) {
H64E_t h64e;
H64E_stream_in sin;
H64E_stream_out sout;
+
+ memset(&h64e,0,sizeof(H64E_t));
h64e_init(&h64e);
h64e_si_init(&sin, 128);
- h64e_so_init(&sout, 512);
+ h64e_so_init(&sout, 4096);
h64e_set_input(&h64e, &sin);
h64e_set_output(&h64e, &sout);
H64E_format int8_fmt;
//list of supported formats
+
h64e_fmt_init(&int8_fmt);
//set all params from arguments
/*get cmd args and set options */
- while ( (c = getopt(argc, argv, "abo:il:vc:g:e:s")) != -1 )
+ while ( (c = getopt(argc, argv, "abo:il:vc:g:e:st")) != -1 )
{
switch(c)
{
@@ -266,6 +269,7 @@ int main(int argc, const char * argv[]) {
//configure format of u8 to terminate on new line and have space between types
//printf("Column size set to %d\n",h64e.fmt.column_size);
int8_fmt.f_space = !h64e.fmt.flag_space;
+ printf("h64e.fmt.flag_space %d\n",h64e.fmt.flag_space);
int8_fmt.f_new_line = 1;
int8_fmt.column_size = h64e.fmt.column_size;
int8_fmt.group_fmt = h64e.fmt.group;
@@ -290,11 +294,11 @@ int main(int argc, const char * argv[]) {
h64e_si_data_in(&sin, &buf_in[0], in_bytes);
//if buffer have enought data then convert it
- if (h64e_si_len(&sin)>1)
+ if (h64e_si_len(&sin)>=int8_fmt.column_size)
{
int cnv_num=-1;
//printf("Input Out\n");
- cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], 1);
+ cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], int8_fmt.column_size);
//cnv_total += cnv_bytes;
@@ -303,7 +307,7 @@ int main(int argc, const char * argv[]) {
switch (h64e.fmt.group)
{
case H64E_G_BYTE:
- cnv_num = h64e_fmt_byte(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512);
+ cnv_num = h64e_fmt_byte_align16(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 2048);
break;
case H64E_G_WORD:
cnv_num = h64e_fmt_word(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512);