From 6fc8f242005f42f3cb6a810df7b1eb5524a861fb Mon Sep 17 00:00:00 2001
From: Ralf Habacker <ralf.habacker@freenet.de>
Date: Thu, 24 Feb 2022 23:40:08 +0100
Subject: [PATCH] Refactor gsa tool to use GWEN_Funcs_xxx functions

---
 po/de.po              | 53 +++++++++++-------------------------
 tools/gsa/Makefile.am |  2 +-
 tools/gsa/main.c      | 63 ++++++++++++++-----------------------------
 3 files changed, 36 insertions(+), 82 deletions(-)

diff --git a/po/de.po b/po/de.po
index 2f690ee5..4850d45f 100644
--- a/po/de.po
+++ b/po/de.po
@@ -5,19 +5,20 @@
 #
 # Martin Preuss <martin@libchipcard.de>, 2004, 2005, 2007.
 # Martin Preuss <martin@aqbanking.de>, 2010.
+# Ralf Habacker <ralf.habacker@freenet.de>, 2022.
 msgid ""
 msgstr ""
 "Project-Id-Version: gwenhywfar\n"
 "Report-Msgid-Bugs-To: aqbanking-user@lists.aqbanking.de\n"
 "POT-Creation-Date: 2022-08-10 19:57+0200\n"
 "PO-Revision-Date: 2021-02-16 21:00+0100\n"
-"Last-Translator: Christian Stimming <christian@cstimming.de>\n"
 "Language-Team: Deutsch <kde-i18n-de@kde.org>\n"
+"Last-Translator: Ralf Habacker <ralf.habacker@freenet.de>\n"
 "Language: de_DE\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
-"X-Generator: Lokalize 1.0\n"
+"X-Generator: Lokalize 20.04.2\n"
 "Plural-Forms: nplurals=2; plural=n != 1;\n"
 "X-Poedit-Basepath: /home/martin/projekte/c/gwenhywfar/git\n"
 
@@ -1188,45 +1189,21 @@ msgstr ""
 msgid "GWEN's Simple Archiver"
 msgstr "GWEN's Simple Archiver - Einfache Archiverstellung"
 
-#: tools/gsa/main.c:150
-msgid ""
-"  create:\n"
-"    This command creates an archive file\n"
-"\n"
-msgstr ""
-"  create:\n"
-"    Dieser Befehl erzeugt eine Archiv-Datei\n"
-"\n"
+#: tools/gsa/main.c:91
+msgid "This command creates an archive file"
+msgstr "Erzeugen einer Archiv-Datei"
 
-#: tools/gsa/main.c:154
-msgid ""
-"  add:\n"
-"    Add files and folders to an archive file\n"
-"\n"
-msgstr ""
-"  add:\n"
-"    Dateien und Ordner zu einer Archiv-Datei hinzufügen\n"
-"\n"
+#: tools/gsa/main.c:92
+msgid "Add files and folders to an archive file"
+msgstr "Dateien und Ordner zu einer Archiv-Datei hinzufügen"
 
-#: tools/gsa/main.c:157
-msgid ""
-"  list:\n"
-"    List files and folders in an archive file\n"
-"\n"
-msgstr ""
-"  list:\n"
-"    Die Dateien und Ordner aus einer Archiv-Datei anzeigen\n"
-"\n"
+#: tools/gsa/main.c:93
+msgid "List files and folders in an archive file"
+msgstr "Dateien und Ordner aus einer Archiv-Datei anzeigen"
 
-#: tools/gsa/main.c:161
-msgid ""
-"  check:\n"
-"    Check integrity of files and folders in an archive file\n"
-"\n"
-msgstr ""
-"  check:\n"
-"    Die Integrität der Dateien und Ordner einer Archiv-Datei überprüfen\n"
-"\n"
+#: tools/gsa/main.c:94
+msgid "Check integrity of files and folders in an archive file"
+msgstr "Integrität der Dateien und Ordner einer Archiv-Datei überprüfen"
 
 #. type: Attribute 'text' of: <dialog><widget><widget><widget>
 #: src/gui/dlg_input.dlg:7
diff --git a/tools/gsa/Makefile.am b/tools/gsa/Makefile.am
index da6fce58..e005002f 100644
--- a/tools/gsa/Makefile.am
+++ b/tools/gsa/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS= -I$(top_builddir) -I$(top_srcdir) -I$(gwenhywfar_symlinkdir)
+AM_CPPFLAGS= -I$(top_builddir) -I$(top_srcdir) -I$(gwenhywfar_symlinkdir) -I$(top_srcdir)/src/base
 
 #EXTRA_DIST=
 
diff --git a/tools/gsa/main.c b/tools/gsa/main.c
index 8264a138..e4418703 100644
--- a/tools/gsa/main.c
+++ b/tools/gsa/main.c
@@ -17,6 +17,7 @@
 #include <gwenhywfar/debug.h>
 #include <gwenhywfar/cgui.h>
 
+#include "funcs.h"
 #include "globals.h"
 
 
@@ -86,6 +87,19 @@ int main(int argc, char **argv)
       "Show this help screen"       /* long description */
     }
   };
+  const GWEN_FUNCS funcs[]= {
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS_HELP("create", createArchive, I18N("This command creates an archive file")),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS_HELP("add", add2Archive, I18N("Add files and folders to an archive file")),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS_HELP("list", listArchive, I18N("List files and folders in an archive file")),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS_HELP("check", checkArchive, I18N("Check integrity of files and folders in an archive file")),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS("extract", extractArchive),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS("sign", signArchive),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS("verify", verifyArchive),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS("mkkey", mkArchiveKey),
+    GWEN_FUNCS_ENTRY_DB_NODE_ARGS("rfi", releaseFillIn),
+    GWEN_FUNCS_ENTRY_END(),
+  };
+  const GWEN_FUNCS *func;
 
   err=GWEN_Init();
   if (err) {
@@ -144,25 +158,11 @@ int main(int argc, char **argv)
       fprintf(stderr, "ERROR: Could not create help string\n");
       return 1;
     }
-    GWEN_Buffer_AppendString(ubuf,
-                             I18N("\nCommands:\n\n"));
-    GWEN_Buffer_AppendString(ubuf,
-                             I18N("  create:\n"
-                                  "    This command creates an archive file"
-                                  "\n\n"));
-    GWEN_Buffer_AppendString(ubuf,
-                             I18N("  add:\n"
-                                  "    Add files and folders to an archive file\n\n"));
-    GWEN_Buffer_AppendString(ubuf,
-                             I18N("  list:\n"
-                                  "    List files and folders in an archive file\n\n"));
-
-    GWEN_Buffer_AppendString(ubuf,
-                             I18N("  check:\n"
-                                  "    Check integrity of files and folders in an archive file\n\n"));
-
     fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
     GWEN_Buffer_free(ubuf);
+
+    fprintf(stderr, "%s\n", I18N("\nCommands:\n\n"));
+    GWEN_Funcs_Usage_With_Help(funcs);
     return 0;
   }
   if (rv) {
@@ -176,32 +176,9 @@ int main(int argc, char **argv)
     return 1;
   }
 
-  if (strcasecmp(cmd, "create")==0) {
-    rv=createArchive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "add")==0) {
-    rv=add2Archive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "list")==0) {
-    rv=listArchive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "check")==0) {
-    rv=checkArchive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "extract")==0) {
-    rv=extractArchive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "sign")==0) {
-    rv=signArchive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "verify")==0) {
-    rv=verifyArchive(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "mkkey")==0) {
-    rv=mkArchiveKey(db, argc, argv);
-  }
-  else if (strcasecmp(cmd, "rfi")==0) {
-    rv=releaseFillIn(db, argc, argv);
+  func=GWEN_Funcs_Find(funcs, cmd);
+  if (func!=NULL) {
+    rv=GWEN_Funcs_Call_DB_NODE_Args(func, db, argc, argv);
   }
   else {
     fprintf(stderr, "ERROR: Unknown command \"%s\".\n", cmd);
-- 
2.34.1

