0
|
1 #include "../../../context.h"
|
|
2 #interface "GearsDirectory.h"
|
|
3 #interface "Stack.h"
|
|
4 #interface "FTree.h"
|
|
5 #interface "Integer.h"
|
|
6 #impl "GearsDirectory.h" as "GearsDirectoryImpl.h"
|
|
7
|
|
8 // ----
|
|
9 // typedef struct GearsDirectoryImpl <> impl GearsDirectory {
|
|
10 // struct FTree* currentDirectory;
|
|
11 // struct Stack* directoryStack;
|
|
12 // } GearsDirectoryImpl;
|
|
13 // ----
|
|
14
|
|
15 GearsDirectory* createGearsDirectoryImpl(struct Context* context) {
|
|
16 struct GearsDirectory* gearsDirectory = new GearsDirectory();
|
|
17 struct GearsDirectoryImpl* gears_directory_impl = new GearsDirectoryImpl();
|
|
18 gearsDirectory->gearsDirectory = (union Data*)gears_directory_impl;
|
|
19
|
|
20 struct FTree* firstDirectory = createFileSystemTree(context, NULL);
|
|
21 struct FTree* iNodeTree = createFileSystemTree(context, NULL);
|
|
22 gears_directory_impl->currentDirectory = firstDirectory;
|
|
23 gears_directory_impl->iNodeTree = iNodeTree;
|
|
24 gears_directory_impl->directoryStack = createSingleLinkedStack(context);
|
|
25 gears_directory_impl->INodeNumber = 0;
|
|
26 gearsDirectory->mkdir = C_mkdirGearsDirectoryImpl;
|
|
27 gearsDirectory->ls = C_lsGearsDirectoryImpl;
|
|
28 gearsDirectory->cd2Child = C_cd2ChildGearsDirectoryImpl;
|
|
29 gearsDirectory->cd2Parent = C_cd2ParentGearsDirectoryImpl;
|
|
30 return gearsDirectory;
|
|
31 }
|
|
32
|
|
33 __code mkdir(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
|
|
34 struct FTree* newDirectory = createFileSystemTree(context, gearsDirectory->currentDirectory);
|
|
35 Node* inode = new Node();
|
|
36 inode->key = gearsDirectory->INodeNumber;
|
|
37 inode->value = newDirectory;
|
|
38 struct FTree* cDirectory = new FTree();
|
|
39 cDirectory = gearsDirectory->iNodeTree;
|
|
40 goto cDirectory->put(inode, mkdir2);
|
|
41 }
|
|
42
|
|
43 __code mkdir2(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
|
|
44 Node* dir = new Node();
|
|
45 dir->key = name->value;
|
|
46 Integer* iNum = new Integer();
|
|
47 iNum->value = gearsDirectory->INodeNumber;
|
|
48 dir->value = iNum;
|
|
49 gearsDirectory->INodeNumber = gearsDirectory->INodeNumber + 1;
|
|
50 struct FTree* cDirectory = new FTree();
|
|
51 cDirectory = gearsDirectory->currentDirectory;
|
|
52 goto cDirectory->put(dir, next(...));
|
|
53 }
|
|
54
|
|
55 __code ls(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
|
|
56 Node* dir = new Node();
|
|
57 dir->key = name->value;
|
|
58 struct FTree* cDirectory = new FTree();
|
|
59 cDirectory = gearsDirectory->currentDirectory;
|
|
60 goto cDirectory->get(dir, ls2);
|
|
61 }
|
|
62
|
|
63 __code ls2(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
|
|
64 printf("%d\n", node->key);
|
|
65 goto next(...);
|
|
66 }
|
|
67
|
|
68 __code ls2_stub(struct Context* context) {
|
|
69 GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
|
|
70 Integer* name = Gearef(context, FTree)->node;
|
|
71 enum Code next = Gearef(context, GearsDirectory)->next;
|
|
72 goto ls2(context, gearsDirectory, name, next);
|
|
73 }
|
|
74
|
|
75 __code cd2Child(struct GearsDirectoryImpl* gearsDirectory, struct Integer* name, __code next(...)) {
|
|
76 struct FTree* cDirectory = new FTree();
|
|
77 cDirectory = gearsDirectory->currentDirectory;
|
|
78 struct Node* node = new Node();
|
|
79 node->key = name->value;
|
|
80 goto cDirectory->get(node, cd2Child2);
|
|
81 }
|
|
82
|
|
83 __code cd2Child2(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
|
|
84 struct FTree* iNodeTree = new FTree();
|
|
85 iNodeTree = gearsDirectory->iNodeTree;
|
|
86 goto iNodeTree->get(node->value, cd2Child3);
|
|
87 }
|
|
88
|
|
89 __code cd2Child2_stub(struct Context* context) {
|
|
90 GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
|
|
91 enum Code next = Gearef(context, GearsDirectory)->next;
|
|
92 Node* node0 = Gearef(context, FTree)->node;
|
|
93 goto cd2Child2(context, gearsDirectory, node0, next);
|
|
94 }
|
|
95
|
|
96 __code cd2Child3(struct GearsDirectoryImpl* gearsDirectory, struct Node* node, __code next(...)) {
|
|
97 gearsDirectory->currentDirectory = node->value;
|
|
98 goto next(...);
|
|
99 }
|
|
100
|
|
101 __code cd2Child3_stub(struct Context* context) {
|
|
102 GearsDirectoryImpl* gearsDirectory = (GearsDirectoryImpl*)GearImpl(context, GearsDirectory, gearsDirectory);
|
|
103 Integer* name = Gearef(context, FTree)->node;
|
|
104 enum Code next = Gearef(context, GearsDirectory)->next;
|
|
105 goto ls2(context, gearsDirectory, name, next);
|
|
106 }
|
|
107
|
|
108
|
|
109
|
|
110 __code cd2Parent(struct GearsDirectoryImpl* gearsDirectory, __code next(...)) {
|
|
111 gearsDirectory->currentDirectory = gearsDirectory->currentDirectory->treeParent;
|
|
112 goto next(...);
|
|
113 }
|