consertar bug no formato real com zero casas decimais e
implementar a funcao readuntil.
This commit is contained in:
39
iolib.c
39
iolib.c
@@ -3,7 +3,7 @@
|
|||||||
** Input/output library to LUA
|
** Input/output library to LUA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_iolib="$Id: iolib.c,v 1.8 1994/08/17 22:34:20 roberto Exp celes $";
|
char *rcs_iolib="$Id: iolib.c,v 1.9 1994/09/12 19:24:31 celes Exp celes $";
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -314,6 +314,38 @@ static void io_read (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Read characters until a given one. The delimiter is not read.
|
||||||
|
*/
|
||||||
|
static void io_readuntil (void)
|
||||||
|
{
|
||||||
|
int n=255,m=0;
|
||||||
|
char c,d;
|
||||||
|
char *s;
|
||||||
|
lua_Object lo = lua_getparam(1);
|
||||||
|
if (!lua_isstring(lo))
|
||||||
|
d = EOF;
|
||||||
|
else
|
||||||
|
d = *lua_getstring(lo);
|
||||||
|
|
||||||
|
s = calloc(n+1, sizeof(char));
|
||||||
|
while((c = fgetc(in)) != EOF && c != d)
|
||||||
|
{
|
||||||
|
if (m==n)
|
||||||
|
{
|
||||||
|
n *= 2;
|
||||||
|
s = realloc(s, (n+1)*sizeof(char));
|
||||||
|
}
|
||||||
|
s[m++] = c;
|
||||||
|
}
|
||||||
|
if (c != EOF) ungetc(c,in);
|
||||||
|
s[m] = 0;
|
||||||
|
lua_pushstring(s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Write a variable. On error put 0 on stack, otherwise put 1.
|
** Write a variable. On error put 0 on stack, otherwise put 1.
|
||||||
** LUA interface:
|
** LUA interface:
|
||||||
@@ -360,8 +392,8 @@ static char *buildformat (char *e, lua_Object o)
|
|||||||
|
|
||||||
sprintf(f,"%%");
|
sprintf(f,"%%");
|
||||||
if (j == '<' || j == '|') sprintf(strchr(f,0),"-");
|
if (j == '<' || j == '|') sprintf(strchr(f,0),"-");
|
||||||
if (m != 0) sprintf(strchr(f,0),"%d", m);
|
if (m > 0) sprintf(strchr(f,0),"%d", m);
|
||||||
if (n != 0) sprintf(strchr(f,0),".%d", n);
|
if (n >= 0) sprintf(strchr(f,0),".%d", n);
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case 'i': case 'I': t = 'd';
|
case 'i': case 'I': t = 'd';
|
||||||
@@ -536,6 +568,7 @@ void iolib_open (void)
|
|||||||
lua_register ("writeto", io_writeto);
|
lua_register ("writeto", io_writeto);
|
||||||
lua_register ("appendto", io_appendto);
|
lua_register ("appendto", io_appendto);
|
||||||
lua_register ("read", io_read);
|
lua_register ("read", io_read);
|
||||||
|
lua_register ("readuntil",io_readuntil);
|
||||||
lua_register ("write", io_write);
|
lua_register ("write", io_write);
|
||||||
lua_register ("execute", io_execute);
|
lua_register ("execute", io_execute);
|
||||||
lua_register ("remove", io_remove);
|
lua_register ("remove", io_remove);
|
||||||
|
|||||||
Reference in New Issue
Block a user