… | |
… | |
540 | * This routine can read a line of any length if it is called enough times. |
540 | * This routine can read a line of any length if it is called enough times. |
541 | */ |
541 | */ |
542 | int |
542 | int |
543 | lineinput (struct logfile_entry *logfile) |
543 | lineinput (struct logfile_entry *logfile) |
544 | { |
544 | { |
545 | char buff[1024], *p = buff; |
545 | char buff[1024], *p; |
546 | int ch; |
546 | int ch; |
547 | /* HACK-2: add on the length of any partial line which we will be appending to */ |
547 | /* HACK-2: add on the length of any partial line which we will be appending to */ |
548 | int ofs = logfile->buf ? strlen (logfile->buf) : 0; |
548 | int ofs = logfile->buf ? strlen (logfile->buf) : 0; |
549 | |
549 | |
|
|
550 | /* this loop ensures that the whole line is read, even if it's |
|
|
551 | * longer than the buffer. we need to do this because when --whole |
|
|
552 | * is in effect we don't know whether to display the line or not |
|
|
553 | * until we've seen how (ie. whether) it ends */ |
550 | do |
554 | do |
551 | { |
555 | { |
|
|
556 | p = buff; |
|
|
557 | do |
|
|
558 | { |
552 | ch = fgetc (logfile->fp); |
559 | ch = fgetc (logfile->fp); |
553 | |
560 | |
554 | if (ch == '\n' || ch == EOF) |
561 | if (ch == '\n' || ch == EOF) |
555 | break; |
562 | break; |
556 | else if (ch == '\r') |
563 | else if (ch == '\r') |
557 | continue; /* skip */ |
564 | continue; /* skip */ |
558 | else if (ch == '\t') |
565 | else if (ch == '\t') |
559 | { |
566 | { |
560 | do |
567 | do |
561 | { |
568 | { |
562 | *p++ = ' '; |
569 | *p++ = ' '; |
563 | ofs++; |
570 | ofs++; |
564 | } |
571 | } |
565 | while (ofs & 7); |
572 | while (ofs & 7); |
566 | } |
|
|
567 | else |
|
|
568 | { |
|
|
569 | *p++ = ch; |
|
|
570 | ofs++; |
|
|
571 | } |
|
|
572 | } |
573 | } |
|
|
574 | else |
|
|
575 | { |
|
|
576 | *p++ = ch; |
|
|
577 | ofs++; |
|
|
578 | } |
|
|
579 | } |
573 | while (p < buff + (sizeof buff) - 8 - 1); |
580 | while (p < buff + (sizeof buff) - 8 - 1); |
574 | |
581 | |
575 | if (p == buff && ch == EOF) |
582 | if (p == buff && ch == EOF) |
576 | return 0; |
583 | return 0; |
577 | |
584 | |
578 | *p = 0; |
585 | *p = 0; |
579 | |
586 | |
580 | p = concat_line (logfile->buf, buff); |
587 | p = concat_line (logfile->buf, buff); |
581 | free (logfile->buf); logfile->buf = p; |
588 | free (logfile->buf); logfile->buf = p; |
|
|
589 | } |
|
|
590 | while (ch != '\n' && ch != EOF); |
582 | |
591 | |
583 | logfile->lastpartial = logfile->partial; |
592 | logfile->lastpartial = logfile->partial; |
584 | /* there are 3 ways we could have exited the loop: reading '\n', |
593 | /* there are 3 ways we could have exited the loop: reading '\n', |
585 | * reaching EOF, or filling the buffer; the 2nd and 3rd of these |
594 | * reaching EOF, or filling the buffer; the 2nd and 3rd of these |
586 | * both result in a partial line */ |
595 | * both result in a partial line */ |