| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: dewey.c,v 1.12 2022/07/30 08:41:25 rillig Exp $ */ | | 1 | /* $NetBSD: dewey.c,v 1.13 2022/07/30 08:53:42 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2002 Alistair G. Crooks. All rights reserved. | | 4 | * Copyright (c) 2002 Alistair G. Crooks. All rights reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * 3. The name of the author may not be used to endorse or promote | | 14 | * 3. The name of the author may not be used to endorse or promote |
| @@ -37,58 +37,58 @@ | | | @@ -37,58 +37,58 @@ |
37 | #include <ctype.h> | | 37 | #include <ctype.h> |
38 | #endif | | 38 | #endif |
39 | #if HAVE_STDLIB_H | | 39 | #if HAVE_STDLIB_H |
40 | #include <stdlib.h> | | 40 | #include <stdlib.h> |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include "defs.h" | | 43 | #include "defs.h" |
44 | #include "dewey.h" | | 44 | #include "dewey.h" |
45 | | | 45 | |
46 | #define PKG_PATTERN_MAX 1024 | | 46 | #define PKG_PATTERN_MAX 1024 |
47 | | | 47 | |
48 | /* do not modify these values, or things will NOT work */ | | 48 | /* do not modify these values, or things will NOT work */ |
49 | enum { | | 49 | enum { |
50 | Alpha = -3, | | 50 | Alpha = -3, |
51 | Beta = -2, | | 51 | Beta = -2, |
52 | RC = -1, | | 52 | RC = -1, |
53 | Dot = 0, | | 53 | Dot = 0, |
54 | Patch = 1 | | 54 | Patch = 1 |
55 | }; | | 55 | }; |
56 | | | 56 | |
57 | /* this struct defines a version number */ | | 57 | /* this struct defines a version number */ |
58 | typedef struct arr_t { | | 58 | typedef struct arr_t { |
59 | unsigned c; /* # of version numbers */ | | 59 | unsigned c; /* # of version numbers */ |
60 | unsigned size; /* size of array */ | | 60 | unsigned size; /* size of array */ |
61 | int *v; /* array of decimal numbers */ | | 61 | int *v; /* array of decimal numbers */ |
62 | int netbsd; /* any "nb" suffix */ | | 62 | int netbsd; /* any "nb" suffix */ |
63 | } arr_t; | | 63 | } arr_t; |
64 | | | 64 | |
65 | /* this struct describes a test */ | | 65 | /* this struct describes a test */ |
66 | typedef struct test_t { | | 66 | typedef struct test_t { |
67 | const char *s; /* string representation */ | | 67 | const char *s; /* string representation */ |
68 | unsigned len; /* length of string */ | | 68 | unsigned len; /* length of string */ |
69 | int t; /* enumerated type of test */ | | 69 | int t; /* enumerated type of test */ |
70 | } test_t; | | 70 | } test_t; |
71 | | | 71 | |
72 | | | 72 | |
73 | /* the tests that are recognised. */ | | 73 | /* the tests that are recognised. */ |
74 | const test_t tests[] = { | | 74 | const test_t tests[] = { |
75 | { "<=", 2, DEWEY_LE }, | | 75 | { "<=", 2, DEWEY_LE }, |
76 | { "<", 1, DEWEY_LT }, | | 76 | { "<", 1, DEWEY_LT }, |
77 | { ">=", 2, DEWEY_GE }, | | 77 | { ">=", 2, DEWEY_GE }, |
78 | { ">", 1, DEWEY_GT }, | | 78 | { ">", 1, DEWEY_GT }, |
79 | { "==", 2, DEWEY_EQ }, | | 79 | { "==", 2, DEWEY_EQ }, |
80 | { "!=", 2, DEWEY_NE }, | | 80 | { "!=", 2, DEWEY_NE }, |
81 | { NULL, 0, 0 } | | 81 | { NULL, 0, 0 } |
82 | }; | | 82 | }; |
83 | | | 83 | |
84 | const test_t modifiers[] = { | | 84 | const test_t modifiers[] = { |
85 | { "alpha", 5, Alpha }, | | 85 | { "alpha", 5, Alpha }, |
86 | { "beta", 4, Beta }, | | 86 | { "beta", 4, Beta }, |
87 | { "pre", 3, RC }, | | 87 | { "pre", 3, RC }, |
88 | { "rc", 2, RC }, | | 88 | { "rc", 2, RC }, |
89 | { "pl", 2, Dot }, | | 89 | { "pl", 2, Dot }, |
90 | { "_", 1, Dot }, | | 90 | { "_", 1, Dot }, |
91 | { ".", 1, Dot }, | | 91 | { ".", 1, Dot }, |
92 | { NULL, 0, 0 } | | 92 | { NULL, 0, 0 } |
93 | }; | | 93 | }; |
94 | | | 94 | |
| @@ -242,27 +242,27 @@ vtest(arr_t *lhs, int tst, arr_t *rhs) | | | @@ -242,27 +242,27 @@ vtest(arr_t *lhs, int tst, arr_t *rhs) |
242 | int | | 242 | int |
243 | dewey_cmp(const char *lhs, int op, const char *rhs) | | 243 | dewey_cmp(const char *lhs, int op, const char *rhs) |
244 | { | | 244 | { |
245 | arr_t right; | | 245 | arr_t right; |
246 | arr_t left; | | 246 | arr_t left; |
247 | int retval; | | 247 | int retval; |
248 | | | 248 | |
249 | if (!mkversion(&left, lhs)) | | 249 | if (!mkversion(&left, lhs)) |
250 | return 0; | | 250 | return 0; |
251 | if (!mkversion(&right, rhs)) { | | 251 | if (!mkversion(&right, rhs)) { |
252 | freeversion(&left); | | 252 | freeversion(&left); |
253 | return 0; | | 253 | return 0; |
254 | } | | 254 | } |
255 | retval = vtest(&left, op, &right); | | 255 | retval = vtest(&left, op, &right); |
256 | freeversion(&left); | | 256 | freeversion(&left); |
257 | freeversion(&right); | | 257 | freeversion(&right); |
258 | return retval; | | 258 | return retval; |
259 | } | | 259 | } |
260 | | | 260 | |
261 | /* | | 261 | /* |
262 | * Perform dewey match on "pkg" against "pattern". | | 262 | * Perform dewey match on "pkg" against "pattern". |
263 | * Return 1 on match, 0 on non-match, -1 on error. | | 263 | * Return 1 on match, 0 on non-match, -1 on error. |
264 | */ | | 264 | */ |
265 | int | | 265 | int |
266 | dewey_match(const char *pattern, const char *pkg) | | 266 | dewey_match(const char *pattern, const char *pkg) |
267 | { | | 267 | { |
268 | const char *version; | | 268 | const char *version; |
| @@ -273,29 +273,29 @@ dewey_match(const char *pattern, const c | | | @@ -273,29 +273,29 @@ dewey_match(const char *pattern, const c |
273 | /* compare names */ | | 273 | /* compare names */ |
274 | if ((version=strrchr(pkg, '-')) == NULL) { | | 274 | if ((version=strrchr(pkg, '-')) == NULL) { |
275 | return 0; | | 275 | return 0; |
276 | } | | 276 | } |
277 | if ((sep = strpbrk(pattern, "<>")) == NULL) | | 277 | if ((sep = strpbrk(pattern, "<>")) == NULL) |
278 | return -1; | | 278 | return -1; |
279 | /* compare name lengths */ | | 279 | /* compare name lengths */ |
280 | if ((sep-pattern != version-pkg) || | | 280 | if ((sep-pattern != version-pkg) || |
281 | strncmp(pkg, pattern, (size_t)(version-pkg)) != 0) | | 281 | strncmp(pkg, pattern, (size_t)(version-pkg)) != 0) |
282 | return 0; | | 282 | return 0; |
283 | version++; | | 283 | version++; |
284 | | | 284 | |
285 | /* extract comparison operator */ | | 285 | /* extract comparison operator */ |
286 | if ((n = dewey_mktest(&op, sep)) < 0) { | | 286 | if ((n = dewey_mktest(&op, sep)) < 0) { |
287 | return 0; | | 287 | return 0; |
288 | } | | 288 | } |
289 | /* skip operator */ | | 289 | /* skip operator */ |
290 | sep += n; | | 290 | sep += n; |
291 | | | 291 | |
292 | /* if greater than, look for less than */ | | 292 | /* if greater than, look for less than */ |
293 | sep2 = NULL; | | 293 | sep2 = NULL; |
294 | if (op == DEWEY_GT || op == DEWEY_GE) { | | 294 | if (op == DEWEY_GT || op == DEWEY_GE) { |
295 | if ((sep2 = strchr(sep, '<')) != NULL) { | | 295 | if ((sep2 = strchr(sep, '<')) != NULL) { |
296 | if ((n = dewey_mktest(&op2, sep2)) < 0) { | | 296 | if ((n = dewey_mktest(&op2, sep2)) < 0) { |
297 | return 0; | | 297 | return 0; |
298 | } | | 298 | } |
299 | /* compare upper limit */ | | 299 | /* compare upper limit */ |
300 | if (!dewey_cmp(version, op2, sep2+n)) | | 300 | if (!dewey_cmp(version, op2, sep2+n)) |
301 | return 0; | | 301 | return 0; |