digitalmars.D - [your code here] HexViewer
- Andre Pany (23/23) Aug 02 2017 This application opens the file passed as argument and display
- Nick B (4/6) Aug 02 2017 Is this code in GitHub or DUB ?
- Steven Schveighoffer (5/12) Aug 02 2017 Here is a link:
- H. S. Teoh via Digitalmars-d (6/13) Aug 02 2017 [...]
- Steven Schveighoffer (9/32) Aug 02 2017 Very nice!
- Vladimir Panteleev (14/16) Aug 02 2017 Good idea! But I think it needs more ranges:
- Vladimir Panteleev (14/15) Aug 02 2017 The format call can be substituted with writefln directly:
- Vladimir Panteleev (3/6) Aug 02 2017 https://github.com/dlang/dlang.org/pull/1854
- Andre Pany (5/20) Aug 02 2017 Really cool:)
- Martin Tschierschke (7/22) Aug 03 2017 Very cool!
- Martin Tschierschke (6/29) Aug 03 2017 Error should be cols: byChunk(cols)
- Biotronic (17/18) Aug 03 2017 https://dlang.org/phobos/std_format.html
- H. S. Teoh via Digitalmars-d (7/25) Aug 02 2017 Whoa. This is cool and everything, but it also looks pretty intimidating
- Vladimir Panteleev (5/8) Aug 02 2017 Perhaps we should make some examples only available if the user
This application opens the file passed as argument and display the content in hex and text format: 00 00 03 00 00 00 64 00 00 00 FF 56 01 00 00 70 .....d... V..p 02 00 FF A6 00 00 00 20 02 00 00 00 00 00 00 00 . ª... ....... 00 00 00 00 00 00 00 00 00 00 00 00 ............ void main(string[] args) { import std.file, std.string, std.range, std.array, std.algorithm, std.digest, std.conv; import std.stdio: writeln; enum cols = 16; auto data = cast(const(ubyte)[]) read(args[1]); foreach(g; data.chunks(cols)) { string hex = g.toHexString.chunks(2).join(" ").to!string; string txt = g.map!(b => b == 0 ? '.' : char(b)).array; writeln(hex.leftJustify(cols * 2 + (cols - 1), ' '), " ", txt); } }
Aug 02 2017
On Wednesday, 2 August 2017 at 19:39:18 UTC, Andre Pany wrote:This application opens the file passed as argument and display the content in hex and text format:Is this code in GitHub or DUB ? Is there a link ? Nick
Aug 02 2017
On 8/2/17 5:27 PM, Nick B wrote:On Wednesday, 2 August 2017 at 19:39:18 UTC, Andre Pany wrote:Here is a link: https://forum.dlang.org/post/dvjltobyaaxoihhqywhp forum.dlang.org :) -SteveThis application opens the file passed as argument and display the content in hex and text format:Is this code in GitHub or DUB ? Is there a link ?
Aug 02 2017
On Wed, Aug 02, 2017 at 09:27:07PM +0000, Nick B via Digitalmars-d wrote:On Wednesday, 2 August 2017 at 19:39:18 UTC, Andre Pany wrote:[...] The code is right there in the message. T -- Sometimes the best solution to morale problems is just to fire all of the unhappy people. -- despair.comThis application opens the file passed as argument and display the content in hex and text format:Is this code in GitHub or DUB ? Is there a link ?
Aug 02 2017
On 8/2/17 3:39 PM, Andre Pany wrote:This application opens the file passed as argument and display the content in hex and text format: 00 00 03 00 00 00 64 00 00 00 FF 56 01 00 00 70 ......d... V..p 02 00 FF A6 00 00 00 20 02 00 00 00 00 00 00 00 . ª... ....... 00 00 00 00 00 00 00 00 00 00 00 00 ............ void main(string[] args) { import std.file, std.string, std.range, std.array, std.algorithm, std.digest, std.conv; import std.stdio: writeln; enum cols = 16; auto data = cast(const(ubyte)[]) read(args[1]); foreach(g; data.chunks(cols)) { string hex = g.toHexString.chunks(2).join(" ").to!string; string txt = g.map!(b => b == 0 ? '.' : char(b)).array; writeln(hex.leftJustify(cols * 2 + (cols - 1), ' '), " ", txt); } }Very nice! I think actually you are going to have a bit of trouble with the 'text' output, since D is going to output the character array as unicode, vs. a normal hexdump which will output as one glyph per byte. You could do this poorly by changing the map condition to b == 0 || b >= 0x80. Actually you may want to substitute some extra chars, as I'm not sure low bytes are printable (or will print what you really want them to). -Steve
Aug 02 2017
On Wednesday, 2 August 2017 at 19:39:18 UTC, Andre Pany wrote:This application opens the file passed as argument and display the content in hex and text format:Good idea! But I think it needs more ranges: void main(string[] args) { import std.algorithm, std.format, std.stdio; enum cols = 16; args[1].File("rb").byChunk(16).map!(chunk => format!"%(%02X %)%*s %s"( chunk, 3 * (cols - chunk.length), "", chunk.map!(c => c < 0x20 || c > 0x7E ? '.' : char(c)))) .each!writeln; }
Aug 02 2017
On Wednesday, 2 August 2017 at 21:59:23 UTC, Vladimir Panteleev wrote:Good idea! But I think it needs more ranges:The format call can be substituted with writefln directly: void main(string[] args) { import std.algorithm, std.format, std.stdio; enum cols = 16; args[1].File("rb").byChunk(16).each!(chunk => writefln!"%(%02X %)%*s %s"( chunk, 3 * (cols - chunk.length), "", chunk.map!(c => c < 0x20 || c > 0x7E ? '.' : char(c)))); }
Aug 02 2017
On Wednesday, 2 August 2017 at 22:02:49 UTC, Vladimir Panteleev wrote:On Wednesday, 2 August 2017 at 21:59:23 UTC, Vladimir Panteleev wrote:https://github.com/dlang/dlang.org/pull/1854Good idea!
Aug 02 2017
On Wednesday, 2 August 2017 at 22:02:49 UTC, Vladimir Panteleev wrote:On Wednesday, 2 August 2017 at 21:59:23 UTC, Vladimir Panteleev wrote:Really cool:) Kind regards AndréGood idea! But I think it needs more ranges:The format call can be substituted with writefln directly: void main(string[] args) { import std.algorithm, std.format, std.stdio; enum cols = 16; args[1].File("rb").byChunk(16).each!(chunk => writefln!"%(%02X %)%*s %s"( chunk, 3 * (cols - chunk.length), "", chunk.map!(c => c < 0x20 || c > 0x7E ? '.' : char(c)))); }
Aug 02 2017
On Wednesday, 2 August 2017 at 22:02:49 UTC, Vladimir Panteleev wrote:On Wednesday, 2 August 2017 at 21:59:23 UTC, Vladimir Panteleev wrote:Very cool! Now you can remove: std.format, and I would substitute: byChunk(16) with byChunk(col) Can you point me to the explanation of this: %(%02X %)%*s %s ? Best regards mt.Good idea! But I think it needs more ranges:The format call can be substituted with writefln directly: void main(string[] args) { import std.algorithm, std.format, std.stdio; enum cols = 16; args[1].File("rb").byChunk(16).each!(chunk => writefln!"%(%02X %)%*s %s"( chunk, 3 * (cols - chunk.length), "", chunk.map!(c => c < 0x20 || c > 0x7E ? '.' : char(c)))); }
Aug 03 2017
On Thursday, 3 August 2017 at 08:47:12 UTC, Martin Tschierschke wrote:On Wednesday, 2 August 2017 at 22:02:49 UTC, Vladimir Panteleev wrote:Error should be cols: byChunk(cols)On Wednesday, 2 August 2017 at 21:59:23 UTC, Vladimir Panteleev wrote:Very cool! Now you can remove: std.format, and I would substitute: byChunk(16) with byChunk(col)Good idea! But I think it needs more ranges:The format call can be substituted with writefln directly: void main(string[] args) { import std.algorithm, std.format, std.stdio; enum cols = 16; args[1].File("rb").byChunk(16).each!(chunk => writefln!"%(%02X %)%*s %s"( chunk, 3 * (cols - chunk.length), "", chunk.map!(c => c < 0x20 || c > 0x7E ? '.' : char(c)))); }Can you point me to the explanation of this: %(%02X %)%*s %s ?Ah I found it myself: https://dlang.org/library/std/format/formatted_write.html The %( %) called "nested array formatting" was new for me.
Aug 03 2017
On Thursday, 3 August 2017 at 08:47:12 UTC, Martin Tschierschke wrote:Can you point me to the explanation of this: %(%02X %)%*s %s ?https://dlang.org/phobos/std_format.html Under "Example using array and nested array formatting:" writefln("My items are %(%s %).", [1,2,3]); So "%( %)" is an array format specifier, with the stuff between the two as the element format. In the case of "%(%02X %)%*s %s", that reads: "%(" // Start array format specifier for arg 1. "%02X " // Format each element as a 2 digit hex number followed by a space. "%)" // End array format specifier. "%*s" // Right justify arg 3 (""), using width specified by arg 2. " %s" // And print arg 4 using no special format. -- Biotronic
Aug 03 2017
On Wed, Aug 02, 2017 at 09:59:23PM +0000, Vladimir Panteleev via Digitalmars-d wrote:On Wednesday, 2 August 2017 at 19:39:18 UTC, Andre Pany wrote:Whoa. This is cool and everything, but it also looks pretty intimidating for a newcomer to D. I'm not sure if we should put this on the front page! T -- Democracy: The triumph of popularity over principle. -- C.BondThis application opens the file passed as argument and display the content in hex and text format:Good idea! But I think it needs more ranges: void main(string[] args) { import std.algorithm, std.format, std.stdio; enum cols = 16; args[1].File("rb").byChunk(16).map!(chunk => format!"%(%02X %)%*s %s"( chunk, 3 * (cols - chunk.length), "", chunk.map!(c => c < 0x20 || c > 0x7E ? '.' : char(c)))) .each!writeln; }
Aug 02 2017
On Wednesday, 2 August 2017 at 21:58:18 UTC, H. S. Teoh wrote:Whoa. This is cool and everything, but it also looks pretty intimidating for a newcomer to D. I'm not sure if we should put this on the front page!Perhaps we should make some examples only available if the user selects them explicitly from the dropdown, i.e. never show them initially, and only use simpler examples for the initially-visible random example.
Aug 02 2017