/*
+-------------------------------------------------------------------------+
|                           loghorn vers. 0.1.01                          |
|    Copyright (c) Andrey V. Stolyarov  <croco at croco dot net>  2026    |
| ----------------------------------------------------------------------- |
| This is free software.  Permission is granted to everyone to use, copy  |
|    or modify this software under the terms and conditions of either     |
|             CROCO'S INDIVIDUALISTIC FREE SOFTWARE LICENSE               |
|                          or, at your option,                            |
|               GNU LESSER GENERAL PUBLIC LICENSE, v. 2.1                 |
|                                                                         |
| Please visit http://www.croco.net/software/loghorn  to get a fresh copy |
| ----------------------------------------------------------------------- |
|   This code is provided strictly and exclusively on the "AS IS" basis.  |
|        THERE IS NO WARRANTY OF ANY KIND, DON'T EVEN THINK ABOUT IT      |
+-------------------------------------------------------------------------+
*/




#include <stdio.h>
#include <stdarg.h>

#include "message.h"


static int msg_verbosity = 0;

void message_set_verbosity(int verbosity)
{
    msg_verbosity = verbosity;
}

void message(int level, const char *fmt, ...)
{
    va_list args;
    if(level > msg_verbosity)
        return;

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

void message_perror(int level, const char *s1, const char *s2)
{
    if(level > msg_verbosity)
        return;
    if(s1) {
        fputs(s1, stderr);
        fputs(": ", stderr);
    }
    perror(s2);
}
