Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. The goal of this assignment is to write a C++ program that provides a basic directory maintenance simulator to process UNIX/Linux-style commands.
  2.  
  3.  
  4.  
  5.  
  6. we could use a binary tree structure where one branchis essentially a linked list of sibling nodes at a given level, and the other branch is a pointer to the contents of the given directory. Pictorially,the data structure would look like this:
  7.  
  8.  
  9. For simplicity, we will use the same type of node for a file or a directory.
  10.  
  11. Requirements for this assignment:
  12.  
  13. We will simulate several of the UNIX command-line operating system commandsfor a directory system in order to add directories, add files, list directory contents, etc.
  14.  
  15. We will implement the following commands:
  16. ls // lists all filesand directories in the current directory, indicating which (file or directory)it is
  17. mkdir <dirname> // creates a new directory if it does not alreadyexist
  18. cd <dirname> // changes into specified directory ifit exists
  19. cd .. // changes to the parentdirectory
  20. pwd // specifies the current directory as: <yourname>/root/nextdir/etc/
  21. addf <filename> // adds a file to the current directory
  22.  
  23. mv <fname1> <fname2> // change the name of the file or directory to the new name
  24.  
  25. cp <fname1> <fname2> // copy file or folder to the new name
  26.  
  27.  
  28. rm <filename> // locate and remove the file or directory
  29. bye // ends the session
  30.  
  31. whereis <filename> // show path to first occurrence of file or directory if it exists
  32.  
  33. A technical note:
  34. Think of the structure for a Node in this system. The cd .. command suggests that it will be really critical to be able to navigate from a given node to that node's parent. Does it appear that the second picture above would make such a process efficient? One other thought. You will REALLY want to practice drawing how your pointers get set as you develop this program!!
  35.  
  36. Program execution:
  37. This assignment will simulate an interactive program by reading the commands from a file. Commands will be in the file, one per line. You will NOT have to construct commands from multiple lines and SHOULD NOT code your progam to work that way. We will adopt the approach of running an interactive program non-interactively for two reasons:
  38. •It will illustrate that you can test interactive programs without having to do all the typing (most important)
  39.  
  40. •It will simplify life for the person grading the assignment (me in this case)
  41.  
  42.  
  43. Error Checking:
  44.  
  45.  
  46. This assignment will require quite a bit of error checking. For instance, you should not be able to make a file or directory in a directory that already has a file or directory by that name. You obviously cannot switch into a directory that is not there, and you cannot switch to the parent directory of your root directory (although UNIX might permit you to do this if the System Administrator is not too picky). The data structure will be available in the background and will grow as we add subdirectories and files, or shrink as we remove them. Note the use of the $ as the command prompt - just like a typical command-line system!!
  47.  
  48. Here is a typical output of a program run:
  49. $ pwd
  50. coffey/root/
  51. $ mkdir abc
  52. abc
  53. $ cd abc
  54. coffey/root/abc/
  55. $ addf f3
  56. $ addf f2
  57. $ addf f1
  58. $ ls
  59. F f1
  60. F f2
  61. F f3
  62. $ mkdir def
  63. def
  64. $ ls
  65. D def
  66. F f1
  67. F f2
  68. F f3
  69. $ cd cdf
  70. cdf is not located in abc
  71. $ cd def
  72. coffey/root/abc/def/
  73. $ pwd
  74. coffey/root/abc/def/
  75.  
  76. $ whereis f3
  77.  
  78. coffey/root/abc/
  79.  
  80. $ whereis qwerty
  81.  
  82. qwerty not found
  83.  
  84. $ cd ..
  85. coffey/root/abc/
  86. $ ls
  87. D def
  88. F f1
  89. F f2
  90. F f3
  91. $ cd ..
  92. coffey/root/
  93. $ pwd
  94. coffey/root/
  95. $ ls
  96. D abc
  97. $ cd abc
  98. coffey/root/abc/
  99. $ pwd
  100. coffey/root/abc/
  101. $ ls
  102. D def
  103. F f1
  104. F f2
  105. F f3
  106.  
  107. $ rm f5
  108.  
  109. f5 is not in coffey/root/abc/
  110.  
  111. $ rm f2
  112.  
  113. $ ls
  114.  
  115. D def
  116. F f1
  117. F f3
  118.  
  119. $ mv f3 file3
  120.  
  121. $ ls
  122.  
  123. D def
  124. F f1
  125. F file3
  126. $ bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement