deptest.c

Go to the documentation of this file.
00001 /*
00002  *  deptest.c
00003  *
00004  *  Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include "config.h"
00021 
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 
00026 #include <alpm.h>
00027 #include <alpm_list.h>
00028 
00029 /* pacman */
00030 #include "pacman.h"
00031 #include "util.h"
00032 #include "conf.h"
00033 
00034 /* TODO: This should use _alpm_checkdeps() */
00035 int pacman_deptest(alpm_list_t *targets)
00036 {
00037     int retval = 0;
00038     alpm_list_t *i;
00039 
00040     if(targets == NULL) {
00041         return(0);
00042     }
00043 
00044     for(i = targets; i; i = alpm_list_next(i)) {
00045         int found = 0;
00046         pmpkg_t *pkg;
00047         pmdepend_t *dep;
00048         const char *target;
00049         alpm_list_t *j, *provides;
00050 
00051         target = alpm_list_getdata(i);
00052         dep = alpm_splitdep(target);
00053 
00054         pkg = alpm_db_get_pkg(alpm_option_get_localdb(),
00055                 alpm_dep_get_name(dep));
00056         if(pkg && alpm_depcmp(pkg, dep)) {
00057             found = 1;
00058         } else {
00059             /* not found, can we find anything that provides this in the local DB? */
00060             provides = alpm_db_whatprovides(alpm_option_get_localdb(),
00061                     alpm_dep_get_name(dep));
00062             for(j = provides; j; j = alpm_list_next(j)) {
00063                 pmpkg_t *pkg;
00064                 pkg = alpm_list_getdata(j);
00065 
00066                 if(pkg && alpm_depcmp(pkg, dep)) {
00067                     found = 1;
00068                     break;
00069                 }
00070             }
00071             alpm_list_free(provides);
00072         }
00073 
00074         if(!found) {
00075             printf("%s\n", target);
00076             retval = 127;
00077         }
00078         free(dep);
00079     }
00080     return(retval);
00081 }
00082 
00083 /* vim: set ts=2 sw=2 noet: */

Generated on Mon Jan 14 23:53:40 2008 for libalpm by  doxygen 1.5.4