gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Handle url fields in bib2dox.py (#184) and modify the bibtex file using url fields.
0 2 0
default
2 files changed with 17 insertions and 23 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
1 1
%%%%% Defining LEMON %%%%%
2 2

	
3 3
@misc{lemon,
4 4
  key =          {LEMON},
5 5
  title =        {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and
6 6
                  {O}ptimization in {N}etworks},
7 7
  howpublished = {\url{http://lemon.cs.elte.hu/}},
8 8
  year =         2009
9 9
}
10 10

	
11 11
@misc{egres,
12 12
  key =          {EGRES},
13 13
  title =        {{EGRES} -- {E}gerv{\'a}ry {R}esearch {G}roup on
14 14
                  {C}ombinatorial {O}ptimization},
15
  howpublished = {\url{http://www.cs.elte.hu/egres/}},
16
  year =         2009
15
  url =          {http://www.cs.elte.hu/egres/}
17 16
}
18 17

	
19 18
@misc{coinor,
20 19
  key =          {COIN-OR},
21 20
  title =        {{COIN-OR} -- {C}omputational {I}nfrastructure for
22 21
                  {O}perations {R}esearch},
23
  howpublished = {\url{http://www.coin-or.org/}},
24
  year =         2009
22
  url =          {http://www.coin-or.org/}
25 23
}
26 24

	
27 25

	
28 26
%%%%% Other libraries %%%%%%
29 27

	
30 28
@misc{boost,
31 29
  key =          {Boost},
32 30
  title =        {{B}oost {C++} {L}ibraries},
33
  howpublished = {\url{http://www.boost.org/}},
34
  year =         2009
31
  url =          {http://www.boost.org/}
35 32
}
36 33

	
37 34
@book{bglbook,
38 35
  author =       {Jeremy G. Siek and Lee-Quan Lee and Andrew
39 36
                  Lumsdaine},
40 37
  title =        {The Boost Graph Library: User Guide and Reference
41 38
                  Manual},
42 39
  publisher =    {Addison-Wesley},
43 40
  year =         2002
44 41
}
45 42

	
46 43
@misc{leda,
47 44
  key =          {LEDA},
48 45
  title =        {{LEDA} -- {L}ibrary of {E}fficient {D}ata {T}ypes and
49 46
                  {A}lgorithms},
50
  howpublished = {\url{http://www.algorithmic-solutions.com/}},
51
  year =         2009
47
  url =          {http://www.algorithmic-solutions.com/}
52 48
}
53 49

	
54 50
@book{ledabook,
55 51
  author =       {Kurt Mehlhorn and Stefan N{\"a}her},
56 52
  title =        {{LEDA}: {A} platform for combinatorial and geometric
57 53
                  computing},
58 54
  isbn =         {0-521-56329-1},
59 55
  publisher =    {Cambridge University Press},
60 56
  address =      {New York, NY, USA},
61 57
  year =         1999
62 58
}
63 59

	
64 60

	
65 61
%%%%% Tools that LEMON depends on %%%%%
66 62

	
67 63
@misc{cmake,
68 64
  key =          {CMake},
69 65
  title =        {{CMake} -- {C}ross {P}latform {M}ake},
70
  howpublished = {\url{http://www.cmake.org/}},
71
  year =         2009
66
  url =          {http://www.cmake.org/}
72 67
}
73 68

	
74 69
@misc{doxygen,
75 70
  key =          {Doxygen},
76 71
  title =        {{Doxygen} -- {S}ource code documentation generator
77 72
                  tool},
78
  howpublished = {\url{http://www.doxygen.org/}},
79
  year =         2009
73
  url =          {http://www.doxygen.org/}
80 74
}
81 75

	
82 76

	
83 77
%%%%% LP/MIP libraries %%%%%
84 78

	
85 79
@misc{glpk,
86 80
  key =          {GLPK},
87 81
  title =        {{GLPK} -- {GNU} {L}inear {P}rogramming {K}it},
88
  howpublished = {\url{http://www.gnu.org/software/glpk/}},
89
  year =         2009
82
  url =          {http://www.gnu.org/software/glpk/}
90 83
}
91 84

	
92 85
@misc{clp,
93 86
  key =          {Clp},
94 87
  title =        {{Clp} -- {Coin-Or} {L}inear {P}rogramming},
95
  howpublished = {\url{http://projects.coin-or.org/Clp/}},
96
  year =         2009
88
  url =          {http://projects.coin-or.org/Clp/}
97 89
}
98 90

	
99 91
@misc{cbc,
100 92
  key =          {Cbc},
101 93
  title =        {{Cbc} -- {Coin-Or} {B}ranch and {C}ut},
102
  howpublished = {\url{http://projects.coin-or.org/Cbc/}},
103
  year =         2009
94
  url =          {http://projects.coin-or.org/Cbc/}
104 95
}
105 96

	
106 97
@misc{cplex,
107 98
  key =          {CPLEX},
108 99
  title =        {{ILOG} {CPLEX}},
109
  howpublished = {\url{http://www.ilog.com/}},
110
  year =         2009
100
  url =          {http://www.ilog.com/}
111 101
}
112 102

	
113 103
@misc{soplex,
114 104
  key =          {SoPlex},
115 105
  title =        {{SoPlex} -- {T}he {S}equential {O}bject-{O}riented
116 106
                  {S}implex},
117
  howpublished = {\url{http://soplex.zib.de/}},
118
  year =         2009
107
  url =          {http://soplex.zib.de/}
119 108
}
120 109

	
121 110

	
122 111
%%%%% General books %%%%%
123 112

	
124 113
@book{amo93networkflows,
125 114
  author =       {Ravindra K. Ahuja and Thomas L. Magnanti and James
126 115
                  B. Orlin},
127 116
  title =        {Network Flows: Theory, Algorithms, and Applications},
128 117
  publisher =    {Prentice-Hall, Inc.},
129 118
  year =         1993,
130 119
  month =        feb,
131 120
  isbn =         {978-0136175490}
132 121
}
133 122

	
134 123
@book{schrijver03combinatorial,
135 124
  author =       {Alexander Schrijver},
136 125
  title =        {Combinatorial Optimization: Polyhedra and Efficiency},
137 126
  publisher =    {Springer-Verlag},
138 127
  year =         2003,
139 128
  isbn =         {978-3540443896}
140 129
}
141 130

	
142 131
@book{clrs01algorithms,
143 132
  author =       {Thomas H. Cormen and Charles E. Leiserson and Ronald
144 133
                  L. Rivest and Clifford Stein},
145 134
  title =        {Introduction to Algorithms},
146 135
  publisher =    {The MIT Press},
147 136
  year =         2001,
148 137
  edition =      {2nd}
149 138
}
150 139

	
151 140
@book{stroustrup00cpp,
152 141
  author =       {Bjarne Stroustrup},
153 142
  title =        {The C++ Programming Language},
154 143
  edition =      {3rd},
155 144
  publisher =    {Addison-Wesley Professional},
156 145
  isbn =         0201700735,
157 146
  month =        {February},
158 147
  year =         2000
159 148
}
160 149

	
161 150

	
162 151
%%%%% Maximum flow algorithms %%%%%
163 152

	
164 153
@inproceedings{goldberg86newapproach,
165 154
  author =       {Andrew V. Goldberg and Robert E. Tarjan},
166 155
  title =        {A new approach to the maximum flow problem},
167 156
  booktitle =    {STOC '86: Proceedings of the Eighteenth Annual ACM
168 157
                  Symposium on Theory of Computing},
169 158
  year =         1986,
170 159
  publisher =    {ACM Press},
171 160
  address =      {New York, NY},
172 161
  pages =        {136-146}
173 162
}
174 163

	
175 164
@article{dinic70algorithm,
176 165
  author =       {E. A. Dinic},
177 166
  title =        {Algorithm for solution of a problem of maximum flow
178 167
                  in a network with power estimation},
179 168
  journal =      {Soviet Math. Doklady},
180 169
  year =         1970,
181 170
  volume =       11,
182 171
  pages =        {1277-1280}
183 172
}
184 173

	
185 174
@article{goldberg08partial,
186 175
  author =       {Andrew V. Goldberg},
187 176
  title =        {The Partial Augment-Relabel Algorithm for the
188 177
                  Maximum Flow Problem},
189 178
  journal =      {16th Annual European Symposium on Algorithms},
190 179
  year =         2008,
191 180
  pages =        {466-477}
192 181
}
193 182

	
194 183
@article{sleator83dynamic,
195 184
  author =       {Daniel D. Sleator and Robert E. Tarjan},
196 185
  title =        {A data structure for dynamic trees},
197 186
  journal =      {Journal of Computer and System Sciences},
198 187
  year =         1983,
199 188
  volume =       26,
200 189
  number =       3,
201 190
  pages =        {362-391}
202 191
}
203 192

	
204 193

	
205 194
%%%%% Minimum mean cycle algorithms %%%%%
206 195

	
207 196
@article{karp78characterization,
208 197
  author =       {Richard M. Karp},
209 198
  title =        {A characterization of the minimum cycle mean in a
210 199
                  digraph},
211 200
  journal =      {Discrete Math.},
212 201
  year =         1978,
213 202
  volume =       23,
214 203
  pages =        {309-311}
Ignore white space 192 line context
1 1
#!/usr/bin/env /usr/local/Python/bin/python2.1
2 2
"""
3 3
  BibTeX to Doxygen converter
4 4
  Usage: python bib2dox.py bibfile.bib > bibfile.dox
5 5

	
6 6
  This code is the modification of the BibTeX to XML converter
7 7
  by Vidar Bronken Gundersen et al. See the original copyright notices below. 
8 8

	
9 9
  **********************************************************************
10 10

	
11 11
  Decoder for bibliographic data, BibTeX
12 12
  Usage: python bibtex2xml.py bibfile.bib > bibfile.xml
13 13

	
14 14
  v.8
15 15
  (c)2002-06-23 Vidar Bronken Gundersen
16 16
  http://bibtexml.sf.net/
17 17
  Reuse approved as long as this notification is kept.
18 18
  Licence: GPL.
19 19

	
20 20
  Contributions/thanks to:
21 21
  Egon Willighagen, http://sf.net/projects/jreferences/
22 22
  Richard Mahoney (for providing a test case)
23 23

	
24 24
  Editted by Sara Sprenkle to be more robust and handle more bibtex features.
25 25
  (c) 2003-01-15
26 26

	
27 27
  1.  Changed bibtex: tags to bibxml: tags.
28 28
  2.  Use xmlns:bibxml="http://bibtexml.sf.net/"
29 29
  3.  Allow spaces between @type and first {
30 30
  4.  "author" fields with multiple authors split by " and "
31 31
      are put in separate xml "bibxml:author" tags.
32 32
  5.  Option for Titles: words are capitalized
33 33
      only if first letter in title or capitalized inside braces
34 34
  6.  Removes braces from within field values
35 35
  7.  Ignores comments in bibtex file (including @comment{ or % )
36 36
  8.  Replaces some special latex tags, e.g., replaces ~ with ' '
37 37
  9.  Handles bibtex @string abbreviations
38 38
        --> includes bibtex's default abbreviations for months
39 39
        --> does concatenation of abbr # " more " and " more " # abbr
40 40
  10. Handles @type( ... ) or @type{ ... }
41 41
  11. The keywords field is split on , or ; and put into separate xml
42 42
      "bibxml:keywords" tags
43 43
  12. Ignores @preamble
44 44

	
45 45
  Known Limitations
46 46
  1.  Does not transform Latex encoding like math mode and special
47 47
      latex symbols.
48 48
  2.  Does not parse author fields into first and last names.
49 49
      E.g., It does not do anything special to an author whose name is
50 50
      in the form LAST_NAME, FIRST_NAME
51 51
      In "author" tag, will show up as
52 52
      <bibxml:author>LAST_NAME, FIRST_NAME</bibxml:author>
53 53
  3.  Does not handle "crossref" fields other than to print
54 54
      <bibxml:crossref>...</bibxml:crossref>
55 55
  4.  Does not inform user of the input's format errors.  You just won't
56 56
      be able to transform the file later with XSL
57 57

	
58 58
  You will have to manually edit the XML output if you need to handle
59 59
  these (and unknown) limitations.
60 60

	
61 61
"""
62 62

	
63 63
import string, re
64 64

	
65 65
# set of valid name characters
66 66
valid_name_chars = '[\w\-:]'
67 67

	
68 68
#
69 69
# define global regular expression variables
70 70
#
71 71
author_rex = re.compile('\s+and\s+')
72 72
rembraces_rex = re.compile('[{}]')
73
capitalize_rex = re.compile('({\w*})')
73
capitalize_rex = re.compile('({[^}]*})')
74 74

	
75 75
# used by bibtexkeywords(data)
76 76
keywords_rex = re.compile('[,;]')
77 77

	
78 78
# used by concat_line(line)
79 79
concatsplit_rex = re.compile('\s*#\s*')
80 80

	
81 81
# split on {, }, or " in verify_out_of_braces
82 82
delimiter_rex = re.compile('([{}"])',re.I)
83 83

	
84 84
field_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
85 85
data_rex = re.compile('\s*(\w*)\s*=\s*([^,]*),?')
86 86

	
87 87
url_rex = re.compile('\\\url\{([^}]*)\}')
88 88

	
89 89
#
90 90
# styles for html formatting
91 91
#
92 92
divstyle = 'margin-top: -4ex; margin-left: 8em;'
93 93

	
94 94
#
95 95
# return the string parameter without braces
96 96
#
97 97
def transformurls(str):
98 98
    return url_rex.sub(r'<a href="\1">\1</a>', str)
99 99

	
100 100
#
101 101
# return the string parameter without braces
102 102
#
103 103
def removebraces(str):
104 104
    return rembraces_rex.sub('', str)
105 105

	
106 106
#
107 107
# latex-specific replacements
108 108
# (do this after braces were removed)
109 109
#
110 110
def latexreplacements(line):
111 111
    line = string.replace(line, '~', '&nbsp;')
112 112
    line = string.replace(line, '\\\'a', '&aacute;')
113 113
    line = string.replace(line, '\\"a', '&auml;')
114 114
    line = string.replace(line, '\\\'e', '&eacute;')
115 115
    line = string.replace(line, '\\"e', '&euml;')
116 116
    line = string.replace(line, '\\\'i', '&iacute;')
117 117
    line = string.replace(line, '\\"i', '&iuml;')
118 118
    line = string.replace(line, '\\\'o', '&oacute;')
119 119
    line = string.replace(line, '\\"o', '&ouml;')
120 120
    line = string.replace(line, '\\\'u', '&uacute;')
121 121
    line = string.replace(line, '\\"u', '&uuml;')
122 122
    line = string.replace(line, '\\H o', '&otilde;')
123 123
    line = string.replace(line, '\\H u', '&uuml;')   # &utilde; does not exist
124 124
    line = string.replace(line, '\\\'A', '&Aacute;')
125 125
    line = string.replace(line, '\\"A', '&Auml;')
126 126
    line = string.replace(line, '\\\'E', '&Eacute;')
127 127
    line = string.replace(line, '\\"E', '&Euml;')
128 128
    line = string.replace(line, '\\\'I', '&Iacute;')
129 129
    line = string.replace(line, '\\"I', '&Iuml;')
130 130
    line = string.replace(line, '\\\'O', '&Oacute;')
131 131
    line = string.replace(line, '\\"O', '&Ouml;')
132 132
    line = string.replace(line, '\\\'U', '&Uacute;')
133 133
    line = string.replace(line, '\\"U', '&Uuml;')
134 134
    line = string.replace(line, '\\H O', '&Otilde;')
135 135
    line = string.replace(line, '\\H U', '&Uuml;')   # &Utilde; does not exist
136 136

	
137 137
    return line
138 138

	
139 139
#
140 140
# copy characters form a string decoding html expressions (&xyz;)
141 141
#
142 142
def copychars(str, ifrom, count):
143 143
    result = ''
144 144
    i = ifrom
145 145
    c = 0
146 146
    html_spec = False
147 147
    while (i < len(str)) and (c < count):
148 148
        if str[i] == '&':
149 149
            html_spec = True;
150 150
            if i+1 < len(str):
151 151
                result += str[i+1]
152 152
            c += 1
153 153
            i += 2
154 154
        else:
155 155
            if not html_spec:
156 156
                if ((str[i] >= 'A') and (str[i] <= 'Z')) or \
157 157
                   ((str[i] >= 'a') and (str[i] <= 'z')):
158 158
                    result += str[i]
159 159
                    c += 1
160 160
            elif str[i] == ';':
161 161
                html_spec = False;
162 162
            i += 1
163 163
    
164 164
    return result
165 165

	
166 166

	
167 167
# 
168 168
# Handle a list of authors (separated by 'and').
169 169
# It gives back an array of the follwing values:
... ...
@@ -270,239 +270,244 @@
270 270
    bracefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
271 271
    bracedata_rex = re.compile('\s*(\w*)\s*=\s*{(.*)},?')
272 272

	
273 273
    quotefield_rex = re.compile('\s*(\w*)\s*=\s*(.*)')
274 274
    quotedata_rex = re.compile('\s*(\w*)\s*=\s*"(.*)",?')
275 275

	
276 276
    for line in filecont_source:
277 277
        line = line[:-1]
278 278

	
279 279
        # encode character entities
280 280
        line = string.replace(line, '&', '&amp;')
281 281
        line = string.replace(line, '<', '&lt;')
282 282
        line = string.replace(line, '>', '&gt;')
283 283

	
284 284
        # start entry: publication type (store for later use)
285 285
        if pubtype_rex.match(line):
286 286
        # want @<alphanumeric chars><spaces>{<spaces><any chars>,
287 287
            entrycont = {}
288 288
            entry = []
289 289
            entrytype = pubtype_rex.sub('\g<1>',line)
290 290
            entrytype = string.lower(entrytype)
291 291
            entryid   = pubtype_rex.sub('\g<2>', line)
292 292

	
293 293
        # end entry if just a }
294 294
        elif endtype_rex.match(line):
295 295
            # generate doxygen code for the entry
296 296

	
297 297
            # enty type related formattings
298 298
            if entrytype in ('book', 'inbook'):
299 299
                entrycont['title'] = '<em>' + entrycont['title'] + '</em>'
300 300
                if not entrycont.has_key('author'):
301 301
                    entrycont['author'] = entrycont['editor']
302 302
                    entrycont['author']['text'] += ', editors'
303 303
            elif entrytype == 'article':
304 304
                entrycont['journal'] = '<em>' + entrycont['journal'] + '</em>'
305 305
            elif entrytype in ('inproceedings', 'incollection', 'conference'):
306 306
                entrycont['booktitle'] = '<em>' + entrycont['booktitle'] + '</em>'
307 307
            elif entrytype == 'techreport':
308 308
                if not entrycont.has_key('type'):
309 309
                    entrycont['type'] = 'Technical report'
310 310
            elif entrytype == 'mastersthesis':
311 311
                entrycont['type'] = 'Master\'s thesis'
312 312
            elif entrytype == 'phdthesis':
313 313
                entrycont['type'] = 'PhD thesis'
314 314

	
315 315
            for eline in entrycont:
316 316
                if eline != '':
317 317
                    eline = latexreplacements(eline)
318 318

	
319 319
            if entrycont.has_key('pages') and (entrycont['pages'] != ''):
320 320
                entrycont['pages'] = string.replace(entrycont['pages'], '--', '-')
321 321

	
322 322
            if entrycont.has_key('author') and (entrycont['author'] != ''):
323 323
                entry.append(entrycont['author']['text'] + '.')
324 324
            if entrycont.has_key('title') and (entrycont['title'] != ''):
325 325
                entry.append(entrycont['title'] + '.')
326 326
            if entrycont.has_key('journal') and (entrycont['journal'] != ''):
327 327
                entry.append(entrycont['journal'] + ',')
328 328
            if entrycont.has_key('booktitle') and (entrycont['booktitle'] != ''):
329 329
                entry.append('In ' + entrycont['booktitle'] + ',')
330 330
            if entrycont.has_key('type') and (entrycont['type'] != ''):
331 331
                eline = entrycont['type']
332 332
                if entrycont.has_key('number') and (entrycont['number'] != ''):
333 333
                    eline += ' ' + entrycont['number']
334 334
                eline += ','
335 335
                entry.append(eline)
336 336
            if entrycont.has_key('institution') and (entrycont['institution'] != ''):
337 337
                entry.append(entrycont['institution'] + ',')
338 338
            if entrycont.has_key('publisher') and (entrycont['publisher'] != ''):
339 339
                entry.append(entrycont['publisher'] + ',')
340 340
            if entrycont.has_key('school') and (entrycont['school'] != ''):
341 341
                entry.append(entrycont['school'] + ',')
342 342
            if entrycont.has_key('address') and (entrycont['address'] != ''):
343 343
                entry.append(entrycont['address'] + ',')
344 344
            if entrycont.has_key('edition') and (entrycont['edition'] != ''):
345 345
                entry.append(entrycont['edition'] + ' edition,')
346 346
            if entrycont.has_key('howpublished') and (entrycont['howpublished'] != ''):
347 347
                entry.append(entrycont['howpublished'] + ',')
348 348
            if entrycont.has_key('volume') and (entrycont['volume'] != ''):
349 349
                eline = entrycont['volume'];
350 350
                if entrycont.has_key('number') and (entrycont['number'] != ''):
351 351
                    eline += '(' + entrycont['number'] + ')'
352 352
                if entrycont.has_key('pages') and (entrycont['pages'] != ''):
353 353
                    eline += ':' + entrycont['pages']
354 354
                eline += ','
355 355
                entry.append(eline)
356 356
            else:
357 357
                if entrycont.has_key('pages') and (entrycont['pages'] != ''):
358 358
                    entry.append('pages ' + entrycont['pages'] + ',')
359 359
            if entrycont.has_key('year') and (entrycont['year'] != ''):
360 360
                if entrycont.has_key('month') and (entrycont['month'] != ''):
361 361
                    entry.append(entrycont['month'] + ' ' + entrycont['year'] + '.')
362 362
                else:
363 363
                    entry.append(entrycont['year'] + '.')
364 364
            if entrycont.has_key('note') and (entrycont['note'] != ''):
365 365
                entry.append(entrycont['note'] + '.')
366
            if entrycont.has_key('url') and (entrycont['url'] != ''):
367
                entry.append(entrycont['url'] + '.')
366 368

	
367 369
            # generate keys for sorting and for the output
368 370
            sortkey = ''
369 371
            bibkey = ''
370 372
            if entrycont.has_key('author'):
371 373
                for author in entrycont['author']['list']:
372 374
                    sortkey += copychars(author, author.rfind(' ')+1, len(author))
373 375
                bibkey = entrycont['author']['abbrev']
374 376
            else:
375 377
                bibkey = 'x'
376 378
            if entrycont.has_key('year'):
377 379
                sortkey += entrycont['year']
378 380
                bibkey += entrycont['year'][-2:]
379 381
            if entrycont.has_key('title'):
380 382
                sortkey += entrycont['title']
381 383
            if entrycont.has_key('key'):
382 384
                sortkey = entrycont['key'] + sortkey
383 385
                bibkey = entrycont['key']
384 386
            entry.insert(0, sortkey)
385 387
            entry.insert(1, bibkey)
386 388
            entry.insert(2, entryid)
387 389
           
388 390
            # add the entry to the file contents
389 391
            filecont.append(entry)
390 392

	
391 393
        else:
392 394
            # field, publication info
393 395
            field = ''
394 396
            data = ''
395 397
            
396 398
            # field = {data} entries
397 399
            if bracedata_rex.match(line):
398 400
                field = bracefield_rex.sub('\g<1>', line)
399 401
                field = string.lower(field)
400 402
                data =  bracedata_rex.sub('\g<2>', line)
401 403

	
402 404
            # field = "data" entries
403 405
            elif quotedata_rex.match(line):
404 406
                field = quotefield_rex.sub('\g<1>', line)
405 407
                field = string.lower(field)
406 408
                data =  quotedata_rex.sub('\g<2>', line)
407 409

	
408 410
            # field = data entries
409 411
            elif data_rex.match(line):
410 412
                field = field_rex.sub('\g<1>', line)
411 413
                field = string.lower(field)
412 414
                data =  data_rex.sub('\g<2>', line)
415

	
416
            if field == 'url':
417
                data = '\\url{' + data.strip() + '}'
413 418
            
414 419
            if field in ('author', 'editor'):
415 420
                entrycont[field] = bibtexauthor(data)
416 421
                line = ''
417 422
            elif field == 'title':
418 423
                line = bibtextitle(data, entrytype)
419 424
            elif field != '':
420 425
                line = removebraces(transformurls(data.strip()))
421 426

	
422 427
            if line != '':
423 428
                line = latexreplacements(line)
424 429
                entrycont[field] = line
425 430

	
426 431

	
427 432
    # sort entries
428 433
    filecont.sort(entry_cmp)
429 434
    
430 435
    # count the bibtex keys
431 436
    keytable = {}
432 437
    counttable = {}
433 438
    for entry in filecont:
434 439
        bibkey = entry[1]
435 440
        if not keytable.has_key(bibkey):
436 441
            keytable[bibkey] = 1
437 442
        else:
438 443
            keytable[bibkey] += 1
439 444

	
440 445
    for bibkey in keytable.keys():
441 446
        counttable[bibkey] = 0
442 447
    
443 448
    # generate output
444 449
    for entry in filecont:
445 450
        # generate output key form the bibtex key
446 451
        bibkey = entry[1]
447 452
        entryid = entry[2]
448 453
        if keytable[bibkey] == 1:
449 454
            outkey = bibkey
450 455
        else:
451 456
            outkey = bibkey + chr(97 + counttable[bibkey])
452 457
        counttable[bibkey] += 1
453 458
        
454 459
        # append the entry code to the output
455 460
        file.append('\\section ' + entryid + ' [' + outkey + ']')
456 461
        file.append('<div style="' + divstyle + '">')
457 462
        for line in entry[3:]:
458 463
            file.append(line)
459 464
        file.append('</div>')
460 465
        file.append('')
461 466

	
462 467
    return file
463 468

	
464 469

	
465 470
#
466 471
# return 1 iff abbr is in line but not inside braces or quotes
467 472
# assumes that abbr appears only once on the line (out of braces and quotes)
468 473
#
469 474
def verify_out_of_braces(line, abbr):
470 475

	
471 476
    phrase_split = delimiter_rex.split(line)
472 477

	
473 478
    abbr_rex = re.compile( '\\b' + abbr + '\\b', re.I)
474 479

	
475 480
    open_brace = 0
476 481
    open_quote = 0
477 482

	
478 483
    for phrase in phrase_split:
479 484
        if phrase == "{":
480 485
            open_brace = open_brace + 1
481 486
        elif phrase == "}":
482 487
            open_brace = open_brace - 1
483 488
        elif phrase == '"':
484 489
            if open_quote == 1:
485 490
                open_quote = 0
486 491
            else:
487 492
                open_quote = 1
488 493
        elif abbr_rex.search(phrase):
489 494
            if open_brace == 0 and open_quote == 0:
490 495
                return 1
491 496

	
492 497
    return 0
493 498

	
494 499

	
495 500
#
496 501
# a line in the form phrase1 # phrase2 # ... # phrasen
497 502
# is returned as phrase1 phrase2 ... phrasen
498 503
# with the correct punctuation
499 504
# Bug: Doesn't always work with multiple abbreviations plugged in
500 505
#
501 506
def concat_line(line):
502 507
    # only look at part after equals
503 508
    field = field_rex.sub('\g<1>',line)
504 509
    rest = field_rex.sub('\g<2>',line)
505 510

	
506 511
    concat_line = field + ' ='
507 512

	
508 513
    pound_split = concatsplit_rex.split(rest)
0 comments (0 inline)