| 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_md5sums.c,v 1.2 2003/08/31 14:29:48 djpig-guest Exp $";
|
| 21 |
|
| 22 |
/*****
|
| 23 |
This module lists all packages, sorted by md5sum.
|
| 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 |
#include "parser.h"
|
| 33 |
|
| 34 |
extern int mkdir (const char *, mode_t);
|
| 35 |
extern char *compress_ext;
|
| 36 |
|
| 37 |
#define OUTPUT_FILE "md5sums.html"
|
| 38 |
|
| 39 |
|
| 40 |
/*+
|
| 41 |
Comparison function for sorting by package md5sum.
|
| 42 |
It serves as a "knock on the side of the head" - what other fields
|
| 43 |
could be used for the sort? What information would that provide?
|
| 44 |
+*/
|
| 45 |
static int cmp_md5sum (const void *p, const void *q)
|
| 46 |
{
|
| 47 |
struct package_info *pp = *((struct package_info **) p);
|
| 48 |
struct package_info *qq = *((struct package_info **) q);
|
| 49 |
|
| 50 |
if (!pp->md5sum)
|
| 51 |
return 1;
|
| 52 |
if (!qq->md5sum)
|
| 53 |
return -1;
|
| 54 |
|
| 55 |
return strcmp (pp->md5sum, qq->md5sum);
|
| 56 |
}
|
| 57 |
|
| 58 |
|
| 59 |
/*+
|
| 60 |
+*/
|
| 61 |
static int md5sums_init (void)
|
| 62 |
{
|
| 63 |
int i;
|
| 64 |
FILE *fp;
|
| 65 |
struct package_info *p;
|
| 66 |
|
| 67 |
qsort (cache, cachecnt, sizeof (cache[0]), cmp_md5sum);
|
| 68 |
|
| 69 |
fp = fopen (OUTPUT_FILE, "w");
|
| 70 |
mp_doc_open (fp, "All Packages Sorted by MD5 Checksum");
|
| 71 |
|
| 72 |
mp_abstract (fp, "\
|
| 73 |
This is a list of packages ordered by MD5 checksum. It serves no real\n\
|
| 74 |
purpose.");
|
| 75 |
|
| 76 |
mp_list_open (fp);
|
| 77 |
for (i = 0; i < cachecnt; i++) {
|
| 78 |
p = cache[i];
|
| 79 |
mp_package (fp, p, 2, T_MD5SUM);
|
| 80 |
}
|
| 81 |
mp_list_close (fp);
|
| 82 |
mp_doc_close (fp);
|
| 83 |
fclose (fp);
|
| 84 |
|
| 85 |
gzip (OUTPUT_FILE);
|
| 86 |
|
| 87 |
return 0;
|
| 88 |
}
|
| 89 |
|
| 90 |
|
| 91 |
/*+
|
| 92 |
Print the *tasks* packages ordered by name.
|
| 93 |
+*/
|
| 94 |
static int md5sums_index (FILE *fp, int type)
|
| 95 |
{
|
| 96 |
if (type != MAGPIE_ALL_PACKAGES)
|
| 97 |
return 0;
|
| 98 |
|
| 99 |
mp_item_open (fp);
|
| 100 |
mp_url (fp, "%s%s", "Ordered by MD5 checksum",
|
| 101 |
OUTPUT_FILE, compress_ext);
|
| 102 |
mp_item_close (fp);
|
| 103 |
|
| 104 |
return 0;
|
| 105 |
}
|
| 106 |
|
| 107 |
|
| 108 |
struct magpie_module mod_md5sums = {
|
| 109 |
version : MAGPIE_VERSION,
|
| 110 |
description : "group packages by package md5sums",
|
| 111 |
init : md5sums_init,
|
| 112 |
unannotated_index : md5sums_index
|
| 113 |
};
|