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
36 do not do any diffing, just dump the output
39 if [ ! -x /usr/bin/getopt ]; then
40 echo >&1 "You need to install util-linux to use adapter"
44 if [ ! -x /usr/bin/patch ]; then
45 echo >&1 "You need to install patch to use adapter"
49 t=$(getopt -o hsomdaV --long help,version,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@") || exit $?
58 -s|--no-sort|--skip-sort)
61 -m|--no-macros|--skip-macros)
82 echo 2>&1 "$self: Internal error: [$1] not recognized!"
91 # vim like diff colourization
93 s,
\e,
\e[44m^[
\e[49m,g;
94 s,
\a,
\e[44m^G
\e[49m,g;
95 s,^\(Index:\|diff\|---\|+++\) .*$,
\e[32m&,;
99 s,\r,
\e[44m^M
\e[49m,g;
101 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1
\e[41m\2
\e[49m,g;
108 # diff2hunks orignally by dig
114 for my $filename (@ARGV) {
117 open $fh, "<", $filename or die "$filename: open for reading: $!";
121 for my $i (0 ... $#lines) {
122 next unless $lines[$i] =~ m/^\@\@ /;
123 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
124 @curheader = @lines[$i - 2 ... $i - 1];
126 next unless @curheader;
128 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
130 if $j >= 3 and $j < @lines
131 and $lines[$j - 2] =~ m/^--- /
132 and $lines[$j - 1] =~ m/^\+\+\+ /;
134 $j-- until $lines[$j] =~ m/^[ @+-]/;
135 my $hunkfilename = $filename;
136 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
138 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
139 print $ofh @curheader, @lines[$i ... $j];
146 # import selected macros for adapter.awk
147 # you should update the list also in adapter.awk when making changes here
148 import_rpm_macros() {
191 for macro in $macros; do
192 eval_expr="$eval_expr\nexport $macro='%{$macro}'"
196 # get cvsaddress for changelog section
197 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
198 eval_expr="$eval_expr
199 export _cvsmaildomain='%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'
200 export _cvsmailfeedback='%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'
203 eval $(rpm --eval "$(echo -e $eval_expr)")
208 workdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
209 if grep -q '\.UTF-8' $SPECFILE; then
215 local tmp=$workdir/$(basename $SPECFILE) || exit
219 $awk -f $adapter $SPECFILE > $tmp || exit
221 if [ "$outputonly" = 1 ]; then
224 elif [ "$(diff --brief $SPECFILE $tmp)" ]; then
225 diff -u $SPECFILE $tmp > $tmp.diff
227 diffcol $tmp.diff | less -r
229 echo -n "Accept? (Yes, No, Confirm each chunk)? "
234 echo "Ok, adapterized."
237 [cC]) # confirm each chunk
239 for t in $(ls $tmp-*.diff); do
241 echo -n "Accept? (Yes, [N]o, Quit)? "
264 echo "The SPEC is perfect ;)"
271 [ -f "$SPECFILE" ] || SPECFILE="$(basename $SPECFILE .spec).spec"
273 if [ $# -ne 1 -o ! -f "$SPECFILE" ]; then