X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fcheck_texi_refs.py;h=dff7e334f1ccc45d9e2ab039ef8b222ef8443a48;hb=5c14a087ca6cbd665fd631452b7b1283ba0387c3;hp=4e8f5eedb9267542e3ef3f6d4c368344d9ed9008;hpb=f0281fe544e045d6219e19f6f9ab41921611b680;p=lilypond.git diff --git a/buildscripts/check_texi_refs.py b/buildscripts/check_texi_refs.py index 4e8f5eedb9..dff7e334f1 100755 --- a/buildscripts/check_texi_refs.py +++ b/buildscripts/check_texi_refs.py @@ -143,8 +143,10 @@ else: return None -ref_re = re.compile (r'@(ref|ruser|rlearning|rprogram|rglos)\{([^,\\]*?)\}(.)', - re.DOTALL) +ref_re = re.compile \ + ('@(ref|ruser|rlearning|rprogram|rglos)(?:\\{(?P[^,\\\\\\}]+?)|\ +named\\{(?P[^,\\\\]+?),(?P[^,\\\\\\}]+?))\\}(?P.)', + re.DOTALL) node_include_re = re.compile (r'(?m)^@(node|include)\s+(.+?)$') whitespace_re = re.compile (r'\s+') @@ -327,17 +329,24 @@ in the list)\n") t -= 1 raise InteractionError ("%d retries limit exceeded" % retries) +refs_count = 0 def check_ref (manual, file, m): - global fixes_count, bad_refs_count + global fixes_count, bad_refs_count, refs_count + refs_count += 1 bad_ref = False + fixed = True type = m.group (1) - original_name = m.group (2) + original_name = m.group ('ref') or m.group ('refname') name = whitespace_re.sub (' ', original_name). strip () newline_indices = manuals[manual]['newline_indices'][file] line = which_line (m.start (), newline_indices) - linebroken = '\n' in m.group (2) - next_char = m.group (3) + linebroken = '\n' in original_name + original_display_name = m.group ('display') + next_char = m.group ('last') + if original_display_name: # the xref has an explicit display name + display_linebroken = '\n' in original_display_name + display_name = whitespace_re.sub (' ', original_display_name). strip () commented_out = is_commented_out \ (m.start (), m.end (), manuals[manual]['comments_boundaries'][file]) useful_fix = not outdir in file @@ -352,11 +361,13 @@ not followed by punctuation\n" % (file, line, name)) new_name = name if type != 'ref' and type == manual and not commented_out: - bad_ref = True - stdout.write ("\n%s: %d: `%s': external %s x-ref should be internal\n" - % (file, line, name, type)) - if options.auto_fix or yes_prompt ("Fix this?"): - type = 'ref' + if useful_fix: + fixed = False + bad_ref = True + stdout.write ("\n%s: %d: `%s': external %s x-ref should be internal\n" + % (file, line, name, type)) + if options.auto_fix or yes_prompt ("Fix this?"): + type = 'ref' if type == 'ref': explicit_type = manual @@ -366,10 +377,10 @@ not followed by punctuation\n" % (file, line, name)) fixed = False stdout.write ('\n') if type == 'ref': - stdout.write ("%s: %d: `%s': wrong internal x-ref\n" + stdout.write ("%s: %d: `%s': wrong internal x-ref\n" % (file, line, name)) else: - stdout.write ("%s: %d: `%s': wrong external `%s' x-ref\n" + stdout.write ("%s: %d: `%s': wrong external `%s' x-ref\n" % (file, line, name, type)) # print context stdout.write ('--\n' + manuals[manual]['contents'][file] @@ -384,11 +395,11 @@ not followed by punctuation\n" % (file, line, name)) if name in manuals[k]['nodes']: if k == manual: found = ['ref'] - stdout.write (" found as internal x-ref\n") + stdout.write (" found as internal x-ref\n") break else: found.append (k) - stdout.write (" found as `%s' x-ref\n" % k) + stdout.write (" found as `%s' x-ref\n" % k) if (len (found) == 1 and (options.auto_fix or yes_prompt ("Fix this x-ref?"))): @@ -432,7 +443,7 @@ and x-ref by index number or beginning of name:\n", [''.join ([i[0], ' ', i[1]]) fixed = True if not fixed: - # all previous automatic fixes attempts failed, + # all previous automatic fixing attempts failed, # ask user for substring to look in node names while True: node_list = search_prompt () @@ -461,15 +472,33 @@ node name and manual for this x-ref by index number or beginning of name:\n", \ bad_refs_count += int (bad_ref) if bad_ref and not useful_fix: stdout.write ("*** Warning: this file is automatically generated, \ -please fix the code source manually.\n") +please fix the code source instead of generated documentation.\n") # compute returned string if new_name == name: - return ('@%s{%s}' % (type, original_name)) + next_char + if bad_ref and (options.interactive or options.auto_fix): + # only the type of the ref was fixed + fixes_count += int (fixed) + if original_display_name: + return ('@%snamed{%s,%s}' % (type, original_name, original_display_name)) + next_char + else: + return ('@%s{%s}' % (type, original_name)) + next_char else: - fixes_count += 1 + fixes_count += int (fixed) (ref, n) = preserve_linebreak (new_name, linebroken) - return ('@%s{%s}' % (type, ref)) + next_char + n + if original_display_name: + if bad_ref: + stdout.write ("Current display name is `%s'\n") + display_name = raw_input \ + ("Enter a new display name or press enter to keep the existing name:\n") \ + or display_name + (display_name, n) = preserve_linebreak (display_name, display_linebroken) + else: + display_name = original_display_name + return ('@%snamed{%s,%s}' % (type, ref, display_name)) + \ + next_char + n + else: + return ('@%s{%s}' % (type, ref)) + next_char + n log.write ("Checking cross-references...\n") @@ -488,5 +517,5 @@ except InteractionError, instance: log.write ("Operation refused by user: %s\nExiting.\n" % instance) sys.exit (3) -log.write ("Done, %d bad x-refs found, fixed %d.\n" % - (bad_refs_count, fixes_count)) +log.write ("Done: %d x-refs found, %d bad x-refs found, fixed %d.\n" % + (refs_count, bad_refs_count, fixes_count))