Skip to content

Commit

Permalink
Excellent stuff.
Browse files Browse the repository at this point in the history
Makefile:
 - After s/autodefs/autorefs/.ent and adding auto{glossary,howtos}.ent,
   I forgot to modify Makefile which broke the build. Fixed.

bin/refs-autogen:
 - Placed sub compress_availability() out of another sub, where it was
   placed mistakenly.
 - Removed some commented code that's not going to be used any more
 - Increased Max. Context Reports from 10 to 20
 - Split the FINAL loop that produces the .xml into 2 passes (avoiding
   any kind of chicken-or-egg problem).
 - SEE ALSO sections work again, they're pure joy to look at !:)
  • Loading branch information
docelic committed Nov 12, 2004
1 parent 7d2cab6 commit d44d6aa
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -114,7 +114,7 @@ $T/%-c.db: %.xml $T

#############################################################
# STANDARD TARGETS || two-pass processing method
$O/%.html: %.xml docbook/autodefs.ent skel
$O/%.html: %.xml docbook/autorefs.ent docbook/autoglossary.ent docbook/autohowtos.ent skel
echo "C $@"
$(PSR) $(PSR_FLAGS) \
$(PROFILE) \
Expand Down
198 changes: 94 additions & 104 deletions bin/refs-autogen
Expand Up @@ -220,8 +220,8 @@ while ( $path = shift @paths) { # For each version specified

# Make sure we don't overdo it with source contexts.
# MV_PAGE appears on like 31 place. We definitely don't need to
# see more than 10.
if ( $ctxshown++ > 10 ) {
# see more than 10; let's say 20.
if ( $ctxshown++ > 20 ) {
print STDERR "$$ag{name} has ", scalar @$ar,
" contexts, limiting to $max_ctxs\n" if $verbose;
goto DONELOOP;
Expand Down Expand Up @@ -313,10 +313,10 @@ ENDD
}
}

### THIS IS LAST RUN ###
### THIS IS LAST RUN (Split in multiple loops to avoid chicken-and-egg problem)###
# Final entry. That's where we add examples
# (which don't have version-specific data, they're always "latest")

# FINAL / PASS 1
for my $group ( keys %autogenerated ) {
while ( my($k,$v) = each %{ $autogenerated{$group} } ) {
my %ag = %$v;
Expand All @@ -335,46 +335,62 @@ while ( my($k,$v) = each %{ $autogenerated{$group} } ) {
# jump out to symbol-specific-subroutine that will handle that.
################################################################

## _See Also_ section: "bidirectional" linking
#if ( defined @{ $ag{'_see also'} } ) {
# my $list = $ag{'_see also'};
# @$list = grep {$autogenerated{$group}{$_} and $_ ne $ag{name}} @$list;
#
# for my $sym ( @$list ) {
# my $list2 = $autogenerated{$group}{$sym}{'_see also'};
# push @$list2, @$list, $k;
# { my %h; @$list2 = grep {!$h{$_}++ and $sym ne $_} @$list2 }
# @{ $autogenerated{$group}{$sym}{'_see also'} } = @$list2;
# }
#}
#
# # Turn 'See Also' items to refentries
# my @see_items = @{ $ag{'_see also'} };
# # XXX only if it's the symbol from same category, otherwise use
# # olink to link between documents
# for my $itm ( @see_items ) {
# next if $itm =~ /^</;
# if ( $autogenerated{$group}{$itm} ) {
# my $linktype = "link"; # the default, linking inside the same document
# my $linkarg = "linkend";
# if ( $autogenerated{$group}{$itm}{'_symbol type'} eq
# $ag{'_symbol type'} ) {
# # Nothing, just use link linkend= if the targets are inside the same
# # document.
# } else {
# # If they're not, find appropriate external document to link to
# for my $sect ( keys %symbol_lists ) {
# if ( grep {/^$itm$/} @{ $symbol_lists{$sect} } ) {
# $linktype = "olink";
# $linkarg = "targetdoc='${sect}s' targetptr";
# }
# }
# }
# # Now that $linktype and $linkarg are set, make the link/citerefentry
# $itm =~ s/^(.+)$/<$linktype $linkarg='$1'><citerefentry><refentrytitle>$1<\/refentrytitle><manvolnum>7ic<\/manvolnum><\/citerefentry><\/$linktype>/;
# }
# }
# $ag{'_see also'} = @see_items;
# _See Also_ section: "bidirectional" linking
# Interesting how I actually had this very good idea in the beginning, then I commented
# it thinking it's crap, and now I'm back to just modifying it a little so it works
# as expected again.
if ( defined @{ $ag{'_see also'} } ) {
my $list = $ag{'_see also'};
my %tmp;

# This loop is now needed since we added the concept of groups in %autogenerated.
for my $gr ( keys %autogenerated ) {
$tmp{$_} = $gr for (grep {$autogenerated{$gr}{$_} and $_ ne $ag{name}} @$list);
}
@$list =keys %tmp;

for my $sym ( @$list ) {
my $list2 = $autogenerated{$tmp{$sym}}{$sym}{'_see also'};
push @$list2, @$list, $k;
{ my %h; @$list2 = grep {!$h{$_}++ and $sym ne $_} @$list2 }
@{ $autogenerated{$tmp{$sym}}{$sym}{'_see also'} } = @$list2;
}
}
}
}
# FINAL / PASS 2
for my $group ( keys %autogenerated ) {
while ( my($k,$v) = each %{ $autogenerated{$group} } ) {
my %ag = %$v;

# Turn 'See Also' items to refentries
goto END_SEEALSO unless $ag{'_see also'};
my @see_items = @{ $ag{'_see also'} };
# XXX only if it's the symbol from same category, otherwise use
# olink to link between documents
for my $itm ( @see_items ) {
next if $itm =~ /^</;
my $linktype = "link";
my $linkarg = "linkend";
if ( $autogenerated{$group}{$itm} ) {
# This means our item and the target it links to are of same type. So,
# nothing, just use default link/linkend=
} else {
# If they're not, find appropriate external document to link to
for my $sect ( keys %symbol_lists ) {
if ( grep {/^$itm$/} @{ $symbol_lists{$sect} } ) {
$linktype = "olink";
$linkarg = "targetdoc='${sect}s' targetptr";
}
}
}
## Now that $linktype and $linkarg are set, make the link/citerefentry
$itm or warn "NO ITM???\n";
$itm =~ s/^(.+)$/<$linktype $linkarg='$1'><citerefentry><refentrytitle>$1<\/refentrytitle><manvolnum>7ic<\/manvolnum><\/citerefentry><\/$linktype>/;
}
$ag{'_see also'} = @see_items;
$ag{'see also'} = join ", ", @see_items;
END_SEEALSO:

# Finally, set default values if they weren't overriden by real information
for my $field (@page_order) {
Expand Down Expand Up @@ -452,41 +468,6 @@ while ( my($k,$v) = each %{ $autogenerated{$group} } ) {
}
}

sub compress_availability {
my @avails = my @orig = @{ (shift) };
@avails or die "compress_availability(): Shouldn't happen";

# XXX this needs work, but at the moment it serves us well
# (it can't handle like x-y, z, a-b. It only handles start-end)

my $start = shift @avails;
my $si; # starting index
my $cl = 0; # compress level
for (my $i=0; $i<@parsed_versions;$i++) {
if ( $parsed_versions[$i] eq $start ) {
$si = $i;
}
}
my $end;
while ( $_ = shift @avails ) {
if ( $parsed_versions[++$si] eq $_ ) {
$end = $_;
$cl++;
} else {
unshift @avails, $_;
last
}
}
local $" = ", ";
if ( $cl > 1 ) {
unshift @avails, "$start-$end";
return "@avails"
} else {
return "@orig"
}
}


# Produce reference sets (docbook element Reference contains RefEntries)
for my $group ( keys %symbols ) {
# Prepare reference page
Expand Down Expand Up @@ -741,21 +722,12 @@ sub update_field {
( my $list = $content ) =~ s/,/ /g;
my @list = split /\s+/, $list;
@{ $$sref{'_see also'} } = @list;
#push @{ $$sref{'_see also'} }, @list;
#$$sref{'see also'} = join ", ", @{$$sref{'_see also'}};
}

} else { # "Missing" section
my @missing_list = split /\n/, $content;
push @{ $invalid{$name} }, $_ for @missing_list
}

# Older code
#if ( $mode eq 'override' ) {
# $$sref{$sect} = $content;
#} elsif ( $mode eq 'append' ) {
# $$sref{$sect} .= $content;
#}
}

sub loaddb {
Expand All @@ -774,6 +746,40 @@ sub loaddb {
%hash = %{ $refcache{$dbpath} };
}

sub compress_availability {
my @avails = my @orig = @{ (shift) };
@avails or die "compress_availability(): Shouldn't happen";

# XXX this needs work, but at the moment it serves us well
# (it can't handle like x-y, z, a-b. It only handles start-end)

my $start = shift @avails;
my $si; # starting index
my $cl = 0; # compress level
for (my $i=0; $i<@parsed_versions;$i++) {
if ( $parsed_versions[$i] eq $start ) {
$si = $i;
}
}
my $end;
while ( $_ = shift @avails ) {
if ( $parsed_versions[++$si] eq $_ ) {
$end = $_;
$cl++;
} else {
unshift @avails, $_;
last
}
}
local $" = ", ";
if ( $cl > 1 ) {
unshift @avails, "$start-$end";
return "@avails"
} else {
return "@orig"
}
}

sub O { print "@_\n"; print STDOUT "@_\n" if $verbose }


Expand Down Expand Up @@ -848,14 +854,6 @@ $ag{source}
<para>$ag{"author"}</para>
</refsect1>
<!-- Removed because copyright is seen in Source (first few lines),
and the generated document starts with copyright notice
<refsect1 id='$ag{"name"}_copyright'>
<title>COPYRIGHT</title>
$ag{"copyright"}
</refsect1>
-->
<refsect1 id='$ag{"name"}_seeAlso'>
<title>SEE ALSO</title>
<para>$ag{"see also"}</para>
Expand Down Expand Up @@ -1012,14 +1010,6 @@ $ag{source}
<para>$ag{"author"}</para>
</refsect1>
<!-- Removed because copyright is seen in Source (first few lines),
and the generated document starts with copyright notice
<refsect1 id='$ag{"name"}_copyright'>
<title>COPYRIGHT</title>
$ag{"copyright"}
</refsect1>
-->
<refsect1 id='$ag{"name"}_seeAlso'>
<title>SEE ALSO</title>
<para>$ag{"see also"}</para>
Expand Down

0 comments on commit d44d6aa

Please sign in to comment.