From 43583e5795a8010629a1567d7328b0dac3aecfd3 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Thu, 6 Feb 2025 16:15:59 +0100 Subject: [PATCH] fix readme --- README.md | 314 +++++++++++++++++++++++++++----------------- inc/allowed.h | 18 +-- src/prompt/prompt.c | 14 +- 3 files changed, 207 insertions(+), 139 deletions(-) diff --git a/README.md b/README.md index 9350ac0..d85bf12 100644 --- a/README.md +++ b/README.md @@ -1,155 +1,223 @@ # Minishell -======= +A lot of amazing shell stuff ## Dependencies - libreadline-dev - libncurses-dev -## merge info -origen/quinten -> willem: - -ik het TokenType veranderd naar t_token_type vanwege de norm - -Volgens mij had je een off-by-one error in ft_lexer_readword:85 -je moet de null terminator ook meerekenen in de malloc size -```c - if (!(word = malloc(sizeof(char) * (i + 1)))) -``` - +## TODO +- Find absolute path for command input ('/', './', 'cmd') +- Add heredoc to tokenizer +- Environment to `t_list` +- Get environment array (export) +- Preliminary signals +- Define struct for commands, something like ( + ```c + typedef struct s_command + { + char *command; + char *path; + char **args; + int fd_in; + int fd_out; + } t_command; + ``` +) +- Make the `executor`, run a command +- Make a parser to create a command list +- Add redirects, appends, pipe etc. File descriptor functions +- Expand \$ vars & support \$? +- __Bonus:__ Command tree for &&, ||, * ## Allowed Functions -### `` -* `open` - * `int open(const char *pathname, int flags, ...);` - * Opens a file specified by pathname. The flags argument determines the file access mode and file status flags. - -### `` -* `opendir` - * `DIR *opendir(const char *name);` - * Opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream. -* `readdir` - * `struct dirent *readdir(DIR *dirp);` - * Reads the next directory entry from the directory stream pointed to by dirp. -* `closedir` - * `int closedir(DIR *dirp);` - * Closes the directory stream associated with dirp. - -### `` -* `malloc` - * `void *malloc(size_t size);` - * Allocates size bytes of memory and returns a pointer to the allocated memory. -* `free` - * `void free(void *ptr);` - * Frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc. +### `` +* `readline` + * `char *readline(const char *prompt);` + * Reads a line from the terminal with editing capabilities. +* `rl_clear_history` + * `void rl_clear_history(void);` + * Clears the history of lines read by readline. +* `rl_on_new_line` + * `int rl_on_new_line(void);` + * Resets the state to indicate that a new line of input is being read. +* `rl_replace_line` + * `int rl_replace_line(const char *text, int clear_undo);` + * Replaces the contents of the current line with text. +* `rl_redisplay` + * `int rl_redisplay(void);` + * Redisplays the current input line. +* `add_history` + * `void add_history(const char *line);` + * Adds the line to the history list. ### `` * `printf` - * `int printf(const char *format, ...);` - * Sends formatted output to stdout. + * `int printf(const char *format, ...);` + * Sends formatted output to stdout. -### `` -* `stat` - * `int stat(const char *pathname, struct stat *statbuf);` - * Retrieves information about the file pointed to by pathname and fills in the stat structure. -* `lstat` - * `int lstat(const char *pathname, struct stat *statbuf);` - * Similar to stat, but does not follow symbolic links. -* `fstat` - * `int fstat(int fd, struct stat *statbuf);` - * Retrieves information about the file referred to by the open file descriptor fd. - -### `` -* `wait` - * `pid_t wait(int *wstatus);` - * Suspends execution of the calling process until one of its children terminates. -* `waitpid` - * `pid_t waitpid(pid_t pid, int *wstatus, int options);` - * Suspends execution of the calling process until the child specified by pid changes state. -* `wait3` - * `pid_t wait3(int *wstatus, int options, struct rusage *rusage);` - * Similar to wait, but also returns resource usage information. -* `wait4` - * `pid_t wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);` - * Similar to waitpid, but also returns resource usage information. - -### `` -* `signal` - * `void (*signal(int signum, void (*handler)(int)))(int);` - * Sets a function to handle signal signum. -* `sigaction` - * `int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);` - * Examines and changes the action associated with a specific signal. -* `sigemptyset` - * `int sigemptyset(sigset_t *set);` - * Initializes the signal set pointed to by set to exclude all signals. -* `sigaddset` - * `int sigaddset(sigset_t *set, int signum);` - * Adds the individual signal specified by signum to the signal set pointed to by set. -* `kill` - * `int kill(pid_t pid, int sig);` - * Sends the signal sig to the process specified by pid. +### `` +* `malloc` + * `void *malloc(size_t size);` + * Allocates size bytes of memory and returns a pointer to the allocated memory. +* `free` + * `void free(void *ptr);` + * Frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc. ### `` * `write` - * `ssize_t write(int fd, const void *buf, size_t count);` - * Writes up to count bytes from the buffer starting at buf to the file referred to by the file descriptor fd. + * `ssize_t write(int fd, const void *buf, size_t count);` + * Writes up to count bytes from the buffer starting at buf to the file referred to by the file descriptor fd. * `access` - * `int access(const char *pathname, int mode);` - * Checks the file named by pathname for accessibility according to the bit pattern contained in mode. + * `int access(const char *pathname, int mode);` + * Checks the file named by pathname for accessibility according to the bit pattern contained in mode. +* `open` + * `int open(const char *pathname, int flags, ...);` + * Opens a file specified by pathname. The flags argument determines the file access mode and file status flags. * `read` - * `ssize_t read(int fd, void *buf, size_t count);` - * Reads up to count bytes from file descriptor fd into the buffer starting at buf. + * `ssize_t read(int fd, void *buf, size_t count);` + * Reads up to count bytes from file descriptor fd into the buffer starting at buf. * `close` - * `int close(int fd);`q - * Closes the file descriptor fd. + * `int close(int fd);` + * Closes the file descriptor fd. * `fork` - * `pid_t fork(void);` - * Creates a new process by duplicating the calling process. + * `pid_t fork(void);` + * Creates a new process by duplicating the calling process. -### `` -* `readline` - * `char *readline(const char *prompt);` - * Reads a line from the terminal with editing capabilities. -* `rl_clear_history` - * `void rl_clear_history(void);` - * Clears the history of lines read by readline. -* `rl_on_new_line` - * `int rl_on_new_line(void);` - * Resets the state to indicate that a new line of input is being read. -* `rl_replace_line` - * `int rl_replace_line(const char *text, int clear_undo);` - * Replaces the contents of the current line with text. -* `rl_redisplay` - * `int rl_redisplay(void);` - * Redisplays the current input line. -* `add_history` - * `void add_history(const char *line);` - * Adds the line to the history list. +### `` +* `wait` + * `pid_t wait(int *wstatus);` + * Suspends execution of the calling process until one of its children terminates. +* `waitpid` + * `pid_t waitpid(pid_t pid, int *wstatus, int options);` + * Suspends execution of the calling process until the child specified by pid changes state. +* `wait3` + * `pid_t wait3(int *wstatus, int options, struct rusage *rusage);` + * Similar to wait, but also returns resource usage information. +* `wait4` + * `pid_t wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);` + * Similar to waitpid, but also returns resource usage information. + +### `` +* `signal` + * `void (*signal(int signum, void (*handler)(int)))(int);` + * Sets a function to handle signal signum. +* `sigaction` + * `int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);` + * Examines and changes the action associated with a specific signal. +* `sigemptyset` + * `int sigemptyset(sigset_t *set);` + * Initializes the signal set pointed to by set to exclude all signals. +* `sigaddset` + * `int sigaddset(sigset_t *set, int signum);` + * Adds the individual signal specified by signum to the signal set pointed to by set. +* `kill` + * `int kill(pid_t pid, int sig);` + * Sends the signal sig to the process specified by pid. + +### `` +* `exit` + * `void exit(int status);` + * Causes normal process termination and returns an exit status to the host environment. + +### `` +* `stat` + * `int stat(const char *pathname, struct stat *statbuf);` + * Retrieves information about the file pointed to by pathname and fills in the stat structure. +* `lstat` + * `int lstat(const char *pathname, struct stat *statbuf);` + * Similar to stat, but does not follow symbolic links. +* `fstat` + * `int fstat(int fd, struct stat *statbuf);` + * Retrieves information about the file referred to by the open file descriptor fd. + +### `` +* `unlink` + * `int unlink(const char *pathname);` + * Deletes a name from the filesystem. +* `pipe` + * `int pipe(int pipefd[2]);` + * Creates a pipe, a unidirectional data channel that can be used for interprocess communication. +* `dup` + * `int dup(int oldfd);` + * Duplicates the file descriptor oldfd. +* `dup2` + * `int dup2(int oldfd, int newfd);` + * Duplicates oldfd to newfd, closing newfd first if necessary. +* `execve` + * `int execve(const char *pathname, char *const argv[], char *const envp[]);` + * Executes the program referred to by pathname. +* `getcwd` + * `char *getcwd(char *buf, size_t size);` + * Gets the current working directory and stores it in the buffer pointed to by buf. +* `chdir` + * `int chdir(const char *path);` + * Changes the current working directory to the directory specified in path. + +### `` +* `opendir` + * `DIR *opendir(const char *name);` + * Opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream. +* `readdir` + * `struct dirent *readdir(DIR *dirp);` + * Reads the next directory entry from the directory stream pointed to by dirp. +* `closedir` + * `int closedir(DIR *dirp);` + * Closes the directory stream associated with dirp. + +### `` +* `strerror` + * `char *strerror(int errnum);` + * Returns a pointer to the textual representation of the error number errnum. +* `perror` + * `void perror(const char *s);` + * Prints a descriptive error message to stderr. + +### `` +* `isatty` + * `int isatty(int fd);` + * Tests whether fd is an open file descriptor referring to a terminal. +* `ttyname` + * `char *ttyname(int fd);` + * Returns a pointer to the null-terminated pathname of the terminal associated with fd. +* `ttyslot` + * `int ttyslot(void);` + * Returns the index of the current user's terminal in the user accounting file. + +### `` +* `ioctl` + * `int ioctl(int fd, unsigned long request, ...);` + * Manipulates the underlying device parameters of special files. + +### `` +* `getenv` + * `char *getenv(const char *name);` + * Searches the environment list for a string that matches the name. ### `` * `tcsetattr` - * `int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);` - * Sets the parameters associated with the terminal referred to by fd. + * `int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);` + * Sets the parameters associated with the terminal referred to by fd. * `tcgetattr` - * `int tcgetattr(int fd, struct termios *termios_p);` - * Gets the parameters associated with the terminal referred to by fd. + * `int tcgetattr(int fd, struct termios *termios_p);` + * Gets the parameters associated with the terminal referred to by fd. ### `` * `tgetent` - * `int tgetent(char *bp, const char *name);` - * Loads the entry for name from the termcap database. + * `int tgetent(char *bp, const char *name);` + * Loads the entry for name from the termcap database. * `tgetflag` - * `int tgetflag(const char *id);` - * Gets the boolean entry for id from the termcap database. + * `int tgetflag(const char *id);` + * Gets the boolean entry for id from the termcap database. * `tgetnum` - * `int tgetnum(const char *id);` - * Gets the numeric entry for id from the termcap database. + * `int tgetnum(const char *id);` + * Gets the numeric entry for id from the termcap database. * `tgetstr` - * `char *tgetstr(const char *id, char **area);` - * Gets the string entry for id from the termcap database. + * `char *tgetstr(const char *id, char **area);` + * Gets the string entry for id from the termcap database. * `tgoto` - * `char *tgoto(const char *cap, int col, int row);` - * Returns a cursor addressing string for the given capability cap. + * `char *tgoto(const char *cap, int col, int row);` + * Returns a cursor addressing string for the given capability cap. * `tputs` - * `int tputs(const char *str, int affcnt, int (*putc)(int));` - * Outputs the string str with padding. + * `int tputs(const char *str, int affcnt, int (*putc)(int));` + * Outputs the string str with padding. + diff --git a/inc/allowed.h b/inc/allowed.h index 2003010..e562c19 100644 --- a/inc/allowed.h +++ b/inc/allowed.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* allowed.h :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/02/04 16:13:11 by whaffman #+# #+# */ -/* Updated: 2025/02/04 16:13:12 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* allowed.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/04 16:13:11 by whaffman #+# #+# */ +/* Updated: 2025/02/06 16:14:44 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,12 +19,12 @@ # include # include # include +# include +# include # include # include # include # include -# include -# include # include # include diff --git a/src/prompt/prompt.c b/src/prompt/prompt.c index 46713fe..20cd44f 100644 --- a/src/prompt/prompt.c +++ b/src/prompt/prompt.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* prompt.c :+: :+: */ -/* +:+ */ -/* By: whaffman +#+ */ -/* +#+ */ -/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */ -/* Updated: 2025/02/05 17:05:12 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* prompt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */ +/* Updated: 2025/02/06 16:12:02 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */