multiple ipmi shortname implementations

As ipmi subsystem requires short names, and there are multiple
ways to implement that, this patch provides compile-time configuration
options.

 - shortname-remove-suffix
 - shortname-replace-words

Previously, PSU Sensor Names were stripped of some
suffixes, some of which uniquely identified the sensor.

e.g. "_Input_Voltage", "_Output_Voltage".
Without the suffix, the sensor cannot be uniquely identified.

Example: "PSU0_Input_Voltage", "PSU0_Output_Voltage"
both become "PSU0".

Tested:
 - with both configurations turned off, name is only trucated
 - with nothing configured, default config is applied and suffix is
   removed (current behavior)
 - word replacement enabled and suffix removal disabled: expected
   behavior
 - word replacement disabled and suffix removal enabled: expected
   behavior

Change-Id: I01dd35f31e75df3c31733e9818884813a241440a
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 39e61f0..b4dfa5a 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -14,6 +14,8 @@
 // limitations under the License.
 */
 
+#include "config.h"
+
 #include "dbus-sdr/sensorcommands.hpp"
 
 #include "dbus-sdr/sdrutils.hpp"
@@ -483,7 +485,7 @@
 
     if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH)
     {
-        // try to not truncate by replacing common words
+#ifdef SHORTNAME_REMOVE_SUFFIX
         for (const auto& suffix : suffixes)
         {
             if (boost::ends_with(name, suffix))
@@ -492,10 +494,19 @@
                 break;
             }
         }
-        if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH)
+#endif
+#ifdef SHORTNAME_REPLACE_WORDS
+        constexpr std::array<std::pair<const char*, const char*>, 2>
+            replaceWords = {std::make_pair("Output", "Out"),
+                            std::make_pair("Input", "In")};
+        for (const auto& [find, replace] : replaceWords)
         {
-            name.resize(FULL_RECORD_ID_STR_MAX_LENGTH);
+            boost::replace_all(name, find, replace);
         }
+#endif
+
+        // as a backup and if nothing else is configured
+        name.resize(FULL_RECORD_ID_STR_MAX_LENGTH);
     }
     return name;
 }