Mercurial > hg
annotate mcabber/src/parsecfg.c @ 289:72fa52203651
Update documentation
* Update /alias doc
* Add documentation for /bind
* Improve /msay help for AsciiDoc and HTML formats. Don't know how to get a
better presentation with the manpage format :(
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 08 Jul 2005 22:10:42 +0100 |
parents | f5dd437c057b |
children | 9bdfef4f4735 12f919be3da5 |
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 |
11 int cfg_file(char *filename) | |
12 { | |
13 FILE *fp; | |
14 char *buf; | |
15 char *line; | |
16 char *value; | |
17 | |
169 | 18 if (!filename) { |
19 // Use default config file locations | |
20 char *home = getenv("HOME"); | |
21 if (!home) { | |
22 ut_WriteLog("Can't find home dir!\n"); | |
23 exit(EXIT_FAILURE); | |
24 } | |
25 filename = g_new(char, strlen(home)+24); | |
26 sprintf(filename, "%s/.mcabber/mcabberrc", home); | |
27 if ((fp = fopen(filename, "r")) == NULL) { | |
28 // 2nd try... | |
29 sprintf(filename, "%s/.mcabberrc", home); | |
30 if ((fp = fopen(filename, "r")) == NULL) { | |
31 fprintf(stderr, "Cannot open config file!\n"); | |
32 exit(EXIT_FAILURE); | |
33 } | |
34 } | |
35 g_free(filename); | |
36 } | |
37 else if ((fp = fopen(filename, "r")) == NULL) { | |
24 | 38 perror("fopen (parsecfg.c:46)"); |
39 exit(EXIT_FAILURE); | |
40 } | |
41 | |
170 | 42 buf = g_new(char, 256); |
169 | 43 |
170 | 44 while (fgets(buf, 256, fp) != NULL) { |
24 | 45 line = buf; |
46 | |
47 while (isspace((int) *line)) | |
48 line++; | |
49 | |
50 while ((strlen(line) > 0) | |
51 && isspace((int) line[strlen(line) - 1])) | |
52 line[strlen(line) - 1] = '\0'; | |
53 | |
54 if ((*line == '\n') || (*line == '\0') || (*line == '#')) | |
55 continue; | |
56 | |
57 if ((strchr(line, '=') != NULL)) { | |
58 value = strchr(line, '='); | |
59 *value = '\0'; | |
60 value++; | |
61 | |
62 while (isspace((int) *value)) | |
63 value++; | |
64 | |
65 while ((strlen(line) > 0) | |
66 && isspace((int) line[strlen(line) - 1])) | |
67 line[strlen(line) - 1] = '\0'; | |
68 | |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
69 settings_set(SETTINGS_TYPE_OPTION, line, value); |
24 | 70 continue; |
71 } | |
72 fprintf(stderr, "CFG: orphaned line \"%s\"\n", line); | |
73 } | |
169 | 74 g_free(buf); |
24 | 75 return 1; |
76 } |