Changeset 6ea3890b92add2d38b6907fc33d3ac71ab76db92

Show
Ignore:
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:
1 modified

Legend:

Unmodified
Added
Removed
  • zephyr.c

    rb7ee89b r6ea3890  
    1919 
    2020#define HM_SVC_FALLBACK         htons((unsigned short) 2104) 
     21 
     22static 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} 
    2129 
    2230#ifdef HAVE_LIBZEPHYR 
     
    254262 
    255263  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); 
    260265 
    261266  if (stat(subsfile, &statbuff) != 0) { 
     
    373378 
    374379  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); 
    380381 
    381382  if (stat(subsfile, &statbuff) == -1) 
     
    957958 
    958959  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); 
    964961 
    965962  /* if the file already exists, check to see if the sub is already there */ 
     
    1000997  line[strlen(line)-1]='\0'; 
    1001998 
    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); 
    10071000   
    10081001  linesdeleted = owl_util_file_deleteline(subsfile, line, 1); 
     
    10791072  FILE *file; 
    10801073   
    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"); 
    10831076  owl_free(filename); 
    10841077  if (!file) { 
     
    10941087  char *filename; 
    10951088 
    1096   filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); 
     1089  filename = owl_zephyr_dotfile(".anyone", NULL); 
    10971090  owl_util_file_deleteline(filename, name, 0); 
    10981091  owl_free(filename); 
     
    12781271  FILE *f; 
    12791272 
    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); 
    12841274 
    12851275  f = fopen(ourfile, "r");