[dasher] Avoid use of snprintf().



commit d54a0105aa349940d1ac7785b7d3f49152ec0545
Author: Patrick Welche <prlw1 cam ac uk>
Date:   Wed Apr 13 11:19:09 2011 +0100

    Avoid use of snprintf().
    
    According to speech dispatcher code, Solaris libc doesn't have
    snprintf. Then again, this is C++, so we hardly need to use it!

 Src/Gtk2/GConfStore.cpp |   44 ++++++++++++++++++++------------------------
 1 files changed, 20 insertions(+), 24 deletions(-)
---
diff --git a/Src/Gtk2/GConfStore.cpp b/Src/Gtk2/GConfStore.cpp
index c6bef98..3b7424f 100644
--- a/Src/Gtk2/GConfStore.cpp
+++ b/Src/Gtk2/GConfStore.cpp
@@ -1,5 +1,7 @@
 #include "GnomeSettingsStore.h"
 
+#define GCONF_KEY_ROOT "/apps/dasher4/"
+
 CGnomeSettingsStore::CGnomeSettingsStore(Dasher::CEventHandler *pEventHandler):CSettingsStore(pEventHandler) {
   the_gconf_client = gconf_client_get_default();
 
@@ -13,13 +15,12 @@ CGnomeSettingsStore::~CGnomeSettingsStore() {
 }
 
 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
-  char keypath[1024];
-
-  snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
+  std::string keypath(GCONF_KEY_ROOT);
+  keypath += Key;
 
   GError *the_error = NULL;
 
-  GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
+  GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath.c_str(), &the_error);
 
   if(got_value == NULL) {
     return false;
@@ -32,13 +33,12 @@ bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
 }
 
 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
-  char keypath[1024];
-
-  snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
+  std::string keypath(GCONF_KEY_ROOT);
+  keypath += Key;
 
   GError *the_error = NULL;
 
-  GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
+  GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath.c_str(), &the_error);
 
   if(got_value == NULL) {
     return false;
@@ -51,13 +51,12 @@ bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
 }
 
 bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value) {
-  char keypath[1024];
-
-  snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
+  std::string keypath(GCONF_KEY_ROOT);
+  keypath += Key;
 
   GError *the_error = NULL;
 
-  GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath, &the_error);
+  GConfValue *got_value = gconf_client_get_without_default(the_gconf_client, keypath.c_str(), &the_error);
 
   if(got_value == NULL) {
     return false;
@@ -70,31 +69,28 @@ bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value
 }
 
 void CGnomeSettingsStore::SaveSetting(const std::string &Key, bool Value) {
-  char keypath[1024];
-
-  snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
+  std::string keypath(GCONF_KEY_ROOT);
+  keypath += Key;
 
   GError *the_error = NULL;
 
-  gconf_client_set_bool(the_gconf_client, keypath, Value, &the_error);
+  gconf_client_set_bool(the_gconf_client, keypath.c_str(), Value, &the_error);
 }
 
 void CGnomeSettingsStore::SaveSetting(const std::string &Key, long Value) {
-  char keypath[1024];
-
-  snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
+  std::string keypath(GCONF_KEY_ROOT);
+  keypath += Key;
 
   GError *the_error = NULL;
 
-  gconf_client_set_int(the_gconf_client, keypath, Value, &the_error);
+  gconf_client_set_int(the_gconf_client, keypath.c_str(), Value, &the_error);
 }
 
 void CGnomeSettingsStore::SaveSetting(const std::string &Key, const std::string &Value) {
-  char keypath[1024];
-
-  snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
+  std::string keypath(GCONF_KEY_ROOT);
+  keypath += Key;
 
   GError *the_error = NULL;
 
-  gconf_client_set_string(the_gconf_client, keypath, Value.c_str(), &the_error);
+  gconf_client_set_string(the_gconf_client, keypath.c_str(), Value.c_str(), &the_error);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]