Mercurial > pidgin
annotate src/gaimrc.c @ 382:5e6edca11fcb
[gaim-migrate @ 392]
yo
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sat, 10 Jun 2000 07:27:41 +0000 |
parents | b402a23f35df |
children | dd82845ed7b6 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
23 #include "../config.h" |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
340
diff
changeset
|
24 #endif |
1 | 25 #include <string.h> |
26 #include <sys/time.h> | |
27 | |
28 #include <sys/types.h> | |
29 #include <sys/stat.h> | |
30 | |
31 #include <unistd.h> | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
34 #include <gtk/gtk.h> | |
35 #include "gaim.h" | |
36 #include "proxy.h" | |
37 | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
38 /* for people like myself, who are too lazy to add an away msg :) */ |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
39 #define BORING_DEFAULT_AWAY_MSG "sorry, i ran out for a while. bbl" |
1 | 40 |
41 struct aim_user *current_user = NULL; | |
42 GList *aim_users = NULL; | |
43 int general_options; | |
44 int display_options; | |
45 int sound_options; | |
46 int font_options; | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
47 char *fontface; |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
48 char *fontname; |
1 | 49 |
50 int report_idle, web_browser; | |
51 struct save_pos blist_pos; | |
52 char web_command[2048]; | |
53 char aim_host[512]; | |
54 int aim_port; | |
55 char login_host[512]; | |
56 int login_port; | |
180 | 57 char latest_ver[25]; |
1 | 58 |
59 struct parse { | |
60 char option[256]; | |
61 char value[6][256]; | |
62 }; | |
63 | |
64 static struct parse *parse_line(char *line) | |
65 { | |
66 char *c = line; | |
67 int inopt = 1, inval = 0, curval = -1; | |
68 int optlen = 0, vallen = 0; | |
69 static struct parse p; | |
70 | |
71 | |
72 while(*c) { | |
73 if (*c == '\t') { | |
74 c++; | |
75 continue; | |
76 } | |
77 if (inopt) { | |
78 // if ((*c < 'a' || *c > 'z') && *c != '_') { | |
79 if ((*c < 'a' || *c > 'z') && *c != '_' && (*c < 'A' || *c > 'Z')) { | |
80 inopt = 0; | |
81 p.option[optlen] = 0; | |
82 c++; | |
83 continue; | |
84 } | |
85 | |
86 p.option[optlen] = *c; | |
87 optlen++; | |
88 c++; | |
89 continue; | |
90 } else if (inval) { | |
91 if ( (*c == '}') ) { | |
92 if (*(c-1) == '\\') { | |
93 p.value[curval][vallen - 1] = *c; | |
94 c++; | |
95 continue; | |
96 } else { | |
97 p.value[curval][vallen - 1] = 0; | |
98 inval = 0; | |
99 c++; | |
100 continue; | |
101 } | |
102 } else { | |
103 p.value[curval][vallen] = *c; | |
104 vallen++; | |
105 c++; | |
106 continue; } | |
107 } else if (*c == '{') { | |
108 if (*(c-1) == '\\') { | |
109 p.value[curval][vallen-1] = *c; | |
110 c++; | |
111 continue; | |
112 } | |
113 else | |
114 { | |
115 curval++; | |
116 vallen = 0; | |
117 inval = 1; | |
118 c++; | |
119 c++; | |
120 continue; | |
121 } | |
122 } | |
123 c++; | |
124 } | |
125 return &p; | |
126 } | |
127 | |
128 | |
129 static int gaimrc_parse_tag(FILE *f) | |
130 { | |
131 char buf[2048]; | |
132 char tag[256]; | |
133 buf[0] = '#'; | |
134 | |
135 while (buf[0] == '#' && !feof(f)) | |
136 fgets(buf, sizeof(buf), f); | |
137 | |
138 if (feof(f)) | |
139 return -1; | |
140 | |
141 sscanf(buf, "%s {", tag); | |
142 | |
143 if (!strcmp(tag, "users")) { | |
144 return 0; | |
145 } else if (!strcmp(tag, "options")) { | |
146 return 1; | |
147 } else if (!strcmp(tag, "away")) { | |
148 return 2; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
149 } else if (!strcmp(tag, "plugins")) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
150 return 3; |
1 | 151 } |
152 | |
153 return -1; | |
154 } | |
155 | |
156 void filter_break(char *msg) | |
157 { | |
44 | 158 char *c; |
159 int mc; | |
160 int cc; | |
161 | |
162 c = g_malloc(strlen(msg)+1); | |
163 strcpy(c, msg); | |
1 | 164 |
44 | 165 mc = 0; |
166 cc = 0; | |
167 while (c[cc] != '\0') | |
168 { | |
169 if (c[cc] == '\\') { | |
170 cc++; | |
171 msg[mc] = c[cc]; | |
172 } | |
173 else { | |
174 msg[mc] = c[cc]; | |
175 } | |
176 mc++; | |
177 cc++; | |
178 } | |
179 msg[mc] = 0; | |
180 g_free(c); | |
1 | 181 } |
182 | |
44 | 183 |
1 | 184 static void gaimrc_read_away(FILE *f) |
185 { | |
186 struct parse *p; | |
187 char buf[4096]; | |
188 struct away_message *a; | |
189 | |
190 buf[0] = 0; | |
191 | |
192 while (buf[0] != '}') | |
193 { | |
194 if (!fgets(buf, sizeof(buf), f)) | |
195 return; | |
196 | |
197 if (buf[0] == '}') | |
198 return; | |
199 | |
200 p = parse_line(buf); | |
15 | 201 if (!strcmp(p->option, "message")) |
202 { | |
203 a = g_new0(struct away_message, 1); | |
1 | 204 |
15 | 205 g_snprintf(a->name, sizeof(a->name), "%s", p->value[0]); |
206 g_snprintf(a->message, sizeof(a->message), "%s", p->value[1]); | |
207 filter_break(a->message); | |
208 away_messages = g_list_append(away_messages, a); | |
209 } | |
1 | 210 } |
211 } | |
212 | |
213 static void gaimrc_write_away(FILE *f) | |
214 { | |
215 GList *awy = away_messages; | |
216 struct away_message *a; | |
217 | |
218 fprintf(f, "away {\n"); | |
219 | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
220 if (awy) |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
221 { |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
222 while (awy) { |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
223 char *str1, *str2; |
26 | 224 |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
225 a = (struct away_message *)awy->data; |
26 | 226 |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
227 str1 = escape_text2(a->name); |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
228 str2 = escape_text2(a->message); |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
229 |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
230 fprintf(f, "\tmessage { %s } { %s }\n", str1, str2); |
26 | 231 |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
232 /* escape_text2 uses malloc(), so we don't want to g_free these */ |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
233 free(str1); |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
234 free(str2); |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
235 |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
236 awy = awy->next; |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
237 } |
1 | 238 } |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
239 else |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
240 fprintf(f, "\tmessage { boring default } { %s }\n", BORING_DEFAULT_AWAY_MSG); |
1 | 241 |
242 fprintf(f, "}\n"); | |
243 } | |
244 | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
245 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
246 static void gaimrc_write_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
247 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
248 GList *pl = plugins; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
249 struct gaim_plugin *p; |
1 | 250 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
251 fprintf(f, "plugins {\n"); |
1 | 252 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
253 while (pl) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
254 char *path; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
255 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
256 p = (struct gaim_plugin *)pl->data; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
257 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
258 path = escape_text2(p->filename); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
259 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
260 fprintf(f, "\tplugin { %s }\n", path); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
261 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
262 free(path); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
263 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
264 pl = pl->next; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
265 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
266 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
267 fprintf(f, "}\n"); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
268 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
269 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
270 static void gaimrc_read_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
271 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
272 struct parse *p; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
273 char buf[4096]; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
274 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
275 buf[0] = 0; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
276 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
277 while (buf[0] != '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
278 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
279 if (!fgets(buf, sizeof(buf), f)) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
280 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
281 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
282 if (buf[0] == '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
283 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
284 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
285 p = parse_line(buf); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
286 if (!strcmp(p->option, "plugin")) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
287 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
288 load_plugin(p->value[0]); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
289 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
290 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
291 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
292 #endif /* GAIM_PLUGINS */ |
1 | 293 |
294 static struct aim_user *gaimrc_read_user(FILE *f) | |
295 { | |
296 struct parse *p; | |
297 struct aim_user *u; | |
298 char buf[4096]; | |
299 | |
300 if (!fgets(buf, sizeof(buf), f)) | |
301 return NULL; | |
302 | |
303 p = parse_line(buf); | |
304 | |
305 if (strcmp(p->option, "ident")) | |
306 return NULL; | |
307 | |
308 u = g_new0(struct aim_user, 1); | |
309 | |
310 strcpy(u->username, p->value[0]); | |
311 strcpy(u->password, p->value[1]); | |
312 | |
313 u->user_info[0] = 0; | |
314 | |
315 if (!fgets(buf, sizeof(buf), f)) | |
316 return u; | |
317 | |
318 if (strcmp(buf, "\t\tuser_info {\n")) { | |
319 return u; | |
320 } | |
321 | |
322 if (!fgets(buf, sizeof(buf), f)) | |
323 return u; | |
324 | |
325 while (strncmp(buf, "\t\t}", 3)) { | |
326 if (strlen(buf) > 3) | |
327 strcat(u->user_info, &buf[3]); | |
328 | |
329 if (!fgets(buf, sizeof(buf), f)) { | |
330 return u; | |
331 } | |
332 } | |
333 | |
334 return u; | |
335 | |
336 } | |
337 | |
338 static void gaimrc_write_user(FILE *f, struct aim_user *u) | |
339 { | |
340 char *c; | |
341 int nl = 1;; | |
131
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
342 if (general_options & OPT_GEN_REMEMBER_PASS) |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
343 fprintf(f, "\t\tident { %s } { %s }\n", u->username, u->password); |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
344 else |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
345 fprintf(f, "\t\tident { %s } { }\n", u->username); |
1 | 346 fprintf(f, "\t\tuser_info {"); |
347 c = u->user_info; | |
348 while(*c) { | |
349 /* This is not as silly as it looks. */ | |
350 if (*c == '\n') { | |
351 nl++; | |
352 } else { | |
353 if (nl) { | |
354 while(nl) { | |
355 fprintf(f, "\n\t\t\t"); | |
356 nl--; | |
357 } | |
358 } | |
359 fprintf(f, "%c", *c); | |
360 } | |
361 c++; | |
362 } | |
363 fprintf(f, "\n\t\t}\n"); | |
364 | |
365 } | |
366 | |
367 | |
368 static void gaimrc_read_users(FILE *f) | |
369 { | |
370 char buf[2048]; | |
371 struct aim_user *u; | |
372 struct parse *p; | |
373 int cur = 0; | |
374 | |
375 buf[0] = 0; | |
376 | |
377 while (buf[0] != '}') { | |
378 if (buf[0] == '#') | |
379 continue; | |
380 | |
381 if (!fgets(buf, sizeof(buf), f)) | |
382 return; | |
383 | |
384 | |
385 | |
386 p = parse_line(buf); | |
387 | |
388 if (!strcmp(p->option, "current_user")) { | |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
389 cur = 1; |
1 | 390 } else if (strcmp(p->option, "user")) { |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
391 cur = 0; |
1 | 392 continue; |
159
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
393 } else { |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
394 cur = 0; |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
395 } |
1 | 396 |
397 u = gaimrc_read_user(f); | |
398 | |
399 if (cur) | |
400 current_user = u; | |
401 | |
402 aim_users = g_list_append(aim_users, u); | |
403 } | |
404 } | |
405 | |
406 static void gaimrc_write_users(FILE *f) | |
407 { | |
408 GList *usr = aim_users; | |
409 struct aim_user *u; | |
410 | |
411 fprintf(f, "users {\n"); | |
412 | |
413 while(usr) { | |
414 u = (struct aim_user *)usr->data; | |
415 if (current_user == u) { | |
416 fprintf(f, "\tcurrent_user {\n"); | |
417 } else { | |
418 fprintf(f, "\tuser {\n"); | |
419 } | |
420 gaimrc_write_user(f, u); | |
421 | |
422 fprintf(f, "\t}\n"); | |
423 | |
424 usr = usr->next; | |
425 } | |
426 | |
427 fprintf(f, "}\n"); | |
428 } | |
429 | |
430 | |
431 | |
432 | |
433 static void gaimrc_read_options(FILE *f) | |
434 { | |
435 char buf[2048]; | |
436 struct parse *p; | |
437 | |
438 buf[0] = 0; | |
439 | |
440 while (buf[0] != '}') { | |
441 if (buf[0] == '#') | |
442 continue; | |
443 | |
444 if (!fgets(buf, sizeof(buf), f)) | |
445 return; | |
446 | |
447 p = parse_line(buf); | |
448 | |
449 if (!strcmp(p->option, "general_options")) { | |
450 general_options = atoi(p->value[0]); | |
451 } else if (!strcmp(p->option, "display_options")) { | |
452 display_options = atoi(p->value[0]); | |
453 } else if (!strcmp(p->option, "sound_options")) { | |
454 sound_options = atoi(p->value[0]); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
455 } else if (!strcmp(p->option, "font_options")) { |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
456 font_options = atoi(p->value[0]); |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
457 } else if (!strcmp(p->option, "font_face")) { |
233 | 458 if (p->value[0] != NULL) |
459 fontface = g_strconcat(p->value[0], '\0'); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
460 } else if (!strcmp(p->option, "font_name")) { |
233 | 461 if (p->value[0] != NULL) |
462 fontname = g_strconcat(p->value[0], '\0'); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
463 } else if (!strcmp(p->option, "latest_ver")) { |
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
464 g_snprintf(latest_ver, BUF_LONG, "%s", p->value[0]); |
1 | 465 } else if (!strcmp(p->option, "report_idle")) { |
466 report_idle = atoi(p->value[0]); | |
467 } else if (!strcmp(p->option, "web_browser")) { | |
468 web_browser = atoi(p->value[0]); | |
469 } else if (!strcmp(p->option, "web_command")) { | |
470 strcpy(web_command, p->value[0]); | |
471 } else if (!strcmp(p->option, "proxy_type")) { | |
472 proxy_type = atoi(p->value[0]); | |
473 } else if (!strcmp(p->option, "proxy_host")) { | |
474 strcpy(proxy_host, p->value[0]); | |
475 } else if (!strcmp(p->option, "proxy_port")) { | |
476 proxy_port = atoi(p->value[0]); | |
477 } else if (!strcmp(p->option, "aim_host")) { | |
478 strcpy(aim_host, p->value[0]); | |
479 } else if (!strcmp(p->option, "aim_port")) { | |
480 aim_port = atoi(p->value[0]); | |
481 } else if (!strcmp(p->option, "login_host")) { | |
482 strcpy(login_host, p->value[0]); | |
483 } else if (!strcmp(p->option, "login_port")) { | |
484 login_port = atoi(p->value[0]); | |
485 } else if (!strcmp(p->option, "blist_pos")) { | |
486 blist_pos.x = atoi(p->value[0]); | |
487 blist_pos.y = atoi(p->value[1]); | |
488 blist_pos.width = atoi(p->value[2]); | |
489 blist_pos.height = atoi(p->value[3]); | |
490 blist_pos.xoff = atoi(p->value[4]); | |
491 blist_pos.yoff = atoi(p->value[5]); | |
82 | 492 } |
1 | 493 |
494 } | |
495 | |
496 } | |
497 | |
498 static void gaimrc_write_options(FILE *f) | |
499 { | |
500 | |
501 fprintf(f, "options {\n"); | |
502 fprintf(f, "\tgeneral_options { %d }\n", general_options); | |
503 fprintf(f, "\tdisplay_options { %d }\n", display_options); | |
504 fprintf(f, "\tsound_options { %d }\n", sound_options); | |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
505 fprintf(f, "\tfont_options { %d }\n", font_options); |
232 | 506 if (fontface) |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
507 fprintf(f, "\tfont_face { %s }\n", fontface); |
232 | 508 if (fontname) |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
509 fprintf(f, "\tfont_name { %s }\n", fontname); |
1 | 510 fprintf(f, "\treport_idle { %d }\n", report_idle); |
511 fprintf(f, "\tweb_browser { %d }\n", web_browser); | |
512 fprintf(f, "\tweb_command { %s }\n", web_command); | |
513 fprintf(f, "\tproxy_type { %d }\n", proxy_type); | |
514 fprintf(f, "\tproxy_host { %s }\n", proxy_host); | |
515 fprintf(f, "\tproxy_port { %d }\n", proxy_port); | |
516 fprintf(f, "\taim_host { %s }\n", aim_host); | |
517 fprintf(f, "\taim_port { %d }\n", aim_port); | |
518 fprintf(f, "\tlogin_host { %s }\n", login_host); | |
519 fprintf(f, "\tlogin_port { %d }\n", login_port); | |
520 fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d } { %d } { %d }\n", | |
521 blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height, | |
522 blist_pos.xoff, blist_pos.yoff); | |
180 | 523 fprintf(f, "\tlatest_ver { %s }\n", latest_ver); |
1 | 524 fprintf(f, "}\n"); |
525 } | |
526 | |
527 | |
528 void set_defaults() | |
529 { | |
530 general_options = | |
531 OPT_GEN_SEND_LINKS | | |
532 OPT_GEN_ENTER_SENDS | | |
533 OPT_GEN_SAVED_WINDOWS | | |
534 OPT_GEN_REMEMBER_PASS | | |
340
0d9cfc3579a5
[gaim-migrate @ 350]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
535 OPT_GEN_REGISTERED | |
0d9cfc3579a5
[gaim-migrate @ 350]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
536 OPT_GEN_NEAR_APPLET; |
1 | 537 display_options = |
538 OPT_DISP_SHOW_IDLETIME | | |
539 OPT_DISP_SHOW_TIME | | |
540 OPT_DISP_SHOW_PIXMAPS | | |
541 OPT_DISP_SHOW_BUTTON_XPM; | |
542 font_options = 0; | |
156 | 543 sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON; |
1 | 544 report_idle = IDLE_GAIM; |
545 web_browser = BROWSER_NETSCAPE; | |
546 proxy_type = PROXY_NONE; | |
547 | |
548 aim_port = TOC_PORT; | |
549 login_port = AUTH_PORT; | |
550 g_snprintf(aim_host, sizeof(aim_host), "%s", TOC_HOST); | |
551 g_snprintf(login_host, sizeof(login_host), "%s", AUTH_HOST); | |
552 proxy_host[0] = 0; | |
553 proxy_port = 0; | |
554 g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s"); | |
555 blist_pos.width = 0; | |
556 blist_pos.height = 0; | |
557 blist_pos.x = 0; | |
558 blist_pos.y = 0; | |
559 blist_pos.xoff = 0; | |
560 blist_pos.yoff = 0; | |
180 | 561 g_snprintf(latest_ver, BUF_LONG, "%s", VERSION); |
1 | 562 } |
563 | |
564 | |
565 void load_prefs() | |
566 { | |
567 FILE *f; | |
568 char buf[1024]; | |
569 int ver = 0; | |
570 | |
571 if (getenv("HOME")) { | |
572 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
573 if ((f = fopen(buf,"r"))) { | |
574 fgets(buf, sizeof(buf), f); | |
575 sscanf(buf, "# .gaimrc v%d", &ver); | |
15 | 576 if ( (ver <= 1) || (buf[0] != '#')) { |
1 | 577 fclose(f); |
578 set_defaults(); | |
579 save_prefs(); | |
580 load_prefs(); | |
581 return; | |
582 } | |
583 while(!feof(f)) { | |
584 switch(gaimrc_parse_tag(f)) { | |
585 case -1: | |
586 /* Let the loop end, EOF*/ | |
587 break; | |
588 case 0: | |
589 gaimrc_read_users(f); | |
590 break; | |
591 case 1: | |
592 gaimrc_read_options(f); | |
593 break; | |
594 case 2: | |
595 gaimrc_read_away(f); | |
596 break; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
597 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
598 case 3: |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
599 gaimrc_read_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
600 break; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
601 #endif |
1 | 602 default: |
603 /* NOOP */ | |
604 break; | |
605 } | |
606 } | |
607 fclose(f); | |
608 } | |
609 } | |
610 | |
611 } | |
612 | |
613 void save_prefs() | |
614 { | |
615 FILE *f; | |
616 char buf[BUF_LONG]; | |
617 | |
618 if (getenv("HOME")) { | |
619 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
620 if ((f = fopen(buf,"w"))) { | |
15 | 621 fprintf(f, "# .gaimrc v%d\n", 2); |
1 | 622 gaimrc_write_users(f); |
623 gaimrc_write_options(f); | |
624 gaimrc_write_away(f); | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
625 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
626 gaimrc_write_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
627 #endif |
1 | 628 fclose(f); |
629 chmod(buf, S_IRUSR | S_IWUSR); | |
630 } | |
631 | |
632 } | |
633 } | |
634 |