Index: include/dpkg-db.h =================================================================== RCS file: /home/mh21/cvs/dpkg/include/dpkg-db.h,v retrieving revision 1.1 diff -u -r1.1 dpkg-db.h --- include/dpkg-db.h 11 Dec 2004 16:59:39 -0000 1.1 +++ include/dpkg-db.h 13 Dec 2004 11:47:15 -0000 @@ -132,6 +132,9 @@ pri_optional, pri_extra, pri_contrib, pri_other, pri_unknown, pri_unset=-1 } priority; + enum pkgremove { + rem_manual, rem_suggested, rem_recommended, rem_required + } remove; const char *otherpriority; const char *section; struct versionrevision configversion; @@ -217,6 +220,7 @@ extern const struct namevalue statusinfos[]; extern const struct namevalue eflaginfos[]; extern const struct namevalue wantinfos[]; +extern const struct namevalue removeinfos[]; const char *skip_slash_dotslash(const char *p); Index: include/parsedump.h =================================================================== RCS file: /home/mh21/cvs/dpkg/include/parsedump.h,v retrieving revision 1.1 diff -u -r1.1 parsedump.h --- include/parsedump.h 11 Dec 2004 16:59:39 -0000 1.1 +++ include/parsedump.h 11 Dec 2004 17:13:00 -0000 @@ -49,6 +49,7 @@ freadfunction f_name, f_charfield, f_priority, f_section, f_status, f_filecharf; freadfunction f_boolean, f_dependency, f_conffiles, f_version, f_revision; freadfunction f_configversion; +freadfunction f_remove; enum fwriteflags { fw_printheader = 001 /* print field header and trailing newline */ @@ -60,6 +61,7 @@ fwritefunction w_name, w_charfield, w_priority, w_section, w_status, w_configversion; fwritefunction w_version, w_null, w_booleandefno, w_dependency, w_conffiles; fwritefunction w_filecharf; +fwritefunction w_remove; struct fieldinfo { const char *name; Index: lib/database.c =================================================================== RCS file: /home/mh21/cvs/dpkg/lib/database.c,v retrieving revision 1.1 diff -u -r1.1 database.c --- lib/database.c 11 Dec 2004 16:59:40 -0000 1.1 +++ lib/database.c 11 Dec 2004 17:44:50 -0000 @@ -64,6 +64,7 @@ pigp->eflag= eflagv_ok; pigp->want= want_unknown; pigp->priority= pri_unknown; + pigp->remove= rem_manual; pigp->otherpriority = NULL; pigp->section= NULL; blankversion(&pigp->configversion); Index: lib/dump.c =================================================================== RCS file: /home/mh21/cvs/dpkg/lib/dump.c,v retrieving revision 1.1 diff -u -r1.1 dump.c --- lib/dump.c 11 Dec 2004 16:59:40 -0000 1.1 +++ lib/dump.c 14 Dec 2004 10:26:43 -0000 @@ -155,6 +155,19 @@ varbufaddc(vb,'\n'); } +void w_remove(struct varbuf *vb, + const struct pkginfo *pigp, const struct pkginfoperfile *pifp, + enum fwriteflags flags, const struct fieldinfo *fip) { + if (pifp != &pigp->installed) return; + if (pigp->remove == rem_manual) return; + assert(pigp->remove <= rem_required); + if (flags&fw_printheader) + varbufaddstr(vb,"Automatic-Remove: "); + varbufaddstr(vb,removeinfos[pigp->remove].name); + if (flags&fw_printheader) + varbufaddc(vb,'\n'); +} + void w_status(struct varbuf *vb, const struct pkginfo *pigp, const struct pkginfoperfile *pifp, enum fwriteflags flags, const struct fieldinfo *fip) { Index: lib/fields.c =================================================================== RCS file: /home/mh21/cvs/dpkg/lib/fields.c,v retrieving revision 1.1 diff -u -r1.1 fields.c --- lib/fields.c 11 Dec 2004 16:59:40 -0000 1.1 +++ lib/fields.c 11 Dec 2004 17:13:00 -0000 @@ -155,6 +155,16 @@ if (pigp->priority == pri_other) pigp->otherpriority= nfstrsave(value); } +void f_remove(struct pkginfo *pigp, struct pkginfoperfile *pifp, + enum parsedbflags flags, + const char *filename, int lno, FILE *warnto, int *warncount, + const char *value, const struct fieldinfo *fip) { + if (!*value) return; + pigp->remove= convert_string(filename,lno,"word in `remove' field", rem_manual, + warnto,warncount,pigp, + value,removeinfos,NULL); +} + void f_status(struct pkginfo *pigp, struct pkginfoperfile *pifp, enum parsedbflags flags, const char *filename, int lno, FILE *warnto, int *warncount, Index: lib/parse.c =================================================================== RCS file: /home/mh21/cvs/dpkg/lib/parse.c,v retrieving revision 1.1 diff -u -r1.1 parse.c --- lib/parse.c 11 Dec 2004 16:59:41 -0000 1.1 +++ lib/parse.c 13 Dec 2004 11:08:28 -0000 @@ -55,6 +55,7 @@ { "Version", f_version, w_version, PKGIFPOFF(version) }, { "Revision", f_revision, w_null }, { "Config-Version", f_configversion, w_configversion }, + { "Automatic-Remove", f_remove, w_remove }, { "Replaces", f_dependency, w_dependency, dep_replaces }, { "Provides", f_dependency, w_dependency, dep_provides }, { "Depends", f_dependency, w_dependency, dep_depends }, @@ -303,6 +304,7 @@ pigp->want= newpig.want; pigp->eflag= newpig.eflag; pigp->status= newpig.status; + pigp->remove= newpig.remove; pigp->configversion= newpig.configversion; pigp->files= NULL; } else if (!(flags & pdb_ignorefiles)) { Index: lib/parsehelp.c =================================================================== RCS file: /home/mh21/cvs/dpkg/lib/parsehelp.c,v retrieving revision 1.1 diff -u -r1.1 parsehelp.c --- lib/parsehelp.c 11 Dec 2004 16:59:41 -0000 1.1 +++ lib/parsehelp.c 11 Dec 2004 17:13:00 -0000 @@ -105,6 +105,14 @@ { NULL } }; +const struct namevalue removeinfos[]= { /* Note ! These must be in order ! */ + { "manual", rem_manual, 6 }, + { "suggested", rem_suggested, 9 }, + { "recommended", rem_recommended, 11 }, + { "required", rem_required, 8 }, + { NULL } +}; + const char *illegal_packagename(const char *p, const char **ep) { static const char alsoallowed[]= "-+._"; /* _ is deprecated */ static char buf[150]; Index: main/Makefile.in =================================================================== RCS file: /home/mh21/cvs/dpkg/main/Makefile.in,v retrieving revision 1.1 diff -u -r1.1 Makefile.in --- main/Makefile.in 11 Dec 2004 16:59:41 -0000 1.1 +++ main/Makefile.in 13 Dec 2004 12:09:56 -0000 @@ -8,7 +8,7 @@ SOURCES = main.c enquiry.c filesdb.c archives.c processarc.c \ cleanup.c select.c packages.c configure.c remove.c \ - help.c depcon.c errors.c update.c + help.c depcon.c errors.c update.c autoremove.c MAN8PAGES = dpkg.8 dpkg-query.8 Index: main/autoremove.c =================================================================== RCS file: main/autoremove.c diff -N main/autoremove.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ main/autoremove.c 15 Dec 2004 14:31:44 -0000 @@ -0,0 +1,136 @@ +/* + * dpkg - main program for package management + * autoremove.c - automatic dependency flags + * + * Copyright (C) 2004 Michael Hofmann + * + * based on select.c, + * Copyright (C) 1995,1996 Ian Jackson + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with dpkg; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "filesdb.h" +#include "main.h" + +static void getrem1package(struct pkginfo *pkg) { + int l; + + l= strlen(pkg->name); l >>= 3; l= 6-l; if (l<1) l=1; + printf("%s%.*s%s\n",pkg->name,l,"\t\t\t\t\t\t",removeinfos[pkg->remove].name); +} + +void getremove(const char *const *argv) { + struct pkgiterator *it; + struct pkginfo *pkg; + struct pkginfo **pkgl; + const char *thisarg; + int np, i, head, found; + + modstatdb_init(admindir,msdbrw_readonly); + + np= countpackages(); + pkgl= m_malloc(sizeof(struct pkginfo*)*np); + it= iterpkgstart(); i=0; + while ((pkg= iterpkgnext(it))) { + assert(istatus == stat_notinstalled) continue; + getrem1package(pkg); + } + } else { + while ((thisarg= *argv++)) { + found= 0; + for (i=0; iname,0)) continue; + if (pkg->status == stat_notinstalled) continue; + getrem1package(pkg); found++; + } + if (!found) + fprintf(stderr,_("No packages found matching %s.\n"),thisarg); + } + } + if (ferror(stdout)) werr("stdout"); + if (ferror(stderr)) werr("stderr"); +} + +void setremove(const char *const *argv) { + const struct namevalue *nvp; + struct pkginfo *pkg; + const char *e; + const char *const *ap; + char c; + int lno; + struct varbuf namevb; + struct varbuf remvb; + + if (! *argv) badusage(_("--set-remove needs at least one argument")); + + modstatdb_init(admindir,msdbrw_write); + + varbufinit(&namevb); + varbufinit(&remvb); + for (lno=1,ap=argv;*ap;++ap,++lno) { + const char* cur=*ap; + varbufreset(&namevb); + varbufreset(&remvb); + c= *(cur++); + if (c == 0) ohshit(_("unexpected parameter end in package name in parameter %d"),lno); + while (c != '/') { + varbufaddc(&namevb,c); + c= *(cur++); + if (c == 0) ohshit(_("unexpected parameter end in package name in parameter %d"),lno); + } + c= *(cur++); + if (c == 0) ohshit(_("unexpected parameter end after package name in parameter %d"),lno); + while (c != 0) { + varbufaddc(&remvb,c); + c= *(cur++); + } + varbufaddc(&namevb,0); + varbufaddc(&remvb,0); + e= illegal_packagename(namevb.buf,0); + if (e) ohshit(_("illegal package name in parameter %d: %.250s"),lno,e); + for (nvp=removeinfos; nvp->name && strcmp(nvp->name,remvb.buf); nvp++); + if (!nvp->name) ohshit(_("unknown remove status in parameter %d: %.250s"),lno,remvb.buf); + pkg= findpackage(namevb.buf); + pkg->remove= nvp->value; + } + modstatdb_shutdown(); + varbufreset(&namevb); + varbufreset(&remvb); +} + Index: main/main.c =================================================================== RCS file: /home/mh21/cvs/dpkg/main/main.c,v retrieving revision 1.1 diff -u -r1.1 main.c --- main/main.c 11 Dec 2004 16:59:42 -0000 1.1 +++ main/main.c 13 Dec 2004 12:03:34 -0000 @@ -369,6 +369,8 @@ ACTIONBACKEND( "status", 's', DPKGQUERY), ACTION( "get-selections", 0, act_getselections, getselections ), ACTION( "set-selections", 0, act_setselections, setselections ), + ACTION( "get-remove", 0, act_getremove, getremove ), + ACTION( "set-remove", 0, act_setremove, setremove ), ACTIONBACKEND( "print-avail", 'p', DPKGQUERY), ACTION( "update-avail", 0, act_avreplace, updateavailable ), ACTION( "merge-avail", 0, act_avmerge, updateavailable ), Index: main/main.h =================================================================== RCS file: /home/mh21/cvs/dpkg/main/main.h,v retrieving revision 1.1 diff -u -r1.1 main.h --- main/main.h 11 Dec 2004 16:59:42 -0000 1.1 +++ main/main.h 13 Dec 2004 12:11:44 -0000 @@ -55,7 +55,7 @@ act_printinstarch, act_compareversions, act_printavail, act_avclear, act_forgetold, act_getselections, act_setselections, act_printgnuarch, act_assertepoch, act_assertlongfilenames, act_assertmulticonrep, - act_commandfd }; + act_commandfd, act_getremove, act_setremove }; enum conffopt { cfof_prompt = 001, @@ -136,6 +136,11 @@ void getselections(const char *const *argv); void setselections(const char *const *argv); +/* from autoremove.c */ + +void getremove(const char *const *argv); +void setremove(const char *const *argv); + /* from packages.c, remove.c and configure.c */ void add_to_queue(struct pkginfo *pkg);