summaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: b547a9f4c690d550c84a5af0571a7bc7d56ce021 (plain)
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
32
33
34
35
36
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"

int
main(int argc, char *argv[])
{
	char            *program_dir;
	const char      *games_dir;
	struct db_game **games;
	int              n;
	int              i;

	program_dir = realpath(dirname(argv[0]), NULL);
	if (strcmp(program_dir, ABS_BUILDDIR) == 0) {
		/* Running in place */
		games_dir = ABS_BUILDDIR "/games";
	} else {
		/* Running from installation */
		games_dir = GAMESDIR;
	}
	free(program_dir);
	n = db_games_find(games_dir, &games);
	if (n > 0) {
		printf("%d games:\n", n);
		for (i = 0; i < n; ++i) {
			printf("\t%s - %s\n", db_game_get_name(games[i]),
					db_game_get_desc(games[i]));
			db_game_free(games[i]);
		}
		free(games);
	}
	return EXIT_SUCCESS;
}