src/protocols/zephyr/ZVariables.c

changeset 10867
b39f9b646d6c
parent 10772
783fa6f14695
child 11105
842fa517e08c
equal deleted inserted replaced
10866:40eab743e22b 10867:b39f9b646d6c
3 * functions. 3 * functions.
4 * 4 *
5 * Created by: Robert French 5 * Created by: Robert French
6 * 6 *
7 * $Source$ 7 * $Source$
8 * $Author: nosnilmot $ 8 * $Author: thekingant $
9 * 9 *
10 * Copyright (c) 1987 by the Massachusetts Institute of Technology. 10 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, see the file 11 * For copying and distribution information, see the file
12 * "mit-copyright.h". 12 * "mit-copyright.h".
13 */ 13 */
19 19
20 #include "internal.h" 20 #include "internal.h"
21 #include "util.h" 21 #include "util.h"
22 22
23 #include <ctype.h> 23 #include <ctype.h>
24 #ifndef WIN32
24 #include <pwd.h> 25 #include <pwd.h>
26 #endif
25 27
26 static int get_localvarfile __P((char *bfr)); 28 static int get_localvarfile __P((char *bfr));
27 static char *get_varval __P((char *fn, char *val)); 29 static char *get_varval __P((char *fn, char *val));
28 static int varline __P((char *bfr, char *var)); 30 static int varline __P((char *bfr, char *var));
29 31
36 return ((char *)0); 38 return ((char *)0);
37 39
38 if ((ret = get_varval(varfile, var)) != ZERR_NONE) 40 if ((ret = get_varval(varfile, var)) != ZERR_NONE)
39 return (ret); 41 return (ret);
40 42
43 #ifdef WIN32
44 sprintf(varfile, "C:\\zephyr\\zephyr.var");
45 #else
41 sprintf(varfile, "%s/zephyr.vars", CONFDIR); 46 sprintf(varfile, "%s/zephyr.vars", CONFDIR);
47 #endif
42 return (get_varval(varfile, var)); 48 return (get_varval(varfile, var));
43 } 49 }
44 50
45 Code_t ZSetVariable(var, value) 51 Code_t ZSetVariable(var, value)
46 char *var; 52 char *var;
114 120
115 static int get_localvarfile(bfr) 121 static int get_localvarfile(bfr)
116 char *bfr; 122 char *bfr;
117 { 123 {
118 const char *envptr; 124 const char *envptr;
125 #ifndef WIN32
119 struct passwd *pwd; 126 struct passwd *pwd;
120
121 envptr = gaim_home_dir(); 127 envptr = gaim_home_dir();
128 #else
129 envptr = getenv("HOME");
130 if (!envptr)
131 envptr = getenv("HOMEPATH");
132 if (!envptr)
133 envptr = "C:\\";
134 #endif
122 if (envptr) 135 if (envptr)
123 (void) strcpy(bfr, envptr); 136 (void) strcpy(bfr, envptr);
124 else { 137 else {
138 #ifndef WIN32
125 if (!(pwd = getpwuid((int) getuid()))) { 139 if (!(pwd = getpwuid((int) getuid()))) {
126 fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); 140 fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n");
127 return (1); 141 return (1);
128 } 142 }
129 (void) strcpy(bfr, pwd->pw_dir); 143 (void) strcpy(bfr, pwd->pw_dir);
144 #endif
130 } 145 }
131 146
132 (void) strcat(bfr, "/"); 147 (void) strcat(bfr, "/");
133 (void) strcat(bfr, ".zephyr.vars"); 148 (void) strcat(bfr, ".zephyr.vars");
134 return (0); 149 return (0);
172 187
173 cp = bfr; 188 cp = bfr;
174 while (*cp && !isspace(*cp) && (*cp != '=')) 189 while (*cp && !isspace(*cp) && (*cp != '='))
175 cp++; 190 cp++;
176 191
192 #ifndef WIN32
177 #define max(a,b) ((a > b) ? (a) : (b)) 193 #define max(a,b) ((a > b) ? (a) : (b))
194 #endif
178 195
179 if (strncasecmp(bfr, var, max(strlen(var),cp - bfr))) 196 if (strncasecmp(bfr, var, max(strlen(var),cp - bfr)))
180 return(0); /* var is not the var in 197 return(0); /* var is not the var in
181 bfr ==> no match */ 198 bfr ==> no match */
182 199

mercurial