This commit is contained in:
parent
9900c570e2
commit
97fb77f21f
@ -97,35 +97,35 @@ static int handle_args (int argc, ase_char_t* argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xin_t
|
typedef struct xin_t
|
||||||
{
|
{
|
||||||
const ase_char_t* name;
|
const ase_char_t* name;
|
||||||
ASE_FILE* fp;
|
ASE_FILE* fp;
|
||||||
};
|
} xin_t;
|
||||||
|
|
||||||
struct xout_t
|
typedef struct xout_t
|
||||||
{
|
{
|
||||||
const ase_char_t* name;
|
const ase_char_t* name;
|
||||||
ASE_FILE* fp;
|
ASE_FILE* fp;
|
||||||
};
|
} xout_t;
|
||||||
|
|
||||||
|
|
||||||
static int io_1 (ase_tgp_t* tgp, int cmd, ase_char_t* buf, int len)
|
static int io_1 (int cmd, void* arg, ase_char_t* buf, int len)
|
||||||
{
|
{
|
||||||
xin_t* xin = (xin_t*)arg;
|
xin_t* xin = (xin_t*)arg;
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case ASE_IO_OPEN:
|
case ASE_TGP_IO_OPEN:
|
||||||
xin->fp = ase_fopen (ASE_T("abc.tgp"), ASE_T("r"));
|
xin->fp = ase_fopen (ASE_T("abc.tgp"), ASE_T("r"));
|
||||||
return (xin->fp == NULL) -1: 0;
|
return (xin->fp == NULL)? -1: 0;
|
||||||
|
|
||||||
case ASE_IO_CLOSE
|
case ASE_TGP_IO_CLOSE:
|
||||||
ase_fclose (xin->fp);
|
ase_fclose (xin->fp);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ASE_IO_READ:
|
case ASE_TGP_IO_READ:
|
||||||
ase_fgets (xin->fp);
|
//ase_fgets (xin->fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +151,8 @@ int tgp_main (int argc, ase_char_t* argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ase_tgp_setstdin (tgp, io, xin);
|
//ase_tgp_setstdin (tgp, io, xin);
|
||||||
ase_tgp_setstdout (tgp, io, ASE_NULL);
|
//ase_tgp_setstdout (tgp, io, ASE_NULL);
|
||||||
/*
|
/*
|
||||||
ase_tgp_setexecin (tgp, io, );
|
ase_tgp_setexecin (tgp, io, );
|
||||||
ase_tgp_setexecout (tgp, io, );
|
ase_tgp_setexecout (tgp, io, );
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: tgp.h 233 2008-06-29 13:41:11Z baconevi $
|
* $Id: tgp.h 235 2008-07-05 07:25:54Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -33,9 +33,6 @@ void ase_tgp_close (ase_tgp_t* tgp);
|
|||||||
void ase_tgp_setassocdata (ase_tgp_t* tgp, void* data);
|
void ase_tgp_setassocdata (ase_tgp_t* tgp, void* data);
|
||||||
void* ase_tgp_getassocdata (ase_tgp_t* tgp);
|
void* ase_tgp_getassocdata (ase_tgp_t* tgp);
|
||||||
|
|
||||||
void ase_tgp_setio (ase_tgp_t* tgp, ase_tgp_io_t* io);
|
|
||||||
void ase_tgp_getio (ase_tgp_t* tgp, ase_tgp_io_t* io);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,13 +11,23 @@ struct ase_tgp_t
|
|||||||
void* assoc_data;
|
void* assoc_data;
|
||||||
int errnum;
|
int errnum;
|
||||||
|
|
||||||
ase_tgp_io_t* ih;
|
struct
|
||||||
ase_tgp_io_t* oh;
|
{
|
||||||
ase_tgp_io_t* rh;
|
ase_tgp_io_t func;
|
||||||
|
void* arg;
|
||||||
|
} ih;
|
||||||
|
|
||||||
void* ih_arg;
|
struct
|
||||||
void* oh_arg;
|
{
|
||||||
void* rh_arg;
|
ase_tgp_io_t func;
|
||||||
|
void* arg;
|
||||||
|
} oh;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ase_tgp_io_t func;
|
||||||
|
void* arg;
|
||||||
|
} rh;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -92,7 +102,7 @@ static int getc (ase_tgp_t* tgp, ase_char_t* c)
|
|||||||
{
|
{
|
||||||
ase_ssize_t n;
|
ase_ssize_t n;
|
||||||
|
|
||||||
n = tgp->ih (tgp->ih.arg, ASE_TGP_IO_READ, tgp->ib.ptr, ASE_COUNTOF(tgp->ib.ptr));
|
n = tgp->ih.func (ASE_TGP_IO_READ, tgp->ih.arg, tgp->ib.ptr, ASE_COUNTOF(tgp->ib.ptr));
|
||||||
if (n < 0) return -1;
|
if (n < 0) return -1;
|
||||||
else if (n == 0)
|
else if (n == 0)
|
||||||
{
|
{
|
||||||
@ -117,7 +127,7 @@ static int putc (ase_tgp_t* tgp, ase_char_t c)
|
|||||||
ase_ssize_t n;
|
ase_ssize_t n;
|
||||||
|
|
||||||
/* TODO: submit on a newline as well */
|
/* TODO: submit on a newline as well */
|
||||||
n = tgp->oh (tgp->oh.arg, ASE_TGP_IO_WRITE, tgp->ob.ptr, ASE_COUNTOF(tgp->ob.ptr));
|
n = tgp->oh.func (ASE_TGP_IO_WRITE, tgp->oh.arg, tgp->ob.ptr, ASE_COUNTOF(tgp->ob.ptr));
|
||||||
if (n < 0) return -1;
|
if (n < 0) return -1;
|
||||||
else if (n == 0) return 0;
|
else if (n == 0) return 0;
|
||||||
}
|
}
|
||||||
@ -132,11 +142,11 @@ static int runc (ase_tgp_t* tgp, ase_char_t c)
|
|||||||
{
|
{
|
||||||
ase_ssize_t n;
|
ase_ssize_t n;
|
||||||
|
|
||||||
n = tgp->rh (tgp->rh.arg, ASE_TGP_IO_PUT, tgp->rb.ptr, tgp->rb.len);
|
n = tgp->rh.func (ASE_TGP_IO_WRITE, tgp->rh.arg, tgp->rb.ptr, tgp->rb.len);
|
||||||
if (n < 0) return -1;
|
if (n < 0) return -1;
|
||||||
else if (n == 0) return 0;
|
else if (n == 0) return 0;
|
||||||
|
|
||||||
tgp->rh (tgp->rh.arg, ASE_TGP_IO_GET, tgp->rb.ptr, tgp->rb.len);
|
tgp->rh.func (ASE_TGP_IO_READ, tgp->rh.arg, tgp->rb.ptr, tgp->rb.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
tgp->rb.ptr[tgp->rb.len++] = c;
|
tgp->rb.ptr[tgp->rb.len++] = c;
|
||||||
@ -252,38 +262,38 @@ int ase_tgp_run (ase_tgp_t* tgp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_tgp_attachin (ase_tgp_t* tgp, ase_tgp_io_t* io, void* arg)
|
void ase_tgp_attachin (ase_tgp_t* tgp, ase_tgp_io_t io, void* arg)
|
||||||
{
|
{
|
||||||
tgp->ih = io;
|
tgp->ih.func = io;
|
||||||
tgp->ih_arg = arg;
|
tgp->ih.arg = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_tgp_detachin (ase_tgp_t* tgp)
|
void ase_tgp_detachin (ase_tgp_t* tgp)
|
||||||
{
|
{
|
||||||
tgp->ih = ASE_NULL;
|
tgp->ih.func = ASE_NULL;
|
||||||
tgp->ih_arg = ASE_NULL;
|
tgp->ih.arg = ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_tgp_attachout (ase_tgp_t* tgp, ase_tgp_io_t* io)
|
void ase_tgp_attachout (ase_tgp_t* tgp, ase_tgp_io_t io, void* arg)
|
||||||
{
|
{
|
||||||
tgp->oh = io;
|
tgp->oh.func = io;
|
||||||
tgp->oh_arg = arg;
|
tgp->oh.arg = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_tgp_detachout (ase_tgp_t* tgp)
|
void ase_tgp_detachout (ase_tgp_t* tgp)
|
||||||
{
|
{
|
||||||
tgp->oh = ASE_NULL;
|
tgp->oh.func = ASE_NULL;
|
||||||
tgp->oh_arg = ASE_NULL;
|
tgp->oh.arg = ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_tgp_attachin (ase_tgp_t* tgp, ase_tgp_io_t* io)
|
void ase_tgp_attachexec (ase_tgp_t* tgp, ase_tgp_io_t io, void* arg)
|
||||||
{
|
{
|
||||||
tgp->rh = io;
|
tgp->rh.func = io;
|
||||||
tgp->rh_arg = arg;
|
tgp->rh.arg = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ase_tgp_detachin (ase_tgp_t* tgp)
|
void ase_tgp_detachexec (ase_tgp_t* tgp)
|
||||||
{
|
{
|
||||||
tgp->rh = ASE_NULL;
|
tgp->rh.func = ASE_NULL;
|
||||||
tgp->rh_arg = ASE_NULL;
|
tgp->rh.arg = ASE_NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user