64f10b4687eae05cf0f5ce9986b40c164d6ea8bc
hiram
  Tue Feb 14 11:31:03 2017 -0800
add description to searchTrix results refs #13673

diff --git src/lib/common.c src/lib/common.c
index f0681b6..f2a3f96 100644
--- src/lib/common.c
+++ src/lib/common.c
@@ -3211,30 +3211,53 @@
     needleCopy[index] = tolower(needle[index]);
     }
 needleCopy[needleLen] = 0; /* Null terminate */
 
 p=strstr(haystackCopy, needleCopy);
 q=haystackCopy;
 
 freeMem(haystackCopy);
 freeMem(needleCopy);
 
 if(p==NULL) return NULL;
 
 return p-q+haystack;
 }
 
+int vatruncatef(char *buf, int size, char *format, va_list args)
+/* Like vasafef, but truncates the formatted string instead of barfing on
+ * overflow. */
+{
+char *truncStr = " [truncated]";
+int sz = vsnprintf(buf, size, format, args);
+/* note that some version return -1 if too small */
+if ((sz < 0) || (sz >= size))
+    strncpy(buf + size - 1 - strlen(truncStr), truncStr, strlen(truncStr));
+buf[size-1] = 0;
+return sz;
+}
+
+void truncatef(char *buf, int size, char *format, ...)
+/* Like safef, but truncates the formatted string instead of barfing on
+ * overflow. */
+{
+va_list args;
+va_start(args, format);
+vatruncatef(buf, size, format, args);  // ignore returned size
+va_end(args);
+}
+
 int vasafef(char* buffer, int bufSize, char *format, va_list args)
 /* Format string to buffer, vsprintf style, only with buffer overflow
  * checking.  The resulting string is always terminated with zero byte. */
 {
 int sz = vsnprintf(buffer, bufSize, format, args);
 /* note that some version return -1 if too small */
 if ((sz < 0) || (sz >= bufSize))
     {
     buffer[bufSize-1] = (char) 0;
     errAbort("buffer overflow, size %d, format: %s, buffer: '%s'", bufSize, format, buffer);
     }
 return sz;
 }
 
 int safef(char* buffer, int bufSize, char *format, ...)