add comments
This commit is contained in:
parent
9dcc874357
commit
838ee3d216
@ -21,12 +21,20 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the logged in user's username.
|
||||||
|
* @return Returns the logged in user's username.
|
||||||
|
*/
|
||||||
char *get_user() {
|
char *get_user() {
|
||||||
struct passwd *pass;
|
struct passwd *pass;
|
||||||
pass = getpwuid(getuid());
|
pass = getpwuid(getuid());
|
||||||
return pass->pw_name;
|
return pass->pw_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current working directory of the shell.
|
||||||
|
* @return Returns the current working directory.
|
||||||
|
*/
|
||||||
char *get_working_directory() {
|
char *get_working_directory() {
|
||||||
char *cwd = NULL;
|
char *cwd = NULL;
|
||||||
cwd = getcwd(NULL, PATH_MAX);
|
cwd = getcwd(NULL, PATH_MAX);
|
||||||
@ -39,6 +47,9 @@ char *get_working_directory() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the console line before the user input.
|
||||||
|
*/
|
||||||
void print_input_line() {
|
void print_input_line() {
|
||||||
char *name = get_user();
|
char *name = get_user();
|
||||||
char *cwd = get_working_directory();
|
char *cwd = get_working_directory();
|
||||||
|
@ -19,10 +19,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "console_line.h"
|
#include "console_line.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove new line from the end of a string.
|
||||||
|
* @param line The string to remove the new line from.
|
||||||
|
*/
|
||||||
void remove_new_line(char* line) {
|
void remove_new_line(char* line) {
|
||||||
line[strcspn(line, "\n")] = 0;
|
line[strcspn(line, "\n")] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the loop that checks for user input and acts on it.
|
||||||
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
size_t buffer_size = 0;
|
size_t buffer_size = 0;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main entry point to the program.
|
||||||
|
* @param argc The number of arguments passed.
|
||||||
|
* @return Returns 0 on success or an error code on failure.
|
||||||
|
*/
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
loop();
|
loop();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Loading…
Reference in New Issue
Block a user