opkg: introduce the protype of active_list
[oweals/opkg-lede.git] / tests / opkg_hash_test.c
1 /* opkg_hash_test.c - the itsy package management system
2
3    Carl D. Worth
4
5    Copyright (C) 2001 University of Southern California
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 */
17
18 #include <libopkg/opkg.h>
19
20 #include <libopkg/hash_table.h>
21 #include <libopkg/opkg_utils.h>
22 #include <libopkg/pkg_hash.h>
23
24 int main(int argc, char *argv[])
25 {
26      opkg_conf_t conf;
27      hash_table_t *hash = &conf.pkg_hash;
28      pkg_vec_t * pkg_vec;
29
30     if (argc < 3) {
31         fprintf(stderr, "Usage: %s <pkgs_file1> <pkgs_file2> [pkg_name...]\n", argv[0]);
32         exit(1);
33     }
34     pkg_hash_init("test", hash, 1024);
35
36     pkg_hash_add_from_file(&conf, argv[1], NULL, NULL, 0);
37     pkg_hash_add_from_file(&conf, argv[2], NULL, NULL, 0);
38
39     if (argc < 4) {
40         pkg_print_info( pkg_hash_fetch_by_name_version(hash, "libc6", "2.2.3-2"), stdout);
41         /*      for(i = 0; i < pkg_vec->len; i++)
42                 pkg_print(pkg_vec->pkgs[i], stdout);
43         */
44     } else {
45         int i, j, k;
46         char **unresolved;
47
48         pkg_vec_t * dep_vec;
49         for (i = 3; i < argc; i++) {
50             pkg_vec = pkg_vec_fetch_by_name(hash, argv[i]);
51             if (pkg_vec == NULL) {
52                 fprintf(stderr, "*** WARNING: Unknown package: %s\n\n", argv[i]);
53                 continue;
54             }
55
56             for(j = 0; j < pkg_vec->len; j++){
57                 pkg_print_info(pkg_vec->pkgs[j], stdout);
58                 dep_vec = pkg_vec_alloc();
59                 pkg_hash_fetch_unsatisfied_dependencies(&conf,
60                                                         pkg_vec->pkgs[j],
61                                                         dep_vec,
62                                                         &unresolved);
63                 if(dep_vec){
64                     fprintf(stderr, "and the unsatisfied dependencies are:\n");
65                     for(k = 0; k < dep_vec->len; k++){
66                         fprintf(stderr, "%s version %s\n", dep_vec->pkgs[k]->name, dep_vec->pkgs[k]->version);
67                     }
68                 }
69                 
70                 fputs("", stdout);
71                 
72             }
73         }
74     }
75
76     pkg_hash_deinit(hash);
77
78     return 0;
79 }