qse/ase/lib/awk/std.c

66 lines
1.2 KiB
C
Raw Normal View History

2008-08-04 08:14:52 +00:00
/*
* $Id$
*/
#include "awk_i.h"
2008-08-04 08:13:03 +00:00
#include <ase/utl/stdio.h>
2008-08-04 08:14:52 +00:00
#include <ase/utl/helper.h>
#include <math.h>
2008-08-04 08:13:03 +00:00
typedef struct ext_t
{
ase_awk_prmfns_t prmfns;
}
ext_t;
static ase_real_t custom_awk_pow (void* custom, ase_real_t x, ase_real_t y)
{
return pow (x, y);
}
static int custom_awk_sprintf (
void* custom, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = ase_vsprintf (buf, size, fmt, ap);
va_end (ap);
return n;
}
static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
ase_vfprintf (stderr, fmt, ap);
va_end (ap);
}
ase_awk_t* ase_awk_openstd (void)
{
ase_awk_t* awk;
2008-08-04 08:14:52 +00:00
ext_t* ext;
2008-08-04 08:13:03 +00:00
awk = ase_awk_open (ASE_MMGR_GET(), ASE_SIZEOF(ext_t), ASE_NULL);
2008-08-04 08:14:52 +00:00
ase_awk_setccls (awk, ASE_GETCCLS());
2008-08-04 08:13:03 +00:00
ext = (ext_t*) ase_awk_getextension (awk);
ext->prmfns.pow = custom_awk_pow;
ext->prmfns.sprintf = custom_awk_sprintf;
ext->prmfns.dprintf = custom_awk_dprintf;
ext->prmfns.custom_data = ASE_NULL;
ase_awk_setprmfns (awk, &ext->prmfns);
ase_awk_setoption (awk,
ASE_AWK_IMPLICIT | ASE_AWK_EXTIO | ASE_AWK_NEWLINE |
ASE_AWK_BASEONE | ASE_AWK_PABLOCK);
/*ase_awk_addfunction ();*/
return awk;
}