Thu, 13 Feb 2020 20:57:31 -0600
Move the libidn check to jabber/meson.build as it needs specific functions of the library
| 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 | ||
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40093
diff
changeset
|
50 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40093
diff
changeset
|
51 | ZSetVariable(char *var, char *value) |
| 2086 | 52 | { |
| 53 | int written; | |
| 54 | 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
|
55 | char *varfile, *varfilebackup, varbfr[512]; |
| 2086 | 56 | |
| 57 | written = 0; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
58 | |
|
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
|
59 | if ((varfile = get_localvarfile()) == NULL) |
| 2086 | 60 | return (ZERR_INTERNAL); |
| 61 | ||
|
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
|
62 | varfilebackup = g_strconcat(varfile, ".backup", NULL); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
63 | |
|
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
|
64 | 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
|
65 | 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
|
66 | g_free(varfilebackup); |
| 2086 | 67 | 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
|
68 | } |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
69 | if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 70 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 71 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 72 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 73 | if (varline(varbfr, var)) { | |
| 74 | fprintf(fpout, "%s = %s\n", var, value); | |
| 75 | written = 1; | |
| 76 | } | |
| 77 | else | |
| 78 | fprintf(fpout, "%s\n", varbfr); | |
| 79 | } | |
| 80 | (void) fclose(fpin); /* don't care about errs on input */ | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
81 | } |
| 2086 | 82 | if (!written) |
| 83 | 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
|
84 | 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
|
85 | 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
|
86 | 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
|
87 | 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
|
88 | } |
|
40093
dd7183cf0a71
Use g_rename directly instead of rename.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39832
diff
changeset
|
89 | 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
|
90 | 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
|
91 | g_free(varfile); |
| 2086 | 92 | 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
|
93 | } |
|
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 | 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
|
95 | g_free(varfile); |
| 2086 | 96 | return (ZERR_NONE); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
97 | } |
| 2086 | 98 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40093
diff
changeset
|
99 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40093
diff
changeset
|
100 | ZUnsetVariable(char *var) |
| 2086 | 101 | { |
| 102 | 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
|
103 | char *varfile, *varfilebackup, varbfr[512]; |
| 2086 | 104 | |
|
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
|
105 | if ((varfile = get_localvarfile()) == NULL) |
| 2086 | 106 | return (ZERR_INTERNAL); |
| 107 | ||
|
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
|
108 | varfilebackup = g_strconcat(varfile, ".backup", NULL); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
109 | |
|
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
|
110 | 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
|
111 | 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
|
112 | g_free(varfilebackup); |
| 2086 | 113 | 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
|
114 | } |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
115 | if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 116 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 117 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 118 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 119 | if (!varline(varbfr, var)) | |
| 120 | fprintf(fpout, "%s\n", varbfr); | |
| 121 | } | |
| 122 | (void) fclose(fpin); /* don't care about read close errs */ | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
123 | } |
|
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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | } |
|
40093
dd7183cf0a71
Use g_rename directly instead of rename.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39832
diff
changeset
|
129 | 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
|
130 | 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
|
131 | g_free(varfile); |
| 2086 | 132 | 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
|
133 | } |
|
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 | 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
|
135 | g_free(varfile); |
| 2086 | 136 | return (ZERR_NONE); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
137 | } |
| 2086 | 138 | |
|
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
|
139 | static char *get_localvarfile(void) |
| 2086 | 140 | { |
|
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
|
141 | const char *base; |
| 10867 | 142 | #ifndef WIN32 |
| 2086 | 143 | 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
|
144 | base = purple_home_dir(); |
| 10867 | 145 | #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
|
146 | 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
|
147 | 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
|
148 | base = getenv("HOMEPATH"); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
149 | 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
|
150 | base = "C:\\"; |
| 10867 | 151 | #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
|
152 | if (!base) { |
| 10867 | 153 | #ifndef WIN32 |
| 2086 | 154 | if (!(pwd = getpwuid((int) getuid()))) { |
| 155 | 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
|
156 | return NULL; |
| 2086 | 157 | } |
|
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
|
158 | base = pwd->pw_dir; |
| 10867 | 159 | #endif |
| 2086 | 160 | } |
| 161 | ||
|
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
|
162 | return g_strconcat(base, "/.zephyr.vars", NULL); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
163 | } |
|
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
164 | |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
165 | static const gchar * |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
166 | get_varval(const gchar *fn, const gchar *var) |
| 2086 | 167 | { |
| 168 | FILE *fp; | |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
169 | static gchar varbfr[512]; |
| 2086 | 170 | int i; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
171 | |
|
10592
cd4c3a7d7bdf
[gaim-migrate @ 11998]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
172 | fp = fopen(fn, "r"); |
| 2086 | 173 | if (!fp) |
| 174 | return ((char *)0); | |
| 175 | ||
| 176 | while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { | |
| 177 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 178 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 179 | if (!(i = varline(varbfr, var))) | |
| 180 | continue; | |
| 181 | (void) fclose(fp); /* open read-only, don't care */ | |
| 182 | return (varbfr+i); | |
| 183 | } | |
| 184 | (void) fclose(fp); /* open read-only, don't care */ | |
| 185 | return ((char *)0); | |
| 186 | } | |
| 187 | ||
| 188 | /* If the variable in the line bfr[] is the same as var, return index to | |
| 189 | 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
|
190 | static int |
|
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
191 | varline(const gchar *bfr, const gchar *var) |
| 2086 | 192 | { |
|
39831
c7e0d1617aae
zephyr: Fix const-ness of variable loading.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
193 | register const gchar *cp; |
| 2086 | 194 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
195 | if (!bfr[0] || bfr[0] == '#') { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
196 | /* comment or null line */ |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
197 | return (0); |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
198 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
30617
diff
changeset
|
199 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
200 | cp = bfr; |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
201 | while (*cp && !isspace(*cp) && (*cp != '=')) { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
202 | cp++; |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
203 | } |
| 2086 | 204 | |
|
39828
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35851
diff
changeset
|
205 | 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
|
206 | /* 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
|
207 | return 0; |
|
7372deed606c
zephyr: Use GLib's min/max macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35851
diff
changeset
|
208 | } |
| 2086 | 209 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
210 | cp = strchr(bfr, '='); |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
211 | if (!cp) { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
212 | return (0); |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
213 | } |
| 2086 | 214 | cp++; |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
215 | while (*cp && isspace(*cp)) { |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
216 | /* space up to variable value */ |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
217 | cp++; |
|
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
218 | } |
| 2086 | 219 | |
|
39832
df2dff0f1359
Fix misleading indentation warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39831
diff
changeset
|
220 | return (cp - bfr); /* return index */ |
| 2086 | 221 | } |