]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - adapter_.sh
- added adapter frontend script
[packages/rpm-build-tools.git] / adapter_.sh
CommitLineData
fd283fd9
ER
1#!/bin/sh
2#
3# This is adapter v0.28. Adapter adapts .spec files for PLD Linux.
4#
5# Copyright (C) 1999-2003 PLD-Team <feedback@pld-linux.org>
6# Authors:
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>
13#
14# See cvs log adapter{,.awk} for list of contributors
15#
16# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
17
18self=$(basename "$0")
19usage="Usage: $self [FLAGS] SPECFILE
20
21-s|--no-sort|--skip-sort
22 skip BuildRequires, Requires sorting
23-m|--no-macros|--skip-macros
24 skip use_macros() substitutions
25-d|--skip-desc
26 skip desc wrapping
27-a|--skip-defattr
28 skip %defattr corrections
29
30"
31
32if [ ! -x /usr/bin/getopt ]; then
33 echo >&1 "You need to install util-linux to use adapter"
34 exit 1
35fi
36
37if [ ! -x /usr/bin/patch ]; then
38 echo >&1 "You need to install patch to use adapter"
39 exit 1
40fi
41
42t=`getopt -o hsmda --long help,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@"` || exit $?
43eval set -- "$t"
44
45while true; do
46 case "$1" in
47 -h|--help)
48 echo 2>&1 "$usage"
49 exit 1
50 ;;
51 -s|--no-sort|--skip-sort)
52 export SKIP_SORTBR=1
53 ;;
54 -m|--no-macros|--skip-macros)
55 export SKIP_MACROS=1
56 ;;
57 -d|--skip-desc)
58 export SKIP_DESC=1
59 ;;
60 -a|--skip-defattr)
61 export SKIP_DEFATTR=1
62 ;;
63 --)
64 shift
65 break
66 ;;
67 *)
68 echo 2>&1 "$self: Internal error: [$1] not recognized!"
69 exit 1
70 ;;
71 esac
72 shift
73done
74
75diffcol()
76{
77 # vim like diff colourization
78 sed -e '
79 s,\e,\e[44m^[\e[49m,g;
80 s,\a,\e[44m^G\e[49m,g;
81 s,^\(Index:\|diff\|---\|+++\) .*$,\e[32m&,;
82 s,^@@ ,\e[33m&,g;
83 s,^-,\e[35m&,;
84 s,^+,\e[36m&,;
85 s,\r,\e[44m^M\e[49m,g;
86 s, , ,g;
87 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1\e[41m\2\e[49m,g;
88 s,$,\e[0m,
89 ' "$@"
90}
91
92diff2hunks()
93{
94 # diff2hunks orignally by dig
95 perl -e '
96#! /usr/bin/perl -w
97
98use strict;
99
100for my $filename (@ARGV) {
101 my $counter = 1;
102 my $fh;
103 open $fh, "<", $filename or die "$filename: open for reading: $!";
104 my @lines = <$fh>;
105 my @hunks;
106 my @curheader;
107 for my $i (0 ... $#lines) {
108 next unless $lines[$i] =~ m/^\@\@ /;
109 if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
110 @curheader = @lines[$i - 2 ... $i - 1];
111 }
112 next unless @curheader;
113 my $j = $i + 1;
114 while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
115 $j -= 2
116 if $j >= 3 and $j < @lines
117 and $lines[$j - 2] =~ m/^--- /
118 and $lines[$j - 1] =~ m/^\+\+\+ /;
119 $j--;
120 $j-- until $lines[$j] =~ m/^[ @+-]/;
121 my $hunkfilename = $filename;
122 $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
123 my $ofh;
124 open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
125 print $ofh @curheader, @lines[$i ... $j];
126 close $ofh;
127 }
128}
129' "$@"
130}
131
132adapterize()
133{
134 local tmpdir
135 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
136 if grep -q '\.UTF-8' $SPECFILE; then
137 awk=gawk
138 else
139 awk=awk
140 fi
141 $awk -f adapter.awk $SPECFILE > $tmpdir/$SPECFILE || exit
142
143 if [ "`diff --brief $SPECFILE $tmpdir/$SPECFILE`" ]; then
144 diff -u $SPECFILE $tmpdir/$SPECFILE > $tmpdir/$SPECFILE.diff
145 if [ -t 1 ]; then
146 diffcol $tmpdir/$SPECFILE.diff | less -r
147 while : ; do
148 echo -n "Accept? (Yes, No, Confirm each chunk)? "
149 read ans
150 case "$ans" in
151 [yYoO]) # y0 mama
152 mv -f $tmpdir/$SPECFILE $SPECFILE
153 echo "Ok, adapterized."
154 break
155 ;;
156 [cC]) # confirm each chunk
157 diff2hunks $tmpdir/$SPECFILE.diff
158 for t in $(ls $tmpdir/$SPECFILE-*.diff); do
159 diffcol $t | less -r
160 echo -n "Accept? (Yes, [N]o, Quit)? "
161 read ans
162 case "$ans" in
163 [yYoO]) # y0 mama
164 patch < $t
165 ;;
166 [Q]) # Abort
167 break
168 ;;
169 esac
170 done
171 break
172 ;;
173 [QqnNsS])
174 echo "Ok, exiting."
175 break
176 ;;
177 esac
178 done
179 else
180 cat $tmpdir/$SPECFILE.diff
181 fi
182 else
183 echo "The SPEC is perfect ;)"
184 fi
185
186 rm -rf $tmpdir
187}
188
189if [ $# -ne 1 -o ! -f "$1" ]; then
190 echo "$usage"
191 exit 1
192fi
193
194SPECFILE="$1"
195adapterize
This page took 0.09176 seconds and 4 git commands to generate.