From: Michael Göhler Date: Sat, 16 Aug 2014 22:00:37 +0000 (+0200) Subject: draft main application with file io + fixed Makefiles X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=66fa8273ac6f360864e8a594da3310f42379ae1e;p=smdp.git draft main application with file io + fixed Makefiles --- diff --git a/Makefile b/Makefile index d318563..ee57e1d 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,23 @@ -# set some compiler flags -CFLAGS=-lncurses - -# find *.c in the current directory -SOURCES=$(wildcard *.c) -TESTS=$(wildcard test/*.c) - -# define the output objects by replacing .c with .o -TARGETS=$(SOURCES:.c=) -TEST_TARGETS=$(TESTS:.c=) - -# this will make all objects -all: $(TEST_TARGETS) $(TARGETS) -test: $(TEST_TARGETS) - -# each objects will be build by a *.c file -#%.o: %.c -%: %.c - cc $(CFLAGS) -o $@ $^ - -# this will delete all objects -# if not all objects are there, they will be compiled first -clean: $(TARGETS) $(TEST_TARGETS) - rm -f $^ +tmp: tmp.c cstring.o markdown.o markdown_io.o + cc -g -o tmp tmp.c cstring.o markdown.o markdown_io.o + +markdown_io.o: markdown_io.c cstring.o markdown.o + cc -g -c markdown_io.c -o markdown_io.o -lmarkdown + +markdown.o: markdown.c cstring.o + cc -g -c markdown.c -o markdown.o -lcstring + +cstring.o: cstring.c + cc -g -c cstring.c -o cstring.o + +all: tmp + +.PHONY: test + +test: + $(MAKE) -C test + +clean: + rm -f tmp *.o + $(MAKE) -C test clean diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..6e8c05e --- /dev/null +++ b/test/Makefile @@ -0,0 +1,22 @@ +# set some compiler flags +CFLAGS= + +# find *.c in the current directory +SOURCES=$(wildcard *.c) + +# define the output objects by replacing .c with .o +TARGETS=$(SOURCES:.c=) + +# this will make all objects +all: $(TARGETS) + +# each objects will be build by a *.c file +#%.o: %.c +%: %.c + cc $(CFLAGS) -o $@ $^ + +# this will delete all objects +# if not all objects are there, they will be compiled first +clean: $(TARGETS) + rm -f $^ + diff --git a/test/cstring.c b/test/cstring.c index c9d50c2..70892a6 100644 --- a/test/cstring.c +++ b/test/cstring.c @@ -1,6 +1,7 @@ #include #include "../include/cstring.h" +#include "../cstring.c" int main(int argc, char *argv[]) { diff --git a/tmp.c b/tmp.c new file mode 100644 index 0000000..bcdfeed --- /dev/null +++ b/tmp.c @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "include/markdown.h" + +int main(int argc, char *argv[]) { + + FILE *input; + document_t *doc; + + if (argc > 1) { + if(!strcmp(argv[1], "-")) { + input = stdin; + } else { + input = fopen(argv[1],"r"); + if(!input) { + fprintf(stderr, "Unable to open '%s': %s\n", + argv[1], strerror(errno)); + exit(EXIT_FAILURE); + } + } + } else { + input = stdin; + } + + doc = markdown_load(input); +} +