blob: 584b3232340be47bdbfcb074fbe8361ecbb18d76 [file]
#!/usr/bin/env perl
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Adjust index entry format in .idx file generated by \IXB{} and
# its variants.
#
# Adjustment samples (diff):
#
# -\indexentry{deadlock|hyperindexformat{\bf@\makefirstuc {deadlock|bf}}}{228}
# +\indexentry{deadlock@\makefirstuc {deadlock}|hyperindexformat{\BF}}{228}
# -\indexentry{read-copy update (RCU)@\makefirstuc {read-copy update} [RCU]|hyperpage}{306}
# +\indexentry{read-copy update (RCU)@\makefirstuc {read-copy update} (RCU)|hyperindexformat{\BF}}{306}
# -\indexentry{critical section|hyperindexformat{\bf@\makefirstuc {critical section|bf}!RCU read-side}}{325}
# +\indexentry{critical section@\makefirstuc {critical section}!RCU read-side|hyperindexformat{\BF}}{325}
# -\indexentry{cache associativity|hyperindexformat{\gl@\makefirstuc {cache associativity|gl}}}{1222}
# +\indexentry{cache associativity@\makefirstuc {cache associativity}|hyperindexformat{\GL}}{1222}
# -\indexentry{wait free|hyperindexformat{\gl@\makefirstuc {wait free|gl}!bounded}}{1223}
# +\indexentry{wait free@\makefirstuc {wait free}!bounded|hyperindexformat{\GL}}{1223}
# -\indexentry{interrupt request (IRQ)@\makefirstuc {interrupt request} <IRQ>|hyperpage}{1228}
# +\indexentry{interrupt request (IRQ)@\makefirstuc {interrupt request} (IRQ)|hyperindexformat{\GL}}{1228}
#
# Copyright (C) Akira Yokosawa, 2022
#
# Authors: Akira Yokosawa <akiyks@gmail.com>
use strict;
use warnings;
my $line;
open(my $fh, '<:encoding(UTF-8)', $ARGV[0])
or die "Could not open file '$ARGV[0]' $!";
while($line = <$fh>) {
$line =~ s/\{([^\|]+)(\|hyperindexformat)\{\\bf(@\\makefirstuc )\{.+\}\}\}/\{$1$3\{$1\}$2\{\\BF\}\}/ ;
$line =~ s/\{([^\|]+)(\|hyperindexformat)\{\\bf(@\\makefirstuc )\{.+\}!([^\}]+)\}\}/\{$1$3\{$1}!$4$2\{\\BF\}\}/ ;
$line =~ s/(\\makefirstuc )\{([^\)]+)\} \[([^\]]+)\]\|hyperpage\}/$1\{$2\} \($3\)|hyperindexformat\{\\BF\}\}/ ;
$line =~ s/\{([^\|]+)(\|hyperindexformat)\{\\gl(@\\makefirstuc )\{.+\}\}\}/\{$1$3\{$1\}$2\{\\GL\}\}/ ;
$line =~ s/\{([^\|]+)(\|hyperindexformat)\{\\gl(@\\makefirstuc )\{.+\}!([^\}]+)\}\}/\{$1$3\{$1}!$4$2\{\\GL\}\}/ ;
$line =~ s/(\\makefirstuc )\{([^\)]+)\} \<([^\]]+)\>\|hyperpage\}/$1\{$2\} \($3\)|hyperindexformat\{\\GL\}\}/ ;
print $line ;
}