renamed a parameter name of ase_awk_getrundata()

This commit is contained in:
hyung-hwan 2008-12-12 07:43:05 +00:00
parent cd1dd05766
commit 25a776e842
6 changed files with 176 additions and 135 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h 469 2008-12-11 10:05:28Z baconevi $ * $Id: awk.h 470 2008-12-11 13:43:05Z baconevi $
* *
* {License} * {License}
*/ */
@ -975,7 +975,7 @@ ase_mmgr_t* ase_awk_getrunmmgr (
* SYNOPSIS * SYNOPSIS
*/ */
void* ase_awk_getrundata ( void* ase_awk_getrundata (
ase_awk_run_t* awk ase_awk_run_t* run
); );
/******/ /******/

View File

@ -88,6 +88,21 @@ ase_fio_hnd_t ase_fio_gethandle (
ase_fio_t* fio ase_fio_t* fio
); );
/****f* ase.cmn.fio/ase_fio_sethandle
* SYNOPSIS
* ase_fio_sethandle - set the file handle
* WARNING
* Avoid using this function if you don't know what you are doing.
* You may have to retrieve the previous handle using ase_fio_gethandle()
* to take relevant actions before resetting it with ase_fio_sethandle().
* SYNOPSIS
*/
void ase_fio_sethandle (
ase_fio_t* fio,
ase_fio_hnd_t handle
);
/******/
ase_fio_off_t ase_fio_seek ( ase_fio_off_t ase_fio_seek (
ase_fio_t* fio, ase_fio_t* fio,
ase_fio_off_t offset, ase_fio_off_t offset,

View File

@ -68,19 +68,55 @@ void ase_sio_fini (
ase_sio_t* sio ase_sio_t* sio
); );
ase_fio_hnd_t ase_sio_gethandle (ase_sio_t* sio); ase_fio_hnd_t ase_sio_gethandle (
ase_sio_t* sio
);
ase_ssize_t ase_sio_flush (ase_sio_t* sio); ase_ssize_t ase_sio_flush (
void ase_sio_purge (ase_sio_t* sio); ase_sio_t* sio
);
ase_ssize_t ase_sio_getc (ase_sio_t* sio, ase_char_t* c); void ase_sio_purge (
ase_ssize_t ase_sio_gets (ase_sio_t* sio, ase_char_t* buf, ase_size_t size); ase_sio_t* sio
ase_ssize_t ase_sio_getsx (ase_sio_t* sio, ase_char_t* buf, ase_size_t size); );
ase_ssize_t ase_sio_getstr (ase_sio_t* sio, ase_str_t* buf);
ase_ssize_t ase_sio_putc (ase_sio_t* sio, ase_char_t c); ase_ssize_t ase_sio_getc (
ase_ssize_t ase_sio_puts (ase_sio_t* sio, const ase_char_t* str); ase_sio_t* sio,
ase_ssize_t ase_sio_putsx (ase_sio_t* sio, const ase_char_t* str, ase_size_t size); ase_char_t* c
);
ase_ssize_t ase_sio_gets (
ase_sio_t* sio,
ase_char_t* buf,
ase_size_t size
);
ase_ssize_t ase_sio_getsx (
ase_sio_t* sio,
ase_char_t* buf,
ase_size_t size
);
ase_ssize_t ase_sio_getstr (
ase_sio_t* sio,
ase_str_t* buf
);
ase_ssize_t ase_sio_putc (
ase_sio_t* sio,
ase_char_t c
);
ase_ssize_t ase_sio_puts (
ase_sio_t* sio,
const ase_char_t* str
);
ase_ssize_t ase_sio_putsx (
ase_sio_t* sio,
const ase_char_t* str,
ase_size_t size
);
#if 0 #if 0
ase_ssize_t ase_sio_putsn (ase_sio_t* sio, ...); ase_ssize_t ase_sio_putsn (ase_sio_t* sio, ...);

View File

@ -448,9 +448,79 @@ static ase_ssize_t awk_extio_file (
return -1; return -1;
} }
static int open_extio_console (ase_awk_extio_t* epa); static int open_extio_console (ase_awk_extio_t* epa)
static int close_extio_console (ase_awk_extio_t* epa); {
static int next_extio_console (ase_awk_extio_t* epa); runio_data_t* rd = (runio_data_t*)epa->data;
//dprint (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type);
if (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ)
{
if (rd->icf[rd->icf_cur] == ASE_NULL)
{
/* no more input file */
//dprint (ASE_T("console - no more file\n"));;
return 0;
}
if (rd->icf[rd->icf_cur][0] == ASE_T('\0'))
{
//dprint (ASE_T(" console(r) - <standard input>\n"));
epa->handle = ase_sio_in;
}
else
{
/* a temporary variable fp is used here not to change
* any fields of epa when the open operation fails */
ase_sio_t* fp;
fp = ase_sio_open (
ase_awk_getrunmmgr(epa->run),
0,
rd->icf[rd->icf_cur],
ASE_SIO_READ
);
if (fp == ASE_NULL)
{
ase_cstr_t errarg;
errarg.ptr = rd->icf[rd->icf_cur];
errarg.len = ase_strlen(rd->icf[rd->icf_cur]);
ase_awk_setrunerror (epa->run, ASE_AWK_EOPEN, 0, &errarg, 1);
return -1;
}
//dprint (ASE_T(" console(r) - %s\n"), rd->icf[rd->icf_cur]);
if (ase_awk_setfilename (
epa->run, rd->icf[rd->icf_cur],
ase_strlen(rd->icf[rd->icf_cur])) == -1)
{
ase_sio_close (fp);
return -1;
}
epa->handle = fp;
}
rd->icf_cur++;
return 1;
}
else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE)
{
//dprint (ASE_T(" console(w) - <standard output>\n"));
if (ase_awk_setofilename (epa->run, ASE_T(""), 0) == -1)
{
return -1;
}
epa->handle = ase_sio_out;
return 1;
}
return -1;
}
static ase_ssize_t awk_extio_console ( static ase_ssize_t awk_extio_console (
int cmd, void* arg, ase_char_t* data, ase_size_t size) int cmd, void* arg, ase_char_t* data, ase_size_t size)
@ -464,7 +534,17 @@ static ase_ssize_t awk_extio_console (
} }
else if (cmd == ASE_AWK_IO_CLOSE) else if (cmd == ASE_AWK_IO_CLOSE)
{ {
return close_extio_console (epa); //dprint (ASE_T("closing console of type %x\n"), epa->type);
if (epa->handle != ASE_NULL &&
epa->handle != ase_sio_in &&
epa->handle != ase_sio_out &&
epa->handle != ase_sio_err)
{
ase_sio_close ((ase_sio_t*)epa->handle);
}
return 0;
} }
else if (cmd == ASE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
@ -561,129 +641,34 @@ static ase_ssize_t awk_extio_console (
} }
else if (cmd == ASE_AWK_IO_NEXT) else if (cmd == ASE_AWK_IO_NEXT)
{ {
return next_extio_console (epa); int n;
} ase_sio_t* fp = (ase_sio_t*)epa->handle;
return -1; //dprint (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type);
}
static int open_extio_console (ase_awk_extio_t* epa) n = open_extio_console(epa);
{ if (n == -1) return -1;
runio_data_t* rd = (runio_data_t*)epa->data;
if (n == 0)
//dprint (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type);
if (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ)
{
if (rd->icf[rd->icf_cur] == ASE_NULL)
{ {
/* no more input file */ /* if there is no more file, keep the previous handle */
//dprint (ASE_T("console - no more file\n"));;
return 0; return 0;
} }
if (rd->icf[rd->icf_cur][0] == ASE_T('\0')) if (fp != ASE_NULL &&
fp != ase_sio_in &&
fp != ase_sio_out &&
fp != ase_sio_err)
{ {
//dprint (ASE_T(" console(r) - <standard input>\n")); ase_sio_close (fp);
epa->handle = ase_sio_in;
}
else
{
/* a temporary variable fp is used here not to change
* any fields of epa when the open operation fails */
ase_sio_t* fp;
fp = ase_sio_open (
ase_awk_getrunmmgr(epa->run),
0,
rd->icf[rd->icf_cur],
ASE_SIO_READ
);
if (fp == ASE_NULL)
{
ase_cstr_t errarg;
errarg.ptr = rd->icf[rd->icf_cur];
errarg.len = ase_strlen(rd->icf[rd->icf_cur]);
ase_awk_setrunerror (epa->run, ASE_AWK_EOPEN, 0, &errarg, 1);
return -1;
}
//dprint (ASE_T(" console(r) - %s\n"), rd->icf[rd->icf_cur]);
if (ase_awk_setfilename (
epa->run, rd->icf[rd->icf_cur],
ase_strlen(rd->icf[rd->icf_cur])) == -1)
{
ase_sio_close (fp);
return -1;
}
epa->handle = fp;
} }
rd->icf_cur++; return n;
return 1;
}
else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE)
{
//dprint (ASE_T(" console(w) - <standard output>\n"));
if (ase_awk_setofilename (epa->run, ASE_T(""), 0) == -1)
{
return -1;
}
epa->handle = ase_sio_out;
return 1;
} }
return -1; return -1;
} }
static int close_extio_console (ase_awk_extio_t* epa)
{
//dprint (ASE_T("closing console of type %x\n"), epa->type);
if (epa->handle != ASE_NULL &&
epa->handle != ase_sio_in &&
epa->handle != ase_sio_out &&
epa->handle != ase_sio_err)
{
ase_sio_close ((ase_sio_t*)epa->handle);
}
return 0;
}
static int next_extio_console (ase_awk_extio_t* epa)
{
int n;
ase_sio_t* fp = (ase_sio_t*)epa->handle;
//dprint (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type);
n = open_extio_console(epa);
if (n == -1) return -1;
if (n == 0)
{
/* if there is no more file, keep the previous handle */
return 0;
}
if (fp != ASE_NULL &&
fp != ase_sio_in &&
fp != ase_sio_out &&
fp != ase_sio_err)
{
ase_sio_close (fp);
}
return n;
}
int ase_awk_runsimple (ase_awk_t* awk, ase_char_t** icf) int ase_awk_runsimple (ase_awk_t* awk, ase_char_t** icf)
{ {
ase_awk_runcbs_t runcbs; ase_awk_runcbs_t runcbs;

View File

@ -181,6 +181,11 @@ ase_fio_hnd_t ase_fio_gethandle (ase_fio_t* fio)
return fio->handle; return fio->handle;
} }
void ase_fio_sethandle (ase_fio_t* fio, ase_fio_hnd_t handle)
{
fio->handle = handle;
}
ase_fio_off_t ase_fio_seek ( ase_fio_off_t ase_fio_seek (
ase_fio_t* fio, ase_fio_off_t offset, ase_fio_ori_t origin) ase_fio_t* fio, ase_fio_off_t offset, ase_fio_ori_t origin)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: rex.c 337 2008-08-20 09:17:25Z baconevi $ * $Id: rex.c 470 2008-12-11 13:43:05Z baconevi $
* *
* {License} * {License}
*/ */
@ -9,7 +9,8 @@
#include "chr.h" #include "chr.h"
#ifdef DEBUG_REX #ifdef DEBUG_REX
#include <ase/utl/stdio.h> #include <ase/bas/sio.h>
#define DPUTS(x) ase_sio_puts(&ase_sio_err,x)
#endif #endif
enum enum
@ -736,8 +737,7 @@ static int build_charset (builder_t* builder, code_t* cmd)
{ {
/* invalid range */ /* invalid range */
#ifdef DEBUG_REX #ifdef DEBUG_REX
ase_dprintf ( DPUTS (ASE_T("build_charset: invalid character set range\n"));
ASE_T("build_charset: invalid character set range\n"));
#endif #endif
builder->errnum = ASE_REX_ECRANGE; builder->errnum = ASE_REX_ECRANGE;
return -1; return -1;
@ -768,7 +768,7 @@ static int build_cclass (builder_t* builder, ase_char_t* cc)
{ {
/* wrong class name */ /* wrong class name */
#ifdef DEBUG_REX #ifdef DEBUG_REX
ase_dprintf (ASE_T("build_cclass: wrong class name\n")); DPUTS (ASE_T("build_cclass: wrong class name\n"));
#endif #endif
builder->errnum = ASE_REX_ECCLASS; builder->errnum = ASE_REX_ECCLASS;
return -1; return -1;
@ -781,7 +781,7 @@ static int build_cclass (builder_t* builder, ase_char_t* cc)
builder->ptn.curc.value != ASE_T(':')) builder->ptn.curc.value != ASE_T(':'))
{ {
#ifdef DEBUG_REX #ifdef DEBUG_REX
ase_dprintf (ASE_T("build_cclass: a colon(:) expected\n")); DPUTS (ASE_T("build_cclass: a colon(:) expected\n"));
#endif #endif
builder->errnum = ASE_REX_ECOLON; builder->errnum = ASE_REX_ECOLON;
return -1; return -1;
@ -794,7 +794,7 @@ static int build_cclass (builder_t* builder, ase_char_t* cc)
builder->ptn.curc.value != ASE_T(']')) builder->ptn.curc.value != ASE_T(']'))
{ {
#ifdef DEBUG_REX #ifdef DEBUG_REX
ase_dprintf (ASE_T("build_cclass: ] expected\n")); DPUTS (ASE_T("build_cclass: ] expected\n"));
#endif #endif
builder->errnum = ASE_REX_ERBRACKET; builder->errnum = ASE_REX_ERBRACKET;
return -1; return -1;
@ -1427,11 +1427,11 @@ static const ase_byte_t* match_ord_char (
while (si < ubound) while (si < ubound)
{ {
if (&mat->match_ptr[si] >= matcher->match.str.end) break; if (&mat->match_ptr[si] >= matcher->match.str.end) break;
#ifdef DEBUG_REX #ifdef DEBUG_REX
ase_dprintf ( ase_dprintf (
ASE_T("match_ord_char: <ignorecase> %c %c\n"), ASE_T("match_ord_char: <ignorecase> %c %c\n"),
cc, mat->match_ptr[si]); cc, mat->match_ptr[si]);
#endif #endif
if (cc != ASE_CCLS_TOUPPER (matcher->ccls, mat->match_ptr[si])) break; if (cc != ASE_CCLS_TOUPPER (matcher->ccls, mat->match_ptr[si])) break;
si++; si++;
} }
@ -1441,11 +1441,11 @@ static const ase_byte_t* match_ord_char (
while (si < ubound) while (si < ubound)
{ {
if (&mat->match_ptr[si] >= matcher->match.str.end) break; if (&mat->match_ptr[si] >= matcher->match.str.end) break;
#ifdef DEBUG_REX #ifdef DEBUG_REX
ase_dprintf ( ase_dprintf (
ASE_T("match_ord_char: %c %c\n"), ASE_T("match_ord_char: %c %c\n"),
cc, mat->match_ptr[si]); cc, mat->match_ptr[si]);
#endif #endif
if (cc != mat->match_ptr[si]) break; if (cc != mat->match_ptr[si]) break;
si++; si++;
} }