Skip to content

fractalfox01/ft_ls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FT_LS - A 42 Silicon Valley Project

Description

Ft_ls is the first project in the systems branch.

The Project outline is to recreate the functionality of the ls command.

Running version:

FreeBSD: src/bin/ls/ls.c,v 1.66 2002/09/21 01:28:36 wollman Ex

Located via -> https://opensource.apple.com/source/file_cmds/file_cmds-230/ls/

Our goal is to recreate the program with flags l ('ell'), r, a, t, R.

l flag: long list format (drw-rw-r-- 1 root wheel 0 Apr 20 11:42 fileA)

r flag: reverse output

a flag: print hidden files/directories along with normal output

t flag: sort output by time last modified

R flag: Recursivley interate through all subdirectories

The implementation is not allowed to segfault or fail for any reason. The program cannot have any leaks. The format of the source code must follow strict format guidelines employed by 42. This is the sole reason for all of the funky functions and the spacing of each program. This task is carried out 'after' writting readable code.

Along with the other requirments we are restricted by system functions that are available to us. The allowed functions for this project are:

write, opendir, readdir, closedir, stat,

lstat, getpwuid, getgrgid, listxattr, getxattr

time, ctime, readlink, malloc, free,

perror, strerror, exit

Plus, anything we've created for our libft and/or printf projects/implementations.

For this project i've refrained from including my printf implementation due to the large amount of added work each call represents and because of the time sensitivity of the program during larger recursive calls it must handle.

I've chosen to implement merge sort for all sorting (lexographical and time).

The program uses a few stacks for storing output data but sorts using a 2d character array.

The time complexity of merge sort is O(NLogN) and the lookup of each sorted output is O(N)

O(n) + O(n log(n)) = O(n log(n)) ...Sound about right??

Output is not buffered and is noticeably slower during large recursive calls.

Program Features

My implementation covers all required flags plus the bonus flags A, c, i.

A flag: same as the (a flag) except with "." and ".." directories omitted.

c flag: when used with the (t flag) sort time by last (file change). When used with the (l flag) sort by creation time and output modification time. when used with the (l flag) and (t flag) sort by and output creation time.

i flag: include the inode of each file/directory with output

Installing && Using This Program:

requires git

headers and src/ls_get_info3.c modified to run on https://repl.it

From a command line; clone the repository.

$> git clone https://github.com/fractalfox01/ft_ls.git
$> cd ft_ls
$> make
$> ./ft_ls -al
total 696
drwxr-xr-x  1 runner  runner     154 Apr  6 00:42 .
drwxr-xr-x  1 runner  runner    4096 Apr  5 23:58 ..
drwxr-xr-x  1 runner  runner     168 Apr  5 23:58 .git
-rw-r--r--  1 runner  runner      27 Apr  5 23:58 .replit
-rw-r--r--  1 runner  runner    2615 Apr  5 23:58 README.md
-rw-r--r--  1 runner  runner      11 Apr  5 23:58 author
-rw-r--r--  1 runner  runner    1820 Apr  5 23:58 color_table.txt
-rwxr-xr-x  1 runner  runner  147256 Apr  6 00:42 ft_ls
drwxr-xr-x  1 runner  runner      28 Apr  6 00:39 includes
drwxr-xr-x  1 runner  runner      58 Apr  6 00:42 libft
-rw-r--r--  1 runner  runner  182102 Apr  6 00:42 libft.a
-rw-r--r--  1 runner  runner    1192 Apr  5 23:58 makefile
drwxr-xr-x  1 runner  runner     794 Apr  6 00:42 srcft_ls

About

Ls project for 42

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages