-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1567d93
Showing
23 changed files
with
1,294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
IDIR := include | ||
SDIR := source | ||
|
||
SRC := $(wildcard $(SDIR)/*.c) | ||
HEAD := $(wildcard $(IDIR)/*.h) | ||
OBJS := $(SRC:.c=.o) | ||
|
||
.PHONY: all | ||
all: $(OBJS) shell clean | ||
|
||
$(SDIR)/%.o: $(SDIR)/%.c $(HEAD) | ||
gcc -c $< -o $@ | ||
|
||
help: $(SDIR)/help.txt | ||
ld -r -b binary $(SDIR)/help.txt -o $(SDIR)/help.o | ||
|
||
OBJ := $(wildcard $(SDIR)/*.o) | ||
|
||
shell: $(OBJ) | ||
gcc $(OBJ) -o shell | ||
|
||
clean: | ||
rm $(OBJS) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# Shell - Kier Kilian | ||
|
||
|
||
------------ | ||
|
||
## Installation und Ausführung | ||
|
||
### help.o | ||
help.o kann mit: | ||
```bash | ||
ld -r -b binary source/help.txt -o source/help.o | ||
``` | ||
generiert werden. | ||
|
||
### Windows | ||
|
||
```cmd | ||
windows.cmd | ||
Shell.exe | ||
``` | ||
oder | ||
```cmd | ||
cd source | ||
ld -r -b binary help.txt -o help.o | ||
gcc alias.c basic_cmd.c command.c file_cmd.c functions.c help.o input.c main.c struct.c -o ../Shell.exe | ||
cd .. | ||
Shell.exe | ||
``` | ||
### Linux | ||
|
||
```bash | ||
./linux.sh | ||
./shell | ||
``` | ||
oder | ||
```bash | ||
make | ||
./shell | ||
``` | ||
oder | ||
```bash | ||
cd source | ||
ld -r -b binary help.txt -o help.o | ||
gcc alias.c basic_cmd.c command.c file_cmd.c functions.c help.o input.c main.c struct.c -o ../shell | ||
cd .. | ||
./shell | ||
``` | ||
|
||
------------ | ||
|
||
|
||
## Befehle | ||
Der Syntax der Befehle ist manchmal anders als wie es üblich wäre, da wenn mehrere Parameter übergeben werden können, | ||
ist der 1. Parameter immer fix und alle anderen Parameter können beliebig danach verwendet werden. | ||
|
||
$: ein Parameter\ | ||
$$: beliebig viele Parameter\ | ||
($): optionaler Parameter | ||
>**ls**\ | ||
ls ($): gib den Inhalt des übergebenen Ordners aus. Bei keinem Parameter den Inhalt des aktuellen Ordners. | ||
>**cd**\ | ||
cd $: wechselt das current working directory in den übergebenen Pfad. | ||
>**cat**\ | ||
cat $$: gibt den Inhalt der übergebenen Datei aus. | ||
>**rm**\ | ||
rm $$: löscht die übergebenen Ordner oder Dateien. Deshalb kein rmdir notwendig | ||
>**mv**\ | ||
mv $ $$: verschiebt die übergebene Dateien ($$) in den übergebenen Ordner ($) | ||
>**cp**\ | ||
cp $ $$: kopiert den Inhalt der übergebene Dateien ($$) in die übergebene Datei ($). | ||
> Die Datei ($) wird überschrieben (nach Bestätigung des Benutzers) und falls noch nicht vorhanden wird sie erstellt. | ||
> Anstelle von einer Datei kann man auch einen Ordner ($) übergeben und die Dateien ($) dorthin kopieren. | ||
> Falls sich in diesem Ordner bereits eine Datei mit gleichen Name befindet wird sie überschrieben (nach Bestätigung des Benutzers). | ||
>**echo**\ | ||
echo $$: gibt den übergebene Text aus. | ||
>**mkdir**\ | ||
mkdir $$: erstellt im current working directory einen oder mehrere Ordner. | ||
>**pwd**\ | ||
pwd: gibt das current working directory aus. | ||
>**chmod**\ | ||
chmod $ $$: die Rechte der übergebene Dateinen und Ordner ($$) werden geändert. $ muss ein numerischer | ||
> Code sein mit der bereits in Linux bekannten Zahlenmethode. | ||
>**touch**\ | ||
touch $$: erstellt im current working directory Dateien ($$). | ||
>**help**\ | ||
help ($$): listet alle Befehle mit kurzer Beschreibung auf. Falls Parameter übergeben werden, wird nur die Beschreibung dieser Befehler aufgelistet. | ||
>**exit**\ | ||
exit: beendet die Shell. | ||
### zusätzliche Befehle | ||
>**whoami**\ | ||
whoami: gibt den Username des Benutzers aus. | ||
>**write**\ | ||
write ($) $ $$: schreibt $$ in die übergebene Datei $. | ||
> Standardmäßig wird überschrieben, aber mit -a ($) als ersten Parameter kann der übergeben String in die Datei angehängt werden. | ||
>**date**\ | ||
date: gib das aktuelle Datum aus. | ||
>**time**\ | ||
time: gib die aktuelle Uhrzeit aus. | ||
>**set_alias**\ | ||
set_alias $ $$: für einen Befehl ($) können Aliase ($$) festgelegt werden, die in der Shell die gleiche Funktion aufrufen. | ||
>**rm_alias**\ | ||
rm_alias $ $$: löscht die Aliase ($$) eines Befehls ($). | ||
>**show_aliases**\ | ||
show_aliases: gibt alle aliase aus. | ||
------------ | ||
## Kurze Beschreibung der Umsetzung | ||
Beim Start werden die Befehle und dessen Beschreibung von der help.o Datei gelesen, | ||
die in das ausführende Programm eingebunden wurde, damit sie im Nachhinein nicht verändert werden kann. | ||
Die Aliase werden von einer Datei gelesen. Falls es diese Datei nicht gibt, wird eine neue erstellt. | ||
Die Befehle werden in einen binären Baum gespeichert, der alphabetisch sortiert ist, um die Suche nach Befehlen zu vereinfachen. | ||
Jeder Knoten besitzt den Befehl als String, einen Zeiger auf die Funktion, die Beschreibung als String, | ||
einen Zeiger auf das erste Element des binären Baums für seine Aliase und jeweils einen Zeiger auf den linken und rechten Knoten im Baum. | ||
Die Eingabe wird in ein struct gespeichert als String Array und Anzahl der Strings. | ||
Das erste Element des Arrays (der Befehl) wird im binären Baum gesucht und falls er nicht gefunden wurde, | ||
wird der Benutzer gefragt ob er ihn im System suchen und ausführen soll (mit system()) | ||
### was noch nicht funktioniert | ||
- Umlauten auf Windows (Ausgabe, Dateinamen, Write, …) | ||
- verschieben und kopieren von ganzen Ordnern | ||
- ls: wirkliche Größe auf Festplatte stimmt meistens nicht | ||
- rm: mehrere Ordner. Ein Ordner und mehrere Dateien funktioniert. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef SHELL_ALIAS_H | ||
#define SHELL_ALIAS_H | ||
|
||
#include "struct.h" | ||
#include "main.h" | ||
|
||
alias *set_alias(alias *node, char *string, command *cmd); | ||
|
||
alias *delete_alias(alias *node, char *string, command *cmd); | ||
|
||
alias *search_alias(alias *node, char *string); | ||
|
||
#endif //SHELL_ALIAS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef SHELL_BASIC_CMD_H | ||
#define SHELL_BASIC_CMD_H | ||
|
||
#include "main.h" | ||
#include "struct.h" | ||
#include "functions.h" | ||
|
||
void stop(struct cmd_line *line); | ||
|
||
void help(struct cmd_line *line); | ||
|
||
void clear(struct cmd_line *line); | ||
|
||
void working_dir(struct cmd_line *line); | ||
|
||
void ls(struct cmd_line *line); | ||
|
||
void cd(struct cmd_line *line); | ||
|
||
void makedir(struct cmd_line *line); | ||
|
||
void echo(struct cmd_line *line); | ||
|
||
void username(struct cmd_line *line); | ||
|
||
void date(struct cmd_line *line); | ||
|
||
void time_now(struct cmd_line *line); | ||
|
||
void show_aliases(struct cmd_line *line); | ||
|
||
void insert_alias(struct cmd_line *line); | ||
|
||
void rm_alias(struct cmd_line *line); | ||
|
||
#endif //SHELL_BASIC_CMD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef SHELL_COMMAND_H | ||
#define SHELL_COMMAND_H | ||
|
||
#include "struct.h" | ||
|
||
command *create_cmd(char *cmd, void (*fun)(cmd_line *), char *help, command *node); | ||
|
||
command *search_cmd(char *cmd, command *node); | ||
|
||
void print_help(command *node); | ||
|
||
#endif //SHELL_COMMAND_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef SHELL_FILE_CMD_H | ||
#define SHELL_FILE_CMD_H | ||
|
||
#include "main.h" | ||
#include "struct.h" | ||
|
||
void cat(struct cmd_line *line); | ||
|
||
void touch(struct cmd_line *line); | ||
|
||
void rm(struct cmd_line *line); | ||
|
||
void mv(struct cmd_line *line); | ||
|
||
void cp(struct cmd_line *line); | ||
|
||
void chmode(struct cmd_line *line); | ||
|
||
void write_to_file(struct cmd_line *line); | ||
|
||
#endif //SHELL_FILE_CMD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef SHELL_FUNCTIONS_H | ||
#define SHELL_FUNCTIONS_H | ||
|
||
#include <limits.h> | ||
#include "main.h" | ||
|
||
char *pwd(); | ||
|
||
int file_size(char *filename); | ||
|
||
int file_blksize(char *filename); | ||
|
||
char *file_owner(char *filename); | ||
|
||
char *file_group(char *filename); | ||
|
||
char *last_change(char *filename); | ||
|
||
char *file_permission(char *filename); | ||
|
||
char *whoami(); | ||
|
||
int copy_file(const char *old_file, const char *new_file); | ||
|
||
char *destination_path(const char *dir, const char *name); | ||
|
||
int convertChmod(int x); | ||
|
||
#endif //SHELL_FUNCTIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef SHELL_INPUT_H | ||
#define SHELL_INPUT_H | ||
|
||
#include "basic_cmd.h" | ||
#include "file_cmd.h" | ||
#include "main.h" | ||
|
||
#define MAX_SIZE 10000 | ||
|
||
void input(FILE *history); | ||
|
||
#endif //SHELL_INPUT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef SHELL_MAIN_H | ||
#define SHELL_MAIN_H | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <dirent.h> | ||
#include <unistd.h> | ||
#include <sys/stat.h> | ||
#include <math.h> | ||
#include <time.h> | ||
#include <wchar.h> | ||
#include "input.h" | ||
#include "struct.h" | ||
#include "functions.h" | ||
|
||
command *global_cmd_root; | ||
FILE *global_alias_file; | ||
char *global_alias_path; | ||
|
||
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) | ||
#define WIN | ||
#define path_separator '\\' | ||
#define clear_cmd "cls" | ||
|
||
#include <windows.h> | ||
|
||
char *realpath(char *relative, char *absolut); | ||
|
||
#else | ||
#define LINUX | ||
#define path_separator '/' | ||
#define clear_cmd "clear" | ||
#include <pwd.h> | ||
#include <grp.h> | ||
#endif | ||
|
||
int count_line(FILE *f); | ||
|
||
#endif //SHELL_MAIN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef SHELL_STRUCT_H | ||
#define SHELL_STRUCT_H | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
typedef struct cmd_line { | ||
int argc; | ||
char **argv; | ||
} cmd_line; | ||
|
||
typedef struct alias { | ||
char *alias; | ||
struct alias *left; | ||
struct alias *right; | ||
} alias; | ||
|
||
typedef struct command { | ||
char *cmd; | ||
alias *aliases; | ||
|
||
void (*cmd_functions)(struct cmd_line *); | ||
|
||
char *help; | ||
struct command *left; | ||
struct command *right; | ||
} command; | ||
|
||
#include "alias.h" | ||
#include "command.h" | ||
|
||
cmd_line *create_line(int n, int size, char *args[]); | ||
|
||
#endif //SHELL_STRUCT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
cd source | ||
ld -r -b binary help.txt -o help.o | ||
gcc alias.c basic_cmd.c command.c file_cmd.c functions.c help.o input.c main.c struct.c -o ../shell |
Oops, something went wrong.