Date: Fri, 27 Jun 2014 17:57:19 GMT From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r270129 - in soc2014/pedrosouza/lua_loader/head/sys: boot/lua lua/src Message-ID: <201406271757.s5RHvJJ1056271@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pedrosouza Date: Fri Jun 27 17:57:18 2014 New Revision: 270129 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=270129 Log: Fix code style Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.h soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.c soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Fri Jun 27 16:33:43 2014 (r270128) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Fri Jun 27 17:57:18 2014 (r270129) @@ -34,10 +34,10 @@ int lua_perform(lua_State *L) { - int argc, ret; - char **argv; - int res = -1; - int n = lua_gettop(L); + int argc, ret; + char **argv; + int res = -1; + int n = lua_gettop(L); if (n >= 1) { @@ -59,7 +59,7 @@ int lua_gets(lua_State *L) { - char buf[129]; + char buf[129]; ngets(buf, 128); lua_pushstring(L, buf); return 1; @@ -68,9 +68,10 @@ int lua_strchar(lua_State *L) { - const char * str; - int i, j; - int n = lua_gettop(L); + const char *str; + int i, j; + int n = lua_gettop(L); + if (n != 2) return 0; str = lua_tostring(L, 1); if (str == NULL) return 0; @@ -87,8 +88,9 @@ int lua_charstr(lua_State *L) { - int n = lua_gettop(L); - char buf[129]; + int n = lua_gettop(L); + char buf[129]; + if (n < 1) return 0; n = n > 128 ? 128 : n; @@ -102,9 +104,10 @@ } int -lua_delay(lua_State * L) +lua_delay(lua_State *L) { - int n = lua_gettop(L); + int n = lua_gettop(L); + if (n == 1) { delay((int)lua_tonumber(L, 1)); @@ -112,10 +115,11 @@ return 0; } -int lua_getenv(lua_State * L) +int lua_getenv(lua_State *L) { - char * ev; - int n = lua_gettop(L); + char *ev; + int n = lua_gettop(L); + if (n == 1) { ev = getenv(lua_tostring(L, 1)); @@ -148,7 +152,7 @@ } data_chunk; const char * -read_chunk(lua_State *L, void * chunk, size_t *sz) +read_chunk(lua_State *L, void *chunk, size_t *sz) { data_chunk * ds = (data_chunk *)chunk; if (ds->size == 0) return NULL; @@ -159,13 +163,14 @@ int -ldo_string(lua_State *L, const char * str, size_t size) +ldo_string(lua_State *L, const char *str, size_t size) { - int res; - data_chunk ds; + int res; + data_chunk ds; + ds.data = (void*)str; ds.size = size; - res = lua_load(L, read_chunk, &ds, "do_string", 0); + res = lua_load(L, read_chunk, &ds, "do_string_", 0); res = lua_pcall(L, 0, LUA_MULTRET, 0); return res; } @@ -220,9 +225,10 @@ return 0; } -int lua_include(lua_State * L) +int lua_include(lua_State *L) { - const char * str; + const char *str; + if (lua_gettop(L) != 1) { lua_pushboolean(L, 0); @@ -234,7 +240,7 @@ } void -lregister(lua_State * L, const char * tableName, const char * funcName, int (*funcPointer)(lua_State *)) +lregister(lua_State *L, const char *tableName, const char *funcName, int (*funcPointer)(lua_State *)) { lua_getglobal(L, tableName); if (!lua_istable(L, -1)) @@ -254,8 +260,8 @@ typedef struct utils_func { int (*func)(lua_State *); - const char * table; - const char * name; + const char *table; + const char *name; } utils_func; utils_func reg_funcs[] = { @@ -271,9 +277,10 @@ }; void -register_utils(lua_State * L) +register_utils(lua_State *L) { - utils_func * f = reg_funcs; + utils_func *f = reg_funcs; + while (f->func != NULL && f->name != NULL) { if (f->table != NULL) Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.h ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.h Fri Jun 27 16:33:43 2014 (r270128) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.h Fri Jun 27 17:57:18 2014 (r270129) @@ -36,11 +36,11 @@ void * lua_realloc(void *ud, void *ptr, size_t osize, size_t nsize); -int ldo_string(lua_State *L, const char * str, size_t size); +int ldo_string(lua_State *L, const char *str, size_t size); -int ldo_file(lua_State *L, const char * filename); +int ldo_file(lua_State *L, const char *filename); -void lregister(const char * tname, const char * fname, int (*fptr)(lua_State *)); +void lregister(const char *tname, const char *fname, int (*fptr)(lua_State *)); -void register_utils(lua_State * L); +void register_utils(lua_State *L); Modified: soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.c Fri Jun 27 16:33:43 2014 (r270128) +++ soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.c Fri Jun 27 17:57:18 2014 (r270129) @@ -25,6 +25,9 @@ * */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #include "lstd.h" #ifdef BOOT_LUA @@ -43,11 +46,11 @@ } char * -strpbrk (const char * str1, const char * str2) +strpbrk (const char *str1, const char *str2) { while (*str1) { - const char * tmp = str2; + const char *tmp = str2; while (*tmp) if (*str1 == *tmp++) return str1; ++str1; @@ -170,15 +173,16 @@ return ret * exp_m; } -int dtostr(double v, char * str) +int +dtostr(double v, char *str) { - int exp = 0; - int i; + int exp = 0; + int i; long long n; - double e = 1; - char * ptr; - char tmp[20]; - char *buf = str; + double e = 1; + char *ptr; + char tmp[20]; + char *buf = str; if (v == 0) { @@ -200,8 +204,7 @@ --exp; e *= 0.1; } - } else - { + } else { while (v > e) { ++exp; @@ -213,8 +216,7 @@ if (exp > 9 || exp < -9) { v /= e; - } else - { + } else { exp = 0; } @@ -270,24 +272,24 @@ return buf - str; } -FILE * fopen(const char * filename, const char * mode) +FILE * +fopen(const char *filename, const char *mode) { - struct stat st; - int fd, r; - FILE * f; + struct stat st; + int fd, r; + FILE *f; + if (mode == NULL || mode[0] != 'r') return NULL; fd = open(filename, O_RDONLY); if (fd < 0) { - printf("fopen fd <0\n"); return NULL; } f = malloc(sizeof(FILE)); if (f == NULL) { - printf("fopen malloc null\n"); close(fd); return NULL; } @@ -298,35 +300,34 @@ f->fd = fd; f->offset = 0; f->size = st.st_size; - } else - { - printf("fopen fstat < 0\n"); + } else { free(f); close(fd); f = NULL; } - printf("fopen succeeded\n"); return f; } -FILE * freopen(const char * filename, const char * mode, FILE * stream) +FILE * +freopen(const char *filename, const char *mode, FILE *stream) { fclose(stream); return fopen(filename, mode); } -size_t fread(void * ptr, size_t size, size_t count, FILE * stream) +size_t +fread(void *ptr, size_t size, size_t count, FILE *stream) { size_t r; if (stream == NULL) return 0; r = (size_t)read(stream->fd, ptr, size * count); - printf("fread r:%d, s: %d\n", r, size*count); stream->offset += r; return r; } -int fclose(FILE * stream) +int +fclose(FILE *stream) { if (stream == NULL) return EOF; close(stream->fd); @@ -334,28 +335,38 @@ return 0; } -int ferror(FILE * stream) {return (stream == NULL) || (stream->fd < 0);} -int feof(FILE * stream) +int +ferror(FILE *stream) +{ + return (stream == NULL) || (stream->fd < 0); +} + +int +feof(FILE *stream) { if (stream == NULL) return 1; return stream->offset >= stream->size; } -int getc(FILE * stream) + +int +getc(FILE *stream) { - char ch; - size_t r; + char ch; + size_t r; + if (stream == NULL) return EOF; r = read(stream->fd, &ch, 1); if (r == 1) return ch; - printf("getc EOF\n"); return EOF; } -char * strstr(const char * str1, const char * str2) +char * +strstr(const char *str1, const char *str2) { - const char * s1 = str1; - const char * s2 = str2; - int eq = 0; + const char *s1 = str1; + const char *s2 = str2; + int eq = 0; + while (*s1) { while (*s2 && *s1) @@ -374,7 +385,8 @@ return NULL; } -void luai_writestring(const char * s, int i) +void +luai_writestring(const char *s, int i) { while (i-- > 0) putchar(*s++); Modified: soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h Fri Jun 27 16:33:43 2014 (r270128) +++ soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h Fri Jun 27 17:57:18 2014 (r270129) @@ -23,7 +23,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * + * $FreeBSD$ */ + #ifndef LSTD_H #define LSDT_H @@ -40,6 +42,7 @@ #include <setjmp.h> typedef __ptrdiff_t ptrdiff_t; + typedef struct FILE { int fd; @@ -47,12 +50,18 @@ size_t size; } FILE; -FILE * fopen(const char * filename, const char * mode); -FILE * freopen( const char * filename, const char * mode, FILE * stream); -size_t fread(void * ptr, size_t size, size_t count, FILE * stream); -int fclose(FILE * stream); -int ferror(FILE * stream); -int feof(FILE * stream); +FILE * fopen(const char *filename, const char *mode); + +FILE * freopen( const char *filename, const char *mode, FILE *stream); + +size_t fread(void *ptr, size_t size, size_t count, FILE *stream); + +int fclose(FILE *stream); + +int ferror(FILE *stream); + +int feof(FILE *stream); + int getc(FILE * stream); #ifndef EOF @@ -73,7 +82,7 @@ double floor(double v); -char * strpbrk (const char * str1, const char * str2); +char * strpbrk (const char *str1, const char *str2); double ldexp (double x, int exp); @@ -81,9 +90,9 @@ double strtod(const char *string, char **endPtr); -int dtostr(double v, char * str); +int dtostr(double v, char *str); -char * strstr(const char * str1, const char * str2); +char * strstr(const char *str1, const char *str2); #endif #endif //LSTD_H
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406271757.s5RHvJJ1056271>