Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/parsecfg.c @ 301:efcbd3c1ad15
Free unread_list when the roster is freed
It fixes a bug after a /disconnect
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 11 Jul 2005 18:52:29 +0100 |
parents | 12f919be3da5 |
children | db5bebe96c89 |
rev | line source |
---|---|
24 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <unistd.h> | |
4 #include <ctype.h> | |
5 #include <string.h> | |
169 | 6 #include <glib.h> |
24 | 7 |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
8 #include "settings.h" |
170 | 9 #include "utils.h" |
24 | 10 |
297
9bdfef4f4735
Add comment for the cfg_file() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
11 // cfg_file(filename) |
9bdfef4f4735
Add comment for the cfg_file() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
12 // Read and parse config file "filename". If filename is NULL, |
9bdfef4f4735
Add comment for the cfg_file() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
13 // try to open the configuration file at the default locations. |
9bdfef4f4735
Add comment for the cfg_file() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
14 // |
9bdfef4f4735
Add comment for the cfg_file() function
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
15 // This function comes from Cabber, and has been slightly modified. |
24 | 16 int cfg_file(char *filename) |
17 { | |
18 FILE *fp; | |
19 char *buf; | |
20 char *line; | |
21 char *value; | |
22 | |
169 | 23 if (!filename) { |
24 // Use default config file locations | |
25 char *home = getenv("HOME"); | |
26 if (!home) { | |
27 ut_WriteLog("Can't find home dir!\n"); | |
28 exit(EXIT_FAILURE); | |
29 } | |
30 filename = g_new(char, strlen(home)+24); | |
31 sprintf(filename, "%s/.mcabber/mcabberrc", home); | |
32 if ((fp = fopen(filename, "r")) == NULL) { | |
33 // 2nd try... | |
34 sprintf(filename, "%s/.mcabberrc", home); | |
35 if ((fp = fopen(filename, "r")) == NULL) { | |
36 fprintf(stderr, "Cannot open config file!\n"); | |
37 exit(EXIT_FAILURE); | |
38 } | |
39 } | |
40 g_free(filename); | |
41 } | |
42 else if ((fp = fopen(filename, "r")) == NULL) { | |
24 | 43 perror("fopen (parsecfg.c:46)"); |
44 exit(EXIT_FAILURE); | |
45 } | |
46 | |
170 | 47 buf = g_new(char, 256); |
169 | 48 |
170 | 49 while (fgets(buf, 256, fp) != NULL) { |
24 | 50 line = buf; |
51 | |
52 while (isspace((int) *line)) | |
53 line++; | |
54 | |
55 while ((strlen(line) > 0) | |
56 && isspace((int) line[strlen(line) - 1])) | |
57 line[strlen(line) - 1] = '\0'; | |
58 | |
59 if ((*line == '\n') || (*line == '\0') || (*line == '#')) | |
60 continue; | |
61 | |
62 if ((strchr(line, '=') != NULL)) { | |
63 value = strchr(line, '='); | |
64 *value = '\0'; | |
65 value++; | |
66 | |
67 while (isspace((int) *value)) | |
68 value++; | |
69 | |
70 while ((strlen(line) > 0) | |
71 && isspace((int) line[strlen(line) - 1])) | |
72 line[strlen(line) - 1] = '\0'; | |
73 | |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
74 settings_set(SETTINGS_TYPE_OPTION, line, value); |
24 | 75 continue; |
76 } | |
77 fprintf(stderr, "CFG: orphaned line \"%s\"\n", line); | |
78 } | |
169 | 79 g_free(buf); |
24 | 80 return 1; |
81 } |