summaryrefslogtreecommitdiff
path: root/test/nsoption.c
blob: 0f079e9f7298f29f17b005982a196509a2452794 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include "utils/errors.h"
#include "utils/log.h"
#include "utils/nsoption.h"



nserror gui_options_init_defaults(struct nsoption_s *defaults)
{
#if defined(riscos)
	/* Set defaults for absent option strings */
	nsoption_setnull_charp(ca_bundle, strdup("NetSurf:Resources.ca-bundle"));
	nsoption_setnull_charp(cookie_file, strdup("NetSurf:Cookies"));
	nsoption_setnull_charp(cookie_jar, strdup(CHOICES_PREFIX "Cookies"));

	if (nsoption_charp(ca_bundle) == NULL ||
	    nsoption_charp(cookie_file) == NULL ||
	    nsoption_charp(cookie_jar) == NULL) {
		return NSERROR_BAD_PARAMETER;
	}
#elif defined(nsgtk)
	char *hdir = getenv("HOME");
	char buf[PATH_MAX];

	/* Set defaults for absent option strings */
	snprintf(buf, PATH_MAX, "%s/.netsurf/Cookies", hdir);
	nsoption_setnull_charp(cookie_file, strdup(buf));
	nsoption_setnull_charp(cookie_jar, strdup(buf));
	if (nsoption_charp(cookie_file) == NULL ||
	    nsoption_charp(cookie_jar) == NULL) {
		return NSERROR_BAD_PARAMETER;
	}

	if (nsoption_charp(downloads_directory) == NULL) {
		snprintf(buf, PATH_MAX, "%s/", hdir);
		nsoption_set_charp(downloads_directory, strdup(buf));
	}

	if (nsoption_charp(url_file) == NULL) {
		snprintf(buf, PATH_MAX, "%s/.netsurf/URLs", hdir);
		nsoption_set_charp(url_file, strdup(buf));
	}

	if (nsoption_charp(hotlist_path) == NULL) {
		snprintf(buf, PATH_MAX, "%s/.netsurf/Hotlist", hdir);
		nsoption_set_charp(hotlist_path, strdup(buf));
	}

	nsoption_setnull_charp(ca_path, strdup("/etc/ssl/certs"));

	if (nsoption_charp(url_file) == NULL ||
	    nsoption_charp(ca_path) == NULL ||
	    nsoption_charp(downloads_directory) == NULL ||
	    nsoption_charp(hotlist_path) == NULL) {
		return NSERROR_BAD_PARAMETER;
	}

#endif
	return NSERROR_OK;
}


int main(int argc, char**argv)
{
	FILE *fp;

	verbose_log = false;

	nsoption_init(gui_options_init_defaults, NULL, NULL);

	nsoption_read("test/data/Choices", NULL);

	nsoption_write("Choices-short", NULL, NULL);

	fp = fopen("Choices-all", "w");

	nsoption_dump(fp, NULL);

	fclose(fp);

	return 0;
}