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-2009 Free Penguins".
24 dir=$(d=$0; [ -L "$d" ] && d=$(readlink "$d"); dirname "$d")
25 adapter=$dir/adapter.awk
26 usage="Usage: $PROGRAM [FLAGS] SPECFILE
28 -s|--no-sort|--skip-sort
29 skip BuildRequires, Requires sorting
30 -m|--no-macros|--skip-macros
31 skip use_macros() substitutions
35 skip %defattr corrections
37 do not do any diffing, just dump the output
40 if [ ! -x /usr/bin/getopt ]; then
41 echo >&2 "You need to install util-linux to use adapter"
45 if [ ! -x /usr/bin/patch ]; then
46 echo >&2 "You need to install patch to use adapter"
50 t=$(getopt -o hsomdaV --long help,version,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$PROGRAM" -- "$@") || exit $?
59 -s|--no-sort|--skip-sort)
62 -m|--no-macros|--skip-macros)
83 echo >&2 "$PROGRAM: Internal error: \`$1' not recognized!"
92 # vim like diff colourization
94 s,
\e,
\e[44m^[
\e[49m,g;
95 s,
\a,
\e[44m^G
\e[49m,g;
96 s,^\(Index:\|diff\|---\|+++\) .*$,
\e[32m&,;
100 s,\r,
\e[44m^M
\e[49m,g;
102 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1
\e[41m\2
\e[49m,g;
110 eval $(resize) # get terminal size
111 if [ $l -gt $LINES ]; then
120 # diff2hunks orignally by dig
126 for my $filename (@ARGV) {
129 open $fh, "<", $filename or die "$filename: open for reading: $!";
133 for my $i (0 ... $#lines) {
134 next unless $lines[$i] =~ m/^\@\@ /;
135 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
136 @curheader = @lines[$i - 2 ... $i - 1];
138 next unless @curheader;
140 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
142 if $j >= 3 and $j < @lines
143 and $lines[$j - 2] =~ m/^--- /
144 and $lines[$j - 1] =~ m/^\+\+\+ /;
146 $j-- until $lines[$j] =~ m/^[ @+-]/;
147 my $hunkfilename = $filename;
148 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
150 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
151 print $ofh @curheader, @lines[$i ... $j];
158 # import selected macros for adapter.awk
159 # you should update the list also in adapter.awk when making changes here
160 import_rpm_macros() {
204 for macro in $macros; do
205 eval_expr="$eval_expr\nexport $macro='%{$macro}'"
209 # get cvsaddress for changelog section
210 # using rpm macros as too lazy to add ~/.adapterrc parsing support.
211 eval_expr="$eval_expr
212 export _cvsmaildomain='%{?_cvsmaildomain}%{!?_cvsmaildomain:@pld-linux.org}'
213 export _cvsmailfeedback='%{?_cvsmailfeedback}%{!?_cvsmailfeedback:PLD Team <feedback@pld-linux.org>}'
216 eval $(rpm --eval "$(echo -e $eval_expr)")
221 workdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
224 local tmp=$workdir/$(basename $SPECFILE) || exit
228 LC_ALL=en_US.UTF-8 $awk -f $adapter $SPECFILE > $tmp || exit
230 if [ "$outputonly" = 1 ]; then
233 elif [ "$(diff --brief $SPECFILE $tmp)" ]; then
234 diff -u $SPECFILE $tmp > $tmp.diff
238 echo -n "Accept? (Yes, No, Confirm each chunk)? "
243 echo "Ok, adapterized."
246 [cC]) # confirm each chunk
248 for t in $(ls $tmp-*.diff); do
250 echo -n "Accept? (Yes, [N]o, Quit)? "
273 echo "The SPEC is perfect ;)"
280 [ -f "$SPECFILE" ] || SPECFILE="$(basename $SPECFILE .spec).spec"
282 if [ $# -ne 1 -o ! -f "$SPECFILE" ]; then