From cdb6207632da8edc9ff1b268e1d4e71541b6df9c Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 7 Jun 2015 04:25:25 -0400 Subject: [PATCH] added examples and a clean target --- Makefile | 12 ++++++++++++ examples/a.txt | 1 + examples/conf.lua | 5 +++++ examples/main.c | 40 ++++++++++++++++++++++++++++++++++++++++ examples/main.lua | 28 ++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 examples/a.txt create mode 100644 examples/conf.lua create mode 100644 examples/main.c create mode 100644 examples/main.lua diff --git a/Makefile b/Makefile index c2fa3bc..166f1d9 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,27 @@ CC= MKDIR= +RM= PCFLAGS= PLFLAGS= LIBNAME= OUTDIR=bin LFLAGS=-shared -g -ggdb CFLAGS=--std=c99 -g -ggdb -O2 -Wall +RMEXTRA= +EXAMPLEBIN= ifeq ($(OS),Windows_NT) CC+=mingw32-gcc MKDIR+=mkdir -p + RM+=rm PLFLAGS+=-Wl,--out-implib,bin/libLoveToken.a LIBNAME+=$(OUTDIR)/LoveToken.dll + RMEXTRA+=bin/libLoveToken.a else ifeq ($(shell uname -s), Linux) CC+=gcc MKDIR+=mkdir -p + RM+=rm PCFLAGS+=-fPIC LIBNAME+=$(OUTDIR)/LoveToken.so endif @@ -25,3 +31,9 @@ all: $(MKDIR) $(OUTDIR) $(CC) $(CFLAGS) $(PCFLAGS) -c -o $(OUTDIR)/lt.o src/lt.c $(CC) $(LFLAGS) -o $(LIBNAME) $(OUTDIR)/lt.o $(PLFLAGS) -liconv + +clean: + $(RM) $(LIBNAME) bin/lt.o $(RMEXTRA) + +example: + $(CC) $(CFLAGS) -Isrc -Lbin -o bin/example examples/main.c -lLoveToken diff --git a/examples/a.txt b/examples/a.txt new file mode 100644 index 0000000..a542002 --- /dev/null +++ b/examples/a.txt @@ -0,0 +1 @@ +The quick brown fox jumps over the !lazy dog. \ No newline at end of file diff --git a/examples/conf.lua b/examples/conf.lua new file mode 100644 index 0000000..3946d76 --- /dev/null +++ b/examples/conf.lua @@ -0,0 +1,5 @@ +-- This file is placed under public domain. +function love.conf(t) + t.console = true + t.window.title = "Tokenizer Example" +end \ No newline at end of file diff --git a/examples/main.c b/examples/main.c new file mode 100644 index 0000000..f6f6cc2 --- /dev/null +++ b/examples/main.c @@ -0,0 +1,40 @@ +// This file is placed under public domain. +#include "lt.h" +#include + +int main(int argc, char **argv) +{ + LT_Config initCfg = { 0 }; // we don't need to set any options here + LT_Token tk; + + LT_OpenFile("a.txt"); + + LT_Init(initCfg); + + while(tk.token != LT_TkNames[TOK_EOF]) + { + LT_AssertInfo check; + tk = LT_GetToken(); + check = LT_CheckAssert(); + + if(check.failure) + { + printf("%s\n", check.str); + break; + } + + if(tk.string != NULL) + { + printf("%s\n", tk.string); + } + else + { + printf("%s\n", tk.token); + } + } + + LT_CloseFile(); + LT_Quit(); + + return 0; +} diff --git a/examples/main.lua b/examples/main.lua new file mode 100644 index 0000000..5848682 --- /dev/null +++ b/examples/main.lua @@ -0,0 +1,28 @@ +-- This file is placed under public domain. +local tokenizer = require("lua/tokenizer") +local ffi = require("ffi") + +function love.load(arg) + local initCfg = ffi.new("LT_Config") -- we don't need to set any options here + local tk + + tokenizer:init(initCfg, "a.txt") + + while (tk.token ~= "TOK_EOF") do + tk = tokenizer:getToken() + + if (tk.string ~= nil) then + print(tk.string) + else + print(tk.token) + end + end + + tokenizer:quit() +end + +function love.update(dt) +end + +function love.draw(dt) +end \ No newline at end of file