#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include "spasm.h"
#include "dbfunc.h"

void spasm_error(int syslevel, char *errstr, ...) {
    va_list arglist;

    va_start(arglist, errstr);
    vfprintf(stderr, errstr, arglist);
    fprintf(stderr, "\n");      /* spasm_error args aren't terminated by \n */
    va_end(arglist);
}

int main(int argc, char **argv) {
    char *nl;
    char data[256];
    char *buf;

    buf = sp_strcat(DB_WHITELIST_DIR, argv[1]);
    if(buf == NULL) {
	fprintf(stderr, "Error allocating memory\n");
	exit(1);
    }
    unlink(buf);
    free(buf);

    while(fgets(data, sizeof(data), stdin) != NULL) {
	char *val = NULL;
        if((nl = strchr(data, '\n')) != NULL) *nl = '\0';
        if((nl = strchr(data, ' ')) != NULL) {
	    *nl = '\0';
	    nl++;
            if((val = strstr(nl, "//")) != NULL) val += 2;
	}
	if(val == NULL) val = "1";
	spasm_insert_wl(argv[1], data, val);
    }

    exit(0);
}
