Skip to content

Commit 8b9b199

Browse files
author
Slipstream_Max
committed
main
0 parents  commit 8b9b199

16 files changed

+737
-0
lines changed

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"command_exec.h": "c",
4+
"history_log.h": "c",
5+
"pipe_redirect.h": "c"
6+
}
7+
}

.vscode/tasks.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "cppbuild",
5+
"label": "C/C++: gcc build active file",
6+
"command": "/usr/bin/gcc",
7+
"args": [
8+
"-fdiagnostics-color=always",
9+
"-g",
10+
"${file}",
11+
"-o",
12+
"${fileDirname}/${fileBasenameNoExtension}"
13+
],
14+
"options": {
15+
"cwd": "${fileDirname}"
16+
},
17+
"problemMatcher": [
18+
"$gcc"
19+
],
20+
"group": {
21+
"kind": "build",
22+
"isDefault": true
23+
},
24+
"detail": "Task generated by Debugger."
25+
}
26+
],
27+
"version": "2.0.0"
28+
}

Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Makefile for lite-shell project
2+
3+
# Compiler
4+
CC = gcc
5+
6+
# Compiler flags
7+
CFLAGS = -I./include -Wall -Wextra
8+
9+
# Build directory
10+
BUILDDIR = build
11+
12+
# Source and object files
13+
SRCDIR = src
14+
OBJDIR = $(BUILDDIR)/obj
15+
SRC = $(wildcard $(SRCDIR)/*.c)
16+
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
17+
18+
# Target executable
19+
TARGET = $(BUILDDIR)/lite-shell
20+
21+
# Default target
22+
all: $(TARGET)
23+
24+
# Rule to link object files to create the executable
25+
$(TARGET): $(OBJ)
26+
$(CC) $(OBJ) -o $(TARGET)
27+
28+
# Rule to compile source files into object files
29+
$(OBJDIR)/%.o: $(SRCDIR)/%.c
30+
mkdir -p $(OBJDIR)
31+
$(CC) $(CFLAGS) -c $< -o $@
32+
33+
# Clean rule to remove object files and executable
34+
clean:
35+
rm -rf $(BUILDDIR)
36+
37+
.PHONY: all clean

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Lite-Shell
2+
3+
Lite-Shell is a lightweight shell implementation written in C. This project demonstrates fundamental concepts of shell programming, including process creation, command parsing, and execution.
4+
5+
## Features
6+
7+
- Execute basic shell commands
8+
- Support for built-in commands
9+
- Customizable through source code modifications
10+
11+
## Project Structure
12+
```python
13+
lite-shell/
14+
15+
├── src/ # Source files
16+
│ ├── main.c # Main entry point
17+
│ ├── command_exec.c # Command execution logic
18+
│ ├── history_log.c # History Log logic
19+
│ └── pipe_redirect.c # Pipe and redirect symbol logic
20+
21+
├── include/ # Header files
22+
│ ├── command_exec.h
23+
│ ├── history_log.h
24+
│ └── pipe_redirect.h
25+
26+
├── build/ # Build directory (generated)
27+
│ ├── lite-shell # Compiled executable
28+
│ └── obj/ # Object files
29+
30+
├── Makefile # Makefile for the project
31+
└── README.md
32+
```
33+
## Requirements
34+
35+
- GCC (GNU Compiler Collection)
36+
37+
## Building the Project
38+
39+
To build the project, simply run this at repo's root directory:
40+
41+
```bash
42+
make
43+
```
44+
45+
This command will compile the source files and create an executable named lite-shell in the build directory.
46+
47+
## Running Lite-Shell
48+
After building the project, you can run the shell using:
49+
50+
```bash
51+
./build/lite-shell
52+
```
53+
Cleaning the Build
54+
To clean up the build files, run:
55+
56+
```bash
57+
make clean
58+
```
59+
This command will remove the build directory and all compiled files.

build/lite-shell

71.1 KB
Binary file not shown.

build/obj/command_exec.o

14.6 KB
Binary file not shown.

build/obj/history_log.o

2.59 KB
Binary file not shown.

build/obj/main.o

4.66 KB
Binary file not shown.

build/obj/pipe_redirect.o

5.68 KB
Binary file not shown.

include/command_exec.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef COMMAND_EXEC_H
2+
#define COMMAND_EXEC_H
3+
4+
void handle_command(char** arguments, int arg_count, char** history, int* history_line, char* initial_directory);
5+
6+
#endif

include/history_log.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef HISTORY_LOG_H
2+
#define HISTORY_LOG_H
3+
4+
int add_cmd_his(char* command, char** history, int* history_line);
5+
void log_error(const char* command, const char* error_message);
6+
7+
#endif

include/pipe_redirect.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef PIPE_REDIRECT_H
2+
#define PIPE_REDIRECT_H
3+
4+
int redirect_io(char** arguments, int arg_count, int* is_input_redirect, int* insert_point);
5+
void restore_io(int saved_stdin, int saved_stdout);
6+
int exec_piped_commands(char* commands[], int num_commands);
7+
8+
#endif

0 commit comments

Comments
 (0)