Mercurial > dottes
annotate abcfield.py @ 582:0206ab9fd6ba build-default-239
Switch from txt2tags to using pandoc with Markdown (Pandoc flavour) input.
author | Jim Hague <jim.hague@acm.org> |
---|---|
date | Sat, 29 Oct 2016 21:51:59 +0100 |
parents | 760d0ae5acea |
children | 696c461c8dc0 |
rev | line source |
---|---|
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
2 # |
122
295ba8275ab4
Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents:
110
diff
changeset
|
3 # Extact a text field (title, by default) from a .abc file, and print it out |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
4 # with any ABC accented characters converted to HTML (default) or Latex. |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
5 # Recognise continuation fields and print those too. |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
6 # |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
7 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
8 import optparse |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
9 import sys |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
10 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
11 accentedletters = { |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
12 # Acute accents |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
13 "'A" : ("Á", "\\'{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
14 "'E" : ("É", "\\'{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
15 "'I" : ("Í", "\\'{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
16 "'O" : ("Ó", "\\'{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
17 "'U" : ("Ú", "\\'{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
18 "'Y" : ("Ý", "\\'{Y}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
19 "'a" : ("á", "\\'{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
20 "'e" : ("é", "\\'{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
21 "'i" : ("í", "\\'{i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
22 "'o" : ("ó", "\\'{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
23 "'u" : ("ú", "\\'{u}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
24 "'y" : ("ý", "\\'{y}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
25 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
26 # Grave accents |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
27 "`A" : ("À", "\\`{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
28 "`E" : ("È", "\\`{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
29 "`I" : ("Ì", "\\`{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
30 "`O" : ("Ò", "\\`{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
31 "`U" : ("Ù", "\\`{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
32 "`a" : ("à", "\\`{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
33 "`e" : ("è", "\\`{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
34 "`i" : ("ì", "\\`{i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
35 "`o" : ("ò", "\\`{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
36 "`u" : ("ù", "\\`{u}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
37 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
38 # Umlauts |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
39 "\"A" : ("Ä", "\\\"{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
40 "\"E" : ("Ë", "\\\"{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
41 "\"I" : ("Ï", "\\\"{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
42 "\"O" : ("Ö", "\\\"{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
43 "\"U" : ("Ü", "\\\"{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
44 "\"Y" : ("Ÿ", "\\\"{Y}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
45 "\"a" : ("ä", "\\\"{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
46 "\"e" : ("ë", "\\\"{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
47 "\"i" : ("ï", "\\\"{\i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
48 "\"o" : ("ö", "\\\"{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
49 "\"u" : ("ü", "\\\"{u}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
50 "\"y" : ("ÿ", "\\\"{y}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
51 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
52 # Circumflexes |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
53 "^A" : ("Â", "\\^{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
54 "^E" : ("Ê", "\\^{E}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
55 "^I" : ("Î", "\\^{I}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
56 "^O" : ("Ô", "\\^{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
57 "^U" : ("Û", "\\^{U}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
58 "^a" : ("â", "\\^{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
59 "^e" : ("ê", "\\^{e}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
60 "^i" : ("î", "\\^{\i}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
61 "^o" : ("ô", "\\^{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
62 "^u" : ("û", "\\^{u}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
63 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
64 # Tilde |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
65 "~A" : ("Ã", "\\~{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
66 "~N" : ("Ñ", "\\~{N}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
67 "~O" : ("Õ", "\\~{O}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
68 "~a" : ("ã", "\\~{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
69 "~n" : ("ñ", "\\~{n}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
70 "~o" : ("õ", "\\~{o}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
71 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
72 # Cedilla |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
73 ",C" : ("Ç", "\\c{C}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
74 ",c" : ("ç", "\\c{c}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
75 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
76 # Slash |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
77 "/O" : ("Ø", "\\O"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
78 "/o" : ("ø", "\\o"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
79 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
80 # Ring |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
81 "AA" : ("Å", "\\r{A}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
82 "aa" : ("å", "\\r{a}"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
83 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
84 # Ligatures |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
85 "AE" : ("Æ", "\\AE"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
86 "ae" : ("æ", "\\ae"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
87 "ss" : ("ß", "\\ss"), |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
88 } |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
89 |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
90 def convertField(t, options): |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
91 res = "" |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
92 while True: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
93 p = t.partition('\\') |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
94 res += p[0] |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
95 if p[1] == "": |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
96 break |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
97 abc = p[2][0:2] |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
98 t = p[2][2:] |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
99 if abc in accentedletters: |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
100 if options.html: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
101 res += accentedletters[abc][0] |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
102 else: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
103 res += accentedletters[abc][1] |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
104 else: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
105 res += "\\" + abc |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
106 return res |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
107 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
108 def process(inf, options): |
316
eedf65564226
Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents:
122
diff
changeset
|
109 n = options.index |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
110 found = False |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
111 for line in inf: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
112 line = line.strip() |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
113 if len(line) > 2 and line[1] == ':': |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
114 if found: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
115 if line[0] != '+': |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
116 break |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
117 line = line[2:].strip() |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
118 elif line[0] == options.field: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
119 if n > 1: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
120 n = n - 1 |
326
27f29e8aafea
Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents:
316
diff
changeset
|
121 continue |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
122 else: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
123 line = line[2:].strip() |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
124 if len(options.starts) > 0: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
125 if line.find(options.starts) == 0: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
126 line = line[len(options.starts):].strip() |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
127 else: |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
128 continue |
316
eedf65564226
Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents:
122
diff
changeset
|
129 else: |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
130 continue |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
131 found = True |
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
132 print(convertField(line, options)) |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
133 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
134 parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" |
122
295ba8275ab4
Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents:
110
diff
changeset
|
135 " Extract field data from ABC file.") |
295ba8275ab4
Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents:
110
diff
changeset
|
136 parser.add_option("-f", "--field", dest="field", default="T", |
295ba8275ab4
Make output larger where possible.
Jim Hague <jim.hague@laicatc.com>
parents:
110
diff
changeset
|
137 help="extract the field FIELD", metavar="FIELD") |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
138 parser.add_option("-l", "--latex", dest="latex", |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
139 action="store_true", default=False, |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
140 help="convert special characters for LaTeX") |
316
eedf65564226
Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents:
122
diff
changeset
|
141 parser.add_option("-n", "--index", dest="index", |
eedf65564226
Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents:
122
diff
changeset
|
142 action="store", type="int", default=1, |
eedf65564226
Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents:
122
diff
changeset
|
143 help="report INDEXth value [default: %default]", |
eedf65564226
Add --index parameter to allow selection of nth occurence of field.
Jim Hague <jim.hague@acm.org>
parents:
122
diff
changeset
|
144 metavar="INDEX") |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
145 parser.add_option("-s", "--starts", dest="starts", |
326
27f29e8aafea
Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents:
316
diff
changeset
|
146 action="store", type="string", default="", |
581
760d0ae5acea
Revise abcfield.py to recognise continuation fields.
Jim Hague <jim.hague@acm.org>
parents:
326
diff
changeset
|
147 help="report only if line starts CONTENT and remove CONTENT", |
326
27f29e8aafea
Add --contains flag to abcfield.py.
Jim Hague <jim.hague@acm.org>
parents:
316
diff
changeset
|
148 metavar="CONTENT") |
110
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
149 (options, args) = parser.parse_args() |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
150 |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
151 if len(args) > 0: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
152 for arg in args: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
153 try: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
154 inf = open(arg, "r") |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
155 process(inf, options) |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
156 finally: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
157 inf.close() |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
158 else: |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
159 process(sys.stdin, options) |
a63e39fc3410
Add basic diacritic handling for LaTeX and web.
Jim Hague <jim.hague@acm.org>
parents:
diff
changeset
|
160 sys.exit(0) |