#!/usr/bin/python3 ''' # nsreconfig.py, version 3.0 # (c) 2002-2008,2014,2022 Jan ONDREJ (SAL) # Licensed under GNU GPLv2+. # You can use standard netsaint commands as: # command[...]=... # Also you can use varaibles: # var="$1;..." # Add to variable: # var+string # - this is replaced by: # var="$var,string" or var="string" # Any variable can be user as command: # var param1;param2;... # And repetition operator: # @param1;param2;... cmd1,cmd2,... # - this is replaced by: # cmd1 param1;param2;... # cmd2 param1;param2;... # ... # - paramters can be separated by " ", ",", ";" # Include file: # "): # include file self.include_file(s[1:]) elif '=' in s and self.ereg(r'^[ ]*([a-zA-Z0-9_.]+)=\"?([^"]*)\"?$', s): # variable assignment self.cmdt[self.c[0]] = self.c[1] # image position manipulation elif s.startswith('moveto '): self.pos_x = self.start_x + float(s.split(' ', 2)[1])*self.size_x self.pos_y = self.start_y + float(s.split(' ', 2)[2])*self.size_y elif s=='startx': self.start_x = self.pos_x elif s.startswith('startx '): self.start_x = int(s.split(' ', 1)[1]) elif s=='nextrow': self.pos_y += self.size_y self.pos_x = self.start_x elif s.startswith('nextrow '): self.pos_y += float(s.split(' ', 1)[1])*self.size_y self.pos_x = self.start_x elif s=='empty': self.pos_x += self.size_x elif s.startswith('empty '): self.pos_x += float(s.split(' ', 1)[1])*self.size_x elif s.startswith('hostextinfo ') and s.count(';')<3: ret = self.chk(s+';%d,%d' % (self.pos_x, self.pos_y)) self.pos_x += self.size_x return ret # other elif self.ereg(r"^[ ]*([a-zA-Z0-9_.]+)\+(.*)$", s): if self.c[0] in self.cmdt: self.cmdt[self.c[0]] = self.cmdt[self.c[0]]+","+self.c[1] else: self.cmdt[self.c[0]] = self.c[1] elif s.strip().split(" ", 1)[0] in self.cmdt and \ self.ereg(r"^[ \t]*([a-zA-Z0-9_]+)[ \t]*[( ](.*)\)?$", s, self.cmdt): mcmd = self.cmdt[self.c[0]] margs = self.c[1].split(";") for i in range(1, 10): if len(margs)>=i: mcmd = mcmd.replace("$%d" % i, margs[i-1]) for key, value in self.cmdt.items(): if ("$"+key) in mcmd: mcmd = re.compile(r"\$%s([^a-zA-Z0-9_]|$)" % key ).sub(value+"\\1", mcmd) return mcmd+"\n" elif s.lstrip().startswith("@") and \ self.ereg(r"^@([-a-zA-Z0-9_;.]*) (.*)$", s): # split by " ,;" but not within parentheses ca = re.split(r"[ ,;]\s*(?![^()]*\))", self.c[1]) c0 = self.c[0] ret = [] for value in ca: with_arg = re.compile(r"^([a-z0-9_-]+)\((.+)\)$").match(value) if with_arg: ret.append(self.chk("%s %s;%s" \ % (with_arg.group(1), c0, with_arg.group(2)))) else: ret.append(self.chk("%s %s" % (value, c0))) return ''.join(ret) elif self.ereg(r"^[ ]*[a-zA-Z0-9_.]*\[", s): #print(s) return s+"\n" elif self.ereg(r"^define [a-zA-Z0-9_.]+[ \t]*\{", s): #print(s) return s+"\n" elif s!="": print("# Illegal command: '%s'" % s) return "" reconfigurator(sys.argv[1])