Colorize some more output.
This commit is contained in:
parent
48ca1a50d5
commit
40d299d001
9
devcmd.c
9
devcmd.c
|
@ -43,8 +43,13 @@ static void show_regs(u_int16_t *regs)
|
|||
for (j = 0; j < REG_COLUMNS; j++) {
|
||||
int k = j * REG_ROWS + i;
|
||||
|
||||
if (k < DEVICE_NUM_REGS)
|
||||
printf("(r%02d: %04x) ", k, regs[k]);
|
||||
if (k < DEVICE_NUM_REGS) {
|
||||
printf("(");
|
||||
colorize("1m");
|
||||
printf("R%02d: ", k);
|
||||
colorize("0m");
|
||||
printf("%04x) ", regs[k]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
|
|
@ -329,7 +329,7 @@ The following are all valid examples of address expressions:
|
|||
.SH OPTIONS
|
||||
MSPDebug's behaviour can be configured via the following variables:
|
||||
.IP "\fBcolor\fR (boolean)"
|
||||
If true, MSPDebug will colorize disassembly output.
|
||||
If true, MSPDebug will colorize debugging output.
|
||||
.SH BUGS
|
||||
If you find any bugs, you should report them to the author at
|
||||
daniel@tortek.co.nz. It would help if you could include a transcript
|
||||
|
|
41
parse.c
41
parse.c
|
@ -302,15 +302,19 @@ static int cmd_help(char **arg)
|
|||
const struct option *opt = find_option(topic);
|
||||
|
||||
if (cmd) {
|
||||
colorize("1m");
|
||||
printf("COMMAND: %s\n", cmd->name);
|
||||
colorize("0m");
|
||||
fputs(cmd->help, stdout);
|
||||
if (opt)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (opt) {
|
||||
colorize("1m");
|
||||
printf("OPTION: %s (%s)\n", opt->name,
|
||||
type_text(opt->type));
|
||||
colorize("0m");
|
||||
fputs(opt->help, stdout);
|
||||
}
|
||||
|
||||
|
@ -551,7 +555,7 @@ static struct command command_read = {
|
|||
static struct option option_color = {
|
||||
.name = "color",
|
||||
.type = OPTION_BOOLEAN,
|
||||
.help = "Colorize disassembly output.\n"
|
||||
.help = "Colorize debugging output.\n"
|
||||
};
|
||||
|
||||
int colorize(const char *text)
|
||||
|
@ -868,3 +872,38 @@ int modify_prompt(int flags)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hexdump(int addr, const u_int8_t *data, int len)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
while (offset < len) {
|
||||
int i, j;
|
||||
|
||||
/* Address label */
|
||||
colorize("36m");
|
||||
printf(" %04x:", offset + addr);
|
||||
colorize("0m");
|
||||
|
||||
/* Hex portion */
|
||||
for (i = 0; i < 16 && offset + i < len; i++)
|
||||
printf(" %02x", data[offset + i]);
|
||||
for (j = i; j < 16; j++)
|
||||
printf(" ");
|
||||
|
||||
/* Printable characters */
|
||||
colorize("32m");
|
||||
printf(" |");
|
||||
for (j = 0; j < i; j++) {
|
||||
int c = data[offset + j];
|
||||
|
||||
printf("%c", (c >= 32 && c <= 126) ? c : '.');
|
||||
}
|
||||
for (; j < 16; j++)
|
||||
printf(" ");
|
||||
printf("|\n");
|
||||
colorize("0m");
|
||||
|
||||
offset += i;
|
||||
}
|
||||
}
|
||||
|
|
3
parse.h
3
parse.h
|
@ -116,4 +116,7 @@ void register_option(struct option *o);
|
|||
/* Initialise the parser, and register built-ins. */
|
||||
void parse_init(void);
|
||||
|
||||
/* Display a canonical hexdump */
|
||||
void hexdump(int addr, const u_int8_t *data, int len);
|
||||
|
||||
#endif
|
||||
|
|
4
rf2500.c
4
rf2500.c
|
@ -23,6 +23,10 @@
|
|||
#include "transport.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef DEBUG_USBTR
|
||||
#include "parse.h"
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* USB transport
|
||||
*
|
||||
|
|
4
uif.c
4
uif.c
|
@ -27,6 +27,10 @@
|
|||
#include "transport.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef DEBUG_SERIAL
|
||||
#include "parse.h"
|
||||
#endif
|
||||
|
||||
static int serial_fd = -1;
|
||||
|
||||
static int serial_send(const u_int8_t *data, int len)
|
||||
|
|
31
util.c
31
util.c
|
@ -58,37 +58,6 @@ int ctrlc_check(void)
|
|||
return ctrlc_flag;
|
||||
}
|
||||
|
||||
void hexdump(int addr, const u_int8_t *data, int len)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
while (offset < len) {
|
||||
int i, j;
|
||||
|
||||
/* Address label */
|
||||
printf(" %04x:", offset + addr);
|
||||
|
||||
/* Hex portion */
|
||||
for (i = 0; i < 16 && offset + i < len; i++)
|
||||
printf(" %02x", data[offset + i]);
|
||||
for (j = i; j < 16; j++)
|
||||
printf(" ");
|
||||
|
||||
/* Printable characters */
|
||||
printf(" |");
|
||||
for (j = 0; j < i; j++) {
|
||||
int c = data[offset + j];
|
||||
|
||||
printf("%c", (c >= 32 && c <= 126) ? c : '.');
|
||||
}
|
||||
for (; j < 16; j++)
|
||||
printf(" ");
|
||||
printf("|\n");
|
||||
|
||||
offset += i;
|
||||
}
|
||||
}
|
||||
|
||||
int read_with_timeout(int fd, u_int8_t *data, int max_len)
|
||||
{
|
||||
int r;
|
||||
|
|
Loading…
Reference in New Issue