1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-15 04:28:05 +02:00

qpkg: sort package version list such that highest comes first

- Makefile (OBJS_qpkg): added fixup.o
- fixup.h, fixup.c (sort_versions): sort package versions
- qpkg.c (do_fixups, main): do fixups when done gobbling
- qpkg.h: need to include id.h to be self-contained
- test/sortver: test version sorting
This commit is contained in:
Werner Almesberger 2010-11-21 22:53:27 -03:00
parent b0c29c4d7a
commit c05e6d5dbb
6 changed files with 219 additions and 1 deletions

View File

@ -12,7 +12,7 @@
SHELL = /bin/bash
OBJS_qpkg = gobble.o id.o prereq.o qpkg.o jrb.o
OBJS_qpkg = fixup.o gobble.o id.o prereq.o qpkg.o jrb.o
OBJS_rbtest = rbtest.o jrb.o
OBJS = $(OBJS_qpkg) $(OBJS_rbtest)

42
qpkg/fixup.c Normal file
View File

@ -0,0 +1,42 @@
/*
* fixup.c - Adjust things after parsing is done
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
*
* This program 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 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include "jrb.h"
#include "qpkg.h"
#include "fixup.h"
void sort_versions(void)
{
const struct jrb *n;
struct pkg **a, **b;
struct pkg *tmp;
for (n = jrb_first(packages->root); n != jrb_nil(packages->root);
n = jrb_next(n))
for (a = (struct pkg **) &n->val; *a; a = &(*a)->more)
for (b = &(*a)->more; *b;)
if (comp_versions((*a)->version,
(*b)->version) >= 0)
b = &(*b)->more;
else {
tmp = *a;
*a = *b;
*b = tmp;
tmp = (*a)->more;
(*a)->more = (*b)->more;
(*b)->more = tmp;
}
}

18
qpkg/fixup.h Normal file
View File

@ -0,0 +1,18 @@
/*
* fixup.c - Adjust things after parsing is done
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
*
* This program 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 of the License, or
* (at your option) any later version.
*/
#ifndef FIXUP_H
#define FIXUP_H
void sort_versions(void);
#endif /* !FIXUP_H */

View File

@ -20,6 +20,7 @@
#include "id.h"
#include "prereq.h"
#include "gobble.h"
#include "fixup.h"
#include "qpkg.h"
@ -116,6 +117,12 @@ static void find_prereq(const char *name, const char *version)
}
static void do_fixups(void)
{
sort_versions();
}
static void usage(const char *name)
{
fprintf(stderr,
@ -145,6 +152,7 @@ int main(int argc, char **argv)
if (*argv[arg] == '-')
usage(*argv);
if (!strcmp(argv[arg], "list")) {
do_fixups();
switch (argc-arg) {
case 1:
list_all_packages();
@ -156,6 +164,7 @@ int main(int argc, char **argv)
usage(*argv);
}
} else if (!strcmp(argv[arg], "prereq")) {
do_fixups();
switch (argc-arg) {
case 2:
find_prereq(argv[arg+1], NULL);

View File

@ -13,6 +13,9 @@
#ifndef QPKG_H
#define QPKG_H
#include "id.h"
enum flags {
/* parse-time flags */
QPKG_INSTALLED = 1 << 0, /* installed on target */

146
qpkg/test/sortver Executable file
View File

@ -0,0 +1,146 @@
#!/bin/sh
. ./Common
###############################################################################
qpkg "sort versions 1 2 3" list <<EOF
Package: X
Version: 1
Architecture: test
Filename: X_1
Package: X
Version: 2
Architecture: test
Filename: X_2
Package: X
Version: 3
Architecture: test
Filename: X_3
EOF
expect <<EOF
X (3) +++
X (2) +++
X (1)
EOF
###############################################################################
qpkg "sort versions 1 3 2" list <<EOF
Package: X
Version: 1
Architecture: test
Filename: X_1
Package: X
Version: 3
Architecture: test
Filename: X_3
Package: X
Version: 2
Architecture: test
Filename: X_2
EOF
expect <<EOF
X (3) +++
X (2) +++
X (1)
EOF
###############################################################################
qpkg "sort versions 2 1 3" list <<EOF
Package: X
Version: 2
Architecture: test
Filename: X_2
Package: X
Version: 1
Architecture: test
Filename: X_1
Package: X
Version: 3
Architecture: test
Filename: X_3
EOF
expect <<EOF
X (3) +++
X (2) +++
X (1)
EOF
###############################################################################
qpkg "sort versions 2 3 1" list <<EOF
Package: X
Version: 2
Architecture: test
Filename: X_2
Package: X
Version: 3
Architecture: test
Filename: X_3
Package: X
Version: 1
Architecture: test
Filename: X_1
EOF
expect <<EOF
X (3) +++
X (2) +++
X (1)
EOF
###############################################################################
qpkg "sort versions 3 1 2" list <<EOF
Package: X
Version: 3
Architecture: test
Filename: X_3
Package: X
Version: 1
Architecture: test
Filename: X_1
Package: X
Version: 2
Architecture: test
Filename: X_2
EOF
expect <<EOF
X (3) +++
X (2) +++
X (1)
EOF
###############################################################################
qpkg "sort versions 3 2 1" list <<EOF
Package: X
Version: 3
Architecture: test
Filename: X_3
Package: X
Version: 2
Architecture: test
Filename: X_2
Package: X
Version: 1
Architecture: test
Filename: X_1
EOF
expect <<EOF
X (3) +++
X (2) +++
X (1)
EOF