From 7844008980d4d1b9cb7cbd4dda4ae912e12dd7a9 Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Wed, 9 Jun 2004 17:36:27 +0000 Subject: Added the strscroll function git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1424 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/support.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/support.c') diff --git a/src/support.c b/src/support.c index 6ba261213..23b67d3e7 100644 --- a/src/support.c +++ b/src/support.c @@ -116,6 +116,44 @@ strcasestr(const char *haystack, const char *needle) } #endif /* HAVE_STRCASESTR */ +char * +strscroll(char *str, char *separator, int width, scroll_state_t *st) +{ + char *tmp, *buf; + size_t len; + + if( st->offset==0 ) + { + st->offset++; + return g_strdup(str); + } + + /* create a buffer containing the string and the separator */ + tmp = g_malloc(strlen(str)+strlen(separator)+1); + strcpy(tmp, str); + strcat(tmp, separator); + len = strlen(tmp); + + if( st->offset >= len ) + st->offset = 0; + + /* create the new scrolled string */ + buf = g_malloc(width+1); + strncpy(buf, tmp+st->offset, width); + if( strlen(buf) < width ) + strncat(buf, tmp, width-strlen(buf)); + + if( time(NULL)-st->t >= 1 ) + { + st->t = time(NULL); + st->offset++; + } + g_free(tmp); + return buf; + +} + + void charset_init(gboolean disable) { -- cgit v1.2.3