Date:2010-11-22 01:14:04 (8 years 7 months ago)
Author:Werner Almesberger
Commit:dd8bb6eecdbc1778e81a8bfad84b3b47d8a7d7a6
Message:qpkg: moved comp_versions from prereq.c to id.c

- id.c: added section titles
- prereq.c (comp_versions), id.h, id.c: moved comp_versions from prereq.c
to id.c, to allow sharing with other code
Files: qpkg/id.c (3 diffs)
qpkg/id.h (1 diff)
qpkg/prereq.c (2 diffs)

Change Details

qpkg/id.c
1212
1313
1414#include <string.h>
15#include <ctype.h>
1516
1617#include "jrb.h"
1718
...... 
2223static struct id *free_id = NULL;
2324
2425
26/* ----- ID comparison (regular string compare) ---------------------------- */
27
28
2529static int do_comp_id(const struct id *a, const struct id *b)
2630{
2731    int len = a->len < b->len ? a->len : b->len;
...... 
3943    return do_comp_id(a, b);
4044}
4145
46
47/* ----- Version comparison ------------------------------------------------ */
48
49
50static int epoch(const char **s, const struct id *id)
51{
52    const char *end = id->s+id->len;
53    int n = 0;
54
55    while (*s != end && isdigit(**s)) {
56        n = 10*n+**s-'0';
57        (*s)++;
58    }
59    if (*s == id->s || (*s != end && **s == ':'))
60        return n;
61    *s = id->s;
62    return 0;
63}
64
65
66int comp_versions(const struct id *va, const struct id *vb)
67{
68    int epoch_a = 0, epoch_b = 0;
69    const char *a = va->s;
70    const char *b = vb->s;
71    const char *ea = a+va->len;
72    const char *eb = b+vb->len;
73
74    epoch_a = epoch(&a, va);
75    epoch_b = epoch(&b, vb);
76    if (epoch_a != epoch_b)
77        return epoch_a-epoch_b;
78
79    while (1) {
80        if (a == ea || b == eb)
81            return (a != ea)-(b != eb);
82        if (isdigit(*a) && isdigit(*b)) {
83            int na = 0, nb = 0;
84
85            while (a != ea && isdigit(*a)) {
86                na = na*10+*a-'0';
87                a++;
88            }
89            while (b != eb && isdigit(*b)) {
90                nb = nb*10+*b-'0';
91                b++;
92            }
93            if (na == nb)
94                continue;
95
96            return na-nb;
97        }
98        if (*a > *b)
99            return 1;
100        if (*a < *b)
101            return 1;
102        a++;
103        b++;
104    }
105}
106
107
108/* ----- Tree maintenance -------------------------------------------------- */
109
110
42111struct tree *make_tree(int (*comp)(const void *a, const void *b))
43112{
44113    struct tree *tree;
qpkg/id.h
6868
6969
7070int comp_id(const void *a, const void *b);
71int comp_versions(const struct id *va, const struct id *vb);
7172
7273struct tree *make_tree(int (*comp)(const void *a, const void *b));
7374struct jrb *make_id(struct tree *tree, const char *s, size_t len);
qpkg/prereq.c
1414#include <stdlib.h>
1515#include <stdio.h>
1616#include <string.h>
17#include <ctype.h>
1817#include <assert.h>
1918
2019#include "id.h"
...... 
4140static int install_max = 0;
4241
4342
44/* ----- Version comparison ------------------------------------------------ */
45
46
47static int epoch(const char **s, const struct id *id)
48{
49    const char *end = id->s+id->len;
50    int n = 0;
51
52    while (*s != end && isdigit(**s)) {
53        n = 10*n+**s-'0';
54        (*s)++;
55    }
56    if (*s == id->s || (*s != end && **s == ':'))
57        return n;
58    *s = id->s;
59    return 0;
60}
61
62
63static int comp_versions(const struct id *va, const struct id *vb)
64{
65    int epoch_a = 0, epoch_b = 0;
66    const char *a = va->s;
67    const char *b = vb->s;
68    const char *ea = a+va->len;
69    const char *eb = b+vb->len;
70
71    epoch_a = epoch(&a, va);
72    epoch_b = epoch(&b, vb);
73    if (epoch_a != epoch_b)
74        return epoch_a-epoch_b;
75
76    while (1) {
77        if (a == ea || b == eb)
78            return (a != ea)-(b != eb);
79        if (isdigit(*a) && isdigit(*b)) {
80            int na = 0, nb = 0;
81
82            while (a != ea && isdigit(*a)) {
83                na = na*10+*a-'0';
84                a++;
85            }
86            while (b != eb && isdigit(*b)) {
87                nb = nb*10+*b-'0';
88                b++;
89            }
90            if (na == nb)
91                continue;
92
93            return na-nb;
94        }
95        if (*a > *b)
96            return 1;
97        if (*a < *b)
98            return 1;
99        a++;
100        b++;
101    }
102}
103
104
10543/* ----- List of packages considered for installation ---------------------- */
10644
10745

Archive Download the corresponding diff file

Branches:
master



interactive