From e1e7859ef4b3353a8ac182fd456b053c653239d1 Mon Sep 17 00:00:00 2001 From: systemcoder Date: Tue, 17 Mar 2020 19:25:03 +0000 Subject: Add support for ascii, column output. Space no space is added --- H64E-2/h64e.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'H64E-2/h64e.c') diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 1e0662c..decaff5 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -67,31 +67,44 @@ int h64e_fmt_byte(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *o int cur_size=0; int i,j=0; const int SZ=16; - uint8_t buf[SZ]; + uint8_t buf[SZ+1]; int buf_sz=0; int trail_size=0; for (i=0; igroup_fmt == H64E_G_BYTE)||(fs->group_fmt == H64E_G_NONE)) && (fs->output_fmt == H64E_O_STRING)) + { + if (isprint(in_data[i])) + { + buf_sz = snprintf(&buf[0], SZ, "%c",(unsigned char)in_data[i]); + } else { + buf_sz = snprintf(&buf[0], SZ, ".",(unsigned char)in_data[i]); + } + } else { + //group byte output + buf_sz = snprintf(&buf[0], SZ, "%02x",in_data[i]); + + } //count converted chars per line - fs->cur_pos += 1; + fs->column_pos += 1; //add space if configured if (fs->f_space) { - if (buf_sz+1cur_pos == fs->column_size) + if (fs->column_pos == fs->column_size) { if (fs->f_new_line) { //set triger to newline fs->t_new_line = 1; - fs->cur_pos = 0; + fs->column_pos = 0; //set new line to buffer if (buf_sz+1