[vim/vim] xxd: Add -n[ame] option to set the variable name used with -i (PR #10599)

974 views
Skip to first unread message

David Gow

unread,
Jun 20, 2022, 3:32:45 AM6/20/22
to vim/vim, Subscribed

At present, xxd -i will always create an output file either with no variables (if stdin is used as input), or with variables with names
based on the input filename/path. In particular:

  • An array of bytes with the name of the input file (with special characters removed), and
  • An integer length of the output.

It'd be very convenient to allow overriding these names (or providing them at all in the case of stdin), particularly since they're based on the exact argument passed to xxd, which may be an absolute path. (No one would want to have to access variables based on the absolute path name in their code!)

This patch adds a -n option, which accepts a new variable name as an argument. This variable name is used for the data, and _len is appended to it for the length variable. Both still have special characters stripped and replaced with '_', and are capitalised if -C is used.

For example:

xxd -i -n myvar ~/data.dat

produces the following variables:

  • unsigned char myvar[]
  • unsigned int myvar_len
    instead of something like:
  • unsigned char _home_david_data_dat
  • unsigned int _home_david_data_dat_len

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/10599

Commit Summary

  • 852c275 xxd: Add -n[ame] option to set the variable name used with -i

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599@github.com>

K.Takata

unread,
Jun 20, 2022, 3:46:37 AM6/20/22
to vim/vim, Subscribed

runtime/doc/xxd.man.1 should be also updated.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/c1160092614@github.com>

codecov[bot]

unread,
Jun 20, 2022, 3:51:49 AM6/20/22
to vim/vim, Subscribed

Codecov Report

Merging #10599 (852c275) into master (e366ed4) will increase coverage by 0.89%.
The diff coverage is n/a.

@@            Coverage Diff             @@

##           master   #10599      +/-   ##

==========================================

+ Coverage   81.70%   82.59%   +0.89%     

==========================================

  Files         158      148      -10     

  Lines      185384   172729   -12655     

  Branches    41931    39053    -2878     

==========================================

- Hits       151463   142669    -8794     

+ Misses      21459    17464    -3995     

- Partials    12462    12596     +134     
Flag Coverage Δ
huge-clang-none 82.59% <ø> (-0.01%) ⬇️
linux 82.59% <ø> (-0.01%) ⬇️
mingw-x64-HUGE ?
mingw-x64-HUGE-gui ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/highlight.c 78.69% <0.00%> (-2.70%) ⬇️
src/time.c 87.08% <0.00%> (-2.56%) ⬇️
src/misc2.c 86.38% <0.00%> (-2.52%) ⬇️
src/buffer.c 84.15% <0.00%> (-2.39%) ⬇️
src/help.c 80.07% <0.00%> (-2.38%) ⬇️
src/session.c 63.15% <0.00%> (-1.94%) ⬇️
src/menu.c 81.37% <0.00%> (-1.83%) ⬇️
src/gui.c 71.19% <0.00%> (-1.78%) ⬇️
src/arglist.c 83.83% <0.00%> (-1.72%) ⬇️
src/vim9cmds.c 85.16% <0.00%> (-1.70%) ⬇️
... and 129 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e366ed4...852c275. Read the comment docs.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/c1160097405@github.com>

David Gow

unread,
Jun 20, 2022, 4:28:43 AM6/20/22
to vim/vim, Push

@sulix pushed 1 commit.

  • 7a99257 xxd: Add -n[ame] option to set the variable name used with -i


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/push/10207597285@github.com>

David Gow

unread,
Jun 20, 2022, 4:29:49 AM6/20/22
to vim/vim, Subscribed

runtime/doc/xxd.man.1 should be also updated.

Thanks — I've updated runtime/doc/xxd.1. I haven't regenerated xxd.man, as it's adding a bunch of extra formatting changes here. I can look into whatever settings need changing and do so if that's desired, though. Similarly, I haven't attempted to update the translated pages.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/c1160136612@github.com>

Bram Moolenaar

unread,
Jun 29, 2022, 9:29:51 AM6/29/22
to vim/vim, Subscribed

Please add a test for this in src/testdir/test_xxd.vim


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/c1169982479@github.com>

David Gow

unread,
Jun 29, 2022, 10:10:59 AM6/29/22
to vim/vim, Subscribed

Please add a test for this in src/testdir/test_xxd.vim

Thanks — I've added tests 17 and 18 to Test_xxd(), and they pass:

From test_xxd.vim:

Executed Test_xxd()                                in   0.400411 seconds

Executed Test_xxd_bit_dump()                       in   0.007860 seconds

Executed Test_xxd_c0_is_def_cols()                 in   0.170939 seconds

Executed Test_xxd_ignore_garbage()                 in   0.007741 seconds

Executed Test_xxd_max_cols()                       in   0.068192 seconds

Executed Test_xxd_min_cols()                       in   0.131794 seconds

Executed Test_xxd_patch()                          in   0.121765 seconds

Executed Test_xxd_plain_one_line()                 in   0.028997 seconds

Executed Test_xxd_usage()                          in   0.065982 seconds

Executed Test_xxd_version()                        in   0.011954 seconds

Executed 10 tests                        in   1.022748 seconds

(I thought of putting them next to tests 8 and 9, which are the other tests for -i, but thought that renumbering the other tests was not worth it. Happy to move them if you disagree, though.)

I've also rebased the change to the latest git version: there were no conflicts.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/c1170031043@github.com>

Bram Moolenaar

unread,
Jun 29, 2022, 3:25:38 PM6/29/22
to vim/vim, Subscribed

Closed #10599 via 83e1180.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10599/issue_event/6905214311@github.com>

Reply all
Reply to author
Forward
0 new messages