forked from Matway/mpl-sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.mpl
executable file
·68 lines (57 loc) · 1.89 KB
/
file.mpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"file" module
"control" includeModule
"String" includeModule
{filename: 0nx; mode: 0nx;} 0nx {convention: cdecl;} "fopen" importFunction
{buffer: 0nx; sizeOfElement: 0nx; count: 0nx; file: 0nx;} 0nx {convention: cdecl;} "fread" importFunction
{buffer: 0nx; sizeOfElement: 0nx; count: 0nx; file: 0nx;} 0nx {convention: cdecl;} "fwrite" importFunction
{file: 0nx;} 0 {convention: cdecl;} "fflush" importFunction
{file: 0nx;} 0 {convention: cdecl;} "fclose" importFunction
{file: 0nx; offset: 0; origin: 0;} 0 {convention: cdecl;} "fseek" importFunction
{file: 0nx;} 0nx {convention: cdecl;} "ftell" importFunction
SEEK_SET: [0i32];
SEEK_CUR: [1i32];
SEEK_END: [2i32];
loadString: [
fileName: toString;
result: {
success: TRUE;
data: String;
};
size: 0nx dynamic;
f: "rb" storageAddress fileName stringMemory fopen;
f 0nx = not [
SEEK_END 0 f fseek 0 =
[f ftell @size set
SEEK_SET 0 f fseek 0 =] &&
[size 0ix cast 0 cast @result.@data.@chars.resize
f size 1nx @result.@data stringMemory fread size =] &&
[0n8 @result.@data.@chars.pushBack TRUE] &&
f fclose 0 = and
] &&
@result.@success set
result
];
saveString: [
stringView: makeStringView;
fileName: toString;
size: stringView textSize;
f: "wb" storageAddress fileName stringMemory fopen;
f 0nx = not
[
size 0nx = [f size 1nx stringView stringMemory fwrite size =] ||
f fflush 0 = and
f fclose 0 = and
] &&
];
appendString: [
stringView: makeStringView;
fileName: toString;
size: stringView textSize;
f: "ab" storageAddress fileName stringMemory fopen;
f 0nx = not
[
size 0nx = [f size 1nx stringView stringMemory fwrite size =] ||
f fflush 0 = and
f fclose 0 = and
] &&
];