49 lines
1.1 KiB
Python
Executable File
49 lines
1.1 KiB
Python
Executable File
#!/usr/bin/python
|
|
import sys
|
|
import math
|
|
|
|
if (len(sys.argv)<2):
|
|
print('''Anduril network file indentation tool:
|
|
give the filename to break...
|
|
|
|
''')
|
|
sys.exit()
|
|
|
|
|
|
f=open(sys.argv[1],'r')
|
|
orig=f.read()
|
|
size=len(orig)
|
|
f.close()
|
|
chrcount=0
|
|
brace=0
|
|
firstofrow=True
|
|
inquotes=False
|
|
space=' '
|
|
|
|
for i in range(size):
|
|
c=orig[i]
|
|
chrcount+=1
|
|
if c=="\t":
|
|
sys.stdout.write(" ")
|
|
else:
|
|
sys.stdout.write(c)
|
|
if c=='"':
|
|
inquotes = not inquotes
|
|
if ( not inquotes ):
|
|
if c=="\n":
|
|
chrcount=0
|
|
brace=0
|
|
firstofrow=True
|
|
if ( c=="(" ) & ( firstofrow ):
|
|
brace=int(min(32,math.ceil((chrcount)/4)*4))
|
|
firstofrow=False
|
|
if ( i+1<size ):
|
|
if ( c=="," ):
|
|
if ( orig[i+1] == " " ):
|
|
spacecount=1
|
|
while ( orig[i+spacecount] == " " ):
|
|
spacecount+=1
|
|
sys.stdout.write('\n' + (1+brace-spacecount)*' ')
|
|
elif ( orig[i+1] != "\n"):
|
|
sys.stdout.write('\n' + (brace)*' ')
|