libopkg: add option to strip ABI versions from listed names
authorDaniel Golle <daniel@makrotopia.org>
Sun, 14 Mar 2021 22:28:05 +0000 (22:28 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 14 Mar 2021 22:50:41 +0000 (22:50 +0000)
Listing packages without the ABI versions appended to their names is
needed in some situations. Add a new command line option '--strip-abi'
for that which affects the 'list' and 'list-installed' command.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
libopkg/opkg_cmd.c
libopkg/opkg_conf.c
libopkg/opkg_conf.h
src/opkg-cl.c

index 83e345e527856ec5eebdcd4fb76284f8154839e3..7a9ee37006e64e77d3f2799cfef02d9d861c9965 100644 (file)
@@ -45,7 +45,23 @@ static void print_pkg(pkg_t * pkg)
 {
        char *version = pkg_version_str_alloc(pkg);
        char *description = pkg_get_string(pkg, PKG_DESCRIPTION);
-       printf("%s - %s", pkg->name, version);
+       const char *abiver;
+       char *tmp, *tmpname = NULL;
+
+       if (conf->strip_abi &&
+           (abiver = pkg_get_string(pkg, PKG_ABIVERSION)) &&
+           (strlen(pkg->name) > strlen(abiver))) {
+               tmpname = strdup(pkg->name);
+               tmp = &tmpname[strlen(tmpname) - strlen(abiver)];
+               if (!strncmp(abiver, tmp, strlen(abiver)))
+                       *tmp = '\0';
+       };
+
+       printf("%s - %s", tmpname?tmpname:pkg->name, version);
+
+       if (tmpname)
+               free(tmpname);
+
        if (conf->size)
                printf(" - %lu", (unsigned long) pkg_get_int(pkg, PKG_SIZE));
        if (description)
@@ -578,7 +594,8 @@ static void opkg_list_find_cmd_cb(pkg_t *pkg, void *priv)
        char *description = pkg_get_string(pkg, PKG_DESCRIPTION);
        char *version = pkg_version_str_alloc(pkg);
        struct opkg_list_find_cmd_item *item;
-       char *nameptr, *versionptr, *descriptionptr;
+       char *nameptr, *versionptr, *descriptionptr, *tmp;
+       const char *abiver;
        int i, found = 0;
 
        /* if we have package name or pattern and pkg does not match, then skip it */
@@ -603,6 +620,15 @@ static void opkg_list_find_cmd_cb(pkg_t *pkg, void *priv)
                                &descriptionptr, description ? strlen(description) + 1 : 0);
 
                item->name = strcpy(nameptr, pkg->name);
+
+               if (conf->strip_abi &&
+                   (abiver = pkg_get_string(pkg, PKG_ABIVERSION)) &&
+                   (strlen(item->name) > strlen(abiver))) {
+                       tmp = &item->name[strlen(item->name) - strlen(abiver)];
+                       if (!strncmp(abiver, tmp, strlen(abiver)))
+                               *tmp = '\0';
+               };
+
                item->size = pkg_get_int(pkg, PKG_SIZE);
                item->version = strcpy(versionptr, version);
                item->description = description ? strcpy(descriptionptr, description) : NULL;
index 5fe0be9363c4bce6fd1d93c60ccdef99452da33e..e36f66bb79dd639e1c6f7554b6ba6de392a31cbf 100644 (file)
@@ -70,6 +70,7 @@ opkg_option_t options[] = {
        {"proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user},
        {"query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all},
        {"size", OPKG_OPT_TYPE_BOOL, &_conf.size},
+       {"strip_abi", OPKG_OPT_TYPE_BOOL, &_conf.strip_abi},
        {"tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir},
        {"verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity},
        {"verify_program", OPKG_OPT_TYPE_STRING, &_conf.verify_program},
index d38fd735905bf034d29b3c83a07688f897d3f2e2..cd69cebbb11abecf1fb8548509c0f0504c1c694d 100644 (file)
@@ -89,6 +89,7 @@ struct opkg_conf {
        char *verify_program;
        int noaction;
        int size;
+       int strip_abi;
        int download_only;
        char *cache;
 
index 01c6e94627af927a59bd63542b9f65e670d64ed5..793690d252c82509ed7aad3d07126a01e9a99fff 100644 (file)
@@ -55,6 +55,7 @@ enum {
        ARGS_OPT_NO_CHECK_CERTIFICATE,
        ARGS_OPT_VERIFY_PROGRAM,
        ARGS_OPT_SIZE,
+       ARGS_OPT_STRIP_ABI,
 };
 
 static struct option long_options[] = {
@@ -104,6 +105,8 @@ static struct option long_options[] = {
        {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH},
        {"add-dest", 1, 0, ARGS_OPT_ADD_DEST},
        {"size", 0, 0, ARGS_OPT_SIZE},
+       {"strip-abi", 0, 0, ARGS_OPT_STRIP_ABI},
+       {"strip_abi", 0, 0, ARGS_OPT_STRIP_ABI},
        {"test", 0, 0, ARGS_OPT_NOACTION},
        {"tmp-dir", 1, 0, 't'},
        {"tmp_dir", 1, 0, 't'},
@@ -238,6 +241,9 @@ static int args_parse(int argc, char *argv[])
                case ARGS_OPT_VERIFY_PROGRAM:
                        conf->verify_program = xstrdup(optarg);
                        break;
+               case ARGS_OPT_STRIP_ABI:
+                       conf->strip_abi = 1;
+                       break;
                case ':':
                        parse_err = -1;
                        break;
@@ -357,6 +363,8 @@ static void usage()
            ("\t--nocase                Perform case insensitive pattern matching\n");
        printf
            ("\t--size                  Print package size when listing available packages\n");
+       printf
+           ("\t--strip-abi             Print package name without appended ABI version\n");
        printf("\t--force-removal-of-dependent-packages\n");
        printf("\t                      Remove package and all dependencies\n");
        printf("\t--autoremove          Remove packages that were installed\n");