Mercurial > pidgin
annotate src/gaimrc.c @ 686:cd6772d0685a
[gaim-migrate @ 696]
:)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 15 Aug 2000 18:32:56 +0000 |
parents | ddc3fd0dcd51 |
children | 16831576f242 |
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; | |
47 | |
48 int report_idle, web_browser; | |
49 struct save_pos blist_pos; | |
50 char web_command[2048]; | |
51 char aim_host[512]; | |
52 int aim_port; | |
53 char login_host[512]; | |
54 int login_port; | |
180 | 55 char latest_ver[25]; |
1 | 56 |
57 struct parse { | |
58 char option[256]; | |
59 char value[6][256]; | |
60 }; | |
61 | |
62 static struct parse *parse_line(char *line) | |
63 { | |
64 char *c = line; | |
65 int inopt = 1, inval = 0, curval = -1; | |
66 int optlen = 0, vallen = 0; | |
67 static struct parse p; | |
68 | |
69 | |
70 while(*c) { | |
71 if (*c == '\t') { | |
72 c++; | |
73 continue; | |
74 } | |
75 if (inopt) { | |
76 // if ((*c < 'a' || *c > 'z') && *c != '_') { | |
77 if ((*c < 'a' || *c > 'z') && *c != '_' && (*c < 'A' || *c > 'Z')) { | |
78 inopt = 0; | |
79 p.option[optlen] = 0; | |
80 c++; | |
81 continue; | |
82 } | |
83 | |
84 p.option[optlen] = *c; | |
85 optlen++; | |
86 c++; | |
87 continue; | |
88 } else if (inval) { | |
89 if ( (*c == '}') ) { | |
90 if (*(c-1) == '\\') { | |
91 p.value[curval][vallen - 1] = *c; | |
92 c++; | |
93 continue; | |
94 } else { | |
95 p.value[curval][vallen - 1] = 0; | |
96 inval = 0; | |
97 c++; | |
98 continue; | |
99 } | |
100 } else { | |
101 p.value[curval][vallen] = *c; | |
102 vallen++; | |
103 c++; | |
104 continue; } | |
105 } else if (*c == '{') { | |
106 if (*(c-1) == '\\') { | |
107 p.value[curval][vallen-1] = *c; | |
108 c++; | |
109 continue; | |
110 } | |
111 else | |
112 { | |
113 curval++; | |
114 vallen = 0; | |
115 inval = 1; | |
116 c++; | |
117 c++; | |
118 continue; | |
119 } | |
120 } | |
121 c++; | |
122 } | |
123 return &p; | |
124 } | |
125 | |
126 | |
127 static int gaimrc_parse_tag(FILE *f) | |
128 { | |
129 char buf[2048]; | |
130 char tag[256]; | |
131 buf[0] = '#'; | |
132 | |
133 while (buf[0] == '#' && !feof(f)) | |
134 fgets(buf, sizeof(buf), f); | |
135 | |
136 if (feof(f)) | |
137 return -1; | |
138 | |
139 sscanf(buf, "%s {", tag); | |
140 | |
141 if (!strcmp(tag, "users")) { | |
142 return 0; | |
143 } else if (!strcmp(tag, "options")) { | |
144 return 1; | |
145 } else if (!strcmp(tag, "away")) { | |
146 return 2; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
147 } else if (!strcmp(tag, "plugins")) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
148 return 3; |
673 | 149 } else if (!strcmp(tag, "pounce")) { |
150 return 4; | |
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 | |
673 | 245 static void gaimrc_read_pounce(FILE *f) |
246 { | |
247 struct parse *p; | |
248 char buf[4096]; | |
249 struct buddy_pounce *b; | |
250 | |
251 buf[0] = 0; | |
252 | |
253 while (buf[0] != '}') | |
254 { | |
255 if (!fgets(buf, sizeof(buf), f)) | |
256 return; | |
257 | |
258 if (buf[0] == '}') | |
259 return; | |
260 | |
261 p = parse_line(buf); | |
262 if (!strcmp(p->option, "entry")) | |
263 { | |
264 b = g_new0(struct buddy_pounce, 1); | |
265 | |
266 g_snprintf(b->name, sizeof(b->name), "%s", p->value[0]); | |
267 g_snprintf(b->message, sizeof(b->message), "%s", p->value[1]); | |
268 | |
269 b->popup = atoi(p->value[2]); | |
270 b->sendim = atoi(p->value[3]); | |
271 | |
272 filter_break(b->message); | |
273 buddy_pounces = g_list_append(buddy_pounces, b); | |
274 } | |
275 } | |
276 } | |
277 | |
278 static void gaimrc_write_pounce(FILE *f) | |
279 { | |
280 GList *pnc = buddy_pounces; | |
281 struct buddy_pounce *b; | |
282 | |
283 fprintf(f, "pounce {\n"); | |
284 | |
285 if (pnc) | |
286 { | |
287 while (pnc) { | |
288 char *str1, *str2; | |
289 int popup, sendim; | |
290 | |
291 b = (struct buddy_pounce *)pnc->data; | |
292 | |
293 str1 = escape_text2(b->name); | |
294 str2 = escape_text2(b->message); | |
295 popup = b->popup; | |
296 sendim = b->sendim; | |
297 | |
298 fprintf(f, "\tentry { %s } { %s } { %d } { %d }\n", str1, str2, popup, sendim); | |
299 | |
300 /* escape_text2 uses malloc(), so we don't want to g_free these */ | |
301 free(str1); | |
302 free(str2); | |
303 | |
304 pnc = pnc->next; | |
305 } | |
306 } | |
307 | |
308 fprintf(f, "}\n"); | |
309 } | |
310 | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
311 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
312 static void gaimrc_write_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
313 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
314 GList *pl = plugins; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
315 struct gaim_plugin *p; |
1 | 316 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
317 fprintf(f, "plugins {\n"); |
1 | 318 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
319 while (pl) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
320 char *path; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
321 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
322 p = (struct gaim_plugin *)pl->data; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
323 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
324 path = escape_text2(p->filename); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
325 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
326 fprintf(f, "\tplugin { %s }\n", path); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
327 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
328 free(path); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
329 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
330 pl = pl->next; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
331 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
332 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
333 fprintf(f, "}\n"); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
334 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
335 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
336 static void gaimrc_read_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
337 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
338 struct parse *p; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
339 char buf[4096]; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
340 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
341 buf[0] = 0; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
342 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
343 while (buf[0] != '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
344 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
345 if (!fgets(buf, sizeof(buf), f)) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
346 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
347 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
348 if (buf[0] == '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
349 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
350 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
351 p = parse_line(buf); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
352 if (!strcmp(p->option, "plugin")) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
353 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
354 load_plugin(p->value[0]); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
355 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
356 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
357 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
358 #endif /* GAIM_PLUGINS */ |
1 | 359 |
360 static struct aim_user *gaimrc_read_user(FILE *f) | |
361 { | |
362 struct parse *p; | |
363 struct aim_user *u; | |
364 char buf[4096]; | |
365 | |
366 if (!fgets(buf, sizeof(buf), f)) | |
367 return NULL; | |
368 | |
369 p = parse_line(buf); | |
370 | |
371 if (strcmp(p->option, "ident")) | |
372 return NULL; | |
373 | |
374 u = g_new0(struct aim_user, 1); | |
375 | |
376 strcpy(u->username, p->value[0]); | |
377 strcpy(u->password, p->value[1]); | |
378 | |
379 u->user_info[0] = 0; | |
380 | |
381 if (!fgets(buf, sizeof(buf), f)) | |
382 return u; | |
383 | |
384 if (strcmp(buf, "\t\tuser_info {\n")) { | |
385 return u; | |
386 } | |
387 | |
388 if (!fgets(buf, sizeof(buf), f)) | |
389 return u; | |
390 | |
391 while (strncmp(buf, "\t\t}", 3)) { | |
392 if (strlen(buf) > 3) | |
393 strcat(u->user_info, &buf[3]); | |
394 | |
395 if (!fgets(buf, sizeof(buf), f)) { | |
396 return u; | |
397 } | |
398 } | |
399 | |
400 return u; | |
401 | |
402 } | |
403 | |
404 static void gaimrc_write_user(FILE *f, struct aim_user *u) | |
405 { | |
406 char *c; | |
407 int nl = 1;; | |
131
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
408 if (general_options & OPT_GEN_REMEMBER_PASS) |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
409 fprintf(f, "\t\tident { %s } { %s }\n", u->username, u->password); |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
410 else |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
411 fprintf(f, "\t\tident { %s } { }\n", u->username); |
1 | 412 fprintf(f, "\t\tuser_info {"); |
413 c = u->user_info; | |
414 while(*c) { | |
415 /* This is not as silly as it looks. */ | |
416 if (*c == '\n') { | |
417 nl++; | |
418 } else { | |
419 if (nl) { | |
420 while(nl) { | |
421 fprintf(f, "\n\t\t\t"); | |
422 nl--; | |
423 } | |
424 } | |
425 fprintf(f, "%c", *c); | |
426 } | |
427 c++; | |
428 } | |
429 fprintf(f, "\n\t\t}\n"); | |
430 | |
431 } | |
432 | |
433 | |
434 static void gaimrc_read_users(FILE *f) | |
435 { | |
436 char buf[2048]; | |
437 struct aim_user *u; | |
438 struct parse *p; | |
439 int cur = 0; | |
440 | |
441 buf[0] = 0; | |
442 | |
443 while (buf[0] != '}') { | |
444 if (buf[0] == '#') | |
445 continue; | |
446 | |
447 if (!fgets(buf, sizeof(buf), f)) | |
448 return; | |
449 | |
450 | |
451 | |
452 p = parse_line(buf); | |
453 | |
454 if (!strcmp(p->option, "current_user")) { | |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
455 cur = 1; |
1 | 456 } else if (strcmp(p->option, "user")) { |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
457 cur = 0; |
1 | 458 continue; |
159
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
459 } else { |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
460 cur = 0; |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
461 } |
1 | 462 |
463 u = gaimrc_read_user(f); | |
464 | |
465 if (cur) | |
466 current_user = u; | |
467 | |
468 aim_users = g_list_append(aim_users, u); | |
469 } | |
470 } | |
471 | |
472 static void gaimrc_write_users(FILE *f) | |
473 { | |
474 GList *usr = aim_users; | |
475 struct aim_user *u; | |
476 | |
477 fprintf(f, "users {\n"); | |
478 | |
479 while(usr) { | |
480 u = (struct aim_user *)usr->data; | |
481 if (current_user == u) { | |
482 fprintf(f, "\tcurrent_user {\n"); | |
483 } else { | |
484 fprintf(f, "\tuser {\n"); | |
485 } | |
486 gaimrc_write_user(f, u); | |
487 | |
488 fprintf(f, "\t}\n"); | |
489 | |
490 usr = usr->next; | |
491 } | |
492 | |
493 fprintf(f, "}\n"); | |
494 } | |
495 | |
496 | |
497 | |
498 | |
499 static void gaimrc_read_options(FILE *f) | |
500 { | |
501 char buf[2048]; | |
502 struct parse *p; | |
503 | |
504 buf[0] = 0; | |
505 | |
506 while (buf[0] != '}') { | |
507 if (buf[0] == '#') | |
508 continue; | |
509 | |
510 if (!fgets(buf, sizeof(buf), f)) | |
511 return; | |
512 | |
513 p = parse_line(buf); | |
514 | |
515 if (!strcmp(p->option, "general_options")) { | |
516 general_options = atoi(p->value[0]); | |
517 } else if (!strcmp(p->option, "display_options")) { | |
518 display_options = atoi(p->value[0]); | |
519 } else if (!strcmp(p->option, "sound_options")) { | |
520 sound_options = atoi(p->value[0]); | |
666
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
521 } else if (!strcmp(p->option, "font_options")) { |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
522 font_options = atoi(p->value[0]); |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
523 } else if (!strcmp(p->option, "font_face")) { |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
524 if (p->value[0] != NULL) |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
525 g_snprintf(fontface, sizeof(fontface), "%s", p->value[0]); |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
526 } else if (!strcmp(p->option, "foreground")) { |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
527 fgcolor = atoi(p->value[0]); |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
528 } else if (!strcmp(p->option, "background")) { |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
529 bgcolor = atoi(p->value[0]); |
1 | 530 } else if (!strcmp(p->option, "report_idle")) { |
531 report_idle = atoi(p->value[0]); | |
532 } else if (!strcmp(p->option, "web_browser")) { | |
533 web_browser = atoi(p->value[0]); | |
534 } else if (!strcmp(p->option, "web_command")) { | |
535 strcpy(web_command, p->value[0]); | |
536 } else if (!strcmp(p->option, "proxy_type")) { | |
537 proxy_type = atoi(p->value[0]); | |
538 } else if (!strcmp(p->option, "proxy_host")) { | |
539 strcpy(proxy_host, p->value[0]); | |
540 } else if (!strcmp(p->option, "proxy_port")) { | |
541 proxy_port = atoi(p->value[0]); | |
542 } else if (!strcmp(p->option, "aim_host")) { | |
543 strcpy(aim_host, p->value[0]); | |
544 } else if (!strcmp(p->option, "aim_port")) { | |
545 aim_port = atoi(p->value[0]); | |
546 } else if (!strcmp(p->option, "login_host")) { | |
547 strcpy(login_host, p->value[0]); | |
548 } else if (!strcmp(p->option, "login_port")) { | |
549 login_port = atoi(p->value[0]); | |
550 } else if (!strcmp(p->option, "blist_pos")) { | |
551 blist_pos.x = atoi(p->value[0]); | |
552 blist_pos.y = atoi(p->value[1]); | |
553 blist_pos.width = atoi(p->value[2]); | |
554 blist_pos.height = atoi(p->value[3]); | |
555 blist_pos.xoff = atoi(p->value[4]); | |
556 blist_pos.yoff = atoi(p->value[5]); | |
82 | 557 } |
1 | 558 |
559 } | |
560 | |
561 } | |
562 | |
563 static void gaimrc_write_options(FILE *f) | |
564 { | |
565 | |
566 fprintf(f, "options {\n"); | |
567 fprintf(f, "\tgeneral_options { %d }\n", general_options); | |
568 fprintf(f, "\tdisplay_options { %d }\n", display_options); | |
569 fprintf(f, "\tsound_options { %d }\n", sound_options); | |
666
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
570 fprintf(f, "\tfont_options { %d }\n", font_options); |
232 | 571 if (fontface) |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
572 fprintf(f, "\tfont_face { %s }\n", fontface); |
666
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
573 fprintf(f, "\tforeground { %d }\n", fgcolor); |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
574 fprintf(f, "\tbackground { %d }\n", bgcolor); |
1 | 575 fprintf(f, "\treport_idle { %d }\n", report_idle); |
576 fprintf(f, "\tweb_browser { %d }\n", web_browser); | |
577 fprintf(f, "\tweb_command { %s }\n", web_command); | |
578 fprintf(f, "\tproxy_type { %d }\n", proxy_type); | |
579 fprintf(f, "\tproxy_host { %s }\n", proxy_host); | |
580 fprintf(f, "\tproxy_port { %d }\n", proxy_port); | |
581 fprintf(f, "\taim_host { %s }\n", aim_host); | |
582 fprintf(f, "\taim_port { %d }\n", aim_port); | |
583 fprintf(f, "\tlogin_host { %s }\n", login_host); | |
584 fprintf(f, "\tlogin_port { %d }\n", login_port); | |
585 fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d } { %d } { %d }\n", | |
586 blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height, | |
587 blist_pos.xoff, blist_pos.yoff); | |
180 | 588 fprintf(f, "\tlatest_ver { %s }\n", latest_ver); |
1 | 589 fprintf(f, "}\n"); |
590 } | |
591 | |
592 | |
593 void set_defaults() | |
594 { | |
570 | 595 if (aim_users) |
596 { | |
597 g_list_free(aim_users); | |
598 aim_users = NULL; | |
599 } | |
600 if (away_messages) | |
601 { | |
602 g_list_free(away_messages); | |
603 away_messages = NULL; | |
604 } | |
1 | 605 general_options = |
606 OPT_GEN_SEND_LINKS | | |
607 OPT_GEN_ENTER_SENDS | | |
608 OPT_GEN_SAVED_WINDOWS | | |
609 OPT_GEN_REMEMBER_PASS | | |
340
0d9cfc3579a5
[gaim-migrate @ 350]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
610 OPT_GEN_REGISTERED | |
0d9cfc3579a5
[gaim-migrate @ 350]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
611 OPT_GEN_NEAR_APPLET; |
1 | 612 display_options = |
613 OPT_DISP_SHOW_IDLETIME | | |
614 OPT_DISP_SHOW_TIME | | |
615 OPT_DISP_SHOW_PIXMAPS | | |
453 | 616 OPT_DISP_SHOW_BUDDYTICKER | |
1 | 617 OPT_DISP_SHOW_BUTTON_XPM; |
618 font_options = 0; | |
156 | 619 sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON; |
1 | 620 report_idle = IDLE_GAIM; |
621 web_browser = BROWSER_NETSCAPE; | |
622 proxy_type = PROXY_NONE; | |
623 | |
624 aim_port = TOC_PORT; | |
625 login_port = AUTH_PORT; | |
626 g_snprintf(aim_host, sizeof(aim_host), "%s", TOC_HOST); | |
627 g_snprintf(login_host, sizeof(login_host), "%s", AUTH_HOST); | |
628 proxy_host[0] = 0; | |
629 proxy_port = 0; | |
630 g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s"); | |
631 blist_pos.width = 0; | |
632 blist_pos.height = 0; | |
633 blist_pos.x = 0; | |
634 blist_pos.y = 0; | |
635 blist_pos.xoff = 0; | |
636 blist_pos.yoff = 0; | |
180 | 637 g_snprintf(latest_ver, BUF_LONG, "%s", VERSION); |
1 | 638 } |
639 | |
640 | |
641 void load_prefs() | |
642 { | |
643 FILE *f; | |
644 char buf[1024]; | |
645 int ver = 0; | |
570 | 646 |
1 | 647 if (getenv("HOME")) { |
648 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
649 if ((f = fopen(buf,"r"))) { | |
650 fgets(buf, sizeof(buf), f); | |
651 sscanf(buf, "# .gaimrc v%d", &ver); | |
15 | 652 if ( (ver <= 1) || (buf[0] != '#')) { |
1 | 653 fclose(f); |
654 set_defaults(); | |
655 save_prefs(); | |
656 load_prefs(); | |
657 return; | |
658 } | |
659 while(!feof(f)) { | |
660 switch(gaimrc_parse_tag(f)) { | |
661 case -1: | |
662 /* Let the loop end, EOF*/ | |
663 break; | |
664 case 0: | |
665 gaimrc_read_users(f); | |
666 break; | |
667 case 1: | |
668 gaimrc_read_options(f); | |
669 break; | |
670 case 2: | |
671 gaimrc_read_away(f); | |
672 break; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
673 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
674 case 3: |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
675 gaimrc_read_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
676 break; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
677 #endif |
673 | 678 case 4: |
679 gaimrc_read_pounce(f); | |
680 break; | |
1 | 681 default: |
682 /* NOOP */ | |
683 break; | |
684 } | |
685 } | |
686 fclose(f); | |
687 } | |
688 } | |
689 | |
690 } | |
691 | |
692 void save_prefs() | |
693 { | |
694 FILE *f; | |
695 char buf[BUF_LONG]; | |
696 | |
697 if (getenv("HOME")) { | |
698 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
699 if ((f = fopen(buf,"w"))) { | |
15 | 700 fprintf(f, "# .gaimrc v%d\n", 2); |
1 | 701 gaimrc_write_users(f); |
673 | 702 gaimrc_write_options(f); |
703 gaimrc_write_away(f); | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
704 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
705 gaimrc_write_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
706 #endif |
673 | 707 gaimrc_write_pounce(f); |
708 fclose(f); | |
709 chmod(buf, S_IRUSR | S_IWUSR); | |
710 } | |
1 | 711 } |
712 } | |
713 |