Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open BTree ;; (* Abre o modulo das �rvores *)
- (* M�todo indutivo aplicado a strings. A fun��o cut "separa a cabe�a da cauda", numa string. *)
- let cut s = (* pre: s <> "" *)
- (String.get s 0, String.sub s 1 ((String.length s)-1))
- ;;
- let rec split s = (* parte a string s no primeiro ' ' *)
- if s = "" then ("", "") (* caso base *)
- else
- let (x,xs) = cut s in (* separa cabe�a da cauda *)
- if x = ' ' then ("", xs) (* outro caso base *)
- else let (a,b) = split xs in (* chamada recursiva para a cauda *)
- ((Char.escaped x)^a,b)
- ;;
- (* count -- Displays the number of files contained in the working file system.
- load name -- Loads a new file system and the current path is reset to [].
- show -- Displays the working file system.
- pwd -- Displays the current path, using Unix like notation. For example: /users/jose/documents/lap.
- up -- Changes the current path, moving up one level, if possible.
- down name -- Changes the current path, moving down one level to a specific sub-element, if possible.
- quit -- Exits the command-line interpreter. *)
- ;;
- let z=Dir("root", []);;
- let p=[];;
- (*working file system is set to Dir("root", []) and the initial current path is set to []*)
- let quit () =
- exit 0
- ;;
- let show()=
- show z;;
- let load(name)=
- p=[];
- z=load name;;
- let pwd()=;;
- let up()=
- up p;;
- let count()=countFiles z;;
- let down(name)=
- down p name
- ;;
- let exec comm filename =
- match comm with
- "count" -> count()
- | "load name" -> (name)
- | "show" -> show ()
- | "pwd" -> pwd ()
- | "up" -> up ()
- | "down name"-> down(name)
- | "quit" -> quit ()
- ;;
- let error mesg =
- output_string stderr mesg ;
- output_string stderr "!\n" ;
- flush stderr
- ;;
- let rec main () =
- let z=Dir("root", []);;
- let p=[];;
- (try
- print_string "> " ;
- let line = read_line () in
- let (comm, fileName) = split line in
- exec comm fileName
- with
- End_of_file -> quit ()
- | Sys_error str -> error str
- | _ -> error "Erro") ;
- main ()
- ;;
- main () ;; (* Esta linha faz o programa come�ar a correr aqui *)
Add Comment
Please, Sign In to add comment