diff options
Diffstat (limited to 'H64E-2/h64e.c')
-rw-r--r-- | H64E-2/h64e.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 0072030..1e0662c 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -49,3 +49,86 @@ int h64e_destroy(H64E_t *s) { return 0; } + +int h64e_fmt_init( H64E_format *fs) +{ + memset(fs,0,sizeof(H64E_format)); + + return 0; +} + +/* + * out_size - allways give enought data to buffer otherwise it will partially write data, or flush data out more often + */ +int h64e_fmt_byte(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + //printf("h64e_fmt_byte in %d out %d\n",in_size,out_size); + int ret=0; + int cur_size=0; + int i,j=0; + const int SZ=16; + uint8_t buf[SZ]; + int buf_sz=0; + int trail_size=0; + + for (i=0; i<in_size; i++) + { + buf_sz = snprintf(&buf[0], SZ, "%02x",in_data[i]); + //count converted chars per line + fs->cur_pos += 1; + //add space if configured + if (fs->f_space) + { + if (buf_sz+1<SZ) + { + buf[buf_sz] = ' '; + buf_sz += 1; + } + } + + if (fs->cur_pos == fs->column_size) + { + if (fs->f_new_line) { + //set triger to newline + fs->t_new_line = 1; + fs->cur_pos = 0; + //set new line to buffer + if (buf_sz+1<SZ) + { + buf[buf_sz] = '\n'; + buf_sz += 1; + } + } + } + //printf("D: %s",buf); + if (trail_size+buf_sz<out_size) + { + for(j=0;j<buf_sz;j++) + { + out_data[trail_size+j] = buf[j]; + } + ret = buf_sz; + + } else { + //not enought output to handle data + ret=-1; + } + } +#if 0 + printf("D:["); + for (i=0;i<ret;i++) + { + printf("%c",(unsigned char)out_data[i]); + } + printf("]\n"); +#endif + + return ret; +} + +int h64e_fmt_finish(H64E_format *fs) +{ + + + return 0; +} |