comparison mcabber/src/utils.c @ 1167:9726c78a91f3

Allow '~' (HOME directory) in config options
author Mikael Berthe <mikael@lilotux.net>
date Sun, 18 Feb 2007 11:03:49 +0100
parents 648fe6f715a6
children 7b8765c10abb
comparison
equal deleted inserted replaced
1166:c4da23bf8958 1167:9726c78a91f3
43 #include "logprint.h" 43 #include "logprint.h"
44 44
45 static int DebugEnabled; 45 static int DebugEnabled;
46 static char *FName; 46 static char *FName;
47 47
48 // expand_filename(filename)
49 // Expand "~/" with the $HOME env. variable in a file name.
50 // The caller must free the string after use.
51 char *expand_filename(const char *fname)
52 {
53 if (!strncmp(fname, "~/", 2)) {
54 char *homedir = getenv("HOME");
55 if (homedir)
56 return g_strdup_printf("%s%s", homedir, fname+1);
57 }
58 return g_strdup(fname);
59 }
60
48 void ut_InitDebug(int level, const char *filename) 61 void ut_InitDebug(int level, const char *filename)
49 { 62 {
50 FILE *fp; 63 FILE *fp;
51 struct stat buf; 64 struct stat buf;
52 int err; 65 int err;
56 FName = NULL; 69 FName = NULL;
57 return; 70 return;
58 } 71 }
59 72
60 if (filename) 73 if (filename)
61 FName = g_strdup(filename); 74 FName = expand_filename(filename);
62 else { 75 else {
63 FName = getenv("HOME"); 76 FName = getenv("HOME");
64 if (!FName) 77 if (!FName)
65 FName = "/tmp/mcabberlog"; 78 FName = g_strdup("/tmp/mcabberlog");
66 else { 79 else {
67 char *tmpname = g_new(char, strlen(FName) + 12); 80 FName = g_strdup_printf("%s/mcabberlog", FName);
68 strcpy(tmpname, FName);
69 strcat(tmpname, "/mcabberlog");
70 FName = tmpname;
71 } 81 }
72 } 82 }
73 83
74 DebugEnabled = level; 84 DebugEnabled = level;
75 85
410 420
411 // split_arg(arg, n, preservelast) 421 // split_arg(arg, n, preservelast)
412 // Split the string arg into a maximum of n pieces, taking care of 422 // Split the string arg into a maximum of n pieces, taking care of
413 // double quotes. 423 // double quotes.
414 // Return a null-terminated array of strings. This array should be freed 424 // Return a null-terminated array of strings. This array should be freed
415 // be the caller after use, for example with free_arg_lst(). 425 // by the caller after use, for example with free_arg_lst().
416 // If dontstriplast is true, the Nth argument isn't stripped (i.e. no 426 // If dontstriplast is true, the Nth argument isn't stripped (i.e. no
417 // processing of quote chars) 427 // processing of quote chars)
418 char **split_arg(const char *arg, unsigned int n, int dontstriplast) 428 char **split_arg(const char *arg, unsigned int n, int dontstriplast)
419 { 429 {
420 char **arglst; 430 char **arglst;