ao-elftohex: Add '-n' option to elide symbol table from output
authorKeith Packard <keithp@keithp.com>
Sat, 24 Sep 2022 22:53:04 +0000 (15:53 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 24 Sep 2022 22:53:04 +0000 (15:53 -0700)
The symbol table is a non-standard Altus Metrum hex file extension;
add this option to allow use with standard hex file tools.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-elftohex/ao-elftohex.1
ao-tools/ao-elftohex/ao-elftohex.c

index 0c1666c8cf2849fc04dabbd603554ce34fc14982..859d26785fe06215d790af361462b009d974563b 100644 (file)
@@ -34,5 +34,10 @@ This specifies the output file (default is stdout)
 .TP
 \--verbose
 Dumps some debug information.
+.TP
+\--nosym
+Excluded symbol table information from the resulting file. This
+information is a non-standard extension supported by the Altus Metrum
+tools.
 .SH AUTHOR
 Keith Packard
index 7afd29c321ff5bc3b0e7d29d265c0c155cc605ee..a31f9656f6cd80a88d11f6eded1d9b4f008eef68 100644 (file)
@@ -27,6 +27,7 @@
 static const struct option options[] = {
        { .name = "verbose", .has_arg = 1, .val = 'v' },
        { .name = "output", .has_arg = 1, .val = 'o' },
+       { .name = "nosym", .has_arg = 0, .val = 'n' },
        { 0, 0, 0, 0},
 };
 
@@ -53,13 +54,14 @@ main (int argc, char **argv)
        char                    *input = NULL;
        char                    *output = NULL;
        struct ao_hex_image     *full_image = NULL;
-       struct ao_sym           *file_symbols;
+       struct ao_sym           *file_symbols = NULL;
        int                     num_file_symbols;
        FILE                    *file;
        int                     c;
        int                     i;
+       int                     nosym = 0;
 
-       while ((c = getopt_long(argc, argv, "v:o:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "nv:o:", options, NULL)) != -1) {
                switch (c) {
                case 'o':
                        output = optarg;
@@ -67,6 +69,9 @@ main (int argc, char **argv)
                case 'v':
                        ao_verbose = (int) strtol(optarg, NULL, 0);
                        break;
+               case 'n':
+                       nosym = 1;
+                       break;
                default:
                        usage(argv[0]);
                        break;
@@ -81,6 +86,8 @@ main (int argc, char **argv)
 
                input = argv[i];
 
+               free(file_symbols);
+               num_file_symbols = 0;
                if (ends_with (input, ".ihx"))
                        image = ao_hex_load(input, &file_symbols, &num_file_symbols);
                else
@@ -91,6 +98,12 @@ main (int argc, char **argv)
                        usage(argv[0]);
                }
 
+               if (nosym) {
+                       free(file_symbols);
+                       file_symbols = NULL;
+                       num_file_symbols = 0;
+               }
+
                if (full_image) {
                        full_image = ao_hex_image_cat(full_image, image);
                        if (!full_image) {