Mercurial > pidgin.yaz
annotate libpurple/protocols/zephyr/ZVariables.c @ 31449:1c660ba17ba1
propagate from branch 'im.pidgin.pidgin' (head 6f879669a6513a5c40335bbaefe842389a92b39e)
to branch 'im.pidgin.cpw.qulogic.cairo' (head 4ab0199887f74442673fd46dcbb662bc7f070bc4)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 21 Nov 2010 20:30:12 +0000 |
parents | e59a86a86643 |
children | a8cc50c2279f |
rev | line source |
---|---|
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1 /* This file is part of the Project Athena Zephyr Notification System. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2 * It contains source for the ZGetVariable, ZSetVariable, and ZUnsetVariable |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3 * functions. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
5 * Created by: Robert French |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
6 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
7 * Copyright (c) 1987 by the Massachusetts Institute of Technology. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
8 * For copying and distribution information, see the file |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
9 * "mit-copyright.h". |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
10 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
11 |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
15823
diff
changeset
|
12 #include "libpurple/internal.h" |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
13 #include "internal.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
14 #include "util.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
15 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
16 #include <ctype.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
17 #ifndef WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
18 #include <pwd.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
19 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
20 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
21 static char *get_localvarfile __P((void)); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
22 static char *get_varval __P((char *fn, char *val)); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
23 static int varline __P((char *bfr, char *var)); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
24 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
25 char *ZGetVariable(var) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
26 char *var; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
27 { |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
28 char *varfile, *ret; |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
29 |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
30 if ((varfile = get_localvarfile()) == NULL) |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
31 return ((char *)0); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
32 |
30780
e59a86a86643
Fix a minor memleak on initialization
Mark Doliner <mark@kingant.net>
parents:
28067
diff
changeset
|
33 ret = get_varval(varfile, var); |
e59a86a86643
Fix a minor memleak on initialization
Mark Doliner <mark@kingant.net>
parents:
28067
diff
changeset
|
34 g_free(varfile); |
e59a86a86643
Fix a minor memleak on initialization
Mark Doliner <mark@kingant.net>
parents:
28067
diff
changeset
|
35 if (ret != ZERR_NONE) |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
36 return ret; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
37 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
38 #ifdef WIN32 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
39 varfile = g_strdup("C:\\zephyr\\zephyr.var"); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 #else |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
41 varfile = g_strdup_printf("%s/zephyr.vars", CONFDIR); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 #endif |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
43 ret = get_varval(varfile, var); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
44 g_free(varfile); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
45 |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
46 return ret; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
47 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
48 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
49 Code_t ZSetVariable(var, value) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
50 char *var; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
51 char *value; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
52 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
53 int written; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 FILE *fpin, *fpout; |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
55 char *varfile, *varfilebackup, varbfr[512]; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 written = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
59 if ((varfile = get_localvarfile()) == NULL) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
60 return (ZERR_INTERNAL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
61 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
62 varfilebackup = g_strconcat(varfile, ".backup", NULL); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
64 if (!(fpout = fopen(varfilebackup, "w"))) { |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
65 g_free(varfile); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
66 g_free(varfilebackup); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
67 return (errno); |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
68 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
69 if ((fpin = fopen(varfile, "r")) != NULL) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
70 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
71 if (varbfr[strlen(varbfr)-1] < ' ') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
72 varbfr[strlen(varbfr)-1] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
73 if (varline(varbfr, var)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
74 fprintf(fpout, "%s = %s\n", var, value); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
75 written = 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
76 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
77 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
78 fprintf(fpout, "%s\n", varbfr); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
79 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
80 (void) fclose(fpin); /* don't care about errs on input */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
81 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
82 if (!written) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
83 fprintf(fpout, "%s = %s\n", var, value); |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
84 if (fclose(fpout) == EOF) { |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
85 g_free(varfilebackup); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
86 g_free(varfile); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
87 return(EIO); /* can't rely on errno */ |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
88 } |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
89 if (rename(varfilebackup, varfile)) { |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
90 g_free(varfilebackup); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
91 g_free(varfile); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
92 return (errno); |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
93 } |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
94 g_free(varfilebackup); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
95 g_free(varfile); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
96 return (ZERR_NONE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
97 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
98 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
99 Code_t ZUnsetVariable(var) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
100 char *var; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
101 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
102 FILE *fpin, *fpout; |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
103 char *varfile, *varfilebackup, varbfr[512]; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
104 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
105 if ((varfile = get_localvarfile()) == NULL) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
106 return (ZERR_INTERNAL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
107 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
108 varfilebackup = g_strconcat(varfile, ".backup", NULL); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
109 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
110 if (!(fpout = fopen(varfilebackup, "w"))) { |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
111 g_free(varfile); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
112 g_free(varfilebackup); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
113 return (errno); |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
114 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
115 if ((fpin = fopen(varfile, "r")) != NULL) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
116 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
117 if (varbfr[strlen(varbfr)-1] < ' ') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
118 varbfr[strlen(varbfr)-1] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
119 if (!varline(varbfr, var)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
120 fprintf(fpout, "%s\n", varbfr); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
122 (void) fclose(fpin); /* don't care about read close errs */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
123 } |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
124 if (fclose(fpout) == EOF) { |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
125 g_free(varfilebackup); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
126 g_free(varfile); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
127 return(EIO); /* errno isn't reliable */ |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
128 } |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
129 if (rename(varfilebackup, varfile)) { |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
130 g_free(varfilebackup); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
131 g_free(varfile); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
132 return (errno); |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
133 } |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
134 g_free(varfilebackup); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
135 g_free(varfile); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
136 return (ZERR_NONE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
137 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
138 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
139 static char *get_localvarfile(void) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
140 { |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
141 const char *base; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
142 #ifndef WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
143 struct passwd *pwd; |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
144 base = purple_home_dir(); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
145 #else |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
146 base = getenv("HOME"); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
147 if (!base) |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
148 base = getenv("HOMEPATH"); |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
149 if (!base) |
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
150 base = "C:\\"; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
151 #endif |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
152 if (!base) { |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
153 #ifndef WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
154 if (!(pwd = getpwuid((int) getuid()))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
155 fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
156 return NULL; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
157 } |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
158 base = pwd->pw_dir; |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
159 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
160 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
161 |
28067
bd1b1353e8fa
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26587
diff
changeset
|
162 return g_strconcat(base, "/.zephyr.vars", NULL); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
163 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
164 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
165 static char *get_varval(fn, var) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
166 char *fn; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
167 char *var; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
168 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
169 FILE *fp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
170 static char varbfr[512]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
171 int i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
172 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
173 fp = fopen(fn, "r"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
174 if (!fp) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
175 return ((char *)0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
176 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
177 while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
178 if (varbfr[strlen(varbfr)-1] < ' ') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
179 varbfr[strlen(varbfr)-1] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
180 if (!(i = varline(varbfr, var))) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
181 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
182 (void) fclose(fp); /* open read-only, don't care */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
183 return (varbfr+i); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
184 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
185 (void) fclose(fp); /* open read-only, don't care */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
186 return ((char *)0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
187 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
188 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
189 /* If the variable in the line bfr[] is the same as var, return index to |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
190 the variable value, else return 0. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
191 static int varline(bfr, var) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
192 char *bfr; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
193 char *var; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
194 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
195 register char *cp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
196 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
197 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
198 if (!bfr[0] || bfr[0] == '#') /* comment or null line */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
199 return (0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
200 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
201 cp = bfr; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
202 while (*cp && !isspace(*cp) && (*cp != '=')) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
203 cp++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
204 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
205 #ifndef WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
206 #define max(a,b) ((a > b) ? (a) : (b)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
207 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
208 |
26587
0c796a1950b7
Updates for GTK+ 3.0. Remove some deprecated functions (someone should
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
18398
diff
changeset
|
209 if (g_ascii_strncasecmp(bfr, var, max(strlen(var), cp - bfr))) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
210 return(0); /* var is not the var in |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
211 bfr ==> no match */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
212 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
213 cp = strchr(bfr, '='); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
214 if (!cp) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
215 return(0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
216 cp++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
217 while (*cp && isspace(*cp)) /* space up to variable value */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
218 cp++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
219 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
220 return (cp - bfr); /* return index */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
221 } |