dump.c
author viric@llimona
Thu, 27 Sep 2007 00:25:54 +0200
changeset 58 2cf8c513d18f
parent 53 07500c5c53cb
child 64 4db3a61ec257
permissions -rw-r--r--
added authors.

/*
    Terminal Mixer - multi-point multi-user access to terminal applications
    Copyright (C) 2007  LluĂ­s Batlle i Rossell

    Please find the license in the provided COPYING file.
*/
#include <stdio.h>
#include <stdarg.h>

#include "main.h"

const int should_dump = 1;

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