csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
#include "system.h"
2ff057
2ff057
#include <rpm/rpmbuild.h>
2ff057
#include <rpm/argv.h>
2ff057
#include <rpm/rpmds.h>
2ff057
#include <rpm/rpmfc.h>
2ff057
2ff057
#include "debug.h"
2ff057
2ff057
static int print_provides;
2ff057
2ff057
static int print_requires;
2ff057
2ff057
static int print_recommends;
2ff057
2ff057
static int print_suggests;
2ff057
2ff057
static int print_supplements;
2ff057
2ff057
static int print_enhances;
2ff057
2ff057
static int print_conflicts;
2ff057
2ff057
static int print_obsoletes;
2ff057
2ff057
static int print_alldeps;
2ff057
2ff057
static void rpmdsPrint(const char * msg, rpmds ds, FILE * fp)
2ff057
{
2ff057
    if (fp == NULL) fp = stderr;
2ff057
2ff057
    if (msg)
2ff057
	fprintf(fp, "===================================== %s\n", msg);
2ff057
2ff057
    ds = rpmdsInit(ds);
2ff057
    while (rpmdsNext(ds) >= 0)
2ff057
	fprintf(fp, "%s\n", rpmdsDNEVR(ds)+2);
2ff057
}
2ff057
2ff057
static struct poptOption optionsTable[] = {
2ff057
2ff057
 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
2ff057
	N_("Common options for all rpm modes and executables:"),
2ff057
	NULL }, 
2ff057
2ff057
 { "provides", 'P', POPT_ARG_VAL, &print_provides, -1,
2ff057
        NULL, NULL },
2ff057
 { "requires", 'R', POPT_ARG_VAL, &print_requires, -1,
2ff057
        NULL, NULL },
2ff057
 { "recommends", '\0', POPT_ARG_VAL, &print_recommends, -1,
2ff057
        NULL, NULL },
2ff057
 { "suggests", '\0', POPT_ARG_VAL, &print_suggests, -1,
2ff057
        NULL, NULL },
2ff057
 { "supplements", '\0', POPT_ARG_VAL, &print_supplements, -1,
2ff057
        NULL, NULL },
2ff057
 { "enhances", '\0', POPT_ARG_VAL, &print_enhances, -1,
2ff057
        NULL, NULL },
2ff057
 { "conflicts", '\0', POPT_ARG_VAL, &print_conflicts, -1,
2ff057
        NULL, NULL },
2ff057
 { "obsoletes", '\0', POPT_ARG_VAL, &print_obsoletes, -1,
2ff057
        NULL, NULL },
2ff057
 { "alldeps", '\0', POPT_ARG_VAL, &print_alldeps, -1,
2ff057
        NULL, NULL },
2ff057
2ff057
   POPT_AUTOALIAS
2ff057
   POPT_AUTOHELP
2ff057
   POPT_TABLEEND
2ff057
};
2ff057
2ff057
int
2ff057
main(int argc, char *argv[])
2ff057
{
2ff057
    poptContext optCon = NULL;
2ff057
    ARGV_t av = NULL;
2ff057
    rpmfc fc = NULL;
2ff057
    int ec = 1;
2ff057
    char buf[BUFSIZ];
2ff057
2ff057
    xsetprogname(argv[0]); /* Portability call -- see system.h */
2ff057
2ff057
    optCon = rpmcliInit(argc, argv, optionsTable);
2ff057
    if (optCon == NULL)
2ff057
	goto exit;
2ff057
2ff057
    /* normally files get passed through stdin but also accept files as args */
2ff057
    if (poptPeekArg(optCon)) {
2ff057
	const char *arg;
2ff057
	while ((arg = poptGetArg(optCon)) != NULL) {
2ff057
	    argvAdd(&av, arg);
2ff057
	}
2ff057
    } else {
2ff057
	while (fgets(buf, sizeof(buf), stdin) != NULL) {
2ff057
	    char *be = buf + strlen(buf) - 1;
2ff057
	    while (strchr("\r\n", *be) != NULL)
2ff057
		*be-- = '\0';
2ff057
	    argvAdd(&av, buf);
2ff057
	}
2ff057
    }
2ff057
    /* Make sure file names are sorted. */
2ff057
    argvSort(av, NULL);
2ff057
2ff057
    /* Build file/package class and dependency dictionaries. */
2ff057
    fc = rpmfcCreate(getenv("RPM_BUILD_ROOT"), 0);
2ff057
    if (rpmfcClassify(fc, av, NULL) || rpmfcApply(fc))
2ff057
	goto exit;
2ff057
2ff057
    if (print_alldeps || _rpmfc_debug)
2ff057
	rpmfcPrint(NULL, fc, print_alldeps ? stdout : NULL);
2ff057
2ff057
    if (!print_alldeps) {
2ff057
	if (print_provides)
2ff057
	    rpmdsPrint(NULL, rpmfcProvides(fc), stdout);
2ff057
	if (print_requires)
2ff057
	    rpmdsPrint(NULL, rpmfcRequires(fc), stdout);
2ff057
	if (print_recommends)
2ff057
	    rpmdsPrint(NULL, rpmfcRecommends(fc), stdout);
2ff057
	if (print_suggests)
2ff057
	    rpmdsPrint(NULL, rpmfcSuggests(fc), stdout);
2ff057
	if (print_supplements)
2ff057
	    rpmdsPrint(NULL, rpmfcSupplements(fc), stdout);
2ff057
	if (print_enhances)
2ff057
	    rpmdsPrint(NULL, rpmfcEnhances(fc), stdout);
2ff057
	if (print_conflicts)
2ff057
	    rpmdsPrint(NULL, rpmfcConflicts(fc), stdout);
2ff057
	if (print_obsoletes)
2ff057
	    rpmdsPrint(NULL, rpmfcObsoletes(fc), stdout);
2ff057
    }
2ff057
2ff057
    ec = 0;
2ff057
2ff057
exit:
2ff057
    argvFree(av);
2ff057
    rpmfcFree(fc);
2ff057
    rpmcliFini(optCon);
2ff057
    return ec;
2ff057
}