diff options
| author | Nick Mathewson <nickm@torproject.org> | 2003-05-20 19:14:14 +0000 |
|---|---|---|
| committer | Nick Mathewson <nickm@torproject.org> | 2003-05-20 19:14:14 +0000 |
| commit | 8476b829518881789cfaf1b365c747c0696df0c8 (patch) | |
| tree | f01b61cec5b6054de52037e756237331ff4d5b25 | |
| parent | 78e0d3191c446262f000229cd94969f7924e1325 (diff) | |
| download | anonbib-8476b829518881789cfaf1b365c747c0696df0c8.tar.gz | |
Preserve strings while reconciling
svn:r18
| -rw-r--r-- | BibTeX.py | 16 | ||||
| -rw-r--r-- | reconcile.py | 12 |
2 files changed, 24 insertions, 4 deletions
@@ -186,7 +186,7 @@ class BibTeXEntry: best = u return best - def format(self, width=70, indent=8, v=0): + def format(self, width=70, indent=8, v=0, invStrings={}): d = ["@%s{%s,\n" % (self.type, self.key)] if v: df = DISPLAYED_FIELDS[:] @@ -204,7 +204,10 @@ class BibTeXEntry: d.append("%% %s = {?????},\n"%f) continue d.append(" ") - s = "%s = {%s},\n" % (f, v) + if invStrings.has_key(v): + s = "%s = %s," %(f, invStrings[v]) + else: + s = "%s = {%s},\n" % (f, v) d.append(_split(s,width,indent)) d.append("}\n") return "".join(d) @@ -609,6 +612,10 @@ class Parser: def __init__(self, fileiter, initial_strings, result=None): self.strings = config.INITIAL_STRINGS.copy() self.strings.update(initial_strings) + self.newStrings = {} + self.invStrings = {} + for k,v in config.INITIAL_STRINGS.items(): + self.invStrings[v]=k self.fileiter = fileiter self.entries = {} if result is None: @@ -768,6 +775,8 @@ class Parser: if self.curEntType == 'string': self.strings[v[0]] = v[1] + self.newStrings[v[0]] = v[1] + self.invStrings[v[1]] = v[0] elif self.curEntType == 'preamble': pass else: @@ -791,6 +800,9 @@ class Parser: raise ParseError("Unexpected EOF at line %s (%s)" % ( self.fileiter.lineno, self.entryLine)) + self.result.invStrings = self.invStrings + self.result.newStrings = self.newStrings + return self.result def _parse(self): diff --git a/reconcile.py b/reconcile.py index e580b48..23e3963 100644 --- a/reconcile.py +++ b/reconcile.py @@ -208,12 +208,12 @@ def emit(f,ent): for e in errs: print >>f, "%%%%", e - print >>f, ent.format(77, 4, v=1) + print >>f, ent.format(77, 4, v=1, invStrings=invStrings) def emitKnown(f, ent, matches): print >>f, "%% Candidates are:", ", ".join([e.key for g,e in matches]) print >>f, "%%" - print >>f, "%"+(ent.format(77).replace("\n", "\n%")) + print >>f, "%"+(ent.format(77,4,1,invStrings).replace("\n", "\n%")) if len(sys.argv) != 2: print "reconcile.py expects 1 argument" @@ -233,6 +233,14 @@ except BibTex.ParseError, e: sys.exit(1) f = open('tmp.bib', 'w') +keys = input.newStrings.keys() +keys.sort() +for k in keys: + v = input.newStrings[k] + print >>f, "@string{%s = {%s}}"%(k,v) + +invStrings = input.invStrings + for e in input.entries: if not (e.get('title') and e.get('author')): print >>f, "%%\n%%%% Not enough information to search for a match: need title and author.\n%%" |
