From 7afe31370ef9d95ca652077c98cf225fff66068c Mon Sep 17 00:00:00 2001 From: systemcoder Date: Thu, 26 Mar 2020 20:32:28 +0000 Subject: Feature complete version of project --- H64E-2/h64e.c | 8 ++++---- H64E-2/h64e.h | 8 +++++++- H64E-2/main.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 10 deletions(-) (limited to 'H64E-2') diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 39884ca..ad8957e 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -95,7 +95,7 @@ int h64e_destroy(H64E_t *s) int h64e_fmt_init( H64E_format *fs) { memset(fs,0,sizeof(H64E_format)); - + fs->length = -1; return 0; } @@ -222,10 +222,10 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui int trail_size=0; //set offset to output - if (fs->f_offset) + if (fs->f_show_offset) { //printf("Print offset\n"); - int offset = fs->start_offset + fs->total_output; + int offset = fs->offset_addr + fs->total_output; buf_offset_sz = snprintf((char *)&buf_offset[0], BUF_SZ, "%08x: ",offset); //make it wider } @@ -502,7 +502,7 @@ int h64e_fmt_align( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t if (fs->f_offset) { //printf("Print offset\n"); - int offset = fs->start_offset + fs->total_output; + int offset = fs->offset_addr + fs->total_output; buf_offset_sz = snprintf((char *)&buf_offset[0], BUF_SZ, "%08x: ",offset); //make it wider } diff --git a/H64E-2/h64e.h b/H64E-2/h64e.h index 7871d21..21d334e 100644 --- a/H64E-2/h64e.h +++ b/H64E-2/h64e.h @@ -49,6 +49,7 @@ typedef struct H64E_params int flag_space; /*space between columns **/ int flag_ascii; int flag_hex; /* hex outout */ + int flag_show_offset; } H64E_params; typedef struct H64E_t @@ -86,7 +87,7 @@ typedef struct H64E_format { int column_pos; //position where output stoped int end_pos; //end postion before new line int f_new_line; //should be new line set after - int start_offset; //start position of offset + //int start_offset; //start position of offset int slide_offset; //offset since stream start int state; int t_new_line; // if new line or buffer full @@ -94,7 +95,12 @@ typedef struct H64E_format { int f_ascii; int f_offset; int f_hex; + int f_show_offset; + uint64_t offset_addr; int total_output; + int f_length; + uint64_t length; //size to output + } H64E_format; int h64e_fmt_init( H64E_format *fs); diff --git a/H64E-2/main.c b/H64E-2/main.c index c95291f..07e96d8 100644 --- a/H64E-2/main.c +++ b/H64E-2/main.c @@ -180,8 +180,9 @@ void helper( char *progname ) " -c - column size in bytes\n" " -e - interp data output: u8,i8,u16,i16,u32,i32,u64,i64\n" " -s - disable space between columns\n" + " -t - show offset numbers\n" " -h - extra hex output\n" - "Version: 2.0.4 \n" + "Version: 2.1.0 \n" "\n" , progname); } @@ -229,7 +230,7 @@ int main(int argc, const char * argv[]) { //set all params from arguments /*get cmd args and set options */ - while ( (c = getopt(argc, argv, "abo:il:vc:e:sh")) != -1 ) + while ( (c = getopt(argc, argv, "abo:il:vc:e:sht")) != -1 ) { switch(c) { @@ -266,6 +267,9 @@ int main(int argc, const char * argv[]) { case 'h': h64e.fmt.flag_hex = 0; break; + case 't': + h64e.fmt.flag_show_offset = 1; + break; case 'v': version(); exit(1); @@ -312,14 +316,25 @@ int main(int argc, const char * argv[]) { int8_fmt.group_fmt = h64e.fmt.group; int8_fmt.output_fmt = h64e.fmt.output_type; int8_fmt.f_offset = h64e.fmt.flag_offset; - int8_fmt.start_offset = h64e.fmt.offset_addr; + int8_fmt.offset_addr = h64e.fmt.offset_addr; int8_fmt.f_output_types = h64e.fmt.flag_output_types; int8_fmt.output_fmt = h64e.fmt.output_type; int8_fmt.f_ascii = h64e.fmt.flag_ascii; int8_fmt.f_hex = h64e.fmt.flag_hex; + int8_fmt.f_show_offset = h64e.fmt.flag_show_offset; - - + if (param_length > -1) + { + printf("param length %d\n", param_length); + int8_fmt.length = param_length; + int8_fmt.f_length = 1; + } + + //set offset in file + if (int8_fmt.f_offset) + { + file_seek(fd, int8_fmt.offset_addr); + } //do conversation, reading input and outputing while ((in_bytes = file_read(fd,(char *)&buf_in,int8_fmt.column_size)) != -1) { @@ -329,6 +344,27 @@ int main(int argc, const char * argv[]) { break; } + if (in_total == int8_fmt.length) + { + break; + } + + if (int8_fmt.f_length == 1) + { + /* + printf("-->\n"); + printf("in_total %d\n", in_total); + printf("in_bytes %d\n", in_bytes); + printf("(in_total+in_bytes)=%d",(in_total+in_bytes)); + */ + //if ((int8_fmt.total_output+in_bytes) >= int8_fmt.length) + if ((in_total+in_bytes) >= int8_fmt.length) + { + in_bytes = int8_fmt.length - in_total; + //printf("in_bytes %d\n", in_bytes); + } + } + //write to input stream, connect all streams in a pipe in_total += in_bytes; //printf("Read from file %d bytes %d bytes total\n",in_bytes,in_total); -- cgit v1.2.3