Mercurial > pidgin
annotate src/protocols/zephyr/ZVariables.c @ 11016:6417b2f5de4e
[gaim-migrate @ 12885]
Wherever possible, allow users to act on objects and data directly, rather
than through dialogs or explicit commands. For example, it is more intuitive
to drag a circle object around in a diagram rather than selecting a "Move"
command from a menu while the circle is selected. Simlarly, in an email
application, allow the user to attach files by dragging them from the file
manager and dropping them onto the message composition window if they wish.
-- GNOME HIG
This allows direct manipulation of buddy aliases and group names, by moving
the features from dialogs to GtkTreeView's inline editing.
I think this is a great change, but it seems like the type of thing that
might stir up controversy. If so, take it to the mailing list for discussion.
If not, I'll go ahead and perfect this sometime later.
-s.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Tue, 21 Jun 2005 04:40:34 +0000 |
| parents | 5727afad0fb8 |
| children | 64895571248f |
| rev | line source |
|---|---|
| 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 * $Source$ | |
| 10867 | 8 * $Author: thekingant $ |
| 2086 | 9 * |
| 10 * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 11 * For copying and distribution information, see the file | |
| 12 * "mit-copyright.h". | |
| 13 */ | |
| 14 /* $Header$ */ | |
| 15 | |
| 16 #ifndef lint | |
| 17 static char rcsid_ZVariables_c[] = "$Header$"; | |
| 18 #endif | |
| 19 | |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
20 #include "internal.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
4272
diff
changeset
|
21 #include "util.h" |
| 2086 | 22 |
| 23 #include <ctype.h> | |
| 10867 | 24 #ifndef WIN32 |
| 2086 | 25 #include <pwd.h> |
| 10867 | 26 #endif |
| 2086 | 27 |
| 28 static int get_localvarfile __P((char *bfr)); | |
| 29 static char *get_varval __P((char *fn, char *val)); | |
| 30 static int varline __P((char *bfr, char *var)); | |
| 31 | |
| 32 char *ZGetVariable(var) | |
| 33 char *var; | |
| 34 { | |
| 35 char varfile[128], *ret; | |
| 36 | |
| 37 if (get_localvarfile(varfile)) | |
| 38 return ((char *)0); | |
| 39 | |
| 40 if ((ret = get_varval(varfile, var)) != ZERR_NONE) | |
| 41 return (ret); | |
| 42 | |
| 10867 | 43 #ifdef WIN32 |
| 44 sprintf(varfile, "C:\\zephyr\\zephyr.var"); | |
| 45 #else | |
| 2086 | 46 sprintf(varfile, "%s/zephyr.vars", CONFDIR); |
| 10867 | 47 #endif |
| 2086 | 48 return (get_varval(varfile, var)); |
| 49 } | |
| 50 | |
| 51 Code_t ZSetVariable(var, value) | |
| 52 char *var; | |
| 53 char *value; | |
| 54 { | |
| 55 int written; | |
| 56 FILE *fpin, *fpout; | |
| 57 char varfile[128], varfilebackup[128], varbfr[512]; | |
| 58 | |
| 59 written = 0; | |
| 60 | |
| 61 if (get_localvarfile(varfile)) | |
| 62 return (ZERR_INTERNAL); | |
| 63 | |
| 64 (void) strcpy(varfilebackup, varfile); | |
| 65 (void) strcat(varfilebackup, ".backup"); | |
| 66 | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
67 if (!(fpout = fopen(varfilebackup, "w"))) |
| 2086 | 68 return (errno); |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
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 */ | |
| 81 } | |
| 82 if (!written) | |
| 83 fprintf(fpout, "%s = %s\n", var, value); | |
| 84 if (fclose(fpout) == EOF) | |
| 85 return(EIO); /* can't rely on errno */ | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
86 if (rename(varfilebackup, varfile)) |
| 2086 | 87 return (errno); |
| 88 return (ZERR_NONE); | |
| 89 } | |
| 90 | |
| 91 Code_t ZUnsetVariable(var) | |
| 92 char *var; | |
| 93 { | |
| 94 FILE *fpin, *fpout; | |
| 95 char varfile[128], varfilebackup[128], varbfr[512]; | |
| 96 | |
| 97 if (get_localvarfile(varfile)) | |
| 98 return (ZERR_INTERNAL); | |
| 99 | |
| 100 (void) strcpy(varfilebackup, varfile); | |
| 101 (void) strcat(varfilebackup, ".backup"); | |
| 102 | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
103 if (!(fpout = fopen(varfilebackup, "w"))) |
| 2086 | 104 return (errno); |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
105 if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 106 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 107 if (varbfr[strlen(varbfr)-1] < ' ') | |
| 108 varbfr[strlen(varbfr)-1] = '\0'; | |
| 109 if (!varline(varbfr, var)) | |
| 110 fprintf(fpout, "%s\n", varbfr); | |
| 111 } | |
| 112 (void) fclose(fpin); /* don't care about read close errs */ | |
| 113 } | |
| 114 if (fclose(fpout) == EOF) | |
| 115 return(EIO); /* errno isn't reliable */ | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
116 if (rename(varfilebackup, varfile)) |
| 2086 | 117 return (errno); |
| 118 return (ZERR_NONE); | |
| 119 } | |
| 120 | |
| 121 static int get_localvarfile(bfr) | |
| 122 char *bfr; | |
| 123 { | |
| 4272 | 124 const char *envptr; |
| 10867 | 125 #ifndef WIN32 |
| 2086 | 126 struct passwd *pwd; |
| 4272 | 127 envptr = gaim_home_dir(); |
| 10867 | 128 #else |
| 129 envptr = getenv("HOME"); | |
| 130 if (!envptr) | |
| 131 envptr = getenv("HOMEPATH"); | |
| 132 if (!envptr) | |
| 133 envptr = "C:\\"; | |
| 134 #endif | |
| 2086 | 135 if (envptr) |
| 136 (void) strcpy(bfr, envptr); | |
| 137 else { | |
| 10867 | 138 #ifndef WIN32 |
| 2086 | 139 if (!(pwd = getpwuid((int) getuid()))) { |
| 140 fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); | |
| 141 return (1); | |
| 142 } | |
| 143 (void) strcpy(bfr, pwd->pw_dir); | |
| 10867 | 144 #endif |
| 2086 | 145 } |
| 146 | |
| 147 (void) strcat(bfr, "/"); | |
| 148 (void) strcat(bfr, ".zephyr.vars"); | |
| 149 return (0); | |
| 150 } | |
| 151 | |
| 152 static char *get_varval(fn, var) | |
| 153 char *fn; | |
| 154 char *var; | |
| 155 { | |
| 156 FILE *fp; | |
| 157 static char varbfr[512]; | |
| 158 int i; | |
| 159 | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
160 fp = fopen(fn, "r"); |
| 2086 | 161 if (!fp) |
| 162 return ((char *)0); | |
| 163 | |
| 164 while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { | |
| 165 if (varbfr[strlen(varbfr)-1] < ' ') | |
| 166 varbfr[strlen(varbfr)-1] = '\0'; | |
| 167 if (!(i = varline(varbfr, var))) | |
| 168 continue; | |
| 169 (void) fclose(fp); /* open read-only, don't care */ | |
| 170 return (varbfr+i); | |
| 171 } | |
| 172 (void) fclose(fp); /* open read-only, don't care */ | |
| 173 return ((char *)0); | |
| 174 } | |
| 175 | |
| 176 /* If the variable in the line bfr[] is the same as var, return index to | |
| 177 the variable value, else return 0. */ | |
| 178 static int varline(bfr, var) | |
| 179 char *bfr; | |
| 180 char *var; | |
| 181 { | |
| 182 register char *cp; | |
| 183 | |
| 184 | |
| 185 if (!bfr[0] || bfr[0] == '#') /* comment or null line */ | |
| 186 return (0); | |
| 187 | |
| 188 cp = bfr; | |
| 189 while (*cp && !isspace(*cp) && (*cp != '=')) | |
| 190 cp++; | |
| 191 | |
| 10867 | 192 #ifndef WIN32 |
| 2086 | 193 #define max(a,b) ((a > b) ? (a) : (b)) |
| 10867 | 194 #endif |
| 2086 | 195 |
| 196 if (strncasecmp(bfr, var, max(strlen(var),cp - bfr))) | |
| 197 return(0); /* var is not the var in | |
| 198 bfr ==> no match */ | |
| 199 | |
| 200 cp = strchr(bfr, '='); | |
| 201 if (!cp) | |
| 202 return(0); | |
| 203 cp++; | |
| 204 while (*cp && isspace(*cp)) /* space up to variable value */ | |
| 205 cp++; | |
| 206 | |
| 207 return (cp - bfr); /* return index */ | |
| 208 } |
