blob: b20642721ca14ede41a96771d28e59f4d22b1b0a (
plain) (
blame)
1
June McEnroe |
2019-07-20 | Handle shotty output options more centrally | June McEnroe |
2019-07-17 | Add ^Q to ptee for MC sequence | June McEnroe |
2019-07-17 | Add Adulthood Rites | June McEnroe |
2019-07-16 | Add catgirl shotty | June McEnroe |
2019-07-16 | Fix SGRs 90 and 100 | June McEnroe |
2019-07-15 | Add up -t | June McEnroe |
2019-07-15 | Implement scrolling region | June McEnroe |
2019-07-14 | Add CSI names to shotty -d | June McEnroe |
2019-07-14 | Ignore CSI t | June McEnroe |
2019-07-14 | Add more info to shotty man page | June McEnroe |
2019-07-14 | Fix OSC PT handling | June McEnroe |
2019-07-14 | Handle OSC in shotty | June McEnroe |
2019-07-14 | Add shotty -d | June McEnroe |
2019-07-13 | Add shotty -c | June McEnroe |
2019-07-13 | Add DL to shotty | June McEnroe |
2019-07-12 | Color html rather than body | June McEnroe |
2019-07-12 | Make author consistent and update URLs | June McEnroe |
2019-07-12 | Move to www/text.causal.agency | June McEnroe |
2019-07-12 | ) {
*dirs = "";
return path;
}
*dirs = getenv(base.envDirs);
if (!*dirs) *dirs = base.defDirs;
const char *home = getenv("HOME");
const char *baseHome = getenv(base.envHome);
if (baseHome) {
snprintf(buf, sizeof(buf), "%s/" SUBDIR "/%s", baseHome, path);
} else if (home) {
snprintf(
buf, sizeof(buf), "%s/%s/" SUBDIR "/%s",
home, base.defHome, path
);
} else {
errx(EX_CONFIG, "HOME unset");
}
return buf;
}
const char *configPath(const char **dirs, const char *path) {
return basePath(Config, dirs, path);
}
const char *dataPath(const char **dirs, const char *path) {
return basePath(Data, dirs, path);
}
FILE *configOpen(const char *path, const char *mode) {
const char *dirs = NULL;
for (const char *abs; NULL != (abs = configPath(&dirs, path));) {
FILE *file = fopen(abs, mode);
if (file) return file;
if (errno != ENOENT) warn("%s", abs);
}
dirs = NULL;
warn("%s", configPath(&dirs, path));
return NULL;
}
void dataMkdir(const char *path) {
const char *dirs = NULL;
path = dataPath(&dirs, path);
int error = mkdir(path, S_IRWXU);
if (error && errno != EEXIST) warn("%s", path);
}
FILE *dataOpen(const char *path, const char *mode) {
const char *dirs = NULL;
for (const char *abs; NULL != (abs = dataPath(&dirs, path));) {
FILE *file = fopen(abs, mode);
if (file) return file;
if (errno != ENOENT) warn("%s", abs);
}
if (mode[0] != 'r') dataMkdir("");
dirs = NULL;
path = dataPath(&dirs, path);
FILE *file = fopen(path, mode);
if (!file) warn("%s", path);
return file;
}
|