summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-11-12 17:09:06 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-11-12 17:09:06 -0500
commit429a6e1a88d37d61575656bf004325d3257c9c56 (patch)
treebcce741a68ca4f0e51f3816c45e8db32979e0ab5
parent59556c80283cddf1827092ff0954b775529228a3 (diff)
combine pkgbuild2mw.*
-rwxr-xr-xdoc4
-rwxr-xr-xpkgbuild2mw205
-rwxr-xr-xpkgbuild2mw.0116
-rwxr-xr-xpkgbuild2mw.15
-rwxr-xr-xpkgbuild2mw.234
5 files changed, 207 insertions, 157 deletions
diff --git a/doc b/doc
index abc6b42..ce02105 100755
--- a/doc
+++ b/doc
@@ -6,8 +6,8 @@ pkgbuilds = $(sort $(wildcard *.PKGBUILD))
config.mw: .var.pkgbuilds $(patsubst %.PKGBUILD,%.mw,$(pkgbuilds))
cat $(sort $(filter %.mw,$^)) > $@
-%.mw: %.PKGBUILD ./pkgbuild2mw.0 ./pkgbuild2mw.1 ./pkgbuild2mw.2
- < $< ./pkgbuild2mw.0 | ./pkgbuild2mw.1 | ./pkgbuild2mw.2 | cat -s > $@
+%.mw: %.PKGBUILD ./pkgbuild2mw
+ < $< ./pkgbuild2mw > $@
.var.%: FORCE
@printf '%s' '$(subst ','\\'',$($*))' | sed 's/^/#/' | ./write-ifchanged $@
diff --git a/pkgbuild2mw b/pkgbuild2mw
new file mode 100755
index 0000000..b3a4a30
--- /dev/null
+++ b/pkgbuild2mw
@@ -0,0 +1,205 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+load 'pandoc.rb'
+
+class Pass0
+ def initialize
+ @line = ''
+ end
+
+ def getline
+ @line = $stdin.readline
+ end
+
+ def is_md
+ @line.start_with? "#"
+ end
+ def section_md
+ section = ""
+ while @line.start_with? "#"
+ section += @line.sub(/^# ?/, '')
+ getline
+ end
+ $stdout.puts "\n\n#{Pandoc::load('markdown', section).to('mediawiki')}\n\n"
+ end
+
+ def is_hd
+ not /(.*)[^<]<<\s*([^<]\S+)/.match(@line).nil?
+ end
+ def section_hd
+ m = /(.*)[^<]<<\s*([^<]\S+)/.match(@line)
+ return if m.nil?
+ prefix = m[1]
+ eot = m[2]
+ getline
+ body = ""
+ while @line != "#{eot}\n"
+ body += @line
+ getline
+ end
+ getline
+ $stdout.puts "\n\n{{hc|#{prefix}|<nowiki>#{body.chomp}</nowiki>}}\n\n"
+ end
+
+ def section_sh
+ section = ""
+ while true
+ if is_md
+ $stdout.puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ section_md
+ section = ""
+ elsif is_hd
+ $stdout.puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ section_hd
+ section = ""
+ elsif @line == "}\n"
+ $stdout.puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ return
+ else
+ if @line.start_with? 'add-unit '
+ $stdout.puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ $stdout.puts "f* {{ic|/#{@line.sub('add-unit ', '').chomp}}}"
+ section = ""
+ getline
+ next
+ end
+ m = /^ln -s (.*) (\S*)$/.match(@line)
+ if not m.nil?
+ $stdout.puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ $stdout.puts "f* {{ic|/#{m[2]}}}: {{ic|-> #{m[1]}}}"
+ section = ""
+ getline
+ next
+ end
+ if @line == "preamble\n" or @line == "postamble" or @line.start_with? 'install -d'
+ getline
+ next
+ end
+ if @line.start_with? 'netctl-enable '
+ $stdout.puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
+ unit="netctl@#{`systemd-escape -- #{@line.sub(/^netctl-enable /, '')}`.chomp}.service"
+ $stdout.puts "f* {{ic|/etc/systemd/system/#{unit}}}"
+ $stdout.puts "f* {{ic|/etc/systemd/system/multi-user.target.wants/#{unit}}}"
+ getline
+ next
+ end
+ m = /^depends\+?=\((.*)\)/.match(@line)
+ if not m.nil?
+ m[1].split(/\s+/).each do |pkg|
+ $stdout.puts "p* {{ic|#{pkg}}"
+ end
+ getline
+ next
+ end
+ m = /^conflicts\+?=\((.*)\)/.match(@line)
+ if not m.nil?
+ $stdout.puts "p* group:{{ic|base}} except for {{ic|#{m[1]}}}"
+ getline
+ next
+ end
+ section += @line
+ getline
+ end
+ end
+ end
+
+ def run
+ while @line != "package() {\n"
+ getline
+ end
+ getline
+ section_sh
+ end
+end
+def pass0
+ Pass0.new.run
+end
+
+def pass1
+ exec('sed', '-r',
+ '-e', 's@^\{\{hc\|add-file ([^|]*)\|(.*)\}\}$@f* {{ic|/\1}}: {{ic|\2}}@',
+ '-e', 's@^\{\{hc\|add-file ([^|]*)\|@f* {{ic|/\1}}\n&@',
+ :in=>$stdin, :out=>$stdout)
+end
+
+class Pass2
+ def initialize
+ @pfix = ''
+ @ffix = ''
+ @body = ''
+ end
+
+ def flush
+ if @pfix != ''
+ $stdout.puts 'Packages installed:'
+ $stdout.puts @pfix.split("\n").sort.join("\n")
+ end
+ if @ffix != ''
+ $stdout.puts 'Files affected:'
+ $stdout.puts @ffix.split("\n").sort.join("\n")
+ end
+ $stdout.puts @body
+ @pfix = ''
+ @ffix = ''
+ @body = ''
+ end
+
+ def run
+ $stdin.each_line do |line|
+ if line.start_with? "p*"
+ @pfix += line[1,line.length]
+ elsif line.start_with? "f*"
+ @ffix += line[1,line.length]
+ elsif line.start_with? '='
+ flush
+ $stdout.puts line
+ else
+ @body += line
+ end
+ end
+ flush
+ end
+end
+def pass2
+ Pass2.new.run
+end
+
+def pass3
+ exec('cat', '-s', :in=>$stdin, :out=>$stdout)
+end
+
+# just a utility function for making pipelines
+def pipeline(p, i, o)
+ ret = []
+ if i == :pipe
+ r, w = IO.pipe
+ i = r
+ ret.push(w)
+ end
+ if o == :pipe
+ r, w = IO.pipe
+ o = w
+ ret.push(r)
+ end
+ pid = fork {
+ $stdin = i
+ $stdout = o
+ ret.each{|fd| fd.close}
+
+ p.call
+ }
+ i.close
+ o.close
+ ret.unshift(pid)
+ return ret
+end
+
+def main
+ # ./pass0 | ./pass1 | ./pass2 | ./pass3
+ _, p0 = pipeline(Proc.new{pass0}, $stdin, :pipe )
+ _, p1 = pipeline(Proc.new{pass1}, p0 , :pipe )
+ _, p2 = pipeline(Proc.new{pass2}, p1 , :pipe )
+ _ = pipeline(Proc.new{pass3}, p2 , $stdout)
+ Process.waitall
+end
+main
diff --git a/pkgbuild2mw.0 b/pkgbuild2mw.0
deleted file mode 100755
index 78efcf5..0000000
--- a/pkgbuild2mw.0
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/env ruby
-# coding: utf-8
-load 'pandoc.rb'
-
-class Translator
- def initialize(file)
- @file = file
- @line = ''
- end
-
- def getline
- @line = @file.readline
- end
-
- def is_md
- @line.start_with? "#"
- end
- def section_md
- section = ""
- while @line.start_with? "#"
- section += @line.sub(/^# ?/, '')
- getline
- end
- puts "\n\n#{Pandoc::load('markdown', section).to('mediawiki')}\n\n"
- end
-
- def is_hd
- not /(.*)[^<]<<\s*([^<]\S+)/.match(@line).nil?
- end
- def section_hd
- m = /(.*)[^<]<<\s*([^<]\S+)/.match(@line)
- return if m.nil?
- prefix = m[1]
- eot = m[2]
- getline
- body = ""
- while @line != "#{eot}\n"
- body += @line
- getline
- end
- getline
- puts "\n\n{{hc|#{prefix}|<nowiki>#{body.chomp}</nowiki>}}\n\n"
- end
-
- def section_sh
- section = ""
- while true
- if is_md
- puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
- section_md
- section = ""
- elsif is_hd
- puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
- section_hd
- section = ""
- elsif @line == "}\n"
- puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
- return
- else
- if @line.start_with? 'add-unit '
- puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
- puts "f* {{ic|/#{@line.sub('add-unit ', '').chomp}}}"
- section = ""
- getline
- next
- end
- m = /^ln -s (.*) (\S*)$/.match(@line)
- if not m.nil?
- puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
- puts "f* {{ic|/#{m[2]}}}: {{ic|-> #{m[1]}}}"
- section = ""
- getline
- next
- end
- if @line == "preamble\n" or @line == "postamble" or @line.start_with? 'install -d'
- getline
- next
- end
- if @line.start_with? 'netctl-enable '
- puts "\n\n{{bc|<nowiki>#{section.chomp}</nowiki>}}\n\n" unless section.gsub("\n", '') == ""
- unit="netctl@#{`systemd-escape -- #{@line.sub(/^netctl-enable /, '')}`.chomp}.service"
- puts "f* {{ic|/etc/systemd/system/#{unit}}}"
- puts "f* {{ic|/etc/systemd/system/multi-user.target.wants/#{unit}}}"
- getline
- next
- end
- m = /^depends\+?=\((.*)\)/.match(@line)
- if not m.nil?
- m[1].split(/\s+/).each do |pkg|
- puts "p* {{ic|#{pkg}}"
- end
- getline
- next
- end
- m = /^conflicts\+?=\((.*)\)/.match(@line)
- if not m.nil?
- puts "p* group:{{ic|base}} except for {{ic|#{m[1]}}}"
- getline
- next
- end
- section += @line
- getline
- end
- end
- end
-
- def run
- while @line != "package() {\n"
- getline
- end
- getline
- section_sh
- end
-end
-
-Translator.new(STDIN).run()
diff --git a/pkgbuild2mw.1 b/pkgbuild2mw.1
deleted file mode 100755
index 6d6aa89..0000000
--- a/pkgbuild2mw.1
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-sed -r \
- -e 's@^\{\{hc\|add-file ([^|]*)\|(.*)\}\}$@f* {{ic|/\1}}: {{ic|\2}}@' \
- -e 's@^\{\{hc\|add-file ([^|]*)\|@f* {{ic|/\1}}\n&@'
diff --git a/pkgbuild2mw.2 b/pkgbuild2mw.2
deleted file mode 100755
index 272a7b6..0000000
--- a/pkgbuild2mw.2
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env ruby
-
-$pfix = ''
-$ffix = ''
-$body = ''
-
-def flush
- if $pfix != ''
- puts 'Packages installed:'
- puts $pfix.split("\n").sort.join("\n")
- end
- if $ffix != ''
- puts 'Files affected:'
- puts $ffix.split("\n").sort.join("\n")
- end
- puts $body
- $pfix = ''
- $ffix = ''
- $body = ''
-end
-
-STDIN.each_line do |line|
- if line.start_with? "p*"
- $pfix += line[1,line.length]
- elsif line.start_with? "f*"
- $ffix += line[1,line.length]
- elsif line.start_with? '='
- flush
- puts line
- else
- $body += line
- end
-end
-flush