distromatic/src/requirelist.c

149 lines
4.6 KiB
C
Raw Normal View History

2011-04-27 21:50:52 +02:00
/*
* distromatic - tool for RPM based repositories
*
* Copyright (C) 2004-2007 by Silvan Calarco <silvan.calarco@mambasoft.it>
* Copyright (C) 2006 by Davide Madrisan <davide.madrisan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of version 2 of the GNU General Public License as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY, to the extent permitted by law; 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
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
#include <stdio.h>
#if HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#endif
#if HAVE_STRINGS_H
# include <strings.h>
#endif
#ifndef HEADERLIST_H
# include "headerlist.h"
#endif
#ifndef REQUIRELIST_H
# include "requirelist.h"
#endif
#if !HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
#endif
struct requireList *
mergeRequireLists(struct requireList *base, struct requireList *insert)
{
struct requireList *currbase, *currinsert, *prevbase;
currinsert = insert;
currbase = base;
prevbase = NULL;
while (currinsert) {
while ((currinsert) &&
((!currbase) ||
((strcmp(currbase->header->name,
currinsert->header->name) > 0)))) {
if (!prevbase) {
base = malloc(sizeof(struct requireList));
memcpy(base, currinsert, sizeof(struct requireList));
base->next = currbase;
} else
if (strcmp(prevbase->header->name,
currinsert->header->name)) {
prevbase->next = malloc(sizeof(struct requireList));
memcpy(prevbase->next, currinsert,
sizeof(struct requireList));
prevbase->next->next = currbase;
}
currinsert = currinsert->next;
}
if (currbase) {
prevbase = currbase;
currbase = currbase->next;
}
}
return base;
}
struct requireList *
recurseRequireList(struct headerList *headerlist)
{
struct requireList *currrequirelist, *recrequirelist;
currrequirelist = headerlist->requirelist;
recrequirelist = NULL;
if (headerlist->recursed < 2) {
headerlist->recursed = 1;
while (currrequirelist) {
if (currrequirelist->header->recursed < 1) {
/* if (!strcmp(headerlist->name,"glibc")) {
* printf("glibc with %s\n",curre
* }
* currrequirelist->header->recursed+=1;
*
* printf("recursing %s %d from %s %d\n",
* currrequirelist->header->name,
* currrequirelist->header->recursed,
* headerlist->name,headerlist->recursed); */
recrequirelist =
recurseRequireList(currrequirelist->header);
headerlist->requirelist =
mergeRequireLists(headerlist->requirelist,
recrequirelist);
} else {
/* printf("merging %s %d from %s %d\n",
* currrequirelist->header->name,
* currrequirelist->header->recursed,
* headerlist->name,headerlist->recursed); */
headerlist->requirelist =
mergeRequireLists(headerlist->requirelist,
currrequirelist->header->
requirelist);
}
currrequirelist = currrequirelist->next;
}
}
return headerlist->requirelist;
}
int
printRequireList(FILE *f, struct requireList *requirelist)
{
while (requirelist) {
fprintf(f,"%s ", requirelist->header->name);
requirelist = requirelist->next;
}
return 0;
}