main.c
changeset 100 27aada326858
parent 94 0aa93cfbcb3f
child 101 9708f6d5db8c
     1.1 --- a/main.c	Thu Jan 10 21:08:03 2008 -0500
     1.2 +++ b/main.c	Thu Jan 10 23:42:42 2008 -0500
     1.3 @@ -137,29 +137,52 @@
     1.4  }
     1.5  
     1.6  static int
     1.7 -command_what_requires(int argc, const char *argv[])
     1.8 +list_property_packages(const char *ref_name,
     1.9 +		       const char *ref_version,
    1.10 +		       enum razor_property_type ref_type)
    1.11  {
    1.12  	struct razor_set *set;
    1.13 +	struct razor_property *property;
    1.14 +	struct razor_property_iterator *pi;
    1.15 +	const char *name, *version;
    1.16 +	enum razor_property_type type;
    1.17 +
    1.18 +	if (ref_name == NULL)
    1.19 +		return 0;
    1.20  
    1.21  	set = razor_set_open(repo_filename);
    1.22 -	razor_set_list_property_packages(set, argv[0], argv[1],
    1.23 -					 RAZOR_PROPERTY_REQUIRES);
    1.24 -	razor_set_destroy(set);
    1.25 +	if (set == NULL)
    1.26 +		return 1;
    1.27 +
    1.28 +	pi = razor_property_iterator_create(set, NULL);
    1.29 +	while (razor_property_iterator_next(pi, &property,
    1.30 +					    &name, &version, &type)) {
    1.31 +		if (strcmp(ref_name, name) != 0)
    1.32 +			continue;
    1.33 +		if (ref_version && strcmp(ref_version, version) != 0)
    1.34 +			continue;
    1.35 +		if (ref_type != type)
    1.36 +			continue;
    1.37 +
    1.38 +		razor_set_list_property_packages(set, property);
    1.39 +	}
    1.40 +	razor_property_iterator_destroy(pi);
    1.41  
    1.42  	return 0;
    1.43  }
    1.44  
    1.45  static int
    1.46 +command_what_requires(int argc, const char *argv[])
    1.47 +{
    1.48 +	return list_property_packages(argv[0], argv[1],
    1.49 +				      RAZOR_PROPERTY_REQUIRES);
    1.50 +}
    1.51 +
    1.52 +static int
    1.53  command_what_provides(int argc, const char *argv[])
    1.54  {
    1.55 -	struct razor_set *set;
    1.56 -
    1.57 -	set = razor_set_open(repo_filename);
    1.58 -	razor_set_list_property_packages(set, argv[0], argv[1],
    1.59 -					 RAZOR_PROPERTY_PROVIDES);
    1.60 -	razor_set_destroy(set);
    1.61 -
    1.62 -	return 0;
    1.63 +	return list_property_packages(argv[0], argv[1],
    1.64 +				      RAZOR_PROPERTY_PROVIDES);
    1.65  }
    1.66  
    1.67  static int