#include "common.h"#include "hash.h"#include <fcntl.h>#include "dystring.h"#include "errabort.h"#include "linefile.h"#include "pipeline.h"#include <signal.h>Include dependency graph for linefile.c:

Go to the source code of this file.
Functions | |
| char * | getFileNameFromHdrSig (char *m) |
| static char ** | getDecompressor (char *fileName) |
| static void | metaDataAdd (struct lineFile *lf, char *line) |
| static void | metaDataFree (struct lineFile *lf) |
| void | lineFileSetMetaDataOutput (struct lineFile *lf, FILE *f) |
| void | lineFileSetUniqueMetaData (struct lineFile *lf) |
| static char * | headerBytes (char *fileName, int numbytes) |
| lineFile * | lineFileDecompress (char *fileName, bool zTerm) |
| lineFile * | lineFileDecompressFd (char *name, bool zTerm, int fd) |
| lineFile * | lineFileDecompressMem (bool zTerm, char *mem, long size) |
| lineFile * | lineFileAttach (char *fileName, bool zTerm, int fd) |
| lineFile * | lineFileOnString (char *name, bool zTerm, char *s) |
| void | lineFileExpandBuf (struct lineFile *lf, int newSize) |
| lineFile * | lineFileStdin (bool zTerm) |
| lineFile * | lineFileMayOpen (char *fileName, bool zTerm) |
| lineFile * | lineFileOpen (char *fileName, bool zTerm) |
| void | lineFileReuse (struct lineFile *lf) |
| void | lineFileSeek (struct lineFile *lf, off_t offset, int whence) |
| int | lineFileLongNetRead (int fd, char *buf, int size) |
| static void | determineNlType (struct lineFile *lf, char *buf, int bufSize) |
| boolean | lineFileNext (struct lineFile *lf, char **retStart, int *retSize) |
| void | lineFileVaAbort (struct lineFile *lf, char *format, va_list args) |
| void | lineFileAbort (struct lineFile *lf, char *format,...) |
| void | lineFileUnexpectedEnd (struct lineFile *lf) |
| void | lineFileNeedNext (struct lineFile *lf, char **retStart, int *retSize) |
| void | lineFileClose (struct lineFile **pLf) |
| void | lineFileCloseList (struct lineFile **pList) |
| void | lineFileExpectWords (struct lineFile *lf, int expecting, int got) |
| void | lineFileExpectAtLeast (struct lineFile *lf, int expecting, int got) |
| void | lineFileShort (struct lineFile *lf) |
| boolean | lineFileNextReal (struct lineFile *lf, char **retStart) |
| int | lineFileChopNext (struct lineFile *lf, char *words[], int maxWords) |
| int | lineFileChopCharNext (struct lineFile *lf, char sep, char *words[], int maxWords) |
| int | lineFileChopNextTab (struct lineFile *lf, char *words[], int maxWords) |
| boolean | lineFileNextCharRow (struct lineFile *lf, char sep, char *words[], int wordCount) |
| boolean | lineFileNextRow (struct lineFile *lf, char *words[], int wordCount) |
| boolean | lineFileNextRowTab (struct lineFile *lf, char *words[], int wordCount) |
| int | lineFileNeedFullNum (struct lineFile *lf, char *words[], int wordIx) |
| int | lineFileNeedNum (struct lineFile *lf, char *words[], int wordIx) |
| double | lineFileNeedDouble (struct lineFile *lf, char *words[], int wordIx) |
| void | lineFileSkip (struct lineFile *lf, int lineCount) |
| char * | lineFileSkipToLineStartingWith (struct lineFile *lf, char *start, int maxCount) |
| boolean | lineFileParseHttpHeader (struct lineFile *lf, char **hdr, boolean *chunked, int *contentLength) |
| dyString * | lineFileSlurpHttpBody (struct lineFile *lf, boolean chunked, int contentLength) |
Variables | |
| static char const | rcsid [] = "$Id: linefile.c,v 1.54 2007/03/23 08:12:42 kent Exp $" |
| static void determineNlType | ( | struct lineFile * | lf, | |
| char * | buf, | |||
| int | bufSize | |||
| ) | [static] |
Definition at line 280 of file linefile.c.
References nlt_dos, nlt_mac, nlt_undet, nlt_unix, and lineFile::nlType.
Referenced by lineFileNext().
00282 { 00283 char *c = buf; 00284 if (bufSize==0) return; 00285 if (lf->nlType != nlt_undet) return; /* if already determined just exit */ 00286 lf->nlType = nlt_unix; /* start with default of unix lf type */ 00287 while (c < buf+bufSize) 00288 { 00289 if (*c=='\r') 00290 { 00291 lf->nlType = nlt_mac; 00292 if (++c < buf+bufSize) 00293 if (*c == '\n') 00294 lf->nlType = nlt_dos; 00295 return; 00296 } 00297 if (*(c++) == '\n') 00298 { 00299 return; 00300 } 00301 } 00302 }
Here is the caller graph for this function:

| static char** getDecompressor | ( | char * | fileName | ) | [static] |
Definition at line 33 of file linefile.c.
References endsWith().
Referenced by lineFileDecompress(), lineFileDecompressFd(), lineFileDecompressMem(), and lineFileMayOpen().
00036 { 00037 static char *GZ_READ[] = {"gzip", "-dc", NULL}; 00038 static char *Z_READ[] = {"compress", "-dc", NULL}; 00039 static char *BZ2_READ[] = {"bzip2", "-dc", NULL}; 00040 00041 if (endsWith(fileName, ".gz")) 00042 return GZ_READ; 00043 else if (endsWith(fileName, ".Z")) 00044 return Z_READ; 00045 else if (endsWith(fileName, ".bz2")) 00046 return BZ2_READ; 00047 else 00048 return NULL; 00049 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char* getFileNameFromHdrSig | ( | char * | m | ) |
Definition at line 18 of file linefile.c.
References cloneString(), safef(), and startsWith().
Referenced by lineFileDecompress(), and lineFileDecompressMem().
00021 { 00022 char buf[20]; 00023 char *ext=NULL; 00024 if (startsWith("\x1f\x8b",m)) ext = "gz"; 00025 else if (startsWith("\x1f\x9d\x90",m)) ext = "Z"; 00026 else if (startsWith("BZ",m)) ext = "bz2"; 00027 if (ext==NULL) 00028 return NULL; 00029 safef(buf, sizeof(buf), "somefile.%s", ext); 00030 return cloneString(buf); 00031 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static char* headerBytes | ( | char * | fileName, | |
| int | numbytes | |||
| ) | [static] |
Definition at line 98 of file linefile.c.
References freez(), and needMem().
Referenced by lineFileDecompress().
00101 { 00102 int fd,bytesread=0; 00103 char *result = NULL; 00104 if ((fd = open(fileName, O_RDONLY)) >= 0) 00105 { 00106 result=needMem(numbytes+1); 00107 if ((bytesread=read(fd,result,numbytes)) < numbytes) 00108 freez(&result); /* file too short? can read numbytes */ 00109 else 00110 result[numbytes]=0; 00111 close(fd); 00112 } 00113 return result; 00114 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileAbort | ( | struct lineFile * | lf, | |
| char * | format, | |||
| ... | ||||
| ) |
Definition at line 472 of file linefile.c.
References lineFileVaAbort().
00474 { 00475 va_list args; 00476 va_start(args, format); 00477 lineFileVaAbort(lf, format, args); 00478 va_end(args); 00479 }
Here is the call graph for this function:

| struct lineFile* lineFileAttach | ( | char * | fileName, | |
| bool | zTerm, | |||
| int | fd | |||
| ) | [read] |
Definition at line 168 of file linefile.c.
References AllocVar, lineFile::buf, lineFile::bufSize, cloneString(), lineFile::fd, lineFile::fileName, needMem(), and lineFile::zTerm.
Referenced by lineFileDecompress(), lineFileDecompressFd(), lineFileDecompressMem(), lineFileMayOpen(), lineFileStdin(), netHttpLineFileMayOpen(), netLineFileMayOpen(), netLineFileMayOpenCatchError(), netUrlHead(), and pipelineLineFile().
00170 { 00171 struct lineFile *lf; 00172 AllocVar(lf); 00173 lf->fileName = cloneString(fileName); 00174 lf->fd = fd; 00175 lf->bufSize = 64*1024; 00176 lf->zTerm = zTerm; 00177 lf->buf = needMem(lf->bufSize+1); 00178 return lf; 00179 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int lineFileChopCharNext | ( | struct lineFile * | lf, | |
| char | sep, | |||
| char * | words[], | |||
| int | maxWords | |||
| ) |
Definition at line 585 of file linefile.c.
References chopByChar(), and lineFileNext().
Referenced by lineFileNextCharRow().
00588 { 00589 int lineSize, wordCount; 00590 char *line; 00591 00592 while (lineFileNext(lf, &line, &lineSize)) 00593 { 00594 if (line[0] == '#') 00595 continue; 00596 wordCount = chopByChar(line, sep, words, maxWords); 00597 if (wordCount != 0) 00598 return wordCount; 00599 } 00600 return 0; 00601 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int lineFileChopNext | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | maxWords | |||
| ) |
Definition at line 568 of file linefile.c.
References chopByWhite(), and lineFileNext().
Referenced by lineFileNextRow().
00570 { 00571 int lineSize, wordCount; 00572 char *line; 00573 00574 while (lineFileNext(lf, &line, &lineSize)) 00575 { 00576 if (line[0] == '#') 00577 continue; 00578 wordCount = chopByWhite(line, words, maxWords); 00579 if (wordCount != 0) 00580 return wordCount; 00581 } 00582 return 0; 00583 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int lineFileChopNextTab | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | maxWords | |||
| ) |
Definition at line 603 of file linefile.c.
References chopByChar(), and lineFileNext().
Referenced by lineFileNextRowTab().
00606 { 00607 int lineSize, wordCount; 00608 char *line; 00609 00610 while (lineFileNext(lf, &line, &lineSize)) 00611 { 00612 if (line[0] == '#') 00613 continue; 00614 wordCount = chopByChar(line, '\t', words, maxWords); 00615 if (wordCount != 0) 00616 return wordCount; 00617 } 00618 return 0; 00619 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileClose | ( | struct lineFile ** | pLf | ) |
Definition at line 494 of file linefile.c.
References lineFile::buf, lineFile::fd, lineFile::fileName, freeMem(), freez(), metaDataFree(), pipelineFree(), pipelineWait(), and lineFile::pl.
Referenced by aliLines(), bigBlat(), blastFileFree(), blastFileReadAll(), cgiFromFile(), chainReadAllWithMeta(), chainReadUsedSwap(), closePipeline(), convertEpsToPdf(), countWordsInFile(), dnaLoadStackFree(), doDetailLine(), dtdParse(), faReadAllSeqMixable(), faReadNamedSeq(), gapCalcFromFile(), gapCalcFromString(), genoFindDirect(), gffFileAdd(), gfPcrInputLoadAll(), hashNameIntFile(), hashTwoColumnFile(), hashWordsInFile(), htmlCookieFileRead(), lineFileCloseList(), loadPsls(), mafFileFree(), mafNextWithPos(), maskFromOut(), netUrlHead(), phyloOpenTree(), pslLoadAll(), quotedPrintableDecode(), raFoldIn(), raReadAll(), raReadSingle(), readPartHeaderMB(), readPslToBinKeeper(), searchOneIndex(), slNameLoadReal(), spacedColumnFromFile(), tokenizerFree(), trixOpen(), twoBitSpecNewFile(), and xAliLoadAll().
00496 { 00497 struct lineFile *lf; 00498 if ((lf = *pLf) != NULL) 00499 { 00500 if (lf->pl != NULL) 00501 { 00502 pipelineWait(lf->pl); 00503 pipelineFree(&lf->pl); 00504 } 00505 else if (lf->fd > 0 && lf->fd != fileno(stdin)) 00506 { 00507 close(lf->fd); 00508 freeMem(lf->buf); 00509 } 00510 freeMem(lf->fileName); 00511 metaDataFree(lf); 00512 freez(pLf); 00513 } 00514 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileCloseList | ( | struct lineFile ** | pList | ) |
Definition at line 516 of file linefile.c.
References lineFileClose(), and lineFile::next.
00518 { 00519 struct lineFile *el, *next; 00520 00521 for (el = *pList; el != NULL; el = next) 00522 { 00523 next = el->next; 00524 lineFileClose(&el); 00525 } 00526 *pList = NULL; 00527 }
Here is the call graph for this function:

| struct lineFile* lineFileDecompress | ( | char * | fileName, | |
| bool | zTerm | |||
| ) | [read] |
Definition at line 117 of file linefile.c.
References freez(), getDecompressor(), getFileNameFromHdrSig(), headerBytes(), lineFileAttach(), pipelineFd(), pipelineOpen1(), pipelineRead, and lineFile::pl.
Referenced by lineFileMayOpen().
00119 { 00120 struct pipeline *pl; 00121 struct lineFile *lf; 00122 char *testName = NULL; 00123 char *testbytes = NULL; /* the header signatures for .gz .bz2, .Z are all 2 or 3 bytes only */ 00124 if (fileName==NULL) 00125 return NULL; 00126 testbytes=headerBytes(fileName,3); 00127 if (!testbytes) 00128 return NULL; /* avoid error from pipeline */ 00129 testName=getFileNameFromHdrSig(testbytes); 00130 freez(&testbytes); 00131 if (!testName) 00132 return NULL; /* avoid error from pipeline */ 00133 pl = pipelineOpen1(getDecompressor(fileName), pipelineRead, fileName, NULL); 00134 lf = lineFileAttach(fileName, zTerm, pipelineFd(pl)); 00135 lf->pl = pl; 00136 return lf; 00137 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct lineFile* lineFileDecompressFd | ( | char * | name, | |
| bool | zTerm, | |||
| int | fd | |||
| ) | [read] |
Definition at line 139 of file linefile.c.
References getDecompressor(), lineFileAttach(), pipelineFd(), pipelineOpenFd1(), pipelineRead, and lineFile::pl.
Referenced by netLineFileMayOpen(), and netLineFileMayOpenCatchError().
00141 { 00142 struct pipeline *pl; 00143 struct lineFile *lf; 00144 pl = pipelineOpenFd1(getDecompressor(name), pipelineRead, fd, STDERR_FILENO); 00145 lf = lineFileAttach(name, zTerm, pipelineFd(pl)); 00146 lf->pl = pl; 00147 return lf; 00148 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct lineFile* lineFileDecompressMem | ( | bool | zTerm, | |
| char * | mem, | |||
| long | size | |||
| ) | [read] |
Definition at line 152 of file linefile.c.
References lineFile::fileName, getDecompressor(), getFileNameFromHdrSig(), lineFileAttach(), pipelineFd(), pipelineOpenMem1(), pipelineRead, and lineFile::pl.
00154 { 00155 struct pipeline *pl; 00156 struct lineFile *lf; 00157 char *fileName = getFileNameFromHdrSig(mem); 00158 if (fileName==NULL) 00159 return NULL; 00160 pl = pipelineOpenMem1(getDecompressor(fileName), pipelineRead, mem, size, STDERR_FILENO); 00161 lf = lineFileAttach(fileName, zTerm, pipelineFd(pl)); 00162 lf->pl = pl; 00163 return lf; 00164 }
Here is the call graph for this function:

| void lineFileExpandBuf | ( | struct lineFile * | lf, | |
| int | newSize | |||
| ) |
Definition at line 196 of file linefile.c.
References lineFile::buf, lineFile::bufSize, lineFile::bytesInBuf, and needMoreMem().
Referenced by lineFileNext().
00198 { 00199 assert(newSize > lf->bufSize); 00200 lf->buf = needMoreMem(lf->buf, lf->bytesInBuf, newSize); 00201 lf->bufSize = newSize; 00202 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileExpectAtLeast | ( | struct lineFile * | lf, | |
| int | expecting, | |||
| int | got | |||
| ) |
Definition at line 537 of file linefile.c.
References errAbort(), lineFile::fileName, and lineFile::lineIx.
00539 { 00540 if (got < expecting) 00541 errAbort("Expecting at least %d words line %d of %s got %d", 00542 expecting, lf->lineIx, lf->fileName, got); 00543 }
Here is the call graph for this function:

| void lineFileExpectWords | ( | struct lineFile * | lf, | |
| int | expecting, | |||
| int | got | |||
| ) |
Definition at line 529 of file linefile.c.
References errAbort(), lineFile::fileName, and lineFile::lineIx.
Referenced by lineFileNextCharRow(), lineFileNextRow(), lineFileNextRowTab(), and mafNextWithPos().
00531 { 00532 if (expecting != got) 00533 errAbort("Expecting %d words line %d of %s got %d", 00534 expecting, lf->lineIx, lf->fileName, got); 00535 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int lineFileLongNetRead | ( | int | fd, | |
| char * | buf, | |||
| int | size | |||
| ) |
Definition at line 262 of file linefile.c.
Referenced by lineFileNext().
00265 { 00266 int oneSize, totalRead = 0; 00267 00268 while (size > 0) 00269 { 00270 oneSize = read(fd, buf, size); 00271 if (oneSize <= 0) 00272 break; 00273 totalRead += oneSize; 00274 buf += oneSize; 00275 size -= oneSize; 00276 } 00277 return totalRead; 00278 }
Here is the caller graph for this function:

| struct lineFile* lineFileMayOpen | ( | char * | fileName, | |
| bool | zTerm | |||
| ) | [read] |
Definition at line 211 of file linefile.c.
References lineFile::fd, getDecompressor(), lineFileAttach(), lineFileDecompress(), lineFileStdin(), and sameString.
Referenced by lineFileOpen(), mafMayOpen(), and raFoldIn().
00213 { 00214 if (sameString(fileName, "stdin")) 00215 return lineFileStdin(zTerm); 00216 else if (getDecompressor(fileName) != NULL) 00217 return lineFileDecompress(fileName, zTerm); 00218 else 00219 { 00220 int fd = open(fileName, O_RDONLY); 00221 if (fd == -1) 00222 return NULL; 00223 return lineFileAttach(fileName, zTerm, fd); 00224 } 00225 }
Here is the call graph for this function:

Here is the caller graph for this function:

| double lineFileNeedDouble | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | wordIx | |||
| ) |
Definition at line 688 of file linefile.c.
References errAbort(), lineFile::fileName, and lineFile::lineIx.
Referenced by hpfNext().
00691 { 00692 char *valEnd; 00693 char *val = words[wordIx]; 00694 double doubleValue; 00695 00696 doubleValue = strtod(val, &valEnd); 00697 if ((*val == '\0') || (*valEnd != '\0')) 00698 errAbort("Expecting double field %d line %d of %s, got %s", 00699 wordIx+1, lf->lineIx, lf->fileName, val); 00700 return doubleValue; 00701 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int lineFileNeedFullNum | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | wordIx | |||
| ) |
Definition at line 660 of file linefile.c.
References errAbort(), lineFile::fileName, lineFileNeedNum(), and lineFile::lineIx.
00663 { 00664 char *c; 00665 for (c = words[wordIx]; *c; c++) 00666 { 00667 if (*c == '-' || isdigit(*c)) 00668 /* NOTE: embedded '-' will be caught by lineFileNeedNum */ 00669 continue; 00670 errAbort("Expecting number field %d line %d of %s, got %s", 00671 wordIx+1, lf->lineIx, lf->fileName, words[wordIx]); 00672 } 00673 return lineFileNeedNum(lf, words, wordIx); 00674 }
Here is the call graph for this function:

| void lineFileNeedNext | ( | struct lineFile * | lf, | |
| char ** | retStart, | |||
| int * | retSize | |||
| ) |
Definition at line 487 of file linefile.c.
References lineFileNext(), and lineFileUnexpectedEnd().
Referenced by axtReadWithPos(), hpfNext(), and mafMayOpen().
00489 { 00490 if (!lineFileNext(lf, retStart, retSize)) 00491 lineFileUnexpectedEnd(lf); 00492 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int lineFileNeedNum | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | wordIx | |||
| ) |
Definition at line 676 of file linefile.c.
References errAbort(), lineFile::fileName, and lineFile::lineIx.
Referenced by axtReadWithPos(), axtScoreSchemeReadLf(), chainReadBlocks(), chainReadChainLine(), hashNameIntFile(), hpfNext(), lineFileNeedFullNum(), mafNextWithPos(), and readPslToBinKeeper().
00679 { 00680 char *ascii = words[wordIx]; 00681 char c = ascii[0]; 00682 if (c != '-' && !isdigit(c)) 00683 errAbort("Expecting number field %d line %d of %s, got %s", 00684 wordIx+1, lf->lineIx, lf->fileName, ascii); 00685 return atoi(ascii); 00686 }
Here is the call graph for this function:

Here is the caller graph for this function:

| boolean lineFileNext | ( | struct lineFile * | lf, | |
| char ** | retStart, | |||
| int * | retSize | |||
| ) |
Definition at line 304 of file linefile.c.
References lineFile::buf, lineFile::bufOffsetInFile, lineFile::bufSize, lineFile::bytesInBuf, determineNlType(), errAbort(), FALSE, lineFile::fd, lineFile::fileName, lineFile::lineEnd, lineFileExpandBuf(), lineFileLongNetRead(), lineFile::lineIx, lineFile::lineStart, metaDataAdd(), lineFile::metaOutput, nlt_dos, nlt_mac, nlt_undet, nlt_unix, lineFile::nlType, lineFile::reuse, and TRUE.
Referenced by axtReadWithPos(), axtScoreSchemeReadLf(), bfNextLine(), cgiFromFile(), convertEpsToPdf(), countWordsInFile(), dtdxTag(), eatComment(), emblLineGroup(), faMixedSpeedReadNext(), gffFileAdd(), hashWordsInFile(), lineFileChopCharNext(), lineFileChopNext(), lineFileChopNextTab(), lineFileNeedNext(), lineFileNextReal(), lineFileParseHttpHeader(), lineFileSkip(), lineFileSkipToLineStartingWith(), lineFileSlurpHttpBody(), maskFromOut(), netUrlHead(), nextLine(), phyloReadTree(), pslxFileOpen(), pslxFileOpenWithMetaConfig(), quotedPrintableDecode(), raFoldInOneRetName(), raNextRecord(), readAllLines(), readPartHeaderMB(), spacedColumnFromLineFile(), tokenizerNext(), trixOpen(), and trixSearchWordResults().
00306 { 00307 char *buf = lf->buf; 00308 int bytesInBuf = lf->bytesInBuf; 00309 int endIx = lf->lineEnd; 00310 boolean gotLf = FALSE; 00311 int newStart; 00312 00313 if (lf->reuse) 00314 { 00315 lf->reuse = FALSE; 00316 if (retSize != NULL) 00317 *retSize = lf->lineEnd - lf->lineStart; 00318 *retStart = buf + lf->lineStart; 00319 if (lf->metaOutput && *retStart[0] == '#') 00320 metaDataAdd(lf, *retStart); 00321 return TRUE; 00322 } 00323 00324 determineNlType(lf, buf+endIx, bytesInBuf); 00325 00326 /* Find next end of line in buffer. */ 00327 switch(lf->nlType) 00328 { 00329 case nlt_unix: 00330 case nlt_dos: 00331 for (endIx = lf->lineEnd; endIx < bytesInBuf; ++endIx) 00332 { 00333 if (buf[endIx] == '\n') 00334 { 00335 gotLf = TRUE; 00336 endIx += 1; 00337 break; 00338 } 00339 } 00340 break; 00341 case nlt_mac: 00342 for (endIx = lf->lineEnd; endIx < bytesInBuf; ++endIx) 00343 { 00344 if (buf[endIx] == '\r') 00345 { 00346 gotLf = TRUE; 00347 endIx += 1; 00348 break; 00349 } 00350 } 00351 break; 00352 case nlt_undet: 00353 break; 00354 } 00355 00356 /* If not in buffer read in a new buffer's worth. */ 00357 while (!gotLf) 00358 { 00359 int oldEnd = lf->lineEnd; 00360 int sizeLeft = bytesInBuf - oldEnd; 00361 int bufSize = lf->bufSize; 00362 int readSize = bufSize - sizeLeft; 00363 00364 if (oldEnd > 0 && sizeLeft > 0) 00365 { 00366 memmove(buf, buf+oldEnd, sizeLeft); 00367 } 00368 lf->bufOffsetInFile += oldEnd; 00369 if (lf->fd >= 0) 00370 readSize = lineFileLongNetRead(lf->fd, buf+sizeLeft, readSize); 00371 else 00372 readSize = 0; 00373 00374 if ((readSize == 0) && (endIx > oldEnd)) 00375 { 00376 endIx = sizeLeft; 00377 buf[endIx] = 0; 00378 lf->bytesInBuf = newStart = lf->lineStart = 0; 00379 lf->lineEnd = endIx; 00380 ++lf->lineIx; 00381 if (retSize != NULL) 00382 *retSize = endIx - newStart; 00383 *retStart = buf + newStart; 00384 if (*retStart[0] == '#') 00385 metaDataAdd(lf, *retStart); 00386 return TRUE; 00387 } 00388 else if (readSize <= 0) 00389 { 00390 lf->bytesInBuf = lf->lineStart = lf->lineEnd = 0; 00391 return FALSE; 00392 } 00393 bytesInBuf = lf->bytesInBuf = readSize + sizeLeft; 00394 lf->lineEnd = 0; 00395 00396 determineNlType(lf, buf+endIx, bytesInBuf); 00397 00398 /* Look for next end of line. */ 00399 switch(lf->nlType) 00400 { 00401 case nlt_unix: 00402 case nlt_dos: 00403 for (endIx = sizeLeft; endIx <bytesInBuf; ++endIx) 00404 { 00405 if (buf[endIx] == '\n') 00406 { 00407 endIx += 1; 00408 gotLf = TRUE; 00409 break; 00410 } 00411 } 00412 break; 00413 case nlt_mac: 00414 for (endIx = sizeLeft; endIx <bytesInBuf; ++endIx) 00415 { 00416 if (buf[endIx] == '\r') 00417 { 00418 endIx += 1; 00419 gotLf = TRUE; 00420 break; 00421 } 00422 } 00423 break; 00424 case nlt_undet: 00425 break; 00426 } 00427 if (!gotLf && bytesInBuf == lf->bufSize) 00428 { 00429 if (bufSize >= 512*1024*1024) 00430 { 00431 errAbort("Line too long (more than %d chars) line %d of %s", 00432 lf->bufSize, lf->lineIx+1, lf->fileName); 00433 } 00434 else 00435 { 00436 lineFileExpandBuf(lf, bufSize*2); 00437 buf = lf->buf; 00438 } 00439 } 00440 } 00441 00442 if (lf->zTerm) 00443 { 00444 buf[endIx-1] = 0; 00445 if ((lf->nlType == nlt_dos) && (buf[endIx-2]=='\r')) 00446 { 00447 buf[endIx-2] = 0; 00448 } 00449 } 00450 00451 lf->lineStart = newStart = lf->lineEnd; 00452 lf->lineEnd = endIx; 00453 ++lf->lineIx; 00454 if (retSize != NULL) 00455 *retSize = endIx - newStart; 00456 *retStart = buf + newStart; 00457 if (*retStart[0] == '#') 00458 metaDataAdd(lf, *retStart); 00459 return TRUE; 00460 }
Here is the call graph for this function:

Here is the caller graph for this function:

| boolean lineFileNextCharRow | ( | struct lineFile * | lf, | |
| char | sep, | |||
| char * | words[], | |||
| int | wordCount | |||
| ) |
Definition at line 621 of file linefile.c.
References FALSE, lineFileChopCharNext(), lineFileExpectWords(), and TRUE.
00624 { 00625 int wordsRead; 00626 wordsRead = lineFileChopCharNext(lf, sep, words, wordCount); 00627 if (wordsRead == 0) 00628 return FALSE; 00629 if (wordsRead < wordCount) 00630 lineFileExpectWords(lf, wordCount, wordsRead); 00631 return TRUE; 00632 }
Here is the call graph for this function:

| boolean lineFileNextReal | ( | struct lineFile * | lf, | |
| char ** | retStart | |||
| ) |
Definition at line 551 of file linefile.c.
References FALSE, lineFileNext(), skipLeadingSpaces(), and TRUE.
Referenced by dnaLoadNextFromStack(), dnaLoadStackNew(), dtdxTag(), gfWebConfigRead(), htmlCookieFileRead(), pslNext(), raFoldInOneRetName(), readTaggedNumLine(), slNameLoadReal(), and twoBitSpecNewFile().
00554 { 00555 char *s, c; 00556 while (lineFileNext(lf, retStart, NULL)) 00557 { 00558 s = skipLeadingSpaces(*retStart); 00559 c = s[0]; 00560 if (c != 0 && c != '#') 00561 { 00562 return TRUE; 00563 } 00564 } 00565 return FALSE; 00566 }
Here is the call graph for this function:

Here is the caller graph for this function:

| boolean lineFileNextRow | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | wordCount | |||
| ) |
Definition at line 634 of file linefile.c.
References FALSE, lineFileChopNext(), lineFileExpectWords(), and TRUE.
Referenced by readPslToBinKeeper().
00637 { 00638 int wordsRead; 00639 wordsRead = lineFileChopNext(lf, words, wordCount); 00640 if (wordsRead == 0) 00641 return FALSE; 00642 if (wordsRead < wordCount) 00643 lineFileExpectWords(lf, wordCount, wordsRead); 00644 return TRUE; 00645 }
Here is the call graph for this function:

Here is the caller graph for this function:

| boolean lineFileNextRowTab | ( | struct lineFile * | lf, | |
| char * | words[], | |||
| int | wordCount | |||
| ) |
Definition at line 647 of file linefile.c.
References FALSE, lineFileChopNextTab(), lineFileExpectWords(), and TRUE.
Referenced by loadPsls().
00650 { 00651 int wordsRead; 00652 wordsRead = lineFileChopNextTab(lf, words, wordCount); 00653 if (wordsRead == 0) 00654 return FALSE; 00655 if (wordsRead < wordCount) 00656 lineFileExpectWords(lf, wordCount, wordsRead); 00657 return TRUE; 00658 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct lineFile* lineFileOnString | ( | char * | name, | |
| bool | zTerm, | |||
| char * | s | |||
| ) | [read] |
Definition at line 181 of file linefile.c.
References AllocVar, lineFile::buf, lineFile::bufSize, lineFile::bytesInBuf, cloneString(), lineFile::fd, lineFile::fileName, and lineFile::zTerm.
Referenced by asParseText(), gapCalcFromString(), quotedPrintableDecode(), and readPartHeaderMB().
00185 { 00186 struct lineFile *lf; 00187 AllocVar(lf); 00188 lf->fileName = cloneString(name); 00189 lf->fd = -1; 00190 lf->bufSize = lf->bytesInBuf = strlen(s); 00191 lf->zTerm = zTerm; 00192 lf->buf = s; 00193 return lf; 00194 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct lineFile* lineFileOpen | ( | char * | fileName, | |
| bool | zTerm | |||
| ) | [read] |
Definition at line 227 of file linefile.c.
References errAbort(), errno, and lineFileMayOpen().
Referenced by asParseFile(), axtScoreSchemeRead(), bigBlat(), blastFileOpenVerify(), cgiFromFile(), chainReadAllWithMeta(), chainReadUsedSwap(), convertEpsToPdf(), countWordsInFile(), dnaLoadStackNew(), dtdParse(), emblOpen(), faReadAllSeqMixable(), faReadNamedSeq(), gapCalcFromFile(), genoFindDirect(), gfClient(), gffFileAdd(), gfPcrInputLoadAll(), gfWebConfigRead(), hashNameIntFile(), hashTwoColumnFile(), hashWordsInFile(), htmlCookieFileRead(), loadPsls(), maskFromOut(), phyloOpenTree(), pslxFileOpen(), pslxFileOpenWithMetaConfig(), raReadAll(), raReadSingle(), readAllLines(), readPslToBinKeeper(), searchOneIndex(), slNameLoadReal(), spacedColumnFromFile(), tokenizerNew(), trixOpen(), twoBitSpecNewFile(), and xAliLoadAll().
00229 { 00230 struct lineFile *lf = lineFileMayOpen(fileName, zTerm); 00231 if (lf == NULL) 00232 errAbort("Couldn't open %s , %s", fileName, strerror(errno)); 00233 return lf; 00234 }
Here is the call graph for this function:

Here is the caller graph for this function:

| boolean lineFileParseHttpHeader | ( | struct lineFile * | lf, | |
| char ** | hdr, | |||
| boolean * | chunked, | |||
| int * | contentLength | |||
| ) |
Definition at line 729 of file linefile.c.
References cloneString(), dyStringAppendC(), dyStringAppendN(), dyStringClear, dyStringFree, FALSE, lineFile::fileName, lineFileNext(), lineFileReuse(), newDyString(), nextWord(), sameString, startsWith(), dyString::string, TRUE, and warn().
Referenced by netHttpGetMultiple().
00732 : chunked" or if it has a contentLength. */ 00733 { 00734 struct dyString *header = newDyString(1024); 00735 char *line; 00736 int lineSize; 00737 00738 if (chunked != NULL) 00739 *chunked = FALSE; 00740 if (contentLength != NULL) 00741 *contentLength = -1; 00742 dyStringClear(header); 00743 if (lineFileNext(lf, &line, &lineSize)) 00744 { 00745 if (startsWith("HTTP/", line)) 00746 { 00747 char *version, *code; 00748 dyStringAppendN(header, line, lineSize-1); 00749 dyStringAppendC(header, '\n'); 00750 version = nextWord(&line); 00751 code = nextWord(&line); 00752 if (code == NULL) 00753 { 00754 warn("%s: Expecting HTTP/<version> <code> header line, got this: %s\n", lf->fileName, header->string); 00755 *hdr = cloneString(header->string); 00756 dyStringFree(&header); 00757 return FALSE; 00758 } 00759 if (!sameString(code, "200")) 00760 { 00761 warn("%s: Errored HTTP response header: %s %s %s\n", lf->fileName, version, code, line); 00762 *hdr = cloneString(header->string); 00763 dyStringFree(&header); 00764 return FALSE; 00765 } 00766 while (lineFileNext(lf, &line, &lineSize)) 00767 { 00768 /* blank line means end of HTTP header */ 00769 if ((line[0] == '\r' && line[1] == 0) || line[0] == 0) 00770 break; 00771 if (strstr(line, "Transfer-Encoding: chunked") && chunked != NULL) 00772 *chunked = TRUE; 00773 dyStringAppendN(header, line, lineSize-1); 00774 dyStringAppendC(header, '\n'); 00775 if (strstr(line, "Content-Length:")) 00776 { 00777 code = nextWord(&line); 00778 code = nextWord(&line); 00779 if (contentLength != NULL) 00780 *contentLength = atoi(code); 00781 } 00782 } 00783 } 00784 else 00785 { 00786 /* put the line back, don't put it in header/hdr */ 00787 lineFileReuse(lf); 00788 warn("%s: Expecting HTTP/<version> <code> header line, got this: %s\n", lf->fileName, header->string); 00789 *hdr = cloneString(header->string); 00790 dyStringFree(&header); 00791 return FALSE; 00792 } 00793 } 00794 else 00795 { 00796 *hdr = cloneString(header->string); 00797 dyStringFree(&header); 00798 return FALSE; 00799 } 00800 00801 *hdr = cloneString(header->string); 00802 dyStringFree(&header); 00803 return TRUE; 00804 } /* lineFileParseHttpHeader */
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileReuse | ( | struct lineFile * | lf | ) |
Definition at line 236 of file linefile.c.
References lineFile::reuse, and TRUE.
Referenced by bfSkipBlankLines(), blastFileNextQuery(), dnaLoadStackNew(), emblLineGroup(), faMixedSpeedReadNext(), lineFileParseHttpHeader(), lineFileSlurpHttpBody(), nextBlock(), nextBlockLine(), pslxFileOpen(), pslxFileOpenWithMetaConfig(), and raNextRecord().
Here is the caller graph for this function:

| void lineFileSeek | ( | struct lineFile * | lf, | |
| off_t | offset, | |||
| int | whence | |||
| ) |
Definition at line 243 of file linefile.c.
References lineFile::bufOffsetInFile, lineFile::bytesInBuf, errnoAbort(), FALSE, lineFile::fd, lineFile::fileName, lineFile::lineEnd, lineFile::lineStart, lineFile::pl, lineFile::reuse, and SEEK_SET.
Referenced by mafRewind(), and trixSearchWordResults().
00245 { 00246 if (lf->pl != NULL) 00247 errnoAbort("Can't lineFileSeek on a compressed file: %s", lf->fileName); 00248 lf->reuse = FALSE; 00249 if (whence == SEEK_SET && offset >= lf->bufOffsetInFile 00250 && offset < lf->bufOffsetInFile + lf->bytesInBuf) 00251 { 00252 lf->lineStart = lf->lineEnd = offset - lf->bufOffsetInFile; 00253 } 00254 else 00255 { 00256 lf->lineStart = lf->lineEnd = lf->bytesInBuf = 0; 00257 if ((lf->bufOffsetInFile = lseek(lf->fd, offset, whence)) == -1) 00258 errnoAbort("Couldn't lineFileSeek %s", lf->fileName); 00259 } 00260 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileSetMetaDataOutput | ( | struct lineFile * | lf, | |
| FILE * | f | |||
| ) |
Definition at line 78 of file linefile.c.
References AllocVar, metaOutput::metaFile, lineFile::metaOutput, metaOutput::next, and slAddHead.
Referenced by chainReadAllWithMeta(), and pslxFileOpenWithMetaConfig().
00081 { 00082 struct metaOutput *meta = NULL; 00083 if (lf == NULL) 00084 return; 00085 AllocVar(meta); 00086 meta->next = NULL; 00087 meta->metaFile = f; 00088 slAddHead(&lf->metaOutput, meta); 00089 }
Here is the caller graph for this function:

| void lineFileSetUniqueMetaData | ( | struct lineFile * | lf | ) |
Definition at line 91 of file linefile.c.
References hashNew, lineFile::isMetaUnique, lineFile::metaLines, and TRUE.
Referenced by pslxFileOpenWithMetaConfig().
00093 { 00094 lf->isMetaUnique = TRUE; 00095 lf->metaLines = hashNew(8); 00096 }
Here is the caller graph for this function:

| void lineFileShort | ( | struct lineFile * | lf | ) |
Definition at line 545 of file linefile.c.
References errAbort(), lineFile::fileName, and lineFile::lineIx.
Here is the call graph for this function:

| void lineFileSkip | ( | struct lineFile * | lf, | |
| int | lineCount | |||
| ) |
Definition at line 703 of file linefile.c.
References errAbort(), lineFile::fileName, and lineFileNext().
00705 { 00706 int i, lineSize; 00707 char *line; 00708 00709 for (i=0; i<lineCount; ++i) 00710 { 00711 if (!lineFileNext(lf, &line, &lineSize)) 00712 errAbort("Premature end of file in %s", lf->fileName); 00713 } 00714 }
Here is the call graph for this function:

| char* lineFileSkipToLineStartingWith | ( | struct lineFile * | lf, | |
| char * | start, | |||
| int | maxCount | |||
| ) |
Definition at line 716 of file linefile.c.
References lineFileNext(), and startsWith().
Referenced by hpfNext(), and needLineStartingWith().
00719 { 00720 char *line; 00721 while (lineFileNext(lf, &line, NULL) && --maxCount >= 0) 00722 { 00723 if (startsWith(start, line)) 00724 return line; 00725 } 00726 return NULL; 00727 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct dyString* lineFileSlurpHttpBody | ( | struct lineFile * | lf, | |
| boolean | chunked, | |||
| int | contentLength | |||
| ) | [read] |
Definition at line 806 of file linefile.c.
References dyStringAppendC(), dyStringAppendN(), dyStringClear, lineFile::fileName, lineFileNext(), lineFileReuse(), newDyString(), nextWord(), startsWith(), dyString::string, dyString::stringSize, and warn().
Referenced by netHttpGetMultiple().
00810 { 00811 struct dyString *body = newDyString(64*1024); 00812 char *line; 00813 int lineSize; 00814 00815 dyStringClear(body); 00816 if (chunked) 00817 { 00818 /* Handle "Transfer-Encoding: chunked" body */ 00819 /* Procedure from RFC2068 section 19.4.6 */ 00820 char *csword; 00821 unsigned chunkSize = 0; 00822 unsigned size; 00823 do 00824 { 00825 /* Read line that has chunk size (in hex) as first word. */ 00826 if (lineFileNext(lf, &line, NULL)) 00827 csword = nextWord(&line); 00828 else break; 00829 if (sscanf(csword, "%x", &chunkSize) < 1) 00830 { 00831 warn("%s: chunked transfer-encoding chunk size parse error.\n", 00832 lf->fileName); 00833 break; 00834 } 00835 /* If chunk size is 0, read in a blank line & then we're done. */ 00836 if (chunkSize == 0) 00837 { 00838 lineFileNext(lf, &line, NULL); 00839 if (line == NULL || (line[0] != '\r' && line[0] != 0)) 00840 warn("%s: chunked transfer-encoding: expected blank line, got %s\n", 00841 lf->fileName, line); 00842 00843 break; 00844 } 00845 /* Read (and save) lines until we have read in chunk. */ 00846 for (size = 0; size < chunkSize; size += lineSize) 00847 { 00848 if (! lineFileNext(lf, &line, &lineSize)) 00849 break; 00850 dyStringAppendN(body, line, lineSize-1); 00851 dyStringAppendC(body, '\n'); 00852 } 00853 /* Read blank line - or extra CRLF inserted in the middle of the 00854 * current line, in which case we need to trim it. */ 00855 if (size > chunkSize) 00856 { 00857 body->stringSize -= (size - chunkSize); 00858 body->string[body->stringSize] = 0; 00859 } 00860 else if (size == chunkSize) 00861 { 00862 lineFileNext(lf, &line, NULL); 00863 if (line == NULL || (line[0] != '\r' && line[0] != 0)) 00864 warn("%s: chunked transfer-encoding: expected blank line, got %s\n", 00865 lf->fileName, line); 00866 } 00867 } while (chunkSize > 0); 00868 /* Try to read in next line. If it's an HTTP header, put it back. */ 00869 /* If there is a next line but it's not an HTTP header, it's a footer. */ 00870 if (lineFileNext(lf, &line, NULL)) 00871 { 00872 if (startsWith("HTTP/", line)) 00873 lineFileReuse(lf); 00874 else 00875 { 00876 /* Got a footer -- keep reading until blank line */ 00877 warn("%s: chunked transfer-encoding: got footer %s, discarding it.\n", 00878 lf->fileName, line); 00879 while (lineFileNext(lf, &line, NULL)) 00880 { 00881 if ((line[0] == '\r' && line[1] == 0) || line[0] == 0) 00882 break; 00883 warn("discarding footer line: %s\n", line); 00884 } 00885 } 00886 } 00887 } 00888 else if (contentLength >= 0) 00889 { 00890 /* Read in known length */ 00891 int size; 00892 for (size = 0; size < contentLength; size += lineSize) 00893 { 00894 if (! lineFileNext(lf, &line, &lineSize)) 00895 break; 00896 dyStringAppendN(body, line, lineSize-1); 00897 dyStringAppendC(body, '\n'); 00898 } 00899 } 00900 else 00901 { 00902 /* Read in to end of file (assume it's not a persistent connection) */ 00903 while (lineFileNext(lf, &line, &lineSize)) 00904 { 00905 dyStringAppendN(body, line, lineSize-1); 00906 dyStringAppendC(body, '\n'); 00907 } 00908 } 00909 00910 return(body); 00911 } /* lineFileSlurpHttpBody */
Here is the call graph for this function:

Here is the caller graph for this function:

| struct lineFile* lineFileStdin | ( | bool | zTerm | ) | [read] |
Definition at line 205 of file linefile.c.
References lineFileAttach().
Referenced by lineFileMayOpen().
00207 { 00208 return lineFileAttach("stdin", zTerm, fileno(stdin)); 00209 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileUnexpectedEnd | ( | struct lineFile * | lf | ) |
Definition at line 481 of file linefile.c.
References errAbort(), and lineFile::fileName.
Referenced by lineFileNeedNext(), and readTaggedNumLine().
Here is the call graph for this function:

Here is the caller graph for this function:

| void lineFileVaAbort | ( | struct lineFile * | lf, | |
| char * | format, | |||
| va_list | args | |||
| ) |
Definition at line 462 of file linefile.c.
References dyStringFree, dyStringNew, dyStringPrintf(), dyStringVaPrintf(), errAbort(), lineFile::fileName, lineFile::lineIx, and dyString::string.
Referenced by lineFileAbort().
00464 { 00465 struct dyString *dy = dyStringNew(0); 00466 dyStringPrintf(dy, "Error line %d of %s: ", lf->lineIx, lf->fileName); 00467 dyStringVaPrintf(dy, format, args); 00468 errAbort("%s", dy->string); 00469 dyStringFree(&dy); 00470 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void metaDataAdd | ( | struct lineFile * | lf, | |
| char * | line | |||
| ) | [static] |
Definition at line 51 of file linefile.c.
References hashAdd(), hashLookup(), lineFile::isMetaUnique, metaOutput::metaFile, lineFile::metaLines, lineFile::metaOutput, and metaOutput::next.
Referenced by lineFileNext().
00054 { 00055 struct metaOutput *meta = NULL; 00056 00057 if (lf->isMetaUnique) 00058 { 00059 /* suppress repetition of comments */ 00060 if (hashLookup(lf->metaLines, line)) 00061 { 00062 return; 00063 } 00064 hashAdd(lf->metaLines, line, NULL); 00065 } 00066 for (meta = lf->metaOutput ; meta != NULL ; meta = meta->next) 00067 if (line != NULL && meta->metaFile != NULL) 00068 fprintf(meta->metaFile,"%s\n", line); 00069 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void metaDataFree | ( | struct lineFile * | lf | ) | [static] |
Definition at line 71 of file linefile.c.
References freeHash(), lineFile::isMetaUnique, and lineFile::metaLines.
Referenced by lineFileClose().
00073 { 00074 if (lf->isMetaUnique && lf->metaLines) 00075 freeHash(&lf->metaLines); 00076 }
Here is the call graph for this function:

Here is the caller graph for this function:

char const rcsid[] = "$Id: linefile.c,v 1.54 2007/03/23 08:12:42 kent Exp $" [static] |
Definition at line 16 of file linefile.c.
1.5.2