porting tio from xpkit
This commit is contained in:
@ -63,8 +63,8 @@ am__libaseawk___la_SOURCES_DIST = Awk.cpp StdAwk.cpp
|
||||
libaseawk___la_OBJECTS = $(am_libaseawk___la_OBJECTS)
|
||||
@ENABLE_CXX_TRUE@am_libaseawk___la_rpath = -rpath $(libdir)
|
||||
libaseawk_la_DEPENDENCIES =
|
||||
am_libaseawk_la_OBJECTS = awk.lo err.lo tree.lo parse.lo run.lo \
|
||||
rec.lo val.lo func.lo misc.lo extio.lo std.lo
|
||||
am_libaseawk_la_OBJECTS = awk.lo err.lo tree.lo parse.lo run.lo rec.lo \
|
||||
val.lo func.lo misc.lo extio.lo std.lo
|
||||
libaseawk_la_OBJECTS = $(am_libaseawk_la_OBJECTS)
|
||||
DEFAULT_INCLUDES =
|
||||
depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp
|
||||
|
@ -35,7 +35,7 @@ static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
ase_vfprintf (stderr, fmt, ap);
|
||||
ase_vfprintf (ASE_STDERR, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
@ -69,16 +69,16 @@ struct sf_t
|
||||
{
|
||||
struct
|
||||
{
|
||||
const ase_char_t** files;
|
||||
ase_size_t count; /* the number of files */
|
||||
ase_size_t index; /* current file index */
|
||||
ASE_FILE* handle; /* the handle to an open file */
|
||||
const ase_char_t*const* files;
|
||||
ase_size_t count; /* the number of files */
|
||||
ase_size_t index; /* current file index */
|
||||
ASE_FILE* handle; /* the handle to an open file */
|
||||
} in;
|
||||
|
||||
struct
|
||||
{
|
||||
const ase_char_t* file;
|
||||
ASE_FILE* handle;
|
||||
const ase_char_t* file;
|
||||
ASE_FILE* handle;
|
||||
} out;
|
||||
};
|
||||
|
||||
@ -90,8 +90,16 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
if (cmd == ASE_AWK_IO_OPEN)
|
||||
{
|
||||
if (sf->in.index >= sf->in.count) return 0;
|
||||
sf->in.handle = ase_fopen (sf->in.files[sf->in.index], ASE_T("r"));
|
||||
if (sf->in.handle == ASE_NULL) return -1;
|
||||
|
||||
if (sf->in.files[sf->in.index][0] == ASE_T('\0'))
|
||||
{
|
||||
sf->in.handle = ASE_STDIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
sf->in.handle = ase_fopen (sf->in.files[sf->in.index], ASE_T("r"));
|
||||
if (sf->in.handle == ASE_NULL) return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
ase_awk_setsinname ();
|
||||
@ -102,8 +110,7 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
else if (cmd == ASE_AWK_IO_CLOSE)
|
||||
{
|
||||
if (sf->in.index >= sf->in.count) return 0;
|
||||
|
||||
fclose (sf->in.handle);
|
||||
if (sf->in.handle != ASE_STDIN) ase_fclose (sf->in.handle);
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_READ)
|
||||
@ -129,9 +136,16 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
sf->in.index++;
|
||||
if (sf->in.index < sf->in.count)
|
||||
{
|
||||
ase_fclose (fp);
|
||||
sf->in.handle = ase_fopen (sf->in.files[sf->in.index], ASE_T("r"));
|
||||
if (sf->in.handle == ASE_NULL) return -1;
|
||||
if (fp != ASE_STDIN) ase_fclose (fp);
|
||||
if (sf->in.files[sf->in.index][0] == ASE_T('\0'))
|
||||
{
|
||||
sf->in.handle = ASE_STDIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
sf->in.handle = ase_fopen (sf->in.files[sf->in.index], ASE_T("r"));
|
||||
if (sf->in.handle == ASE_NULL) return -1;
|
||||
}
|
||||
/* TODO: reset internal line counters...
|
||||
ase_awk_setsinname ();
|
||||
*/
|
||||
@ -144,16 +158,29 @@ static ase_ssize_t sf_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static ase_ssize_t sf_out (
|
||||
int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
static ase_ssize_t sf_out (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
{
|
||||
/*struct srcio_data_t* srcio = (struct srcio_data_t*)arg;*/
|
||||
sf_t* sf = (sf_t*)arg;
|
||||
|
||||
if (cmd == ASE_AWK_IO_OPEN) return 1;
|
||||
if (cmd == ASE_AWK_IO_OPEN)
|
||||
{
|
||||
if (sf->out.file[0] == ASE_T('\0'))
|
||||
{
|
||||
sf->out.handle = ASE_STDOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
sf->out.handle = ase_fopen (sf->out.file, ASE_T("r"));
|
||||
if (sf->out.handle == ASE_NULL) return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_CLOSE)
|
||||
{
|
||||
ase_fflush (stdout);
|
||||
ase_fflush (sf->out.handle);
|
||||
if (sf->out.handle != ASE_STDOUT &&
|
||||
sf->out.handle != ASE_STDERR) ase_fclose (sf->out.handle);
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_WRITE)
|
||||
@ -164,13 +191,13 @@ static ase_ssize_t sf_out (
|
||||
{
|
||||
if (*data == ASE_T('\0'))
|
||||
{
|
||||
if (ase_fputc (*data, stdout) == ASE_CHAR_EOF) return -1;
|
||||
if (ase_fputc (*data, sf->out.handle) == ASE_CHAR_EOF) return -1;
|
||||
left -= 1; data += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
|
||||
int n = ase_fprintf (stdout, ASE_T("%.*s"), chunk, data);
|
||||
int n = ase_fprintf (sf->out.handle, ASE_T("%.*s"), chunk, data);
|
||||
if (n < 0) return -1;
|
||||
left -= n; data += n;
|
||||
}
|
||||
@ -181,13 +208,18 @@ static ase_ssize_t sf_out (
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ase_awk_parsefiles (ase_awk_t* awk, const ase_char_t** isf, ase_size_t isfl, const ase_char_t* osf)
|
||||
int ase_awk_parsefiles (ase_awk_t* awk, const ase_char_t*const* isf, ase_size_t isfl, const ase_char_t* osf)
|
||||
{
|
||||
sf_t sf;
|
||||
ase_awk_srcios_t sio;
|
||||
|
||||
if (isf == ASE_NULL || isfl == 0)
|
||||
{
|
||||
ase_awk_seterrnum (awk, ASE_AWK_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sf.in.files = isf;
|
||||
sf.in.count = isfl;
|
||||
sf.in.index = 0;
|
||||
@ -196,8 +228,7 @@ int ase_awk_parsefiles (ase_awk_t* awk, const ase_char_t** isf, ase_size_t isfl,
|
||||
sf.out.file = osf;
|
||||
|
||||
sio.in = sf_in;
|
||||
//sio.out = deparse? sf_out: NULL;
|
||||
sio.out = ASE_NULL;
|
||||
sio.out = (osf == ASE_NULL)? ASE_NULL: sf_out;
|
||||
sio.data = &sf;
|
||||
|
||||
return ase_awk_parse (awk, &sio);
|
||||
|
Reference in New Issue
Block a user