Skip to content

Commit 0e97bd1

Browse files
committed
Remaining changes in autoconfiscation and
loading of resource files using PKGDATADIR
1 parent d0faafa commit 0e97bd1

File tree

11 files changed

+415
-399
lines changed

11 files changed

+415
-399
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
What's new in version 0.1
2+
-------------------------
3+
4+
* Everything!
5+

Files.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33

44
#include "Prototypes.h"
55

6+
/*{
7+
8+
typedef bool(*Method_Files_fileHandler)(void*, char*);
9+
10+
}*/
11+
612
FILE* Files_open(char* mode, char* picture, char* value) {
713
char fileName[4097];
8-
char* dataDir = DATADIR;
14+
char* dataDir = PKGDATADIR;
915
FILE* fd = Files_openHome(mode, picture, value);
1016
if (fd) return fd;
1117
snprintf(fileName, 4096, "%s/", dataDir);
@@ -34,3 +40,43 @@ void Files_makeHome() {
3440
fileName[4095] = '\0';
3541
mkdir(fileName, 0755);
3642
}
43+
44+
void Files_forEachInDir(char* dirName, Method_Files_fileHandler fileHandler, void* data) {
45+
bool result = false;
46+
FILE* fd;
47+
char homeName[4097];
48+
char* homeDir = getenv("HOME");
49+
snprintf(homeName, 4096, "%s/.dit/", homeDir);
50+
int homeLen = strlen(homeName);
51+
snprintf(homeName + homeLen, 4096 - homeLen, "%s", dirName);
52+
DIR* dir = opendir(homeName);
53+
while (dir) {
54+
struct dirent* entry = readdir(dir);
55+
if (!entry) break;
56+
if (entry->d_name[0] == '.') continue;
57+
snprintf(homeName + homeLen, 4096 - homeLen, "%s/%s", dirName, entry->d_name);
58+
if (fileHandler(data, homeName)) {
59+
if (dir) closedir(dir);
60+
return;
61+
}
62+
}
63+
char dataName[4097];
64+
char* dataDir = PKGDATADIR;
65+
snprintf(dataName, 4096, "%s/", dataDir);
66+
int dataLen = strlen(dataName);
67+
snprintf(dataName + dataLen, 4096 - homeLen, "%s", dirName);
68+
dir = opendir(dataName);
69+
while (dir) {
70+
struct dirent* entry = readdir(dir);
71+
if (!entry) break;
72+
if (entry->d_name[0] == '.') continue;
73+
snprintf(homeName + homeLen, 4096 - homeLen, "%s/%s", dirName, entry->d_name);
74+
if (access(homeName, R_OK) == 0)
75+
continue;
76+
snprintf(dataName + dataLen, 4096 - dataLen, "%s/%s", dirName, entry->d_name);
77+
if (fileHandler(data, dataName)) {
78+
if (dir) closedir(dir);
79+
return;
80+
}
81+
}
82+
}

GenHeaders

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)