Revision: 76773
          http://sourceforge.net/p/brlcad/code/76773
Author:   brlcad
Date:     2020-08-15 04:15:00 +0000 (Sat, 15 Aug 2020)
Log Message:
-----------
expand bu_units_conversion() to also match conversion value so that callers may 
specify '4ft' for example, and it will evaluate to the corresponding conversion 
factor.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/units.c

Modified: brlcad/trunk/src/libbu/units.c
===================================================================
--- brlcad/trunk/src/libbu/units.c      2020-08-15 02:33:03 UTC (rev 76772)
+++ brlcad/trunk/src/libbu/units.c      2020-08-15 04:15:00 UTC (rev 76773)
@@ -241,17 +241,29 @@
 double
 bu_units_conversion(const char *str)
 {
-    register const struct cvt_tab *tp;
-    register const struct conv_table *cvtab;
+    const struct cvt_tab *tp;
+    const struct conv_table *cvtab;
+    double factor = 1.0;
 
-    /* Search for this string in the table */
+    /* Search for the units string in the table matching by name. */
     for (cvtab=unit_lists; cvtab->cvttab; cvtab++) {
        for (tp=cvtab->cvttab; tp->name[0]; tp++) {
-           if (!units_name_matches(str, tp->name))
-               continue;
-           return tp->val;
+           if (units_name_matches(str, tp->name)) {
+               return tp->val;
+           }
        }
     }
+    /* couldn't find it by name, check by value */
+    factor = bu_mm_value(str);
+    if (!EQUAL(factor, 1.0)) {
+       for (cvtab=unit_lists; cvtab->cvttab; cvtab++) {
+           for (tp=cvtab->cvttab; tp->name[0]; tp++) {
+               if (EQUAL(factor, tp->val)) {
+                   return tp->val;
+               }
+           }
+       }
+    }
     return 0.0;                /* Unable to find it */
 }
 
@@ -357,6 +369,8 @@
 
 double
 bu_mm_value(const char *s)
+
+
 {
     double v;
     char *ptr;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to