Save lattice in conf file

This commit is contained in:
Ian Jauslin 2024-02-21 17:10:33 -05:00
parent 37f8d181c2
commit 0070094b94
2 changed files with 50 additions and 1 deletions

48
src/jam
View File

@ -42,7 +42,7 @@ def read_cli():
flag="lattice"
else:
print("error: unrecognized option '"+c+"'\n", file=sys.stderr)
exit()
exit(-1)
else:
@ -61,10 +61,56 @@ def read_cli():
else:
openfile=arg
(ret,message)=filecheck.check_edit(openfile)
preread_conf(openfile)
if ret<0:
print(message,file=sys.stderr)
exit(-1)
# read command line arguments from configuration file
def preread_conf(file):
global lattice
try:
ff=open(file,"r")
except:
print("error: could not read file '"+file+"' (this should not happen and is probably a bug)", file=sys.stderr)
exit(-1)
# counter
i=0
try:
lines=ff.readlines()
except:
print("error: could not read the contents of file '"+file+"'", file=sys.stderr)
exit(-1)
for line in lines:
i+=1
# remove newline
line=line[:len(line)-1]
# ignore comments
if '#' in line:
line=line[:line.find('#')]
# ignore empty lines
if len(line)==0:
continue
# read options
if line[0]=='%':
# ignore empty line
if len(line)==1:
continue
[key,val]=line[1:].split('=',1)
if key=="lattice":
# test the specification
(obj,message)=Lattice.new(val)
if obj==None:
print("error: line "+str(i)+" in file '"+file+"': "+message,file=sys.stderr)
exit(-1)
lattice=val
ff.close()
# read cli
read_cli()

View File

@ -533,6 +533,9 @@ class Painter(Widget):
self.set_color((float(color_str[0]),float(color_str[1]),float(color_str[2])))
except:
print("warning: ignoring line "+str(i)+" in file '"+file+"': color '"+color_str+"' cannot be read",file=sys.stderr)
# lattice is handled by main function
elif key=="lattice":
continue
else:
print("warning: ignoring line "+str(i)+" in file '"+file+"': unrecognized option '"+key+"'",file=sys.stderr)
continue