summaryrefslogtreecommitdiff
path: root/error.h
blob: 104905da7c5c9b03160df7bc4be53ed315fa1a0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef ERROR_H
#define ERROR_H

#include <stdio.h>
#include <stdlib.h>

enum errcode {
    OK = 0,
    GENERAL_ERROR = 1,
    COMMAND_NOT_FOUND = 2,
    UNKNOWN_ID,
    SYNTAX_ERROR,
    INVALID_ARGUMENTS
};

/* FIXME: double fprintf is ugly */
#define error(v, ...) do { \
    fprintf(stderr, __VA_ARGS__); \
    fprintf(stderr, "\n"); \
    exit(v); \
} while (0)

#define _warn(fmt, ...) do { \
    fprintf(stderr, fmt "\n", __VA_ARGS__); \
} while (0)

#define warn(...) do { \
    _warn(__VA_ARGS__); \
} while (0)

#endif /* ERROR_H */