-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeomancy_cli.js
More file actions
executable file
·185 lines (160 loc) · 3.86 KB
/
Copy pathgeomancy_cli.js
File metadata and controls
executable file
·185 lines (160 loc) · 3.86 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/node
const geomancy = require("./node");
const fs = require("fs/promises");
const fsc = require("fs");
const cm = require("child_process");
const unzipper = geomancy("unzipper");
const path = require('path');
async function searchInFile(entry, targetWord) {
// Determine the path based on whether entry is a string or a Dirent object
const fullPath = typeof entry === "string"
? entry
: path.join(entry.parentPath, entry.name);
try {
const content = await fs.readFile(fullPath, 'utf8');
const lines = content.split(/\r?\n/);
const returnType = "([A-Za-z_][A-Za-z0-9_]*\\s+)+";
const pointer = "[*]*";
const funcName = "([A-Za-z_][A-Za-z0-9_]*)";
const params = "\\s*\\(([^)]*)\\)\\s*[{;]";
// Combine them using the RegExp constructor
const cFunctionRegex = new RegExp(returnType
+ pointer
+ funcName
+ params
);
let last_function;
lines.forEach((line, index) => {
if(cFunctionRegex.test(line)){
last_function = line;
}
if (line.includes(targetWord)) {
const lineNumber = index + 1;
console.log(`\x1b[36m${fullPath}\x1b[0m `
+ `[\x1b[33mLine ${lineNumber}\x1b[0m]`
+ `: ${line.trim()}`);
}
});
} catch (err) {
console.error(`Could not read ${fullPath}: ${err.message}`);
}
}
async function searchInFiles(dir, targetWord) {
try {
const entries = await fs.readdir(dir, {
recursive: true,
withFileTypes: true
});
for (const entry of entries) {
if (entry.isFile()) {
await searchInFile(entry, targetWord);
}
}
} catch (err) {
console.error('Error scanning directory:', err.message);
}
}
function parse(args){
return args;
}
const rdir = (process.env.HOME || "~/")
+ '/storage/shared/Documents/FlipaClip Documents'
;
const tools = {}
tools.browse = async function(){
const dir = await fs.readdir(rdir);
for(const file of dir){
if(!file.endsWith(".zip"))
continue ;
console.log(file);
}
}
tools.import = async function(target){
async function loadPNG(entry){
}
async function onEntry(entry){
/*if(entry.path.endsWith(".png"))
await loadPNG(entry);*/
const path = `app/res/${target}+${entry.path}`
const buffer = await entry.buffer();
try { await fs.unlink(path); } catch(error){
console.log(error);
}
try { await fs.writeFile(path, buffer); } catch(error){
console.log(error);
}
console.log("Imported");
}
async function onEntry32(entry){
const inp = `app/res/${target}+${entry.path}`
const out = `app/res/${target}32+${entry.path}`
const child = cm.spawn("convert", [
inp, "-resize", "32x32", out
]);
}
fsc.createReadStream(`${rdir}/${target}.zip`)
.pipe(unzipper.Parse())
.on('entry', entry => {
onEntry(entry);
onEntry32(entry);
});
}
tools.memory = async function(target){
for(const name of [
"malloc",
"realloc",
"calloc",
"memcpy",
"free"
]){
await searchInFiles('geo', name);
await searchInFile('geo.c', name);
await searchInFile('geo.h', name);
await searchInFile('geomancy.c', name);
await searchInFile('geomancy.h', name);
}
}
tools.list = async function(){
const dir = await fs.readdir("app/res");
for(const file of dir){
console.log(file);
}
}
tools.todo = async function(){
await geomancy("./todos")(__dirname,
"/index.js",
"/app/index.js",
"/geomancy.c",
"/geomancy.h",
"/geo.c",
"/geo.h",
"/app/",
"/geo/"
);
}
const [ invocation, script, command, ...args ] = parse(process.argv);
const tool = tools[command];
if(command){
if(tool)
tool(...args);
else
console.error("Command Not Found:", command);
} else {
console.log([
"Usage: ./geomancy [command] [...arguments]",
"Commands:",
" browse",
" browse files available for import",
" ",
" todo",
" search and print all todo comments",
" ",
" memory",
" search for memory functions",
" ",
" import filename",
" import a zip with filename (without zip extension)",
" ",
" example: ./geomancy import items",
].join('\n'));
}