Colorize some more output.

This commit is contained in:
Daniel Beer 2010-04-10 16:41:57 +12:00
parent 48ca1a50d5
commit 40d299d001
8 changed files with 59 additions and 38 deletions

View File

@ -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");
}

View File

@ -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
View File

@ -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;
}
}

View File

@ -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

View File

@ -23,6 +23,10 @@
#include "transport.h"
#include "util.h"
#ifdef DEBUG_USBTR
#include "parse.h"
#endif
/*********************************************************************
* USB transport
*

4
uif.c
View File

@ -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
View File

@ -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;

3
util.h
View File

@ -21,9 +21,6 @@
#include <sys/types.h>
/* Display a canonical hexdump */
void hexdump(int addr, const u_int8_t *data, int len);
#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
int open_serial(const char *device, int rate);