Rename source files and improve readability 34/24134/1
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 13 Sep 2019 14:46:39 +0000 (16:46 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 28 Feb 2020 11:19:23 +0000 (12:19 +0100)
Also rename wgtpkg-installer tools as wgtpkg-install.
Shorter and obvious.

Bug-AGL: SPEC-2840

Change-Id: Ifed072bfef488700807613dd61875a30a4041d7a
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
README.md
docs/2.1-widgets.md
src/CMakeLists.txt
src/README.md
src/main-wgtpkg-info.c [moved from src/wgtpkg-info.c with 100% similarity]
src/main-wgtpkg-install.c [moved from src/wgtpkg-installer.c with 98% similarity]
src/main-wgtpkg-pack.c [moved from src/wgtpkg-pack.c with 100% similarity]
src/main-wgtpkg-sign.c [moved from src/wgtpkg-sign.c with 84% similarity]

index 49993bf..9c040f5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -74,7 +74,7 @@ The installed programs are:
 - ***wgtpkg-info***: command line tool to display
   information about a widget file.
 
 - ***wgtpkg-info***: command line tool to display
   information about a widget file.
 
-- ***wgtpkg-installer***: command line tool to
+- ***wgtpkg-install***: command line tool to
   install a widget file.
 
 - ***wgtpkg-pack***: command line tool to create
   install a widget file.
 
 - ***wgtpkg-pack***: command line tool to create
@@ -199,7 +199,7 @@ The current version of afm allows to install widgets
 from local files (either pre-installed or downloaded).
 
 To install a widget, you can use either the program
 from local files (either pre-installed or downloaded).
 
 To install a widget, you can use either the program
-***wgtpkg-installer*** while being the framework user.
+***wgtpkg-install*** while being the framework user.
 
 TO BE CONTINUED
 
 
 TO BE CONTINUED
 
index f799133..f41e2d9 100644 (file)
@@ -6,7 +6,7 @@ These tools are:
 - ***wgtpkg-info***: command line tool to display
   informations about a widget file.
 
 - ***wgtpkg-info***: command line tool to display
   informations about a widget file.
 
-- ***wgtpkg-installer***: command line tool to
+- ***wgtpkg-install***: command line tool to
   install a widget file.
 
 - ***wgtpkg-pack***: command line tool to create
   install a widget file.
 
 - ***wgtpkg-pack***: command line tool to create
index 0fde569..3a94d0d 100644 (file)
@@ -148,19 +148,19 @@ add_library(afm STATIC
 
 MESSAGE(STATUS "Creating packaging tools")
 
 
 MESSAGE(STATUS "Creating packaging tools")
 
-add_executable(wgtpkg-sign wgtpkg-sign.c)
+add_executable(wgtpkg-sign main-wgtpkg-sign.c)
 target_link_libraries(wgtpkg-sign wgtpkg utils)
 
 target_link_libraries(wgtpkg-sign wgtpkg utils)
 
-add_executable(wgtpkg-pack wgtpkg-pack.c)
+add_executable(wgtpkg-pack main-wgtpkg-pack.c)
 target_link_libraries(wgtpkg-pack wgtpkg utils)
 
 target_link_libraries(wgtpkg-pack wgtpkg utils)
 
-add_executable(wgtpkg-info wgtpkg-info.c)
+add_executable(wgtpkg-info main-wgtpkg-info.c)
 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
 
 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
 
-add_executable(wgtpkg-installer wgtpkg-installer.c)
-target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
+add_executable(wgtpkg-install main-wgtpkg-install.c)
+target_link_libraries(wgtpkg-install wgtpkg wgt secwrp utils)
 
 
-install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-install DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 ###########################################################################
 # dynamic tool daemons
 
 ###########################################################################
 # dynamic tool daemons
index df62fe3..49c48e9 100644 (file)
@@ -53,13 +53,13 @@ widget package management
 wgtpkg-certs.c
 wgtpkg-digsig.c
 wgtpkg-files.c
 wgtpkg-certs.c
 wgtpkg-digsig.c
 wgtpkg-files.c
-wgtpkg-info.c
+main-wgtpkg-info.c
 wgtpkg-install.c
 wgtpkg-install.c
-wgtpkg-installer.c
+main-wgtpkg-instal.c
 wgtpkg-mustach.c
 wgtpkg-mustach.c
-wgtpkg-pack.c
+main-wgtpkg-pack.c
 wgtpkg-permissions.c
 wgtpkg-permissions.c
-wgtpkg-sign.c
+main-wgtpkg-sign.c
 wgtpkg-uninstall.c
 wgtpkg-unit.c
 wgtpkg-workdir.c
 wgtpkg-uninstall.c
 wgtpkg-unit.c
 wgtpkg-workdir.c
similarity index 100%
rename from src/wgtpkg-info.c
rename to src/main-wgtpkg-info.c
similarity index 98%
rename from src/wgtpkg-installer.c
rename to src/main-wgtpkg-install.c
index a19c21a..7f6f187 100644 (file)
@@ -35,7 +35,7 @@
 #include "wgt-info.h"
 #include "wgtpkg-install.h"
 
 #include "wgt-info.h"
 #include "wgtpkg-install.h"
 
-static const char appname[] = "wgtpkg-installer";
+static const char appname[] = "wgtpkg-install";
 static const char *root;
 static int force;
 
 static const char *root;
 static int force;
 
similarity index 100%
rename from src/wgtpkg-pack.c
rename to src/main-wgtpkg-pack.c
similarity index 84%
rename from src/wgtpkg-sign.c
rename to src/main-wgtpkg-sign.c
index 4e2adf2..d40ddaf 100644 (file)
@@ -60,6 +60,16 @@ static unsigned int get_number(const char *value)
        return (unsigned int)val;
 }
 
        return (unsigned int)val;
 }
 
+static void make_realpath(char **x)
+{
+       char *p = realpath(*x, NULL);
+       if (p == NULL) {
+               ERROR("realpath failed for %s", *x);
+               exit(1);
+       }
+       *x = p;
+}
+
 static void version()
 {
        printf(
 static void version()
 {
        printf(
@@ -92,25 +102,27 @@ static void usage()
        );
 }
 
        );
 }
 
-static struct option options[] = {
-       { "key",         required_argument, NULL, 'k' },
+static struct option options_l[] = {
+       { "author",      no_argument,       NULL, 'a' },
        { "certificate", required_argument, NULL, 'c' },
        { "distributor", required_argument, NULL, 'd' },
        { "certificate", required_argument, NULL, 'c' },
        { "distributor", required_argument, NULL, 'd' },
-       { "author",      no_argument,       NULL, 'a' },
        { "force",       no_argument,       NULL, 'f' },
        { "help",        no_argument,       NULL, 'h' },
        { "force",       no_argument,       NULL, 'f' },
        { "help",        no_argument,       NULL, 'h' },
+       { "key",         required_argument, NULL, 'k' },
        { "quiet",       no_argument,       NULL, 'q' },
        { "verbose",     no_argument,       NULL, 'v' },
        { "version",     no_argument,       NULL, 'V' },
        { NULL, 0, NULL, 0 }
 };
 
        { "quiet",       no_argument,       NULL, 'q' },
        { "verbose",     no_argument,       NULL, 'v' },
        { "version",     no_argument,       NULL, 'V' },
        { NULL, 0, NULL, 0 }
 };
 
+static const char options_s[] = "ac:d:fhk:qvV";
+
 /* install the widgets of the list */
 int main(int ac, char **av)
 {
        int i, force, ncert, author;
        unsigned int number;
 /* install the widgets of the list */
 int main(int ac, char **av)
 {
        int i, force, ncert, author;
        unsigned int number;
-       char *keyfile, *certfiles[MAXCERT+1], *directory, **x;
+       char *keyfile, *certfiles[MAXCERT+1], *directory;
        struct stat s;
 
        LOGUSER(appname);
        struct stat s;
 
        LOGUSER(appname);
@@ -119,7 +131,7 @@ int main(int ac, char **av)
        number = UINT_MAX;
        keyfile = directory = NULL;
        for (;;) {
        number = UINT_MAX;
        keyfile = directory = NULL;
        for (;;) {
-               i = getopt_long(ac, av, "hfqvVak:c:d:", options, NULL);
+               i = getopt_long(ac, av, options_s, options_l, NULL);
                if (i < 0)
                        break;
                switch (i) {
                if (i < 0)
                        break;
                switch (i) {
@@ -129,13 +141,33 @@ int main(int ac, char **av)
                                return 1;
                        }
                        certfiles[ncert++] = optarg;
                                return 1;
                        }
                        certfiles[ncert++] = optarg;
-                       continue;
-               case 'k': x = &keyfile; break;
-               case 'd': number = get_number(optarg); continue;
-               case 'f': force = 1; continue;
-               case 'a': author = 1; continue;
-               case 'h': usage(); return 0;
-               case 'V': version(); return 0;
+                       break;
+               case 'k':
+                       if (keyfile) {
+                               ERROR("key already set");
+                               return 1;
+                       }
+                       keyfile = optarg;
+                       break;
+               case 'd':
+                       if (number != UINT_MAX) {
+                               ERROR("number already set");
+                               return 1;
+                       }
+                       number = get_number(optarg);
+                       break;
+               case 'f':
+                       force = 1;
+                       break;
+               case 'a':
+                       author = 1;
+                       break;
+               case 'h':
+                       usage();
+                       return 0;
+               case 'V':
+                       version();
+                       return 0;
                case 'q':
                        if (verbosity)
                                verbosity--;
                case 'q':
                        if (verbosity)
                                verbosity--;
@@ -150,11 +182,6 @@ int main(int ac, char **av)
                        ERROR("unrecognized option");
                        return 1;
                }
                        ERROR("unrecognized option");
                        return 1;
                }
-               if (*x != NULL) {
-                       ERROR("option set twice");
-                       return 1;
-               }
-               *x = optarg;
        }
 
        /* remaining arguments and final checks */
        }
 
        /* remaining arguments and final checks */
@@ -187,7 +214,7 @@ int main(int ac, char **av)
                ERROR("can't access private key %s", keyfile);
                return 1;
        }
                ERROR("can't access private key %s", keyfile);
                return 1;
        }
-       for(i = 0 ; i < ncert ; i++) 
+       for(i = 0 ; i < ncert ; i++)
                if (access(certfiles[i], R_OK) != 0) {
                        ERROR("can't access certificate %s", certfiles[i]);
                        return 1;
                if (access(certfiles[i], R_OK) != 0) {
                        ERROR("can't access certificate %s", certfiles[i]);
                        return 1;
@@ -197,13 +224,10 @@ int main(int ac, char **av)
        if (xmlsec_init())
                return 1;
 
        if (xmlsec_init())
                return 1;
 
-
        /* compute absolutes paths */
        /* compute absolutes paths */
-#define rp(x) do { char *p = realpath(x, NULL); if (p != NULL) x = p; else { ERROR("realpath failed for %s",x); return 1; } } while(0)
-       rp(keyfile);
-       for(i = 0 ; i < ncert ; i++) 
-               rp(certfiles[i]);
-#undef rp
+       make_realpath(&keyfile);
+       for(i = 0 ; i < ncert ; i++)
+               make_realpath(&certfiles[i]);
 
        /* set and enter the workdir */
        if (set_workdir(directory, 0))
 
        /* set and enter the workdir */
        if (set_workdir(directory, 0))