ook een versie voor slocate en mooi opties afhandelen
This commit is contained in:
parent
7b0f469d24
commit
ef13833b4e
2 changed files with 133 additions and 3 deletions
|
|
@ -8,8 +8,43 @@
|
|||
|
||||
# Zie ook: http://linux.die.net/man/5/mlocate.db
|
||||
|
||||
# Geen argumenten. Probeert gewoon een bestand met de naam 'mlocate.db'
|
||||
# in de huidige dir te openen
|
||||
require "getoptlong"
|
||||
|
||||
def parse_options
|
||||
@options = {}
|
||||
begin
|
||||
opts = GetoptLong.new(
|
||||
[ "-i", GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ "-h", "--help", GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
opts.quiet=true
|
||||
opts.each do |opt, arg|
|
||||
@options[opt] = arg
|
||||
end
|
||||
if @options["-h"]
|
||||
usage
|
||||
end
|
||||
rescue GetoptLong::InvalidOption
|
||||
print "#{$!}\n"
|
||||
usage
|
||||
end
|
||||
# default values
|
||||
if @options["-i"].nil?
|
||||
@options["-i"] = "slocate.db"
|
||||
end
|
||||
return @options
|
||||
end
|
||||
|
||||
def usage
|
||||
print <<XXX
|
||||
Usage: slocatedb-dump.rb [-i <inputfile>] [-l] [-h]
|
||||
|
||||
-i <inputfile> use <inputfile> for input (default: slocate.db)
|
||||
-h this help message
|
||||
XXX
|
||||
exit
|
||||
end
|
||||
|
||||
|
||||
def arr2long(arr)
|
||||
return (arr[0]<<24) + (arr[1]<<16) + (arr[2]<<8) + arr[3]
|
||||
|
|
@ -23,8 +58,9 @@ def arr2string(arr)
|
|||
return string
|
||||
end
|
||||
|
||||
parse_options
|
||||
|
||||
fh = File.new("mlocate.db", "r")
|
||||
fh = File.new(@options["-i"], "r")
|
||||
|
||||
magic_number=fh.read(8)
|
||||
if magic_number == "\000mlocate"
|
||||
|
|
@ -91,6 +127,10 @@ while true
|
|||
|
||||
curdir=''
|
||||
while (b=fh.read(1)) != "\000"
|
||||
if b.nil?
|
||||
# we're done
|
||||
exit
|
||||
end
|
||||
curdir += b
|
||||
end
|
||||
puts "#{curdir}/"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue