Bugfix: chars followed by backspace should not be displayed
authorNikolas Garofil <ngarofil@users.sourceforge.net>
Wed, 4 Jun 2008 08:51:15 +0000 (08:51 +0000)
committerNikolas Garofil <ngarofil@users.sourceforge.net>
Wed, 4 Jun 2008 08:51:15 +0000 (08:51 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1126 7f574dfc-610e-0410-a909-a81674777703

AUTHORS
ChangeLog
src/conky.c

diff --git a/AUTHORS b/AUTHORS
index 8e27fe8..4c03ff0 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -64,6 +64,7 @@ David McCabe
 
 garo <nikolas at garofil dot be>
   gw_iface fix
+  deleted chars fix
 
 Ram Yalamanchili
   tztime
index 78eca40..d5499c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@
 2008-06-04
        * Fix bug where conky tries to free a already freed pointer when you
        use gw_iface with a empty routingtable in linux
+       * Fix bug where conky tries to tries to display deleted chars in a
+       string (chars followed by a backspace-char) causing strange output.
 
 2008-06-03
        * Added NVIDIA Graficcard support patch (thanks meissna)
index 9af0d8c..b993862 100644 (file)
@@ -4251,6 +4251,21 @@ char *format_time(unsigned long timeval, const int width)
        return strndup("<inf>", text_buffer_size);
 }
 
+//remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
+//string has to end with \0 and it's length should fit in a int
+#define BACKSPACE 8
+void remove_deleted_chars(char *string){
+       int i = 0;
+       while(string[i] != 0){
+               if(string[i] == BACKSPACE){
+                       if(i != 0){
+                               strcpy( &(string[i-1]), &(string[i+1]) );
+                               i--;
+                       }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
+               }else i++;
+       }
+}
+
 static void generate_text_internal(char *p, int p_max_size,
                struct text_object *objs, unsigned int object_count,
                struct information *cur)
@@ -4761,6 +4776,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                pclose(fp);
 
                                p[length] = '\0';
+                               remove_deleted_chars(p);
                                if (length > 0 && p[length - 1] == '\n') {
                                        p[length - 1] = '\0';
                                }