#!/usr/bin/env gosh (use gauche.process) ;; ((version parent ...) ...) (define versions '()) ;; string-split is too simple minded, splitting argument can only be ;; only single character: (string-split "string" #\c) ;; string-scan does the job: ;; (string-scan "a:b:c" ":") => 1 ;; (string-scan "aap:noot:mies" ":" 'before) => "aap" ;; (string-scan "aap:noot:mies" ":" 'before*) => (values "aap" ":noot:mies") ;; (string-scan "aap:noot:mies" ":" 'both) => (values "aap" "noot:mies") ;; problem: final record: ;; (string-scan "mies" ":" 'both) => (values #f #f) (define (collect-records-from-string str) (receive (match rest) (string-scan str "\n\n" 'both) (if match (begin (set! versions (cons match versions)) (collect-records-from-string rest)) (set! versions (cons str versions))))) ;; TODO build real support for regex (string-scan doesn't want regex's) (define (string-split string regex) (define (string-split-internal string regex result) (receive (match rest) (string-scan string regex 'both) (if match (begin (set! result (cons match result)) (string-split-internal rest regex result)) (begin (set! result (cons string result)) (reverse result))))) (string-split-internal string regex '())) (define (collect-info) (call-with-input-process "prcs info -f -l" (lambda (port) (collect-records-from-string (port->string port))))) (collect-info) (format #t "~S\n" versions) ;; ----------------------------------------------------------------- ;; ruby version ;; class Version ;; attr_reader :project, :version, :parents ;; ;; def initialize block ;; block = block.split("\n") ;; @project, @version = block[0].split[0..1] ;; @parents = [] ;; block[1..-1].each { |line| ;; case line ;; when /^Parent-Version:\s*(.*)/ ;; @parents << $1 ;; end ;; } ;; end ;; ;; def to_s ;; "(#@version (#{@parents.join(' ')}))" ;; end ;; end ;; ;; class VersionGraph ;; DOTFILE = "prcstree.dot" ;; PSFILE = "prcstree.ps" ;; ;; def initialize info ;; @versions = info.split(/\n\n/).collect { |rec| Version.new(rec) } ;; end ;; ;; def to_lists ;; @versions.each { |v| puts v } ;; end ;; ;; def to_dot ;; File.open(DOTFILE, "w") { |f| ;; f.puts "digraph prcs {" ;; @versions.each { |v| ;; v.parents.each { |p| ;; #f.puts "v#{v.version.gsub('\.', '_')} -> v#{p.gsub('\.', '_')};" ;; f.puts %!"#{v.version}" -> "#{p}";! ;; } ;; } ;; f.puts "}" ;; } ;; system "dot -Tps #{DOTFILE} > #{PSFILE} && gv #{PSFILE} &" ;; end ;; end ;; ;; vg = VersionGraph.new(`prcs info -f -l`) ;; vg.to_lists ;; vg.to_dot ;; ;; Local Variables: ;; mode: gauche ;; End: