src/lib/common.c 1.136

1.136 2009/11/12 19:33:54 kent
Adding a few new utilities to common.h/common.c for benefit of bbi compressed encoders.
Index: src/lib/common.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/common.c,v
retrieving revision 1.135
retrieving revision 1.136
diff -b -B -U 4 -r1.135 -r1.136
--- src/lib/common.c	2 Nov 2009 21:27:48 -0000	1.135
+++ src/lib/common.c	12 Nov 2009 19:33:54 -0000	1.136
@@ -2072,8 +2072,27 @@
 slReverse(&newList);
 return newList;
 }
 
+void fileOffsetSizeFindGap(struct fileOffsetSize *list, 
+	struct fileOffsetSize **pBeforeGap, struct fileOffsetSize **pAfterGap)
+/* Starting at list, find all items that don't have a gap between them and the previous item.  
+ * Return at gap, or at end of list, returning pointers to the items before and after the gap. */
+{
+struct fileOffsetSize *pt, *next;
+for (pt = list; ; pt = next)
+    {
+    next = pt->next;
+    if (next == NULL || next->offset != pt->offset + pt->size)
+	{
+	*pBeforeGap = pt;
+	*pAfterGap = next;
+	return;
+	}
+    }
+}
+
+
 void maybeSystem(char *cmd)
 /* Execute cmd using "sh -c" or die.  (See man 3 system.) warn on errors */
 {
 if (cmd == NULL) // don't allow (system() supports testing for shell this way)
@@ -2134,14 +2153,27 @@
 return ret;
 }
 
 void memRead(char **pPt, void *buf, int size)
-/* Copy memory from *pPt to buf, and advance *pPt by size */
+/* Copy memory from *pPt to buf, and advance *pPt by size. */
 {
 memcpy(buf, *pPt, size);
 *pPt += size;
 }
 
+void memWrite(char **pPt, void *buf, int size)
+/* Copy memory from buf to *pPt and advance *pPt by size. */
+{
+memcpy(*pPt, buf, size);
+*pPt += size;
+}
+
+void memWriteFloat(char **pPt, float val)
+/* Write out floating point val to file.  Mostly to convert from double... */
+{
+memWriteOne(pPt, val);
+}
+
 bits64 byteSwap64(bits64 a)
 /* Return byte-swapped version of a */
 {
 union {bits64 whole; UBYTE bytes[4];} u,v;