X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=Configuration.py;h=6f08a20b442bb2ab9073adc5e243fdecf5b583a6;hb=e71fe82b3b12b0fe1092e2a26f9ff8887c001ece;hp=e3ee6647950b74d6b7efd58166ecf6f0fcca7889;hpb=8c801b8d27db07d2bc95eb0e7b65e73a31f8a7bf;p=pygdb.git diff --git a/Configuration.py b/Configuration.py index e3ee664..6f08a20 100755 --- a/Configuration.py +++ b/Configuration.py @@ -13,16 +13,24 @@ import StatusWindow class Configuration: def __init__(self): + self.clear() + + + def clear(self): self.breakpoints = [] self.watches = [] self.ints = [] + self.currfile, self.currlineno = None, 0 def load(self, filename): try: + self.clear() + cnt = 0 #Parse all lines - for line in file(filename).readlines(): + f = file(filename, "r") + for line in f.readlines(): cnt += 1 #Get command and tail @@ -35,33 +43,46 @@ class Configuration: self.parseWatch(tail) elif cmd == "int": self.parseInt(tail) + elif cmd == "currpos": + self.parseCurrpos(tail) else: cnt -= 1 print "Unkown command", cmd + f.close() return cnt + except IOError: return None def store(self, filename): + try: + f = file(filename, "w") - f = file(filename, "w") + for b in self.breakpoints: + self.__writeBreak(f, b) - for b in self.breakpoints: - self.__writeBreak(f, b) + for w in self.watches: + self.__writeWatch(f, w) - for w in self.watches: - self.__writeWatch(f, w) + for s in self.ints: + self.__writeInt(f, s) - for s in self.ints: - self.__writeInt(f, s) + if self.isCurrposSet(): + self.__writeCurrpos(f) + + f.close() + return True + + except IOError: + return False def parseBreak(self, tail): tail = tail.strip() - rx = re.compile("^[\w\._\-]+:\d+(\s+if\s+\S+.*)?$") + rx = re.compile("^[\w/\._\-]+:\d+(\s+if\s+\S+.*)?$") if not rx.search(tail): print "Wrong breakpoint format:", tail @@ -94,6 +115,20 @@ class Configuration: def parseWatch(self, tail): self.addWatch(tail) + def parseCurrpos(self, tail): + + tail = tail.strip() + rx = re.compile("^[\w/\._\-]+:\d+$") + + if not rx.search(tail): + print "Wrong current position format:", tail + return + + [file,lineno] = string.split(tail, ":") + lineno = int(lineno) + + self.setCurrpos(file, lineno) + def __writeBreak(self, f, b): if b["cond"] != None: @@ -107,6 +142,9 @@ class Configuration: def __writeWatch(self, f, w): f.write("watch %(expr)s\n" % w) + def __writeCurrpos(self, f): + f.write("currpos %s:%d\n" % (self.currfile, self.currlineno)) + def addBreak(self, file, lineno, cond=None): bp = {"file" : file, "lineno" : lineno, "cond" : cond} @@ -123,6 +161,12 @@ class Configuration: if not w in self.watches: self.watches += [w] + def setCurrpos(self, file, lineno): + self.currfile, self.currlineno = file, lineno + + def isCurrposSet(self): + return self.currfile!=None + def findInt(self, name): for i in self.ints: @@ -134,7 +178,8 @@ class Configuration: def __str__(self): return "breakpoints=" + str(self.breakpoints) + \ ", watches=" + str(self.watches) + \ - ", ints=" + str(self.ints) + ", ints=" + str(self.ints) + \ + ", currpos=" + str((self.currfile, self.currlineno))