4 # Michał Kuratczyk <kura@pld.org.pl>
5 # Sebastian Zagrodzki <s.zagrodzki@mimuw.edu.pl>
6 # Tomasz Kłoczko <kloczek@rudy.mif.pg.gda.pl>
7 # Artur Frysiak <wiget@pld-linux.org>
8 # Michal Kochanowicz <mkochano@pld.org.pl>
9 # Elan Ruusamäe <glen@pld-linux.org>
11 # See cvs log adapter{,.awk} for list of contributors
13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
20 Adapter adapts .spec files for PLD Linux.
21 $VERSION (C) 1999-2008 Free Penguins".
24 adapter=$(dirname "$0")/adapter.awk
25 usage="Usage: $self [FLAGS] SPECFILE
27 -s|--no-sort|--skip-sort
28 skip BuildRequires, Requires sorting
29 -m|--no-macros|--skip-macros
30 skip use_macros() substitutions
34 skip %defattr corrections
38 if [ ! -x /usr/bin/getopt ]; then
39 echo >&1 "You need to install util-linux to use adapter"
43 if [ ! -x /usr/bin/patch ]; then
44 echo >&1 "You need to install patch to use adapter"
48 t=$(getopt -o hsmdaV --long help,version,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@") || exit $?
57 -s|--no-sort|--skip-sort)
60 -m|--no-macros|--skip-macros)
78 echo 2>&1 "$self: Internal error: [$1] not recognized!"
87 # vim like diff colourization
89 s,
\e,
\e[44m^[
\e[49m,g;
90 s,
\a,
\e[44m^G
\e[49m,g;
91 s,^\(Index:\|diff\|---\|+++\) .*$,
\e[32m&,;
95 s,\r,
\e[44m^M
\e[49m,g;
97 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1
\e[41m\2
\e[49m,g;
104 # diff2hunks orignally by dig
110 for my $filename (@ARGV) {
113 open $fh, "<", $filename or die "$filename: open for reading: $!";
117 for my $i (0 ... $#lines) {
118 next unless $lines[$i] =~ m/^\@\@ /;
119 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
120 @curheader = @lines[$i - 2 ... $i - 1];
122 next unless @curheader;
124 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
126 if $j >= 3 and $j < @lines
127 and $lines[$j - 2] =~ m/^--- /
128 and $lines[$j - 1] =~ m/^\+\+\+ /;
130 $j-- until $lines[$j] =~ m/^[ @+-]/;
131 my $hunkfilename = $filename;
132 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
134 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
135 print $ofh @curheader, @lines[$i ... $j];
145 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
146 if grep -q '\.UTF-8' $SPECFILE; then
152 local tmp=$tmpdir/$(basename $SPECFILE) || exit
153 $awk -f $adapter $SPECFILE > $tmp || exit
155 if [ "$(diff --brief $SPECFILE $tmp)" ]; then
156 diff -u $SPECFILE $tmp > $tmp.diff
158 diffcol $tmp.diff | less -r
160 echo -n "Accept? (Yes, No, Confirm each chunk)? "
165 echo "Ok, adapterized."
168 [cC]) # confirm each chunk
170 for t in $(ls $tmp-*.diff); do
172 echo -n "Accept? (Yes, [N]o, Quit)? "
195 echo "The SPEC is perfect ;)"
202 [ -f "$SPECFILE" ] || SPECFILE="$(basename $SPECFILE .spec).spec"
204 if [ $# -ne 1 -o ! -f "$SPECFILE" ]; then