view th_ioctx.h @ 129:aa2d608fb3f3

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 22 Jun 2014 07:23:54 +0300
parents 40568456eb5b
children b392293047da
line wrap: on
line source

/*
 * Standard I/O context helpers
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2012 Tecnic Software productions (TNSP)
 *
 * Please read file 'COPYING' for information on license and distribution.
 */
#ifndef TH_IOCTX_H
#define TH_IOCTX_H

#include "th_util.h"
#include <stdio.h>


#ifdef __cplusplus
extern "C" {
#endif


/* Simple STD I/O contexts
 */
typedef struct _th_ioctx_t
{
    BOOL allocated;
    char *filename;
    FILE *fp;
    size_t line;

    void (*error)(struct _th_ioctx_t *, const int, const char *msg);
    void (*msg)(struct _th_ioctx_t *, const char *msg);
} th_ioctx_t;


BOOL th_ioctx_init(th_ioctx_t *ctx, const char *filename,
    void (*error)(struct _th_ioctx_t *, const int, const char *msg),
    void (*msg)(struct _th_ioctx_t *, const char *msg));

BOOL th_ioctx_open(th_ioctx_t *ctx, const char *filename, const char *mode,
    void (*error)(struct _th_ioctx_t *, const int, const char *msg),
    void (*msg)(struct _th_ioctx_t *, const char *msg));

void th_ioctx_close(th_ioctx_t *ctx);
void th_ioctx_error(th_ioctx_t *ctx, const int err, const char *fmt, ...);

th_ioctx_t * th_ioctx_new(const char *filename,
    void (*error)(struct _th_ioctx_t *, const int, const char *msg),
    void (*msg)(struct _th_ioctx_t *, const char *msg));
void th_ioctx_free(th_ioctx_t *ctx);


#ifdef __cplusplus
}
#endif
#endif // TH_IOCTX_H