diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-11-23 14:03:12 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-11-23 14:03:12 +0100 |
commit | f64ec5e8e03680f0dc170740020f59956cd7039a (patch) | |
tree | 64e3a1305c80957ff55765a0dea1b6e382b4859a | |
parent | 62557c62377a6f0c67f05628a5cbe6c29a3a83de (diff) | |
download | embedlog-f64ec5e8e03680f0dc170740020f59956cd7039a.tar.gz embedlog-f64ec5e8e03680f0dc170740020f59956cd7039a.tar.bz2 embedlog-f64ec5e8e03680f0dc170740020f59956cd7039a.zip |
add: printing memory without ascii table
That ascii table could take a lot of space, especially when
printing single line, now it's an option
-rw-r--r-- | include/embedlog.h | 4 | ||||
-rw-r--r-- | man/el_cleanup.3 | 2 | ||||
-rw-r--r-- | man/el_init.3 | 2 | ||||
-rw-r--r-- | man/el_opmemory_table.3 | 1 | ||||
-rw-r--r-- | man/el_option.3 | 2 | ||||
-rw-r--r-- | man/el_overview.7 | 9 | ||||
-rw-r--r-- | man/el_pmemory_table.3 | 1 | ||||
-rw-r--r-- | man/el_print.3 | 32 | ||||
-rw-r--r-- | src/el-pmemory.c | 179 | ||||
-rw-r--r-- | tst/test-el-file.c | 4 | ||||
-rw-r--r-- | tst/test-el-pmemory.c | 67 |
11 files changed, 214 insertions, 89 deletions
diff --git a/include/embedlog.h b/include/embedlog.h index f980398..5b694e6 100644 --- a/include/embedlog.h +++ b/include/embedlog.h @@ -178,6 +178,8 @@ int el_vprint(const char *file, size_t line, enum el_level level, const char *fmt, va_list ap); int el_pmemory(const char *file, size_t line, enum el_level level, const void *memory, size_t mlen); +int el_pmemory_table(const char *file, size_t line, enum el_level level, + const void *memory, size_t mlen); int el_perror(const char *file, size_t line, enum el_level level, const char *fmt, ...); int el_putb(const void *memory, size_t mlen); @@ -193,6 +195,8 @@ int el_ovprint(const char *file, size_t line, enum el_level level, struct el_options *options, const char *fmt, va_list ap); int el_opmemory(const char *file, size_t line, enum el_level level, struct el_options *options, const void *memory, size_t mlen); +int el_opmemory_table(const char *file, size_t line, enum el_level level, + struct el_options *options, const void *memory, size_t mlen); int el_operror(const char *file, size_t line, enum el_level level, struct el_options *options, const char *fmt, ...); int el_oputb(struct el_options *options, const void *memory, size_t mlen); diff --git a/man/el_cleanup.3 b/man/el_cleanup.3 index 1a03a18..a60dc41 100644 --- a/man/el_cleanup.3 +++ b/man/el_cleanup.3 @@ -49,6 +49,8 @@ Passed options object is not valid .BR el_vprint (3), .BR el_perror (3), .BR el_pmemory (3), +.BR el_pmemory_table (3), +.BR el_opmemory_table (3), .BR el_ooption (3), .BR el_oputs (3), .BR el_oprint (3), diff --git a/man/el_init.3 b/man/el_init.3 index 39fcee3..ed8dc62 100644 --- a/man/el_init.3 +++ b/man/el_init.3 @@ -115,6 +115,8 @@ Note: error handling has been ommited for clarity sake .BR el_vprint (3), .BR el_perror (3), .BR el_pmemory (3), +.BR el_pmemory_table (3), +.BR el_opmemory_table (3), .BR el_ocleanup (3), .BR el_ooption (3), .BR el_oputs (3), diff --git a/man/el_opmemory_table.3 b/man/el_opmemory_table.3 new file mode 100644 index 0000000..8a9800f --- /dev/null +++ b/man/el_opmemory_table.3 @@ -0,0 +1 @@ +.so man3/el_print.3 diff --git a/man/el_option.3 b/man/el_option.3 index 3d1fee2..855a484 100644 --- a/man/el_option.3 +++ b/man/el_option.3 @@ -613,6 +613,8 @@ informations .BR el_vprint (3), .BR el_perror (3), .BR el_pmemory (3), +.BR el_pmemory_table (3), +.BR el_opmemory_table (3), .BR el_ocleanup (3), .BR el_oputs (3), .BR el_oprint (3), diff --git a/man/el_overview.7 b/man/el_overview.7 index d26e5b3..31791f9 100644 --- a/man/el_overview.7 +++ b/man/el_overview.7 @@ -83,6 +83,9 @@ enum el_level " level ", const char *" fmt ", va_list " ap ")" .BI "int el_pmemory(const char *" file ", size_t " line ", \ enum el_level " level ", const void *" memory ", size_t " mlen ")" .br +.BI "int el_pmemory_table(const char *" file ", size_t " line ", \ +enum el_level " level ", const void *" memory ", size_t " mlen ") +.br .BI "int el_perror(const char *" file ", size_t " line ", \ enum el_level " level ", const char *" fmt ", " ... ")" .br @@ -122,6 +125,10 @@ const char *" fmt ", va_list " ap ")" enum el_level " level ", struct el_options *" options ", \ const void *" memory ", size_t " mlen ")" .br +.BI "int el_opmemory_table(const char *" file ", size_t " line ", \ +enum el_level " level ", struct el_options *" options ", \ +const void *" memory ", size_t " mlen ")" +.br .BI "int el_operror(const char *" file ", size_t " line ", \ enum el_level " level ", struct el_options *" options ", \ const char *" fmt ", " ... ")" @@ -253,6 +260,8 @@ for more details. .BR el_vprint (3), .BR el_perror (3), .BR el_pmemory (3), +.BR el_pmemory_table (3), +.BR el_opmemory_table (3), .BR el_oinit (3), .BR el_ocleanup (3), .BR el_ooption (3), diff --git a/man/el_pmemory_table.3 b/man/el_pmemory_table.3 new file mode 100644 index 0000000..8a9800f --- /dev/null +++ b/man/el_pmemory_table.3 @@ -0,0 +1 @@ +.so man3/el_print.3 diff --git a/man/el_print.3 b/man/el_print.3 index 8a76e05..83646ef 100644 --- a/man/el_print.3 +++ b/man/el_print.3 @@ -5,6 +5,7 @@ .BR el_vprint , .BR el_puts , .BR el_pmemory, +.BR el_pmemory_table, .B el_perror - prints message to previously configured outputs. .SH SYNOPSIS @@ -27,6 +28,9 @@ enum el_level " level ", const char *" fmt ", " ... ")" .BI "int el_pmemory(const char *" file ", size_t " line ", \ enum el_level " level ", const void *" memory ", size_t " mlen ") .br +.BI "int el_pmemory_table(const char *" file ", size_t " line ", \ +enum el_level " level ", const void *" memory ", size_t " mlen ") +.br .BI "int el_pbinary(enum el_level " level ", const void *" memory", \ size_t " mlen ") .PP @@ -51,6 +55,10 @@ const char *" fmt ", " ... ")" enum el_level " level ", struct el_options *" options ", \ const void *" memory ", size_t " mlen ")" .br +.BI "int el_opmemory_table(const char *" file ", size_t " line ", \ +enum el_level " level ", struct el_options *" options ", \ +const void *" memory ", size_t " mlen ")" +.br .BI "int el_opbinary(enum el_level " level ", struct el_options *" options ", \ const void *" memory ", size_t " mlen ")" .PP @@ -188,6 +196,22 @@ We print all ascii table, to present printing of printable and non-printable values. .PP .EX + 0x0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................ + 0x0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................ + 0x0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !"#$%&'()*+,-./ + 0x0030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>? + 0x0040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO + 0x0050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\]^_ + 0x0060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno + 0x0070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~. +.EE +.PP +.BR el_pmemory_table (3) +works just like +.BR el_pmemory (3) +but also prints table-like header and footer. +.PP +.EX ------ ----------------------------------------------- ---------------- offset hex ascii ------ ----------------------------------------------- ---------------- @@ -293,7 +317,8 @@ uses only timestamp and log level, rest of the options are simply ignores. .PP .BR el_print (3), .BR el_vprint (3), -.BR el_perror (3) +.BR el_perror (3), +.BR el_pmemory_table (3) and .BR el_pmemory (3) are filtered based on their @@ -434,7 +459,8 @@ All possible outputs are disabled .PP .BR el_print (3), .BR el_vprint (3), -.BR el_perror (3) +.BR el_perror (3), +.BR el_pmemory_table (3) and .BR el_pmemory (3) may also return: @@ -459,6 +485,8 @@ and if file rotation is enabled also from .BR el_overview (7), .BR el_option (3), .BR el_pmemory (3), +.BR el_pmemory_table (3), +.BR el_opmemory_table (3), .BR el_ocleanup (3), .BR el_ooption (3), .BR el_opmemory (3), diff --git a/src/el-pmemory.c b/src/el-pmemory.c index a2130b8..44f0965 100644 --- a/src/el-pmemory.c +++ b/src/el-pmemory.c @@ -129,40 +129,6 @@ static int el_print_line /* ========================================================================== - __ __ _ - ____ __ __ / /_ / /(_)_____ - / __ \ / / / // __ \ / // // ___/ - / /_/ // /_/ // /_/ // // // /__ - / .___/ \__,_//_.___//_//_/ \___/ - /_/ - ____ __ _ - / __/__ __ ____ _____ / /_ (_)____ ____ _____ - / /_ / / / // __ \ / ___// __// // __ \ / __ \ / ___/ - / __// /_/ // / / // /__ / /_ / // /_/ // / / /(__ ) - /_/ \__,_//_/ /_/ \___/ \__//_/ \____//_/ /_//____/ - - ========================================================================== */ - - -/* ========================================================================== - same as el_opmemory but uses default options object - ========================================================================== */ - - -int el_pmemory -( - const char *file, /* file name where log is printed */ - size_t num, /* line number where log is printed */ - enum el_level level, /* log level to print message with */ - const void *mem, /* memory location to print */ - size_t mlen /* number of bytes to print */ -) -{ - return el_opmemory(file, num, level, &g_options, mem, mlen); -} - - -/* ========================================================================== Function prints byte from memory location in a nice format. Single line of data printed will be formated like this (please note, @@ -180,17 +146,26 @@ int el_pmemory ' ' (2 spaces). Next bytes are counted from formula 3*EL_MEM_LINE_SIZE (3 bytes are for 2 hex characters and a space). Next there is 2 bytes for space, and EL_MEM_LINE_SIZE bytes for character representation + + If table is set to 1, table will be printed, and message will look like: + + ------ ----------------------------------------------- ---------------- + offset hex ascii + ------ ----------------------------------------------- ---------------- + 0xNNNN HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH CCCCCCCCCCCCCCCC + ------ ----------------------------------------------- ---------------- ========================================================================== */ -int el_opmemory +static int el_pmem ( const char *file, /* file name where log is printed */ size_t num, /* line number where log is printed */ enum el_level level, /* log level to print message with */ struct el_options *options, /* options defining printing style */ const void *mem, /* memory location to print */ - size_t mlen /* number of bytes to print */ + size_t mlen, /* number of bytes to print */ + int table /* print table? or not to print table? */ ) { /* @@ -231,21 +206,23 @@ int el_opmemory * ------ ----------------------------------------------- ---------------- */ - rv = 0; - rv |= el_oprint(file, num, level, options, "%.*s %.*s %.*s", - EL_MEM_OFFSET_LEN - 2, separator, - EL_MEM_HEX_LEN - 1, separator, - EL_MEM_CHAR_LEN, separator); - - rv |= el_oprint(file, num, level, options, "%-*s%-*s%s", - EL_MEM_OFFSET_LEN, "offset", - EL_MEM_HEX_LEN + 1, "hex", "ascii"); - - rv |= el_oprint(file, num, level, options, "%.*s %.*s %.*s", - EL_MEM_OFFSET_LEN - 2, separator, - EL_MEM_HEX_LEN - 1, separator, - EL_MEM_CHAR_LEN, separator); - + if (table) + { + rv = 0; + rv |= el_oprint(file, num, level, options, "%.*s %.*s %.*s", + EL_MEM_OFFSET_LEN - 2, separator, + EL_MEM_HEX_LEN - 1, separator, + EL_MEM_CHAR_LEN, separator); + + rv |= el_oprint(file, num, level, options, "%-*s%-*s%s", + EL_MEM_OFFSET_LEN, "offset", + EL_MEM_HEX_LEN + 1, "hex", "ascii"); + + rv |= el_oprint(file, num, level, options, "%.*s %.*s %.*s", + EL_MEM_OFFSET_LEN - 2, separator, + EL_MEM_HEX_LEN - 1, separator, + EL_MEM_CHAR_LEN, separator); + } /* * print all lines that contains EL_MEM_LINE_SIZE bytes, meaning we print @@ -281,10 +258,102 @@ int el_opmemory * ------ ----------------------------------------------- ---------------- */ - rv |= el_oprint(file, num, level, options, "%.*s %.*s %.*s", - EL_MEM_OFFSET_LEN - 2, separator, - EL_MEM_HEX_LEN - 1, separator, - EL_MEM_CHAR_LEN, separator); + if (table) + { + rv |= el_oprint(file, num, level, options, "%.*s %.*s %.*s", + EL_MEM_OFFSET_LEN - 2, separator, + EL_MEM_HEX_LEN - 1, separator, + EL_MEM_CHAR_LEN, separator); + } return rv; } + + +/* ========================================================================== + __ __ _ + ____ __ __ / /_ / /(_)_____ + / __ \ / / / // __ \ / // // ___/ + / /_/ // /_/ // /_/ // // // /__ + / .___/ \__,_//_.___//_//_/ \___/ + /_/ + ____ __ _ + / __/__ __ ____ _____ / /_ (_)____ ____ _____ + / /_ / / / // __ \ / ___// __// // __ \ / __ \ / ___/ + / __// /_/ // / / // /__ / /_ / // /_/ // / / /(__ ) + /_/ \__,_//_/ /_/ \___/ \__//_/ \____//_/ /_//____/ + + ========================================================================== */ + + +/* ========================================================================== + same as el_pmem and prints table + ========================================================================== */ + + +int el_opmemory_table +( + const char *file, /* file name where log is printed */ + size_t num, /* line number where log is printed */ + enum el_level level, /* log level to print message with */ + struct el_options *options, /* options defining printing style */ + const void *mem, /* memory location to print */ + size_t mlen /* number of bytes to print */ +) +{ + return el_pmem(file, num, level, &g_options, mem, mlen, 1); +} + + +/* ========================================================================== + same as el_opmemory_table but uses default option object + ========================================================================== */ + + +int el_pmemory_table +( + const char *file, /* file name where log is printed */ + size_t num, /* line number where log is printed */ + enum el_level level, /* log level to print message with */ + const void *mem, /* memory location to print */ + size_t mlen /* number of bytes to print */ +) +{ + return el_opmemory_table(file, num, level, &g_options, mem, mlen); +} + +/* ========================================================================== + Same as el_pmem and prints no table + ========================================================================== */ + + +int el_opmemory +( + const char *file, /* file name where log is printed */ + size_t num, /* line number where log is printed */ + enum el_level level, /* log level to print message with */ + struct el_options *options, /* options defining printing style */ + const void *mem, /* memory location to print */ + size_t mlen /* number of bytes to print */ +) +{ + return el_pmem(file, num, level, options, mem, mlen, 0); +} + + +/* ========================================================================== + same as el_opmemory but uses default option object + ========================================================================== */ + + +int el_pmemory +( + const char *file, /* file name where log is printed */ + size_t num, /* line number where log is printed */ + enum el_level level, /* log level to print message with */ + const void *mem, /* memory location to print */ + size_t mlen /* number of bytes to print */ +) +{ + return el_opmemory(file, num, level, &g_options, mem, mlen); +} diff --git a/tst/test-el-file.c b/tst/test-el-file.c index 5c4b7fd..e9a360a 100644 --- a/tst/test-el-file.c +++ b/tst/test-el-file.c @@ -1602,10 +1602,10 @@ static void file_sync_level(void) mt_fok(el_print(ELD, s1)); mt_fail(file_synced == 0); - mt_fok(el_pmemory(ELI, s8, sizeof(s8))); + mt_fok(el_pmemory_table(ELI, s8, sizeof(s8))); mt_fail(file_synced == 0); - mt_fok(el_pmemory(ELF, s8, sizeof(s8))); + mt_fok(el_pmemory_table(ELF, s8, sizeof(s8))); mt_fail(file_synced == 1); } diff --git a/tst/test-el-pmemory.c b/tst/test-el-pmemory.c index 9ea7203..f2632d8 100644 --- a/tst/test-el-pmemory.c +++ b/tst/test-el-pmemory.c @@ -118,11 +118,7 @@ static void pmemory_one_byte(void) el_pmemory(ELI, &c, sizeof(c)); mt_fok(strcmp(logbuf, -"------ ----------------------------------------------- ----------------\n" -"offset hex ascii\n" -"------ ----------------------------------------------- ----------------\n" -"0x0000 61 a\n" -"------ ----------------------------------------------- ----------------\n")); +"0x0000 61 a\n")); } @@ -137,11 +133,7 @@ static void pmemory_one_line_not_full(void) el_pmemory(ELI, s, strlen(s)); mt_fok(strcmp(logbuf, -"------ ----------------------------------------------- ----------------\n" -"offset hex ascii\n" -"------ ----------------------------------------------- ----------------\n" -"0x0000 74 65 73 74 20 73 74 72 69 6e 67 test string\n" -"------ ----------------------------------------------- ----------------\n")); +"0x0000 74 65 73 74 20 73 74 72 69 6e 67 test string\n")); } @@ -157,11 +149,7 @@ static void pmemory_one_line_full(void) el_pmemory(ELI, s, strlen(s)); mt_fok(strcmp(logbuf, -"------ ----------------------------------------------- ----------------\n" -"offset hex ascii\n" -"------ ----------------------------------------------- ----------------\n" -"0x0000 71 77 65 72 74 79 75 69 6f 70 61 73 64 66 67 68 qwertyuiopasdfgh\n" -"------ ----------------------------------------------- ----------------\n")); +"0x0000 71 77 65 72 74 79 75 69 6f 70 61 73 64 66 67 68 qwertyuiopasdfgh\n")); } @@ -177,12 +165,8 @@ static void pmemory_two_line_not_full(void) el_pmemory(ELI, s, strlen(s)); mt_fok(strcmp(logbuf, -"------ ----------------------------------------------- ----------------\n" -"offset hex ascii\n" -"------ ----------------------------------------------- ----------------\n" "0x0000 66 69 72 73 74 20 6c 69 6e 65 20 69 20 61 6d 20 first line i am \n" -"0x0010 61 6e 64 20 69 20 61 6d 20 32 and i am 2\n" -"------ ----------------------------------------------- ----------------\n")); +"0x0010 61 6e 64 20 69 20 61 6d 20 32 and i am 2\n")); } @@ -198,12 +182,8 @@ static void pmemory_two_line_full(void) el_pmemory(ELI, s, strlen(s)); mt_fok(strcmp(logbuf, -"------ ----------------------------------------------- ----------------\n" -"offset hex ascii\n" -"------ ----------------------------------------------- ----------------\n" "0x0000 66 69 72 73 74 20 6c 69 6e 65 20 69 20 61 6d 20 first line i am \n" -"0x0010 61 6e 64 20 69 20 61 6d 20 32 6e 64 20 6c 69 6e and i am 2nd lin\n" -"------ ----------------------------------------------- ----------------\n")); +"0x0010 61 6e 64 20 69 20 61 6d 20 32 6e 64 20 6c 69 6e and i am 2nd lin\n")); } @@ -218,12 +198,8 @@ static void pmemory_binary_data_with_nulls(void) el_pmemory(ELI, data, sizeof(data)); mt_fok(strcmp(logbuf, -"------ ----------------------------------------------- ----------------\n" -"offset hex ascii\n" -"------ ----------------------------------------------- ----------------\n" "0x0000 05 02 10 50 53 8f ff 3d 00 00 4a ab fc 04 00 fa ...PS..=..J.....\n" -"0x0010 fd fa 7f 80 ....\n" -"------ ----------------------------------------------- ----------------\n")); +"0x0010 fd fa 7f 80 ....\n")); } /* ========================================================================== @@ -245,6 +221,36 @@ static void pmemory_print_ascii_table(void) el_pmemory(ELI, ascii, sizeof(ascii) - 1); mt_fok(strcmp(logbuf, +"0x0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n" +"0x0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................\n" +"0x0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n" +"0x0030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n" +"0x0040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n" +"0x0050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n" +"0x0060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n" +"0x0070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n")); +} + + +/* ========================================================================== + ========================================================================== */ + + +static void pmemory_print_ascii_table_with_table(void) +{ + char ascii[128 + 1]; + int i; + /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + + for (i = 0; i != 0x80; ++i) + { + ascii[i] = (char)i; + } + + ascii[i] = '\0'; + + el_pmemory_table(ELI, ascii, sizeof(ascii) - 1); + mt_fok(strcmp(logbuf, "------ ----------------------------------------------- ----------------\n" "offset hex ascii\n" "------ ----------------------------------------------- ----------------\n" @@ -306,6 +312,7 @@ void el_pmemory_test_group(void) mt_run(pmemory_two_line_full); mt_run(pmemory_binary_data_with_nulls); mt_run(pmemory_print_ascii_table); + mt_run(pmemory_print_ascii_table_with_table); mt_run(pmemory_null_memory); mt_run(pmemory_zero_size); } |