Use ansi C

This commit is contained in:
Łukasz Magiera 2016-01-18 21:24:13 +01:00
parent aed5864c58
commit 05086757e3
6 changed files with 25 additions and 20 deletions

View File

@ -3,7 +3,7 @@
#CC=$(TARGET)-gcc #CC=$(TARGET)-gcc
CC=gcc CC=gcc
CFLAGS=-O2 -std=gnu99 -Isrc/lib/lua -Iinclude CFLAGS=-O2 -std=c90 -Isrc/lib/lua -Iinclude -DLUA_C89_NUMBERS
BUILD = bin/ BUILD = bin/
SOURCE = src/c/ SOURCE = src/c/

View File

@ -4,7 +4,7 @@
#ifndef LUPI_H #ifndef LUPI_H
#define LUPI_H #define LUPI_H
//#define LOGGING /* #define LOGGING */
#ifdef LOGGING #ifdef LOGGING
void logn(const char *message); void logn(const char *message);
void logi(int message); void logi(int message);
@ -15,7 +15,7 @@ void logm(const char *message);
#define logm(m) #define logm(m)
#endif #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 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) #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); int epoll_pull(int timeout);
struct lupi_event_handler { struct lupi_event_handler {
int (*handler)(int, void*); //FD, data, return number of pushed events int (*handler)(int, void*); /* FD, data, return number of pushed events */
//TODO: doc? /* TODO: doc? */
int fd; int fd;
void* data; void* data;
}; };

View File

@ -10,14 +10,14 @@ static int epollfd;
static int handleStdin(int fd, void* data) { static int handleStdin(int fd, void* data) {
char buf; char buf;
int r = read(fd, &buf, 1); //TODO: Wide chars? int r = read(fd, &buf, 1); /* TODO: Wide chars? */
if(r > 0) { if(r > 0) {
//if(buf == 10) buf = 13; /* if(buf == 10) buf = 13; */
lua_State* L = getL(); lua_State* L = getL();
lua_getglobal(L, "pushEvent"); lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_down"); 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, buf);
lua_pushnumber(L, -1); lua_pushnumber(L, -1);
lua_pushstring(L, "user"); lua_pushstring(L, "user");

View File

@ -18,7 +18,7 @@
#include <limits.h> #include <limits.h>
#include <linux/kd.h> #include <linux/kd.h>
//Enable in lupi.h /* Enable in lupi.h */
#ifdef LOGGING #ifdef LOGGING
void logn(const char *message) { void logn(const char *message) {
FILE *file; FILE *file;
@ -73,7 +73,7 @@ static int l_sleep (lua_State *L) {
return 0; return 0;
} }
// Filesystem methods /* Filesystem methods */
static int l_fs_exists (lua_State *L) { static int l_fs_exists (lua_State *L) {
const char* fname = lua_tostring(L, 1); const char* fname = lua_tostring(L, 1);
if( access( fname, F_OK ) != -1 ) { if( access( fname, F_OK ) != -1 ) {
@ -162,7 +162,7 @@ static int l_fs_write (lua_State *L) {
size_t len = 0; size_t len = 0;
const char* data = lua_tolstring(L, 2, &len); 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) { if(write(fd, data, len) == -1) {
lua_pushboolean(L, 0); lua_pushboolean(L, 0);
} else { } else {
@ -201,7 +201,7 @@ static int l_fs_list (lua_State *L) {
if ((dir = opendir(path)) != NULL) { if ((dir = opendir(path)) != NULL) {
lua_newtable(L); lua_newtable(L);
int n = 1; 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) { if(strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) {
lua_pushstring(L, ent->d_name); lua_pushstring(L, ent->d_name);
lua_rawseti(L, -2, n++); lua_rawseti(L, -2, n++);
@ -220,7 +220,7 @@ static int l_fs_lastModified (lua_State *L) {
if( stat(path, &s) != -1 ) { if( stat(path, &s) != -1 ) {
lua_pushnumber(L, s.st_mtime); lua_pushnumber(L, s.st_mtime);
} else { } else {
return 0; //TODO: No error? return 0; /* TODO: No error? */
} }
return 1; return 1;
} }
@ -266,7 +266,7 @@ static int l_fs_size (lua_State *L) {
if( stat(path, &s) != -1 ) { if( stat(path, &s) != -1 ) {
lua_pushnumber(L, s.st_size); lua_pushnumber(L, s.st_size);
} else { } else {
return 0; //TODO: No error? return 0; /* TODO: No error? */
} }
return 1; return 1;
} }
@ -302,14 +302,13 @@ static int l_fs_read (lua_State *L) {
#define CLOCK_TICK_RATE 1193180 #define CLOCK_TICK_RATE 1193180
#endif #endif
//Filesystem end /* Filesystem end */
static int l_beep (lua_State *L) { static int l_beep (lua_State *L) {
int freq = lua_tonumber(L, 1); int freq = lua_tonumber(L, 1);
int btime = lua_tonumber(L, 2); int btime = lua_tonumber(L, 2);
int console_fd = -1; int console_fd = -1;
if((console_fd = open("/dev/console", O_WRONLY)) == -1) { if((console_fd = open("/dev/console", O_WRONLY)) == -1) {
//fprintf(stderr, "Could not open /dev/console for writing.\n");
printf("\a"); printf("\a");
return 0; return 0;
} }
@ -325,7 +324,7 @@ static int l_beep (lua_State *L) {
return 0; return 0;
} }
static int l_uptime (lua_State *L) { //Return ms static int l_uptime (lua_State *L) { /* Return ms */
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
lua_pushnumber(L, tp.tv_sec * 1000 + tp.tv_usec / 1000); lua_pushnumber(L, tp.tv_sec * 1000 + tp.tv_usec / 1000);

View File

@ -29,7 +29,7 @@ void run_init() {
termutils_start (L); termutils_start (L);
epoll_prepare(); 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"); int status = luaL_loadbuffer(L, lua_init, strlen(lua_init), "=INIT");
if (status) { if (status) {
fprintf(stderr, "Couldn't load init: %s\n", lua_tostring(L, -1)); fprintf(stderr, "Couldn't load init: %s\n", lua_tostring(L, -1));

View File

@ -12,7 +12,7 @@
static void handle_winch(int sig){ static void handle_winch(int sig){
signal(SIGWINCH, SIG_IGN); signal(SIGWINCH, SIG_IGN);
//FIXME: Prerelease: Implement /* FIXME: Prerelease: Implement */
signal(SIGWINCH, handle_winch); signal(SIGWINCH, handle_winch);
} }
@ -33,7 +33,13 @@ void termutils_start(lua_State *L) {
return; return;
new = old; 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) if (tcsetattr (STDOUT_FILENO, TCSAFLUSH, &new) != 0)