From b0a14e013b318fa87714414b8ece95780527bddf Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Fri, 18 Sep 2015 11:51:28 +0100 Subject: Initial commit --- ddp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 ddp (limited to 'ddp') diff --git a/ddp b/ddp new file mode 100755 index 0000000..d3bddf3 --- /dev/null +++ b/ddp @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby + +cmd = ['dd'] +countarg = nil + +def decr(mult) + return { + 'c' => ['c', 1], + 'w' => ['c', 2], + 'b' => ['c', 512], + 'kB' => ['w', 500], + 'K' => ['w', 512], + 'MB' => ['kB', 1000], + 'M' => ['K', 1024], + 'GB' => ['MB', 1000], + 'G' => ['M', 1024], + 'TB' => ['GB', 1000], + 'T' => ['G', 1024], + 'PB' => ['TB', 1000], + 'P' => ['T', 1024], + 'EB' => ['PB', 1000], + 'E' => ['P', 1024], + 'ZB' => ['EB', 1000], + 'Z' => ['E', 1024], + 'YB' => ['ZB', 1000], + 'Y' => ['Z', 1024], + }[mult] +end + +def parsecount(countarg) + if countarg =~ /^(\d+)(c|w|b|kB|K|[MGTPEZY]B?)$/ + if $1 == '1' then + unit, num = decr($2) + count = "count=1#{unit}" + seeks = (0...num).map do |i| + "seek=#{i}#{unit}" + end + else + count = "count=1#{$2}" + seeks = (0...($1.to_i)).map do |i| + "seek=#{i}#{$2}" + end + end + return count, seeks + else + puts "BAD COUNT" + exit 1 + end +end + +ARGV.each do |arg| + if arg =~ /count=(.*)/ then + countarg=$1 + else + cmd << arg + end +end + +if countarg.nil? then + run = cmd.join(' ') + puts "*** " + run + system(run) +else + count, seeks = parsecount(countarg) + seeks.each do |seek| + run = (cmd + [seek, count]).join(' ') + puts "*** " + run + system(run) + end +end -- cgit v1.2.1