Changeset 6ea3890b92add2d38b6907fc33d3ac71ab76db92
- Timestamp:
- 10/17/09 18:08:20 (5 weeks ago)
- Author:
- Karl Ramm <kcr@1ts.org>
- git-author:
- Karl Ramm <kcr@1ts.org> / 2009-10-16T11:21:14Z-0400
- Parents:
- b7ee89b6aff39095119c5766ae324557759a7552
- Children:
- 99cc3dceec1bb97699f4e130556ce22975e39b6f
- git-committer:
- Karl Ramm <kcr@1ts.org> / 2009-10-17T18:08:20Z-0400
- Message:
-
helper function owl_zephyr_dotfile and refactor to use it
There were the ~same four lines of code in many different places,
so I stuck them in a function.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rb7ee89b
|
r6ea3890
|
|
| 19 | 19 | |
| 20 | 20 | #define HM_SVC_FALLBACK htons((unsigned short) 2104) |
| | 21 | |
| | 22 | static char *owl_zephyr_dotfile(const char *name, const char *input) |
| | 23 | { |
| | 24 | if (input != NULL) |
| | 25 | return owl_strdup(input); |
| | 26 | else |
| | 27 | return owl_sprintf("%s/%s", owl_global_get_homedir(&g), name); |
| | 28 | } |
| 21 | 29 | |
| 22 | 30 | #ifdef HAVE_LIBZEPHYR |
| … |
… |
|
| 254 | 262 | |
| 255 | 263 | subs = owl_malloc(sizeof(ZSubscription_t) * subSize); |
| 256 | | if (filename == NULL) |
| 257 | | subsfile = owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); |
| 258 | | else |
| 259 | | subsfile = owl_strdup(filename); |
| | 264 | subsfile = owl_zephyr_dotfile(".zephyr.subs", filename); |
| 260 | 265 | |
| 261 | 266 | if (stat(subsfile, &statbuff) != 0) { |
| … |
… |
|
| 373 | 378 | |
| 374 | 379 | subs = owl_malloc(numSubs * sizeof(ZSubscription_t)); |
| 375 | | |
| 376 | | if (filename==NULL) |
| 377 | | subsfile = owl_sprintf("%s/%s", owl_global_get_homedir(&g), ".anyone"); |
| 378 | | else |
| 379 | | subsfile = owl_strdup(filename); |
| | 380 | subsfile = owl_zephyr_dotfile(".anyone", filename); |
| 380 | 381 | |
| 381 | 382 | if (stat(subsfile, &statbuff) == -1) |
| … |
… |
|
| 957 | 958 | |
| 958 | 959 | line = owl_zephyr_makesubline(class, inst, recip); |
| 959 | | |
| 960 | | if (filename == NULL) |
| 961 | | subsfile = owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); |
| 962 | | else |
| 963 | | subsfile = owl_strdup(filename); |
| | 960 | subsfile = owl_zephyr_dotfile(".zephyr.subs", filename); |
| 964 | 961 | |
| 965 | 962 | /* if the file already exists, check to see if the sub is already there */ |
| … |
… |
|
| 1000 | 997 | line[strlen(line)-1]='\0'; |
| 1001 | 998 | |
| 1002 | | if (!filename) { |
| 1003 | | subsfile=owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); |
| 1004 | | } else { |
| 1005 | | subsfile=owl_strdup(filename); |
| 1006 | | } |
| | 999 | subsfile = owl_zephyr_dotfile(".zephyr.subs", filename); |
| 1007 | 1000 | |
| 1008 | 1001 | linesdeleted = owl_util_file_deleteline(subsfile, line, 1); |
| … |
… |
|
| 1079 | 1072 | FILE *file; |
| 1080 | 1073 | |
| 1081 | | filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); |
| 1082 | | file=fopen(filename, "a"); |
| | 1074 | filename = owl_zephyr_dotfile(".anyone", NULL); |
| | 1075 | file = fopen(filename, "a"); |
| 1083 | 1076 | owl_free(filename); |
| 1084 | 1077 | if (!file) { |
| … |
… |
|
| 1094 | 1087 | char *filename; |
| 1095 | 1088 | |
| 1096 | | filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); |
| | 1089 | filename = owl_zephyr_dotfile(".anyone", NULL); |
| 1097 | 1090 | owl_util_file_deleteline(filename, name, 0); |
| 1098 | 1091 | owl_free(filename); |
| … |
… |
|
| 1278 | 1271 | FILE *f; |
| 1279 | 1272 | |
| 1280 | | if (filename == NULL) |
| 1281 | | ourfile = owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); |
| 1282 | | else |
| 1283 | | ourfile = owl_strdup(filename); |
| | 1273 | ourfile = owl_zephyr_dotfile(".anyone", filename); |
| 1284 | 1274 | |
| 1285 | 1275 | f = fopen(ourfile, "r"); |