74 lines
1.1 KiB
C
74 lines
1.1 KiB
C
/* SPDX-License-Identifier: BSD-2 */
|
|
|
|
#include "hashmap.h"
|
|
#include "pp.h"
|
|
#include "pp_defines.h"
|
|
#include "pp_args.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
string_map_t define_map;
|
|
struct args *args;
|
|
FILE *source;
|
|
FILE *out;
|
|
|
|
int ret;
|
|
|
|
|
|
define_map = NULL;
|
|
args = NULL;
|
|
source = NULL;
|
|
out = NULL;
|
|
|
|
define_map = hashmap_new();
|
|
args = pp_parse_args(argc, argv, define_map);
|
|
|
|
if (!args) {
|
|
if (errno)
|
|
ret = errno;
|
|
else
|
|
ret = PP_FAILED;
|
|
goto free_and_exit;
|
|
}
|
|
|
|
if (args->in_file) {
|
|
source = fopen(args->in_file, "r");
|
|
if (!source) {
|
|
ret = errno;
|
|
goto free_and_exit;
|
|
}
|
|
} else {
|
|
source = stdin;
|
|
}
|
|
|
|
if (args->out_file) {
|
|
out = fopen(args->out_file, "w");
|
|
if (!out) {
|
|
ret = errno;
|
|
goto free_and_exit;
|
|
}
|
|
} else {
|
|
out = stdout;
|
|
}
|
|
|
|
ret = pp_compute(define_map, args->inc_dirs, source, out);
|
|
if (ret == PP_FAILED)
|
|
goto free_and_exit;
|
|
|
|
|
|
ret = errno;
|
|
|
|
free_and_exit:
|
|
hashmap_free(define_map);
|
|
pp_free_args(args);
|
|
if (source)
|
|
fclose(source);
|
|
if (out)
|
|
fclose(out);
|
|
|
|
return ret;
|
|
}
|