Add %include facility to SCT template files
This commit is contained in:
@ -30,6 +30,7 @@
|
||||
#
|
||||
|
||||
import os
|
||||
import re
|
||||
import ply.lex as lex
|
||||
import ply.yacc as yacc
|
||||
|
||||
@ -1808,6 +1809,11 @@ def load_file(source_file, depth_list):
|
||||
#print trial_name
|
||||
if os.path.isfile(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)
|
||||
curr_file = len(SourceFileList) - 1
|
||||
fd = open(SourceFile, 'r')
|
||||
@ -1816,6 +1822,11 @@ def load_file(source_file, depth_list):
|
||||
for line in fd:
|
||||
line_no += 1
|
||||
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)
|
||||
SourceLineList.append((curr_file, line_no))
|
||||
fd.close()
|
||||
|
Reference in New Issue
Block a user