fcd12f2b541d84822d13fb7b939c463248647f1f
tdreszer
  Fri Apr 15 17:42:16 2011 -0700
Add simple support for reading lines with continuation characters as single lines.
diff --git src/inc/linefile.h src/inc/linefile.h
index e6bbc9b..0a593fd 100644
--- src/inc/linefile.h
+++ src/inc/linefile.h
@@ -1,24 +1,26 @@
 /* lineFile - stuff to rapidly read text files and parse them into
  * lines. 
  *
  * This file is copyright 2002 Jim Kent, but license is hereby
  * granted for all use - public, private or commercial. */
 
 #ifndef LINEFILE_H
 #define LINEFILE_H
 
+#include "dystring.h"
+
 #ifdef USE_TABIX
 #include "tabix.h"
 #endif
 
 enum nlType {
  nlt_undet, /* undetermined */
  nlt_unix,  /* lf   */
  nlt_dos,   /* crlf */
  nlt_mac    /* cr   */
 };
 
 struct metaOutput
 /* struct to store list of file handles to output meta data to 
  * meta data is text after # */
     {
@@ -40,30 +42,32 @@
     int lineIx;			/* Current line. */
     int lineStart;		/* Offset of line in buffer. */
     int lineEnd;		/* End of line in buffer. */
     bool zTerm;			/* Replace '\n' with zero? */
     enum nlType nlType;         /* type of line endings: dos, unix, mac or undet */  
     bool reuse;			/* Set if reusing input. */
     char *buf;			/* Buffer. */
     struct pipeline *pl;        /* pipeline if reading compressed */
     struct metaOutput *metaOutput;   /* list of FILE handles to write metaData to */
     bool isMetaUnique;          /* if set, do not repeat comments in output */
     struct hash *metaLines;     /* save lines to suppress repetition */
 #ifdef USE_TABIX
     tabix_t *tabix;		/* A tabix-compressed file and its binary index file (.tbi) */
     ti_iter_t tabixIter;	/* An iterator to get decompressed indexed lines of text */
 #endif
+    struct dyString *fullLine;  // Filled with full line when a lineFileNextFull is called
+    boolean fullLineResuse;     // If TRUE, next call to lineFileNextFull will get already built fullLine
     };
 
 char *getFileNameFromHdrSig(char *m);
 /* Check if header has signature of supported compression stream,
    and return a phoney filename for it, or NULL if no sig found. */
 
 struct lineFile *lineFileDecompressFd(char *name, bool zTerm, int fd);
 /* open a linefile with decompression from a file or socket descriptor */
 
 struct lineFile *lineFileDecompressMem(bool zTerm, char *mem, long size);
 /* open a linefile with decompression from a memory stream */
 
 struct lineFile *lineFileMayOpen(char *fileName, bool zTerm);
 /* Try and open up a lineFile. If fileName ends in .gz, .Z, or .bz2,
  * it will be read from a decompress pipeline. */
@@ -80,40 +84,52 @@
 
 struct lineFile *lineFileOnString(char *name, bool zTerm, char *s);
 /* Wrap a line file object around string in memory. This buffer
  * have zeroes written into it if zTerm is non-zero.  It will
  * be freed when the line file is closed. */
 
 void lineFileClose(struct lineFile **pLf);
 /* Close up a line file. */
 
 void lineFileCloseList(struct lineFile **pList);
 /* Close up a list of line files. */
 
 boolean lineFileNext(struct lineFile *lf, char **retStart, int *retSize);
 /* Fetch next line from file. */
 
+boolean lineFileNextFull(struct lineFile *lf, char **retStart, int *retSize);
+// Fetch next line from file joining up any that are continued by ending '\'
+// NOTE: comment lines can't be continued!  ("# comment \ \n more comment" is 2 lines.)
+
 boolean lineFileNextReal(struct lineFile *lf, char **retStart);
 /* Fetch next line from file that is not blank and 
  * does not start with a '#'. */
 
+boolean lineFileNextFullReal(struct lineFile *lf, char **retStart);
+// Fetch next line from file that is not blank and does not start with a '#'.
+// Continuation lines (ending in '\') are joined into a single line.
+
 void lineFileNeedNext(struct lineFile *lf, char **retStart, int *retSize);
 /* Fetch next line from file.  Squawk and die if it's not there. */
 
 void lineFileReuse(struct lineFile *lf);
 /* Reuse current line. */
 
+void lineFileReuseFull(struct lineFile *lf);
+// Reuse last full line read.  Unlike lineFileReuse,
+// lineFileReuseFull only works with previous lineFileNextFull call
+
 #define lineFileString(lf) ((lf)->buf + (lf)->lineStart)
 /* Current string in line file. */
 
 #define lineFileTell(lf) ((lf)->bufOffsetInFile + (lf)->lineStart)
 /* Current offset (of string start) in file. */
 
 void lineFileSeek(struct lineFile *lf, off_t offset, int whence);
 /* Seek to read next line from given position. */
 
 void lineFileRewind(struct lineFile *lf);
 /* Return lineFile to start. */
 
 void lineFileAbort(struct lineFile *lf, char *format, ...)
 /* Print file name, line number, and error message, and abort. */
 #if defined(__GNUC__)