Guest User

Untitled

a guest
Jul 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. open BTree ;; (* Abre o modulo das �rvores *)
  2.  
  3. (* M�todo indutivo aplicado a strings. A fun��o cut "separa a cabe�a da cauda", numa string. *)
  4. let cut s = (* pre: s <> "" *)
  5. (String.get s 0, String.sub s 1 ((String.length s)-1))
  6. ;;
  7. let rec split s = (* parte a string s no primeiro ' ' *)
  8. if s = "" then ("", "") (* caso base *)
  9. else
  10. let (x,xs) = cut s in (* separa cabe�a da cauda *)
  11. if x = ' ' then ("", xs) (* outro caso base *)
  12. else let (a,b) = split xs in (* chamada recursiva para a cauda *)
  13. ((Char.escaped x)^a,b)
  14. ;;
  15.  
  16. (* count -- Displays the number of files contained in the working file system.
  17. load name -- Loads a new file system and the current path is reset to [].
  18. show -- Displays the working file system.
  19. pwd -- Displays the current path, using Unix like notation. For example: /users/jose/documents/lap.
  20. up -- Changes the current path, moving up one level, if possible.
  21. down name -- Changes the current path, moving down one level to a specific sub-element, if possible.
  22. quit -- Exits the command-line interpreter. *)
  23. ;;
  24. let z=Dir("root", []);;
  25. let p=[];;
  26.  
  27. (*working file system is set to Dir("root", []) and the initial current path is set to []*)
  28. let quit () =
  29. exit 0
  30. ;;
  31. let show()=
  32. show z;;
  33. let load(name)=
  34. p=[];
  35. z=load name;;
  36. let pwd()=;;
  37. let up()=
  38. up p;;
  39. let count()=countFiles z;;
  40. let down(name)=
  41. down p name
  42. ;;
  43.  
  44. let exec comm filename =
  45. match comm with
  46. "count" -> count()
  47. | "load name" -> (name)
  48. | "show" -> show ()
  49. | "pwd" -> pwd ()
  50. | "up" -> up ()
  51. | "down name"-> down(name)
  52. | "quit" -> quit ()
  53. ;;
  54. let error mesg =
  55. output_string stderr mesg ;
  56. output_string stderr "!\n" ;
  57. flush stderr
  58. ;;
  59. let rec main () =
  60. let z=Dir("root", []);;
  61. let p=[];;
  62. (try
  63. print_string "> " ;
  64. let line = read_line () in
  65. let (comm, fileName) = split line in
  66. exec comm fileName
  67. with
  68. End_of_file -> quit ()
  69. | Sys_error str -> error str
  70. | _ -> error "Erro") ;
  71. main ()
  72. ;;
  73.  
  74. main () ;; (* Esta linha faz o programa come�ar a correr aqui *)
Add Comment
Please, Sign In to add comment