| @@ -200,42 +200,82 @@ int readrec(uschar **pbuf, int *pbufsize | | | @@ -200,42 +200,82 @@ int readrec(uschar **pbuf, int *pbufsize |
200 | free(inputFS); | | 200 | free(inputFS); |
201 | inputFS = malloc(len + 1); | | 201 | inputFS = malloc(len + 1); |
202 | if (inputFS == NULL) | | 202 | if (inputFS == NULL) |
203 | FATAL("field separator %.10s... is too long", *FS); | | 203 | FATAL("field separator %.10s... is too long", *FS); |
204 | len_inputFS = len; | | 204 | len_inputFS = len; |
205 | memcpy(inputFS, *FS, len + 1); | | 205 | memcpy(inputFS, *FS, len + 1); |
206 | } | | 206 | } |
207 | if ((sep = **RS) == 0) { | | 207 | if ((sep = **RS) == 0) { |
208 | sep = '\n'; | | 208 | sep = '\n'; |
209 | while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ | | 209 | while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ |
210 | ; | | 210 | ; |
211 | if (c != EOF) | | 211 | if (c != EOF) |
212 | ungetc(c, inf); | | 212 | ungetc(c, inf); |
213 | } | | 213 | } else if ((*RS)[1]) { |
214 | for (rr = buf; ; ) { | | 214 | fa *pfa = makedfa(*RS, 1); |
215 | for (; (c=getc(inf)) != sep && c != EOF; ) { | | 215 | int tempstat = pfa->initstat; |
216 | if (rr-buf+1 > bufsize) | | 216 | char *brr = buf; |
217 | if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 1")) | | 217 | char *rrr = NULL; |
218 | FATAL("input record `%.30s...' too long", buf); | | 218 | int x; |
| | | 219 | for (rr = buf; ; ) { |
| | | 220 | while ((c = getc(inf)) != EOF) { |
| | | 221 | if (rr-buf+3 > bufsize) |
| | | 222 | if (!adjbuf(&buf, &bufsize, 3+rr-buf, |
| | | 223 | recsize, &rr, "readrec 2")) |
| | | 224 | FATAL("input record `%.30s...'" |
| | | 225 | " too long", buf); |
| | | 226 | *rr++ = c; |
| | | 227 | *rr = '\0'; |
| | | 228 | if (!(x = nematch(pfa, brr))) { |
| | | 229 | pfa->initstat = tempstat; |
| | | 230 | if (rrr) { |
| | | 231 | rr = rrr; |
| | | 232 | ungetc(c, inf); |
| | | 233 | break; |
| | | 234 | } |
| | | 235 | } else { |
| | | 236 | pfa->initstat = 2; |
| | | 237 | brr = rrr = rr = patbeg; |
| | | 238 | } |
| | | 239 | } |
| | | 240 | if (rrr || c == EOF) |
| | | 241 | break; |
| | | 242 | if ((c = getc(inf)) == '\n' || c == EOF) |
| | | 243 | /* 2 in a row */ |
| | | 244 | break; |
| | | 245 | *rr++ = '\n'; |
| | | 246 | *rr++ = c; |
| | | 247 | } |
| | | 248 | } else { |
| | | 249 | for (rr = buf; ; ) { |
| | | 250 | for (; (c=getc(inf)) != sep && c != EOF; ) { |
| | | 251 | if (rr-buf+1 > bufsize) |
| | | 252 | if (!adjbuf(&buf, &bufsize, 1+rr-buf, |
| | | 253 | recsize, &rr, "readrec 1")) |
| | | 254 | FATAL("input record `%.30s...'" |
| | | 255 | " too long", buf); |
| | | 256 | *rr++ = c; |
| | | 257 | } |
| | | 258 | if (**RS == sep || c == EOF) |
| | | 259 | break; |
| | | 260 | if ((c = getc(inf)) == '\n' || c == EOF) |
| | | 261 | /* 2 in a row */ |
| | | 262 | break; |
| | | 263 | if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr, |
| | | 264 | "readrec 2")) |
| | | 265 | FATAL("input record `%.30s...' too long", buf); |
| | | 266 | *rr++ = '\n'; |
219 | *rr++ = c; | | 267 | *rr++ = c; |
220 | } | | 268 | } |
221 | if (**RS == sep || c == EOF) | | | |
222 | break; | | | |
223 | if ((c = getc(inf)) == '\n' || c == EOF) /* 2 in a row */ | | | |
224 | break; | | | |
225 | if (!adjbuf(&buf, &bufsize, 2+rr-buf, recsize, &rr, "readrec 2")) | | | |
226 | FATAL("input record `%.30s...' too long", buf); | | | |
227 | *rr++ = '\n'; | | | |
228 | *rr++ = c; | | | |
229 | } | | 269 | } |
230 | if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) | | 270 | if (!adjbuf(&buf, &bufsize, 1+rr-buf, recsize, &rr, "readrec 3")) |
231 | FATAL("input record `%.30s...' too long", buf); | | 271 | FATAL("input record `%.30s...' too long", buf); |
232 | *rr = 0; | | 272 | *rr = 0; |
233 | dprintf( ("readrec saw <%s>, returns %d\n", buf, c == EOF && rr == buf ? 0 : 1) ); | | 273 | dprintf( ("readrec saw <%s>, returns %d\n", buf, c == EOF && rr == buf ? 0 : 1) ); |
234 | *pbuf = buf; | | 274 | *pbuf = buf; |
235 | *pbufsize = bufsize; | | 275 | *pbufsize = bufsize; |
236 | return c == EOF && rr == buf ? 0 : 1; | | 276 | return c == EOF && rr == buf ? 0 : 1; |
237 | } | | 277 | } |
238 | | | 278 | |
239 | char *getargv(int n) /* get ARGV[n] */ | | 279 | char *getargv(int n) /* get ARGV[n] */ |
240 | { | | 280 | { |
241 | Cell *x; | | 281 | Cell *x; |