Mercurial > pidgin
annotate src/gaimrc.c @ 708:3ff8b997cd37
[gaim-migrate @ 718]
la la la
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 17 Aug 2000 08:35:34 +0000 |
parents | c7c0d2590681 |
children | b61607d6c2af |
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); | |
690
16831576f242
[gaim-migrate @ 700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
673
diff
changeset
|
294 if (strlen(b->message)) |
16831576f242
[gaim-migrate @ 700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
673
diff
changeset
|
295 str2 = escape_text2(b->message); |
16831576f242
[gaim-migrate @ 700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
673
diff
changeset
|
296 else { |
16831576f242
[gaim-migrate @ 700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
673
diff
changeset
|
297 str2 = malloc(1); |
16831576f242
[gaim-migrate @ 700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
673
diff
changeset
|
298 str2[0] = 0; |
16831576f242
[gaim-migrate @ 700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
673
diff
changeset
|
299 } |
673 | 300 popup = b->popup; |
301 sendim = b->sendim; | |
302 | |
303 fprintf(f, "\tentry { %s } { %s } { %d } { %d }\n", str1, str2, popup, sendim); | |
304 | |
305 /* escape_text2 uses malloc(), so we don't want to g_free these */ | |
306 free(str1); | |
307 free(str2); | |
308 | |
309 pnc = pnc->next; | |
310 } | |
311 } | |
312 | |
313 fprintf(f, "}\n"); | |
314 } | |
315 | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
316 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
317 static void gaimrc_write_plugins(FILE *f) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
318 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
319 GList *pl = plugins; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
320 struct gaim_plugin *p; |
1 | 321 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
322 fprintf(f, "plugins {\n"); |
1 | 323 |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
324 while (pl) { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
325 char *path; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
326 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
327 p = (struct gaim_plugin *)pl->data; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
328 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
329 path = escape_text2(p->filename); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
330 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
331 fprintf(f, "\tplugin { %s }\n", path); |
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 free(path); |
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 pl = pl->next; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
336 } |
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 fprintf(f, "}\n"); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
339 } |
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 static void gaimrc_read_plugins(FILE *f) |
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 struct parse *p; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
344 char buf[4096]; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
345 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
346 buf[0] = 0; |
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 while (buf[0] != '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
349 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
350 if (!fgets(buf, sizeof(buf), f)) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
351 return; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
352 |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
353 if (buf[0] == '}') |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
354 return; |
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 p = parse_line(buf); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
357 if (!strcmp(p->option, "plugin")) |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
358 { |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
359 load_plugin(p->value[0]); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
360 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
361 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
362 } |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
363 #endif /* GAIM_PLUGINS */ |
1 | 364 |
365 static struct aim_user *gaimrc_read_user(FILE *f) | |
366 { | |
367 struct parse *p; | |
368 struct aim_user *u; | |
369 char buf[4096]; | |
370 | |
371 if (!fgets(buf, sizeof(buf), f)) | |
372 return NULL; | |
373 | |
374 p = parse_line(buf); | |
375 | |
376 if (strcmp(p->option, "ident")) | |
377 return NULL; | |
378 | |
379 u = g_new0(struct aim_user, 1); | |
380 | |
381 strcpy(u->username, p->value[0]); | |
382 strcpy(u->password, p->value[1]); | |
383 | |
384 u->user_info[0] = 0; | |
385 | |
386 if (!fgets(buf, sizeof(buf), f)) | |
387 return u; | |
388 | |
389 if (strcmp(buf, "\t\tuser_info {\n")) { | |
390 return u; | |
391 } | |
392 | |
393 if (!fgets(buf, sizeof(buf), f)) | |
394 return u; | |
395 | |
396 while (strncmp(buf, "\t\t}", 3)) { | |
397 if (strlen(buf) > 3) | |
398 strcat(u->user_info, &buf[3]); | |
399 | |
400 if (!fgets(buf, sizeof(buf), f)) { | |
401 return u; | |
402 } | |
403 } | |
404 | |
405 return u; | |
406 | |
407 } | |
408 | |
409 static void gaimrc_write_user(FILE *f, struct aim_user *u) | |
410 { | |
411 char *c; | |
412 int nl = 1;; | |
131
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
413 if (general_options & OPT_GEN_REMEMBER_PASS) |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
414 fprintf(f, "\t\tident { %s } { %s }\n", u->username, u->password); |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
415 else |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
416 fprintf(f, "\t\tident { %s } { }\n", u->username); |
1 | 417 fprintf(f, "\t\tuser_info {"); |
418 c = u->user_info; | |
419 while(*c) { | |
420 /* This is not as silly as it looks. */ | |
421 if (*c == '\n') { | |
422 nl++; | |
423 } else { | |
424 if (nl) { | |
425 while(nl) { | |
426 fprintf(f, "\n\t\t\t"); | |
427 nl--; | |
428 } | |
429 } | |
430 fprintf(f, "%c", *c); | |
431 } | |
432 c++; | |
433 } | |
434 fprintf(f, "\n\t\t}\n"); | |
435 | |
436 } | |
437 | |
438 | |
439 static void gaimrc_read_users(FILE *f) | |
440 { | |
441 char buf[2048]; | |
442 struct aim_user *u; | |
443 struct parse *p; | |
444 int cur = 0; | |
445 | |
446 buf[0] = 0; | |
447 | |
448 while (buf[0] != '}') { | |
449 if (buf[0] == '#') | |
450 continue; | |
451 | |
452 if (!fgets(buf, sizeof(buf), f)) | |
453 return; | |
454 | |
455 | |
456 | |
457 p = parse_line(buf); | |
458 | |
459 if (!strcmp(p->option, "current_user")) { | |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
460 cur = 1; |
1 | 461 } else if (strcmp(p->option, "user")) { |
158
e9414f13d8b7
[gaim-migrate @ 168]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
156
diff
changeset
|
462 cur = 0; |
1 | 463 continue; |
159
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
464 } else { |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
465 cur = 0; |
d56878f647fb
[gaim-migrate @ 169]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
158
diff
changeset
|
466 } |
1 | 467 |
468 u = gaimrc_read_user(f); | |
469 | |
470 if (cur) | |
471 current_user = u; | |
472 | |
473 aim_users = g_list_append(aim_users, u); | |
474 } | |
475 } | |
476 | |
477 static void gaimrc_write_users(FILE *f) | |
478 { | |
479 GList *usr = aim_users; | |
480 struct aim_user *u; | |
481 | |
482 fprintf(f, "users {\n"); | |
483 | |
484 while(usr) { | |
485 u = (struct aim_user *)usr->data; | |
486 if (current_user == u) { | |
487 fprintf(f, "\tcurrent_user {\n"); | |
488 } else { | |
489 fprintf(f, "\tuser {\n"); | |
490 } | |
491 gaimrc_write_user(f, u); | |
492 | |
493 fprintf(f, "\t}\n"); | |
494 | |
495 usr = usr->next; | |
496 } | |
497 | |
498 fprintf(f, "}\n"); | |
499 } | |
500 | |
501 | |
502 | |
503 | |
504 static void gaimrc_read_options(FILE *f) | |
505 { | |
506 char buf[2048]; | |
507 struct parse *p; | |
508 | |
509 buf[0] = 0; | |
510 | |
511 while (buf[0] != '}') { | |
512 if (buf[0] == '#') | |
513 continue; | |
514 | |
515 if (!fgets(buf, sizeof(buf), f)) | |
516 return; | |
517 | |
518 p = parse_line(buf); | |
519 | |
520 if (!strcmp(p->option, "general_options")) { | |
521 general_options = atoi(p->value[0]); | |
522 } else if (!strcmp(p->option, "display_options")) { | |
523 display_options = atoi(p->value[0]); | |
524 } else if (!strcmp(p->option, "sound_options")) { | |
525 sound_options = atoi(p->value[0]); | |
666
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
526 } else if (!strcmp(p->option, "font_options")) { |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
527 font_options = atoi(p->value[0]); |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
528 } else if (!strcmp(p->option, "font_face")) { |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
529 if (p->value[0] != NULL) |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
530 g_snprintf(fontface, sizeof(fontface), "%s", p->value[0]); |
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
531 } else if (!strcmp(p->option, "foreground")) { |
697 | 532 fgcolor.red = atoi(p->value[0]); |
533 fgcolor.green = atoi(p->value[1]); | |
534 fgcolor.blue = atoi(p->value[2]); | |
666
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
535 } else if (!strcmp(p->option, "background")) { |
697 | 536 bgcolor.red = atoi(p->value[0]); |
537 bgcolor.green = atoi(p->value[1]); | |
538 bgcolor.blue = atoi(p->value[2]); | |
1 | 539 } else if (!strcmp(p->option, "report_idle")) { |
540 report_idle = atoi(p->value[0]); | |
541 } else if (!strcmp(p->option, "web_browser")) { | |
542 web_browser = atoi(p->value[0]); | |
543 } else if (!strcmp(p->option, "web_command")) { | |
544 strcpy(web_command, p->value[0]); | |
545 } else if (!strcmp(p->option, "proxy_type")) { | |
546 proxy_type = atoi(p->value[0]); | |
547 } else if (!strcmp(p->option, "proxy_host")) { | |
548 strcpy(proxy_host, p->value[0]); | |
549 } else if (!strcmp(p->option, "proxy_port")) { | |
550 proxy_port = atoi(p->value[0]); | |
551 } else if (!strcmp(p->option, "aim_host")) { | |
552 strcpy(aim_host, p->value[0]); | |
553 } else if (!strcmp(p->option, "aim_port")) { | |
554 aim_port = atoi(p->value[0]); | |
555 } else if (!strcmp(p->option, "login_host")) { | |
556 strcpy(login_host, p->value[0]); | |
557 } else if (!strcmp(p->option, "login_port")) { | |
558 login_port = atoi(p->value[0]); | |
559 } else if (!strcmp(p->option, "blist_pos")) { | |
560 blist_pos.x = atoi(p->value[0]); | |
561 blist_pos.y = atoi(p->value[1]); | |
562 blist_pos.width = atoi(p->value[2]); | |
563 blist_pos.height = atoi(p->value[3]); | |
564 blist_pos.xoff = atoi(p->value[4]); | |
565 blist_pos.yoff = atoi(p->value[5]); | |
82 | 566 } |
1 | 567 |
568 } | |
569 | |
570 } | |
571 | |
572 static void gaimrc_write_options(FILE *f) | |
573 { | |
574 | |
575 fprintf(f, "options {\n"); | |
576 fprintf(f, "\tgeneral_options { %d }\n", general_options); | |
577 fprintf(f, "\tdisplay_options { %d }\n", display_options); | |
578 fprintf(f, "\tsound_options { %d }\n", sound_options); | |
666
71ea550c22ac
[gaim-migrate @ 676]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
570
diff
changeset
|
579 fprintf(f, "\tfont_options { %d }\n", font_options); |
232 | 580 if (fontface) |
230
83dd297aa363
[gaim-migrate @ 240]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
581 fprintf(f, "\tfont_face { %s }\n", fontface); |
697 | 582 fprintf(f, "\tforeground { %d } { %d } { %d }\n", fgcolor.red, fgcolor.green, fgcolor.blue); |
583 fprintf(f, "\tbackground { %d } { %d } { %d }\n", bgcolor.red, bgcolor.green, bgcolor.blue); | |
1 | 584 fprintf(f, "\treport_idle { %d }\n", report_idle); |
585 fprintf(f, "\tweb_browser { %d }\n", web_browser); | |
586 fprintf(f, "\tweb_command { %s }\n", web_command); | |
587 fprintf(f, "\tproxy_type { %d }\n", proxy_type); | |
588 fprintf(f, "\tproxy_host { %s }\n", proxy_host); | |
589 fprintf(f, "\tproxy_port { %d }\n", proxy_port); | |
590 fprintf(f, "\taim_host { %s }\n", aim_host); | |
591 fprintf(f, "\taim_port { %d }\n", aim_port); | |
592 fprintf(f, "\tlogin_host { %s }\n", login_host); | |
593 fprintf(f, "\tlogin_port { %d }\n", login_port); | |
594 fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d } { %d } { %d }\n", | |
595 blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height, | |
596 blist_pos.xoff, blist_pos.yoff); | |
180 | 597 fprintf(f, "\tlatest_ver { %s }\n", latest_ver); |
1 | 598 fprintf(f, "}\n"); |
599 } | |
600 | |
601 | |
602 void set_defaults() | |
603 { | |
570 | 604 if (aim_users) |
605 { | |
606 g_list_free(aim_users); | |
607 aim_users = NULL; | |
608 } | |
609 if (away_messages) | |
610 { | |
611 g_list_free(away_messages); | |
612 away_messages = NULL; | |
613 } | |
1 | 614 general_options = |
615 OPT_GEN_SEND_LINKS | | |
616 OPT_GEN_ENTER_SENDS | | |
617 OPT_GEN_SAVED_WINDOWS | | |
618 OPT_GEN_REMEMBER_PASS | | |
340
0d9cfc3579a5
[gaim-migrate @ 350]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
619 OPT_GEN_REGISTERED | |
0d9cfc3579a5
[gaim-migrate @ 350]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
620 OPT_GEN_NEAR_APPLET; |
1 | 621 display_options = |
622 OPT_DISP_SHOW_IDLETIME | | |
623 OPT_DISP_SHOW_TIME | | |
624 OPT_DISP_SHOW_PIXMAPS | | |
453 | 625 OPT_DISP_SHOW_BUDDYTICKER | |
1 | 626 OPT_DISP_SHOW_BUTTON_XPM; |
627 font_options = 0; | |
156 | 628 sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON; |
1 | 629 report_idle = IDLE_GAIM; |
630 web_browser = BROWSER_NETSCAPE; | |
631 proxy_type = PROXY_NONE; | |
632 | |
633 aim_port = TOC_PORT; | |
634 login_port = AUTH_PORT; | |
635 g_snprintf(aim_host, sizeof(aim_host), "%s", TOC_HOST); | |
636 g_snprintf(login_host, sizeof(login_host), "%s", AUTH_HOST); | |
637 proxy_host[0] = 0; | |
638 proxy_port = 0; | |
639 g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s"); | |
640 blist_pos.width = 0; | |
641 blist_pos.height = 0; | |
642 blist_pos.x = 0; | |
643 blist_pos.y = 0; | |
644 blist_pos.xoff = 0; | |
645 blist_pos.yoff = 0; | |
180 | 646 g_snprintf(latest_ver, BUF_LONG, "%s", VERSION); |
1 | 647 } |
648 | |
649 | |
650 void load_prefs() | |
651 { | |
652 FILE *f; | |
653 char buf[1024]; | |
654 int ver = 0; | |
570 | 655 |
1 | 656 if (getenv("HOME")) { |
657 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
658 if ((f = fopen(buf,"r"))) { | |
659 fgets(buf, sizeof(buf), f); | |
660 sscanf(buf, "# .gaimrc v%d", &ver); | |
15 | 661 if ( (ver <= 1) || (buf[0] != '#')) { |
1 | 662 fclose(f); |
663 set_defaults(); | |
664 save_prefs(); | |
665 load_prefs(); | |
666 return; | |
667 } | |
668 while(!feof(f)) { | |
669 switch(gaimrc_parse_tag(f)) { | |
670 case -1: | |
671 /* Let the loop end, EOF*/ | |
672 break; | |
673 case 0: | |
674 gaimrc_read_users(f); | |
675 break; | |
676 case 1: | |
677 gaimrc_read_options(f); | |
678 break; | |
679 case 2: | |
680 gaimrc_read_away(f); | |
681 break; | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
682 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
683 case 3: |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
684 gaimrc_read_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
685 break; |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
686 #endif |
673 | 687 case 4: |
688 gaimrc_read_pounce(f); | |
689 break; | |
1 | 690 default: |
691 /* NOOP */ | |
692 break; | |
693 } | |
694 } | |
695 fclose(f); | |
696 } | |
697 } | |
698 | |
699 } | |
700 | |
701 void save_prefs() | |
702 { | |
703 FILE *f; | |
704 char buf[BUF_LONG]; | |
705 | |
706 if (getenv("HOME")) { | |
707 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
708 if ((f = fopen(buf,"w"))) { | |
15 | 709 fprintf(f, "# .gaimrc v%d\n", 2); |
1 | 710 gaimrc_write_users(f); |
673 | 711 gaimrc_write_options(f); |
712 gaimrc_write_away(f); | |
142
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
713 #ifdef GAIM_PLUGINS |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
714 gaimrc_write_plugins(f); |
fbabd28795d2
[gaim-migrate @ 152]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
131
diff
changeset
|
715 #endif |
673 | 716 gaimrc_write_pounce(f); |
717 fclose(f); | |
718 chmod(buf, S_IRUSR | S_IWUSR); | |
719 } | |
1 | 720 } |
721 } | |
722 |