3 # This is adapter v0.29. Adapter adapts .spec files for PLD Linux.
5 # Copyright (C) 1999-2003 PLD-Team <feedback@pld-linux.org>
7 # Michał Kuratczyk <kura@pld.org.pl>
8 # Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
9 # Tomasz Kłoczko <kloczek@rudy.mif.pg.gda.pl>
10 # Artur Frysiak <wiget@pld-linux.org>
11 # Michal Kochanowicz <mkochano@pld.org.pl>
12 # Elan Ruusamäe <glen@pld-linux.org>
14 # See cvs log adapter{,.awk} for list of contributors
16 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
19 adapter=$(dirname "$0")/adapter.awk
20 usage="Usage: $self [FLAGS] SPECFILE
22 -s|--no-sort|--skip-sort
23 skip BuildRequires, Requires sorting
24 -m|--no-macros|--skip-macros
25 skip use_macros() substitutions
29 skip %defattr corrections
33 if [ ! -x /usr/bin/getopt ]; then
34 echo >&1 "You need to install util-linux to use adapter"
38 if [ ! -x /usr/bin/patch ]; then
39 echo >&1 "You need to install patch to use adapter"
43 t=`getopt -o hsmda --long help,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@"` || exit $?
52 -s|--no-sort|--skip-sort)
55 -m|--no-macros|--skip-macros)
69 echo 2>&1 "$self: Internal error: [$1] not recognized!"
78 # vim like diff colourization
80 s,
\e,
\e[44m^[
\e[49m,g;
81 s,
\a,
\e[44m^G
\e[49m,g;
82 s,^\(Index:\|diff\|---\|+++\) .*$,
\e[32m&,;
86 s,
\r,
\e[44m^M
\e[49m,g;
88 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1
\e[41m\2
\e[49m,g;
95 # diff2hunks orignally by dig
101 for my $filename (@ARGV) {
104 open $fh, "<", $filename or die "$filename: open for reading: $!";
108 for my $i (0 ... $#lines) {
109 next unless $lines[$i] =~ m/^\@\@ /;
110 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
111 @curheader = @lines[$i - 2 ... $i - 1];
113 next unless @curheader;
115 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
117 if $j >= 3 and $j < @lines
118 and $lines[$j - 2] =~ m/^--- /
119 and $lines[$j - 1] =~ m/^\+\+\+ /;
121 $j-- until $lines[$j] =~ m/^[ @+-]/;
122 my $hunkfilename = $filename;
123 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
125 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
126 print $ofh @curheader, @lines[$i ... $j];
136 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
137 if grep -q '\.UTF-8' $SPECFILE; then
143 local tmp=$tmpdir/$(basename $SPECFILE) || exit
144 $awk -f $adapter $SPECFILE > $tmp || exit
146 if [ "$(diff --brief $SPECFILE $tmp)" ]; then
147 diff -u $SPECFILE $tmp > $tmp.diff
149 diffcol $tmp.diff | less -r
151 echo -n "Accept? (Yes, No, Confirm each chunk)? "
156 echo "Ok, adapterized."
159 [cC]) # confirm each chunk
161 for t in $(ls $tmp-*.diff); do
163 echo -n "Accept? (Yes, [N]o, Quit)? "
186 echo "The SPEC is perfect ;)"
192 if [ $# -ne 1 -o ! -f "$1" ]; then