summary refs log blame commit diff stats
path: root/code/directory.rb
blob: 5c6e84c1ede3af99579f942b51b726d96bc2b59b (plain) (tree)

































































                                                              
# A Class that contains data about directories
class Directory
	class LoadStatus
		# @n contains a three bit number: x3x2x1
		# x1:
		# 0 = not scheduled
		# 1 = scheduled
		# x3x2:
		# 00 = nothing loaded
		# 01 = got the list of files
		# 10 = <undefined>
		# 11 = got the list of files and entry objects
		def initialize(n = 0)
			@n = 0
		end

		def got_files?
			# is bit 2 nd 3 == 01
			return n & 2 == 2
		end

		def scheduled?
			# is the first bit 1?
			return n & 1 == 1
		end

		def got_objects?
			return n & 4 == 4
		end
		attr_accessor :n
	end

	def initialize(path)
		@path = path
		@status = LoadStatus.new(0)
		@files = []
		@sort_time = nil
		@mtime = nil
#		@width = 1000
		@read = false
		@free_space = nil
		@empty = true
		@scheduled = false
	end

	# {{{ Trivial
	def inspect
		return "<Directory: #{path}>"
	end
	alias to_s inspect

	def size
		return @files.size
	end

	def not_loaded?
		return @level == 0
	end
	def file_list_loaded?
		return @level >= 1
	end
	def ready?
		return @level >= 2
	end
	# }}}
end
epresentation # setup # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # append-byte-hex(_test-stream, 0xa) # exercises digit, non-digit as well as leading zero # . . push args 68/push 0xa/imm32 68/push _test-stream/imm32 # . . call e8/call append-byte-hex/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-stream-equal(_test-stream, "0a", msg) # . . push args 68/push "F - test-append-byte-hex"/imm32 68/push "0a"/imm32 68/push _test-stream/imm32 # . . call e8/call check-stream-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . end c3/return write-int32-hex: # f: (addr stream byte), n: int # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp $write-int32-hex:hex-prefix: # write(f, "0x") # . . push args 68/push "0x"/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp $write-int32-hex:rest: # write-int32-hex-bits(f, n, 32) # . . push args 68/push 0x20/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call write-int32-hex-bits/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $write-int32-hex:end: # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return # print rightmost 'bits' of 'n' # bits must be multiple of 4 write-int32-hex-bits: # f: (addr stream byte), n: int, bits: int # pseudocode: # bits -= 4 # while true # if (bits < 0) break # eax = n >> bits # eax = eax & 0xf # append-byte(f, AL) # bits -= 4 # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax 51/push-ecx # ecx = bits-4 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 . # copy *(ebp+16) to ecx 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32 # subtract from ecx $write-int32-hex-bits:loop: # if (bits < 0) break 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32 # compare ecx 7c/jump-if-< $write-int32-hex-bits:end/disp8 # eax = n >> bits 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . . # shift eax right by ecx bits, padding zeroes # eax = to-hex-char(AL) 25/and-eax 0xf/imm32 e8/call to-hex-char/disp32 # append-byte(f, AL) # . . push args 50/push-eax ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call append-byte/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # bits -= 4 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32 # subtract from ecx eb/jump $write-int32-hex-bits:loop/disp8 $write-int32-hex-bits:end: # . restore registers 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-write-int32-hex: # - check that write-int32-hex prints the hex textual representation # setup # . clear-stream(_test-stream) # . . push args 68/push _test-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # write-int32-hex(_test-stream, 0x8899aa) # . . push args 68/push 0x8899aa/imm32 68/push _test-stream/imm32 # . . call e8/call write-int32-hex/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-stream-equal(_test-stream, "0x008899aa", msg) # . . push args 68/push "F - test-write-int32-hex"/imm32 68/push "0x008899aa"/imm32 68/push _test-stream/imm32 # . . call e8/call check-stream-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # . end c3/return # . . vim:nowrap:textwidth=0