]> git.donarmstrong.com Git - lilypond.git/commitdiff
(parse_file): Strip \r from lines. Fixes DOS
authorJan Nieuwenhuizen <janneke@gnu.org>
Thu, 8 Apr 2004 12:02:29 +0000 (12:02 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 8 Apr 2004 12:02:29 +0000 (12:02 +0000)
flavour abc files.  Really ignore unknown keys (backportme).

ChangeLog
scripts/abc2ly.py

index 4bcb4ef14bc5baac655b40aa028c744cb8963801..4b7432eff20a9c4ea66baf44887e8737468b1375 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
 2004-04-08  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * scripts/abc2ly.py (parse_file): Strip \r from lines.  Fixes DOS
-       flavour abc files (backportme).
+       flavour abc files.  Really ignore unknown keys (backportme).
 
 2004-04-08  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
index 534c6a8b7fd7d4ca14ad96dd6f86fec31e85a685..881935f44307e2665342038a05eb8858c2d03f80 100644 (file)
 
 #TODO:
 #
+# * lilylib
+# * GNU style messages:  warning:FILE:LINE:
+# * l10n
+# 
 # Convert to new chord styles.
 #
 # UNDEF -> None
@@ -388,8 +392,11 @@ key_lookup = {     # abc to lilypond key mode names
 }
 
 def lily_key (k):
+       orig = "" + k
+       # UGR
        k = string.lower (k)
        key = k[0]
+       #UGH
        k = k[1:]
        if k and k[0] == '#':
                key = key + 'is'
@@ -401,10 +408,13 @@ def lily_key (k):
                return '%s \\major' % key
 
        type = k[0:3]
-       if key_lookup.has_key (type):
-               return ("%s \\%s" % ( key, key_lookup[type]))
-       sys.stderr.write ("Unknown key type `%s' ignored\n" % type)
-       return ""
+       if not key_lookup.has_key (type):
+               #ugh, use lilylib, say WARNING:FILE:LINE:
+               sys.stderr.write ("abc2ly:warning:")
+               sys.stderr.write ("ignoring unknown key: `%s'" % orig)
+               sys.stderr.write ('\n')
+               return 0
+       return ("%s \\%s" % ( key, key_lookup[type]))
 
 def shift_key (note, acc , shift):
         s = semitone_pitch((note, acc))
@@ -632,12 +642,16 @@ def try_parse_header_line (ln, state):
                                        else:
                                                key_info = m.group(1)
                                                clef_info = m.group(2)
-                                       __main__.global_key  = compute_key (key_info)# ugh.
-                                       voices_append ('\\key %s' % lily_key(key_info))
+                                       __main__.global_key  = compute_key (key_info)
+                                       k = lily_key (key_info)
+                                       if k:
+                                               voices_append ('\\key %s' % k)
                                        check_clef(clef_info)
                                else:
-                                       __main__.global_key  = compute_key (a)# ugh.
-                                       voices_append ('\\key %s \\major' % lily_key(a))
+                                       __main__.global_key  = compute_key (a)
+                                       k = lily_key (a)
+                                       if k:
+                                               voices_append ('\\key %s \\major' % k)
                if g == 'N': # Notes
                        header ['footnotes'] = header['footnotes'] +  '\\\\\\\\' + a
                if g == 'O': # Origin
@@ -1205,6 +1219,7 @@ def try_parse_comment (str):
 #write other kinds of appending  if we ever need them.                 
        return str
 
+lineno = 0
 happy_count = 100
 def parse_file (fn):
        f = open (fn)
@@ -1212,6 +1227,7 @@ def parse_file (fn):
        ls = map (lambda x: re.sub ("\r$", '', x), ls)
 
        select_voice('default', '')
+       global lineno
        lineno = 0
        sys.stderr.write ("Line ... ")
        sys.stderr.flush ()