view jss.c @ 510:43ea59887c69

Start work on making C64 formats encoding possible by changing DMDecodeOps to DMEncDecOps and adding fields and op enums for custom encode functions, renaming, etc. Split generic op sanity checking into a separate function in preparation for its use in generic encoding function.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 19 Nov 2012 15:06:01 +0200
parents 32250b436bca
children 54974f4f2ad6
line wrap: on
line source

/*
 * miniJSS - General functions
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2006-2007 Tecnic Software productions (TNSP)
 */
#include "jss.h"
#include <stdarg.h>


/* Memory and error handling functions
 */

BOOL jssWarningIsFatal, jssErrorIsFatal;

#ifndef JSS_LIGHT
void (*jssError) (int code, char * filename, int linen, char * fmt, ...);
void (*jssWarning) (int code, char * filename, int linen, char * fmt, ...);
#endif


void jssDefaultPrint(int code, char * filename, int linen, char * fmt)
{
    fprintf(stderr, "JSS");
    if (filename)
        fprintf(stderr, "[%s:%i]", filename, linen);
    fprintf(stderr, fmt);
    if (code > 0)
        fprintf(stderr, "(%i)", code);
    fprintf(stderr, ": ");
}


void jssDefaultError(int code, char * filename, int linen, char * fmt, ...)
{
    va_list ap;
    jssDefaultPrint(code, filename, linen, "E");

    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
}


void jssDefaultWarning(int code, char * filename, int linen, char * fmt, ...)
{
    va_list ap;
    jssDefaultPrint(code, filename, linen, "W");

    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
}


/* System initialization
 */
int jssInit(void)
{
    // Error handling
    jssWarningIsFatal = FALSE;
    jssErrorIsFatal = TRUE;

#ifndef JSS_LIGHT
    jssError = jssDefaultError;
    jssWarning = jssDefaultWarning;
#endif

    // Allocate global tables

    return DMERR_OK;
}


/* System shutdown
 */
int jssClose(void)
{
    return DMERR_OK;
}