# HG changeset patch # User Matti Hamalainen # Date 1103641385 0 # Node ID 7833df935239979fdd305173741123e940c272db # Parent 5a390af358fc7b25ab9f9edcb2e1f06a45c98f9b Added xs_pnstrcat() to ease forming of limited size strings. diff -r 5a390af358fc -r 7833df935239 src/xs_fileinfo.c --- a/src/xs_fileinfo.c Tue Dec 21 13:44:03 2004 +0000 +++ b/src/xs_fileinfo.c Tue Dec 21 15:03:05 2004 +0000 @@ -156,7 +156,7 @@ GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu; t_xs_tuneinfo *tmpInfo; t_xs_stil_subnode *tmpNode; - gchar tmpStr[32], *tmpS; + gchar tmpStr[64]; gint n; /* Current implementation leaves old fileinfo window untouched if @@ -217,20 +217,21 @@ /* Other menu items */ for (n = 1; n <= tmpInfo->nsubTunes; n++) { + if (xs_fileinfostil) { + snprintf(tmpStr, sizeof(tmpStr), "Tune #%i: ", n); tmpNode = &xs_fileinfostil->subTune[n]; if (tmpNode->pName) - tmpS = tmpNode->pName; + xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pName); else if (tmpNode->pInfo) - tmpS = tmpNode->pInfo; + xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pInfo); else - tmpS = "---"; - - snprintf(tmpStr, sizeof(tmpStr), "Tune #%i: %s", n, tmpS); - } else + xs_pnstrcat(tmpStr, sizeof(tmpStr), "---"); + } else { snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n); + } tmpMenuItem = gtk_menu_item_new_with_label(tmpStr); gtk_widget_show (tmpMenuItem); diff -r 5a390af358fc -r 7833df935239 src/xs_support.c --- a/src/xs_support.c Tue Dec 21 13:44:03 2004 +0000 +++ b/src/xs_support.c Tue Dec 21 15:03:05 2004 +0000 @@ -114,6 +114,38 @@ } +/* Concatenate a given string up to given dest size or \n. + * If size max is reached, change the end to "..." + */ +void xs_pnstrcat(gchar *pDest, size_t iSize, gchar *pStr) +{ + size_t i, n; + gchar *s, *d; + + d = pDest; i = 0; + while (*d && (i < iSize)) { i++; d++; } + + s = pStr; + while (*s && (*s != '\n') && (i < iSize)) + { + *d = *s; + d++; s++; i++; + } + + *d = 0; + + if (i >= iSize) + { + i--; d--; n = 3; + while ((i > 0) && (n > 0)) + { + *d = '.'; + d--; i--; n--; + } + } +} + + /* Locate character in string */ gchar *xs_strrchr(gchar *pcStr, gchar ch) diff -r 5a390af358fc -r 7833df935239 src/xs_support.h --- a/src/xs_support.h Tue Dec 21 13:44:03 2004 +0000 +++ b/src/xs_support.h Tue Dec 21 15:03:05 2004 +0000 @@ -34,6 +34,7 @@ gchar *xs_strncpy(gchar *, gchar *, size_t); gint xs_pstrcpy(gchar **, const gchar *); gint xs_pstrcat(gchar **, const gchar *); +void xs_pnstrcat(gchar *, size_t, gchar *); gchar *xs_strrchr(gchar *, gchar); inline void xs_findnext(gchar *, guint *); inline void xs_findeol(gchar *, guint *);