2007-05-04 00:14:00 +00:00
|
|
|
/*
|
2008-08-21 04:58:19 +00:00
|
|
|
* $Id: Awk.cpp 341 2008-08-20 10:58:19Z baconevi $
|
2007-05-04 00:14:00 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-07 01:05:00 +00:00
|
|
|
#include <ase/awk/StdAwk.hpp>
|
|
|
|
#include <ase/cmn/str.h>
|
|
|
|
#include <ase/utl/stdio.h>
|
|
|
|
#include <ase/utl/main.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
2007-05-07 20:08:00 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
2007-05-07 01:05:00 +00:00
|
|
|
#include <windows.h>
|
2007-05-24 15:56:00 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2007-05-07 20:08:00 +00:00
|
|
|
#endif
|
2007-05-07 01:05:00 +00:00
|
|
|
|
2007-10-10 22:33:00 +00:00
|
|
|
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
|
|
|
|
#define _CRTDBG_MAP_ALLOC
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
|
2007-12-07 23:58:44 +00:00
|
|
|
#if defined(__linux) && defined(_DEBUG)
|
|
|
|
#include <mcheck.h>
|
|
|
|
#endif
|
|
|
|
|
2008-01-01 07:16:29 +00:00
|
|
|
static bool verbose = false;
|
|
|
|
|
2007-05-07 01:05:00 +00:00
|
|
|
class TestAwk: public ASE::StdAwk
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2007-05-07 01:05:00 +00:00
|
|
|
public:
|
2007-05-15 01:21:00 +00:00
|
|
|
TestAwk (): srcInName(ASE_NULL), srcOutName(ASE_NULL),
|
|
|
|
numConInFiles(0), numConOutFiles(0)
|
2007-05-07 20:08:00 +00:00
|
|
|
{
|
2007-05-18 01:21:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
heap = ASE_NULL;
|
|
|
|
#endif
|
2007-05-07 20:08:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
~TestAwk ()
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
close ();
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
int open ()
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
ASE_ASSERT (heap == ASE_NULL);
|
2007-05-24 15:56:00 +00:00
|
|
|
heap = ::HeapCreate (0, 1000000, 1000000);
|
2007-05-18 01:21:00 +00:00
|
|
|
if (heap == ASE_NULL) return -1;
|
|
|
|
#endif
|
|
|
|
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
int n = StdAwk::open ();
|
|
|
|
#else
|
2007-06-18 00:31:00 +00:00
|
|
|
int n = ASE::StdAwk::open ();
|
2007-06-24 02:19:00 +00:00
|
|
|
#endif
|
2007-10-02 00:22:00 +00:00
|
|
|
if (n == -1)
|
2007-05-24 15:56:00 +00:00
|
|
|
{
|
2007-10-13 01:13:00 +00:00
|
|
|
#ifdef _WIN32
|
2007-05-24 15:56:00 +00:00
|
|
|
HeapDestroy (heap);
|
|
|
|
heap = ASE_NULL;
|
2007-10-13 01:13:00 +00:00
|
|
|
#endif
|
2007-05-24 15:56:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-02 00:22:00 +00:00
|
|
|
idLastSleep = addGlobal (ASE_T("LAST_SLEEP"));
|
|
|
|
if (idLastSleep == -1) goto failure;
|
|
|
|
|
|
|
|
if (addFunction (ASE_T("sleep"), 1, 1,
|
|
|
|
(FunctionHandler)&TestAwk::sleep) == -1) goto failure;
|
|
|
|
|
|
|
|
if (addFunction (ASE_T("sumintarray"), 1, 1,
|
|
|
|
(FunctionHandler)&TestAwk::sumintarray) == -1) goto failure;
|
|
|
|
|
|
|
|
if (addFunction (ASE_T("arrayindices"), 1, 1,
|
|
|
|
(FunctionHandler)&TestAwk::arrayindices) == -1) goto failure;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
StdAwk::close ();
|
|
|
|
#else
|
|
|
|
ASE::StdAwk::close ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
HeapDestroy (heap);
|
|
|
|
heap = ASE_NULL;
|
|
|
|
#endif
|
|
|
|
return -1;
|
2007-05-18 01:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void close ()
|
|
|
|
{
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
StdAwk::close ();
|
|
|
|
#else
|
2007-06-18 00:31:00 +00:00
|
|
|
ASE::StdAwk::close ();
|
2007-06-24 02:19:00 +00:00
|
|
|
#endif
|
2007-05-18 01:21:00 +00:00
|
|
|
|
|
|
|
numConInFiles = 0;
|
|
|
|
numConOutFiles = 0;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2007-07-25 18:53:00 +00:00
|
|
|
if (heap != ASE_NULL)
|
|
|
|
{
|
|
|
|
HeapDestroy (heap);
|
|
|
|
heap = ASE_NULL;
|
|
|
|
}
|
2007-05-18 01:21:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-09-25 00:12:00 +00:00
|
|
|
int sleep (Run& run, Return& ret, const Argument* args, size_t nargs,
|
2007-07-16 20:16:00 +00:00
|
|
|
const char_t* name, size_t len)
|
2007-05-24 15:56:00 +00:00
|
|
|
{
|
2007-10-02 00:22:00 +00:00
|
|
|
if (args[0].isIndexed())
|
|
|
|
{
|
|
|
|
run.setError (ERR_INVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-09-25 00:12:00 +00:00
|
|
|
long_t x = args[0].toInt();
|
2007-09-25 20:25:00 +00:00
|
|
|
|
|
|
|
/*Argument arg;
|
|
|
|
if (run.getGlobal(idLastSleep, arg) == 0)
|
|
|
|
ase_printf (ASE_T("GOOD: [%d]\n"), (int)arg.toInt());
|
|
|
|
else { ase_printf (ASE_T("BAD:\n")); }
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (run.setGlobal (idLastSleep, x) == -1) return -1;
|
|
|
|
|
2007-05-24 15:56:00 +00:00
|
|
|
#ifdef _WIN32
|
2007-10-02 00:22:00 +00:00
|
|
|
::Sleep ((DWORD)(x * 1000));
|
2007-09-25 00:12:00 +00:00
|
|
|
return ret.set ((long_t)0);
|
2007-05-24 15:56:00 +00:00
|
|
|
#else
|
2007-09-25 00:12:00 +00:00
|
|
|
return ret.set ((long_t)::sleep (x));
|
2007-05-24 15:56:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-10-02 00:22:00 +00:00
|
|
|
int sumintarray (Run& run, Return& ret, const Argument* args, size_t nargs,
|
|
|
|
const char_t* name, size_t len)
|
|
|
|
{
|
|
|
|
long_t x = 0;
|
|
|
|
|
|
|
|
if (args[0].isIndexed())
|
|
|
|
{
|
2007-10-08 18:50:00 +00:00
|
|
|
Argument idx(run), val(run);
|
2007-10-02 00:22:00 +00:00
|
|
|
|
|
|
|
int n = args[0].getFirstIndex (idx);
|
|
|
|
while (n > 0)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char_t* ptr = idx.toStr(&len);
|
|
|
|
|
2007-10-03 18:47:00 +00:00
|
|
|
if (args[0].getIndexed(ptr, len, val) == -1) return -1;
|
2007-10-02 00:22:00 +00:00
|
|
|
x += val.toInt ();
|
|
|
|
|
|
|
|
n = args[0].getNextIndex (idx);
|
|
|
|
}
|
|
|
|
if (n != 0) return -1;
|
|
|
|
}
|
|
|
|
else x += args[0].toInt();
|
|
|
|
|
|
|
|
return ret.set (x);
|
|
|
|
}
|
|
|
|
|
|
|
|
int arrayindices (Run& run, Return& ret, const Argument* args, size_t nargs,
|
|
|
|
const char_t* name, size_t len)
|
|
|
|
{
|
|
|
|
if (!args[0].isIndexed()) return 0;
|
|
|
|
|
2007-10-08 18:50:00 +00:00
|
|
|
Argument idx (run);
|
2007-10-03 18:47:00 +00:00
|
|
|
long_t i;
|
2007-10-02 00:22:00 +00:00
|
|
|
|
|
|
|
int n = args[0].getFirstIndex (idx);
|
2007-10-03 00:21:00 +00:00
|
|
|
for (i = 0; n > 0; i++)
|
2007-10-02 00:22:00 +00:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char_t* ptr = idx.toStr(&len);
|
|
|
|
n = args[0].getNextIndex (idx);
|
2007-10-03 18:47:00 +00:00
|
|
|
if (ret.setIndexed (i, ptr, len) == -1) return -1;
|
2007-10-02 00:22:00 +00:00
|
|
|
}
|
|
|
|
if (n != 0) return -1;
|
|
|
|
|
2007-10-03 00:21:00 +00:00
|
|
|
return 0;
|
2007-10-02 00:22:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
int addConsoleInput (const char_t* file)
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
if (numConInFiles < ASE_COUNTOF(conInFile))
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
conInFile[numConInFiles++] = file;
|
|
|
|
return 0;
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
2007-05-15 01:21:00 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int addConsoleOutput (const char_t* file)
|
|
|
|
{
|
|
|
|
if (numConOutFiles < ASE_COUNTOF(conOutFile))
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
conOutFile[numConOutFiles++] = file;
|
2007-05-07 01:05:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
int parse (const char_t* in, const char_t* out)
|
|
|
|
{
|
|
|
|
srcInName = in;
|
|
|
|
srcOutName = out;
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
return StdAwk::parse ();
|
|
|
|
#else
|
2007-06-18 00:31:00 +00:00
|
|
|
return ASE::StdAwk::parse ();
|
2007-06-24 02:19:00 +00:00
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2007-10-30 00:20:00 +00:00
|
|
|
void onRunStart (Run& run)
|
2007-05-16 01:03:00 +00:00
|
|
|
{
|
2008-01-01 07:16:29 +00:00
|
|
|
if (verbose) ase_printf (ASE_T("*** awk run started ***\n"));
|
2007-05-16 01:03:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 00:20:00 +00:00
|
|
|
void onRunEnd (Run& run)
|
2007-05-16 01:03:00 +00:00
|
|
|
{
|
2007-05-21 01:22:00 +00:00
|
|
|
ErrorCode err = run.getErrorCode();
|
|
|
|
|
2007-06-28 00:27:00 +00:00
|
|
|
if (err != ERR_NOERR)
|
2007-05-21 01:22:00 +00:00
|
|
|
{
|
|
|
|
ase_fprintf (stderr, ASE_T("cannot run: LINE[%d] %s\n"),
|
|
|
|
run.getErrorLine(), run.getErrorMessage());
|
|
|
|
}
|
|
|
|
|
2008-01-01 07:16:29 +00:00
|
|
|
if (verbose) ase_printf (ASE_T("*** awk run ended ***\n"));
|
2007-05-21 01:22:00 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 00:20:00 +00:00
|
|
|
void onRunReturn (Run& run, const Argument& ret)
|
2007-05-21 01:22:00 +00:00
|
|
|
{
|
2008-01-01 07:16:29 +00:00
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char_t* ptr = ret.toStr (&len);
|
|
|
|
ase_printf (ASE_T("*** return [%.*s] ***\n"), (int)len, ptr);
|
|
|
|
}
|
2007-05-16 01:03:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
int openSource (Source& io)
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2007-05-07 01:05:00 +00:00
|
|
|
Source::Mode mode = io.getMode();
|
2007-05-15 01:21:00 +00:00
|
|
|
FILE* fp = ASE_NULL;
|
2007-05-07 01:05:00 +00:00
|
|
|
|
|
|
|
if (mode == Source::READ)
|
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
if (srcInName == ASE_NULL)
|
|
|
|
{
|
|
|
|
io.setHandle (stdin);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcInName[0] == ASE_T('\0')) fp = stdin;
|
|
|
|
else fp = ase_fopen (srcInName, ASE_T("r"));
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
|
|
|
else if (mode == Source::WRITE)
|
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
if (srcOutName == ASE_NULL)
|
|
|
|
{
|
|
|
|
io.setHandle (stdout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcOutName[0] == ASE_T('\0')) fp = stdout;
|
|
|
|
else fp = ase_fopen (srcOutName, ASE_T("w"));
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
if (fp == ASE_NULL) return -1;
|
|
|
|
io.setHandle (fp);
|
|
|
|
return 1;
|
2007-05-04 00:14:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
int closeSource (Source& io)
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
Source::Mode mode = io.getMode();
|
|
|
|
FILE* fp = (FILE*)io.getHandle();
|
2007-05-26 21:41:00 +00:00
|
|
|
if (fp == stdout || fp == stderr) fflush (fp);
|
2007-05-15 01:21:00 +00:00
|
|
|
if (fp != stdin && fp != stdout && fp != stderr) fclose (fp);
|
|
|
|
io.setHandle (ASE_NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t readSource (Source& io, char_t* buf, size_t len)
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
FILE* fp = (FILE*)io.getHandle();
|
2007-05-18 01:21:00 +00:00
|
|
|
ssize_t n = 0;
|
2007-05-07 01:05:00 +00:00
|
|
|
|
2007-05-21 01:22:00 +00:00
|
|
|
while (n < (ssize_t)len)
|
2007-05-14 01:20:00 +00:00
|
|
|
{
|
2007-05-18 01:21:00 +00:00
|
|
|
ase_cint_t c = ase_fgetc (fp);
|
2008-01-16 00:36:07 +00:00
|
|
|
if (c == ASE_CHAR_EOF)
|
|
|
|
{
|
|
|
|
if (ase_ferror(fp)) n = -1;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-14 01:20:00 +00:00
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
buf[n++] = c;
|
|
|
|
if (c == ASE_T('\n')) break;
|
2007-05-14 01:20:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
return n;
|
2007-05-14 01:20:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
ssize_t writeSource (Source& io, char_t* buf, size_t len)
|
2007-05-14 00:48:00 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2007-11-11 00:30:00 +00:00
|
|
|
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
|
2007-11-10 00:20:00 +00:00
|
|
|
int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf);
|
|
|
|
if (n < 0 || n > chunk) return -1;
|
2007-05-14 00:48:00 +00:00
|
|
|
left -= n; buf += n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2007-05-07 01:05:00 +00:00
|
|
|
// console io handlers
|
2007-05-15 01:21:00 +00:00
|
|
|
int openConsole (Console& io)
|
|
|
|
{
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
StdAwk::Console::Mode mode = io.getMode();
|
|
|
|
#else
|
|
|
|
ASE::StdAwk::Console::Mode mode = io.getMode();
|
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
FILE* fp = ASE_NULL;
|
|
|
|
const char_t* fn = ASE_NULL;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
case StdAwk::Console::READ:
|
|
|
|
#else
|
|
|
|
case ASE::StdAwk::Console::READ:
|
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
if (numConInFiles == 0) fp = stdin;
|
2007-06-18 00:31:00 +00:00
|
|
|
else
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
|
|
|
fn = conInFile[0];
|
|
|
|
fp = ase_fopen (fn, ASE_T("r"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
case StdAwk::Console::WRITE:
|
|
|
|
#else
|
|
|
|
case ASE::StdAwk::Console::WRITE:
|
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
if (numConOutFiles == 0) fp = stdout;
|
2007-06-18 00:31:00 +00:00
|
|
|
else
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
|
|
|
fn = conOutFile[0];
|
|
|
|
fp = ase_fopen (fn, ASE_T("w"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp == NULL) return -1;
|
2007-05-14 00:48:00 +00:00
|
|
|
|
2007-06-24 02:19:00 +00:00
|
|
|
ConTrack* t = (ConTrack*)
|
2008-08-21 04:58:19 +00:00
|
|
|
ase_awk_alloc (awk, ASE_SIZEOF(ConTrack));
|
2007-05-15 01:21:00 +00:00
|
|
|
if (t == ASE_NULL)
|
|
|
|
{
|
|
|
|
if (fp != stdin && fp != stdout) fclose (fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
t->handle = fp;
|
|
|
|
t->nextConIdx = 1;
|
|
|
|
|
|
|
|
if (fn != ASE_NULL)
|
|
|
|
{
|
2007-10-30 00:20:00 +00:00
|
|
|
if (io.setFileName(fn) == -1)
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
|
|
|
if (fp != stdin && fp != stdout) fclose (fp);
|
|
|
|
ase_awk_free (awk, t);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
io.setHandle (t);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int closeConsole (Console& io)
|
|
|
|
{
|
|
|
|
ConTrack* t = (ConTrack*)io.getHandle();
|
|
|
|
FILE* fp = t->handle;
|
|
|
|
|
2007-05-26 21:41:00 +00:00
|
|
|
if (fp == stdout || fp == stderr) fflush (fp);
|
2007-05-15 01:21:00 +00:00
|
|
|
if (fp != stdin && fp != stdout && fp != stderr) fclose (fp);
|
|
|
|
|
|
|
|
ase_awk_free (awk, t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t readConsole (Console& io, char_t* buf, size_t len)
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
ConTrack* t = (ConTrack*)io.getHandle();
|
|
|
|
FILE* fp = t->handle;
|
2007-05-18 01:21:00 +00:00
|
|
|
ssize_t n = 0;
|
2007-05-15 01:21:00 +00:00
|
|
|
|
2007-05-21 01:22:00 +00:00
|
|
|
while (n < (ssize_t)len)
|
2007-05-14 00:48:00 +00:00
|
|
|
{
|
2007-05-18 01:21:00 +00:00
|
|
|
ase_cint_t c = ase_fgetc (fp);
|
2007-10-30 00:20:00 +00:00
|
|
|
if (c == ASE_CHAR_EOF)
|
|
|
|
{
|
2008-01-16 00:36:07 +00:00
|
|
|
if (ase_ferror(fp)) return -1;
|
2007-10-30 00:20:00 +00:00
|
|
|
if (t->nextConIdx >= numConInFiles) break;
|
|
|
|
|
|
|
|
const char_t* fn = conInFile[t->nextConIdx];
|
|
|
|
FILE* nfp = ase_fopen (fn, ASE_T("r"));
|
|
|
|
if (nfp == ASE_NULL) return -1;
|
|
|
|
|
|
|
|
if (io.setFileName(fn) == -1 || io.setFNR(0) == -1)
|
|
|
|
{
|
|
|
|
fclose (nfp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
fp = nfp;
|
|
|
|
t->nextConIdx++;
|
|
|
|
t->handle = fp;
|
|
|
|
|
|
|
|
if (n == 0) continue;
|
|
|
|
else break;
|
|
|
|
}
|
2007-05-18 01:21:00 +00:00
|
|
|
|
|
|
|
buf[n++] = c;
|
|
|
|
if (c == ASE_T('\n')) break;
|
2007-05-14 00:48:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
return n;
|
2007-05-04 00:14:00 +00:00
|
|
|
}
|
2007-05-14 00:48:00 +00:00
|
|
|
|
2007-05-07 01:05:00 +00:00
|
|
|
ssize_t writeConsole (Console& io, char_t* buf, size_t len)
|
|
|
|
{
|
2007-05-15 01:21:00 +00:00
|
|
|
ConTrack* t = (ConTrack*)io.getHandle();
|
|
|
|
FILE* fp = t->handle;
|
2007-05-14 00:48:00 +00:00
|
|
|
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
|
|
|
|
{
|
2007-11-11 00:30:00 +00:00
|
|
|
int chunk = (left > ASE_TYPE_MAX(int))? ASE_TYPE_MAX(int): (int)left;
|
2007-11-10 00:20:00 +00:00
|
|
|
int n = ase_fprintf (fp, ASE_T("%.*s"), chunk, buf);
|
|
|
|
if (n < 0 || n > chunk) return -1;
|
2007-05-14 00:48:00 +00:00
|
|
|
left -= n; buf += n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
2007-05-14 00:48:00 +00:00
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
int flushConsole (Console& io)
|
|
|
|
{
|
|
|
|
ConTrack* t = (ConTrack*)io.getHandle();
|
|
|
|
FILE* fp = t->handle;
|
|
|
|
return ::fflush (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nextConsole (Console& io)
|
|
|
|
{
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
StdAwk::Console::Mode mode = io.getMode();
|
|
|
|
#else
|
|
|
|
ASE::StdAwk::Console::Mode mode = io.getMode();
|
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
ConTrack* t = (ConTrack*)io.getHandle();
|
|
|
|
FILE* ofp = t->handle;
|
|
|
|
FILE* nfp = ASE_NULL;
|
|
|
|
const char_t* fn = ASE_NULL;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
case StdAwk::Console::READ:
|
|
|
|
#else
|
|
|
|
case ASE::StdAwk::Console::READ:
|
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
if (t->nextConIdx >= numConInFiles) return 0;
|
|
|
|
fn = conInFile[t->nextConIdx];
|
|
|
|
nfp = ase_fopen (fn, ASE_T("r"));
|
|
|
|
break;
|
|
|
|
|
2007-06-24 02:19:00 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
case StdAwk::Console::WRITE:
|
|
|
|
#else
|
|
|
|
case ASE::StdAwk::Console::WRITE:
|
|
|
|
#endif
|
2007-05-15 01:21:00 +00:00
|
|
|
if (t->nextConIdx >= numConOutFiles) return 0;
|
|
|
|
fn = conOutFile[t->nextConIdx];
|
|
|
|
nfp = ase_fopen (fn, ASE_T("w"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nfp == ASE_NULL) return -1;
|
|
|
|
|
2007-06-18 00:31:00 +00:00
|
|
|
if (fn != ASE_NULL)
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
|
|
|
if (io.setFileName (fn) == -1)
|
|
|
|
{
|
|
|
|
fclose (nfp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (ofp);
|
|
|
|
|
|
|
|
t->nextConIdx++;
|
|
|
|
t->handle = nfp;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
void* allocMem (size_t n)
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-18 01:21:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
return ::HeapAlloc (heap, 0, n);
|
|
|
|
#else
|
|
|
|
return ::malloc (n);
|
|
|
|
#endif
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
void* reallocMem (void* ptr, size_t n)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (ptr == NULL)
|
|
|
|
return ::HeapAlloc (heap, 0, n);
|
|
|
|
else
|
|
|
|
return ::HeapReAlloc (heap, 0, ptr, n);
|
|
|
|
#else
|
|
|
|
return ::realloc (ptr, n);
|
|
|
|
#endif
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
void freeMem (void* ptr)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
::HeapFree (heap, 0, ptr);
|
|
|
|
#else
|
|
|
|
::free (ptr);
|
|
|
|
#endif
|
2007-05-07 01:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2007-05-15 01:21:00 +00:00
|
|
|
const char_t* srcInName;
|
|
|
|
const char_t* srcOutName;
|
|
|
|
|
|
|
|
struct ConTrack
|
|
|
|
{
|
|
|
|
FILE* handle;
|
|
|
|
size_t nextConIdx;
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t numConInFiles;
|
|
|
|
const char_t* conInFile[128];
|
|
|
|
|
|
|
|
size_t numConOutFiles;
|
|
|
|
const char_t* conOutFile[128];
|
2007-05-18 01:21:00 +00:00
|
|
|
|
2007-09-25 00:12:00 +00:00
|
|
|
int idLastSleep;
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
void* heap;
|
|
|
|
#endif
|
2007-05-04 00:14:00 +00:00
|
|
|
};
|
|
|
|
|
2007-05-07 01:05:00 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
void ase_assert_abort (void)
|
|
|
|
{
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ase_assert_printf (const ase_char_t* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
#ifdef _WIN32
|
|
|
|
int n;
|
|
|
|
ase_char_t buf[1024];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
#if defined(_WIN32)
|
|
|
|
n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap);
|
|
|
|
if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0');
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER<1400)
|
|
|
|
MessageBox (NULL, buf,
|
|
|
|
ASE_T("Assertion Failure"), MB_OK|MB_ICONERROR);
|
|
|
|
#else
|
|
|
|
MessageBox (NULL, buf,
|
|
|
|
ASE_T("\uB2DD\uAE30\uB9AC \uC870\uB610"), MB_OK|MB_ICONERROR);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
ase_vprintf (fmt, ap);
|
|
|
|
#endif
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
static void print_error (const ase_char_t* msg)
|
|
|
|
{
|
|
|
|
ase_printf (ASE_T("Error: %s\n"), msg);
|
|
|
|
}
|
|
|
|
|
2007-10-13 01:13:00 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const ase_char_t* name;
|
|
|
|
TestAwk::Option opt;
|
|
|
|
} otab[] =
|
|
|
|
{
|
|
|
|
{ ASE_T("implicit"), TestAwk::OPT_IMPLICIT },
|
|
|
|
{ ASE_T("explicit"), TestAwk::OPT_EXPLICIT },
|
2008-07-23 07:12:56 +00:00
|
|
|
{ ASE_T("bxor"), TestAwk::OPT_BXOR },
|
2007-10-13 01:13:00 +00:00
|
|
|
{ ASE_T("shift"), TestAwk::OPT_SHIFT },
|
|
|
|
{ ASE_T("idiv"), TestAwk::OPT_IDIV },
|
|
|
|
{ ASE_T("extio"), TestAwk::OPT_EXTIO },
|
2008-07-15 23:56:32 +00:00
|
|
|
{ ASE_T("newline"), TestAwk::OPT_NEWLINE },
|
2007-10-13 01:13:00 +00:00
|
|
|
{ ASE_T("baseone"), TestAwk::OPT_BASEONE },
|
|
|
|
{ ASE_T("stripspaces"), TestAwk::OPT_STRIPSPACES },
|
|
|
|
{ ASE_T("nextofile"), TestAwk::OPT_NEXTOFILE },
|
2008-01-01 07:30:18 +00:00
|
|
|
{ ASE_T("crlf"), TestAwk::OPT_CRLF },
|
2007-10-13 01:13:00 +00:00
|
|
|
{ ASE_T("argstomain"), TestAwk::OPT_ARGSTOMAIN },
|
|
|
|
{ ASE_T("reset"), TestAwk::OPT_RESET },
|
|
|
|
{ ASE_T("maptovar"), TestAwk::OPT_MAPTOVAR },
|
|
|
|
{ ASE_T("pablock"), TestAwk::OPT_PABLOCK }
|
|
|
|
};
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
static void print_usage (const ase_char_t* argv0)
|
|
|
|
{
|
2007-05-26 01:30:00 +00:00
|
|
|
const ase_char_t* base;
|
2007-10-13 01:13:00 +00:00
|
|
|
int j;
|
2007-05-26 01:30:00 +00:00
|
|
|
|
|
|
|
base = ase_strrchr(argv0, ASE_T('/'));
|
2007-05-26 21:41:00 +00:00
|
|
|
if (base == ASE_NULL) base = ase_strrchr(argv0, ASE_T('\\'));
|
|
|
|
if (base == ASE_NULL) base = argv0; else base++;
|
2007-05-26 01:30:00 +00:00
|
|
|
|
2007-06-20 22:29:00 +00:00
|
|
|
ase_printf (ASE_T("Usage: %s [-m main] [-si file]? [-so file]? [-ci file]* [-co file]* [-a arg]* [-w o:n]* \n"), base);
|
2007-05-26 01:30:00 +00:00
|
|
|
ase_printf (ASE_T(" -m main Specify the main function name\n"));
|
|
|
|
ase_printf (ASE_T(" -si file Specify the input source file\n"));
|
|
|
|
ase_printf (ASE_T(" The source code is read from stdin when it is not specified\n"));
|
|
|
|
ase_printf (ASE_T(" -so file Specify the output source file\n"));
|
|
|
|
ase_printf (ASE_T(" The deparsed code is not output when is it not specified\n"));
|
|
|
|
ase_printf (ASE_T(" -ci file Specify the input console file\n"));
|
|
|
|
ase_printf (ASE_T(" -co file Specify the output console file\n"));
|
|
|
|
ase_printf (ASE_T(" -a str Specify an argument\n"));
|
2007-06-20 22:29:00 +00:00
|
|
|
ase_printf (ASE_T(" -w o:n Specify an old and new word pair\n"));
|
|
|
|
ase_printf (ASE_T(" o - an original word\n"));
|
|
|
|
ase_printf (ASE_T(" n - the new word to replace the original\n"));
|
2008-01-01 07:16:29 +00:00
|
|
|
ase_printf (ASE_T(" -v Print extra messages\n"));
|
2007-10-13 01:13:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
ase_printf (ASE_T("\nYou may specify the following options to change the behavior of the interpreter.\n"));
|
|
|
|
for (j = 0; j < ASE_COUNTOF(otab); j++)
|
|
|
|
{
|
|
|
|
ase_printf (ASE_T(" -%-20s -no%-20s\n"), otab[j].name, otab[j].name);
|
|
|
|
}
|
2007-05-15 01:21:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 03:04:38 +00:00
|
|
|
static int awk_main (int argc, ase_char_t* argv[])
|
2007-05-04 00:14:00 +00:00
|
|
|
{
|
2007-05-07 01:05:00 +00:00
|
|
|
TestAwk awk;
|
2008-02-09 03:04:38 +00:00
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
int mode = 0;
|
|
|
|
const ase_char_t* mainfn = NULL;
|
|
|
|
const ase_char_t* srcin = ASE_T("");
|
|
|
|
const ase_char_t* srcout = NULL;
|
|
|
|
const ase_char_t* args[256];
|
|
|
|
ase_size_t nargs = 0;
|
|
|
|
ase_size_t nsrcins = 0;
|
|
|
|
ase_size_t nsrcouts = 0;
|
|
|
|
|
2007-06-20 22:29:00 +00:00
|
|
|
if (awk.open() == -1)
|
|
|
|
{
|
|
|
|
ase_fprintf (stderr, ASE_T("cannot open awk\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (mode == 0)
|
|
|
|
{
|
|
|
|
if (ase_strcmp(argv[i], ASE_T("-si")) == 0) mode = 1;
|
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-so")) == 0) mode = 2;
|
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-ci")) == 0) mode = 3;
|
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-co")) == 0) mode = 4;
|
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-a")) == 0) mode = 5;
|
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-m")) == 0) mode = 6;
|
2007-06-20 22:29:00 +00:00
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-w")) == 0) mode = 7;
|
2008-01-01 07:16:29 +00:00
|
|
|
else if (ase_strcmp(argv[i], ASE_T("-v")) == 0)
|
|
|
|
{
|
|
|
|
verbose = true;
|
|
|
|
}
|
2007-05-15 01:21:00 +00:00
|
|
|
else
|
|
|
|
{
|
2007-10-01 00:12:00 +00:00
|
|
|
if (argv[i][0] == ASE_T('-'))
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (argv[i][1] == ASE_T('n') && argv[i][2] == ASE_T('o'))
|
|
|
|
{
|
|
|
|
for (j = 0; j < ASE_COUNTOF(otab); j++)
|
|
|
|
{
|
|
|
|
if (ase_strcmp(&argv[i][3], otab[j].name) == 0)
|
|
|
|
{
|
|
|
|
awk.setOption (awk.getOption() & ~otab[j].opt);
|
|
|
|
goto ok_valid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = 0; j < ASE_COUNTOF(otab); j++)
|
|
|
|
{
|
|
|
|
if (ase_strcmp(&argv[i][1], otab[j].name) == 0)
|
|
|
|
{
|
|
|
|
awk.setOption (awk.getOption() | otab[j].opt);
|
|
|
|
goto ok_valid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
2007-10-01 00:12:00 +00:00
|
|
|
|
|
|
|
ok_valid:
|
|
|
|
;
|
2007-05-15 01:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (argv[i][0] == ASE_T('-'))
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == 1) // source input
|
|
|
|
{
|
|
|
|
if (nsrcins != 0)
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcin = argv[i];
|
|
|
|
nsrcins++;
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (mode == 2) // source output
|
|
|
|
{
|
|
|
|
if (nsrcouts != 0)
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcout = argv[i];
|
|
|
|
nsrcouts++;
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (mode == 3) // console input
|
|
|
|
{
|
|
|
|
if (awk.addConsoleInput (argv[i]) == -1)
|
|
|
|
{
|
|
|
|
print_error (ASE_T("too many console inputs"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (mode == 4) // console output
|
|
|
|
{
|
|
|
|
if (awk.addConsoleOutput (argv[i]) == -1)
|
|
|
|
{
|
|
|
|
print_error (ASE_T("too many console outputs"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (mode == 5) // argument mode
|
|
|
|
{
|
|
|
|
if (nargs >= ASE_COUNTOF(args))
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
args[nargs++] = argv[i];
|
|
|
|
mode = 0;
|
|
|
|
}
|
2007-06-20 22:29:00 +00:00
|
|
|
else if (mode == 6) // entry point
|
2007-05-15 01:21:00 +00:00
|
|
|
{
|
|
|
|
if (mainfn != NULL)
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mainfn = argv[i];
|
|
|
|
mode = 0;
|
|
|
|
}
|
2007-06-20 22:29:00 +00:00
|
|
|
else if (mode == 7) // word replacement
|
|
|
|
{
|
|
|
|
const ase_char_t* p;
|
|
|
|
ase_size_t l;
|
|
|
|
|
|
|
|
p = ase_strchr(argv[i], ASE_T(':'));
|
|
|
|
if (p == ASE_NULL)
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = ase_strlen (argv[i]);
|
|
|
|
|
|
|
|
awk.setWord (
|
|
|
|
argv[i], p - argv[i],
|
|
|
|
p + 1, l - (p - argv[i] + 1));
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
}
|
2007-05-15 01:21:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != 0)
|
|
|
|
{
|
|
|
|
print_usage (argv[0]);
|
2007-06-20 22:29:00 +00:00
|
|
|
awk.close ();
|
2007-05-15 01:21:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-05-07 01:05:00 +00:00
|
|
|
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
if (awk.parse (srcin, srcout) == -1)
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-21 01:22:00 +00:00
|
|
|
ase_fprintf (stderr, ASE_T("cannot parse: LINE[%d] %s\n"),
|
|
|
|
awk.getErrorLine(), awk.getErrorMessage());
|
2007-06-20 22:29:00 +00:00
|
|
|
awk.close ();
|
2007-05-07 01:05:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-05-21 01:22:00 +00:00
|
|
|
awk.enableRunCallback ();
|
|
|
|
|
2007-05-15 01:21:00 +00:00
|
|
|
if (awk.run (mainfn, args, nargs) == -1)
|
2007-05-07 01:05:00 +00:00
|
|
|
{
|
2007-05-21 01:22:00 +00:00
|
|
|
ase_fprintf (stderr, ASE_T("cannot run: LINE[%d] %s\n"),
|
|
|
|
awk.getErrorLine(), awk.getErrorMessage());
|
2007-06-20 22:29:00 +00:00
|
|
|
awk.close ();
|
2007-05-07 01:05:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-05-04 00:14:00 +00:00
|
|
|
|
2007-06-20 22:29:00 +00:00
|
|
|
awk.close ();
|
2007-05-07 01:05:00 +00:00
|
|
|
return 0;
|
2007-05-04 00:14:00 +00:00
|
|
|
}
|
2007-05-09 00:09:00 +00:00
|
|
|
|
2007-06-18 00:31:00 +00:00
|
|
|
extern "C" int ase_main (int argc, ase_achar_t* argv[])
|
2007-05-09 00:09:00 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
#if defined(__linux) && defined(_DEBUG)
|
|
|
|
mtrace ();
|
|
|
|
#endif
|
2007-06-20 22:29:00 +00:00
|
|
|
#if defined(_WIN32) && defined(_DEBUG) && defined(_MSC_VER)
|
|
|
|
_CrtSetDbgFlag (_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
|
|
|
|
#endif
|
|
|
|
|
2007-05-18 01:21:00 +00:00
|
|
|
n = ase_runmain (argc,argv,awk_main);
|
2007-05-09 00:09:00 +00:00
|
|
|
|
|
|
|
#if defined(__linux) && defined(_DEBUG)
|
|
|
|
muntrace ();
|
|
|
|
#endif
|
|
|
|
#if defined(_WIN32) && defined(_DEBUG)
|
2007-06-20 22:29:00 +00:00
|
|
|
/* #if defined(_MSC_VER)
|
2007-05-09 00:09:00 +00:00
|
|
|
_CrtDumpMemoryLeaks ();
|
2007-06-20 22:29:00 +00:00
|
|
|
#endif */
|
2007-05-09 00:09:00 +00:00
|
|
|
_tprintf (_T("Press ENTER to quit\n"));
|
|
|
|
getchar ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|