From 0083ad3751cd2b088b5c5d0dea727671ea2a3cca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Fri, 13 Sep 2019 16:46:39 +0200 Subject: [PATCH] Rename source files and improve readability MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also rename wgtpkg-installer tools as wgtpkg-install. Shorter and obvious. Bug-AGL: SPEC-2840 Change-Id: Ifed072bfef488700807613dd61875a30a4041d7a Signed-off-by: José Bollo --- README.md | 4 +- docs/2.1-widgets.md | 2 +- src/CMakeLists.txt | 12 ++-- src/README.md | 8 +-- src/{wgtpkg-info.c => main-wgtpkg-info.c} | 0 src/{wgtpkg-installer.c => main-wgtpkg-install.c} | 2 +- src/{wgtpkg-pack.c => main-wgtpkg-pack.c} | 0 src/{wgtpkg-sign.c => main-wgtpkg-sign.c} | 72 +++++++++++++++-------- 8 files changed, 62 insertions(+), 38 deletions(-) rename src/{wgtpkg-info.c => main-wgtpkg-info.c} (100%) rename src/{wgtpkg-installer.c => main-wgtpkg-install.c} (98%) rename src/{wgtpkg-pack.c => main-wgtpkg-pack.c} (100%) rename src/{wgtpkg-sign.c => main-wgtpkg-sign.c} (84%) diff --git a/README.md b/README.md index 49993bf..9c040f5 100644 --- 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-installer***: command line tool to +- ***wgtpkg-install***: command line tool to 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 -***wgtpkg-installer*** while being the framework user. +***wgtpkg-install*** while being the framework user. TO BE CONTINUED diff --git a/docs/2.1-widgets.md b/docs/2.1-widgets.md index f799133..f41e2d9 100644 --- a/docs/2.1-widgets.md +++ b/docs/2.1-widgets.md @@ -6,7 +6,7 @@ These tools are: - ***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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0fde569..3a94d0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,19 +148,19 @@ add_library(afm STATIC 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) -add_executable(wgtpkg-pack wgtpkg-pack.c) +add_executable(wgtpkg-pack main-wgtpkg-pack.c) 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) -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 diff --git a/src/README.md b/src/README.md index df62fe3..49c48e9 100644 --- a/src/README.md +++ b/src/README.md @@ -53,13 +53,13 @@ widget package management wgtpkg-certs.c wgtpkg-digsig.c wgtpkg-files.c -wgtpkg-info.c +main-wgtpkg-info.c wgtpkg-install.c -wgtpkg-installer.c +main-wgtpkg-instal.c wgtpkg-mustach.c -wgtpkg-pack.c +main-wgtpkg-pack.c wgtpkg-permissions.c -wgtpkg-sign.c +main-wgtpkg-sign.c wgtpkg-uninstall.c wgtpkg-unit.c wgtpkg-workdir.c diff --git a/src/wgtpkg-info.c b/src/main-wgtpkg-info.c similarity index 100% rename from src/wgtpkg-info.c rename to src/main-wgtpkg-info.c diff --git a/src/wgtpkg-installer.c b/src/main-wgtpkg-install.c similarity index 98% rename from src/wgtpkg-installer.c rename to src/main-wgtpkg-install.c index a19c21a..7f6f187 100644 --- a/src/wgtpkg-installer.c +++ b/src/main-wgtpkg-install.c @@ -35,7 +35,7 @@ #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; diff --git a/src/wgtpkg-pack.c b/src/main-wgtpkg-pack.c similarity index 100% rename from src/wgtpkg-pack.c rename to src/main-wgtpkg-pack.c diff --git a/src/wgtpkg-sign.c b/src/main-wgtpkg-sign.c similarity index 84% rename from src/wgtpkg-sign.c rename to src/main-wgtpkg-sign.c index 4e2adf2..d40ddaf 100644 --- a/src/wgtpkg-sign.c +++ b/src/main-wgtpkg-sign.c @@ -60,6 +60,16 @@ static unsigned int get_number(const char *value) 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( @@ -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' }, - { "author", no_argument, NULL, 'a' }, { "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 } }; +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; - char *keyfile, *certfiles[MAXCERT+1], *directory, **x; + char *keyfile, *certfiles[MAXCERT+1], *directory; struct stat s; LOGUSER(appname); @@ -119,7 +131,7 @@ int main(int ac, char **av) 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) { @@ -129,13 +141,33 @@ int main(int ac, char **av) 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--; @@ -150,11 +182,6 @@ int main(int ac, char **av) ERROR("unrecognized option"); return 1; } - if (*x != NULL) { - ERROR("option set twice"); - return 1; - } - *x = optarg; } /* 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; } - 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; @@ -197,13 +224,10 @@ int main(int ac, char **av) if (xmlsec_init()) return 1; - /* 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)) -- 2.16.6