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