diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-05 14:09:48 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-05 14:39:29 +0300 |
commit | 6c3f6c1b02dd5f9ac343c713bdae4aa83bafc328 (patch) | |
tree | 49bc8df1cff7157c711c63447c3e272ebc67cd4c /src/version.c | |
parent | a60eb4b18345626a84e23784d77ca231812e1dff (diff) | |
download | grecs-6c3f6c1b02dd5f9ac343c713bdae4aa83bafc328.tar.gz grecs-6c3f6c1b02dd5f9ac343c713bdae4aa83bafc328.tar.bz2 |
Improve node formatting. Add version comparasion functions.
* am/grecs.m4 (GRECS_SETUP): New option: shared.
* doc/GRECS_SETUP.3: Document new options.
* doc/grecs_format_locus.3: Update.
* doc/grecs_format_node.3: Document new flags.
* src/.gitignore: Update.
* src/version.c: New file.
* src/Make.am (GRECS_SRC): Add version.c
(EXTRA_DIST): Update.
* src/diag.c (default_print_diag): Flush stdout as per the docs.
* src/format.c (grecs_format_locus): Don't print trailing semicolon.
(grecs_format_value): Handle GRECS_NODE_FLAG_NOQUOTE flag.
(grecs_format_node): Print delimiters when needed.
* src/grecs.h (grecs_version_info): New struct.
(grecs_version, grecs_version_cmp): New protos.
(GRECS_NODE_FLAG_NOQUOTE): New flag.
* tests/gcfver.c: New file.
* tests/vercmp.at: New file.
* tests/.gitignore: Update.
* tests/Makefile.am: Define GRECS_VERCMP_AT in package.m4
(TESTSUITE_AT): Add vercmp.at (conditionally).
(noinst_PROGRAMS): Add gcfver.
* tests/testsuite.at: Conditionally include vercmp.at.
Diffstat (limited to 'src/version.c')
-rw-r--r-- | src/version.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..d34b8b5 --- /dev/null +++ b/src/version.c @@ -0,0 +1,86 @@ +/* grecs - Gray's Extensible Configuration System + Copyright (C) 2007-2011 Sergey Poznyakoff + + Grecs 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 3 of the License, or (at your + option) any later version. + + Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <grecs.h> +#include <string.h> +#include <ctype.h> + +void +grecs_version(struct grecs_version_info *pv) +{ + char *p; + memset(pv, 0, sizeof(*pv)); + pv->package = PACKAGE_NAME; + pv->version = PACKAGE_VERSION; + pv->major = strtoul(pv->version, &p, 10); + if (*p && *p == '.') { + pv->minor = strtoul(p + 1, &p, 10); + if (*p && *p == '.') { + char *q; + + pv->patch = strtoul(p + 1, &q, 10); + if (q == p + 1) + pv->patch = 0; + else + p = q; + } + } + pv->suffix = p; +} + +int +grecs_version_cmp(const char *vstr) +{ + struct grecs_version_info v; + char *p; + unsigned long n; + size_t len; + int check; + + if (!vstr) + return -1; + grecs_version(&v); + len = strcspn(vstr, " \t"); + if (vstr[len]) { + if (len != strlen(v.package) || memcmp(v.package, vstr, len)) + return 1; + for (vstr += len; *vstr && isspace(*vstr); vstr++) + ; + } + if (!*vstr) + return 1; + n = strtoul(vstr, &p, 10); + if (n > v.major) + return 1; + check = n == v.major; + if (*p && *p == '.') { + n = strtoul(p + 1, &p, 10); + if (check && n > v.minor) + return 1; + check = n == v.minor; + if (*p && *p == '.') { + n = strtoul(p + 1, &p, 10); + if (check && n > v.patch) + return 1; + } + } + if (*p && (!v.suffix || strcmp(p, v.suffix))) + return 1; + return 0; +} |