OSDN Git Service

monitor: Fix color printing of hexdump
authorMarcel Holtmann <marcel@holtmann.org>
Fri, 9 Nov 2012 22:54:36 +0000 (23:54 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 9 Nov 2012 22:54:36 +0000 (23:54 +0100)
monitor/display.h
monitor/l2cap.c
monitor/packet.c

index d7269ae..621308d 100644 (file)
@@ -40,17 +40,19 @@ bool use_color(void);
 
 #define COLOR_ERROR    "\x1B[1;31m"
 
-#define print_indent(indent, color, prefix, title, fmt, args...) do { \
-       printf("%*c%s%s%s%s" fmt "\n", (indent), ' ', \
-               use_color() ? (color) : "", prefix, title, \
-               use_color() ? COLOR_OFF : "", ## args); \
+#define print_indent(indent, color1, prefix, title, color2, fmt, args...) \
+do { \
+       printf("%*c%s%s%s%s" fmt "%s\n", (indent), ' ', \
+               use_color() ? (color1) : "", prefix, title, \
+               use_color() ? (color2) : "", ## args, \
+               use_color() ? COLOR_OFF : ""); \
 } while (0);
 
 #define print_text(color, fmt, args...) \
-                       print_indent(8, color, "", "", fmt, ## args)
+               print_indent(8, COLOR_OFF, "", "", color, fmt, ## args)
 
 #define print_field(fmt, args...) \
-                       print_indent(8, COLOR_OFF, "", "", fmt, ## args)
+               print_indent(8, COLOR_OFF, "", "", COLOR_OFF, fmt, ## args)
 
 int num_columns(void);
 
index 8fbfc57..2e26510 100644 (file)
@@ -446,6 +446,7 @@ static void sig_packet(bool in, const void *data, uint16_t size)
                }
 
                print_indent(6, opcode_color, "L2CAP: ", opcode_str,
+                                       COLOR_OFF,
                                        " (0x%2.2x) ident %d len %d",
                                        hdr->code, hdr->ident, len);
 
@@ -559,7 +560,7 @@ static void amp_packet(const void *data, uint16_t size)
        else
                opcode_str = "Unknown";
 
-       print_indent(6, COLOR_CYAN, "AMP: ", opcode_str,
+       print_indent(6, COLOR_CYAN, "AMP: ", opcode_str, COLOR_OFF,
                        " (0x%2.2x) ident %d len %d", opcode, ident, len);
 
        packet_hexdump(data + 6, size - 8);
@@ -630,7 +631,7 @@ static void att_packet(const void *data, uint16_t size)
        else
                opcode_str = "Unknown";
 
-       print_indent(6, COLOR_CYAN, "ATT: ", opcode_str,
+       print_indent(6, COLOR_CYAN, "ATT: ", opcode_str, COLOR_OFF,
                                " (0x%2.2x) len %d", opcode, size - 1);
 
        packet_hexdump(data + 1, size - 1);
@@ -684,7 +685,7 @@ static void smp_packet(const void *data, uint16_t size)
        else
                opcode_str = "Unknown";
 
-       print_indent(6, COLOR_CYAN, "SMP: ", opcode_str,
+       print_indent(6, COLOR_CYAN, "SMP: ", opcode_str, COLOR_OFF,
                                " (0x%2.2x) len %d", opcode, size - 1);
 
        packet_hexdump(data + 1, size - 1);
@@ -728,7 +729,7 @@ void l2cap_packet(uint16_t handle, bool in, const void *data, uint16_t size)
                smp_packet(data, len);
                break;
        default:
-               print_indent(6, COLOR_CYAN, "Channel:", "",
+               print_indent(6, COLOR_CYAN, "Channel:", "", COLOR_OFF,
                                                " %d len %d", cid, len);
                packet_hexdump(data, len);
                break;
index 18b4c59..314ecb8 100644 (file)
@@ -3375,7 +3375,7 @@ static void cmd_complete_evt(const void *data, uint8_t size)
                opcode_str = "Unknown";
        }
 
-       print_indent(6, opcode_color, "", opcode_str,
+       print_indent(6, opcode_color, "", opcode_str, COLOR_OFF,
                        " (0x%2.2x|0x%4.4x) ncmd %d", ogf, ocf, evt->ncmd);
 
        if (!opcode_data->rsp_func) {
@@ -3425,7 +3425,7 @@ static void cmd_status_evt(const void *data, uint8_t size)
                opcode_str = "Unknown";
        }
 
-       print_indent(6, opcode_color, "", opcode_str,
+       print_indent(6, opcode_color, "", opcode_str, COLOR_OFF,
                        " (0x%2.2x|0x%4.4x) ncmd %d", ogf, ocf, evt->ncmd);
 
        print_status(evt->status);
@@ -3978,8 +3978,8 @@ static void le_meta_event_evt(const void *data, uint8_t size)
                subevent_str = "Unknown";
        }
 
-       print_indent(6, subevent_color, "", subevent_str,
-                                       " (0x%2.2x)", subevent);
+       print_indent(6, subevent_color, "", subevent_str, COLOR_OFF,
+                                               " (0x%2.2x)", subevent);
 
        if (!subevent_data || !subevent_data->func) {
                packet_hexdump(data + 1, size - 1);