*** empty log message ***
This commit is contained in:
parent
599d50d936
commit
cb27721259
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h,v 1.106 2006-09-01 06:22:11 bacon Exp $
|
* $Id: awk.h,v 1.107 2006-09-01 16:30:50 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _XP_AWK_AWK_H_
|
#ifndef _XP_AWK_AWK_H_
|
||||||
@ -337,6 +337,10 @@ xp_long_t xp_awk_strtolong (
|
|||||||
xp_real_t xp_awk_strtoreal (
|
xp_real_t xp_awk_strtoreal (
|
||||||
xp_awk_t* awk, const xp_char_t* str);
|
xp_awk_t* awk, const xp_char_t* str);
|
||||||
|
|
||||||
|
xp_size_t xp_awk_longtostr (
|
||||||
|
xp_long_t value, int radix, const xp_char_t* prefix,
|
||||||
|
xp_char_t* buf, xp_size_t size);
|
||||||
|
|
||||||
/* string functions exported by awk.h */
|
/* string functions exported by awk.h */
|
||||||
xp_char_t* xp_awk_strdup (
|
xp_char_t* xp_awk_strdup (
|
||||||
xp_awk_t* awk, const xp_char_t* str);
|
xp_awk_t* awk, const xp_char_t* str);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: func.c,v 1.42 2006-09-01 07:18:39 bacon Exp $
|
* $Id: func.c,v 1.43 2006-09-01 16:30:50 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -503,7 +503,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
|
|||||||
xp_char_t* str, * p, * tok;
|
xp_char_t* str, * p, * tok;
|
||||||
xp_size_t len, left, tok_len;
|
xp_size_t len, left, tok_len;
|
||||||
xp_long_t num;
|
xp_long_t num;
|
||||||
xp_char_t key[32];
|
xp_char_t key[xp_sizeof(xp_long_t)*8+2];
|
||||||
|
|
||||||
nargs = xp_awk_getnargs (run);
|
nargs = xp_awk_getnargs (run);
|
||||||
xp_assert (nargs >= 2 && nargs <= 3);
|
xp_assert (nargs >= 2 && nargs <= 3);
|
||||||
@ -579,16 +579,7 @@ static int __bfn_split (xp_awk_t* awk, void* run)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* put it into the map */
|
/* put it into the map */
|
||||||
/* TODO: remove dependency on xp_awk_sprintf */
|
xp_awk_longtostr (num, 10, XP_NULL, key, xp_countof(key));
|
||||||
#if defined(__LCC__)
|
|
||||||
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%lld"), (long long)num);
|
|
||||||
#elif defined(__BORLANDC__) || defined(_MSC_VER)
|
|
||||||
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%I64d"), (__int64)num);
|
|
||||||
#elif defined(vax) || defined(__vax) || defined(_SCO_DS)
|
|
||||||
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%ld"), (long)num);
|
|
||||||
#else
|
|
||||||
xp_awk_sprintf (awk, key, xp_countof(key), XP_T("%lld"), (long long)num);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (xp_awk_map_putx (
|
if (xp_awk_map_putx (
|
||||||
((xp_awk_val_map_t*)t1)->map,
|
((xp_awk_val_map_t*)t1)->map,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: misc.c,v 1.11 2006-09-01 07:18:40 bacon Exp $
|
* $Id: misc.c,v 1.12 2006-09-01 16:30:50 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -290,6 +290,79 @@ done:
|
|||||||
return (sign)? -fraction: fraction;
|
return (sign)? -fraction: fraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xp_size_t xp_awk_longtostr (
|
||||||
|
xp_long_t value, int radix, const xp_char_t* prefix,
|
||||||
|
xp_char_t* buf, xp_size_t size)
|
||||||
|
{
|
||||||
|
xp_long_t t, rem;
|
||||||
|
xp_size_t len, ret, i;
|
||||||
|
xp_size_t prefix_len;
|
||||||
|
|
||||||
|
prefix_len = (prefix != XP_NULL)? xp_awk_strlen(prefix): 0;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
/* zero */
|
||||||
|
if (buf == XP_NULL) return prefix_len + 1;
|
||||||
|
|
||||||
|
if (size < prefix_len+1)
|
||||||
|
{
|
||||||
|
/* buffer too small */
|
||||||
|
return (xp_size_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
buf[prefix_len] = XP_T('0');
|
||||||
|
if (size > prefix_len+1) buf[prefix_len+1] = XP_T('\0');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-zero values */
|
||||||
|
len = prefix_len;
|
||||||
|
if (t < 0) { t = -t; len++; }
|
||||||
|
while (t > 0) { len++; t /= radix; }
|
||||||
|
|
||||||
|
if (buf == XP_NULL)
|
||||||
|
{
|
||||||
|
/* if buf is not given, return the number of bytes required */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < len) return (xp_size_t)-1; /* buffer too small */
|
||||||
|
if (size > len) buf[len] = XP_T('\0');
|
||||||
|
ret = len;
|
||||||
|
|
||||||
|
t = value;
|
||||||
|
if (t < 0) t = -t;
|
||||||
|
|
||||||
|
while (t > 0)
|
||||||
|
{
|
||||||
|
rem = t % radix;
|
||||||
|
if (rem >= 10)
|
||||||
|
buf[--len] = (xp_char_t)rem + XP_T('a') - 10;
|
||||||
|
else
|
||||||
|
buf[--len] = (xp_char_t)rem + XP_T('0');
|
||||||
|
t /= radix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
{
|
||||||
|
for (i = 1; i <= prefix_len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = prefix[i-1];
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
buf[--len] = XP_T('-');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
xp_char_t* xp_awk_strdup (xp_awk_t* awk, const xp_char_t* str)
|
xp_char_t* xp_awk_strdup (xp_awk_t* awk, const xp_char_t* str)
|
||||||
{
|
{
|
||||||
xp_char_t* tmp;
|
xp_char_t* tmp;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c,v 1.177 2006-09-01 07:18:40 bacon Exp $
|
* $Id: parse.c,v 1.178 2006-09-01 16:30:50 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk_i.h>
|
#include <xp/awk/awk_i.h>
|
||||||
@ -7,7 +7,6 @@
|
|||||||
#ifndef XP_AWK_STAND_ALONE
|
#ifndef XP_AWK_STAND_ALONE
|
||||||
#include <xp/bas/memory.h>
|
#include <xp/bas/memory.h>
|
||||||
#include <xp/bas/assert.h>
|
#include <xp/bas/assert.h>
|
||||||
#include <xp/bas/stdio.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -4085,7 +4084,7 @@ struct __deparse_func_t
|
|||||||
static int __deparse (xp_awk_t* awk)
|
static int __deparse (xp_awk_t* awk)
|
||||||
{
|
{
|
||||||
xp_awk_chain_t* chain;
|
xp_awk_chain_t* chain;
|
||||||
xp_char_t tmp[64];
|
xp_char_t tmp[xp_sizeof(xp_size_t)*8 + 32];
|
||||||
struct __deparse_func_t df;
|
struct __deparse_func_t df;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@ -4115,16 +4114,20 @@ static int __deparse (xp_awk_t* awk)
|
|||||||
|
|
||||||
for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++)
|
for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++)
|
||||||
{
|
{
|
||||||
xp_awk_sprintf (awk, tmp, xp_countof(tmp),
|
xp_awk_longtostr ((xp_long_t)i,
|
||||||
XP_T("__global%lu, "), (unsigned long)i);
|
10, XP_T("__global"), tmp, xp_countof(tmp));
|
||||||
if (xp_awk_putsrcstr (awk, tmp) == -1)
|
if (xp_awk_putsrcstr (awk, tmp) == -1)
|
||||||
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
|
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
|
||||||
|
if (xp_awk_putsrcstr (awk, XP_T(", ")) == -1)
|
||||||
|
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
xp_awk_sprintf (awk, tmp, xp_countof(tmp),
|
xp_awk_longtostr ((xp_long_t)i,
|
||||||
XP_T("__global%lu;\n\n"), (unsigned long)i);
|
10, XP_T("__global"), tmp, xp_countof(tmp));
|
||||||
if (xp_awk_putsrcstr (awk, tmp) == -1)
|
if (xp_awk_putsrcstr (awk, tmp) == -1)
|
||||||
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
|
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
|
||||||
|
if (xp_awk_putsrcstr (awk, XP_T(";\n\n")) == -1)
|
||||||
|
EXIT_DEPARSE (XP_AWK_ESRCOUTWRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
df.awk = awk;
|
df.awk = awk;
|
||||||
@ -4214,8 +4217,8 @@ static int __deparse_func (xp_awk_pair_t* pair, void* arg)
|
|||||||
|
|
||||||
for (i = 0; i < afn->nargs; )
|
for (i = 0; i < afn->nargs; )
|
||||||
{
|
{
|
||||||
xp_awk_sprintf (df->awk, df->tmp, df->tmp_len,
|
xp_awk_longtostr (i++, 10,
|
||||||
XP_T("__param%lu"), (unsigned long)i++);
|
XP_T("__param"), df->tmp, df->tmp_len);
|
||||||
if (xp_awk_putsrcstr (df->awk, df->tmp) == -1) return -1;
|
if (xp_awk_putsrcstr (df->awk, df->tmp) == -1) return -1;
|
||||||
if (i >= afn->nargs) break;
|
if (i >= afn->nargs) break;
|
||||||
if (xp_awk_putsrcstr (df->awk, XP_T(", ")) == -1) return -1;
|
if (xp_awk_putsrcstr (df->awk, XP_T(", ")) == -1) return -1;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.85 2006-09-01 07:18:40 bacon Exp $
|
* $Id: awk.c,v 1.86 2006-09-01 16:31:13 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/awk/awk.h>
|
#include <xp/awk/awk.h>
|
||||||
@ -768,6 +768,16 @@ int xp_main (int argc, xp_char_t* argv[])
|
|||||||
_CrtSetDbgFlag (_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF);
|
_CrtSetDbgFlag (_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF);
|
||||||
#endif*/
|
#endif*/
|
||||||
|
|
||||||
|
{
|
||||||
|
xp_char_t buf[xp_sizeof(xp_long_t)*8+2+2];
|
||||||
|
xp_size_t n;
|
||||||
|
n = xp_awk_longtostr (-0x7FFFFFFFFFFFFFFFi64, 16, XP_T("0x"), buf, xp_countof(buf));
|
||||||
|
if (n == (xp_size_t)-1)
|
||||||
|
{
|
||||||
|
xp_printf (XP_T("cannot convert...\n"));
|
||||||
|
}
|
||||||
|
else xp_printf (XP_T("%d, %s\n"), n, buf);
|
||||||
|
}
|
||||||
n = __main (argc, argv);
|
n = __main (argc, argv);
|
||||||
|
|
||||||
#if defined(__linux) && defined(_DEBUG)
|
#if defined(__linux) && defined(_DEBUG)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//global xyz;
|
#global xyz;
|
||||||
|
|
||||||
END {
|
END {
|
||||||
//local xyz;
|
#local xyz;
|
||||||
|
|
||||||
print index ("abc", "abc");
|
print index ("abc", "abc");
|
||||||
print index ("abc", "b");
|
print index ("abc", "b");
|
||||||
@ -25,13 +25,13 @@ END {
|
|||||||
print toupper ("AbcDEF");
|
print toupper ("AbcDEF");
|
||||||
|
|
||||||
arr[0] = "xxx";
|
arr[0] = "xxx";
|
||||||
//print split ("abc def abc", arr);
|
#print split ("abc def abc", arr);
|
||||||
print split ("abc def abc", j);
|
print split ("abc def kkk", j);
|
||||||
|
|
||||||
//xyz = 20;
|
#xyz = 20;
|
||||||
//print xyz;
|
#print xyz;
|
||||||
print split ("abc def abc", ((xyz)));
|
print split ("abc def kkk", ((xyz)));
|
||||||
//for (i in arr)
|
#for (i in arr)
|
||||||
|
|
||||||
for (i in xyz)
|
for (i in xyz)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user