[packages/adapter: 13/631] - added adding translations of Group fields - cleanups

glen glen at pld-linux.org
Mon Sep 12 19:35:33 CEST 2016


commit 8b1938ea37144376c091051a35a1f977347796a2
Author: kura <kura at pld-linux.org>
Date:   Tue Jan 4 00:08:49 2000 +0000

    - added adding translations of Group fields
    - cleanups
    
    Changed files:
        adapter.awk -> 1.13

 adapter.awk | 121 ++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 90 insertions(+), 31 deletions(-)
---
diff --git a/adapter.awk b/adapter.awk
index a0cf90a..f315a3d 100644
--- a/adapter.awk
+++ b/adapter.awk
@@ -1,22 +1,28 @@
 #!/bin/awk -f
 #
-# This is adapter v0.8. Adapter adapts .spec files for PLD.
+# This is adapter v0.9. Adapter adapts .spec files for PLD.
 # Copyright (C) 1999 Micha� Kuratczyk <kura at pld.org.pl>
 
 BEGIN {
 	preamble = 1;
-	bof = 1;	# Beggining of file
-	boc = 2;	# Beggining of %changelog
-	bod = 0;	# Beggining of %description
-	tw = 77;        # Descriptions width	
+	boc = 2;			# Beggining of %changelog
+	bod = 0;			# Beggining of %description
+	tw = 77;        		# Descriptions width
+	groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
+	
+	# Is 'date' macro already defined?
+	if (is_there_line("%define date"))
+		date = 1;
 }
 
 # There should be a comment with CVS keywords on the first line of file.
-bof == 1 {
-	preamble = 0;
-	if (!/# \$Revision:/)
-		 print "# $" "Revision:$, " "$" "Date:$";
-	bof = 0;
+FNR == 1 {
+	if (!/# \$Revision:/)		# If this line is already OK?
+		print "# $" "Revision:$, " "$" "Date:$";	# No
+	else
+		print $0;					# Yes
+
+	next;				# It is enough for first line
 }
 
 # descriptions:
@@ -121,7 +127,6 @@ bof == 1 {
 	
 	if (/%defattr/)
 		$0 = "%defattr(644,root,root,755)";
-
 }
 
 # %changelog section:
@@ -145,7 +150,7 @@ bof == 1 {
 			printf "%%define date\t%%(echo `LC_ALL=\"C\"";
 			print " date +\"%a %b %d %Y\"`)"
 		}
-		boc--;
+	boc--;
 	}
 }
 
@@ -163,9 +168,18 @@ preamble == 1 {
 	if (field ~ /buildroot:/)
 		$2 = "/tmp/%{name}-%{version}-root";
 
-	# Is it X11 application?
-	if (field ~ /group/ && $2 ~ /^X11/ && x11 == 0)
-		x11 = 1;
+	if (field ~ /group:/) {
+		format_preamble();
+		print $0;
+		
+		translate_group($2);
+		close(groups_file);
+		
+		if ($2 ~ /^X11/ && x11 == 0)	# Is it X11 application?
+		       x11 = 1;
+
+		next;	# Line is already formatted and printed
+	}
 		
 	# Use "License" instead of "Copyright" if it is (L)GPL or BSD
 	if (field ~ /copyright:/ && $2 ~ /GPL|BSD/)
@@ -185,15 +199,8 @@ preamble == 1 {
 		sub(version, "%{version}", url[n]);
 		sub(filename, url[n], $2);
 	}
-		
-	# There should be one or two tabs after the colon.
-	sub(/:[ \t]*/, ":");
-	if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
-		if (RLENGTH < 8)
-			sub(/:/, ":\t\t");
-		else
-			sub(/:/, ":\t");
-	}
+
+	format_preamble();
 	
 	# Do not add %define of _prefix if it already is.
 	if ($1 ~ /%define/ && $2 ~ /_prefix/)
@@ -201,16 +208,9 @@ preamble == 1 {
 			
 }
 
-
-# If redundant_line is zero, print this line, otherwise do not print,
-# but set the redundant_line to 0.
 {
 	preamble = 1;
 	
-	# Macro 'date' already defined.
-	if (/%define date/)
-		date = 1;
-	
 	print;
 }
 
@@ -223,3 +223,62 @@ END {
 	}
 }
 
+# This function uses grep to determine if there is line (in the current file)
+# which matches regexp.
+function is_there_line(line, l)
+{
+	command = "grep \"" line "\" " ARGV[1];
+	command	| getline l;
+	close(ARGV[1]);
+
+	if (l != "")
+		return 1;
+	else
+		return 0;
+}
+
+# This function prints translated names of groups.
+function translate_group(group)
+{
+	for(;;) {
+		result = getline line < groups_file;
+		
+		if (result == -1) {
+			print "######\t\t" groups_file ": no such file";
+			return;
+		}
+
+		if (result == 0) {
+			print "######\t\t" "Unknown group!";
+			return;
+		}
+		
+		if (line ~ group) {
+			found = 1;
+			continue;
+		}
+
+		if (found == 1)
+			if (line ~ /\[[a-z][a-z]\]:/) {
+				split(line, g, /\[|\]|\:/);
+				if (!is_there_line("^Group(" g[2] "):"))
+						printf("Group(%s):%s\n", g[2], g[4]);
+			} else {
+				found = 0;
+				return;
+			}
+	}
+}
+
+# There should be one or two tabs after the colon.
+function format_preamble()
+{
+	sub(/:[ \t]*/, ":");
+	if (match($0, /[A-Za-z0-9()# \t]+[ \t]*:[ \t]*/) == 1) {
+		if (RLENGTH < 8)
+			sub(/:/, ":\t\t");
+		else
+			sub(/:/, ":\t");
+	}
+}
+
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/adapter.git/commitdiff/6ca0126d4d0c8c79feb7db10b0a0fade0f3b8885



More information about the pld-cvs-commit mailing list