00001
00002
00003
00004
00005
00006
00007 #ifndef LINEFILE_H
00008 #define LINEFILE_H
00009
00010 enum nlType {
00011 nlt_undet,
00012 nlt_unix,
00013 nlt_dos,
00014 nlt_mac
00015 };
00016
00017 struct metaOutput
00018
00019
00020 {
00021 struct metaOutput *next;
00022 FILE *metaFile;
00023 };
00024
00025 struct lineFile
00026
00027
00028 {
00029 struct lineFile *next;
00030 char *fileName;
00031 int fd;
00032 int bufSize;
00033 off_t bufOffsetInFile;
00034 int bytesInBuf;
00035 int reserved;
00036 int lineIx;
00037 int lineStart;
00038 int lineEnd;
00039 bool zTerm;
00040 enum nlType nlType;
00041 bool reuse;
00042 char *buf;
00043 struct pipeline *pl;
00044 struct metaOutput *metaOutput;
00045 bool isMetaUnique;
00046 struct hash *metaLines;
00047 };
00048
00049 char *getFileNameFromHdrSig(char *m);
00050
00051
00052
00053 struct lineFile *lineFileDecompressFd(char *name, bool zTerm, int fd);
00054
00055
00056 struct lineFile *lineFileDecompressMem(bool zTerm, char *mem, long size);
00057
00058
00059 struct lineFile *lineFileMayOpen(char *fileName, bool zTerm);
00060
00061
00062
00063 struct lineFile *lineFileOpen(char *fileName, bool zTerm);
00064
00065
00066
00067 struct lineFile *lineFileAttach(char *fileName, bool zTerm, int fd);
00068
00069
00070 struct lineFile *lineFileStdin(bool zTerm);
00071
00072
00073 struct lineFile *lineFileOnString(char *name, bool zTerm, char *s);
00074
00075
00076
00077
00078 void lineFileClose(struct lineFile **pLf);
00079
00080
00081 void lineFileCloseList(struct lineFile **pList);
00082
00083
00084 boolean lineFileNext(struct lineFile *lf, char **retStart, int *retSize);
00085
00086
00087 boolean lineFileNextReal(struct lineFile *lf, char **retStart);
00088
00089
00090
00091 void lineFileNeedNext(struct lineFile *lf, char **retStart, int *retSize);
00092
00093
00094 void lineFileReuse(struct lineFile *lf);
00095
00096
00097 #define lineFileString(lf) ((lf)->buf + (lf)->lineStart)
00098
00099
00100 #define lineFileTell(lf) ((lf)->bufOffsetInFile + (lf)->lineStart)
00101
00102
00103 void lineFileSeek(struct lineFile *lf, off_t offset, int whence);
00104
00105
00106 void lineFileAbort(struct lineFile *lf, char *format, ...)
00107
00108 #if defined(__GNUC__) && defined(JK_WARN)
00109 __attribute__((format(printf, 2, 3)))
00110 #endif
00111 ;
00112
00113 void lineFileVaAbort(struct lineFile *lf, char *format, va_list args);
00114
00115
00116 void lineFileUnexpectedEnd(struct lineFile *lf);
00117
00118
00119 void lineFileExpectWords(struct lineFile *lf, int expecting, int got);
00120
00121
00122 void lineFileExpectAtLeast(struct lineFile *lf, int expecting, int got);
00123
00124
00125 void lineFileShort(struct lineFile *lf);
00126
00127
00128 boolean lineFileNextRow(struct lineFile *lf, char *words[], int wordCount);
00129
00130
00131
00132 #define lineFileRow(lf, words) lineFileNextRow(lf, words, ArraySize(words))
00133
00134
00135 boolean lineFileNextCharRow(struct lineFile *lf, char sep, char *words[], int wordCount);
00136
00137
00138
00139 boolean lineFileNextRowTab(struct lineFile *lf, char *words[], int wordCount);
00140
00141
00142
00143 #define lineFileRowTab(lf, words) \
00144 lineFileNextRowTab(lf, words, ArraySize(words))
00145
00146
00147 int lineFileChopNext(struct lineFile *lf, char *words[], int maxWords);
00148
00149
00150 #define lineFileChop(lf, words) lineFileChopNext(lf, words, ArraySize(words))
00151
00152
00153 int lineFileChopCharNext(struct lineFile *lf, char sep, char *words[], int maxWords);
00154
00155
00156
00157 int lineFileChopNextTab(struct lineFile *lf, char *words[], int maxWords);
00158
00159
00160
00161 #define lineFileChopTab(lf, words) lineFileChopNextTab(lf, words, ArraySize(words))
00162
00163
00164 int lineFileNeedNum(struct lineFile *lf, char *words[], int wordIx);
00165
00166
00167
00168 int lineFileNeedFullNum(struct lineFile *lf, char *words[], int wordIx);
00169
00170
00171
00172 double lineFileNeedDouble(struct lineFile *lf, char *words[], int wordIx);
00173
00174
00175
00176 void lineFileSkip(struct lineFile *lf, int lineCount);
00177
00178
00179 char *lineFileSkipToLineStartingWith(struct lineFile *lf, char *start, int maxCount);
00180
00181
00182
00183 boolean lineFileParseHttpHeader(struct lineFile *lf, char **hdr,
00184 boolean *chunked, int *contentLength);
00185
00186
00187
00188 struct dyString *lineFileSlurpHttpBody(struct lineFile *lf,
00189 boolean chunked, int contentLength);
00190
00191
00192
00193 void lineFileSetMetaDataOutput(struct lineFile *lf, FILE *f);
00194
00195
00196
00197 void lineFileSetUniqueMetaData(struct lineFile *lf);
00198
00199
00200 #endif
00201
00202