2 Copyright (C) 2006 by Jonas Kramer
3 Published under the terms of the GNU General Public License (GPL).
15 #include <sys/types.h>
21 struct hash rc
; /* settings read from ~/.shell-fm.rc */
23 int settings(const char * path
, int first
) {
25 FILE * fd
= fopen(path
, "r");
31 memset(& rc
, 0, sizeof(struct hash
));
39 if(!getln(& line
, & size
, fd
))
48 while((ptr
= strchr(ptr
, '#')) != NULL
)
49 if(ptr
== line
|| ptr
[-1] != '\\')
53 unsigned restlen
= strlen(ptr
);
56 memmove(ptr
, ptr
+ 1, restlen
- 1);
57 ptr
[restlen
] = (char) 0;
60 if(strlen(line
) > 1) {
61 char key
[64] = { 0 }, value
[256] = { 0 };
63 if(sscanf(line
, "%63[^= \t] = %255[^\r\n]", key
, value
) == 2)
64 set(& rc
, key
, value
);
66 fprintf(stderr
, "%s, line %d invalid.\n", path
, nline
);
81 mkdir(rcpath(""), 0755);
82 mkdir(rcpath("cache"), 0755);
86 const char * rcpath(const char * file
) {
87 static char path
[4096] = { 0 };
88 memset(path
, 0, sizeof(path
));
90 if(getenv("SHELL_FM_HOME") != NULL
) {
91 snprintf(path
, sizeof(path
), "%s/%s", getenv("SHELL_FM_HOME"), file
);
94 snprintf(path
, sizeof(path
), "%s/.shell-fm/%s", getenv("HOME"), file
);