- Implemented basic functions (init, touch, mkdir)
- Used
while(1)andfgetsto obtain data - Used
strtokto store command arguments in achar* - Implemented 'ls' and 'stop' commands
- Implemented rm, rmdir, and pwd operations
- Encountered most obstacles on this day
- Deletion operations generated many errors due to traversing
head_children_filesandhead_children_dirslists - Spent several hours debugging
- Used valgrind and GDB (Valgrind reported the most errors)
The designed program follows this hierarchy:
.... ........
^ ^ ^
\ | /
d1_1 d2_1 f3_1
^ ^ ^
\ | /
d1 d2 d3 f1 f2
^ ^ ^ ^ ^
\ | | | /
home(directory)
Represented as:
|d1_1
|d1|d2_1
home|d2
|d3|f3_1
|f1
|f2
next: Move to the neighboring directoryhead_children_dirs: First element in the list of subdirectoriesparent: Parent of subdirectories (home directory is the root)
Example:
- In directory d1_1:
d1_1->nextleads to d2_1d1_1->parentis d1d1->head_children_dirsis d1_1
next: Move to the neighboring fileparent: Parent of files in the current directory
Example:
- When pwd returns /home:
f1->parentis homef1->nextis f2
- Created
create_conditionfunction to check for file/directory existence searchtraverses file list,findtraverses subdirectory list- Returns 1 only if file/directory not found in lists
- Allocates memory and adds to end of respective list using while() traversal
- Displays subdirectories list first, then files list
- Uses
aux1_helperfor subdirectories andaux2_helperfor files - Checks for end of lists with
if(...!=NULL)
- Verifies existence of target directory
- Uses sequences
*target = findor*target = (*target)->head_children_dirs - For "..", changes current directory to its parent
- Uses recursion to deallocate memory
- Takes root of hierarchy (home directory) as argument
aux1_helperfrees memory for file list in a subdirectoryaux2_helperuses recursion to traverse subdirectories
- Traverses respective lists to find and delete items
rmdircallsstopfunction if directory contains subdirectories/files
- Uses helper variable to build path string
- Traverses up to root, concatenating directory names
- Implemented recursively
- Uses
aux_iteratorto move towards last-level subdirectory - Displays tree form using
printf("%*s\n",4*level+strlen(string),string)
- Checks conditions: oldname must exist, newname must not
- Moves file/directory to end of list under specified conditions
- Handles all cases: item at beginning, middle, or end of list
- Uses
fgetsto read input line - Uses
strtokto obtain command arguments - Uses
strcspnto handle newline character fromfgets - Implements command execution in a
while(1)loop - Program ends on 'stop' command