parent
e34d2ed5fd
commit
3197d0f64a
51
src/search.c
51
src/search.c
|
@ -18,24 +18,32 @@
|
||||||
|
|
||||||
struct search_ctx {
|
struct search_ctx {
|
||||||
int (*match)(struct apk_package *pkg, const char *str);
|
int (*match)(struct apk_package *pkg, const char *str);
|
||||||
int (*print)(struct apk_package *pkg);
|
void (*print_result)(struct search_ctx *ctx, struct apk_package *pkg);
|
||||||
|
void (*print_package)(struct search_ctx *ctx, struct apk_package *pkg);
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int print_match(struct apk_package *pkg)
|
static void print_package_name(struct search_ctx *ctx, struct apk_package *pkg)
|
||||||
{
|
{
|
||||||
printf("%s", pkg->name->name);
|
printf("%s", pkg->name->name);
|
||||||
if (apk_verbosity > 0)
|
if (apk_verbosity > 0)
|
||||||
printf("-" BLOB_FMT, BLOB_PRINTF(*pkg->version));
|
printf("-" BLOB_FMT, BLOB_PRINTF(*pkg->version));
|
||||||
if (apk_verbosity > 1)
|
if (apk_verbosity > 1)
|
||||||
printf(" - %s", pkg->description);
|
printf(" - %s", pkg->description);
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_rdepends(struct apk_package *pkg)
|
static void print_origin_name(struct search_ctx *ctx, struct apk_package *pkg)
|
||||||
|
{
|
||||||
|
if (pkg->origin != NULL)
|
||||||
|
printf(BLOB_FMT, BLOB_PRINTF(*pkg->origin));
|
||||||
|
else
|
||||||
|
printf("%s", pkg->name->name);
|
||||||
|
if (apk_verbosity > 0)
|
||||||
|
printf("-" BLOB_FMT, BLOB_PRINTF(*pkg->version));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_rdepends(struct search_ctx *ctx, struct apk_package *pkg)
|
||||||
{
|
{
|
||||||
struct apk_name *name, *name0;
|
struct apk_name *name, *name0;
|
||||||
struct apk_package *pkg0;
|
struct apk_package *pkg0;
|
||||||
|
@ -53,15 +61,12 @@ static int print_rdepends(struct apk_package *pkg)
|
||||||
dep = &pkg0->depends->item[k];
|
dep = &pkg0->depends->item[k];
|
||||||
if (name == dep->name &&
|
if (name == dep->name &&
|
||||||
apk_dep_is_satisfied(dep, pkg)) {
|
apk_dep_is_satisfied(dep, pkg)) {
|
||||||
printf(" " PKG_VER_FMT,
|
printf(" ");
|
||||||
PKG_VER_PRINTF(pkg0));
|
ctx->print_package(ctx, pkg0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int search_pkgname(struct apk_package *pkg, const char *str)
|
static int search_pkgname(struct apk_package *pkg, const char *str)
|
||||||
|
@ -85,7 +90,10 @@ static int search_parse(void *ctx, struct apk_db_options *dbopts,
|
||||||
ictx->match = search_desc;
|
ictx->match = search_desc;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
ictx->print = print_rdepends;
|
ictx->print_result = print_rdepends;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
ictx->print_package = print_origin_name;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -102,8 +110,10 @@ static int match_packages(apk_hash_item item, void *ctx)
|
||||||
for (i = 0; i < ictx->argc; i++)
|
for (i = 0; i < ictx->argc; i++)
|
||||||
if (ictx->match(pkg, ictx->argv[i]))
|
if (ictx->match(pkg, ictx->argv[i]))
|
||||||
break;
|
break;
|
||||||
if (ictx->argc == 0 || i < ictx->argc)
|
if (ictx->argc == 0 || i < ictx->argc) {
|
||||||
ictx->print(pkg);
|
ictx->print_result(ictx, pkg);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -125,8 +135,10 @@ static int search_main(void *ctx, struct apk_database *db, int argc, char **argv
|
||||||
|
|
||||||
if (ictx->match == NULL)
|
if (ictx->match == NULL)
|
||||||
ictx->match = search_pkgname;
|
ictx->match = search_pkgname;
|
||||||
if (ictx->print == NULL)
|
if (ictx->print_package == NULL)
|
||||||
ictx->print = print_match;
|
ictx->print_package = print_package_name;
|
||||||
|
if (ictx->print_result == NULL)
|
||||||
|
ictx->print_result = ictx->print_package;
|
||||||
else if (argc == 0)
|
else if (argc == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -140,8 +152,10 @@ static int search_main(void *ctx, struct apk_database *db, int argc, char **argv
|
||||||
name = apk_db_query_name(db, APK_BLOB_STR(argv[i]));
|
name = apk_db_query_name(db, APK_BLOB_STR(argv[i]));
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
continue;
|
continue;
|
||||||
for (j = 0; j < name->pkgs->num; j++)
|
for (j = 0; j < name->pkgs->num; j++) {
|
||||||
ictx->print(name->pkgs->item[j]);
|
ictx->print_result(ctx, name->pkgs->item[j]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +165,7 @@ static int search_main(void *ctx, struct apk_database *db, int argc, char **argv
|
||||||
static struct apk_option search_options[] = {
|
static struct apk_option search_options[] = {
|
||||||
{ 'd', "description", "Search also package descriptions" },
|
{ 'd', "description", "Search also package descriptions" },
|
||||||
{ 'r', "rdepends", "Print reverse dependencies of package" },
|
{ 'r', "rdepends", "Print reverse dependencies of package" },
|
||||||
|
{ 'o', "origin", "Print origin package name instead of the subpackage" },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct apk_applet apk_search = {
|
static struct apk_applet apk_search = {
|
||||||
|
|
Loading…
Reference in New Issue