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 if [ ! -x /usr/bin/getopt ]; then
33 echo >&1 "You need to install util-linux to use adapter"
37 t=`getopt -o hsmda --long help,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@"` || exit $?
46 -s|--no-sort|--skip-sort)
49 -m|--no-macros|--skip-macros)
63 echo 2>&1 "$self: Internal error: [$1] not recognized!"
72 # vim like diff colourization
74 s,
\e,
\e[44m^[
\e[49m,g;
75 s,
\a,
\e[44m^G
\e[49m,g;
76 s,^\(Index:\|diff\|---\|+++\) .*$,
\e[32m&,;
80 s,
\r,
\e[44m^M
\e[49m,g;
82 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1
\e[41m\2
\e[49m,g;
89 # diff2hunks orignally by dig
95 for my $filename (@ARGV) {
98 open $fh, "<", $filename or die "$filename: open for reading: $!";
102 for my $i (0 ... $#lines) {
103 next unless $lines[$i] =~ m/^\@\@ /;
104 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
105 @curheader = @lines[$i - 2 ... $i - 1];
107 next unless @curheader;
109 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
111 if $j >= 3 and $j < @lines
112 and $lines[$j - 2] =~ m/^--- /
113 and $lines[$j - 1] =~ m/^\+\+\+ /;
115 $j-- until $lines[$j] =~ m/^[ @+-]/;
116 my $hunkfilename = $filename;
117 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
119 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
120 print $ofh @curheader, @lines[$i ... $j];
130 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
131 awk -f adapter.awk $SPECFILE > $tmpdir/$SPECFILE || exit
133 if [ "`diff --brief $SPECFILE $tmpdir/$SPECFILE`" ] ; then
134 diff -u $SPECFILE $tmpdir/$SPECFILE > $tmpdir/$SPECFILE.diff
136 diffcol $tmpdir/$SPECFILE.diff | less -r
138 echo -n "Accept? (Yes, No, Confirm each chunk)? "
142 mv -f $tmpdir/$SPECFILE $SPECFILE
143 echo "Ok, adapterized."
146 [cC]) # confirm each chunk
147 diff2hunks $tmpdir/$SPECFILE.diff
148 for t in $(ls $tmpdir/$SPECFILE-*.diff); do
150 echo -n "Accept? (Yes, [N]o)? "
167 cat $tmpdir/$SPECFILE.diff
170 echo "The SPEC is perfect ;)"
176 if [ $# -ne 1 -o ! -f "$1" ]; then