Example #1
0
void top_level_diversion::transparent_output(unsigned char c)
{
  if (before_first_page && begin_page())
    // This can only happen with the .output request.
    fatal("sorry, I didn't manage to begin the first page in time: use an explicit .br request");
  const char *s = asciify(c);
  while (*s)
    the_output->transparent_char(*s++);
}
Example #2
0
void
hexdump(
    char *desc,
    void *addr,
    int len
    )
{
#define BYTE_LEN        (16)
// each byte is two characters (00-FF), plus the whitespace inbetween (BYTE_LEN
// - 1 spaces)
#define BYTE_LEN_HEXED  (BYTE_LEN*2 + BYTE_LEN - 1)

    int i, isZero, beenZero, byte_len, hex_len;
    unsigned char bytes[BYTE_LEN+1], hexed[BYTE_LEN_HEXED+1];
    unsigned char *pc = (unsigned char*)addr;

    if (desc != NULL) {
        printf("%s:\n", desc);
    }

    beenZero = 0;
    for (i = 0; i < len; i += byte_len) {
        hex_len = BYTE_LEN_HEXED;
        byte_len = MIN(BYTE_LEN, len - i);

        hexed[0] = '\0';
        memcpy(bytes, &pc[i], byte_len);
        isZero = all_zero(bytes, byte_len);
        enhex(hexed, hex_len, bytes, byte_len);
        asciify(bytes, byte_len);

        if (!isZero) {
            beenZero = 0;
        }

        if (!beenZero) {
            hexed[hex_len] = '\0';
            bytes[byte_len] = '\0';
            printf("%04x  %-*s  %*s\n", i, hex_len, hexed, byte_len, bytes);

            if (isZero) {
                beenZero = 1;
                printf("*\n");
            }
        }
    }
    printf("%04x\n", i);
}