00001 #include "system.h"
00002
00003 #include <rpmbuild.h>
00004 #include <argv.h>
00005 #include <rpmds.h>
00006 #include <rpmfc.h>
00007
00008 #include "debug.h"
00009
00010
00011 char *progname;
00012
00013
00014 static int print_provides;
00015
00016
00017 static int print_requires;
00018
00019 static void rpmdsPrint(const char * msg, rpmds ds, FILE * fp)
00020 {
00021 if (fp == NULL) fp = stderr;
00022
00023 if (msg)
00024 fprintf(fp, "===================================== %s\n", msg);
00025
00026 ds = rpmdsInit(ds);
00027 while (rpmdsNext(ds) >= 0)
00028 fprintf(fp, "%s\n", rpmdsDNEVR(ds)+2);
00029 }
00030
00031 static struct poptOption optionsTable[] = {
00032
00033 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
00034 N_("Common options for all rpm modes and executables:"),
00035 NULL },
00036
00037 { "provides", 'P', POPT_ARG_VAL, &print_provides, -1,
00038 NULL, NULL },
00039 { "requires", 'R', POPT_ARG_VAL, &print_requires, -1,
00040 NULL, NULL },
00041
00042 POPT_AUTOALIAS
00043 POPT_AUTOHELP
00044 POPT_TABLEEND
00045 };
00046
00047 int
00048 main(int argc, char *const argv[])
00049 {
00050 poptContext optCon;
00051 ARGV_t av = NULL;
00052 rpmfc fc;
00053 int ac = 0;
00054 int ec = 1;
00055 int xx;
00056 char buf[BUFSIZ];
00057
00058
00059 if ((progname = strrchr(argv[0], '/')) != NULL)
00060 progname++;
00061 else
00062 progname = argv[0];
00063
00064
00065 optCon = rpmcliInit(argc, argv, optionsTable);
00066 if (optCon == NULL)
00067 goto exit;
00068
00069 av = poptGetArgs(optCon);
00070 ac = argvCount(av);
00071
00072 if (ac == 0) {
00073 char * b, * be;
00074 av = NULL;
00075 while ((b = fgets(buf, sizeof(buf), stdin)) != NULL) {
00076 buf[sizeof(buf)-1] = '\0';
00077 be = b + strlen(buf) - 1;
00078 while (strchr("\r\n", *be) != NULL)
00079 *be-- = '\0';
00080 xx = argvAdd(&av, b);
00081 }
00082 ac = argvCount(av);
00083 }
00084
00085
00086 xx = argvSort(av, NULL);
00087
00088
00089 fc = rpmfcNew();
00090 xx = rpmfcClassify(fc, av);
00091
00092
00093 xx = rpmfcApply(fc);
00094
00095 if (_rpmfc_debug) {
00096 sprintf(buf, "final: files %d cdict[%d] %d%% ddictx[%d]", fc->nfiles, argvCount(fc->cdict), ((100 * fc->fknown)/fc->nfiles), argiCount(fc->ddictx));
00097 rpmfcPrint(buf, fc, NULL);
00098 }
00099
00100 if (print_provides)
00101 rpmdsPrint(NULL, fc->provides, stdout);
00102 if (print_requires)
00103 rpmdsPrint(NULL, fc->requires, stdout);
00104
00105 fc = rpmfcFree(fc);
00106
00107 ec = 0;
00108
00109 exit:
00110 optCon = rpmcliFini(optCon);
00111 return ec;
00112 }