<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env perl

use strict;
use warnings;

my ( $src_file, $dst_file, $cur_path, $new_path ) = @ARGV;
usage() unless $src_file &amp;&amp; $dst_file &amp;&amp; -e $src_file;
usage() unless $cur_path &amp;&amp; $new_path;

sub usage {
    warn "usage: $0 &lt;input pdldoc.db&gt; &lt;output pdldoc.db&gt;\n";
    warn "          &lt;current path&gt; &lt;path after install&gt;\n";
    warn @_;
    exit 1;
}

my $hash = ensuredb( { File =&gt; [$src_file], Scanned =&gt; [], } );
fix_directories($hash);
savedb( { Outfile =&gt; $dst_file }, $hash );

sub fix_directories {
    my ($hash) = @_;

    for my $key (%$hash) {
        next unless exists $hash-&gt;{$key}-&gt;{File};
        $hash-&gt;{$key}-&gt;{File} =~ s{^$cur_path}{$new_path};
    }
}

# Taken from PDL::Doc with minor modifications
sub ensuredb {
    my ($this) = @_;
    while ( my $fi = pop @{ $this-&gt;{File} } ) {
        open IN, $fi
          or die "can't open database $fi, scan docs first";
        binmode IN;
        my ( $plen, $txt );
        while ( read IN, $plen, 2 ) {
            my ($len) = unpack "S", $plen;
            read IN, $txt, $len;
            my ($sym, @a) = split chr(0), $txt;
            push @a, '' if @a % 2; # Ensure an even number of elements
            $this-&gt;{SYMS}-&gt;{$sym} = {@a};
        }
        close IN;
        push @{ $this-&gt;{Scanned} }, $fi;
    }
    return $this-&gt;{SYMS};
}

sub savedb {
    my ( $this, $hash ) = @_;
    ## my $hash = $this-&gt;ensuredb();

    open OUT, "&gt;$this-&gt;{Outfile}"
      or die "can't write to symdb $this-&gt;{Outfile}";
    binmode OUT;
    while ( my ( $key, $val ) = each %$hash ) {
        next unless scalar(%$val);
        my $txt = "$key" . chr(0) . join( chr(0), %$val );
        print OUT pack( "S", length($txt) ) . $txt;
    }
}

</pre></body></html>