~ubuntu-branches/debian/sid/deborphan/sid

« back to all changes in this revision

Viewing changes to src/libdeps.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Palfrader
  • Date: 2001-10-28 01:28:24 UTC
  • Revision ID: james.westby@ubuntu.com-20011028012824-0jvhpixo5ldm3h85
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libdeps.c - Retrieve and calculate dependencies for deborphan.
 
2
   Copyright (C) 2000 Cris van Pelt
 
3
 
 
4
   Distributed under the terms of the Artistic License. */
 
5
 
 
6
#include <stdio.h>
 
7
#include <stdlib.h>
 
8
#include <string.h>
 
9
#include <regex.h>
 
10
 
 
11
#ifdef HAVE_CONFIG_H
 
12
#  include <config.h>
 
13
#endif
 
14
 
 
15
#include <deborphan.h>
 
16
 
 
17
#ifdef USE_XALLOC
 
18
#  include <xalloc.h>
 
19
#endif
 
20
 
 
21
extern int options[];
 
22
 
 
23
/* For each package found, this scans the `package' structure, to
 
24
 * see if anything depends on it.
 
25
 */
 
26
void
 
27
check_lib_deps(pkg_info * package, pkg_info * current_pkg)
 
28
{
 
29
    int deps, prov, no_dep_found = 1, search_found = 1;
 
30
    int i;
 
31
    static int j;
 
32
 
 
33
    extern char **search_for;
 
34
 
 
35
    if (current_pkg->hold)
 
36
        return;
 
37
    if (current_pkg->priority < options[PRIORITY])
 
38
        return;
 
39
    if (keep && mustkeep(current_pkg->self))
 
40
        return;
 
41
    if (!is_library(current_pkg))
 
42
        return;
 
43
    
 
44
    if (options[SEARCH]) {
 
45
        search_found = 0;
 
46
        /* Count packages. Just once. */
 
47
        if (!j)
 
48
            for (; *(search_for+j); j++);
 
49
 
 
50
        /* Search for the package, and clear it from the list if it is
 
51
           found. */
 
52
        for (i = 0; *(search_for + i); i++) {
 
53
            if (!strcmp(*(search_for + i), current_pkg->self.name)) {
 
54
                search_found = 1;
 
55
                *(search_for + i) = *(search_for + --j);
 
56
                *(search_for + j) = NULL;
 
57
                break;
 
58
            }
 
59
        }
 
60
    }
 
61
    if (!search_found)
 
62
        return;
 
63
 
 
64
    if (options[SHOW_DEPS]) {
 
65
        printf("%s", current_pkg->self.name);
 
66
 
 
67
        if (options[SHOW_SECTION])
 
68
            printf(" (%s", current_pkg->section);
 
69
        if (options[SHOW_PRIORITY])
 
70
            printf(" - %s", priority_to_string(current_pkg->priority));
 
71
        if (options[SHOW_SECTION])
 
72
            printf(")");
 
73
        printf("\n");
 
74
    }
 
75
 
 
76
    /* Search all (installed) packages for dependencies. 
 
77
     */
 
78
    for (; package && no_dep_found; package = package->next) {
 
79
        for (deps = 0; package->deps[deps].name && no_dep_found; deps++) {
 
80
            for (prov = 0; current_pkg->provides[prov].name && no_dep_found;
 
81
                 prov++) {
 
82
                if (pkgcmp(current_pkg->provides[prov], package->deps[deps])) {
 
83
                    if (options[SHOW_DEPS])
 
84
                        printf("      %s\n", package->self.name);
 
85
                    else
 
86
                        no_dep_found = 0;
 
87
                }
 
88
            }
 
89
 
 
90
            if (pkgcmp(current_pkg->self, package->deps[deps])) {
 
91
                if (options[SHOW_DEPS])
 
92
                    printf("      %s\n", package->self.name);
 
93
                else
 
94
                    no_dep_found = 0;
 
95
            }
 
96
        }
 
97
    }
 
98
 
 
99
    if (no_dep_found && (!options[SHOW_DEPS])) {
 
100
        if (options[SHOW_SECTION])
 
101
            printf("%-25s", current_pkg->section);
 
102
 
 
103
        if (options[SHOW_PRIORITY])
 
104
            printf("%-24s%s", current_pkg->self.name,
 
105
                   priority_to_string(current_pkg->priority));
 
106
        else
 
107
            printf("%s", current_pkg->self.name);
 
108
 
 
109
        printf("\n");
 
110
    }
 
111
}