-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathimportcode.src
More file actions
49 lines (38 loc) · 1.41 KB
/
importcode.src
File metadata and controls
49 lines (38 loc) · 1.41 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
if params.len != 1 then exit(program_path+" [/path/to/file.src]")
importStr = "import_"+"code("""
handleFileImports = function(pathSrc)
srcFile = get_shell.host_computer.File(pathSrc)
if not srcFile or srcFile.is_binary then return pathSrc+": Not a source code file"
src = srcFile.get_content
pos = 0
while pos < src.len and src.indexOf(importStr)!=null
pos = src.indexOf(importStr) + importStr.len
if pos >= 2 and src[pos-2:pos]=="//" then continue
importCap = src[pos:].indexOf(""")")
text = src[pos:importCap]
if text.len < 1 then continue
//-- handle relative imports
if text[:2] == "./" then text = parent_path(pathSrc)+text[1:]
//-- handle non-dot relative imports
if text[0] != "/" then text = parent_path(pathSrc)+"/"+text
//-- handle nested imports
if text[-4:]==".src" then
result = handleFileImports(text)
if result then
print result
else
get_shell.build(text, parent_path(text), 1)
text = text[:-4]
end if
end if
src = src[:pos+importStr.len] + text + src[importCap:]
end while
srcFile.set_content(src)
return 0
end function//() <-- shuts up syntax highlighter
origFile = params[0]
if origFile[0] != "/" then origFile=current_path+"/"+origFile
result = handleFileImports(origFile)
if result then exit result
//-- do not build last src actually
//-- get_shell.build(origFile, parent_path(origFile), 0)