*** empty log message ***
This commit is contained in:
parent
2de8c5f69e
commit
244c5062d9
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.java,v 1.6 2006-11-22 15:12:03 bacon Exp $
|
* $Id: Awk.java,v 1.7 2006-11-23 03:31:35 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ase.awk;
|
package ase.awk;
|
||||||
@ -30,14 +30,19 @@ public abstract class Awk
|
|||||||
private native void open () throws Exception;
|
private native void open () throws Exception;
|
||||||
private native int setconsolename (long run_id, String name);
|
private native int setconsolename (long run_id, String name);
|
||||||
|
|
||||||
public void setConsoleName (long run_id, String name) //throws Exception
|
public void setConsoleName (Extio extio, String name) //throws Exception
|
||||||
{
|
{
|
||||||
/* TODO: setconsolename is not safe. for example, it can
|
/* TODO: setconsolename is not safe. for example, it can
|
||||||
* crash the program if run_id is invalid. so this wrapper
|
* crash the program if run_id is invalid. so this wrapper
|
||||||
* needs to do some sanity check. */
|
* needs to do some sanity check. */
|
||||||
//if (setconsolename (run_id, name) == -1)
|
//if (setconsolename (run_id, name) == -1)
|
||||||
// throw new Exception ("cannot set the consle name");
|
// throw new Exception ("cannot set the consle name");
|
||||||
setconsolename (run_id, name);
|
setconsolename (extio.getRunId(), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputConsoleName (Extio extio, String name)
|
||||||
|
{
|
||||||
|
// TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* abstrace methods */
|
/* abstrace methods */
|
||||||
@ -68,6 +73,12 @@ public abstract class Awk
|
|||||||
|
|
||||||
protected int read_extio (Extio extio, char[] buf, int len)
|
protected int read_extio (Extio extio, char[] buf, int len)
|
||||||
{
|
{
|
||||||
|
// this check is needed because 0 is used to indicate
|
||||||
|
// the end of the stream. java streams can return 0
|
||||||
|
// if the data given is 0 bytes and it didn't reach
|
||||||
|
// the end of the stream.
|
||||||
|
if (len <= 0) return -1;
|
||||||
|
|
||||||
int type = extio.getType ();
|
int type = extio.getType ();
|
||||||
if (type == Extio.TYPE_CONSOLE)
|
if (type == Extio.TYPE_CONSOLE)
|
||||||
return read_console (extio, buf, len);
|
return read_console (extio, buf, len);
|
||||||
@ -82,6 +93,8 @@ public abstract class Awk
|
|||||||
|
|
||||||
protected int write_extio (Extio extio, char[] buf, int len)
|
protected int write_extio (Extio extio, char[] buf, int len)
|
||||||
{
|
{
|
||||||
|
if (len <= 0) return -1;
|
||||||
|
|
||||||
int type = extio.getType ();
|
int type = extio.getType ();
|
||||||
if (type == Extio.TYPE_CONSOLE)
|
if (type == Extio.TYPE_CONSOLE)
|
||||||
return write_console (extio, buf, len);
|
return write_console (extio, buf, len);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h,v 1.148 2006-11-21 15:06:14 bacon Exp $
|
* $Id: awk.h,v 1.149 2006-11-23 03:31:35 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ASE_AWK_AWK_H_
|
#ifndef _ASE_AWK_AWK_H_
|
||||||
@ -131,25 +131,6 @@ enum
|
|||||||
ASE_AWK_IO_NEXT = 5
|
ASE_AWK_IO_NEXT = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
ASE_AWK_EXTIO_PIPE_READ = 0,
|
|
||||||
ASE_AWK_EXTIO_PIPE_WRITE = 1,
|
|
||||||
|
|
||||||
/*
|
|
||||||
ASE_AWK_EXTIO_COPROC_READ = 0,
|
|
||||||
ASE_AWK_EXTIO_COPROC_WRITE = 1,
|
|
||||||
ASE_AWK_EXTIO_COPROC_RDWR = 2,
|
|
||||||
*/
|
|
||||||
|
|
||||||
ASE_AWK_EXTIO_FILE_READ = 0,
|
|
||||||
ASE_AWK_EXTIO_FILE_WRITE = 1,
|
|
||||||
ASE_AWK_EXTIO_FILE_APPEND = 2,
|
|
||||||
|
|
||||||
ASE_AWK_EXTIO_CONSOLE_READ = 0,
|
|
||||||
ASE_AWK_EXTIO_CONSOLE_WRITE = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
/* various options */
|
/* various options */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -208,8 +189,11 @@ enum
|
|||||||
*/
|
*/
|
||||||
ASE_AWK_STRIPSPACES = (1 << 12),
|
ASE_AWK_STRIPSPACES = (1 << 12),
|
||||||
|
|
||||||
|
/* enable the nextoutfile keyword */
|
||||||
|
ASE_AWK_NEXTOUTFILE = (1 << 13),
|
||||||
|
|
||||||
/* a newline terminates a statement */
|
/* a newline terminates a statement */
|
||||||
ASE_AWK_NEWLINE = (1 << 13)
|
ASE_AWK_NEWLINE = (1 << 14)
|
||||||
};
|
};
|
||||||
|
|
||||||
/* error code */
|
/* error code */
|
||||||
@ -336,6 +320,25 @@ enum ase_awk_extio_type_t
|
|||||||
ASE_AWK_EXTIO_NUM
|
ASE_AWK_EXTIO_NUM
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ASE_AWK_EXTIO_PIPE_READ = 0,
|
||||||
|
ASE_AWK_EXTIO_PIPE_WRITE = 1,
|
||||||
|
|
||||||
|
/*
|
||||||
|
ASE_AWK_EXTIO_COPROC_READ = 0,
|
||||||
|
ASE_AWK_EXTIO_COPROC_WRITE = 1,
|
||||||
|
ASE_AWK_EXTIO_COPROC_RDWR = 2,
|
||||||
|
*/
|
||||||
|
|
||||||
|
ASE_AWK_EXTIO_FILE_READ = 0,
|
||||||
|
ASE_AWK_EXTIO_FILE_WRITE = 1,
|
||||||
|
ASE_AWK_EXTIO_FILE_APPEND = 2,
|
||||||
|
|
||||||
|
ASE_AWK_EXTIO_CONSOLE_READ = 0,
|
||||||
|
ASE_AWK_EXTIO_CONSOLE_WRITE = 1
|
||||||
|
};
|
||||||
|
|
||||||
/* assertion statement */
|
/* assertion statement */
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define ASE_AWK_ASSERT(awk,expr) ((void)0)
|
#define ASE_AWK_ASSERT(awk,expr) ((void)0)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: extio.c,v 1.62 2006-11-22 15:12:04 bacon Exp $
|
* $Id: extio.c,v 1.63 2006-11-23 03:31:35 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/awk/awk_i.h>
|
||||||
@ -648,6 +648,8 @@ int ase_awk_nextextio_read (
|
|||||||
if (p == ASE_NULL)
|
if (p == ASE_NULL)
|
||||||
{
|
{
|
||||||
/* something is totally wrong */
|
/* something is totally wrong */
|
||||||
|
ASE_AWK_ASSERT (run->awk,
|
||||||
|
!"should never happen - cannot find the relevant extio entry");
|
||||||
run->errnum = ASE_AWK_EINTERNAL;
|
run->errnum = ASE_AWK_EINTERNAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -687,6 +689,81 @@ int ase_awk_nextextio_read (
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ase_awk_nextextio_write (
|
||||||
|
ase_awk_run_t* run, int out_type, const ase_char_t* name)
|
||||||
|
{
|
||||||
|
ase_awk_extio_t* p = run->extio.chain;
|
||||||
|
ase_awk_io_t handler;
|
||||||
|
int extio_type, /*extio_mode,*/ extio_mask, n;
|
||||||
|
|
||||||
|
ASE_AWK_ASSERT (run->awk,
|
||||||
|
out_type >= 0 && out_type <= ase_countof(__out_type_map));
|
||||||
|
ASE_AWK_ASSERT (run->awk,
|
||||||
|
out_type >= 0 && out_type <= ase_countof(__out_mode_map));
|
||||||
|
ASE_AWK_ASSERT (run->awk,
|
||||||
|
out_type >= 0 && out_type <= ase_countof(__out_mask_map));
|
||||||
|
|
||||||
|
/* translate the out_type into the relevant extio type and mode */
|
||||||
|
extio_type = __out_type_map[out_type];
|
||||||
|
/*extio_mode = __out_mode_map[out_type];*/
|
||||||
|
extio_mask = __out_mask_map[out_type];
|
||||||
|
|
||||||
|
handler = run->extio.handler[extio_type];
|
||||||
|
if (handler == ASE_NULL)
|
||||||
|
{
|
||||||
|
/* no io handler provided */
|
||||||
|
run->errnum = ASE_AWK_EIOIMPL; /* TODO: change the error code */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (p != ASE_NULL)
|
||||||
|
{
|
||||||
|
if (p->type == (extio_type | extio_mask) &&
|
||||||
|
ase_awk_strcmp (p->name,name) == 0) break;
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p == ASE_NULL)
|
||||||
|
{
|
||||||
|
/* something is totally wrong */
|
||||||
|
ASE_AWK_ASSERT (run->awk,
|
||||||
|
!"should never happen - cannot find the relevant extio entry");
|
||||||
|
|
||||||
|
run->errnum = ASE_AWK_EINTERNAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->out.eos)
|
||||||
|
{
|
||||||
|
/* no more streams. */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0);
|
||||||
|
if (n == -1)
|
||||||
|
{
|
||||||
|
/* TODO: is this errnum correct? */
|
||||||
|
run->errnum = ASE_AWK_EIOHANDLER;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
/* the next stream cannot be opened.
|
||||||
|
* set the eos flags so that the next call to nextextio_write
|
||||||
|
* will return 0 without executing the handler */
|
||||||
|
p->out.eos = ase_true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* as the next stream has been opened successfully,
|
||||||
|
* the eof flag should be cleared if set */
|
||||||
|
p->out.eof = ase_false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
int ase_awk_closeextio_read (
|
int ase_awk_closeextio_read (
|
||||||
ase_awk_run_t* run, int in_type, const ase_char_t* name)
|
ase_awk_run_t* run, int in_type, const ase_char_t* name)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: extio.h,v 1.15 2006-10-24 04:10:12 bacon Exp $
|
* $Id: extio.h,v 1.16 2006-11-23 03:31:36 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ASE_AWK_EXTIO_H_
|
#ifndef _ASE_AWK_EXTIO_H_
|
||||||
@ -31,10 +31,8 @@ int ase_awk_flushextio (
|
|||||||
int ase_awk_nextextio_read (
|
int ase_awk_nextextio_read (
|
||||||
ase_awk_run_t* run, int in_type, const ase_char_t* name);
|
ase_awk_run_t* run, int in_type, const ase_char_t* name);
|
||||||
|
|
||||||
/* TODO:
|
|
||||||
int ase_awk_nextextio_write (
|
int ase_awk_nextextio_write (
|
||||||
ase_awk_run_t* run, int out_type, const ase_char_t* name);
|
ase_awk_run_t* run, int out_type, const ase_char_t* name);
|
||||||
*/
|
|
||||||
|
|
||||||
int ase_awk_closeextio_read (
|
int ase_awk_closeextio_read (
|
||||||
ase_awk_run_t* run, int in_type, const ase_char_t* name);
|
ase_awk_run_t* run, int in_type, const ase_char_t* name);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: jni.c,v 1.20 2006-11-22 15:12:04 bacon Exp $
|
* $Id: jni.c,v 1.21 2006-11-23 03:31:36 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/jni.h>
|
#include <ase/awk/jni.h>
|
||||||
@ -196,7 +196,8 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
|
|||||||
|
|
||||||
opt = ASE_AWK_EXPLICIT | ASE_AWK_UNIQUE | ASE_AWK_DBLSLASHES |
|
opt = ASE_AWK_EXPLICIT | ASE_AWK_UNIQUE | ASE_AWK_DBLSLASHES |
|
||||||
ASE_AWK_SHADING | ASE_AWK_IMPLICIT | ASE_AWK_SHIFT |
|
ASE_AWK_SHADING | ASE_AWK_IMPLICIT | ASE_AWK_SHIFT |
|
||||||
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_HASHSIGN;
|
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_HASHSIGN |
|
||||||
|
ASE_AWK_NEXTOUTFILE;
|
||||||
ase_awk_setopt (awk, opt);
|
ase_awk_setopt (awk, opt);
|
||||||
|
|
||||||
printf ("__awk(native) done => %u, 0x%X\n", awk, awk);
|
printf ("__awk(native) done => %u, 0x%X\n", awk, awk);
|
||||||
@ -574,7 +575,6 @@ static ase_ssize_t __call_java_read_extio (
|
|||||||
jint ret, i;
|
jint ret, i;
|
||||||
jthrowable thrown;
|
jthrowable thrown;
|
||||||
|
|
||||||
printf ("java_read_extio>>>\n");
|
|
||||||
class = (*env)->GetObjectClass(env, obj);
|
class = (*env)->GetObjectClass(env, obj);
|
||||||
|
|
||||||
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
|
mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c,v 1.204 2006-11-19 11:21:06 bacon Exp $
|
* $Id: parse.c,v 1.205 2006-11-23 03:31:36 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/awk/awk_i.h>
|
||||||
@ -78,6 +78,8 @@ enum
|
|||||||
TOKEN_EXIT,
|
TOKEN_EXIT,
|
||||||
TOKEN_NEXT,
|
TOKEN_NEXT,
|
||||||
TOKEN_NEXTFILE,
|
TOKEN_NEXTFILE,
|
||||||
|
TOKEN_NEXTINFILE,
|
||||||
|
TOKEN_NEXTOUTFILE,
|
||||||
TOKEN_DELETE,
|
TOKEN_DELETE,
|
||||||
TOKEN_PRINT,
|
TOKEN_PRINT,
|
||||||
TOKEN_PRINTF,
|
TOKEN_PRINTF,
|
||||||
@ -182,7 +184,7 @@ static ase_awk_nde_t* __parse_continue (ase_awk_t* awk);
|
|||||||
static ase_awk_nde_t* __parse_return (ase_awk_t* awk);
|
static ase_awk_nde_t* __parse_return (ase_awk_t* awk);
|
||||||
static ase_awk_nde_t* __parse_exit (ase_awk_t* awk);
|
static ase_awk_nde_t* __parse_exit (ase_awk_t* awk);
|
||||||
static ase_awk_nde_t* __parse_next (ase_awk_t* awk);
|
static ase_awk_nde_t* __parse_next (ase_awk_t* awk);
|
||||||
static ase_awk_nde_t* __parse_nextfile (ase_awk_t* awk);
|
static ase_awk_nde_t* __parse_nextfile (ase_awk_t* awk, int out);
|
||||||
static ase_awk_nde_t* __parse_delete (ase_awk_t* awk);
|
static ase_awk_nde_t* __parse_delete (ase_awk_t* awk);
|
||||||
static ase_awk_nde_t* __parse_print (ase_awk_t* awk, int type);
|
static ase_awk_nde_t* __parse_print (ase_awk_t* awk, int type);
|
||||||
|
|
||||||
@ -219,38 +221,39 @@ struct __kwent
|
|||||||
static struct __kwent __kwtab[] =
|
static struct __kwent __kwtab[] =
|
||||||
{
|
{
|
||||||
/* operators */
|
/* operators */
|
||||||
{ ASE_T("in"), 2, TOKEN_IN, 0 },
|
{ ASE_T("in"), 2, TOKEN_IN, 0 },
|
||||||
|
|
||||||
/* top-level block starters */
|
/* top-level block starters */
|
||||||
{ ASE_T("BEGIN"), 5, TOKEN_BEGIN, 0 },
|
{ ASE_T("BEGIN"), 5, TOKEN_BEGIN, 0 },
|
||||||
{ ASE_T("END"), 3, TOKEN_END, 0 },
|
{ ASE_T("END"), 3, TOKEN_END, 0 },
|
||||||
{ ASE_T("function"), 8, TOKEN_FUNCTION, 0 },
|
{ ASE_T("function"), 8, TOKEN_FUNCTION, 0 },
|
||||||
{ ASE_T("func"), 4, TOKEN_FUNCTION, 0 },
|
{ ASE_T("func"), 4, TOKEN_FUNCTION, 0 },
|
||||||
|
|
||||||
/* keywords for variable declaration */
|
/* keywords for variable declaration */
|
||||||
{ ASE_T("local"), 5, TOKEN_LOCAL, ASE_AWK_EXPLICIT },
|
{ ASE_T("local"), 5, TOKEN_LOCAL, ASE_AWK_EXPLICIT },
|
||||||
{ ASE_T("global"), 6, TOKEN_GLOBAL, ASE_AWK_EXPLICIT },
|
{ ASE_T("global"), 6, TOKEN_GLOBAL, ASE_AWK_EXPLICIT },
|
||||||
|
|
||||||
/* keywords that start statements excluding expression statements */
|
/* keywords that start statements excluding expression statements */
|
||||||
{ ASE_T("if"), 2, TOKEN_IF, 0 },
|
{ ASE_T("if"), 2, TOKEN_IF, 0 },
|
||||||
{ ASE_T("else"), 4, TOKEN_ELSE, 0 },
|
{ ASE_T("else"), 4, TOKEN_ELSE, 0 },
|
||||||
{ ASE_T("while"), 5, TOKEN_WHILE, 0 },
|
{ ASE_T("while"), 5, TOKEN_WHILE, 0 },
|
||||||
{ ASE_T("for"), 3, TOKEN_FOR, 0 },
|
{ ASE_T("for"), 3, TOKEN_FOR, 0 },
|
||||||
{ ASE_T("do"), 2, TOKEN_DO, 0 },
|
{ ASE_T("do"), 2, TOKEN_DO, 0 },
|
||||||
{ ASE_T("break"), 5, TOKEN_BREAK, 0 },
|
{ ASE_T("break"), 5, TOKEN_BREAK, 0 },
|
||||||
{ ASE_T("continue"), 8, TOKEN_CONTINUE, 0 },
|
{ ASE_T("continue"), 8, TOKEN_CONTINUE, 0 },
|
||||||
{ ASE_T("return"), 6, TOKEN_RETURN, 0 },
|
{ ASE_T("return"), 6, TOKEN_RETURN, 0 },
|
||||||
{ ASE_T("exit"), 4, TOKEN_EXIT, 0 },
|
{ ASE_T("exit"), 4, TOKEN_EXIT, 0 },
|
||||||
{ ASE_T("next"), 4, TOKEN_NEXT, 0 },
|
{ ASE_T("next"), 4, TOKEN_NEXT, 0 },
|
||||||
{ ASE_T("nextfile"), 8, TOKEN_NEXTFILE, 0 },
|
{ ASE_T("nextfile"), 8, TOKEN_NEXTFILE, 0 },
|
||||||
{ ASE_T("delete"), 6, TOKEN_DELETE, 0 },
|
{ ASE_T("nextoutfile"), 11, TOKEN_NEXTOUTFILE, ASE_AWK_NEXTOUTFILE },
|
||||||
{ ASE_T("print"), 5, TOKEN_PRINT, ASE_AWK_EXTIO },
|
{ ASE_T("delete"), 6, TOKEN_DELETE, 0 },
|
||||||
{ ASE_T("printf"), 6, TOKEN_PRINTF, ASE_AWK_EXTIO },
|
{ ASE_T("print"), 5, TOKEN_PRINT, ASE_AWK_EXTIO },
|
||||||
|
{ ASE_T("printf"), 6, TOKEN_PRINTF, ASE_AWK_EXTIO },
|
||||||
|
|
||||||
/* keywords that can start an expression */
|
/* keywords that can start an expression */
|
||||||
{ ASE_T("getline"), 7, TOKEN_GETLINE, ASE_AWK_EXTIO },
|
{ ASE_T("getline"), 7, TOKEN_GETLINE, ASE_AWK_EXTIO },
|
||||||
|
|
||||||
{ ASE_NULL, 0, 0 }
|
{ ASE_NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __bvent
|
struct __bvent
|
||||||
@ -1256,7 +1259,12 @@ awk->parse.nl_semicolon = 1;
|
|||||||
else if (MATCH(awk,TOKEN_NEXTFILE))
|
else if (MATCH(awk,TOKEN_NEXTFILE))
|
||||||
{
|
{
|
||||||
if (__get_token(awk) == -1) return ASE_NULL;
|
if (__get_token(awk) == -1) return ASE_NULL;
|
||||||
nde = __parse_nextfile (awk);
|
nde = __parse_nextfile (awk, 0);
|
||||||
|
}
|
||||||
|
else if (MATCH(awk,TOKEN_NEXTOUTFILE))
|
||||||
|
{
|
||||||
|
if (__get_token(awk) == -1) return ASE_NULL;
|
||||||
|
nde = __parse_nextfile (awk, 1);
|
||||||
}
|
}
|
||||||
else if (MATCH(awk,TOKEN_DELETE))
|
else if (MATCH(awk,TOKEN_DELETE))
|
||||||
{
|
{
|
||||||
@ -3353,9 +3361,10 @@ static ase_awk_nde_t* __parse_next (ase_awk_t* awk)
|
|||||||
return (ase_awk_nde_t*)nde;
|
return (ase_awk_nde_t*)nde;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ase_awk_nde_t* __parse_nextfile (ase_awk_t* awk)
|
static ase_awk_nde_t* __parse_nextfile (ase_awk_t* awk, int out)
|
||||||
{
|
{
|
||||||
ase_awk_nde_nextfile_t* nde;
|
ase_awk_nde_nextfile_t* nde;
|
||||||
|
int stream = 1;
|
||||||
|
|
||||||
if (awk->parse.id.block == PARSE_BEGIN_BLOCK ||
|
if (awk->parse.id.block == PARSE_BEGIN_BLOCK ||
|
||||||
awk->parse.id.block == PARSE_END_BLOCK)
|
awk->parse.id.block == PARSE_END_BLOCK)
|
||||||
@ -3368,6 +3377,7 @@ static ase_awk_nde_t* __parse_nextfile (ase_awk_t* awk)
|
|||||||
if (nde == ASE_NULL) PANIC (awk, ASE_AWK_ENOMEM);
|
if (nde == ASE_NULL) PANIC (awk, ASE_AWK_ENOMEM);
|
||||||
nde->type = ASE_AWK_NDE_NEXTFILE;
|
nde->type = ASE_AWK_NDE_NEXTFILE;
|
||||||
nde->next = ASE_NULL;
|
nde->next = ASE_NULL;
|
||||||
|
nde->out = out;
|
||||||
|
|
||||||
return (ase_awk_nde_t*)nde;
|
return (ase_awk_nde_t*)nde;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: run.c,v 1.280 2006-11-21 15:06:15 bacon Exp $
|
* $Id: run.c,v 1.281 2006-11-23 03:31:36 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk_i.h>
|
#include <ase/awk/awk_i.h>
|
||||||
@ -1118,7 +1118,7 @@ static int __run_main (
|
|||||||
|
|
||||||
nde.type = ASE_AWK_NDE_AFN;
|
nde.type = ASE_AWK_NDE_AFN;
|
||||||
nde.next = ASE_NULL;
|
nde.next = ASE_NULL;
|
||||||
nde.what.afn.name = main;
|
nde.what.afn.name = (ase_char_t*)main;
|
||||||
nde.what.afn.name_len = ase_awk_strlen(main);
|
nde.what.afn.name_len = ase_awk_strlen(main);
|
||||||
nde.args = ASE_NULL;
|
nde.args = ASE_NULL;
|
||||||
nde.nargs = 0;
|
nde.nargs = 0;
|
||||||
@ -1260,7 +1260,7 @@ static int __run_main (
|
|||||||
|
|
||||||
static int __run_pattern_blocks (ase_awk_run_t* run)
|
static int __run_pattern_blocks (ase_awk_run_t* run)
|
||||||
{
|
{
|
||||||
ase_ssize_t n;
|
// ase_ssize_t n;
|
||||||
ase_bool_t need_to_close = ase_false;
|
ase_bool_t need_to_close = ase_false;
|
||||||
|
|
||||||
run->inrec.buf_pos = 0;
|
run->inrec.buf_pos = 0;
|
||||||
@ -1995,13 +1995,11 @@ static int __run_next (ase_awk_run_t* run, ase_awk_nde_next_t* nde)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __run_nextfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde)
|
static int __run_nextinfile (ase_awk_run_t* run)
|
||||||
{
|
{
|
||||||
/* TODO: some extentions such as nextfile "in/out";
|
|
||||||
* what about awk -i in1,in2,in3 -o out1,out2,out3 ?
|
|
||||||
*/
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
/* normal nextfile statement */
|
||||||
if (run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.begin ||
|
if (run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.begin ||
|
||||||
run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.end)
|
run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.end)
|
||||||
{
|
{
|
||||||
@ -2019,16 +2017,45 @@ static int __run_nextfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde)
|
|||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
/* no more input file */
|
/* no more input console */
|
||||||
run->exit_level = EXIT_GLOBAL;
|
run->exit_level = EXIT_GLOBAL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__update_fnr (run, 0) == -1) return -1;
|
if (__update_fnr (run, 0) == -1) return -1;
|
||||||
|
|
||||||
/* TODO: Consider using FILENAME_IN and FILENAME_OUT to accomplish nextfile in/out */
|
|
||||||
run->exit_level = EXIT_NEXT;
|
run->exit_level = EXIT_NEXT;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __run_nextoutfile (ase_awk_run_t* run)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = ase_awk_nextextio_write (run, ASE_AWK_OUT_CONSOLE, ASE_T(""));
|
||||||
|
if (n == -1)
|
||||||
|
{
|
||||||
|
if (run->errnum == ASE_AWK_EIOHANDLER)
|
||||||
|
run->errnum = ASE_AWK_ECONOUTNEXT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
/* TODO: should it terminate the program
|
||||||
|
* when there is no more output console? */
|
||||||
|
/*run->exit_level = EXIT_GLOBAL;*/
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: update_ofnr */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __run_nextfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde)
|
||||||
|
{
|
||||||
|
return (nde->out)? __run_nextoutfile (run): __run_nextinfile (run);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
static int __run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde)
|
||||||
@ -6088,7 +6115,6 @@ ase_char_t* ase_awk_format (
|
|||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (prec == -1 || prec == 0 || prec > ch_len) prec = ch_len;
|
if (prec == -1 || prec == 0 || prec > ch_len) prec = ch_len;
|
||||||
if (prec > width) width = prec;
|
if (prec > width) width = prec;
|
||||||
|
|
||||||
@ -6134,7 +6160,7 @@ ase_char_t* ase_awk_format (
|
|||||||
}
|
}
|
||||||
else if (fmt[i] == ASE_T('s'))
|
else if (fmt[i] == ASE_T('s'))
|
||||||
{
|
{
|
||||||
ase_char_t* str;
|
ase_char_t* str, * str_free = ASE_NULL;
|
||||||
ase_size_t str_len, k;
|
ase_size_t str_len, k;
|
||||||
ase_awk_val_t* v;
|
ase_awk_val_t* v;
|
||||||
|
|
||||||
@ -6192,6 +6218,8 @@ ase_char_t* ase_awk_format (
|
|||||||
ase_awk_refdownval (run, v);
|
ase_awk_refdownval (run, v);
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str_free = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prec == -1 || prec > str_len ) prec = str_len;
|
if (prec == -1 || prec > str_len ) prec = str_len;
|
||||||
@ -6203,6 +6231,8 @@ ase_char_t* ase_awk_format (
|
|||||||
{
|
{
|
||||||
if (ase_awk_str_ccat (out, ASE_T(' ')) == -1)
|
if (ase_awk_str_ccat (out, ASE_T(' ')) == -1)
|
||||||
{
|
{
|
||||||
|
if (str_free != ASE_NULL)
|
||||||
|
ASE_AWK_FREE (awk, str_free);
|
||||||
ase_awk_refdownval (run, v);
|
ase_awk_refdownval (run, v);
|
||||||
run->errnum = ASE_AWK_ENOMEM;
|
run->errnum = ASE_AWK_ENOMEM;
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
@ -6215,12 +6245,16 @@ ase_char_t* ase_awk_format (
|
|||||||
{
|
{
|
||||||
if (ase_awk_str_ccat (out, str[k]) == -1)
|
if (ase_awk_str_ccat (out, str[k]) == -1)
|
||||||
{
|
{
|
||||||
|
if (str_free != ASE_NULL)
|
||||||
|
ASE_AWK_FREE (awk, str_free);
|
||||||
ase_awk_refdownval (run, v);
|
ase_awk_refdownval (run, v);
|
||||||
run->errnum = ASE_AWK_ENOMEM;
|
run->errnum = ASE_AWK_ENOMEM;
|
||||||
return ASE_NULL;
|
return ASE_NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (str_free != ASE_NULL) ASE_AWK_FREE (awk, str_free);
|
||||||
|
|
||||||
if (minus)
|
if (minus)
|
||||||
{
|
{
|
||||||
while (width > prec)
|
while (width > prec)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: tree.h,v 1.80 2006-11-19 14:52:30 bacon Exp $
|
* $Id: tree.h,v 1.81 2006-11-23 03:31:36 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ASE_AWK_TREE_H_
|
#ifndef _ASE_AWK_TREE_H_
|
||||||
@ -347,6 +347,7 @@ struct ase_awk_nde_next_t
|
|||||||
struct ase_awk_nde_nextfile_t
|
struct ase_awk_nde_nextfile_t
|
||||||
{
|
{
|
||||||
ASE_AWK_NDE_HDR;
|
ASE_AWK_NDE_HDR;
|
||||||
|
int out;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ASE_AWK_NDE_DELETE */
|
/* ASE_AWK_NDE_DELETE */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.java,v 1.5 2006-11-22 15:11:36 bacon Exp $
|
* $Id: Awk.java,v 1.6 2006-11-23 03:31:58 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ase.test.awk;
|
package ase.test.awk;
|
||||||
@ -27,8 +27,10 @@ public class Awk extends ase.awk.Awk
|
|||||||
cin[2] = "c3.txt";
|
cin[2] = "c3.txt";
|
||||||
cin_no = 0;
|
cin_no = 0;
|
||||||
|
|
||||||
cout = new String[1];
|
cout = new String[3];
|
||||||
cout[0] = "";
|
cout[0] = "c4.txt";
|
||||||
|
cout[1] = "c5.txt";
|
||||||
|
cout[2] = "";
|
||||||
cout_no = 0;
|
cout_no = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +98,7 @@ public class Awk extends ase.awk.Awk
|
|||||||
if (isr == null) return -1;
|
if (isr == null) return -1;
|
||||||
|
|
||||||
extio.setHandle (isr);
|
extio.setHandle (isr);
|
||||||
setConsoleName (extio.getRunId(), cin[cin_no]);
|
setConsoleName (extio, cin[cin_no]);
|
||||||
|
|
||||||
cin_no++;
|
cin_no++;
|
||||||
return 1;
|
return 1;
|
||||||
@ -106,20 +108,13 @@ public class Awk extends ase.awk.Awk
|
|||||||
OutputStreamWriter osw;
|
OutputStreamWriter osw;
|
||||||
|
|
||||||
if (cout_no >= cout.length) return 0;
|
if (cout_no >= cout.length) return 0;
|
||||||
if (cout[cout_no].length() == 0)
|
osw = get_output_stream (cout[cout_no]);
|
||||||
{
|
if (osw == null) return -1;
|
||||||
osw = new OutputStreamWriter (System.out);
|
|
||||||
}
|
extio.setHandle (osw);
|
||||||
else
|
setOutputConsoleName (extio, cout[cout_no]);
|
||||||
{
|
|
||||||
FileOutputStream fos;
|
|
||||||
try { fos = new FileOutputStream (cout[cout_no]); }
|
|
||||||
catch (IOException e) { return -1; }
|
|
||||||
osw = new OutputStreamWriter (fos);
|
|
||||||
}
|
|
||||||
|
|
||||||
cout_no++;
|
cout_no++;
|
||||||
extio.setHandle (osw);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +169,7 @@ public class Awk extends ase.awk.Awk
|
|||||||
catch (IOException e) { /* ignore */ }
|
catch (IOException e) { /* ignore */ }
|
||||||
|
|
||||||
extio.setHandle (tmp);
|
extio.setHandle (tmp);
|
||||||
setConsoleName (extio.getRunId(), cin[cin_no]);
|
setConsoleName (extio, cin[cin_no]);
|
||||||
isr = (InputStreamReader)extio.getHandle ();
|
isr = (InputStreamReader)extio.getHandle ();
|
||||||
cin_no++;
|
cin_no++;
|
||||||
|
|
||||||
@ -195,6 +190,9 @@ public class Awk extends ase.awk.Awk
|
|||||||
if (mode == ase.awk.Extio.MODE_CONSOLE_WRITE)
|
if (mode == ase.awk.Extio.MODE_CONSOLE_WRITE)
|
||||||
{
|
{
|
||||||
OutputStreamWriter osw = (OutputStreamWriter)extio.getHandle ();
|
OutputStreamWriter osw = (OutputStreamWriter)extio.getHandle ();
|
||||||
|
// as the write operation below doesn't indicate
|
||||||
|
// if it has reached the end, console can't be
|
||||||
|
// switched here unlike read_console.
|
||||||
try { osw.write (buf, 0, len); osw.flush (); }
|
try { osw.write (buf, 0, len); osw.flush (); }
|
||||||
catch (IOException e) { return -1; }
|
catch (IOException e) { return -1; }
|
||||||
|
|
||||||
@ -222,11 +220,30 @@ public class Awk extends ase.awk.Awk
|
|||||||
catch (IOException e) { /* ignore */ }
|
catch (IOException e) { /* ignore */ }
|
||||||
|
|
||||||
extio.setHandle (tmp);
|
extio.setHandle (tmp);
|
||||||
setConsoleName (extio.getRunId(), cin[cin_no]);
|
setConsoleName (extio, cin[cin_no]);
|
||||||
|
|
||||||
cin_no++;
|
cin_no++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
else if (mode == ase.awk.Extio.MODE_CONSOLE_WRITE)
|
||||||
|
{
|
||||||
|
OutputStreamWriter osw, tmp;
|
||||||
|
|
||||||
|
osw = (OutputStreamWriter)extio.getHandle ();
|
||||||
|
|
||||||
|
if (cout_no >= cout.length) return 0;
|
||||||
|
tmp = get_output_stream (cout[cout_no]);
|
||||||
|
if (tmp == null) return -1;
|
||||||
|
|
||||||
|
try { osw.close (); }
|
||||||
|
catch (IOException e) { /* ignore */ }
|
||||||
|
|
||||||
|
extio.setHandle (tmp);
|
||||||
|
setOutputConsoleName (extio, cout[cout_no]);
|
||||||
|
|
||||||
|
cout_no++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -250,6 +267,25 @@ public class Awk extends ase.awk.Awk
|
|||||||
return isr;
|
return isr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OutputStreamWriter get_output_stream (String name)
|
||||||
|
{
|
||||||
|
OutputStreamWriter osw;
|
||||||
|
|
||||||
|
if (name == null || name.length() == 0)
|
||||||
|
{
|
||||||
|
osw = new OutputStreamWriter (System.out);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FileOutputStream fos;
|
||||||
|
try { fos = new FileOutputStream (name); }
|
||||||
|
catch (IOException e) { return null; }
|
||||||
|
osw = new OutputStreamWriter (fos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return osw;
|
||||||
|
}
|
||||||
|
|
||||||
/* ===== file ===== */
|
/* ===== file ===== */
|
||||||
public int open_file (ase.awk.Extio extio)
|
public int open_file (ase.awk.Extio extio)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.c,v 1.122 2006-11-22 15:11:37 bacon Exp $
|
* $Id: awk.c,v 1.123 2006-11-23 03:31:58 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ase/awk/awk.h>
|
#include <ase/awk/awk.h>
|
||||||
@ -753,7 +753,7 @@ static int __main (int argc, ase_char_t* argv[])
|
|||||||
/*ASE_AWK_DBLSLASHES |*/
|
/*ASE_AWK_DBLSLASHES |*/
|
||||||
ASE_AWK_SHADING | ASE_AWK_SHIFT |
|
ASE_AWK_SHADING | ASE_AWK_SHIFT |
|
||||||
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_STRINDEXONE |
|
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_STRINDEXONE |
|
||||||
ASE_AWK_STRIPSPACES /*| ASE_AWK_NEWLINE*/;
|
ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOUTFILE /*| ASE_AWK_NEWLINE*/;
|
||||||
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user