return None
-ref_re = re.compile (r'@(ref|ruser|rlearning|rprogram|rglos)\{([^,\\]*?)\}(.)',
- re.DOTALL)
+ref_re = re.compile \
+ ('@(ref|ruser|rlearning|rprogram|rglos)(?:\\{(?P<ref>[^,\\\\\\}]+?)|\
+named\\{(?P<refname>[^,\\\\]+?),(?P<display>[^,\\\\\\}]+?))\\}(?P<last>.)',
+ re.DOTALL)
node_include_re = re.compile (r'(?m)^@(node|include)\s+(.+?)$')
whitespace_re = re.compile (r'\s+')
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
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
fixed = False
stdout.write ('\n')
if type == 'ref':
- stdout.write ("%s: %d: `%s': wrong internal x-ref\n"
+ stdout.write ("\e[1;31m%s: %d: `%s': wrong internal x-ref\e[0m\n"
% (file, line, name))
else:
- stdout.write ("%s: %d: `%s': wrong external `%s' x-ref\n"
+ stdout.write ("\e[1;31m%s: %d: `%s': wrong external `%s' x-ref\e[0m\n"
% (file, line, name, type))
# print context
stdout.write ('--\n' + manuals[manual]['contents'][file]
if name in manuals[k]['nodes']:
if k == manual:
found = ['ref']
- stdout.write (" found as internal x-ref\n")
+ stdout.write ("\e[1;32m found as internal x-ref\e[0m\n")
break
else:
found.append (k)
- stdout.write (" found as `%s' x-ref\n" % k)
+ stdout.write ("\e[1;32m found as `%s' x-ref\e[0m\n" % k)
if (len (found) == 1
and (options.auto_fix or yes_prompt ("Fix this x-ref?"))):
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 ()
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")
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 ("\e[1;36mDone: %d x-refs found, %d bad x-refs found, fixed %d.\e[0m\n" %
+ (refs_count, bad_refs_count, fixes_count))