From 0070094b94f0514ff2dcb6016611f0b461d64098 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Wed, 21 Feb 2024 17:10:33 -0500 Subject: [PATCH] Save lattice in conf file --- src/jam | 48 +++++++++++++++++++++++++++++++++++++++++++++++- src/painter.py | 3 +++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/jam b/src/jam index 8dc6152..71afc15 100755 --- a/src/jam +++ b/src/jam @@ -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() diff --git a/src/painter.py b/src/painter.py index 034a6dc..94b5b4a 100644 --- a/src/painter.py +++ b/src/painter.py @@ -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