summaryrefslogtreecommitdiff
path: root/x11/kde4-runtime/files/patch-conf.c
blob: a4de97379b100efe201cdb9d45ba8ae4ffaefc4a (plain) (blame)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
--- /dev/null	Mon Nov 19 17:14:17 2001
+++ ksysguard/ksysguardd/FreeBSD/conf.c	Mon Nov 19 17:06:50 2001
@@ -0,0 +1,133 @@
+/*
+    KSysGuard, the KDE System Guard
+	   
+    Copyright (c) 2001 Tobias Koenig <tokoe82@yahoo.de>
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of version 2 of the GNU General Public
+    License as published by the Free Software Foundation.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+	$Id: conf.c,v 1.3 2001/11/05 23:24:19 tokoe Exp $
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "Command.h"
+#include "ccont.h"
+#include "conf.h"
+
+CONTAINER LogFileList = 0;
+CONTAINER SensorList = 0;
+
+void parseConfigFile(const char *filename)
+{
+	FILE* config;
+	char line[2048];
+	char *begin, *token, *tmp, *confSensor;
+	ConfigLogFile *confLog;
+	
+
+	if (LogFileList)
+		destr_ctnr(LogFileList, free);
+
+	if (SensorList)
+		destr_ctnr(SensorList, free);
+
+	LogFileList = new_ctnr(CT_DLL);
+	SensorList = new_ctnr(CT_DLL);
+
+	if ((config = fopen(filename, "r")) == NULL) {
+		log_error("can't open config file '%s'", filename);
+
+		/* if we can't open a config file we have to add the
+		   available sensors manually
+		*/
+
+		confSensor = strdup("ProcessList");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("Memory");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("Stat");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("NetDev");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("NetStat");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("CpuInfo");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("LoadAvg");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("DiskStat");
+		push_ctnr(SensorList, confSensor);
+		confSensor = strdup("LogFile");
+		push_ctnr(SensorList, confSensor);
+
+		return;
+	}
+
+	while (fgets(line, sizeof(line), config) != NULL) {
+		if ((line[0] == '#') || (strlen(line) == 0)) {
+			continue;
+		}
+
+		if (strchr(line, '#'))
+			*(strchr(line, '#')) = '\0';
+
+		if (line[strlen(line) - 1] == '\n')
+			line[strlen(line) - 1] = '\0';
+
+		if (!strncmp(line, "LogFiles", 8)) {
+			begin = strchr(line, '=');
+			begin++;
+
+			for (token = strtok(begin, ","); token; token = strtok(NULL, ",")) {
+				if ((confLog = (ConfigLogFile *)malloc(sizeof(ConfigLogFile))) == NULL) {
+					log_error("malloc() no free memory avail");
+					continue;
+				}
+				confLog->name = strdup(token);
+				tmp = strchr(confLog->name, ':');
+				*tmp = '\0';
+				confLog->path = tmp;
+				confLog->path++;
+
+				push_ctnr(LogFileList, confLog);
+			}
+		}
+		if (!strncmp(line, "Sensors", 7)) {
+			begin = strchr(line, '=');
+			begin++;
+
+			for (token = strtok(begin, ","); token; token = strtok(NULL, ",")) {
+				confSensor = strdup(token);
+				push_ctnr(SensorList, confSensor);
+			}
+		}
+	}
+
+	fclose(config);
+}
+
+int sensorAvailable(const char *sensor)
+{
+	int i;
+	
+	for (i = 0; i < level_ctnr(SensorList); i++) {
+		char* name = get_ctnr(SensorList, i);
+		if (!strcmp(name, sensor))
+			return 1;
+	}
+
+	return 0;
+}