libopkg: pkg_hash: prefer to-be-installed packages
[project/opkg-lede.git] / libopkg / opkg_cmd.c
index 83e345e527856ec5eebdcd4fb76284f8154839e3..b6c45f523cdd06277cb35c87eef7100046c2c5a7 100644 (file)
 #include "opkg_configure.h"
 #include "xsystem.h"
 
+int opkg_cli_argc = 0;
+char **opkg_cli_argv = NULL;
+
 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 +597,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 +623,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;
@@ -1401,5 +1430,7 @@ opkg_cmd_t *opkg_cmd_find(const char *name)
 
 int opkg_cmd_exec(opkg_cmd_t * cmd, int argc, const char **argv)
 {
+       opkg_cli_argc = argc;
+       opkg_cli_argv = argv;
        return (cmd->fun) (argc, argv);
 }