From c8f8dc0ea69a404b407f84cbccc25c1af7804836 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Wed, 9 Sep 2020 23:21:59 +0200
Subject: Finalized the export of read functions on demand.

---
 tools/d2c/coder.c |  4 ++--
 tools/d2c/coder.h |  1 +
 tools/d2c/d2c.c   | 10 ++++++++--
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/d2c/coder.c b/tools/d2c/coder.c
index a8b6fa9..be68cc5 100644
--- a/tools/d2c/coder.c
+++ b/tools/d2c/coder.c
@@ -1101,7 +1101,7 @@ static bool output_coder_raw(const rented_coder *coder, const output_info *info,
 
     /* Désassemblage : déclaration */
 
-    if (0 /* TODO : export seulement */)
+    if (info->export)
     {
         dprintf(hfd, "/* Décode une forme d'instruction de type '%s'. */\n", coder->ins);
 
@@ -1141,7 +1141,7 @@ static bool output_coder_raw(const rented_coder *coder, const output_info *info,
 
     dprintf(cfd, "\n");
 
-    if (1 /* TODO : si pas exportée */)
+    if (!info->export)
         dprintf(cfd, "static ");
 
     dprintf(cfd, "GArchInstruction *");
diff --git a/tools/d2c/coder.h b/tools/d2c/coder.h
index 1b4c0c5..a17d5ad 100644
--- a/tools/d2c/coder.h
+++ b/tools/d2c/coder.h
@@ -118,6 +118,7 @@ typedef struct _output_info
     const char *id_prefix;                  /* Préfixe pour les constantes */
     int id_len;                             /* Largeur des identifiants    */
 
+    bool export;                            /* Exportation dans les entêtes*/
     size_t filename_reuse;                  /* Taille d'une extention      */
 
 } output_info;
diff --git a/tools/d2c/d2c.c b/tools/d2c/d2c.c
index fddee6a..fbf401e 100644
--- a/tools/d2c/d2c.c
+++ b/tools/d2c/d2c.c
@@ -93,7 +93,8 @@ static void show_usage(const char *argv0)
 
     printf("\n");
 
-    printf("\t--filename-reuse <length>\t\tSet the length of filename to include in identifiers (default = 0).\n");
+    printf("\t--export\t\t\tDefine if read functions have to be exported to external headers (not by default).\n");
+    printf("\t--filename-reuse <length>\tSet the length of filename to include in identifiers (default = 0).\n");
 
     printf("\n");
 
@@ -153,7 +154,8 @@ int main(int argc, char **argv)
         { "id-prefix",      required_argument,  NULL,   0x100 },
         { "id-expected",    required_argument,  NULL,   0x101 },
 
-        { "filename-reuse", required_argument,  NULL,   0x200 },
+        { "export",         no_argument,        NULL,   0x200 },
+        { "filename-reuse", required_argument,  NULL,   0x201 },
 
         { "op-prefix",      required_argument,  NULL,   0x300 },
 
@@ -254,6 +256,10 @@ int main(int argc, char **argv)
                 break;
 
             case 0x200:
+                info.export = true;
+                break;
+
+            case 0x201:
                 info.filename_reuse = strtoul(optarg, NULL, 10);
                 break;
 
-- 
cgit v0.11.2-87-g4458