From 78b05690e76e4e2e89b97dcb0c0070091607cec8 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 7 Mar 2019 19:28:46 +0100 Subject: [PATCH] Update README --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec56759b..bf456a9b 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,44 @@ the minimum information of its interface needed. We can also see in this example so the container ARRAY provides also a macro to define the oplist of the array itself. This is true for -all containers and this allows to define proper recursive container. +all containers and this allows to define proper recursive container like in this example: + + #include + #include "m-array.h" + #include "m-tuple.h" + #include "m-dict.h" + #include "m-string.h" + + TUPLE_DEF2(symbol, (offset, long), (value, long)) + #define M_OPL_symbol_t() TUPLE_OPLIST(symbol, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST) + + ARRAY_DEF(array_symbol, symbol_t) + #define M_OPL_array_symbol_t() ARRAY_OPLIST(array_symbol, M_OPL_symbol_t()) + + DICT_DEF2(sections, string_t, array_symbol_t) + #define M_OPL_sections_t() DICT_OPLIST(sections, STRING_OPLIST, M_OPL_array_symbol_t()) + + int main(int argc, const char *argv[]) + { + if (argc < 2) abort(); + FILE *f = fopen(argv[1], "rt"); + if (!f) abort(); + M_LET(sc, sections_t) { + sections_in_str(sc, f); + array_symbol_t *a = sections_get(sc, STRING_CTE(".text")); + if (a == NULL) { + printf("There is no .text section."); + } else { + printf("Section .text is :"); + array_symbol_out_str(stdout, *a); + printf("\n"); + } + } + return 0; + } + +This example reads the data from a file +and outputs the .text section if it finds it on the terminal. Other examples are available in the example folder.