SOURCES: adapter (NEW) - r1.20

glen glen at pld-linux.org
Tue Nov 6 15:50:30 CET 2007


Author: glen                         Date: Tue Nov  6 14:50:30 2007 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- r1.20

---- Files affected:
SOURCES:
   adapter (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/adapter
diff -u /dev/null SOURCES/adapter:1.1
--- /dev/null	Tue Nov  6 15:50:30 2007
+++ SOURCES/adapter	Tue Nov  6 15:50:25 2007
@@ -0,0 +1,195 @@
+#!/bin/sh
+#
+# This is adapter v0.28. Adapter adapts .spec files for PLD Linux.
+#
+# Copyright (C) 1999-2003 PLD-Team <feedback at pld-linux.org>
+# Authors:
+# 	Michał Kuratczyk <kura at pld.org.pl>
+# 	Sebastian Zagrodzki <s.zagrodzki at mimuw.edu.pl>
+# 	Tomasz Kłoczko <kloczek at rudy.mif.pg.gda.pl>
+# 	Artur Frysiak <wiget at pld-linux.org>
+# 	Michal Kochanowicz <mkochano at pld.org.pl>
+# 	Elan Ruusamäe <glen at pld-linux.org>
+#
+# See cvs log adapter{,.awk} for list of contributors
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+self=$(basename "$0")
+usage="Usage: $self [FLAGS] SPECFILE
+
+-s|--no-sort|--skip-sort
+	skip BuildRequires, Requires sorting
+-m|--no-macros|--skip-macros
+	skip use_macros() substitutions
+-d|--skip-desc
+	skip desc wrapping
+-a|--skip-defattr
+	skip %defattr corrections
+
+"
+
+if [ ! -x /usr/bin/getopt ]; then
+	echo >&1 "You need to install util-linux to use adapter"
+	exit 1
+fi
+
+if [ ! -x /usr/bin/patch ]; then
+	echo >&1 "You need to install patch to use adapter"
+	exit 1
+fi
+
+t=`getopt -o hsmda --long help,sort,sort-br,no-macros,skip-macros,skip-desc,skip-defattr -n "$self" -- "$@"` || exit $?
+eval set -- "$t"
+
+while true; do
+	case "$1" in
+	-h|--help)
+ 		echo 2>&1 "$usage"
+		exit 1
+	;;
+	-s|--no-sort|--skip-sort)
+		export SKIP_SORTBR=1
+	;;
+	-m|--no-macros|--skip-macros)
+		export SKIP_MACROS=1
+	;;
+	-d|--skip-desc)
+		export SKIP_DESC=1
+	;;
+	-a|--skip-defattr)
+		export SKIP_DEFATTR=1
+	;;
+	--)
+		shift
+	   	break
+	;;
+	*)
+		echo 2>&1 "$self: Internal error: [$1] not recognized!"
+		exit 1
+	   	;;
+	esac
+	shift
+done
+
+diffcol()
+{
+	 # vim like diff colourization
+	 sed -e '
+	 s,,^[,g;
+	 s,,^G,g;
+	 s,^\(Index:\|diff\|---\|+++\) .*$,&,;
+	 s,^@@ ,&,g;
+	 s,^-,&,;
+	 s,^+,&,;
+	 s,
,^M,g;
+	 s,	,    ,g;
+	 s,\([^[:space:]]\)\([[:space:]]\+\)$,\1\2,g;
+	 s,$,,
+	 ' "$@"
+}
+
+diff2hunks()
+{
+	 # diff2hunks orignally by dig
+	 perl -e '
+#! /usr/bin/perl -w
+
+use strict;
+
+for my $filename (@ARGV) {
+    my $counter = 1;
+    my $fh;
+    open $fh, "<", $filename or die "$filename: open for reading: $!";
+    my @lines = <$fh>;
+    my @hunks;
+    my @curheader;
+    for my $i (0 ... $#lines) {
+        next unless $lines[$i] =~ m/^\@\@ /;
+        if ($i >= 2 and $lines[$i - 2] =~ m/^--- / and $lines[$i - 1] =~ m/^\+\+\+ /) {
+            @curheader = @lines[$i - 2 ... $i - 1];
+        }
+        next unless @curheader;
+        my $j = $i + 1;
+        while ($j < @lines and $lines[$j] !~ m/^\@\@ /) {$j++}
+        $j -= 2
+            if $j >= 3 and $j < @lines
+                and $lines[$j - 2] =~ m/^--- /
+                and $lines[$j - 1] =~ m/^\+\+\+ /;
+        $j--;
+        $j-- until $lines[$j] =~ m/^[ @+-]/;
+        my $hunkfilename = $filename;
+        $hunkfilename =~ s/((\.(pat(ch)?|diff?))?)$/"-".sprintf("%03i",$counter++).$1/ei;
+        my $ofh;
+        open $ofh, ">", $hunkfilename or die "$hunkfilename: open for writing: $!";
+        print $ofh @curheader, @lines[$i ... $j];
+        close $ofh;
+    }
+}
+' "$@"
+}
+
+adapterize()
+{
+	 local tmpdir
+	 tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/adapter-XXXXXX) || exit
+	 if grep -q '\.UTF-8' $SPECFILE; then
+		 awk=gawk
+	 else
+		 awk=awk
+	 fi
+	 $awk -f adapter.awk $SPECFILE > $tmpdir/$SPECFILE || exit
+
+	 if [ "`diff --brief $SPECFILE $tmpdir/$SPECFILE`" ]; then
+		  diff -u $SPECFILE $tmpdir/$SPECFILE > $tmpdir/$SPECFILE.diff
+		  if [ -t 1 ]; then
+				diffcol $tmpdir/$SPECFILE.diff | less -r
+				while : ; do
+					 echo -n "Accept? (Yes, No, Confirm each chunk)? "
+					 read ans
+					 case "$ans" in
+					 [yYoO]) # y0 mama
+						  mv -f $tmpdir/$SPECFILE $SPECFILE
+						  echo "Ok, adapterized."
+						  break
+					 ;;
+					 [cC]) # confirm each chunk
+						  diff2hunks $tmpdir/$SPECFILE.diff
+						  for t in $(ls $tmpdir/$SPECFILE-*.diff); do
+								diffcol $t | less -r
+								echo -n "Accept? (Yes, [N]o, Quit)? "
+								read ans
+								case "$ans" in
+								[yYoO]) # y0 mama
+									patch < $t
+									;;
+								[Q])  # Abort
+									break
+									;;
+								esac
+						  done
+						  break
+					 ;;
+					 [QqnNsS])
+						  echo "Ok, exiting."
+						  break
+					 ;;
+					 esac
+				done
+		  else
+				cat $tmpdir/$SPECFILE.diff
+		  fi
+	 else
+		  echo "The SPEC is perfect ;)"
+	 fi
+
+	 rm -rf $tmpdir
+}
+
+if [ $# -ne 1 -o ! -f "$1" ]; then
+	echo "$usage"
+	exit 1
+fi
+
+SPECFILE="$1"
+adapterize
================================================================


More information about the pld-cvs-commit mailing list