70 lines
1.3 KiB
Plaintext
70 lines
1.3 KiB
Plaintext
|
#!/usr/local/bin/tlang
|
||
|
func relto(appfile,path)
|
||
|
{
|
||
|
f=fs.parent(getabs(appfile));
|
||
|
while(path.startsWith("../"))
|
||
|
{
|
||
|
path = path.substring(3);
|
||
|
|
||
|
f = fs.parent(f);
|
||
|
}
|
||
|
ret fs.combine(f,path);
|
||
|
}
|
||
|
|
||
|
func getabs(path)
|
||
|
{
|
||
|
d = path.split(":",false);
|
||
|
if(d.length == 2 && d[0].length == 1)
|
||
|
{
|
||
|
if(d[1].startsWith('\\') || d[1].startsWith('/'))
|
||
|
{
|
||
|
ret path;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(path.startsWith('\\') || path.startsWith('/'))
|
||
|
{
|
||
|
ret path;
|
||
|
}else{
|
||
|
ret fs.combine(fs.working,path);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
filesRead = create.array();
|
||
|
func contains(f)
|
||
|
{
|
||
|
each(filesRead)
|
||
|
{
|
||
|
if(item == f) ret true;
|
||
|
}
|
||
|
ret false;
|
||
|
}
|
||
|
__includeStr = "#include ";
|
||
|
func readFile(file)
|
||
|
{
|
||
|
if(contains(file)) ret "";
|
||
|
filesRead.add(file);
|
||
|
f = fs.readalltext(file).replace("\r","").split("\n",false);
|
||
|
myText = "";
|
||
|
each(f)
|
||
|
{
|
||
|
if(item.startsWith(__includeStr))
|
||
|
{
|
||
|
myText += readFile(relto(file,item.substring(__includeStr.length))) + "\n";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
myText += item + "\n";
|
||
|
}
|
||
|
}
|
||
|
ret myText;
|
||
|
}
|
||
|
func main(src,$$args)
|
||
|
{
|
||
|
code=reflection.parse_code(readFile(src));
|
||
|
each(args) code.add(item);
|
||
|
code.run();
|
||
|
}
|