2018-11-19 20:26:37 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-11-20 14:03:46 +01:00
|
|
|
#include "pager.h"
|
2018-11-19 20:47:46 +01:00
|
|
|
#include "static-destruct.h"
|
|
|
|
|
2018-11-20 13:54:12 +01:00
|
|
|
#define _DEFINE_MAIN_FUNCTION(impl, ret) \
|
2018-11-19 20:26:37 +01:00
|
|
|
int main(int argc, char *argv[]) { \
|
|
|
|
int r; \
|
|
|
|
r = impl(argc, argv); \
|
2018-11-19 20:47:46 +01:00
|
|
|
static_destruct(); \
|
2018-11-20 14:03:46 +01:00
|
|
|
pager_close(); \
|
2018-11-20 13:54:12 +01:00
|
|
|
return ret; \
|
2018-11-19 20:26:37 +01:00
|
|
|
}
|
|
|
|
|
2018-11-20 13:54:12 +01:00
|
|
|
/* Negative return values from impl are mapped to EXIT_FAILURE, and
|
|
|
|
* everything else means success! */
|
|
|
|
#define DEFINE_MAIN_FUNCTION(impl) \
|
|
|
|
_DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
|
|
|
|
|
2018-11-19 20:26:37 +01:00
|
|
|
/* Zero is mapped to EXIT_SUCCESS, and both negative and positive values
|
|
|
|
* are mapped to EXIT_FAILURE.
|
|
|
|
* Note: this means "true" maps to EXIT_FAILURE. */
|
|
|
|
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
|
2018-11-20 13:54:12 +01:00
|
|
|
_DEFINE_MAIN_FUNCTION(impl, r != 0 ? EXIT_FAILURE : EXIT_SUCCESS)
|