Add %include facility to SCT template files
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import ply.lex as lex
|
import ply.lex as lex
|
||||||
import ply.yacc as yacc
|
import ply.yacc as yacc
|
||||||
|
|
||||||
@@ -1808,6 +1809,11 @@ def load_file(source_file, depth_list):
|
|||||||
#print trial_name
|
#print trial_name
|
||||||
if os.path.isfile(trial_name):
|
if os.path.isfile(trial_name):
|
||||||
SourceFile = os.path.realpath(os.path.abspath(trial_name))
|
SourceFile = os.path.realpath(os.path.abspath(trial_name))
|
||||||
|
if SourceFile in depth_list:
|
||||||
|
PrintPostError('Error: recursive include of: %s' % SourceFile)
|
||||||
|
for idx, name in enumerate(depth_list):
|
||||||
|
PrintPostError(' ' * idx + name)
|
||||||
|
raise Exception('Bad recursive include of "' + SourceFile + '"')
|
||||||
SourceFileList.append(SourceFile)
|
SourceFileList.append(SourceFile)
|
||||||
curr_file = len(SourceFileList) - 1
|
curr_file = len(SourceFileList) - 1
|
||||||
fd = open(SourceFile, 'r')
|
fd = open(SourceFile, 'r')
|
||||||
@@ -1816,6 +1822,11 @@ def load_file(source_file, depth_list):
|
|||||||
for line in fd:
|
for line in fd:
|
||||||
line_no += 1
|
line_no += 1
|
||||||
line = line.rstrip('\n')
|
line = line.rstrip('\n')
|
||||||
|
match = re.match(r'\s*%include\s+', line, flags=re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
new_source = re.sub(r'\s*%include\s+(.*)', r'\1', line, flags=re.IGNORECASE)
|
||||||
|
LocalData += load_file(new_source, depth_list + [SourceFile])
|
||||||
|
continue
|
||||||
LocalData.append(line)
|
LocalData.append(line)
|
||||||
SourceLineList.append((curr_file, line_no))
|
SourceLineList.append((curr_file, line_no))
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user