Tue, 05 Nov 2019 21:07:41 -0500
Add some NULL checks to silence scan-build.
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZGetVariable, ZSetVariable, and ZUnsetVariable | |
| 3 | * functions. | |
| 4 | * | |
| 5 | * Created by: Robert French | |
| 6 | * | |
| 7 | * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 8 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
9 | * "mit-copyright.h". |
| 2086 | 10 | */ |
| 11 | ||
|
18273
e61c53184c52
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
12 | #include "libpurple/internal.h" |
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
13 | #include "internal.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
4272
diff
changeset
|
14 | #include "util.h" |
| 2086 | 15 | |
| 16 | #include <ctype.h> | |
| 10867 | 17 | #ifndef WIN32 |
| 2086 | 18 | #include <pwd.h> |
| 10867 | 19 | #endif |
| 2086 | 20 | |
|
39829
ce056c64e426
zephyr: Remove support for compilers without __STDC__.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39828
diff
changeset
|
21 | static char *get_localvarfile(void); |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
22 | static const gchar *get_varval(const gchar *fn, const gchar *val); |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
23 | static int varline(const gchar *bfr, const gchar *var); |
| 2086 | 24 | |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
25 | const gchar * |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
26 | ZGetVariable(const gchar *var) |
| 2086 | 27 | { |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
28 | gchar *varfile; |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
29 | const gchar *ret; |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
30 | |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
31 | if ((varfile = get_localvarfile()) == NULL) |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
32 | return ((char *)0); |
| 2086 | 33 | |
|
30617
d79eaf981448
Fix a minor memleak on initialization
Mark Doliner <markdoliner@pidgin.im>
parents:
28001
diff
changeset
|
34 | ret = get_varval(varfile, var); |
|
d79eaf981448
Fix a minor memleak on initialization
Mark Doliner <markdoliner@pidgin.im>
parents:
28001
diff
changeset
|
35 | g_free(varfile); |
|
d79eaf981448
Fix a minor memleak on initialization
Mark Doliner <markdoliner@pidgin.im>
parents:
28001
diff
changeset
|
36 | if (ret != ZERR_NONE) |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
37 | return ret; |
| 2086 | 38 | |
|
35851
53a60c0d3040
cross-win32: tidy remaining macros - SSL_CERTIFICATES_DIR, BUILDDIR, CONFDIR
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34304
diff
changeset
|
39 | #ifdef _WIN32 |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
40 | varfile = g_strdup("C:\\zephyr\\zephyr.var"); |
| 10867 | 41 | #else |
|
35851
53a60c0d3040
cross-win32: tidy remaining macros - SSL_CERTIFICATES_DIR, BUILDDIR, CONFDIR
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34304
diff
changeset
|
42 | varfile = g_build_filename(PURPLE_SYSCONFDIR, "zephyr.vars", NULL); |
| 10867 | 43 | #endif |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
44 | ret = get_varval(varfile, var); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
45 | g_free(varfile); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
46 | |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
47 | return ret; |
| 2086 | 48 | } |
| 49 | ||
| 50 | Code_t ZSetVariable(var, value) | |
| 51 | char *var; | |
| 52 | char *value; | |
| 53 | { | |
| 54 | int written; | |
| 55 | FILE *fpin, *fpout; | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
56 | char *varfile, *varfilebackup, varbfr[512]; |
| 2086 | 57 | |
| 58 | written = 0; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
59 | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
60 | if ((varfile = get_localvarfile()) == NULL) |
| 2086 | 61 | return (ZERR_INTERNAL); |
| 62 | ||
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
63 | varfilebackup = g_strconcat(varfile, ".backup", NULL); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
64 | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
65 | if (!(fpout = fopen(varfilebackup, "w"))) { |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
66 | g_free(varfile); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
67 | g_free(varfilebackup); |
| 2086 | 68 | return (errno); |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
69 | } |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
70 | if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 71 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 72 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 73 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 74 | if (varline(varbfr, var)) { | |
| 75 | fprintf(fpout, "%s = %s\n", var, value); | |
| 76 | written = 1; | |
| 77 | } | |
| 78 | else | |
| 79 | fprintf(fpout, "%s\n", varbfr); | |
| 80 | } | |
| 81 | (void) fclose(fpin); /* don't care about errs on input */ | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
82 | } |
| 2086 | 83 | if (!written) |
| 84 | fprintf(fpout, "%s = %s\n", var, value); | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
85 | if (fclose(fpout) == EOF) { |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
86 | g_free(varfilebackup); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
87 | g_free(varfile); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
88 | return(EIO); /* can't rely on errno */ |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
89 | } |
|
40093
dd7183cf0a71
Use g_rename directly instead of rename.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39832
diff
changeset
|
90 | if (g_rename(varfilebackup, varfile)) { |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
91 | g_free(varfilebackup); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
92 | g_free(varfile); |
| 2086 | 93 | return (errno); |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
94 | } |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
95 | g_free(varfilebackup); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
96 | g_free(varfile); |
| 2086 | 97 | return (ZERR_NONE); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
98 | } |
| 2086 | 99 | |
| 100 | Code_t ZUnsetVariable(var) | |
| 101 | char *var; | |
| 102 | { | |
| 103 | FILE *fpin, *fpout; | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
104 | char *varfile, *varfilebackup, varbfr[512]; |
| 2086 | 105 | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
106 | if ((varfile = get_localvarfile()) == NULL) |
| 2086 | 107 | return (ZERR_INTERNAL); |
| 108 | ||
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
109 | varfilebackup = g_strconcat(varfile, ".backup", NULL); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
110 | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
111 | if (!(fpout = fopen(varfilebackup, "w"))) { |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
112 | g_free(varfile); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
113 | g_free(varfilebackup); |
| 2086 | 114 | return (errno); |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
115 | } |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
116 | if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 117 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 118 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 119 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 120 | if (!varline(varbfr, var)) | |
| 121 | fprintf(fpout, "%s\n", varbfr); | |
| 122 | } | |
| 123 | (void) fclose(fpin); /* don't care about read close errs */ | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
124 | } |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
125 | if (fclose(fpout) == EOF) { |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
126 | g_free(varfilebackup); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
127 | g_free(varfile); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
128 | return(EIO); /* errno isn't reliable */ |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
129 | } |
|
40093
dd7183cf0a71
Use g_rename directly instead of rename.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39832
diff
changeset
|
130 | if (g_rename(varfilebackup, varfile)) { |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
131 | g_free(varfilebackup); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
132 | g_free(varfile); |
| 2086 | 133 | return (errno); |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
134 | } |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
135 | g_free(varfilebackup); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
136 | g_free(varfile); |
| 2086 | 137 | return (ZERR_NONE); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
138 | } |
| 2086 | 139 | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
140 | static char *get_localvarfile(void) |
| 2086 | 141 | { |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
142 | const char *base; |
| 10867 | 143 | #ifndef WIN32 |
| 2086 | 144 | struct passwd *pwd; |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
145 | base = purple_home_dir(); |
| 10867 | 146 | #else |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
147 | base = getenv("HOME"); |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
148 | if (!base) |
|
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
149 | base = getenv("HOMEPATH"); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
150 | if (!base) |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
151 | base = "C:\\"; |
| 10867 | 152 | #endif |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
153 | if (!base) { |
| 10867 | 154 | #ifndef WIN32 |
| 2086 | 155 | if (!(pwd = getpwuid((int) getuid()))) { |
| 156 | fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); | |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
157 | return NULL; |
| 2086 | 158 | } |
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
159 | base = pwd->pw_dir; |
| 10867 | 160 | #endif |
| 2086 | 161 | } |
| 162 | ||
|
28001
c6446d1742d3
Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26726
diff
changeset
|
163 | return g_strconcat(base, "/.zephyr.vars", NULL); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
164 | } |
|
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
165 | |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
166 | static const gchar * |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
167 | get_varval(const gchar *fn, const gchar *var) |
| 2086 | 168 | { |
| 169 | FILE *fp; | |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
170 | static gchar varbfr[512]; |
| 2086 | 171 | int i; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
172 | |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
173 | fp = fopen(fn, "r"); |
| 2086 | 174 | if (!fp) |
| 175 | return ((char *)0); | |
| 176 | ||
| 177 | while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { | |
| 178 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 179 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 180 | if (!(i = varline(varbfr, var))) | |
| 181 | continue; | |
| 182 | (void) fclose(fp); /* open read-only, don't care */ | |
| 183 | return (varbfr+i); | |
| 184 | } | |
| 185 | (void) fclose(fp); /* open read-only, don't care */ | |
| 186 | return ((char *)0); | |
| 187 | } | |
| 188 | ||
| 189 | /* If the variable in the line bfr[] is the same as var, return index to | |
| 190 | the variable value, else return 0. */ | |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
191 | static int |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
192 | varline(const gchar *bfr, const gchar *var) |
| 2086 | 193 | { |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
194 | register const gchar *cp; |
| 2086 | 195 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
196 | if (!bfr[0] || bfr[0] == '#') { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
197 | /* comment or null line */ |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
198 | return (0); |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
199 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
200 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
201 | cp = bfr; |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
202 | while (*cp && !isspace(*cp) && (*cp != '=')) { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
203 | cp++; |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
204 | } |
| 2086 | 205 | |
|
39828
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35851
diff
changeset
|
206 | if (g_ascii_strncasecmp(bfr, var, MAX(strlen(var), (gsize)(cp - bfr)))) { |
|
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35851
diff
changeset
|
207 | /* var is not the var in bfr ==> no match */ |
|
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35851
diff
changeset
|
208 | return 0; |
|
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35851
diff
changeset
|
209 | } |
| 2086 | 210 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
211 | cp = strchr(bfr, '='); |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
212 | if (!cp) { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
213 | return (0); |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
214 | } |
| 2086 | 215 | cp++; |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
216 | while (*cp && isspace(*cp)) { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
217 | /* space up to variable value */ |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
218 | cp++; |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
219 | } |
| 2086 | 220 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
221 | return (cp - bfr); /* return index */ |
| 2086 | 222 | } |