From 05086757e3160169023d196f7ae6834df86f25a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 18 Jan 2016 21:24:13 +0100 Subject: [PATCH] Use ansi C --- Makefile | 2 +- include/lupi.h | 8 ++++---- src/c/epoll.c | 6 +++--- src/c/lnative.c | 17 ++++++++--------- src/c/run.c | 2 +- src/c/termutils.c | 10 ++++++++-- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 8b90a13..344fa20 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ #CC=$(TARGET)-gcc CC=gcc -CFLAGS=-O2 -std=gnu99 -Isrc/lib/lua -Iinclude +CFLAGS=-O2 -std=c90 -Isrc/lib/lua -Iinclude -DLUA_C89_NUMBERS BUILD = bin/ SOURCE = src/c/ diff --git a/include/lupi.h b/include/lupi.h index 7f89ac4..392ac2f 100644 --- a/include/lupi.h +++ b/include/lupi.h @@ -4,7 +4,7 @@ #ifndef LUPI_H #define LUPI_H -//#define LOGGING +/* #define LOGGING */ #ifdef LOGGING void logn(const char *message); void logi(int message); @@ -15,7 +15,7 @@ void logm(const char *message); #define logm(m) #endif -//TODO: move to utils +/* TODO: move to utils */ #define pushstuple(state, name, value) lua_pushstring((state), (name)); lua_pushstring((state), (value)); lua_settable((state), -3) #define pushctuple(state, name, value) lua_pushstring((state), (name)); lua_pushcfunction((state), (value)); lua_settable((state), -3) @@ -29,8 +29,8 @@ void epoll_prepare(); int epoll_pull(int timeout); struct lupi_event_handler { - int (*handler)(int, void*); //FD, data, return number of pushed events - //TODO: doc? + int (*handler)(int, void*); /* FD, data, return number of pushed events */ + /* TODO: doc? */ int fd; void* data; }; diff --git a/src/c/epoll.c b/src/c/epoll.c index bc54153..702f6c4 100644 --- a/src/c/epoll.c +++ b/src/c/epoll.c @@ -10,14 +10,14 @@ static int epollfd; static int handleStdin(int fd, void* data) { char buf; - int r = read(fd, &buf, 1); //TODO: Wide chars? + int r = read(fd, &buf, 1); /* TODO: Wide chars? */ if(r > 0) { - //if(buf == 10) buf = 13; + /* if(buf == 10) buf = 13; */ lua_State* L = getL(); lua_getglobal(L, "pushEvent"); lua_pushstring(L, "key_down"); - lua_pushstring(L, "TODO:SetThisUuid");//Also in textgpu.lua + lua_pushstring(L, "TODO:SetThisUuid");/* Also in textgpu.lua */ lua_pushnumber(L, buf); lua_pushnumber(L, -1); lua_pushstring(L, "user"); diff --git a/src/c/lnative.c b/src/c/lnative.c index 5742a8e..9d5893f 100644 --- a/src/c/lnative.c +++ b/src/c/lnative.c @@ -18,7 +18,7 @@ #include #include -//Enable in lupi.h +/* Enable in lupi.h */ #ifdef LOGGING void logn(const char *message) { FILE *file; @@ -73,7 +73,7 @@ static int l_sleep (lua_State *L) { return 0; } -// Filesystem methods +/* Filesystem methods */ static int l_fs_exists (lua_State *L) { const char* fname = lua_tostring(L, 1); if( access( fname, F_OK ) != -1 ) { @@ -162,7 +162,7 @@ static int l_fs_write (lua_State *L) { size_t len = 0; const char* data = lua_tolstring(L, 2, &len); - //TODO: May not all data be written? + /* TODO: May not all data be written? */ if(write(fd, data, len) == -1) { lua_pushboolean(L, 0); } else { @@ -201,7 +201,7 @@ static int l_fs_list (lua_State *L) { if ((dir = opendir(path)) != NULL) { lua_newtable(L); int n = 1; - while ((ent = readdir(dir)) != NULL) { //TODO: Check if it should be freed + while ((ent = readdir(dir)) != NULL) { /* TODO: Check if it should be freed */ if(strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) { lua_pushstring(L, ent->d_name); lua_rawseti(L, -2, n++); @@ -220,7 +220,7 @@ static int l_fs_lastModified (lua_State *L) { if( stat(path, &s) != -1 ) { lua_pushnumber(L, s.st_mtime); } else { - return 0; //TODO: No error? + return 0; /* TODO: No error? */ } return 1; } @@ -266,7 +266,7 @@ static int l_fs_size (lua_State *L) { if( stat(path, &s) != -1 ) { lua_pushnumber(L, s.st_size); } else { - return 0; //TODO: No error? + return 0; /* TODO: No error? */ } return 1; } @@ -302,14 +302,13 @@ static int l_fs_read (lua_State *L) { #define CLOCK_TICK_RATE 1193180 #endif -//Filesystem end +/* Filesystem end */ static int l_beep (lua_State *L) { int freq = lua_tonumber(L, 1); int btime = lua_tonumber(L, 2); int console_fd = -1; if((console_fd = open("/dev/console", O_WRONLY)) == -1) { - //fprintf(stderr, "Could not open /dev/console for writing.\n"); printf("\a"); return 0; } @@ -325,7 +324,7 @@ static int l_beep (lua_State *L) { return 0; } -static int l_uptime (lua_State *L) { //Return ms +static int l_uptime (lua_State *L) { /* Return ms */ struct timeval tp; gettimeofday(&tp, NULL); lua_pushnumber(L, tp.tv_sec * 1000 + tp.tv_usec / 1000); diff --git a/src/c/run.c b/src/c/run.c index 78491b8..032a844 100644 --- a/src/c/run.c +++ b/src/c/run.c @@ -29,7 +29,7 @@ void run_init() { termutils_start (L); epoll_prepare(); - //int status = luaL_loadstring(L, lua_init); + /* int status = luaL_loadstring(L, lua_init); */ int status = luaL_loadbuffer(L, lua_init, strlen(lua_init), "=INIT"); if (status) { fprintf(stderr, "Couldn't load init: %s\n", lua_tostring(L, -1)); diff --git a/src/c/termutils.c b/src/c/termutils.c index 1a04347..76a29c7 100644 --- a/src/c/termutils.c +++ b/src/c/termutils.c @@ -12,7 +12,7 @@ static void handle_winch(int sig){ signal(SIGWINCH, SIG_IGN); - //FIXME: Prerelease: Implement + /* FIXME: Prerelease: Implement */ signal(SIGWINCH, handle_winch); } @@ -33,7 +33,13 @@ void termutils_start(lua_State *L) { return; new = old; - cfmakeraw(&new); + new.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON); + new.c_oflag &= ~OPOST; + new.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + new.c_cflag &= ~(CSIZE | PARENB); + new.c_cflag |= CS8; + if (tcsetattr (STDOUT_FILENO, TCSAFLUSH, &new) != 0)