Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

reverse mode doesn't skip whitespace #15

Closed
Villemoes opened this issue Oct 23, 2024 · 3 comments
Closed

reverse mode doesn't skip whitespace #15

Villemoes opened this issue Oct 23, 2024 · 3 comments

Comments

@Villemoes
Copy link

With the xxd from vim:

$ printf 'aabbccdd\n01234567\n' | xxd -p -r | xxd -p
aabbccdd01234567

With tinyxxd, the same command results in

$ printf 'aabbccdd\n01234567\n' | xxd -p -r | xxd -p
aabbccdd

That is, the reverse hexdump stops upon hitting the newline character.

I ran into this with a script of mine that uses xxd to convert a series of sha256 outputs to binary, as in

for i in 0 1 2 3 ; do blabla $i | sha256sum ; done | awk '{print $1}' | xxd -p -r | ...

Of course I could insert a step in the pipe that deletes any whitespace, but that wasn't necessary with vim-xxd. So as tinyxxd claims to be a drop-in replacement, I think it's a bug.

The vim code does

  while ((c = getc(fpi)) != EOF)
    {
      if (c == '\r')    /* Doze style input file? */
        continue;

      /* Allow multiple spaces.  This doesn't work when there is normal text
       * after the hex codes in the last line that looks like hex, thus only
       * use it for PostScript format. */
      if (hextype == HEX_POSTSCRIPT && (c == ' ' || c == '\n' || c == '\t'))
        continue;

and as tinyxxd has a separate function for the "reverse, postscript" case, I think its loop could simply just be changed to

    while (((c = getc(input_file)) != EOF)) {
        if ( c == ' ' || c == '\n' || c == '\t' || c != '\r')
             continue;
@xyproto
Copy link
Owner

xyproto commented Oct 23, 2024

Thanks for reporting! I updated the code and everything looks good here now. Please confirm that it now works as expected.

@Villemoes
Copy link
Author

Indeed, my script now works as expected. Thanks for fixing this so quickly!

@xyproto
Copy link
Owner

xyproto commented Oct 23, 2024

Thanks for testing!

philiptaron added a commit to philiptaron/nixpkgs that referenced this issue Oct 23, 2024
Diff: xyproto/tinyxxd@v1.3.6...v1.3.7

A compatibility error with vim's xxd was reported and fixed:

- xyproto/tinyxxd#15
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants