diff options
Diffstat (limited to 'ui-tree.c')
| -rw-r--r-- | ui-tree.c | 26 |
1 files changed, 17 insertions, 9 deletions
| @@ -25,11 +25,14 @@ static void print_text_buffer(char *buf, unsigned long size) | |||
| 25 | html("<tr><td class='linenumbers'><pre>"); | 25 | html("<tr><td class='linenumbers'><pre>"); |
| 26 | idx = 0; | 26 | idx = 0; |
| 27 | lineno = 0; | 27 | lineno = 0; |
| 28 | htmlf(numberfmt, ++lineno); | 28 | |
| 29 | while(idx < size - 1) { // skip absolute last newline | 29 | if (size) { |
| 30 | if (buf[idx] == '\n') | 30 | htmlf(numberfmt, ++lineno); |
| 31 | htmlf(numberfmt, ++lineno); | 31 | while(idx < size - 1) { // skip absolute last newline |
| 32 | idx++; | 32 | if (buf[idx] == '\n') |
| 33 | htmlf(numberfmt, ++lineno); | ||
| 34 | idx++; | ||
| 35 | } | ||
| 33 | } | 36 | } |
| 34 | html("</pre></td>\n"); | 37 | html("</pre></td>\n"); |
| 35 | html("<td class='lines'><pre><code>"); | 38 | html("<td class='lines'><pre><code>"); |
| @@ -37,21 +40,26 @@ static void print_text_buffer(char *buf, unsigned long size) | |||
| 37 | html("</code></pre></td></tr></table>\n"); | 40 | html("</code></pre></td></tr></table>\n"); |
| 38 | } | 41 | } |
| 39 | 42 | ||
| 43 | #define ROWLEN 32 | ||
| 44 | |||
| 40 | static void print_binary_buffer(char *buf, unsigned long size) | 45 | static void print_binary_buffer(char *buf, unsigned long size) |
| 41 | { | 46 | { |
| 42 | unsigned long ofs, idx; | 47 | unsigned long ofs, idx; |
| 48 | static char ascii[ROWLEN + 1]; | ||
| 43 | 49 | ||
| 44 | html("<table summary='blob content' class='bin-blob'>\n"); | 50 | html("<table summary='blob content' class='bin-blob'>\n"); |
| 45 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); | 51 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
| 46 | for (ofs = 0; ofs < size; ofs += 32, buf += 32) { | 52 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
| 47 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); | 53 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); |
| 48 | for (idx = 0; idx < 32 && ofs + idx < size; idx++) | 54 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
| 49 | htmlf("%*s%02x", | 55 | htmlf("%*s%02x", |
| 50 | idx == 16 ? 4 : 1, "", | 56 | idx == 16 ? 4 : 1, "", |
| 51 | buf[idx] & 0xff); | 57 | buf[idx] & 0xff); |
| 52 | html(" </td><td class='hex'>"); | 58 | html(" </td><td class='hex'>"); |
| 53 | for (idx = 0; idx < 32 && ofs + idx < size; idx++) | 59 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
| 54 | htmlf("%c", isgraph(buf[idx]) ? buf[idx] : '.'); | 60 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
| 61 | ascii[idx] = '\0'; | ||
| 62 | html_txt(ascii); | ||
| 55 | html("</td></tr>\n"); | 63 | html("</td></tr>\n"); |
| 56 | } | 64 | } |
| 57 | html("</table>\n"); | 65 | html("</table>\n"); |
