Right-trimming CVS file contents before displaying them

This commit is contained in:
Pierre Pronchery 2011-09-09 17:40:29 +00:00
parent 50081350c2
commit 74b6b30d36

View File

@ -16,6 +16,7 @@
#include <System.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
@ -111,6 +112,8 @@ static void _cvs_task_on_child_watch(GPid pid, gint status, gpointer data);
static gboolean _cvs_task_on_io_can_read(GIOChannel * channel,
GIOCondition condition, gpointer data);
static void _rtrim(char * string);
/* public */
/* variables */
@ -353,6 +356,7 @@ static void _refresh_dir(CVS * cvs)
snprintf(p, len, "%s/%s", cvs->filename, root);
if(g_file_get_contents(p, &q, NULL, NULL) == TRUE)
{
_rtrim(q);
gtk_label_set_text(GTK_LABEL(cvs->d_root), q);
g_free(q);
}
@ -364,6 +368,7 @@ static void _refresh_dir(CVS * cvs)
snprintf(p, len, "%s/%s", cvs->filename, repository);
if(g_file_get_contents(p, &q, NULL, NULL) == TRUE)
{
_rtrim(q);
gtk_label_set_text(GTK_LABEL(cvs->d_repository), q);
g_free(q);
}
@ -375,6 +380,7 @@ static void _refresh_dir(CVS * cvs)
snprintf(p, len, "%s/%s", cvs->filename, tag);
if(g_file_get_contents(p, &q, NULL, NULL) == TRUE)
{
_rtrim(q);
if(q[0] == 'T')
gtk_label_set_text(GTK_LABEL(cvs->d_tag),
&q[1]);
@ -855,3 +861,16 @@ static gboolean _cvs_task_on_io_can_read(GIOChannel * channel,
}
return TRUE;
}
/* rtrim */
static void _rtrim(char * string)
{
size_t i;
int c;
if(string == NULL || (i = strlen(string)) == 0)
return;
for(i--; i > 0 && (c = string[i]) != '\0' && isspace(c); i--)
string[i] = '\0';
}