Recovered from cvs revision 2007-05-13 02:06:00

This commit is contained in:
hyung-hwan 2007-05-14 00:48:00 +00:00
parent 6dbc57d605
commit 1804de35b5
5 changed files with 174 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.22 2007/05/12 03:53:32 bacon Exp $ * $Id: Awk.cpp,v 1.23 2007/05/12 17:05:07 bacon Exp $
*/ */
#include <ase/awk/Awk.hpp> #include <ase/awk/Awk.hpp>
@ -550,22 +550,31 @@ namespace ASE
ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_PIPE); ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_PIPE);
Pipe pipe (epa->name, (Pipe::Mode)epa->mode); Pipe pipe (epa->name, (Pipe::Mode)epa->mode);
ssize_t n;
switch (cmd) switch (cmd)
{ {
case ASE_AWK_IO_OPEN: case ASE_AWK_IO_OPEN:
return awk->openPipe (pipe); n = awk->openPipe (pipe);
if (n >= 0) epa->handle = (void*)pipe.getHandle();
return n;
case ASE_AWK_IO_CLOSE: case ASE_AWK_IO_CLOSE:
pipe.setHandle (epa->handle);
return awk->closePipe (pipe); return awk->closePipe (pipe);
case ASE_AWK_IO_READ: case ASE_AWK_IO_READ:
pipe.setHandle (epa->handle);
return awk->readPipe (pipe, data, count); return awk->readPipe (pipe, data, count);
case ASE_AWK_IO_WRITE: case ASE_AWK_IO_WRITE:
pipe.setHandle (epa->handle);
return awk->writePipe (pipe, data, count); return awk->writePipe (pipe, data, count);
case ASE_AWK_IO_FLUSH: case ASE_AWK_IO_FLUSH:
pipe.setHandle (epa->handle);
return awk->flushPipe (pipe); return awk->flushPipe (pipe);
case ASE_AWK_IO_NEXT: case ASE_AWK_IO_NEXT:
pipe.setHandle (epa->handle);
return awk->nextPipe (pipe); return awk->nextPipe (pipe);
} }
@ -581,22 +590,31 @@ namespace ASE
ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_FILE); ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_FILE);
File file (epa->name, (File::Mode)epa->mode); File file (epa->name, (File::Mode)epa->mode);
ssize_t n;
switch (cmd) switch (cmd)
{ {
case ASE_AWK_IO_OPEN: case ASE_AWK_IO_OPEN:
return awk->openFile (file); n = awk->openFile (file);
if (n >= 0) epa->handle = (void*)file.getHandle();
return n;
case ASE_AWK_IO_CLOSE: case ASE_AWK_IO_CLOSE:
file.setHandle (epa->handle);
return awk->closeFile (file); return awk->closeFile (file);
case ASE_AWK_IO_READ: case ASE_AWK_IO_READ:
file.setHandle (epa->handle);
return awk->readFile (file, data, count); return awk->readFile (file, data, count);
case ASE_AWK_IO_WRITE: case ASE_AWK_IO_WRITE:
file.setHandle (epa->handle);
return awk->writeFile (file, data, count); return awk->writeFile (file, data, count);
case ASE_AWK_IO_FLUSH: case ASE_AWK_IO_FLUSH:
file.setHandle (epa->handle);
return awk->flushFile (file); return awk->flushFile (file);
case ASE_AWK_IO_NEXT: case ASE_AWK_IO_NEXT:
file.setHandle (epa->handle);
return awk->nextFile (file); return awk->nextFile (file);
} }
@ -612,22 +630,31 @@ namespace ASE
ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_CONSOLE); ASE_ASSERT ((epa->type & 0xFF) == ASE_AWK_EXTIO_CONSOLE);
Console console (epa->name, (Console::Mode)epa->mode); Console console (epa->name, (Console::Mode)epa->mode);
ssize_t n;
switch (cmd) switch (cmd)
{ {
case ASE_AWK_IO_OPEN: case ASE_AWK_IO_OPEN:
return awk->openConsole (console); n = awk->openConsole (console);
if (n >= 0) epa->handle = (void*)console.getHandle();
return n;
case ASE_AWK_IO_CLOSE: case ASE_AWK_IO_CLOSE:
console.setHandle (epa->handle);
return awk->closeConsole (console); return awk->closeConsole (console);
case ASE_AWK_IO_READ: case ASE_AWK_IO_READ:
console.setHandle (epa->handle);
return awk->readConsole (console, data, count); return awk->readConsole (console, data, count);
case ASE_AWK_IO_WRITE: case ASE_AWK_IO_WRITE:
console.setHandle (epa->handle);
return awk->writeConsole (console, data, count); return awk->writeConsole (console, data, count);
case ASE_AWK_IO_FLUSH: case ASE_AWK_IO_FLUSH:
console.setHandle (epa->handle);
return awk->flushConsole (console); return awk->flushConsole (console);
case ASE_AWK_IO_NEXT: case ASE_AWK_IO_NEXT:
console.setHandle (epa->handle);
return awk->nextConsole (console); return awk->nextConsole (console);
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.6 2007/05/07 09:30:28 bacon Exp $ * $Id: Awk.cpp,v 1.8 2007/05/12 17:05:07 bacon Exp $
*/ */
#include <ase/awk/StdAwk.hpp> #include <ase/awk/StdAwk.hpp>
@ -94,26 +94,122 @@ protected:
int nextPipe (Pipe& io) { return 0; } int nextPipe (Pipe& io) { return 0; }
// file io handlers // file io handlers
int openFile (File& io) { return -1; } int openFile (File& io)
int closeFile (File& io) { return 0; } {
ssize_t readFile (File& io, char_t* buf, size_t len) { return 0; } Awk::File::Mode mode = io.getMode();
ssize_t writeFile (File& io, char_t* buf, size_t len) { return 0; } FILE* fp = NULL;
int flushFile (File& io) { return 0; }
int nextFile (File& io) { return 0; } switch (mode)
{
case Awk::File::READ:
fp = ase_fopen (io.getName(), ASE_T("r"));
break;
case Awk::File::WRITE:
fp = ase_fopen (io.getName(), ASE_T("w"));
break;
case Awk::File::APPEND:
fp = ase_fopen (io.getName(), ASE_T("a"));
break;
}
if (fp == NULL) return -1;
io.setHandle (fp);
return 1;
}
int closeFile (File& io)
{
fclose ((FILE*)io.getHandle());
return 0;
}
ssize_t readFile (File& io, char_t* buf, size_t len)
{
FILE* fp = (FILE*)io.getHandle();
if (ase_fgets (buf, len, fp) == ASE_NULL)
{
if (ferror(fp)) return -1;
return 0;
}
return ase_strlen(buf);
}
ssize_t writeFile (File& io, char_t* buf, size_t len)
{
FILE* fp = (FILE*)io.getHandle();
size_t left = len;
while (left > 0)
{
if (*buf == ASE_T('\0'))
{
if (ase_fputc (*buf, fp) == ASE_CHAR_EOF) return -1;
left -= 1; buf += 1;
}
else
{
int n = ase_fprintf (fp, ASE_T("%.*s"), left, buf);
if (n < 0) return -1;
left -= n; buf += n;
}
}
return len;
}
int flushFile (File& io)
{
return ::fflush ((FILE*)io.getHandle());
}
int nextFile (File& io)
{
return -1;
}
// console io handlers // console io handlers
int openConsole (Console& io) { return 1; } int openConsole (Console& io) { return 1; }
int closeConsole (Console& io) { return 0; } int closeConsole (Console& io) { return 0; }
ssize_t readConsole (Console& io, char_t* buf, size_t len) ssize_t readConsole (Console& io, char_t* buf, size_t len)
{ {
return 0; FILE* fp = stdin;
if (ase_fgets (buf, len, fp) == ASE_NULL)
{
if (ferror(fp)) return -1;
return 0;
}
return ase_strlen(buf);
} }
ssize_t writeConsole (Console& io, char_t* buf, size_t len) ssize_t writeConsole (Console& io, char_t* buf, size_t len)
{ {
return ase_printf (ASE_T("%.*s"), len, buf); FILE* fp = stdout;
size_t left = len;
while (left > 0)
{
if (*buf == ASE_T('\0'))
{
if (ase_fputc (*buf, fp) == ASE_CHAR_EOF) return -1;
left -= 1; buf += 1;
}
else
{
int n = ase_fprintf (fp, ASE_T("%.*s"), left, buf);
if (n < 0) return -1;
left -= n; buf += n;
}
}
return len;
} }
int flushConsole (Console& io) { return 0; }
int nextConsole (Console& io) { return 0; } int flushConsole (Console& io) { return ::fflush (stdout); }
int nextConsole (Console& io) { return 0; }
// primitive operations // primitive operations
void* allocMem (size_t n) { return ::malloc (n); } void* allocMem (size_t n) { return ::malloc (n); }
@ -193,25 +289,21 @@ int awk_main (int argc, ase_char_t* argv[])
if (awk.open() == -1) if (awk.open() == -1)
{ {
ase_fprintf (stderr, ASE_T("cannot open awk\n")); ase_fprintf (stderr, ASE_T("cannot open awk\n"));
//awk.close ();
return -1; return -1;
} }
if (awk.parse(ASE_T("t.awk")) == -1) if (awk.parse(ASE_T("t.awk")) == -1)
{ {
ase_fprintf (stderr, ASE_T("cannot parse\n")); ase_fprintf (stderr, ASE_T("cannot parse\n"));
//awk.close ();
return -1; return -1;
} }
if (awk.run () == -1) if (awk.run () == -1)
{ {
ase_fprintf (stderr, ASE_T("cannot run\n")); ase_fprintf (stderr, ASE_T("cannot run\n"));
//awk.close ();
return -1; return -1;
} }
// awk.close ();
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.3 2007/04/30 08:32:41 bacon Exp $ * $Id: awk.c,v 1.4 2007/05/12 17:05:07 bacon Exp $
*/ */
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -412,9 +412,23 @@ static ase_ssize_t awk_extio_file (
case ASE_AWK_IO_WRITE: case ASE_AWK_IO_WRITE:
{ {
int n = ase_fprintf ( FILE* fp = (FILE*)epa->handle;
(FILE*)epa->handle, ASE_T("%.*s"), size, data); ssize_t left = size;
if (n < 0) return -1;
while (left > 0)
{
if (*data == ASE_T('\0'))
{
if (ase_fputc (*data, fp) == ASE_CHAR_EOF) return -1;
left -= 1; data += 1;
}
else
{
int n = ase_fprintf (fp, ASE_T("%.*s"), left, data);
if (n < 0) return -1;
left -= n; data += n;
}
}
return size; return size;
} }

View File

@ -6,7 +6,7 @@ run_script_for_init()
data="$2" data="$2"
output=`echo $script | sed 's/\.awk$/.out/g'` output=`echo $script | sed 's/\.awk$/.out/g'`
./aseawk -d -f "$script" "$data" > "$output" "$ASEAWK" -d -f "$script" "$data" > "$output"
} }
run_init() run_init()
@ -34,7 +34,7 @@ run_script_for_test()
output=`echo $script | sed 's/\.awk$/.out/g'` output=`echo $script | sed 's/\.awk$/.out/g'`
echo ">> RUNNING $script" echo ">> RUNNING $script"
./aseawk -d -f "$script" "$data" > "$output.$pid" "$ASEAWK" -d -f "$script" "$data" > "$output.$pid"
#diff -y "$output" "$output.$pid" #diff -y "$output" "$output.$pid"
diff "$output" "$output.$pid" diff "$output" "$output.$pid"
@ -113,8 +113,16 @@ run_test()
# main # # main #
#--------# #--------#
if [ ! -x ./aseawk ] if [ -x ./aseawk ]
then then
ASEAWK="./aseawk"
elif [ -x ../../release/bin/aseawk ]
then
ASEAWK="../../release/bin/aseawk"
elif [ -x ../../debug/bin/aseawk ]
then
ASEAWK="../../debug/bin/aseawk"
else
echo "Error: cannot locate a relevant awk interpreter" echo "Error: cannot locate a relevant awk interpreter"
exit 1; exit 1;
fi fi

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stdio.h,v 1.3 2007/04/30 08:32:51 bacon Exp $ * $Id: stdio.h,v 1.4 2007/05/12 17:05:07 bacon Exp $
*/ */
#ifndef _ASE_UTL_STDIO_H_ #ifndef _ASE_UTL_STDIO_H_
@ -22,12 +22,18 @@
#define ase_fgets _fgetts #define ase_fgets _fgetts
#define ase_fgetc _fgettc #define ase_fgetc _fgettc
#define ase_fputs _fputts
#define ase_fputc _fputtc
#elif defined(ASE_CHAR_IS_MCHAR) #elif defined(ASE_CHAR_IS_MCHAR)
#define ase_fgets fgets #define ase_fgets fgets
#define ase_fgetc fgetc #define ase_fgetc fgetc
#define ase_fputs fputs
#define ase_fputc fputc
#else #else
#define ase_fgets fgetws #define ase_fgets fgetws
#define ase_fgetc fgetwc #define ase_fgetc fgetwc
#define ase_fputs fputws
#define ase_fputc fputwc
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus