]> git.pld-linux.org Git - packages/adapter.git/blobdiff - adapter.awk
version 0.20
[packages/adapter.git] / adapter.awk
index 7871f8b743500006b65c851c4bd0e428fc25ec1d..c9c82477f298ca71bb493e11a770505ab1ec1637 100644 (file)
@@ -1,14 +1,25 @@
 #!/bin/awk -f
 #
-# This is adapter v0.14. Adapter adapts .spec files for PLD.
-# Copyright (C) 1999 Micha³ Kuratczyk <kura@pld.org.pl>
+# This is adapter v0.20. Adapter adapts .spec files for PLD.
+#
+# Copyright (C) 1999, 2000 PLD-Team <pld-list@pld.org.pl>
+# Authors:
+#      Micha³ Kuratczyk <kura@pld.org.pl>
+#      Sebastian Zagrodzki <s.zagrodzki@sith.mimuw.edu.pl>
+#      Tomasz K³oczko <kloczek@rudy.mif.pg.gda.pl>
+#      Artur Frysiak <wiget@pld.org.pl>
+#      Michal Kochanowicz <mkochano@ee.pw.edu.pl>
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 
 BEGIN {
-       preamble = 1
+       preamble = 1            # Is it part of preamble? Default - yes
        boc = 2                 # Beggining of %changelog
        bod = 0                 # Beggining of %description
-       tw = 77                 # Descriptions width
-       groups_file = ENVIRON["HOME"] "/rpm/groups" # File with rpm groups
+       tw = 75                 # Descriptions width
+
+       # File with rpm groups
+       "rpm --eval %_topdir" | getline groups_file
+       groups_file = groups_file "/groups"
 
        # Temporary file for changelog section
        changelog_file = ENVIRON["HOME"] "/tmp/adapter.changelog"
@@ -17,6 +28,7 @@ BEGIN {
        if (is_there_line("%define date"))
                date = 1
        
+       # Load rpm macros
        "rpm --eval %_prefix"   | getline prefix
        "rpm --eval %_bindir"   | getline bindir
        "rpm --eval %_sbindir"  | getline sbindir
@@ -30,11 +42,11 @@ BEGIN {
 
 # There should be a comment with CVS keywords on the first line of file.
 FNR == 1 {
-       if (!/# \$Revision:/)           # If this line is already OK?
-               print "# $" "Revision:$, " "$" "Date:$"         # No
+       if (!/# \$Revision:/)   # If this line is already OK?
+               print "# $" "Revision:$, " "$" "Date:$" # No
        else {
-               print $0                                                # Yes
-               next                            # It is enough for first line
+               print $0                                # Yes
+               next            # It is enough for first line
        }
 }
 
@@ -47,6 +59,7 @@ defattr == 1 {
        defattr = 0
 }
 
+# Remove defining _applnkdir (this macro has been included in rpm-3.0.4)
 /^%define/ {
        if ($2 == "_applnkdir")
                next                                    
@@ -56,9 +69,12 @@ defattr == 1 {
 /^%description/, (/^%[a-z]+/ && !/^%description/) {
        preamble = 0
 
-       if (/^%description/)
+       if (/^%description/) {
                bod++
-       
+               format_line = ""
+               format_indent = -1
+       }
+
        # Define _prefix and _mandir if it is X11 application
        if (/^%description$/ && x11 == 1) {
                print "%define\t\t_prefix\t\t/usr/X11R6"
@@ -66,32 +82,27 @@ defattr == 1 {
                prefix = "/usr/X11R6"
                x11 = 2
        }
-
-        # Collect whole text of description
+       
+       # Format description
        if (description == 1 && !/^%[a-z]+/ && !/^%description/) {
-               description_text = description_text $0 " "
+               if (/^[ \t]*$/) {
+                       format_flush(format_line, format_indent)
+                       print ""
+                       format_line = ""
+                       format_indent = -1
+               } else if (/^[ \t]*[-\*][ \t]*/) {
+                       format_flush(format_line, format_indent)
+                       match($0, /^[ \t]*/)    
+                       format_indent = RLENGTH
+                       match($0, /^[ \t]*[-\*][ \t]/)
+                       format_line = substr($0, RLENGTH)
+               } else 
+                       format_line = format_line " " $0
                next
        }
  
-       # Formt description to the length of tw (default == 77)
        if (/^%[a-z]+/ && (!/^%description/ || bod == 2)) {
-               n = split(description_text, dt, / /)
-               for (i = 1; i <= n; i++) {
-                       if (length(line) + length(dt[i]) + 1 < tw)
-                               line = line dt[i] " "
-                       else {
-                               sub(/[ ]+$/, "", line)
-                               print line
-                               line = ""
-                               i--
-                       }
-               }
-
-               sub(/[ ]+$/, "", line)
-               print line "\n"
-               line = ""
-               delete dt
-               description_text = ""
+               format_flush(format_line, format_indent)
                if (bod == 2) {
                        bod = 1
                        description = 1
@@ -120,7 +131,7 @@ defattr == 1 {
 }
 
 # %install section:
-/^%install/, (/^[a-z]+$/ && !/^%install/) {
+/^%install/, (/^%[a-z]+$/ && !/^%install/) {
        preamble = 0
        
        use_macros()
@@ -136,8 +147,7 @@ defattr == 1 {
        if (/^install/ && /-m[ \t]*644/)
                gsub(/-m[ \t]*644 /, "")
        
-       # No lines contain 'chown' or 'chgrp', which changes
-       # owner/group to 'root'
+       # No lines contain 'chown' or 'chgrp' if owner/group is 'root'
        if (($1 ~ /chown/ && $2 ~ /root\.root/) || ($1 ~ /chgrp/ && $2 ~ /root/))
                next
        
@@ -153,6 +163,12 @@ defattr == 1 {
        }
 }
 
+# Scripts
+/^%pre /, (/^[a-z]+$/ && !/^%pre /) { preamble = 0 }
+/^%preun/, (/^[a-z]+$/ && !/^%preun/) { preamble = 0 }
+/^%post /, (/^[a-z]+$/ && !/^%post /) {        preamble = 0 }
+/^%postun/, (/^[a-z]+$/ && !/^%postun/) { preamble = 0 }
+       
 # %files section:
 /^%files/, (/^%[a-z \-]+$/ && !/^%files/) {
        preamble = 0
@@ -202,11 +218,11 @@ preamble == 1 {
        
        field = tolower($1)
 
-       if (field ~ /packager:|distribution:|prefix:/)
+       if (field ~ /packager:|distribution:|docdir:|prefix:/)
                next
        
        if (field ~ /buildroot:/)
-               $2 = "/tmp/%{name}-%{version}-root-%(id -u -n)"
+               $0 = $1 "%{tmpdir}/%{name}-%{version}-root-%(id -u -n)"
 
        if (field ~ /group:/) {
                format_preamble()
@@ -246,9 +262,6 @@ preamble == 1 {
        if (field ~ /patch:/)
                $1 = "Patch0:"
        
-       if (fiels ~ /buildroot:/)
-               $2 = "%{tmpdir}/%{name}-%{dir}"
-
        format_preamble()
        
        if ($1 ~ /%define/) {
@@ -276,23 +289,24 @@ preamble == 1 {
        }
 }
 
+
+# main()  ;-)
 {
        preamble = 1
        
        print
 }
 
+
 END {
-       if (changelog_file) {
-               close(changelog_file)
-               while ((getline < changelog_file) > 0)
-                       print
-               system("rm -f " changelog_file)
-       }
+       close(changelog_file)
+       while ((getline < changelog_file) > 0)
+               print
+       system("rm -f " changelog_file)
 
        if (boc == 1) {
                print "* %{date} PLD Team <pld-list@pld.org.pl>"
-               printf "All below listed persons can be reached on "
+               printf "All persons listed below can be reached at "
                print "<cvs_login>@pld.org.pl\n"
                print "$" "Log:$"
        }
@@ -383,6 +397,9 @@ function use_macros()
        gsub("%{_prefix}/include", "%{_includedir}")
 
        gsub(mandir, "%{_mandir}")
+       gsub("%{_datadir}/man", "%{_mandir}")
+       gsub("%{_prefix}/share/man", "%{_mandir}")
+       gsub("%{prefix}/share/man", "%{_mandir}")
        gsub("%{prefix}/man", "%{_mandir}")
        gsub("%{_prefix}/man", "%{_mandir}")
 
@@ -390,9 +407,56 @@ function use_macros()
        gsub("%{prefix}/info", "%{_infodir}")
        gsub("%{_prefix}/info", "%{_infodir}")
 
+       gsub("%{_datadir}/aclocal", "%{_aclocaldir}")
+
        if (prefix != "/") {
                gsub(prefix, "%{_prefix}")
                gsub("%{prefix}", "%{_prefix}")
        }
+
+       gsub("%{PACKAGE_VERSION}", "%{version}")
+       gsub("%{PACKAGE_NAME}", "%{name}")
+
+       gsub("^%{_sbindir}", "%attr(755,root,root) %{_sbindir}")
+       gsub("^%{_bindir}", "%attr(755,root,root) %{_bindir}")
+
+       gsub("%{_datadir}/gnome/apps", "%{_applnkdir}")
+}
+
+function fill(ch, n, i) {
+       for (i = 0; i < n; i++)
+               printf("%c", ch)
+}
+
+function format_flush(line, indent, newline, word, first_word) {
+       first_word = 1
+       if (format_indent == -1) 
+               newline = ""
+       else
+               newline = fill(" ", format_indent) "- "
+
+       while (match(line, /[^\t ]+/)) {
+               word = substr(line, RSTART, RLENGTH)
+               if (length(newline) + length(word) + 1 > tw) {
+                       print newline
+                       
+                       if (format_indent == -1)
+                               newline = ""
+                       else
+                               newline = fill(" ", format_indent + 2)
+                       first_word = 1
+               }
+
+               if (first_word) {
+                       newline = newline word
+                       first_word = 0
+               } else
+                       newline = newline " " word
+                       
+               line = substr(line, RSTART + RLENGTH)
+       }
+       if (newline ~ /[^\t ]/) {
+               print newline
+       }
 }
 
This page took 0.049651 seconds and 4 git commands to generate.