| 1 |
/*
|
| 2 |
Magpie - reference librarian for Debian systems
|
| 3 |
Copyright (C) 2000 Bear Giles <bgiles@coyotesong.com>
|
| 4 |
|
| 5 |
This program is free software; you may redistribute it and/or
|
| 6 |
modify it under the terms of the GNU General Public License
|
| 7 |
as published by the Free Software Foundation; either version 2
|
| 8 |
of the license, or (at your option) any later version.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License
|
| 16 |
along with this program; if not, write to the Free Software
|
| 17 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
| 18 |
*/
|
| 19 |
|
| 20 |
static const char rcsid[] = "$Id: mod_maintainers.c,v 1.3 2003/08/31 14:29:48 djpig-guest Exp $";
|
| 21 |
|
| 22 |
/*****
|
| 23 |
This module lists all packages, sorted by package maintainer.
|
| 24 |
*****/
|
| 25 |
#include <assert.h>
|
| 26 |
#include <stdio.h>
|
| 27 |
#include <unistd.h>
|
| 28 |
#include <string.h>
|
| 29 |
#include <stdlib.h>
|
| 30 |
#include "magpie.h"
|
| 31 |
|
| 32 |
#define OUTPUT_FILE "maintainer.html"
|
| 33 |
|
| 34 |
extern char *compress_ext;
|
| 35 |
|
| 36 |
/*+
|
| 37 |
Comparison function for sorting by maintainer.
|
| 38 |
We provide one list sorted by maintainer since that can suggest
|
| 39 |
other packages we may be interested in.
|
| 40 |
+*/
|
| 41 |
static int cmp_maintainer (const void *p, const void *q)
|
| 42 |
{
|
| 43 |
struct package_info *pp = *((struct package_info **) p);
|
| 44 |
struct package_info *qq = *((struct package_info **) q);
|
| 45 |
int r;
|
| 46 |
|
| 47 |
assert (pp->maintainer);
|
| 48 |
assert (qq->maintainer);
|
| 49 |
|
| 50 |
r = strcoll (pp->maintainer, qq->maintainer);
|
| 51 |
if (r)
|
| 52 |
return r;
|
| 53 |
|
| 54 |
return strcoll (pp->name, qq->name);
|
| 55 |
}
|
| 56 |
|
| 57 |
|
| 58 |
/*+
|
| 59 |
Index the packages by maintainer.
|
| 60 |
+*/
|
| 61 |
static int maintainers_init (void)
|
| 62 |
{
|
| 63 |
int i, cnt;
|
| 64 |
FILE *fp;
|
| 65 |
struct package_info *p, *q;
|
| 66 |
|
| 67 |
# define MAX_VALUES 200
|
| 68 |
int histogram[MAX_VALUES];
|
| 69 |
|
| 70 |
memset (histogram, 0, sizeof histogram);
|
| 71 |
|
| 72 |
qsort (cache, cachecnt, sizeof (cache[0]), cmp_maintainer);
|
| 73 |
|
| 74 |
fp = fopen (OUTPUT_FILE, "w");
|
| 75 |
mp_doc_open (fp, "All Packages, Grouped by Maintainer");
|
| 76 |
|
| 77 |
mp_abstract (fp, "\
|
| 78 |
This page lists all packages, grouped by maintainer. It can be useful\n\
|
| 79 |
since maintainers often work on related tasks - if you find one package\n\
|
| 80 |
useful, you may find other packages maintained by the same person equally\n\
|
| 81 |
useful.");
|
| 82 |
|
| 83 |
p = cache[0];
|
| 84 |
mp_list_open (fp);
|
| 85 |
for (i = 0; i < cachecnt; ) {
|
| 86 |
|
| 87 |
/* count the number of packages with this maintainer. */
|
| 88 |
for (cnt = 0; i + cnt < cachecnt; cnt++) {
|
| 89 |
q = cache[i+cnt];
|
| 90 |
if (strcoll (p->maintainer, q->maintainer) != 0)
|
| 91 |
break;
|
| 92 |
}
|
| 93 |
if (cnt < MAX_VALUES)
|
| 94 |
histogram[cnt]++;
|
| 95 |
|
| 96 |
mp_item_open (fp);
|
| 97 |
mp_name (fp, p->maintainer);
|
| 98 |
mp_text (fp, p->maintainer);
|
| 99 |
fprintf (fp, " (%d)", cnt);
|
| 100 |
mp_item_close (fp);
|
| 101 |
|
| 102 |
mp_list_open (fp);
|
| 103 |
while (cnt--) {
|
| 104 |
mp_item_open (fp);
|
| 105 |
mp_url (fp, "details/%1$1.1s/%1$s.html%2$s", "%1$s",
|
| 106 |
p->name, compress_ext);
|
| 107 |
mp_nbsp (fp);
|
| 108 |
mp_text (fp, p->summary);
|
| 109 |
mp_item_close (fp);
|
| 110 |
p = cache[++i];
|
| 111 |
}
|
| 112 |
mp_list_close (fp);
|
| 113 |
fprintf (fp, "\n");
|
| 114 |
}
|
| 115 |
mp_list_close (fp);
|
| 116 |
|
| 117 |
mp_break (fp);
|
| 118 |
mp_title (fp, 2, "Histogram");
|
| 119 |
|
| 120 |
fprintf (fp, "\
|
| 121 |
This histogram shows the number of maintainers with the indicated\n\
|
| 122 |
number of packages.");
|
| 123 |
|
| 124 |
mp_histogram (fp, histogram, MAX_VALUES);
|
| 125 |
|
| 126 |
mp_doc_close (fp);
|
| 127 |
fclose (fp);
|
| 128 |
|
| 129 |
gzip (OUTPUT_FILE);
|
| 130 |
|
| 131 |
return 0;
|
| 132 |
}
|
| 133 |
|
| 134 |
|
| 135 |
/*+
|
| 136 |
Index the packages by package maintainer.
|
| 137 |
+*/
|
| 138 |
static int maintainers_index (FILE *fp, int type)
|
| 139 |
{
|
| 140 |
if (type != MAGPIE_ALL_PACKAGES)
|
| 141 |
return 0;
|
| 142 |
|
| 143 |
mp_item_open (fp);
|
| 144 |
mp_url (fp, "%s%s", "Grouped by package maintainer",
|
| 145 |
OUTPUT_FILE, compress_ext);
|
| 146 |
mp_item_close (fp);
|
| 147 |
|
| 148 |
return 0;
|
| 149 |
}
|
| 150 |
|
| 151 |
|
| 152 |
struct magpie_module mod_maintainers = {
|
| 153 |
version : MAGPIE_VERSION,
|
| 154 |
description : "group packages by package name",
|
| 155 |
init : maintainers_init,
|
| 156 |
unannotated_index : maintainers_index
|
| 157 |
};
|