3 # This is adapter v0.27. 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 usage="Usage: $self [FLAGS] SPECFILE
21 -s|--no-sort|--skip-sort
22 skip BuildRequires, Requires sorting
23 -m|--no-macros|--skip-macros
24 skip use_macros() substitutions
28 skip %defattr corrections
32 t=`getopt -o hsmda --long help,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@"` || exit $?
41 -s|--no-sort|--skip-sort)
44 -m|--no-macros|--skip-macros)
58 echo 2>&1 "$self: Internal error: [$1] not recognized!"
67 # vim like diff colourization
69 s,
\e,
\e[44m^[
\e[49m,g;
70 s,
\a,
\e[44m^G
\e[49m,g;
71 s,^\(Index:\|diff\|---\|+++\) .*$,
\e[32m&,;
75 s,
\r,
\e[44m^M
\e[49m,g;
77 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1
\e[41m\2
\e[49m,g;
84 # diff2hunks orignally by dig
90 for my $filename (@ARGV) {
93 open $fh, "<", $filename or die "$filename: open for reading: $!";
97 for my $i (0 ... $#lines) {
98 next unless $lines[$i] =~ m/^\@\@ /;
99 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
100 @curheader = @lines[$i - 2 ... $i - 1];
102 next unless @curheader;
104 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
106 if $j >= 3 and $j < @lines
107 and $lines[$j - 2] =~ m/^--- /
108 and $lines[$j - 1] =~ m/^\+\+\+ /;
110 $j-- until $lines[$j] =~ m/^[ @+-]/;
111 my $hunkfilename = $filename;
112 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
114 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
115 print $ofh @curheader, @lines[$i ... $j];
125 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
126 awk -f adapter.awk $SPECFILE > $tmpdir/$SPECFILE || exit
128 if [ "`diff --brief $SPECFILE $tmpdir/$SPECFILE`" ] ; then
129 diff -u $SPECFILE $tmpdir/$SPECFILE > $tmpdir/$SPECFILE.diff
131 diffcol $tmpdir/$SPECFILE.diff | less -r
133 echo -n "Accept? (Yes, No, Confirm each chunk)? "
137 mv -f $tmpdir/$SPECFILE $SPECFILE
138 echo "Ok, adapterized."
141 [cC]) # confirm each chunk
142 diff2hunks $tmpdir/$SPECFILE.diff
143 for t in $(ls $tmpdir/$SPECFILE-*.diff); do
145 echo -n "Accept? (Yes, [N]o)? "
162 cat $tmpdir/$SPECFILE.diff
165 echo "The SPEC is perfect ;)"
171 if [ $# -ne 1 -o ! -f "$1" ]; then