no-more-secrets-rust/src/error.c
Brian Barto d921892576 Add input and error modules for getting input and reporting errors
modified:   Makefile
	new file:   src/error.c
	new file:   src/error.h
	new file:   src/input.c
	new file:   src/input.h
	modified:   src/nms.c
	modified:   src/nmseffect.c
	modified:   src/nmseffect.h
2018-10-24 21:44:48 -04:00

56 lines
859 B
C

/*
* Copyright (c) 2017 Brian Barto
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GPL License. See LICENSE for more details.
*/
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
#define ERROR_LIST_MAX 20
#define ERROR_LENGTH_MAX 100
static char error_stack[ERROR_LIST_MAX][ERROR_LENGTH_MAX];
static int N = 0;
void error_log(char *error, ...)
{
va_list argList;
if (N < ERROR_LIST_MAX)
{
va_start(argList, error);
vsnprintf(error_stack[N++], ERROR_LENGTH_MAX - 1, error, argList);
va_end(argList);
}
}
void error_print(void)
{
int i;
for (i = N-1; i >= 0; --i)
{
fprintf(stderr, "%s ", error_stack[i]);
}
fprintf(stderr, "\n");
}
char *error_get(void)
{
if (N > 0)
{
return error_stack[--N];
}
else
{
return NULL;
}
}
void error_clear(void)
{
N = 0;
}