Mercurial > hg > octave-nkf
changeset 17028:89acf2cd9149
Simplify the way pkg checks for dependencies.
* scripts/pkg/fix_depends.m: use regexp to verify correctness
of version strings.
* scripts/pkg/fix_version: use regexp to verify correctness
of version strings.
author | Carlo de Falco <cdf@users.sourceforge.net> |
---|---|
date | Sat, 20 Jul 2013 13:01:45 +0200 |
parents | e0cd6299842c |
children | 359c5ca795cd |
files | scripts/pkg/private/fix_depends.m scripts/pkg/private/fix_version.m |
diffstat | 2 files changed, 39 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/pkg/private/fix_depends.m +++ b/scripts/pkg/private/fix_depends.m @@ -28,38 +28,40 @@ function deps_cell = fix_depends (depends) deps = strtrim (ostrsplit (tolower (depends), ",")); deps_cell = cell (1, length (deps)); + dep_pat = ... + '\s*(?<name>\w+)+\s*(\(\s*(?<op>[<>=]+)\s*(?<ver>\d+\.\d+(\.\d+)*)\s*\))*\s*'; ## For each dependency. for i = 1:length (deps) dep = deps{i}; - lpar = find (dep == "("); - rpar = find (dep == ")"); - ## Does the dependency specify a version - ## Example: package(>= version). - if (length (lpar) == 1 && length (rpar) == 1) - package = tolower (strtrim (dep(1:lpar-1))); - sub = dep(lpar(1)+1:rpar(1)-1); - parts = strsplit (sub, " ", true); - if (length (parts) != 2) - error ("incorrect syntax for dependency '%s' in the DESCRIPTION file\n", - dep); + [start, nm] = regexp (dep, dep_pat, 'start', 'names'); + ## Is the dependency specified + ## in the correct format? + if (! isempty (start)) + package = tolower (strtrim (nm.name)); + ## Does the dependency specify a version + ## Example: package(>= version). + if (! isempty (nm.ver)) + operator = nm.op; + if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) + error ("unsupported operator: %s", operator); + endif + version = fix_version (nm.ver); + ## If no version is specified for the dependency + ## we say that the version should be greater than + ## or equal to "0.0.0". + else + package = tolower (strtrim (dep)); + operator = ">="; + version = "0.0.0"; endif - operator = parts{1}; - if (! any (strcmp (operator, {">", ">=", "<=", "<", "=="}))) - error ("unsupported operator: %s", operator); - endif - version = fix_version (parts{2}); - - ## If no version is specified for the dependency - ## we say that the version should be greater than - ## or equal to "0.0.0". - else - package = tolower (strtrim (dep)); - operator = ">="; - version = "0.0.0"; - endif - deps_cell{i} = struct ("package", package, "operator", operator, - "version", version); + deps_cell{i} = struct ("package", package, + "operator", operator, + "version", version); + else + error ("incorrect syntax for dependency '%s' in the DESCRIPTION file\n", + dep); + endif endfor endfunction
--- a/scripts/pkg/private/fix_version.m +++ b/scripts/pkg/private/fix_version.m @@ -25,23 +25,17 @@ ## Make sure the version string v is a valid x.y.z version string ## Examples: "0.1" => "0.1.0", "monkey" => error(...). function out = fix_version (v) - dots = find (v == "."); - if (length (dots) == 1) - major = str2num (v(1:dots-1)); - minor = str2num (v(dots+1:end)); - if (length (major) != 0 && length (minor) != 0) - out = sprintf ("%d.%d.0", major, minor); - return; + + if (regexp (v, '^\d+(\.\d+){1,2}$') == 1) + parts = ostrsplit (v, '.', true); + if (numel (parts) == 2) + out = strcat (v, ".0"); + else + out = v; endif - elseif (length (dots) == 2) - major = str2num (v(1:dots(1)-1)); - minor = str2num (v(dots(1)+1:dots(2)-1)); - rev = str2num (v(dots(2)+1:end)); - if (length (major) != 0 && length (minor) != 0 && length (rev) != 0) - out = sprintf ("%d.%d.%d", major, minor, rev); - return; - endif + else + error ("bad version string: %s", v); endif - error ("bad version string: %s", v); + endfunction