Skip to content

Commit

Permalink
More fixes to edge cases in --head.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Shepperd committed Aug 15, 2023
1 parent 9be8685 commit fc9147c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct
char **tailArray; /* Pointer to array of pointers */
int numTails; /* Total number of entries in array */
int inIndex; /* Index to next entry to insert */
int tailsRecorded; /* Number of tails recorded so far */
int numHeads; /* flag indicatinng there's a head count */
int head; /* Number of records output so far */
int skipToEnd; /* bool indicating to skip to end of file */
Expand Down Expand Up @@ -93,6 +94,7 @@ static int recordString(FILE *ofp, Tail_t *tailPtr, const char *msg)
++tailPtr->inIndex; /* count it */
if ( tailPtr->inIndex >= tailPtr->numTails ) /* make the count modulo the amount wanted */
tailPtr->inIndex = 0;
++tailPtr->tailsRecorded;
}
return 0; /* keep saving more tail strings */
}
Expand Down Expand Up @@ -138,9 +140,8 @@ void dump_bytes(FILE *ofp, FILE *ifp, CmdOptions_t *opts)
sts = fread(newBuf, 1, bufSize, ifp);
if ( lineCnt && sts == bufSize && memcmp(oldBuf, newBuf, bufSize) == 0 )
{
if ( !tails.numHeads || tails.head > 1 )
if ( !tails.numHeads || tails.tailsRecorded || (tails.numHeads && dups < tails.head-1) )
{
--tails.head;
++dups;
continue;
}
Expand Down

0 comments on commit fc9147c

Please sign in to comment.