diff host/libcdl/cdlmisc.cxx @ 103:95f3e12a6327 ecos-sw-2000-06-23

Merge from eCos master repository on 2000-06-23-16:41:10-BST
author jlarmour
date Fri, 23 Jun 2000 17:06:31 +0000
parents 6736c52df507
children
line wrap: on
line diff
--- a/host/libcdl/cdlmisc.cxx
+++ b/host/libcdl/cdlmisc.cxx
@@ -846,7 +846,7 @@ Cdl::is_interactive(void)
 }
 
 //}}}
-//{{{  Cdl::compare_versions()                                  
+//{{{  version support()                                        
 
 // ----------------------------------------------------------------------------
 // Packages may need to impose constraints on which versions of other
@@ -1013,6 +1013,49 @@ Cdl::compare_versions(std::string arg1, 
     // Not reachable.
 }
 
+// ----------------------------------------------------------------------------
+// Given a version string, extract major, minor and release numbers.
+// Some or all of these may be absent. Basically the code just
+// iterates through the string looking for sequences of numbers.
+
+static void
+version_extract_number(const std::string& version, unsigned int& index, std::string& result)
+{
+    CYG_REPORT_FUNCNAME("version_extract_number");
+
+    // The calling code is expected to supply a sensible default.
+    // Search for a digit
+    for ( ; index < version.size(); index++) {
+        if (isdigit(version[index])) {
+            break;
+        }
+    }
+    if (index != version.size()) {
+        result = "";
+        if ((index > 0) && ('-' == version[index-1])) {
+            result = "-";
+        }
+        do {
+            result += version[index++];
+        } while ((index < version.size()) && isdigit(version[index]));
+    }
+    
+    CYG_REPORT_RETURN();
+}
+
+void
+Cdl::split_version_string(const std::string& version, std::string& major, std::string& minor, std::string& release)
+{
+    CYG_REPORT_FUNCNAME("CdlMisc::split_version_string");
+
+    unsigned int index = 0;
+    version_extract_number(version, index, major);
+    version_extract_number(version, index, minor);
+    version_extract_number(version, index, release);
+    
+    CYG_REPORT_RETURN();
+}
+
 //}}}
 //{{{  Cdl::get_short_form()