@@ -1648,7 +1648,11 @@ int status_get(const char *buf)
16481648 if (!s )
16491649 return 0 ;
16501650
1651- offset = status_buf - s ;
1651+ offset = s - status_buf ;
1652+ #if 0
1653+ upsdebugx (3 , "%s: '%s' in '%s': offset=%" PRIuSIZE " buflen=%" PRIuSIZE " s[buflen]='0x%2X'\n" ,
1654+ __func__ , buf , status_buf , offset , buflen , s [buflen ]);
1655+ #endif
16521656 if (offset == 0 || status_buf [offset - 1 ] == ' ' ) {
16531657 /* We have hit the start of token */
16541658 if (s [buflen ] == '\0' || s [buflen ] == ' ' ) {
@@ -1664,6 +1668,39 @@ int status_get(const char *buf)
16641668/* add a status element */
16651669void status_set (const char * buf )
16661670{
1671+ #if 0
1672+ upsdebugx (3 , "%s: '%s'\n" , __func__ , buf );
1673+ #endif
1674+ if (strstr (buf , " " )) {
1675+ /* Recurse adding each sub-status one by one (avoid duplicates)
1676+ * We frown upon adding "A FEW TOKENS" at once, but in e.g.
1677+ * snmp-ups subdrivers with a mapping table this is not easily
1678+ * avoidable...
1679+ */
1680+ char * tmp = xstrdup (buf ), * p = tmp , * s = tmp ;
1681+ while (* p ) {
1682+ if (* p == ' ' ) {
1683+ * p = '\0' ;
1684+ if (s != p ) {
1685+ /* Only recurse to set non-trivial tokens */
1686+ status_set (s );
1687+ }
1688+ p ++ ;
1689+ s = p ; /* Start of new word... or a consecutive space to ignore on next cycle */
1690+ } else {
1691+ p ++ ;
1692+ }
1693+ }
1694+
1695+ if (s != p ) {
1696+ /* Last valid token did end with (*p=='\0') */
1697+ status_set (s );
1698+ }
1699+
1700+ free (tmp );
1701+ return ;
1702+ }
1703+
16671704 if (ignorelb && !strcasecmp (buf , "LB" )) {
16681705 upsdebugx (2 , "%s: ignoring LB flag from device" , __func__ );
16691706 return ;
0 commit comments