summaryrefslogtreecommitdiff
path: root/file.c
blob: 5dd47ffd7f4152975e7b21732f98df355bc5fd08 (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
//								-*- c++ -*-

#include "file.h"
#include <unistd.h>

cText2SkinFile::cText2SkinFile(const char *Skin):
	mSkin(Skin)
{
}

cText2SkinFile::~cText2SkinFile() {
}

bool cText2SkinFile::Load(const std::string &Filename) {
	bool result = true;
	if (access(Filename.c_str(), F_OK) == 0) {
		isyslog("text2skin: loading %s", Filename.c_str());
		FILE *f = fopen(Filename.c_str(), "r");
		if (f) {
			int line = 0;
			char *buffer = NULL;
			size_t buflen = 0;
			result = true;
			while (getline(&buffer, &buflen, f) != -1) {
				line++;
				char *ptr = skipspace(stripspace(buffer));
				if (!isempty(ptr) && ptr[0] != '#') {
					if (!Parse(ptr)) {
						esyslog("ERROR: error in %s, line %d\n", Filename.c_str(), line);
						result = false;
						break;
					}
				}
			}
			free(buffer);
			fclose(f);
		} else {
			LOG_ERROR_STR(Filename.c_str());
			result = false;
		}
	}
	return result;
}