dump.c
author viric@llimona
Mon, 24 Sep 2007 13:59:40 +0200
changeset 38 f1e581c862d5
parent 36 da427c23d755
child 41 954941c6e40a
permissions -rw-r--r--
Improved help. Moving to 0.2.

#include <stdio.h>
#include <stdarg.h>

#include "main.h"

const int should_dump = 0;

void dump_line(const char *msg, ...)
{
    va_list v;
    FILE *f;

    if (!should_dump) return;

    va_start(v, msg);
    f = fopen("/tmp/dump.txt", "a");
    if (f == 0) return;

    vfprintf(f, msg, v);
    fclose(f);
}

void hex_dump(const char *head, const unsigned char *data, int len)
{
    int i;
    FILE *f;

    if (!should_dump) return;

    f = fopen("/tmp/dump.txt", "a");
    if (f == 0) return;

    fprintf(f, "%s: ", head);
    for(i=0;i<len; ++i)
    {
        int c;
        if (i > 0)
            fprintf(f," ");
        c = data[i];
        if (c >= 32 && c <= 127)
            fprintf(f, "'%c'", c);
        else
            fprintf(f, "%2x", c);
    }
    fputc('\n', f);
    fclose(f);
}