|
|
| version 1.1.1.1, 2012/02/21 22:57:49 | version 1.1.1.2, 2012/05/29 09:29:44 |
|---|---|
| Line 62 xrealloc (void *p, size_t n) | Line 62 xrealloc (void *p, size_t n) |
| struct linebuffer | struct linebuffer |
| { | { |
| size_t size; /* Allocated. */ | size_t size; /* Allocated. */ |
| size_t length; /* Used. */ | size_t length; /* Used. */ |
| char *buffer; | char *buffer; |
| }; | }; |
| Line 97 readline (struct linebuffer *linebuffer, FILE *stream) | Line 97 readline (struct linebuffer *linebuffer, FILE *stream) |
| { | { |
| c = getc (stream); | c = getc (stream); |
| if (c == EOF) | if (c == EOF) |
| { | { |
| if (p == buffer) | if (p == buffer) |
| return 0; | return 0; |
| if (p[-1] == '\n') | if (p[-1] == '\n') |
| break; | break; |
| c = '\n'; | c = '\n'; |
| } | } |
| if (p == end) | if (p == end) |
| { | { |
| linebuffer->size *= 2; | linebuffer->size *= 2; |
| buffer = (char *) xrealloc (buffer, linebuffer->size); | buffer = (char *) xrealloc (buffer, linebuffer->size); |
| p = p - linebuffer->buffer + buffer; | p = p - linebuffer->buffer + buffer; |
| linebuffer->buffer = buffer; | linebuffer->buffer = buffer; |
| end = buffer + linebuffer->size - 1; | end = buffer + linebuffer->size - 1; |
| } | } |
| *p++ = c; | *p++ = c; |
| } | } |
| while (c != '\n'); | while (c != '\n'); |
| Line 210 check_file (const char *infile, const char *outfile) | Line 210 check_file (const char *infile, const char *outfile) |
| { | { |
| int match; | int match; |
| if (readline (thisline, istream) == 0) | if (readline (thisline, istream) == 0) |
| break; | break; |
| thisfield = thisline->buffer; | thisfield = thisline->buffer; |
| thislen = thisline->length; | thislen = thisline->length; |
| match = !different (thisfield, prevfield, thislen, prevlen); | match = !different (thisfield, prevfield, thislen, prevlen); |
| if (match) | if (match) |
| ++match_count; | ++match_count; |
| if (!match) | if (!match) |
| { | { |
| writeline (prevline, ostream, match_count); | writeline (prevline, ostream, match_count); |
| exch = prevline; | exch = prevline; |
| prevline = thisline; | prevline = thisline; |
| thisline = exch; | thisline = exch; |
| prevfield = thisfield; | prevfield = thisfield; |
| prevlen = thislen; | prevlen = thislen; |
| if (!match) | if (!match) |
| match_count = 0; | match_count = 0; |
| } | } |
| } | } |
| writeline (prevline, ostream, match_count); | writeline (prevline, ostream, match_count); |