mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
changing {} style to match majority of previous style
This commit is contained in:
parent
da6cdf014b
commit
961d929f4d
320 changed files with 5502 additions and 10485 deletions
123
liblua/liolib.c
123
liblua/liolib.c
|
@ -126,8 +126,7 @@ typedef luaL_Stream LStream;
|
|||
#define isclosed(p) ((p)->closef == NULL)
|
||||
|
||||
|
||||
static int io_type(lua_State *L)
|
||||
{
|
||||
static int io_type(lua_State *L) {
|
||||
LStream *p;
|
||||
luaL_checkany(L, 1);
|
||||
p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
|
||||
|
@ -141,8 +140,7 @@ static int io_type(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int f_tostring(lua_State *L)
|
||||
{
|
||||
static int f_tostring(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
if (isclosed(p))
|
||||
lua_pushliteral(L, "file (closed)");
|
||||
|
@ -152,8 +150,7 @@ static int f_tostring(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static FILE *tofile(lua_State *L)
|
||||
{
|
||||
static FILE *tofile(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
if (isclosed(p))
|
||||
luaL_error(L, "attempt to use a closed file");
|
||||
|
@ -167,8 +164,7 @@ static FILE *tofile(lua_State *L)
|
|||
** before opening the actual file; so, if there is a memory error, the
|
||||
** file is not left opened.
|
||||
*/
|
||||
static LStream *newprefile(lua_State *L)
|
||||
{
|
||||
static LStream *newprefile(lua_State *L) {
|
||||
LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
|
||||
p->closef = NULL; /* mark file handle as 'closed' */
|
||||
luaL_setmetatable(L, LUA_FILEHANDLE);
|
||||
|
@ -176,8 +172,7 @@ static LStream *newprefile(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int aux_close(lua_State *L)
|
||||
{
|
||||
static int aux_close(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
lua_CFunction cf = p->closef;
|
||||
p->closef = NULL; /* mark stream as closed */
|
||||
|
@ -185,8 +180,7 @@ static int aux_close(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int io_close(lua_State *L)
|
||||
{
|
||||
static int io_close(lua_State *L) {
|
||||
if (lua_isnone(L, 1)) /* no argument? */
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
|
||||
tofile(L); /* make sure argument is an open stream */
|
||||
|
@ -194,8 +188,7 @@ static int io_close(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int f_gc(lua_State *L)
|
||||
{
|
||||
static int f_gc(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
if (!isclosed(p) && p->f != NULL)
|
||||
aux_close(L); /* ignore closed and incompletely open files */
|
||||
|
@ -206,16 +199,14 @@ static int f_gc(lua_State *L)
|
|||
/*
|
||||
** function to close regular files
|
||||
*/
|
||||
static int io_fclose(lua_State *L)
|
||||
{
|
||||
static int io_fclose(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
int res = fclose(p->f);
|
||||
return luaL_fileresult(L, (res == 0), NULL);
|
||||
}
|
||||
|
||||
|
||||
static LStream *newfile(lua_State *L)
|
||||
{
|
||||
static LStream *newfile(lua_State *L) {
|
||||
LStream *p = newprefile(L);
|
||||
p->f = NULL;
|
||||
p->closef = &io_fclose;
|
||||
|
@ -223,8 +214,7 @@ static LStream *newfile(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static void opencheck(lua_State *L, const char *fname, const char *mode)
|
||||
{
|
||||
static void opencheck(lua_State *L, const char *fname, const char *mode) {
|
||||
LStream *p = newfile(L);
|
||||
p->f = fopen(fname, mode);
|
||||
if (p->f == NULL)
|
||||
|
@ -232,8 +222,7 @@ static void opencheck(lua_State *L, const char *fname, const char *mode)
|
|||
}
|
||||
|
||||
|
||||
static int io_open(lua_State *L)
|
||||
{
|
||||
static int io_open(lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
const char *mode = luaL_optstring(L, 2, "r");
|
||||
LStream *p = newfile(L);
|
||||
|
@ -247,15 +236,13 @@ static int io_open(lua_State *L)
|
|||
/*
|
||||
** function to close 'popen' files
|
||||
*/
|
||||
static int io_pclose(lua_State *L)
|
||||
{
|
||||
static int io_pclose(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
return luaL_execresult(L, lua_pclose(L, p->f));
|
||||
}
|
||||
|
||||
|
||||
static int io_popen(lua_State *L)
|
||||
{
|
||||
static int io_popen(lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
const char *mode = luaL_optstring(L, 2, "r");
|
||||
LStream *p = newprefile(L);
|
||||
|
@ -265,16 +252,14 @@ static int io_popen(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int io_tmpfile(lua_State *L)
|
||||
{
|
||||
static int io_tmpfile(lua_State *L) {
|
||||
LStream *p = newfile(L);
|
||||
p->f = tmpfile();
|
||||
return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
|
||||
}
|
||||
|
||||
|
||||
static FILE *getiofile(lua_State *L, const char *findex)
|
||||
{
|
||||
static FILE *getiofile(lua_State *L, const char *findex) {
|
||||
LStream *p;
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, findex);
|
||||
p = (LStream *)lua_touserdata(L, -1);
|
||||
|
@ -284,8 +269,7 @@ static FILE *getiofile(lua_State *L, const char *findex)
|
|||
}
|
||||
|
||||
|
||||
static int g_iofile(lua_State *L, const char *f, const char *mode)
|
||||
{
|
||||
static int g_iofile(lua_State *L, const char *f, const char *mode) {
|
||||
if (!lua_isnoneornil(L, 1)) {
|
||||
const char *filename = lua_tostring(L, 1);
|
||||
if (filename)
|
||||
|
@ -302,14 +286,12 @@ static int g_iofile(lua_State *L, const char *f, const char *mode)
|
|||
}
|
||||
|
||||
|
||||
static int io_input(lua_State *L)
|
||||
{
|
||||
static int io_input(lua_State *L) {
|
||||
return g_iofile(L, IO_INPUT, "r");
|
||||
}
|
||||
|
||||
|
||||
static int io_output(lua_State *L)
|
||||
{
|
||||
static int io_output(lua_State *L) {
|
||||
return g_iofile(L, IO_OUTPUT, "w");
|
||||
}
|
||||
|
||||
|
@ -317,8 +299,7 @@ static int io_output(lua_State *L)
|
|||
static int io_readline(lua_State *L);
|
||||
|
||||
|
||||
static void aux_lines(lua_State *L, int toclose)
|
||||
{
|
||||
static void aux_lines(lua_State *L, int toclose) {
|
||||
int i;
|
||||
int n = lua_gettop(L) - 1; /* number of arguments to read */
|
||||
/* ensure that arguments will fit here and into 'io_readline' stack */
|
||||
|
@ -331,16 +312,14 @@ static void aux_lines(lua_State *L, int toclose)
|
|||
}
|
||||
|
||||
|
||||
static int f_lines(lua_State *L)
|
||||
{
|
||||
static int f_lines(lua_State *L) {
|
||||
tofile(L); /* check that it's a valid file handle */
|
||||
aux_lines(L, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int io_lines(lua_State *L)
|
||||
{
|
||||
static int io_lines(lua_State *L) {
|
||||
int toclose;
|
||||
if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
|
||||
if (lua_isnil(L, 1)) { /* no file name? */
|
||||
|
@ -366,8 +345,7 @@ static int io_lines(lua_State *L)
|
|||
*/
|
||||
|
||||
|
||||
static int read_number(lua_State *L, FILE *f)
|
||||
{
|
||||
static int read_number(lua_State *L, FILE *f) {
|
||||
lua_Number d;
|
||||
if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
|
||||
lua_pushnumber(L, d);
|
||||
|
@ -379,8 +357,7 @@ static int read_number(lua_State *L, FILE *f)
|
|||
}
|
||||
|
||||
|
||||
static int test_eof(lua_State *L, FILE *f)
|
||||
{
|
||||
static int test_eof(lua_State *L, FILE *f) {
|
||||
int c = getc(f);
|
||||
ungetc(c, f);
|
||||
lua_pushlstring(L, NULL, 0);
|
||||
|
@ -388,8 +365,7 @@ static int test_eof(lua_State *L, FILE *f)
|
|||
}
|
||||
|
||||
|
||||
static int read_line(lua_State *L, FILE *f, int chop)
|
||||
{
|
||||
static int read_line(lua_State *L, FILE *f, int chop) {
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
for (;;) {
|
||||
|
@ -413,8 +389,7 @@ static int read_line(lua_State *L, FILE *f, int chop)
|
|||
|
||||
#define MAX_SIZE_T (~(size_t)0)
|
||||
|
||||
static void read_all(lua_State *L, FILE *f)
|
||||
{
|
||||
static void read_all(lua_State *L, FILE *f) {
|
||||
size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
|
||||
luaL_Buffer b;
|
||||
luaL_buffinit(L, &b);
|
||||
|
@ -430,8 +405,7 @@ static void read_all(lua_State *L, FILE *f)
|
|||
}
|
||||
|
||||
|
||||
static int read_chars(lua_State *L, FILE *f, size_t n)
|
||||
{
|
||||
static int read_chars(lua_State *L, FILE *f, size_t n) {
|
||||
size_t nr; /* number of chars actually read */
|
||||
char *p;
|
||||
luaL_Buffer b;
|
||||
|
@ -444,8 +418,7 @@ static int read_chars(lua_State *L, FILE *f, size_t n)
|
|||
}
|
||||
|
||||
|
||||
static int g_read(lua_State *L, FILE *f, int first)
|
||||
{
|
||||
static int g_read(lua_State *L, FILE *f, int first) {
|
||||
int nargs = lua_gettop(L) - 1;
|
||||
int success;
|
||||
int n;
|
||||
|
@ -493,20 +466,17 @@ static int g_read(lua_State *L, FILE *f, int first)
|
|||
}
|
||||
|
||||
|
||||
static int io_read(lua_State *L)
|
||||
{
|
||||
static int io_read(lua_State *L) {
|
||||
return g_read(L, getiofile(L, IO_INPUT), 1);
|
||||
}
|
||||
|
||||
|
||||
static int f_read(lua_State *L)
|
||||
{
|
||||
static int f_read(lua_State *L) {
|
||||
return g_read(L, tofile(L), 2);
|
||||
}
|
||||
|
||||
|
||||
static int io_readline(lua_State *L)
|
||||
{
|
||||
static int io_readline(lua_State *L) {
|
||||
LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
|
||||
int i;
|
||||
int n = (int)lua_tointeger(L, lua_upvalueindex(2));
|
||||
|
@ -536,8 +506,7 @@ static int io_readline(lua_State *L)
|
|||
/* }====================================================== */
|
||||
|
||||
|
||||
static int g_write(lua_State *L, FILE *f, int arg)
|
||||
{
|
||||
static int g_write(lua_State *L, FILE *f, int arg) {
|
||||
int nargs = lua_gettop(L) - arg;
|
||||
int status = 1;
|
||||
for (; nargs--; arg++) {
|
||||
|
@ -556,22 +525,19 @@ static int g_write(lua_State *L, FILE *f, int arg)
|
|||
}
|
||||
|
||||
|
||||
static int io_write(lua_State *L)
|
||||
{
|
||||
static int io_write(lua_State *L) {
|
||||
return g_write(L, getiofile(L, IO_OUTPUT), 1);
|
||||
}
|
||||
|
||||
|
||||
static int f_write(lua_State *L)
|
||||
{
|
||||
static int f_write(lua_State *L) {
|
||||
FILE *f = tofile(L);
|
||||
lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
|
||||
return g_write(L, f, 2);
|
||||
}
|
||||
|
||||
|
||||
static int f_seek(lua_State *L)
|
||||
{
|
||||
static int f_seek(lua_State *L) {
|
||||
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
||||
static const char *const modenames[] = {"set", "cur", "end", NULL};
|
||||
FILE *f = tofile(L);
|
||||
|
@ -590,8 +556,7 @@ static int f_seek(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int f_setvbuf(lua_State *L)
|
||||
{
|
||||
static int f_setvbuf(lua_State *L) {
|
||||
static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
|
||||
static const char *const modenames[] = {"no", "full", "line", NULL};
|
||||
FILE *f = tofile(L);
|
||||
|
@ -603,14 +568,12 @@ static int f_setvbuf(lua_State *L)
|
|||
|
||||
|
||||
|
||||
static int io_flush(lua_State *L)
|
||||
{
|
||||
static int io_flush(lua_State *L) {
|
||||
return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
static int f_flush(lua_State *L)
|
||||
{
|
||||
static int f_flush(lua_State *L) {
|
||||
return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
|
||||
}
|
||||
|
||||
|
@ -651,8 +614,7 @@ static const luaL_Reg flib[] = {
|
|||
};
|
||||
|
||||
|
||||
static void createmeta(lua_State *L)
|
||||
{
|
||||
static void createmeta(lua_State *L) {
|
||||
luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
|
||||
lua_pushvalue(L, -1); /* push metatable */
|
||||
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
|
||||
|
@ -664,8 +626,7 @@ static void createmeta(lua_State *L)
|
|||
/*
|
||||
** function to (not) close the standard files stdin, stdout, and stderr
|
||||
*/
|
||||
static int io_noclose(lua_State *L)
|
||||
{
|
||||
static int io_noclose(lua_State *L) {
|
||||
LStream *p = tolstream(L);
|
||||
p->closef = &io_noclose; /* keep file opened */
|
||||
lua_pushnil(L);
|
||||
|
@ -675,8 +636,7 @@ static int io_noclose(lua_State *L)
|
|||
|
||||
|
||||
static void createstdfile(lua_State *L, FILE *f, const char *k,
|
||||
const char *fname)
|
||||
{
|
||||
const char *fname) {
|
||||
LStream *p = newprefile(L);
|
||||
p->f = f;
|
||||
p->closef = &io_noclose;
|
||||
|
@ -688,8 +648,7 @@ static void createstdfile(lua_State *L, FILE *f, const char *k,
|
|||
}
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_io(lua_State *L)
|
||||
{
|
||||
LUAMOD_API int luaopen_io(lua_State *L) {
|
||||
luaL_newlib(L, iolib); /* new module */
|
||||
createmeta(L);
|
||||
/* create (and set) default files */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue