File: deborphan.h

package info (click to toggle)
deborphan 1.7.35
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 764 kB
  • sloc: ansic: 1,631; makefile: 119; sh: 87; perl: 54
file content (180 lines) | stat: -rw-r--r-- 4,948 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* deborphan.h
   Copyright (C) 2000, 2001, 2002, 2003 Cris van Pelt
   Copyright (C) 2003, 2004 Peter Palfrader
   Copyright (C) 2008, 2009 Carsten Hey

   Distributed under the terms of the MIT License, see the
   file COPYING provided in this package for details.
*/
#pragma once

#include <config.h>
#include <stdio.h>

/* Faster than toupper. Less reliable too. */
#define upcase(c) ((c)&32 ? (c) ^ 32 : (c))

typedef struct dep {
    char* name;
    char* arch;
    unsigned int namehash;
} dep;

/* The initial size of the provides[] and deps[] array, when
 * it is allocated for the first time.
 *
 * Should a grow be required, the count size is doubled.
 */
#define INIT_DEPENDS_COUNT 32
#define INIT_PROVIDES_COUNT 4
#define INIT_EXCLUDES_COUNT 4

/* These arrays aren't exactly neat, but it seems they suffice. */
typedef struct pkg_info {
    dep self;
    int priority;
    dep* provides;
    int provides_cnt;
    int provides_max;
    char* section;
    dep* deps;
    int deps_cnt;
    int deps_max;
    int install;
    int hold;
    int essential;
    int dummy;
    int config;
    long installed_size;
    struct pkg_info* next;
} pkg_info;

/* Make the options[] array easier to read. */
enum {
    SHOW_DEPS = 0,
    NICE_MODE,
    IGNORE_RECOMMENDS,
    IGNORE_SUGGESTS,
    ALL_PACKAGES,
    PRIORITY,
    SHOW_SECTION,
    SHOW_PRIORITY,
    SHOW_SIZE,
    SHOW_ARCH,
    SEARCH,
    FORCE_HOLD,
    ADD_KEEP,
    DEL_KEEP,
    GUESS,
    NO_DEBFOSTER,
    GUESS_ONLY,
    LIST_KEEP,
    ZERO_KEEP,
    FIND_CONFIG,
    SEARCH_LIBDEVEL,
    CHECK_OPTIONS,
    NUM_OPTIONS /* THIS HAS TO BE THE LAST OF THIS ENUM! */
};

/* options[SHOW_ARCH] is set to one of these values. */
enum { DEFAULT = 0, ALWAYS, NEVER };

#define GUESS_DEV (1 << 1)
#define GUESS_PERL (1 << 2)
#define GUESS_SECTION (1 << 3)
#define GUESS_DEBUG (1 << 4)
#define GUESS_PIKE (1 << 5)
#define GUESS_PYTHON (1 << 6)
#define GUESS_RUBY (1 << 7)
#define GUESS_DUMMY (1 << 8)
#define GUESS_COMMON (1 << 9)
#define GUESS_DATA (1 << 10)
#define GUESS_DOC (1 << 11)
#define GUESS_MONO (1 << 12)
#define GUESS_KERNEL (1 << 13)
#define GUESS_JAVA (1 << 14)

// Interpreters
#define GUESS_IP                                                        \
    (GUESS_PERL | GUESS_PIKE | GUESS_PYTHON | GUESS_RUBY | GUESS_MONO | \
     GUESS_JAVA)
#define GUESS_ALL 0xFFFFFFFF

#define guess_chk(n) ((options[GUESS] & (n)) == (n))
#define guess_set(n) (options[GUESS] |= (n))
#define guess_clr(n) (options[GUESS] &= ~(n))
#define guess_unique(n) (!(options[GUESS] ^ (n)))
#define pkgcmp(a, b) \
    (((a).namehash == (b).namehash ? (strcmp((a).name, (b).name) ? 0 : 1) : 0))

extern dep* keep;
extern int options[NUM_OPTIONS];
extern char* program_name;

/* pkginfo.c */
void init_pkg_regex(void);
void free_pkg_regex(void);
void get_pkg_info(const char* line, pkg_info* package, int* multiarch);
void get_pkg_priority(const char* line, pkg_info* package);
void get_pkg_provides(const char* line, pkg_info* package);
void get_pkg_name(const char* line, pkg_info* package);
void get_pkg_status(const char* line, pkg_info* package);
void get_pkg_section(const char* line, pkg_info* package);
void get_pkg_deps(const char* line, pkg_info* package);
void get_pkg_essential(const char* line, pkg_info* package);
void get_pkg_installed_size(const char* line, pkg_info* package);
void get_pkg_dummy(const char* line, pkg_info* package);
unsigned int is_library(pkg_info* package, int search_libdevel);

/* libdeps.c */
void check_lib_deps(pkg_info* package, pkg_info* current_pkg, int print_suffix);

/* exit.c */
__attribute__((noreturn)) void error(int exit_status,
                                     int error_no,
                                     const char* format,
                                     ...);
void exit_help(void);
void exit_improperstate(void);
void exit_invalid_statusfile(void);
void exit_version(void);
void print_usage(FILE* output);

/* string.c */
int string_to_priority(const char* priority);
const char* priority_to_string(int priority);
void strstripchr(char* s, int c);
unsigned int strhash(const char* line);

/* keep.c */
dep* readkeep(const char* kfile);
int mustkeep(dep d);
int delkeep(const char* kfile, char** del);
int addkeep(const char* kfile, char** add);
dep* mergekeep(const dep* a, const dep* b);
void listkeepall(const char* kfile);
int listkeep(const char* kfile);
char** parseargs(int argind, int argc, char** argv);
dep* parseargs_as_dep(int argind, int argc, char** argv);
int hasduplicate(char** list);
int pkggrep(const char* sfile, char** pkgnames);

/* file.c */
char* debopen(const char* filename);
int zerofile(const char* filename);

#ifdef ENABLE_NLS
#undef _
#define _(string) gettext(string)
#else
#undef _
#define _(string) (string)
#undef setlocale
#define setlocale(a, b)
#undef bindtextdomain
#define bindtextdomain(a, b)
#undef textdomain
#define textdomain(a)
#endif /* ENABLE_NLS */

#undef D_ATTRIBUTE