summaryrefslogtreecommitdiffstats
path: root/examples/c4info.c
blob: 09d02572308e5720f4269159d99159588344ba41 (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
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "cc4group.h"

const char* formatTime(int32_t time)
{
	time_t tTime = time;
	static char ret[128];
	strftime(ret, sizeof(ret), "%c", localtime(&tTime));
	return ret;
}

int main(int argc, char* argv[])
{
	if(argc != 2)
	{
		fprintf(stderr, "USAGE: %s <group>\n", argv[0]);
		return EXIT_FAILURE;
	}

	CC4Group* group = cc4group.new();
	bool success = cc4group.openExisting(group, argv[1]);
	if(!success)
	{
		fprintf(stderr, "ERROR: Can not open group file \"%s\": %s\n", argv[1], cc4group.getErrorMessage(group));
	}
	else
	{
		CC4Group_EntryInfo info;
		// yes, this should be error checked, but this is only an example. and actually, if the root entry info can not be retrieved, there must be some serious problem somewhere else
		// anyway, the worst thing that can happen would be printing some random uninitialized data to stdout. what a nice surprise!
		cc4group.getEntryInfo(group, "", &info, false);

		puts(argv[1]);
		printf("Created: %s\n", formatTime(info.modified));
		printf("Author: %s\n", info.author);
		if(info.official)
		{
			puts("Official");
		}
	}
	cc4group.delete(group);

	return success ? EXIT_SUCCESS : EXIT_FAILURE;
}