Skip to content

Commit

Permalink
Merge pull request #2 from dr8co/main
Browse files Browse the repository at this point in the history
Merge main into stable
  • Loading branch information
dr8co authored Jan 20, 2023
2 parents d2221b8 + 345856c commit eecac07
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 77 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Ian Duncan
Copyright (c) 2023 Ian Duncan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* [Other features](#other-features)
* [Uninstallation](#uninstallation)
* [Examples](#examples)
* [Unsupported Functionalities](#unsupported-functionalities-yet)
* [Caveats](#caveats)
* [Acknowledgement](#acknowledgement)

## Introduction
Expand Down Expand Up @@ -220,10 +220,11 @@ normal@prompt:bush$ echo $?
98
```

## Unsupported Functionalities (yet)
## Caveats

* Command separators `;`, `||`, `&&`.
* Background jobs.
* Command separators `;`, `||`, `&&` are not supported.
* No support for background jobs.
* Wildcard expansion/ matching is not fully stable.

## Acknowledgement

Expand Down
4 changes: 2 additions & 2 deletions man/burning-bush.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH man 1 "11 December 2022" "1.00" "The Burning Bush man page"
.TH man 1 "11 December 2023" "1.00" "The Burning Bush man page"
.SH NAME
.B The Burning Bush
- A simple UNIX command interpreter.
Expand All @@ -9,7 +9,7 @@

.SH COPYRIGHT
.B The Burning Bush
is Copyright (C) 2022 by Ian Duncan and licensed under the MIT license.
is Copyright (C) 2023 by Ian Duncan and licensed under the MIT license.

.SH DESCRIPTION
.B The Burning Bush
Expand Down
11 changes: 11 additions & 0 deletions src/arrays.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* @file arrays.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for functions to manipulate arrays.
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2023
*
*/

#include <stdio.h>
#include <stdlib.h>
#include "main.h"
Expand Down
27 changes: 17 additions & 10 deletions src/directories.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* @file directories.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for directory-related functions.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

#include "main.h"
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -17,20 +18,23 @@
extern char *user, hostname[256], cwd[PATH_MAX];
extern char *home, *prompt;
extern int cmd_count;
extern char *ret_dir;

/**
* @brief Changes the shell working directory.
* @return 0 if directory is changed, -1 otherwise.
*/
int change_directory() {
char *old_dir = getenv("OLDPWD");
char *old_dir;

old_dir = getenv("OLDPWD");

// Handle 'cd', 'cd ~' and 'cd ~/' commands to change working directory to home directory.
if ((args[1] == NULL) || (str_cmp(args[1], "~") == 0) || (str_cmp(args[1], "~/") == 0)) {
if (chdir(home) == 0) {
setenv("OLDPWD", cwd, 1);
setenv("PWD", home, 1);
getcwd(cwd, sizeof(cwd));
ret_dir = getcwd(cwd, sizeof(cwd));

// Update the prompt.
free(prompt);
Expand All @@ -46,7 +50,7 @@ int change_directory() {
if (chdir(old_dir) == 0) {
setenv("PWD", old_dir, 1);
setenv("OLDPWD", cwd, 1);
getcwd(cwd, sizeof(cwd));
ret_dir = getcwd(cwd, sizeof(cwd));
printf("%s\n", old_dir);

// Update the prompt.
Expand All @@ -60,7 +64,7 @@ int change_directory() {
if (chdir(home) == 0) {
setenv("PWD", home, 1);
setenv("OLDPWD", cwd, 1);
getcwd(cwd, sizeof(cwd));
ret_dir = getcwd(cwd, sizeof(cwd));
printf("%s\n", home);

// Update the prompt.
Expand All @@ -84,10 +88,10 @@ int change_directory() {
// Change working directory to the specified directory in the argument of the 'cd' command.
else {
char new_dir[PATH_MAX];
getcwd(new_dir, sizeof(new_dir));
ret_dir = getcwd(new_dir, sizeof(new_dir));
setenv("OLDPWD", cwd, 1);
setenv("PWD", new_dir, 1);
getcwd(cwd, sizeof(cwd));
ret_dir = getcwd(cwd, sizeof(cwd));

// Update the prompt.
free(prompt);
Expand All @@ -104,6 +108,9 @@ int change_directory() {
void print_working_dir() {
if (*cwd) {
printf("%s\n", cwd);
} else
} else if (*ret_dir){
printf("%s", ret_dir);
}
else
perror("error in reading current directory");
}
6 changes: 3 additions & 3 deletions src/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file environment.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for manipulating shell environment.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand Down
6 changes: 3 additions & 3 deletions src/execution.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file execution.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for functions that handle execution of commands.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand Down
6 changes: 3 additions & 3 deletions src/fileops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file fileops.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for file operations
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand Down
10 changes: 5 additions & 5 deletions src/get_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file get_info.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for functions to extract information.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand All @@ -16,7 +16,7 @@
#include <stdio.h>

char *user = NULL, hostname[256], cwd[PATH_MAX];
char *home = NULL, *prompt = NULL;
char *home = NULL, *prompt = NULL, *ret_dir;

/**
* @brief Gets the username (and home directory) of the current user.
Expand Down Expand Up @@ -68,7 +68,7 @@ void get_hostname() {
void init_shell() {
get_username();
get_hostname();
getcwd(cwd, sizeof(cwd));
ret_dir = getcwd(cwd, sizeof(cwd));
if (!home) {
home = getenv("HOME");
if (!home)
Expand Down
23 changes: 18 additions & 5 deletions src/globs.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* @file globs.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for glob operations.
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2023
*
*/

#include "main.h"
#include <glob.h>
#include <stdio.h>
Expand All @@ -7,6 +18,8 @@
* @brief Check if a string contains a wildcard character.
* @param str the string to check.
* @return 1 if a wildcard character is present, 0 otherwise.
* @note This is a minimal function, and might return 1 for a string
* without a wildcard character.
*/
int has_wildcard(const char *str) {
if (!str)
Expand All @@ -17,7 +30,7 @@ int has_wildcard(const char *str) {
return 1;

if (*(str + i) == '[') {
for (unsigned int j = i + 1; *(str + j) != '\0' && !is_space(*(str + j)); ++j) {
for (unsigned int j = i + 2; *(str + j) != '\0' && !is_space(*(str + j)); ++j) {
if (*(str + j) == ']')
return 1;
}
Expand Down Expand Up @@ -45,11 +58,11 @@ int replace_pattern(const char *str, glob_t *glob_buf) {
char **expand_globs(const char *string) {
glob_t globBuff;
char **exp;
unsigned int i = 0;
size_t i = 0;
int ret;

ret = replace_pattern(string, &globBuff);
exp = malloc(sizeof(char *) * 1024 * 2);
exp = malloc(sizeof(char *) * 4096);

switch (ret) {
case 0:
Expand Down Expand Up @@ -94,8 +107,8 @@ void process_globs() {
args[j] = str_dup(args_expanded[j]);
}

for (int j = 0; expanded[j]; ++j) {
free(expanded[j]);
for (int k = 0; expanded[k]; ++k) {
free(expanded[k]);
}

free(expanded);
Expand Down
6 changes: 3 additions & 3 deletions src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file help.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for help-related functions.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-02-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand Down
6 changes: 3 additions & 3 deletions src/help_msgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file help_msgs.c
* @author Ian Duncan (dr8co@duck.com)
* @brief file for help messages.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand Down
12 changes: 6 additions & 6 deletions src/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file history.c
* @author Ian Duncan (dr8co@duck.com)
* @brief source file for manipulation of shell history.
* @version 1.0
* @date 2022-12-11
* @version 2.1
* @date 2023-01-21
*
* @copyright Copyright (c) 2022
* @copyright Copyright (c) 2023
*
*/

Expand Down Expand Up @@ -57,7 +57,7 @@ void write_history() {
int fd_out, ret_write, len;
char input_data[2048];
line_number++;
char no[10];
char no[12];
sprintf(no, "%d", line_number);
str_cpy(input_data, " ");
str_cat(input_data, no);
Expand Down Expand Up @@ -159,7 +159,7 @@ int is_histfile_full() {
*/
void delete_histfile() {
if (unlink(history_file) < 0) {
printf("Maximum history record reached. Please delete history file\n");
printf("at %s to avoid unnecessary errors/bugs.\n", history_file);
printf("An error occurred while deleting the shell history\n. Please delete it manually"
"at %s to avoid unnecessary errors/bugs.\n", history_file);
}
}
Loading

0 comments on commit eecac07

Please sign in to comment.