// // h64e.c // H64E-2 // // Created by dianshi on 3/13/20. // Copyright © 2020 dianshi. All rights reserved. // #include "h64e.h" 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.flag_output = 0; s->fmt.output_type = H64E_O_NONE; s->sin = NULL; s->sout = NULL; return 0; } int h64e_check_param( H64E_t *fmt ) { printf("Check parametrs set\n"); return 0; } int h64e_set_input(H64E_t *s, H64E_stream_in *sin) { return 0; } int h64e_set_output(H64E_t *s, H64E_stream_out *sout) { return 0; } int h64e_convert(H64E_t *s) { return 0; } 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+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->column_pos += 1; //add space if configured if (fs->f_space) { if (buf_szcolumn_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 (buf_sz+1