commit 0d4a5ee

Devine Lu Linvega  ·  2025-01-23 19:20:55 +0000 UTC
parent 45d33de
Fixed issue with stat files in folder
2 files changed,  +23, -7
+6, -0
 1@@ -26,6 +26,11 @@
 2 	#0200 .File/length DEO2
 3 	;mem-nested DUP2 .File/read DEO2
 4 	<pstr>
 5+	( | dir nested bad )
 6+	;dir-nested-bad .File/name DEO2
 7+	#0200 .File/length DEO2
 8+	;mem-nested DUP2 .File/read DEO2
 9+	<pstr>
10 	BRK
11 
12 @<pstr> ( str* -- )
13@@ -38,6 +43,7 @@
14 @file-missing "WHAT.md $1
15 @dir ". $1
16 @dir-nested "src/ $1
17+@dir-nested-bad "src $1
18 
19 @stat-mem "............ $1
20 
+17, -7
 1@@ -9,10 +9,10 @@
 2 
 3 #ifdef _WIN32
 4 #include <direct.h>
 5-#define DIR_SEP_CHAR '\\'
 6+#define DIRCHAR '\\'
 7 #define mkdir(file_name) (_mkdir(file_name) == 0)
 8 #else
 9-#define DIR_SEP_CHAR '/'
10+#define DIRCHAR '/'
11 #define mkdir(file_name) (mkdir(file_name, 0755) == 0)
12 #endif
13 
14@@ -97,6 +97,16 @@ put_statfile(Uint8 *dest, unsigned int len, const char *filepath, const char *ba
15 	return dest - anchor;
16 }
17 
18+static void
19+make_pathfile(char *res, char *path, char *file)
20+{
21+	char c;
22+	while(*path) c = *path++, *res = c, res++;
23+	if(c != DIRCHAR) *res = DIRCHAR, res++;
24+	while(*file) *res = *file++, res++;
25+	*res = 0;
26+}
27+
28 static int
29 put_fdir(Uint8 *dest, int len, const char *filepath, DIR *dir)
30 {
31@@ -108,9 +118,9 @@ put_fdir(Uint8 *dest, int len, const char *filepath, DIR *dir)
32 		if(in_folder)
33 			dest += put_statfile(dest, len, de->d_name, de->d_name);
34 		else {
35-			static char pathname[0x2000];
36-			put_text(put_text(pathname, filepath) + pathname, de->d_name);
37-			dest += put_statfile(dest, len, pathname, de->d_name);
38+			static char res[0x2000];
39+			make_pathfile(res, (char *)filepath, de->d_name);
40+			dest += put_statfile(dest, len, res, de->d_name);
41 		}
42 	}
43 	return dest - _dest;
44@@ -122,7 +132,7 @@ is_dir_path(char *p)
45 	char c;
46 	int saw_slash = 0;
47 	while((c = *p++))
48-		saw_slash = c == DIR_SEP_CHAR;
49+		saw_slash = c == DIRCHAR;
50 	return saw_slash;
51 }
52 
53@@ -139,7 +149,7 @@ file_write_dir(char *p)
54 	int ok = 1;
55 	char c, *s = p;
56 	for(; ok && (c = *p); p++) {
57-		if(c == DIR_SEP_CHAR) {
58+		if(c == DIRCHAR) {
59 			*p = '\0';
60 			ok = is_dir_real(s) || mkdir(s);
61 			*p = c;