2 * dpkg - main program for package management
3 * select.c - by-hand (rather than dselect-based) package selection
5 * Copyright © 1995,1996 Ian Jackson <ian@chiark.greenend.org.uk>
6 * Copyright © 2006,2008-2012 Guillem Jover <guillem@debian.org>
7 * Copyright © 2011 Linaro Limited
8 * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
10 * This is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #include <dpkg/i18n.h>
34 #include <dpkg/dpkg.h>
35 #include <dpkg/dpkg-db.h>
36 #include <dpkg/pkg-array.h>
37 #include <dpkg/pkg-show.h>
38 #include <dpkg/pkg-spec.h>
39 #include <dpkg/options.h>
45 static void getsel1package(struct pkginfo *pkg) {
49 if (pkg->want == want_unknown) return;
50 pkgname = pkg_name(pkg, pnaw_nonambig);
56 printf("%s%.*s%s\n", pkgname, l, "\t\t\t\t\t\t", wantinfos[pkg->want].name);
60 getselections(const char *const *argv)
62 struct pkg_array array;
67 modstatdb_open(msdbrw_readonly);
69 pkg_array_init_from_db(&array);
70 pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch);
73 for (i = 0; i < array.n_pkgs; i++) {
75 if (pkg->status == stat_notinstalled) continue;
79 while ((thisarg= *argv++)) {
80 struct pkg_spec pkgspec;
83 pkg_spec_init(&pkgspec, psf_patterns | psf_arch_def_wildcard);
84 pkg_spec_parse(&pkgspec, thisarg);
86 for (i = 0; i < array.n_pkgs; i++) {
88 if (!pkg_spec_match_pkg(&pkgspec, pkg, &pkg->installed))
90 getsel1package(pkg); found++;
93 notice(_("no packages found matching %s"), thisarg);
95 pkg_spec_destroy(&pkgspec);
99 m_output(stdout, _("<standard output>"));
100 m_output(stderr, _("<standard error>"));
102 pkg_array_destroy(&array);
108 setselections(const char *const *argv)
110 const struct namevalue *nv;
113 struct varbuf namevb = VARBUF_INIT;
114 struct varbuf selvb = VARBUF_INIT;
117 badusage(_("--%s takes no arguments"), cipaction->olong);
119 modstatdb_open(msdbrw_write | msdbrw_available_readonly);
120 pkg_infodb_upgrade();
124 struct dpkg_error err;
126 do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && isspace(c));
129 do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && c != '\n');
133 varbuf_reset(&namevb);
134 while (!isspace(c)) {
135 varbuf_add_char(&namevb, c);
137 if (c == EOF) ohshit(_("unexpected eof in package name at line %d"),lno);
138 if (c == '\n') ohshit(_("unexpected end of line in package name at line %d"),lno);
140 varbuf_end_str(&namevb);
142 while (c != EOF && isspace(c)) {
144 if (c == EOF) ohshit(_("unexpected eof after package name at line %d"),lno);
145 if (c == '\n') ohshit(_("unexpected end of line after package name at line %d"),lno);
148 varbuf_reset(&selvb);
149 while (c != EOF && !isspace(c)) {
150 varbuf_add_char(&selvb, c);
153 varbuf_end_str(&selvb);
155 while (c != EOF && c != '\n') {
158 ohshit(_("unexpected data after package and selection at line %d"),lno);
160 pkg = pkg_spec_parse_pkg(namevb.buf, &err);
162 ohshit(_("illegal package name at line %d: %.250s"), lno, err.str);
164 if (!pkg_is_informative(pkg, &pkg->installed) &&
165 !pkg_is_informative(pkg, &pkg->available)) {
166 warning(_("package not in database at line %d: %.250s"), lno, namevb.buf);
170 nv = namevalue_find_by_name(wantinfos, selvb.buf);
172 ohshit(_("unknown wanted status at line %d: %.250s"), lno, selvb.buf);
174 pkg_set_want(pkg, nv->value);
178 if (ferror(stdin)) ohshite(_("read error on standard input"));
179 modstatdb_shutdown();
180 varbuf_destroy(&namevb);
181 varbuf_destroy(&selvb);
187 clearselections(const char *const *argv)
189 struct pkgiterator *it;
193 badusage(_("--%s takes no arguments"), cipaction->olong);
195 modstatdb_open(msdbrw_write);
196 pkg_infodb_upgrade();
198 it = pkg_db_iter_new();
199 while ((pkg = pkg_db_iter_next_pkg(it))) {
200 if (!pkg->installed.essential)
201 pkg_set_want(pkg, want_deinstall);
203 pkg_db_iter_free(it);
205 modstatdb_shutdown();