view scid/main.c @ 31:8c2087e7d381

misc: config.h is no more
author David Demelier <markand@malikania.fr>
date Thu, 04 Aug 2022 14:56:14 +0200
parents 4c16bb25e4f1
children 081e1c258e64
line wrap: on
line source

/*
 * scid.c -- main scid(8) program file
 *
 * Copyright (c) 2021 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

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

#include "http.h"
#include "scid.h"
#include "util.h"

static void
usage(void)
{
	fprintf(stderr, "usage: scid [-d database] [-s sock] [-t themedir]\n");
	exit(1);
}

static void
run_cgi(void)
{
	http_cgi_run();
}

static void
run_fcgi(void)
{
	for (;;)
		http_fcgi_run();
}

int
main(int argc, char **argv)
{
	int ch;
	void (*run)(void) = &(run_cgi);

	while ((ch = getopt(argc, argv, "d:ft:")) != -1) {
		switch (ch) {
		case 'd':
			util_strlcpy(scid.dbpath, optarg, sizeof (scid.dbpath));
			break;
		case 'f':
			run = &(run_fcgi);
			break;
		case 't':
			util_strlcpy(scid.themedir, optarg, sizeof (scid.themedir));
			break;
		default:
			usage();
			break;
		}
	}

	argc -= optind;
	argv += optind;

	scid_init();
	run();
	scid_finish();
}