Recovered from cvs revision 2007-05-26 10:23:00

This commit is contained in:
hyung-hwan 2007-05-26 21:41:00 +00:00
parent 9c128e5a92
commit 38e1af83e6
12 changed files with 814 additions and 570 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.37 2007/05/23 11:43:24 bacon Exp $
* $Id: Awk.cpp,v 1.38 2007/05/25 11:49:42 bacon Exp $
*/
#include <ase/awk/Awk.hpp>
@ -560,13 +560,13 @@ namespace ASE
return ase_awk_getoption (awk);
}
void Awk::setDepth (int id, size_t depth)
void Awk::setMaxDepth (int ids, size_t depth)
{
ASE_ASSERT (awk != ASE_NULL);
ase_awk_setmaxdepth (awk, id, depth);
ase_awk_setmaxdepth (awk, ids, depth);
}
int Awk::getDepth (int id)
int Awk::getMaxDepth (int id)
{
ASE_ASSERT (awk != ASE_NULL);
return ase_awk_getmaxdepth (awk, id);

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.35 2007/05/23 11:43:24 bacon Exp $
* $Id: Awk.hpp,v 1.36 2007/05/25 11:49:42 bacon Exp $
*/
#ifndef _ASE_AWK_AWK_HPP_
@ -406,8 +406,8 @@ namespace ASE
DEPTH_REX_MATCH = ASE_AWK_DEPTH_REX_MATCH
};
virtual void setDepth (int id, size_t depth);
virtual int getDepth (int id);
virtual void setMaxDepth (int ids, size_t depth);
virtual int getMaxDepth (int id);
virtual int parse ();
virtual int run (const char_t* main = ASE_NULL,

View File

@ -1,11 +1,13 @@
/*
* $Id: Awk.java,v 1.6 2007/05/24 06:53:21 bacon Exp $
* $Id: Awk.java,v 1.8 2007/05/25 14:41:48 bacon Exp $
*
* {License}
*/
package ase.awk;
import java.io.*;
public abstract class Awk
{
// mode for open_source & close_source
@ -37,6 +39,12 @@ public abstract class Awk
public static final int OPTION_CRLF = (1 << 13);
public static final int OPTION_ARGSTOMAIN = (1 << 14);
protected final static Reader stdin =
new BufferedReader (new InputStreamReader (System.in));
protected final static Writer stdout =
new BufferedWriter (new OutputStreamWriter (System.out));
private long handle;
public Awk () throws Exception
@ -84,6 +92,7 @@ public abstract class Awk
protected native String strftime (String fmt, long sec);
protected native String strfgmtime (String fmt, long sec);
protected native int system (String cmd);
/* == simpler run methods == */
public void run (String main) throws Exception

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.java,v 1.7 2007/05/24 06:53:21 bacon Exp $
* $Id: StdAwk.java,v 1.9 2007/05/25 14:41:48 bacon Exp $
*
* {License}
*/
@ -10,39 +10,9 @@ import java.io.*;
public abstract class StdAwk extends Awk
{
private Reader src_in = null;
private Writer src_out = null;
private String[] sin = null;
private int sin_no = 0;
private String[] sout = null;
private int sout_no = 0;
private String[] cin = null;
private int cin_no = 0;
private String[] cout = null;
private int cout_no = 0;
private long seed;
private java.util.Random random;
private final static Reader stdin =
new BufferedReader (new InputStreamReader (System.in));
private final static Writer stdout =
new BufferedWriter (new OutputStreamWriter (System.out));
/*
static
{
stdin = new BufferedReader (
new InputStreamReader (System.in));
stdout = new BufferedWriter (
new OutputStreamWriter (System.out));
}
*/
public StdAwk () throws Exception
{
super ();
@ -69,405 +39,6 @@ public abstract class StdAwk extends Awk
addFunction ("system", 1, 1);
}
/* == major methods == */
public void parse () throws Exception
{
sin = sourceInputNames (); sin_no = 0;
sout = sourceOutputNames (); sout_no = 0;
super.parse ();
}
public void run (String main, String[] args) throws Exception
{
cin = consoleInputNames (); cin_no = 0;
cout = consoleOutputNames (); cout_no = 0;
super.run (main, args);
}
public void run (String main) throws Exception
{
run (main, null);
}
public void run (String[] args) throws Exception
{
run (null, args);
}
public void run () throws Exception
{
run (null, null);
}
/* == source code names == */
protected String[] sourceInputNames () { return null; }
protected String[] sourceOutputNames () { return null; }
/* == console names == */
protected String[] consoleInputNames () { return null; }
protected String[] consoleOutputNames () { return null; }
/* == source code == */
protected int openSource (int mode)
{
if (mode == SOURCE_READ)
{
Reader isr;
sin_no = 0;
if (sin == null || sin_no >= sin.length) return 0;
isr = get_stream_reader (sin[sin_no]);
if (isr == null) return -1;
src_in = isr;
sin_no++;
return 1;
}
else if (mode == SOURCE_WRITE)
{
Writer osw;
sout_no = 0;
// when sout is null, the source output is treated
// as if the operation has been successful with
// the writeSource and closeSource method.
if (sout == null) return 1;
if (sout_no >= sin.length) return 0;
osw = get_stream_writer (sout[sout_no]);
if (osw == null) return -1;
src_out = osw;
sout_no++;
return 1;
}
return -1;
}
protected int closeSource (int mode)
{
if (mode == SOURCE_READ)
{
if (src_in != StdAwk.stdin)
{
try { src_in.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == SOURCE_WRITE)
{
if (src_out == null) return 0;
if (src_out != StdAwk.stdout)
{
try { src_out.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
return -1;
}
protected int readSource (char[] buf, int len)
{
try {
int n = src_in.read (buf, 0, len);
while (n == -1)
{
Reader isr;
if (sin == null || sin_no >= sin.length) return 0;
isr = get_stream_reader (sin[sin_no]);
if (isr == null) return -1;
if (src_in != StdAwk.stdin)
{
try { src_in.close (); }
catch (IOException ec) { /* ignore */ }
}
src_in = isr;
sin_no++;
n = src_in.read (buf, 0, len);
}
return n;
}
catch (IOException e)
{
return -1;
}
}
protected int writeSource (char[] buf, int len)
{
if (src_out == null) return len;
// only the first file is used at the moment.
// this is because the write message doesn't indicate
// the end of the output stream.
try { src_out.write (buf, 0, len); }
catch (IOException e) { return -1; }
return len;
}
/* == console interface == */
protected int openConsole (Extio extio)
{
//System.err.println ("[openConsole called.... name: " + extio.getName() + " mode: " + extio.getMode());
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
/*InputStream*/Reader isr;
cin_no = 0;
if (cin == null || cin_no >= cin.length) return 0;
isr = get_stream_reader (cin[cin_no]);
if (isr == null) return -1;
extio.setHandle (isr);
try { setConsoleInputName (extio, cin[cin_no]); }
catch (Exception e) { return -1; }
cin_no++;
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw;
cout_no = 0;
if (cout == null || cout_no >= cout.length) return 0;
osw = get_stream_writer (cout[cout_no]);
if (osw == null) return -1;
extio.setHandle (osw);
try { setConsoleOutputName (extio, cout[cout_no]); }
catch (Exception e) { return -1; }
cout_no++;
return 1;
}
return -1;
}
protected int closeConsole (Extio extio)
{
//System.err.println ("[closeConsole called.... name: " + extio.getName() + " mode: " + extio.getMode());
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader isr = (Reader)extio.getHandle ();
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw = (Writer)extio.getHandle ();
/* TODO: selective close the stream...
* system.out should not be closed??? */
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
return -1;
}
protected int readConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader isr, tmp;
int n;
isr = (Reader)extio.getHandle ();
try { n = isr.read (buf, 0, len); }
catch (IOException e) { return -1; }
while (n == -1)
{
if (cin == null || cin_no >= cin.length) return 0;
tmp = get_stream_reader (cin[cin_no]);
if (tmp == null) return -1;
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { /* ignore */ }
}
extio.setHandle (tmp);
try { setConsoleInputName (extio, cin[cin_no]); }
catch (Exception e) { return -1; }
isr = (Reader)extio.getHandle ();
cin_no++;
try { n = isr.read (buf, 0, len); }
catch (IOException e) { return -1; }
}
return n;
}
return -1;
}
protected int writeConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
//System.err.println ("[writeConsole called name: " + extio.getName() + " mode: " + extio.getMode());
if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle ();
// as the write operation below doesn't
// indicate if it has reached the end, console
// can't be switched here unlike in read_console
try { osw.write (buf, 0, len); osw.flush (); }
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int flushConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle ();
try { osw.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int nextConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader isr, tmp;
isr = (Reader)extio.getHandle ();
if (cin == null || cin_no >= cin.length) return 0;
tmp = get_stream_reader (cin[cin_no]);
if (tmp == null) return -1;
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { /* ignore */ }
}
extio.setHandle (tmp);
try { setConsoleInputName (extio, cin[cin_no]); }
catch (Exception e) { return -1; }
cin_no++;
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw, tmp;
osw = (Writer)extio.getHandle ();
if (cout == null || cout_no >= cout.length) return 0;
tmp = get_stream_writer (cout[cout_no]);
if (tmp == null) return -1;
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { /* ignore */ }
}
extio.setHandle (tmp);
try { setConsoleOutputName (extio, cout[cout_no]); }
catch (Exception e) { return -1;}
cout_no++;
return 1;
}
return -1;
}
private Reader get_stream_reader (String name)
{
Reader isr;
if (name == null || name.length() == 0) isr = StdAwk.stdin;
else
{
FileInputStream fis;
try { fis = new FileInputStream (name); }
catch (IOException e) { return null; }
isr = new BufferedReader(new InputStreamReader (fis));
}
return isr;
}
private Writer get_stream_writer (String name)
{
Writer osw;
if (name == null || name.length() == 0) osw = StdAwk.stdout;
else
{
FileOutputStream fos;
try { fos = new FileOutputStream (name); }
catch (IOException e) { return null; }
osw = new BufferedWriter (new OutputStreamWriter (fos));
}
return osw;
}
/* == file interface == */
protected int openFile (Extio extio)
{
@ -521,7 +92,7 @@ public abstract class StdAwk extends Awk
{
Reader isr;
isr = (Reader)extio.getHandle();
if (isr != StdAwk.stdin)
if (isr != null)
{
try { isr.close (); }
catch (IOException e) { return -1; }
@ -532,7 +103,7 @@ public abstract class StdAwk extends Awk
{
Writer osw;
osw = (Writer)extio.getHandle();
if (osw != StdAwk.stdout)
if (osw != null)
{
try { osw.close (); }
catch (IOException e) { return -1; }
@ -543,7 +114,7 @@ public abstract class StdAwk extends Awk
{
Writer osw;
osw = (Writer)extio.getHandle();
if (osw != StdAwk.stdout)
if (osw != null)
{
try { osw.close (); }
catch (IOException e) { return -1; }
@ -651,7 +222,7 @@ public abstract class StdAwk extends Awk
{
Reader isr;
isr = (Reader)extio.getHandle();
if (isr != StdAwk.stdin)
if (isr != null)
{
try { isr.close (); }
catch (IOException e) { return -1; }
@ -662,7 +233,7 @@ public abstract class StdAwk extends Awk
{
Writer osw;
osw = (Writer)extio.getHandle();
if (osw != StdAwk.stdout)
if (osw != null)
{
try { osw.close (); }
catch (IOException e) { return -1; }
@ -817,6 +388,10 @@ public abstract class StdAwk extends Awk
/* miscellaneous built-in functions */
public Object bfn_system (long runid, Object[] args) throws Exception
{
String str = builtinFunctionArgumentToString (runid, args[0]);
return system (str);
/*
String str = builtinFunctionArgumentToString (runid, args[0]);
Process proc = null;
int n = 0;
@ -846,6 +421,7 @@ public abstract class StdAwk extends Awk
}
return new Long (n);
*/
}
/* == utility functions == */

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.c,v 1.8 2007/05/24 06:53:21 bacon Exp $
* $Id: jni.c,v 1.10 2007/05/25 14:41:48 bacon Exp $
*
* {License}
*/
@ -380,9 +380,19 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj)
(*env)->SetLongField (env, obj, handle, (jlong)awk);
opt = ASE_AWK_EXPLICIT | ASE_AWK_UNIQUEFN | ASE_AWK_SHADING |
ASE_AWK_IMPLICIT | ASE_AWK_SHIFT | ASE_AWK_IDIV |
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_NEXTOFILE;
opt = ASE_AWK_IMPLICIT |
ASE_AWK_EXPLICIT |
ASE_AWK_UNIQUEFN |
ASE_AWK_IDIV |
ASE_AWK_SHADING |
ASE_AWK_SHIFT |
ASE_AWK_EXTIO |
ASE_AWK_BLOCKLESS |
ASE_AWK_STRBASEONE |
ASE_AWK_STRIPSPACES |
ASE_AWK_NEXTOFILE |
ASE_AWK_ARGSTOMAIN;
ase_awk_setoption (awk, opt);
}
@ -2356,6 +2366,7 @@ static jstring JNICALL call_strftime (
ase_size_t len, i;
const jchar* ptr;
ase_char_t* tmp;
jchar* tmp2;
jstring ret;
len = (*env)->GetStringLength (env, fmt);
@ -2371,7 +2382,7 @@ static jstring JNICALL call_strftime (
return NULL;
}
tmp = (jchar*) malloc (ASE_SIZEOF(ase_char_t)*(len+1));
tmp = (ase_char_t*) malloc (ASE_SIZEOF(ase_char_t)*(len+1));
if (tmp == NULL)
{
(*env)->ReleaseStringChars (env, fmt, ptr);
@ -2393,8 +2404,8 @@ static jstring JNICALL call_strftime (
if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t))
{
tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len);
if (tmp == NULL)
tmp2 = (jchar*) malloc (ASE_SIZEOF(jchar)*len);
if (tmp2 == NULL)
{
throw_exception (
env,
@ -2403,9 +2414,9 @@ static jstring JNICALL call_strftime (
0);
return NULL;
}
for (i = 0; i < len; i++) tmp[i] = (jchar)buf[i];
ret = (*env)->NewString (env, tmp, len);
free (tmp);
for (i = 0; i < len; i++) tmp2[i] = (jchar)buf[i];
ret = (*env)->NewString (env, tmp2, len);
free (tmp2);
}
else
{
@ -2459,7 +2470,6 @@ JNIEXPORT jstring JNICALL Java_ase_awk_Awk_strfgmtime (
return call_strftime (env, obj, fmt, tm);
}
/*
JNIEXPORT jint JNICALL Java_ase_awk_Awk_system (
JNIEnv* env, jobject obj, jstring cmd)
{
@ -2468,8 +2478,8 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_system (
ase_char_t* tmp;
jint ret;
len = (*env)->GetStringLength (env, fmt);
ptr = (*env)->GetStringChars (env, fmt, JNI_FALSE);
len = (*env)->GetStringLength (env, cmd);
ptr = (*env)->GetStringChars (env, cmd, JNI_FALSE);
if (ptr == NULL)
{
(*env)->ExceptionClear (env);
@ -2478,37 +2488,36 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_system (
ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return NULL;
return -1;
}
tmp = (jchar*) malloc (ASE_SIZEOF(ase_char_t)*(len+1));
tmp = (ase_char_t*) malloc (ASE_SIZEOF(ase_char_t)*(len+1));
if (tmp == NULL)
{
(*env)->ReleaseStringChars (env, fmt, ptr);
(*env)->ReleaseStringChars (env, cmd, ptr);
throw_exception (
env,
ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM),
ASE_AWK_ENOMEM,
0);
return NULL;
return -1;
}
for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i];
tmp[i] = ASE_T('\0');
#ifdef _WIN32
ret = _tsystem(ptr);
ret = _tsystem(tmp);
#else
char* mbs = (char*)malloc (awk, len*5+1);
char* mbs = (char*)malloc (len*5+1);
if (mbs == ASE_NULL) return -1;
size_t mbl = wcstombs (mbs, ptr, len*5);
size_t mbl = wcstombs (mbs, tmp, len*5);
if (mbl == (size_t)-1) return -1;
mbs[mbl] = '\0';
ret = system(mbs);
free (awk, mbs);
free (mbs);
#endif
return ret;
}
*/

View File

@ -1,5 +1,5 @@
#
# $Id: makefile.in,v 1.5 2007/05/06 04:23:44 bacon Exp $
# $Id: makefile.in,v 1.6 2007/05/25 11:49:42 bacon Exp $
#
NAME = aseawk
@ -123,16 +123,16 @@ $(TMP_DIR)/rex.o: rex.c
$(TMP_DIR)/jni.o: jni.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) $(CFLAGS_JNI) -o $@ -c jni.c
$(TMP_DIR)/ase/awk/Awk.class:
$(TMP_DIR)/ase/awk/Awk.class: Awk.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Awk.java
$(TMP_DIR)/ase/awk/StdAwk.class:
$(TMP_DIR)/ase/awk/StdAwk.class: StdAwk.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) StdAwk.java
$(TMP_DIR)/ase/awk/Extio.class:
$(TMP_DIR)/ase/awk/Extio.class: Extio.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Extio.java
$(TMP_DIR)/ase/awk/Exception.class:
$(TMP_DIR)/ase/awk/Exception.class: Exception.java
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Exception.java
$(TMP_DIR)/cxx/Awk.o: Awk.cpp Awk.hpp

View File

@ -12,6 +12,9 @@
* added awk c++ classes (awk/Awk.hpp awk/Awk.cpp awk/StdAwk.hpp awk/StdAwk.cpp)
* added c++ test program (test/awk/Awk.cpp)
* modified the java test program (test/awk/AseAwk.java) to be the same as
the c++ test program functionally
* changed the way to invoke the main function (utl/main.h utl/main.c)
[0.1.0]

View File

@ -1,5 +1,5 @@
/*
* $Id: str.c,v 1.3 2007/04/30 05:55:36 bacon Exp $
* $Id: str.c,v 1.4 2007/05/25 08:08:47 bacon Exp $
*
* {License}
*/
@ -196,6 +196,41 @@ ase_char_t* ase_strxdup2 (
return tmp;
}
ase_char_t* ase_strstr (const ase_char_t* str, const ase_char_t* sub)
{
const ase_char_t* x, * y;
y = sub;
if (*y == ASE_T('\0')) return (ase_char_t*)str;
while (*str != ASE_T('\0'))
{
if (*str != *y)
{
str++;
continue;
}
x = str;
while (1)
{
if (*y == ASE_T('\0')) return (ase_char_t*)str;
if (*x++ != *y++) break;
}
y = sub;
str++;
}
return ASE_NULL;
}
ase_char_t* ase_strxstr (
const ase_char_t* str, ase_size_t size, const ase_char_t* sub)
{
return ase_strxnstr (str, size, sub, ase_strlen(sub));
}
ase_char_t* ase_strxnstr (
const ase_char_t* str, ase_size_t strsz,
const ase_char_t* sub, ase_size_t subsz)
@ -226,6 +261,55 @@ ase_char_t* ase_strxnstr (
return ASE_NULL;
}
ase_char_t* ase_strchr (const ase_char_t* str, ase_cint_t c)
{
while (*str != ASE_T('\0'))
{
if (*str == c) return (ase_char_t*)str;
str++;
}
return ASE_NULL;
}
ase_char_t* ase_strxchr (const ase_char_t* str, ase_size_t len, ase_cint_t c)
{
const ase_char_t* end = str + len;
while (str < end)
{
if (*str == c) return (ase_char_t*)str;
str++;
}
return ASE_NULL;
}
ase_char_t* ase_strrchr (const ase_char_t* str, ase_cint_t c)
{
const ase_char_t* end = str;
while (*end != ASE_T('\0')) end++;
while (end > str)
{
if (*--end == c) return (ase_char_t*)end;
}
return ASE_NULL;
}
ase_char_t* ase_strxrchr (const ase_char_t* str, ase_size_t len, ase_cint_t c)
{
const ase_char_t* end = str + len;
while (end > str)
{
if (*--end == c) return (ase_char_t*)end;
}
return ASE_NULL;
}
ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr)
{
if (str == ASE_NULL)
@ -382,4 +466,3 @@ ase_size_t ase_str_nccat (ase_str_t* str, ase_char_t c, ase_size_t len)
return str->size;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
* $Id: str.h,v 1.4 2007/05/25 08:08:47 bacon Exp $
*
* {License}
*/
@ -62,10 +62,18 @@ ase_char_t* ase_strxdup2 (
const ase_char_t* str1, ase_size_t len1,
const ase_char_t* str2, ase_size_t len2, ase_mmgr_t* mmgr);
ase_char_t* ase_strstr (const ase_char_t* str, const ase_char_t* sub);
ase_char_t* ase_strxstr (
const ase_char_t* str, ase_size_t size, const ase_char_t* sub);
ase_char_t* ase_strxnstr (
const ase_char_t* str, ase_size_t strsz,
const ase_char_t* sub, ase_size_t subsz);
ase_char_t* ase_strchr (const ase_char_t* str, ase_cint_t c);
ase_char_t* ase_strxchr (const ase_char_t* str, ase_size_t len, ase_cint_t c);
ase_char_t* ase_strrchr (const ase_char_t* str, ase_cint_t c);
ase_char_t* ase_strxrchr (const ase_char_t* str, ase_size_t len, ase_cint_t c);
ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr);
void ase_str_close (ase_str_t* str);
void ase_str_clear (ase_str_t* str);

10
ase/configure vendored
View File

@ -1,5 +1,5 @@
#! /bin/sh
# From configure.ac Revision: 1.4 .
# From configure.ac Revision: 1.5 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for ase deb-0.1.0.
#
@ -25853,7 +25853,7 @@ echo "${ECHO_T}$CUR_JAVAC_PATH" >&6
JAVA_DIR="$REAL_JAVAC_PATH"
while true
do
JAVA_DIR=`echo "$JAVA_DIR" | sed -e 's/\/\/*/\//g' -e 's/\/^/*$//'`
JAVA_DIR=`echo "$JAVA_DIR" | sed -e 's://*:/:g' -e 's:/[^/]*$::'`
if test "$JAVA_DIR" = ""
then
break
@ -25863,8 +25863,6 @@ echo "${ECHO_T}$CUR_JAVAC_PATH" >&6
echo $ECHO_N "checking $JAVA_DIR/etc/javavms... $ECHO_C" >&6
if test -f "$JAVA_DIR/etc/javavms"
then
echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6
# takes the first jvm configured
CUR_JAVAC_PATH=`cat $JAVA_DIR/etc/javavms | head -1`
echo "$as_me:$LINENO: result: $CUR_JAVAC_PATH" >&5
@ -25882,7 +25880,7 @@ echo "${ECHO_T}no" >&6
while true
do
JAVA_DIR=`echo "$JAVA_DIR" | sed -e 's/\/\/*/\//g' -e 's/\/^/*$//'`
JAVA_DIR=`echo "$JAVA_DIR" | sed -e 's://*:/:g' -e 's:/[^/]*$::'`
if test "$JAVA_DIR" = ""
then
break
@ -25907,7 +25905,7 @@ echo "${ECHO_T}no" >&6
JNI_MD_H=`find "$i" -name jni_md.h -print`
if test "$JNI_MD_H" != ""
then
tmp=`echo "$JNI_MD_H" | sed -e 's/\/\/*/\//g' -e 's/\/^/*$//'`
tmp=`echo "$JNI_MD_H" | sed -e 's://*:/:g' -e 's:/[^/]*$::'`
JNI_MD_INCLUDE_DIRS="$JNI_MD_INCLUDE_DIRS $tmp"
fi
done

View File

@ -1,58 +1,20 @@
/*
* $Id: AseAwk.java,v 1.1 2007/04/30 08:32:41 bacon Exp $
* $Id: AseAwk.java,v 1.6 2007/05/25 16:55:02 bacon Exp $
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.Iterator;
import java.net.URL;
import ase.awk.*;
public class AseAwk extends ase.awk.StdAwk
public class AseAwk extends StdAwk
{
public AseAwk () throws ase.awk.Exception
{
super ();
}
protected String[] consoleInputNames ()
{
String[] cin = new String[3];
cin[0] = "c1.txt";
cin[1] = "c2.txt";
cin[2] = "c3.txt";
return cin;
}
protected String[] consoleOutputNames ()
{
String[] cout = new String[1];
cout[0] = "";
return cout;
/*
String[] cout = new String[3];
cout[0] = "c4.txt";
cout[1] = "c5.txt";
cout[2] = "";
return cout;
*/
}
protected String[] sourceInputNames ()
{
String[] sin = new String[1];
sin[0] = "t.awk";
return sin;
}
/*
protected String sourceOutputName ()
{
return "";
}
*/
public static void main (String[] args)
{
// AWT mode
if (args.length == 0)
private static void run_in_awt ()
{
final Frame frame = new Frame ();
@ -72,27 +34,70 @@ public class AseAwk extends ase.awk.StdAwk
frame.add (new AseAwkPanel(), BorderLayout.CENTER);
frame.setVisible (true);
return;
}
// console mode
private static void print_usage ()
{
System.out.print ("Usage: ");
System.out.print (AseAwk.class.getName());
System.out.println (" [-m main] [-si file]? [-so file]? [-ci file]* [-co file]* [-a arg]*");
System.out.println (" -m main Specify the main function name\n");
System.out.println (" -si file Specify the input source file\n");
System.out.println (" The source code is read from stdin when it is not specified\n");
System.out.println (" -so file Specify the output source file\n");
System.out.println (" The deparsed code is not output when is it not specified\n");
System.out.println (" -ci file Specify the input console file\n");
System.out.println (" -co file Specify the output console file\n");
System.out.println (" -a str Specify an argument\n");
}
private static void print_error (String msg)
{
System.out.print ("Error: ");
System.out.println (msg);
}
private static String get_dll_name ()
{
URL url = AseAwk.class.getResource (
AseAwk.class.getName() + ".class");
File file = new File (url.getFile());
String osname = System.getProperty ("os.name").toLowerCase();
String aseBase = file.getParentFile().getParentFile().getParent(
);
String path;
if (osname.startsWith ("windows"))
{
path = aseBase + "\\lib\\aseawk_jni.dll";
return path.substring(6);
}
else if (osname.startsWith ("mac"))
{
path = aseBase + "/lib/.libs/libaseawk_jni.dylib";
return path.substring(5);
}
else
{
path = aseBase + "/lib/.libs/libaseawk_jni.so";
return path.substring(5);
}
}
private static void run_in_console (String[] args)
{
AseAwk awk = null;
if (args.length != 1)
{
System.err.println ("Usage: " + AseAwk.class.getName() + " jni");
System.err.println ("Where jni := the full path to the jni library");
return;
}
String dll = get_dll_name();
try
{
System.load (args[0]);
System.load (dll);
}
catch (java.lang.UnsatisfiedLinkError e)
{
System.err.println ("Error: cannot load the library - " + args[0]);
print_error ("cannot load the library - " + dll);
return;
}
@ -102,28 +107,117 @@ public class AseAwk extends ase.awk.StdAwk
awk.setMaxDepth (AseAwk.DEPTH_BLOCK_PARSE, 30);
awk.setDebug (true);
//awk.setDebug (false);
}
catch (ase.awk.Exception e)
{
print_error ("ase.awk.Exception - " + e.getMessage());
}
//awk.setOption (awk.getOption() | OPTION_STRBASEONE);
System.out.println ("Option: [" + awk.getOption() + "]");
int mode = 0;
String mainfn = null;
String srcin = null;
String srcout = null;
int nsrcins = 0;
int nsrcouts = 0;
ArrayList<String> params = new ArrayList<String> ();
awk.parse ();
for (String arg: args)
{
if (mode == 0)
{
if (arg.equals("-si")) mode = 1;
else if (arg.equals("-so")) mode = 2;
else if (arg.equals("-ci")) mode = 3;
else if (arg.equals("-co")) mode = 4;
else if (arg.equals("-a")) mode = 5;
else if (arg.equals("-m")) mode = 6;
else
{
print_usage ();
return;
}
}
else
{
if (arg.length() >= 1 && arg.charAt(0) == '-')
{
print_usage ();
return;
}
System.out.println ("about to run");
String[] aaa = new String[3];
aaa[0] = "abcdefg";
aaa[1] = "qwerty";
aaa[2] = "awk is bad";
awk.run ("main", aaa);
if (mode == 1) // source input
{
if (nsrcins != 0)
{
print_usage ();
return;
}
srcin = arg;
nsrcins++;
mode = 0;
}
else if (mode == 2) // source output
{
if (nsrcouts != 0)
{
print_usage ();
return;
}
srcout = arg;
nsrcouts++;
mode = 0;
}
else if (mode == 3) // console input
{
awk.addConsoleInput (arg);
mode = 0;
}
else if (mode == 4) // console output
{
awk.addConsoleOutput (arg);
mode = 0;
}
else if (mode == 5) // argument mode
{
params.add (arg);
mode = 0;
}
else if (mode == 6)
{
if (mainfn != null)
{
print_usage ();
return;
}
mainfn = arg;
mode = 0;
}
}
}
if (mode != 0)
{
print_usage ();
return;
}
try
{
awk.parse (srcin, srcout);
awk.run (mainfn, params.toArray(new String[0]));
}
catch (ase.awk.Exception e)
{
if (e.getLine() == 0)
{
System.out.println ("ase.awk.Exception - " + e.getMessage());
print_error ("ase.awk.Exception - " + e.getMessage());
}
else
{
System.out.println (
print_error (
"ase.awk.Exception at line " +
e.getLine() + " - " + e.getMessage());
}
@ -136,7 +230,470 @@ public class AseAwk extends ase.awk.StdAwk
awk = null;
}
}
System.out.println ("==== end of awk ====");
}
public static void main (String[] args)
{
if (args.length == 0)
{
run_in_awt ();
}
else
{
run_in_console (args);
}
}
private Reader srcReader;
private Writer srcWriter;
private String srcInName;
private String srcOutName;
private Reader conReader;
private Writer conWriter;
private LinkedList conInNames;
private LinkedList conOutNames;
private Iterator conInIter;
private Iterator conOutIter;
public AseAwk () throws ase.awk.Exception
{
super ();
srcReader = null;
srcWriter = null;
srcInName = null;
srcOutName = null;
conReader = null;
conWriter = null;
conInNames = new LinkedList ();
conOutNames = new LinkedList ();
addFunction ("sleep", 1, 1);
}
public Object bfn_sleep (
long runid, Object[] args) throws ase.awk.Exception
{
long x = builtinFunctionArgumentToLong (runid, args[0]);
try { Thread.sleep (x * 1000); }
catch (InterruptedException e) {}
return new Long(0);
}
public void parse () throws ase.awk.Exception
{
srcInName = null;
srcOutName = null;
super.parse ();
}
public void parse (String inName) throws ase.awk.Exception
{
srcInName = inName;
srcOutName = null;
super.parse ();
}
public void parse (String inName, String outName) throws ase.awk.Exception
{
srcInName = inName;
srcOutName = outName;
super.parse ();
}
public void run (String main, String[] args) throws ase.awk.Exception
{
conInIter = conInNames.iterator();
conOutIter = conOutNames.iterator();
super.run (main, args);
}
public void addConsoleInput (String name)
{
conInNames.addLast (name);
}
public void addConsoleOutput (String name)
{
conOutNames.addLast (name);
}
protected int openSource (int mode)
{
if (mode == SOURCE_READ)
{
Reader isr;
if (srcInName == null || srcInName.length() == 0)
{
isr = stdin;
}
else
{
FileInputStream fis;
try { fis = new FileInputStream (srcInName); }
catch (IOException e) { return -1; }
isr = new BufferedReader(new InputStreamReader (fis));
}
if (isr == null) return -1;
srcReader = isr;
return 1;
}
else if (mode == SOURCE_WRITE)
{
Writer osw;
if (srcOutName == null)
{
return 0;
}
else if (srcOutName.length() == 0)
{
osw = stdout;
}
else
{
FileOutputStream fos;
try { fos = new FileOutputStream (srcOutName); }
catch (IOException e) { return -1; }
osw = new BufferedWriter(new OutputStreamWriter (fos));
}
srcWriter = osw;
return 1;
}
return -1;
}
protected int closeSource (int mode)
{
if (mode == SOURCE_READ)
{
if (srcReader != null)
{
if (srcReader == stdin)
{
srcReader = null;
}
else
{
try
{
srcReader.close ();
srcReader = null;
}
catch (IOException e) { return -1; }
}
}
return 0;
}
else if (mode == SOURCE_WRITE)
{
if (srcWriter != null)
{
if (srcWriter == stdout)
{
try
{
srcWriter.flush ();
srcWriter = null;
}
catch (IOException e) { return -1; }
}
else
{
try
{
srcWriter.close ();
srcWriter = null;
}
catch (IOException e) { return -1; }
}
}
return 0;
}
return -1;
}
protected int readSource (char[] buf, int len)
{
try
{
int n = srcReader.read (buf, 0, len);
if (n == -1) n = 0;
return n;
}
catch (IOException e)
{
return -1;
}
}
protected int writeSource (char[] buf, int len)
{
if (srcWriter == null) return len;
try { srcWriter.write (buf, 0, len); }
catch (IOException e) { return -1; }
return len;
}
protected int openConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader rd;
if (!conInIter.hasNext()) rd = stdin;
else
{
FileInputStream fis;
String fn = (String)conInIter.next();
try
{
fis = new FileInputStream (fn);
rd = new BufferedReader(
new InputStreamReader (fis));
}
catch (IOException e) { return -1; }
try
{
setConsoleInputName (extio, fn);
}
catch (ase.awk.Exception e)
{
try { rd.close(); }
catch (IOException e2) {}
return -1;
}
}
conReader = rd;
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer wr;
if (!conOutIter.hasNext()) wr = stdout;
else
{
FileOutputStream fos;
String fn = (String)conOutIter.next();
try
{
fos = new FileOutputStream (fn);
wr = new BufferedWriter(
new OutputStreamWriter (fos));
}
catch (IOException e) { return -1; }
try
{
setConsoleOutputName (extio, fn);
}
catch (ase.awk.Exception e)
{
try { wr.close(); }
catch (IOException e2) {}
return -1;
}
}
conWriter = wr;
return 1;
}
return -1;
}
protected int closeConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
if (conReader != null)
{
if (conReader == stdin)
{
conReader = null;
}
else
{
try
{
conReader.close ();
conReader = null;
}
catch (IOException e) { return -1; }
}
}
return 0;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
if (conWriter != null)
{
if (conWriter == stdout)
{
try
{
conWriter.flush ();
conWriter = null;
}
catch (IOException e) { return -1; }
}
else
{
try
{
conWriter.close ();
conWriter = null;
}
catch (IOException e) { return -1; }
}
}
return 0;
}
return -1;
}
protected int readConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
try
{
int n = conReader.read (buf, 0, len);
if (n == -1) n = 0;
return n;
}
catch (IOException e) { return -1; }
}
return -1;
}
protected int writeConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_WRITE)
{
try
{
conWriter.write (buf, 0, len);
conWriter.flush ();
}
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int flushConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_WRITE)
{
try { conWriter.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int nextConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
if (!conInIter.hasNext()) return 0;
String fn = (String)conInIter.next();
Reader rd;
FileInputStream fis;
try
{
fis = new FileInputStream (fn);
rd = new BufferedReader(
new InputStreamReader (fis));
}
catch (IOException e) { return -1; }
try
{
setConsoleInputName (extio, fn);
}
catch (ase.awk.Exception e)
{
try { rd.close(); }
catch (IOException e2) {}
return -1;
}
try { conReader.close (); }
catch (IOException e) { return -1; }
conReader = rd;
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
if (!conOutIter.hasNext()) return 0;
String fn = (String)conOutIter.next();
Writer wr;
FileOutputStream fos;
try
{
fos = new FileOutputStream (fn);
wr = new BufferedWriter(
new OutputStreamWriter (fos));
}
catch (IOException e) { return -1; }
try
{
setConsoleOutputName (extio, fn);
}
catch (ase.awk.Exception e)
{
try { wr.close(); }
catch (IOException e2) {}
return -1;
}
try { conWriter.close (); }
catch (IOException e) { return -1; }
conWriter = wr;
return 1;
}
return -1;
}
}

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.20 2007/05/24 04:17:42 bacon Exp $
* $Id: Awk.cpp,v 1.22 2007/05/25 14:41:48 bacon Exp $
*/
#include <ase/awk/StdAwk.hpp>
@ -172,6 +172,7 @@ protected:
{
Source::Mode mode = io.getMode();
FILE* fp = (FILE*)io.getHandle();
if (fp == stdout || fp == stderr) fflush (fp);
if (fp != stdin && fp != stdout && fp != stderr) fclose (fp);
io.setHandle (ASE_NULL);
return 0;
@ -276,6 +277,7 @@ protected:
ConTrack* t = (ConTrack*)io.getHandle();
FILE* fp = t->handle;
if (fp == stdout || fp == stderr) fflush (fp);
if (fp != stdin && fp != stdout && fp != stderr) fclose (fp);
ase_awk_free (awk, t);
@ -467,9 +469,8 @@ static void print_usage (const ase_char_t* argv0)
const ase_char_t* base;
base = ase_strrchr(argv0, ASE_T('/'));
if (base == ASE_NULL)
base = ase_strrchr(argv0, ASE_T('\\'));
if (base == ASE_NULL) base = argv0;
if (base == ASE_NULL) base = ase_strrchr(argv0, ASE_T('\\'));
if (base == ASE_NULL) base = argv0; else base++;
ase_printf (ASE_T("Usage: %s [-m main] [-si file]? [-so file]? [-ci file]* [-co file]* [-a arg]*\n"), base);
ase_printf (ASE_T(" -m main Specify the main function name\n"));