* pkglist.cc - package list administration
*
* Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
+ * Copyright (C) 2001 Wichert Akkerman <wakkerma@debian.org>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
headings= 0;
verbose= 0;
calcssadone= calcsssdone= 0;
+ searchdescr= 0;
}
void packagelist::finalsetup() {
packagelist::~packagelist() {
if (debug) fprintf(debug,"packagelist[%p]::~packagelist()\n",this);
+ if (searchstring[0])
+ regfree(&searchfsm);
+
discardheadings();
int index;
if (debug) fprintf(debug,"packagelist[%p]::~packagelist() done\n",this);
}
+int packagelist::checksearch(char* rx) {
+ int r,opt = REG_NOSUB;
+
+ if (!rx || !*rx) return 0;
+
+ searchdescr=0;
+ if (searchstring[0]) {
+ regfree(&searchfsm);
+ searchstring[0]=0;
+ }
+
+ /* look for search options */
+ for (r=strlen(rx)-1; r>=0; r--)
+ if ((rx[r]=='/') && ((r==0) || (rx[r-1]!='\\')))
+ break;
+
+ if (r>=0) {
+ rx[r++]='\0';
+ if (strcspn(rx+r, "di")!=0) {
+ displayerror(_("invalid search option given"));
+ return 0;
+ }
+
+ while (rx[r]) {
+ if (rx[r]=='i')
+ opt|=REG_ICASE;
+ else if (rx[r]=='d')
+ searchdescr=1;
+ r++;
+ }
+ }
+
+ if ((r=regcomp(&searchfsm, rx, opt))!=0) {
+ displayerror(_("error in regular expression"));
+ return 0;
+ }
+
+ return 1;
+}
+
+int packagelist::matchsearch(int index) {
+ const char* thisname;
+
+ thisname=itemname(index);
+ if (!thisname) return 0; /* Skip things without a name (seperators) */
+
+ if (regexec(&searchfsm, thisname, 0, NULL, 0)==0)
+ return 1;
+
+ if (searchdescr) {
+ const char* descr = table[index]->pkg->available.description;
+ if (!descr || !*descr) return 0;
+
+ if (regexec(&searchfsm, descr, 0, NULL, 0)==0)
+ return 1;
+ }
+
+ return 0;
+}
+
pkginfo **packagelist::display() {
// returns list of packages as null-terminated array, which becomes owned
// by the caller, if a recursive check is desired.
return 0;
}
}
+
+/* vi: sw=2 ts=8
+ */
* pkglist.h - external definitions for package list handling
*
* Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.uk>
+ * Copyright (C) 2001 Wichert Akkerman <wakkerma@debian.org>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
#ifndef PKGLIST_H
#define PKGLIST_H
+#include <regex.h>
+
enum showpriority {
dp_none, // has not been involved in any unsatisfied things
dp_may, // has been involved in an unsatisfied Suggests
};
class packagelist : public baselist {
+protected:
int status_width, gap_width, section_width, priority_width;
int package_width, versioninstalled_width, versionavailable_width, description_width;
int section_column, priority_column, versioninstalled_column;
int calcssadone, calcsssdone;
struct perpackagestate *headings;
+ // Package searching flags
+ int searchdescr;
+ regex_t searchfsm;
+
// Information displays
struct infotype {
int (packagelist::*relevant)(); // null means always relevant
int deselect_one_of(pkginfo *er, pkginfo *ed, dependency *display);
// Define these virtuals
+ int checksearch(char* str);
+ int matchsearch(int index);
void redraw1itemsel(int index, int selected);
void redrawcolheads();
void redrawthisstate();