summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 72c0b22)
raw | patch | inline | side by side (parent: 72c0b22)
author | Kalle Wallin <kaw@linux.se> | |
Wed, 9 Jun 2004 17:36:27 +0000 (17:36 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Wed, 9 Jun 2004 17:36:27 +0000 (17:36 +0000) |
src/support.c | patch | blob | history | |
src/support.h | patch | blob | history |
diff --git a/src/support.c b/src/support.c
index 6ba26121331dd0f86d45e67276793429531b5d7f..23b67d3e71e9b180b6fb5ec4c1af1f84ee9dec3e 100644 (file)
--- a/src/support.c
+++ b/src/support.c
}
#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)
{
diff --git a/src/support.h b/src/support.h
index 2b79e3aefff261492f2b7471566b9f37e1bb5b26..fce9aac28b68782c3a058ce86322bbcc44fe73cc 100644 (file)
--- a/src/support.h
+++ b/src/support.h
char *lowerstr(char *str);
char *strcasestr(const char *haystack, const char *needle);
+typedef struct
+{
+ int offset;
+ time_t t;
+
+} scroll_state_t;
+
+char *strscroll(char *str, char *separator, int width, scroll_state_t *st);
+
void charset_init(gboolean disable);
char *utf8_to_locale(char *str);
char *locale_to_utf8(char *str);