mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 05:50:32 +05:00
Implement internaltcl functionality
When passing '-internaltcl' to netgen, it will evaluate a preprocessed tcl string instead of loading ng.tcl. The string is stored in the file onetcl.cpp, which is generated by onetcl.py
This commit is contained in:
parent
643ecc2e5e
commit
d45950c5e1
@ -1,4 +1,4 @@
|
|||||||
lappend auto_path $env(NETGENDIR)
|
catch {lappend auto_path $env(NETGENDIR) }
|
||||||
|
|
||||||
set batchmode [Ng_GetCommandLineParameter batchmode]
|
set batchmode [Ng_GetCommandLineParameter batchmode]
|
||||||
if {$batchmode=="undefined"} {
|
if {$batchmode=="undefined"} {
|
||||||
|
5972
ng/onetcl.cpp
5972
ng/onetcl.cpp
File diff suppressed because it is too large
Load Diff
44
ng/onetcl.py
Normal file
44
ng/onetcl.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import glob
|
||||||
|
import functools
|
||||||
|
|
||||||
|
# load all tcl files in current folder
|
||||||
|
tclfiles = {}
|
||||||
|
for fname in glob.glob('*.tcl'):
|
||||||
|
tclfiles[fname] = open(fname,'r').read()
|
||||||
|
|
||||||
|
# do a topological sorting (such that if a.tcl is including b.tcl,
|
||||||
|
# a will come after b in the sorted list)
|
||||||
|
fnames = list(tclfiles.keys())
|
||||||
|
fnames.sort(key=functools.cmp_to_key( lambda x,y: tclfiles[x].find('/'+y) ))
|
||||||
|
|
||||||
|
# replace all occurences of 'source bla.tcl' with the code of bla.tcl
|
||||||
|
for f in fnames:
|
||||||
|
for g in fnames:
|
||||||
|
if(tclfiles[f].find('/'+g) >= 0):
|
||||||
|
tclfiles[f] = tclfiles[f].replace("source ${ngdir}/"+g, tclfiles[g])
|
||||||
|
|
||||||
|
# write a cpp file containing the result of ng.tcl
|
||||||
|
onetclcpp = open("onetcl.cpp",'w')
|
||||||
|
onetclcpp.write('const char * ngscript[] = {""'+'\n');
|
||||||
|
|
||||||
|
# make sure to remove comments (and if lines with comments end with '\' also the next line(s) )
|
||||||
|
skip_next = False # flag to indicate that the next line should be removed
|
||||||
|
for line in tclfiles["ng.tcl"].split('\n'):
|
||||||
|
line = line.strip()
|
||||||
|
if len(line)==0:
|
||||||
|
skip_next = False
|
||||||
|
continue
|
||||||
|
if skip_next:
|
||||||
|
# skip as long as lines end with '\'
|
||||||
|
skip_next = line[-1]=='\\'
|
||||||
|
continue
|
||||||
|
if(line.find('#')>-1):
|
||||||
|
# comment found (not necessarily the whole line)
|
||||||
|
skip_next = line[-1]=='\\'
|
||||||
|
line = line[:line.find('#')]
|
||||||
|
if len(line)>0:
|
||||||
|
s = ',"' + line.replace('\\', r'\\').replace('"', r'\"') + '\\n"\n'
|
||||||
|
onetclcpp.write(s)
|
||||||
|
|
||||||
|
onetclcpp.write('};'+'\n');
|
||||||
|
onetclcpp.close();
|
Loading…
Reference in New Issue
Block a user