1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 SAF_Unit *
 saf_find_one_unit(SAF_Db *database,             /* The database in which to find the specified unit. */
                   const char *name,             /* The singular name of the unit to find, e.g., "meter". */
                   SAF_Unit *buf                 /* [OUT] Optional unit handle to initialize and return. */
                   )
 {
     SAF_ENTER(saf_find_one_unit, NULL);
 #ifdef HASH_UNITS /*RPM DEBUGGING 2004-09-26*/
     size_t limit=1;
     buf = (SAF_Unit*)_saf_htab_find(UHash, _saf_hkey_str(name), &limit, (ss_pers_t*)buf);
     assert(1==limit);
 #else
     int n;

     /* Look for unit by name */
     n = 1;
     saf_find_units(SAF_EACH, database, name, NULL, NULL, SAF_ANY_DOUBLE, SAF_ANY_DOUBLE, SAF_ANY_DOUBLE, SAF_ANY_DOUBLE,
                    NULL, &n, &buf);

     /* Look for unit by abbreviation */
     if (0==n) {
         n = 1;
         saf_find_units(SAF_EACH, database, NULL, name, NULL, SAF_ANY_DOUBLE, SAF_ANY_DOUBLE, SAF_ANY_DOUBLE, SAF_ANY_DOUBLE,
                        NULL, &n, &buf);
     }
 #endif
     SAF_LEAVE(buf);
 }