*** empty log message ***

This commit is contained in:
2006-11-24 13:25:12 +00:00
parent e9757b21c4
commit 92c48f1b2f
12 changed files with 438 additions and 348 deletions

View File

@ -1,12 +1,12 @@
/*
* $Id: Awk.java,v 1.6 2006-11-23 03:31:58 bacon Exp $
* $Id: Awk.java,v 1.7 2006-11-24 13:25:12 bacon Exp $
*/
package ase.test.awk;
import java.io.*;
public class Awk extends ase.awk.Awk
public class Awk extends ase.awk.StdAwk
{
private FileReader insrc;
private FileWriter outsrc;
@ -20,18 +20,24 @@ public class Awk extends ase.awk.Awk
public Awk () throws ase.awk.Exception
{
super ();
}
cin = new String[3];
protected String[] getInputConsoleNames ()
{
String[] cin = new String[3];
cin[0] = "c1.txt";
cin[1] = "c2.txt";
cin[2] = "c3.txt";
cin_no = 0;
return cin;
}
cout = new String[3];
protected String[] getOutputConsoleNames ()
{
String[] cout = new String[3];
cout[0] = "c4.txt";
cout[1] = "c5.txt";
cout[2] = "";
cout_no = 0;
return cout;
}
protected int open_source (int mode)
@ -83,323 +89,6 @@ public class Awk extends ase.awk.Awk
return len;
}
/* ===== console ===== */
protected int open_console (ase.awk.Extio extio)
{
System.err.println ("[open_console called.... name: " + extio.getName() + " mode: " + extio.getMode());
int mode = extio.getMode ();
if (mode == ase.awk.Extio.MODE_CONSOLE_READ)
{
InputStreamReader isr;
if (cin_no >= cin.length) return 0;
isr = get_input_stream (cin[cin_no]);
if (isr == null) return -1;
extio.setHandle (isr);
setConsoleName (extio, cin[cin_no]);
cin_no++;
return 1;
}
else if (mode == ase.awk.Extio.MODE_CONSOLE_WRITE)
{
OutputStreamWriter osw;
if (cout_no >= cout.length) return 0;
osw = get_output_stream (cout[cout_no]);
if (osw == null) return -1;
extio.setHandle (osw);
setOutputConsoleName (extio, cout[cout_no]);
cout_no++;
return 1;
}
return -1;
}
protected int close_console (ase.awk.Extio extio)
{
System.err.println ("[close_console called.... name: " + extio.getName() + " mode: " + extio.getMode());
int mode = extio.getMode ();
if (mode == ase.awk.Extio.MODE_CONSOLE_READ)
{
InputStreamReader isr = (InputStreamReader)extio.getHandle ();
try { isr.close (); }
catch (IOException e) { return -1; }
return 0;
}
else if (mode == ase.awk.Extio.MODE_CONSOLE_WRITE)
{
OutputStreamWriter osw = (OutputStreamWriter)extio.getHandle ();
//try { osw.close (); }
//catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int read_console (ase.awk.Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == ase.awk.Extio.MODE_CONSOLE_READ)
{
InputStreamReader isr, tmp;
int n;
isr = (InputStreamReader)extio.getHandle ();
try { n = isr.read (buf, 0, len); }
catch (IOException e) { return -1; }
while (n == -1)
{
if (cin_no >= cin.length) return 0;
tmp = get_input_stream (cin[cin_no]);
if (tmp == null) return -1;
try { isr.close (); }
catch (IOException e) { /* ignore */ }
extio.setHandle (tmp);
setConsoleName (extio, cin[cin_no]);
isr = (InputStreamReader)extio.getHandle ();
cin_no++;
try { n = isr.read (buf, 0, len); }
catch (IOException e) { return -1; }
}
return n;
}
return -1;
}
protected int write_console (ase.awk.Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == ase.awk.Extio.MODE_CONSOLE_WRITE)
{
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 (); }
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int next_console (ase.awk.Extio extio)
{
int mode = extio.getMode ();
if (mode == ase.awk.Extio.MODE_CONSOLE_READ)
{
InputStreamReader isr, tmp;
isr = (InputStreamReader)extio.getHandle ();
if (cin_no >= cin.length) return 0;
tmp = get_input_stream (cin[cin_no]);
if (tmp == null) return -1;
try { isr.close (); }
catch (IOException e) { /* ignore */ }
extio.setHandle (tmp);
setConsoleName (extio, cin[cin_no]);
cin_no++;
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;
}
private InputStreamReader get_input_stream (String name)
{
InputStreamReader isr;
if (name == null || name.length() == 0)
{
isr = new InputStreamReader (System.in);
}
else
{
FileInputStream fis;
try { fis = new FileInputStream (name); }
catch (IOException e) { return null; }
isr = new InputStreamReader (fis);
}
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 ===== */
public int open_file (ase.awk.Extio extio)
{
int mode = extio.getMode();
if (mode == ase.awk.Extio.MODE_FILE_READ)
{
FileInputStream fis;
InputStreamReader isr;
try { fis = new FileInputStream (extio.getName()); }
catch (IOException e) { return -1; }
isr = new InputStreamReader (fis);
extio.setHandle (isr);
return 1;
}
else if (mode == ase.awk.Extio.MODE_FILE_WRITE)
{
FileOutputStream fos;
OutputStreamWriter osw;
try { fos = new FileOutputStream (extio.getName()); }
catch (IOException e) { return -1; }
osw = new OutputStreamWriter (fos);
extio.setHandle (osw);
return 1;
}
else if (mode == ase.awk.Extio.MODE_FILE_APPEND)
{
FileOutputStream fos;
OutputStreamWriter osw;
try { fos = new FileOutputStream (extio.getName(), true); }
catch (IOException e) { return -1; }
osw = new OutputStreamWriter (fos);
extio.setHandle (osw);
return 1;
}
return -1;
}
public int close_file (ase.awk.Extio extio)
{
int mode = extio.getMode();
if (mode == ase.awk.Extio.MODE_FILE_READ)
{
InputStreamReader isr;
isr = (InputStreamReader)extio.getHandle();
try { isr.close (); }
catch (IOException e) { return -1; }
return 0;
}
else if (mode == ase.awk.Extio.MODE_FILE_WRITE)
{
OutputStreamWriter osw;
osw = (OutputStreamWriter)extio.getHandle();
try { osw.close (); }
catch (IOException e) { return -1; }
return 0;
}
else if (mode == ase.awk.Extio.MODE_FILE_APPEND)
{
OutputStreamWriter osw;
osw = (OutputStreamWriter)extio.getHandle();
try { osw.close (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int read_file (ase.awk.Extio extio, char[] buf, int len)
{
int mode = extio.getMode();
if (mode == ase.awk.Extio.MODE_FILE_READ)
{
InputStreamReader isr;
isr = (InputStreamReader)extio.getHandle();
try
{
len = isr.read (buf, 0, len);
if (len == -1) len = 0;
}
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
protected int write_file (ase.awk.Extio extio, char[] buf, int len)
{
int mode = extio.getMode();
if (mode == ase.awk.Extio.MODE_FILE_WRITE ||
mode == ase.awk.Extio.MODE_FILE_APPEND)
{
OutputStreamWriter osw;
osw = (OutputStreamWriter)extio.getHandle();
try { osw.write (buf, 0, len); }
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
public static void main (String[] args)
{
Awk awk = null;

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.124 2006-11-23 14:31:59 bacon Exp $
* $Id: awk.c,v 1.125 2006-11-24 13:25:12 bacon Exp $
*/
#include <ase/awk/awk.h>
@ -537,7 +537,7 @@ static int open_extio_console (ase_awk_extio_t* epa)
}
__awk_dprintf (ASE_T(" console(r) - %s\n"), infiles[infile_no]);
if (ase_awk_setconsolename (
if (ase_awk_setfilename (
epa->run, infiles[infile_no],
ase_awk_strlen(infiles[infile_no])) == -1)
{