void hexdump(const void * buf, size_t size)
{
const uchar * cbuf = (const uchar *) buf;
const ulong BYTES_PER_LINE = 16;
ulong offset, minioffset;
for (offset = 0; offset < size; offset += BYTES_PER_LINE)
{
// OFFSETXX xx xx xx xx xx xx xx xx xx xx . . .
// . . . xx xx xx xx xx xx abcdefghijklmnop
printf("%08x ", cbuf + offset);
for (minioffset = offset;
minioffset < offset + BYTES_PER_LINE;
minioffset++)
{
if (minioffset - offset == (BYTES_PER_LINE / 2)) {
printf(" ");
}
if (minioffset < size) {
printf("%02x ", cbuf[minioffset]);
} else {
printf(" ");
}
}
printf(" ");
for (minioffset = offset;
minioffset < offset + BYTES_PER_LINE;
minioffset++)
{
if (minioffset >= size)
break;
if (cbuf[minioffset] < 0x20 ||
cbuf[minioffset] > 0x7e)
{
printf(".");
} else {
printf("%c", cbuf[minioffset]);
}
}
printf("\n");
}
}
How to post code in WordPress
- Each line of code must not contain more than 60 characters. Each tab counts as 2 characters.
- Save the code in a file with the proper extension, open it gvim and make sure the code is properly color-highlighted. I used Win32 Vim 7.0.
- Set the color scheme to a nice one, such as torte.
Vim command:colorscheme torte - Set the tabstop to a low value.
Vim command:set tabstop=2 - Syntax -> Convert to HTML
- Create a new post in the HTML editor, not the rich editor.
- Copy and paste everything from <pre> to </pre>.
- If you use something like “0x20″, change the “x” to “x” – otherwise, WordPress turns it into a multiply symbol.
Also, change all backslashes (“\”) to “\”, because otherwise they disappear. - Change the <pre> line to:
<pre style="color: #cccccc; background: #000000; border: solid 1px #80a0ff; font-size: 1.2em; margin: 10px; padding: 10px"> - Post without switching into the rich editor.
May 3, 2007 at 1:29 pm
[...] is given in the previous post.) The output of this program, with the clean (green), dead (blue) and [...]
May 3, 2007 at 4:47 pm
Wouldn’t it be nice if you could script up as much of that as possible?
http://pygments.org/ looks like it’s right up your alley.
May 5, 2007 at 6:34 pm
[...] code-posting rant In addition to what I wrote here, you should also replace any apostrophes with: [...]
March 22, 2008 at 5:24 am
[...] What to do? Okay, the reason I haven’t posted in a long while is that it’s incredibly inconvenient. [...]