From cc74038008611645e78d23f8ae62669e32f4371f Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sat, 19 Jun 2021 19:13:53 -0400 Subject: [PATCH] create the shell loop --- Makefile | 13 +++++++------ src/include/loop.h | 2 ++ src/loop.c | 18 ++++++++++++++++++ src/myshellin.c | 5 +++-- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 src/include/loop.h create mode 100644 src/loop.c diff --git a/Makefile b/Makefile index 111776e..28fe7d8 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,14 @@ CC=clang -CFLAGS=-Wall -Isrc/include -DDEBUG -g -LDFLAGS=-lm -SRC=src/myshellin.c +CFLAGS=-Wall -Isrc/include -DDEBUG -g -std=c17 +LDFLAGS= +FILENAME=myshellin +SRC=src/myshellin.c src/loop.c OBJ=$(SRC:.c=.o) -all: myshellin informe +all: myshellin myshellin: $(OBJ) - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) $(CFLAGS) -o $(FILENAME) $^ $(LDFLAGS) informe: # if pdflatex is installed create the informe @@ -16,7 +17,7 @@ ifneq (, $(shell which pdflatex)) mv doc/Informe.pdf Informe.pdf endif -clean: cleanmyshellin cleaninforme +clean: cleanmyshellin cleanmyshellin: rm -f src/*.o myshellin diff --git a/src/include/loop.h b/src/include/loop.h new file mode 100644 index 0000000..87301ec --- /dev/null +++ b/src/include/loop.h @@ -0,0 +1,2 @@ +void print_input_line(); +void loop(); diff --git a/src/loop.c b/src/loop.c new file mode 100644 index 0000000..afbc009 --- /dev/null +++ b/src/loop.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE +#include +#include +#include + +void print_input_line() { + printf("$ "); +} + +void loop() { + size_t buffer_size = 0; + char *line = NULL; + + while (1) { + print_input_line(); + getline(&line, &buffer_size, stdin); + } +} diff --git a/src/myshellin.c b/src/myshellin.c index 6edf587..5200c5d 100644 --- a/src/myshellin.c +++ b/src/myshellin.c @@ -1,5 +1,6 @@ -int main(int argc, char **argv) -{ +#include "loop.h" +int main(int argc, char **argv) { + loop(); return 0; }