[Dctrl-tools-devel] CVS dctrl-tools
CVS User ajk
ajk@haydn.debian.org
Wed, 08 Jun 2005 20:52:19 +0000
Update of /cvsroot/dctrl-tools/dctrl-tools
In directory haydn:/tmp/cvs-serv8744
Modified Files:
Makefile predicate.c sort-dctrl.c sorter.c sorter.h
Added Files:
version.c version.h
Log Message:
Add option -k to sort-dctrl
--- /cvsroot/dctrl-tools/dctrl-tools/version.h 2003/08/10 13:52:51 1.2
+++ /cvsroot/dctrl-tools/dctrl-tools/version.h 2005/06/08 20:52:19 1.3
@@ -1,2 +1,62 @@
-#define VERSION "0.10"
-#define COPYING "/usr/doc/copyright/GPL"
+/* dctrl-tools - Debian control file inspection tools
+ Copyright © 2005 Antti-Juhani Kaijanaho
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; 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
+ */
+
+// Marked portions of this file are covered by the following
+// copyright:
+/*
+ * libdpkg - Debian packaging suite library routines
+ * vercmp.c - comparison of version numbers
+ *
+ * Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ *
+ * This 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,
+ * or (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; 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 dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef VERSION_H
+#define VERSION_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+struct versionrevision { // from dpkg
+ unsigned long epoch;
+ char *version;
+ char *revision;
+};
+
+// from dpkg
+int versioncompare(const struct versionrevision *version,
+ const struct versionrevision *refversion);
+
+/* warning: modifies ver by adding nul chars; return pointers point
+ * inside ver. */
+bool parse_version(struct versionrevision *rv, char *ver, size_t len);
+
+#endif /* VERSION_H */
--- /cvsroot/dctrl-tools/dctrl-tools/Makefile 2005/06/08 18:13:29 1.23
+++ /cvsroot/dctrl-tools/dctrl-tools/Makefile 2005/06/08 20:52:18 1.24
@@ -17,7 +17,7 @@
libobj = misc.o msg.o predicate.o util.o fsaf.o paragraph.o \
fieldtrie.o rc.o strutil.o getaline.o fnutil.o para_pool.o \
- ifile.o para_bundle.o sorter.o
+ ifile.o para_bundle.o sorter.o version.o
obj = $(libobj) grep-dctrl.o sort-dctrl.o
src = $(obj:.o=.c)
--- /cvsroot/dctrl-tools/dctrl-tools/predicate.c 2005/06/08 18:13:29 1.17
+++ /cvsroot/dctrl-tools/dctrl-tools/predicate.c 2005/06/08 20:52:19 1.18
@@ -14,36 +14,8 @@
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
-
-
*/
-// Marked portions of this file are covered by the following
-// copyright:
-/*
- * libdpkg - Debian packaging suite library routines
- * vercmp.c - comparison of version numbers
- * utils.c - Helper functions for dpkg
- *
- * Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
- * Copyright (C) 2001 Wichert Akkerman <wakkerma@debian.org>
- *
- * This 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,
- * or (at your option) any later version.
- *
- * This is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; 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 dpkg; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-
#include <ctype.h>
#include <stdlib.h>
#include <regex.h>
@@ -53,6 +25,7 @@
#include "util.h"
#include "predicate.h"
#include "strutil.h"
+#include "version.h"
void init_predicate(struct predicate * p)
{
@@ -97,124 +70,6 @@
}
-/* <<<<<<< originally from dpkg >>>>>>> */
-
-struct versionrevision {
- unsigned long epoch;
- char *version;
- char *revision;
-};
-
-/* Reimplementation of the standard ctype.h is* functions. Since gettext
- * has overloaded the meaning of LC_CTYPE we can't use that to force C
- * locale, so use these cis* functions instead.
- */
-static int cisdigit(int c) {
- return (c>='0') && (c<='9');
-}
-
-static int cisalpha(int c) {
- return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z'));
-}
-
-/* assume ascii; warning: evaluates x multiple times! */
-#define order(x) ((x) == '~' ? -1 \
- : cisdigit((x)) ? 0 \
- : !(x) ? 0 \
- : cisalpha((x)) ? (x) \
- : (x) + 256)
-
-static int verrevcmp(const char *val, const char *ref) {
- if (!val) val= "";
- if (!ref) ref= "";
-
- while (*val || *ref) {
- int first_diff= 0;
-
- while ( (*val && !cisdigit(*val)) || (*ref && !cisdigit(*ref)) ) {
- int vc= order(*val), rc= order(*ref);
- if (vc != rc) return vc - rc;
- val++; ref++;
- }
-
- while ( *val == '0' ) val++;
- while ( *ref == '0' ) ref++;
- while (cisdigit(*val) && cisdigit(*ref)) {
- if (!first_diff) first_diff= *val - *ref;
- val++; ref++;
- }
- if (cisdigit(*val)) return 1;
- if (cisdigit(*ref)) return -1;
- if (first_diff) return first_diff;
- }
- return 0;
-}
-
-static int versioncompare(const struct versionrevision *version,
- const struct versionrevision *refversion) {
- int r;
-
- if (version->epoch > refversion->epoch) return 1;
- if (version->epoch < refversion->epoch) return -1;
- r= verrevcmp(version->version,refversion->version); if (r) return r;
- return verrevcmp(version->revision,refversion->revision);
-}
-
-/* <<<<<<< END OF originally from dpkg >>>>>>> */
-
-/* warning: modifies ver by adding nul chars; return pointers point
- * inside ver. */
-static bool parse_version(struct versionrevision *rv, char *ver, size_t len)
-{
- rv->version = strchr(ver, ':');
- if (rv->version == NULL) {
- rv->version = ver;
- } else {
- *(rv->version++) = '\0';
- }
- rv->revision = strrchr(ver, '-');
-
- if (rv->revision == NULL) {
- rv->revision = ver + len;
- } else {
- *(rv->revision++) = '\0';
- }
-
- if (rv->version != ver) {
- rv->epoch = 0;
- for (char *p = ver; *p != '\0'; p++) {
- if (!('0' <= *p && *p <= '9')) return false;
- rv->epoch = rv->epoch * 10 + (*p - '0');
- }
- } else {
- rv->epoch = 0;
- }
-
- for (char *p = rv->version; *p != '\0'; p++) {
- if (('a' <= *p && *p <= 'z') ||
- ('A' <= *p && *p <= 'Z') ||
- ('0' <= *p && *p <= '9') ||
- *p == '.' ||
- *p == '-' ||
- *p == '+' ||
- *p == ':' ||
- *p == '~') continue;
- return false;
- }
-
- for (char *p = rv->revision; *p != '\0'; p++) {
- if (('a' <= *p && *p <= 'z') ||
- ('A' <= *p && *p <= 'Z') ||
- ('0' <= *p && *p <= '9') ||
- *p == '.' ||
- *p == '+' ||
- *p == '~') continue;
- return false;
- }
-
- return true;
-}
-
static bool verify_atom(struct atom * atom, para_t * para)
{
size_t start, end;
--- /cvsroot/dctrl-tools/dctrl-tools/sort-dctrl.c 2005/06/08 18:13:29 1.5
+++ /cvsroot/dctrl-tools/dctrl-tools/sort-dctrl.c 2005/06/08 20:52:19 1.6
@@ -1,5 +1,5 @@
/* dctrl-tools - Debian control file inspection tools
- Copyright (C) 2004 Antti-Juhani Kaijanaho
+ Copyright (C) 2004, 2005 Antti-Juhani Kaijanaho
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
@@ -36,6 +36,7 @@
{ "errorlevel", 'l', N_("LEVEL"), 0, N_("Set debugging level to LEVEL.") },
{ "quiet", 'q', 0, 0, N_("Do no output to stdout.") },
{ "silent", OPT_SILENT, 0, 0, N_("Do no output to stdout.") },
+ { "key-spec", 'k', N_("KEYSPEC"), 0, N_("Specify sort keys.") },
{ 0 }
};
@@ -57,6 +58,39 @@
case 'C':
if (!to_stdout (COPYING)) fail();
exit(0);
+ case 'k':
+ {
+ char *carg = strdup(arg);
+ if (carg == 0) fatal_enomem(0);
+ for (char *s = strtok(carg, ","); s != 0; s = strtok(0, ",")) {
+ char *flags = strrchr(s, ':');
+ if (flags == 0) {
+ flags = "";
+ } else {
+ *(flags++) = '\0';
+ }
+ struct key key;
+ key.field_inx = fieldtrie_insert(carg);
+ key.type = FT_STRING;
+ key.reverse = false;
+ for (char *p = flags; *p != '\0'; p++) {
+ switch (*p) {
+ case 'r':
+ key.reverse = true;
+ break;
+ case 'v': case 'n':
+ key.type = FT_VERSION;
+ break;
+ default:
+ message(L_FATAL, _("invalid key flag"),
+ 0);
+ fail();
+ }
+ }
+ keys_append(&args->keys, key);
+ }
+ break;
+ }
case 'l':
{
int ll = str2loglevel(optarg);
@@ -114,6 +148,7 @@
if (args.keys.nks == 0) {
size_t inx = fieldtrie_insert("Package");
keys_append(&args.keys, (struct key){ .field_inx = inx,
+ .type = FT_STRING,
.reverse = false });
}
--- /cvsroot/dctrl-tools/dctrl-tools/sorter.c 2005/03/26 17:58:22 1.4
+++ /cvsroot/dctrl-tools/dctrl-tools/sorter.c 2005/06/08 20:52:19 1.5
@@ -20,6 +20,7 @@
#include "msg.h"
#include "sorter.h"
+#include "version.h"
//void keys_fini(keys_t *);
@@ -39,7 +40,24 @@
char * af = get_field_as(*a, keys->keys[i].field_inx);
char * bf = get_field_as(*b, keys->keys[i].field_inx);
if (af == 0 || bf == 0) fatal_enomem(0);
- r = strcmp(af, bf);
+ switch (keys->keys[i].type) {
+ case FT_STRING:
+ r = strcmp(af, bf);
+ break;
+ case FT_VERSION:
+ ;
+ struct versionrevision ar, br;
+ if (!parse_version(&ar, af, strlen(af)) ||
+ !parse_version(&br, bf, strlen(bf))) {
+ message(L_IMPORTANT,
+ _("Parse error in field."), 0);
+ free(af);
+ free(bf);
+ return 0;
+ }
+ r = versioncompare(&ar, &br);
+ break;
+ }
debug("cmp: a = %s, b = %s, verdict is %d", af, bf, r);
free(af);
free(bf);
--- /cvsroot/dctrl-tools/dctrl-tools/sorter.h 2005/03/26 17:58:22 1.4
+++ /cvsroot/dctrl-tools/dctrl-tools/sorter.h 2005/06/08 20:52:19 1.5
@@ -1,5 +1,5 @@
/* dctrl-tools - Debian control file inspection tools
- Copyright (C) 2004 Antti-Juhani Kaijanaho
+ Copyright (C) 2004, 2005 Antti-Juhani Kaijanaho
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
@@ -24,6 +24,7 @@
struct key {
int field_inx;
+ enum { FT_STRING, FT_VERSION } type;
bool reverse : 1;
};
--- /cvsroot/dctrl-tools/dctrl-tools/version.c 2005/06/08 20:52:19 NONE
+++ /cvsroot/dctrl-tools/dctrl-tools/version.c 2005/06/08 20:52:19 1.1
/* dctrl-tools - Debian control file inspection tools
Copyright © 2005 Antti-Juhani Kaijanaho
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; 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
*/
// Marked portions of this file are covered by the following
// copyright:
/*
* libdpkg - Debian packaging suite library routines
* vercmp.c - comparison of version numbers
* utils.c - Helper functions for dpkg
*
* Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
* Copyright (C) 2001 Wichert Akkerman <wakkerma@debian.org>
*
* This 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,
* or (at your option) any later version.
*
* This is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; 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 dpkg; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
#include "version.h"
/* <<<<<<< originally from dpkg >>>>>>> */
/* Reimplementation of the standard ctype.h is* functions. Since gettext
* has overloaded the meaning of LC_CTYPE we can't use that to force C
* locale, so use these cis* functions instead.
*/
static int cisdigit(int c) {
return (c>='0') && (c<='9');
}
static int cisalpha(int c) {
return ((c>='a') && (c<='z')) || ((c>='A') && (c<='Z'));
}
/* assume ascii; warning: evaluates x multiple times! */
#define order(x) ((x) == '~' ? -1 \
: cisdigit((x)) ? 0 \
: !(x) ? 0 \
: cisalpha((x)) ? (x) \
: (x) + 256)
static int verrevcmp(const char *val, const char *ref) {
if (!val) val= "";
if (!ref) ref= "";
while (*val || *ref) {
int first_diff= 0;
while ( (*val && !cisdigit(*val)) || (*ref && !cisdigit(*ref)) ) {
int vc= order(*val), rc= order(*ref);
if (vc != rc) return vc - rc;
val++; ref++;
}
while ( *val == '0' ) val++;
while ( *ref == '0' ) ref++;
while (cisdigit(*val) && cisdigit(*ref)) {
if (!first_diff) first_diff= *val - *ref;
val++; ref++;
}
if (cisdigit(*val)) return 1;
if (cisdigit(*ref)) return -1;
if (first_diff) return first_diff;
}
return 0;
}
int versioncompare(const struct versionrevision *version,
const struct versionrevision *refversion) {
int r;
if (version->epoch > refversion->epoch) return 1;
if (version->epoch < refversion->epoch) return -1;
r= verrevcmp(version->version,refversion->version); if (r) return r;
return verrevcmp(version->revision,refversion->revision);
}
/* <<<<<<< END OF originally from dpkg >>>>>>> */
/* warning: modifies ver by adding nul chars; return pointers point
* inside ver. */
bool parse_version(struct versionrevision *rv, char *ver, size_t len)
{
rv->version = strchr(ver, ':');
if (rv->version == NULL) {
rv->version = ver;
} else {
*(rv->version++) = '\0';
}
rv->revision = strrchr(ver, '-');
if (rv->revision == NULL) {
rv->revision = ver + len;
} else {
*(rv->revision++) = '\0';
}
if (rv->version != ver) {
rv->epoch = 0;
for (char *p = ver; *p != '\0'; p++) {
if (!('0' <= *p && *p <= '9')) return false;
rv->epoch = rv->epoch * 10 + (*p - '0');
}
} else {
rv->epoch = 0;
}
for (char *p = rv->version; *p != '\0'; p++) {
if (('a' <= *p && *p <= 'z') ||
('A' <= *p && *p <= 'Z') ||
('0' <= *p && *p <= '9') ||
*p == '.' ||
*p == '-' ||
*p == '+' ||
*p == ':' ||
*p == '~') continue;
return false;
}
for (char *p = rv->revision; *p != '\0'; p++) {
if (('a' <= *p && *p <= 'z') ||
('A' <= *p && *p <= 'Z') ||
('0' <= *p && *p <= '9') ||
*p == '.' ||
*p == '+' ||
*p == '~') continue;
return false;
}
return true;
}