Recovered from cvs revision 2007-05-17 03:03:00

This commit is contained in:
hyung-hwan 2007-05-18 01:21:00 +00:00
parent b564cc2d8a
commit a4d7743175
10 changed files with 425 additions and 250 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.29 2007/05/16 06:43:32 bacon Exp $ * $Id: Awk.cpp,v 1.30 2007/05/16 07:13:32 bacon Exp $
*/ */
#include <ase/awk/Awk.hpp> #include <ase/awk/Awk.hpp>
@ -7,9 +7,6 @@
#include <ase/cmn/str.h> #include <ase/cmn/str.h>
#include <ase/cmn/mem.h> #include <ase/cmn/mem.h>
#include <stdio.h>
#include <tchar.h>
namespace ASE namespace ASE
{ {
@ -158,7 +155,7 @@ namespace ASE
} }
} }
void* Awk::Argument::operator new (size_t n, awk_t* awk) void* Awk::Argument::operator new (size_t n, awk_t* awk) throw ()
{ {
void* ptr = ase_awk_malloc (awk, ASE_SIZEOF(awk) + n); void* ptr = ase_awk_malloc (awk, ASE_SIZEOF(awk) + n);
if (ptr == ASE_NULL) return ASE_NULL; if (ptr == ASE_NULL) return ASE_NULL;
@ -167,7 +164,7 @@ namespace ASE
return (char*)ptr+ASE_SIZEOF(awk); return (char*)ptr+ASE_SIZEOF(awk);
} }
void* Awk::Argument::operator new[] (size_t n, awk_t* awk) void* Awk::Argument::operator new[] (size_t n, awk_t* awk) throw ()
{ {
void* ptr = ase_awk_malloc (awk, ASE_SIZEOF(awk) + n); void* ptr = ase_awk_malloc (awk, ASE_SIZEOF(awk) + n);
if (ptr == ASE_NULL) return ASE_NULL; if (ptr == ASE_NULL) return ASE_NULL;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.hpp,v 1.27 2007/05/16 06:43:32 bacon Exp $ * $Id: Awk.hpp,v 1.28 2007/05/16 07:13:32 bacon Exp $
*/ */
#ifndef _ASE_AWK_AWK_HPP_ #ifndef _ASE_AWK_AWK_HPP_
@ -136,8 +136,8 @@ namespace ASE
~Argument (); ~Argument ();
// initialization // initialization
void* operator new (size_t n, awk_t* awk); void* operator new (size_t n, awk_t* awk) throw ();
void* operator new[] (size_t n, awk_t* awk); void* operator new[] (size_t n, awk_t* awk) throw ();
// deletion when initialization fails // deletion when initialization fails
void operator delete (void* p, awk_t* awk); void operator delete (void* p, awk_t* awk);

View File

@ -1,8 +1,11 @@
/* /*
* $Id: StdAwk.cpp,v 1.12 2007/05/13 10:49:32 bacon Exp $ * $Id: StdAwk.cpp,v 1.14 2007/05/16 14:44:13 bacon Exp $
*/ */
#include <ase/awk/StdAwk.hpp> #include <ase/awk/StdAwk.hpp>
#include <ase/cmn/str.h>
#include <ase/utl/stdio.h>
#include <ase/utl/ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
@ -195,4 +198,270 @@ namespace ASE
return n; return n;
#endif #endif
} }
int StdAwk::openPipe (Pipe& io)
{
Awk::Pipe::Mode mode = io.getMode();
FILE* fp = NULL;
switch (mode)
{
case Awk::Pipe::READ:
fp = ase_popen (io.getName(), ASE_T("r"));
break;
case Awk::Pipe::WRITE:
fp = ase_popen (io.getName(), ASE_T("w"));
break;
}
if (fp == NULL) return -1;
io.setHandle (fp);
return 1;
}
int StdAwk::closePipe (Pipe& io)
{
fclose ((FILE*)io.getHandle());
return 0;
}
StdAwk::ssize_t StdAwk::readPipe (Pipe& io, char_t* buf, size_t len)
{
// TODO: change this implementation...
FILE* fp = (FILE*)io.getHandle();
if (ase_fgets (buf, len, fp) == ASE_NULL)
{
if (ferror(fp)) return -1;
return 0;
}
return ase_strlen(buf);
}
StdAwk::ssize_t StdAwk::writePipe (Pipe& 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 defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
if (fputc ('\0', fp) == EOF)
#else
if (ase_fputc (*buf, fp) == ASE_CHAR_EOF)
#endif
{
return -1;
}
left -= 1; buf += 1;
}
else
{
#if defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
// fwprintf seems to return an error with the file
// pointer opened by popen, as of this writing.
// anyway, hopefully the following replacement
// will work all the way.
int n = fprintf (fp, "%.*ls", left, buf);
if (n >= 0)
{
size_t x;
for (x = 0; x < left; x++)
{
if (buf[x] == ASE_T('\0')) break;
}
n = x;
}
#else
int n = ase_fprintf (fp, ASE_T("%.*s"), left, buf);
#endif
if (n < 0 || n > left) return -1;
left -= n; buf += n;
}
}
return len;
}
int StdAwk::flushPipe (Pipe& io)
{
return ::fflush ((FILE*)io.getHandle());
}
// file io handlers
int StdAwk::openFile (File& io)
{
Awk::File::Mode mode = io.getMode();
FILE* fp = NULL;
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 StdAwk::closeFile (File& io)
{
fclose ((FILE*)io.getHandle());
return 0;
}
StdAwk::ssize_t StdAwk::readFile (File& io, char_t* buf, size_t len)
{
// TODO: replace ase_fgets by something else
FILE* fp = (FILE*)io.getHandle();
if (ase_fgets (buf, len, fp) == ASE_NULL)
{
if (ferror(fp)) return -1;
return 0;
}
return ase_strlen(buf);
}
StdAwk::ssize_t StdAwk::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 || n > left) return -1;
left -= n; buf += n;
}
}
return len;
}
int StdAwk::flushFile (File& io)
{
return ::fflush ((FILE*)io.getHandle());
}
// memory allocation primitives
void* StdAwk::allocMem (size_t n)
{
return ::malloc (n);
}
void* StdAwk::reallocMem (void* ptr, size_t n)
{
return ::realloc (ptr, n);
}
void StdAwk::freeMem (void* ptr)
{
::free (ptr);
}
// character class primitives
StdAwk::bool_t StdAwk::isUpper (cint_t c)
{
return ase_isupper (c);
}
StdAwk::bool_t StdAwk::isLower (cint_t c)
{
return ase_islower (c);
}
StdAwk::bool_t StdAwk::isAlpha (cint_t c)
{
return ase_isalpha (c);
}
StdAwk::bool_t StdAwk::isDigit (cint_t c)
{
return ase_isdigit (c);
}
StdAwk::bool_t StdAwk::isXdigit (cint_t c)
{
return ase_isxdigit (c);
}
StdAwk::bool_t StdAwk::isAlnum (cint_t c)
{
return ase_isalnum (c);
}
StdAwk::bool_t StdAwk::isSpace (cint_t c)
{
return ase_isspace (c);
}
StdAwk::bool_t StdAwk::isPrint (cint_t c)
{
return ase_isprint (c);
}
StdAwk::bool_t StdAwk::isGraph (cint_t c)
{
return ase_isgraph (c);
}
StdAwk::bool_t StdAwk::isCntrl (cint_t c)
{
return ase_iscntrl (c);
}
StdAwk::bool_t StdAwk::isPunct (cint_t c)
{
return ase_ispunct (c);
}
StdAwk::cint_t StdAwk::toUpper (cint_t c)
{
return ase_toupper (c);
}
StdAwk::cint_t StdAwk::toLower (cint_t c)
{
return ase_tolower (c);
}
// miscellaneous primitive
StdAwk::real_t StdAwk::pow (real_t x, real_t y)
{
return ::pow (x, y);
}
int StdAwk::vsprintf (
char_t* buf, size_t size, const char_t* fmt, va_list arg)
{
return ase_vsprintf (buf, size, fmt, arg);
}
void StdAwk::vdprintf (const char_t* fmt, va_list arg)
{
ase_vfprintf (stderr, fmt, arg);
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: StdAwk.hpp,v 1.7 2007/05/11 16:25:38 bacon Exp $ * $Id: StdAwk.hpp,v 1.9 2007/05/16 14:44:13 bacon Exp $
*/ */
#ifndef _ASE_AWK_STDAWK_HPP_ #ifndef _ASE_AWK_STDAWK_HPP_
@ -7,7 +7,6 @@
#include <ase/awk/Awk.hpp> #include <ase/awk/Awk.hpp>
namespace ASE namespace ASE
{ {
class StdAwk: public Awk class StdAwk: public Awk
@ -18,6 +17,8 @@ namespace ASE
int open (); int open ();
protected: protected:
// builtin functions
int sin (Return* ret, const Argument* args, size_t nargs); int sin (Return* ret, const Argument* args, size_t nargs);
int cos (Return* ret, const Argument* args, size_t nargs); int cos (Return* ret, const Argument* args, size_t nargs);
int tan (Return* ret, const Argument* args, size_t nargs); int tan (Return* ret, const Argument* args, size_t nargs);
@ -33,6 +34,45 @@ namespace ASE
int strfgmtime (Return* ret, const Argument* args, size_t nargs); int strfgmtime (Return* ret, const Argument* args, size_t nargs);
int system (Return* ret, const Argument* args, size_t nargs); int system (Return* ret, const Argument* args, size_t nargs);
// pipe io handlers
int openPipe (Pipe& io);
int closePipe (Pipe& io);
ssize_t readPipe (Pipe& io, char_t* buf, size_t len);
ssize_t writePipe (Pipe& io, char_t* buf, size_t len);
int flushPipe (Pipe& io);
// file io handlers
int openFile (File& io);
int closeFile (File& io);
ssize_t readFile (File& io, char_t* buf, size_t len);
ssize_t writeFile (File& io, char_t* buf, size_t len);
int flushFile (File& io);
// primitive handlers
void* allocMem (size_t n);
void* reallocMem (void* ptr, size_t n);
void freeMem (void* ptr);
bool_t isUpper (cint_t c);
bool_t isLower (cint_t c);
bool_t isAlpha (cint_t c);
bool_t isDigit (cint_t c);
bool_t isXdigit (cint_t c);
bool_t isAlnum (cint_t c);
bool_t isSpace (cint_t c);
bool_t isPrint (cint_t c);
bool_t isGraph (cint_t c);
bool_t isCntrl (cint_t c);
bool_t isPunct (cint_t c);
cint_t toUpper (cint_t c);
cint_t toLower (cint_t c);
real_t pow (real_t x, real_t y);
int vsprintf (char_t* buf, size_t size,
const char_t* fmt, va_list arg);
void vdprintf (const char_t* fmt, va_list arg);
protected: protected:
unsigned int seed; unsigned int seed;
}; };

View File

@ -8,6 +8,8 @@
* added awk c++ classes (awk/Awk.hpp awk/Awk.cpp awk/StdAwk.hpp awk/StdAwk.cpp) * added awk c++ classes (awk/Awk.hpp awk/Awk.cpp awk/StdAwk.hpp awk/StdAwk.cpp)
* added c++ test program (test/awk/Awk.cpp) * added c++ test program (test/awk/Awk.cpp)
* changed the way to invoke the main function (utl/main.h utl/main.c)
[0.1.0] [0.1.0]
* initial release * initial release

View File

@ -1,11 +1,9 @@
/* /*
* $Id: Awk.cpp,v 1.12 2007/05/14 08:40:13 bacon Exp $ * $Id: Awk.cpp,v 1.15 2007/05/16 14:44:13 bacon Exp $
*/ */
#include <ase/awk/StdAwk.hpp> #include <ase/awk/StdAwk.hpp>
#include <ase/cmn/str.h> #include <ase/cmn/str.h>
#include <ase/utl/ctype.h>
#include <ase/utl/stdio.h> #include <ase/utl/stdio.h>
#include <ase/utl/main.h> #include <ase/utl/main.h>
@ -22,6 +20,9 @@ public:
TestAwk (): srcInName(ASE_NULL), srcOutName(ASE_NULL), TestAwk (): srcInName(ASE_NULL), srcOutName(ASE_NULL),
numConInFiles(0), numConOutFiles(0) numConInFiles(0), numConOutFiles(0)
{ {
#ifdef _WIN32
heap = ASE_NULL;
#endif
} }
~TestAwk () ~TestAwk ()
@ -29,6 +30,30 @@ public:
close (); close ();
} }
int open ()
{
#ifdef _WIN32
ASE_ASSERT (heap == ASE_NULL);
heap = HeapCreate (0, 1000000, 1000000);
if (heap == ASE_NULL) return -1;
#endif
return StdAwk::open ();
}
void close ()
{
StdAwk::close ();
numConInFiles = 0;
numConOutFiles = 0;
#ifdef _WIN32
HeapDestroy (heap);
heap = ASE_NULL;
#endif
}
int addConsoleInput (const char_t* file) int addConsoleInput (const char_t* file)
{ {
if (numConInFiles < ASE_COUNTOF(conInFile)) if (numConInFiles < ASE_COUNTOF(conInFile))
@ -114,13 +139,19 @@ protected:
ssize_t readSource (Source& io, char_t* buf, size_t len) ssize_t readSource (Source& io, char_t* buf, size_t len)
{ {
if (len <= 0) return -1; FILE* fp = (FILE*)io.getHandle();
ssize_t n = 0;
// TOOD: read more characters... while (n < len)
cint_t c = ase_fgetc ((FILE*)io.getHandle()); {
if (c == ASE_CHAR_EOF) return 0; ase_cint_t c = ase_fgetc (fp);
buf[0] = (ase_char_t)c; if (c == ASE_CHAR_EOF) break;
return 1;
buf[n++] = c;
if (c == ASE_T('\n')) break;
}
return n;
} }
ssize_t writeSource (Source& io, char_t* buf, size_t len) ssize_t writeSource (Source& io, char_t* buf, size_t len)
@ -146,164 +177,6 @@ protected:
return len; return len;
} }
// pipe io handlers
int openPipe (Pipe& io)
{
Awk::Pipe::Mode mode = io.getMode();
FILE* fp = NULL;
switch (mode)
{
case Awk::Pipe::READ:
fp = ase_popen (io.getName(), ASE_T("r"));
break;
case Awk::Pipe::WRITE:
fp = ase_popen (io.getName(), ASE_T("w"));
break;
}
if (fp == NULL) return -1;
io.setHandle (fp);
return 1;
}
int closePipe (Pipe& io)
{
fclose ((FILE*)io.getHandle());
return 0;
}
ssize_t readPipe (Pipe& 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 writePipe (Pipe& 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 defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
if (fputc ('\0', fp) == EOF)
#else
if (ase_fputc (*buf, fp) == ASE_CHAR_EOF)
#endif
{
return -1;
}
left -= 1; buf += 1;
}
else
{
#if defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
/* fwprintf seems to return an error with the file
* pointer opened by popen, as of this writing.
* anyway, hopefully the following replacement
* will work all the way. */
int n = fprintf (fp, "%.*ls", left, buf);
if (n >= 0)
{
size_t x;
for (x = 0; x < left; x++)
{
if (buf[x] == ASE_T('\0')) break;
}
n = x;
}
#else
int n = ase_fprintf (fp, ASE_T("%.*s"), left, buf);
#endif
if (n < 0 || n > left) return -1;
left -= n; buf += n;
}
}
return len;
}
int flushPipe (Pipe& io) { return ::fflush ((FILE*)io.getHandle()); }
// file io handlers
int openFile (File& io)
{
Awk::File::Mode mode = io.getMode();
FILE* fp = NULL;
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 || n > left) return -1;
left -= n; buf += n;
}
}
return len;
}
int flushFile (File& io) { return ::fflush ((FILE*)io.getHandle()); }
// console io handlers // console io handlers
int openConsole (Console& io) int openConsole (Console& io)
{ {
@ -373,14 +246,18 @@ protected:
{ {
ConTrack* t = (ConTrack*)io.getHandle(); ConTrack* t = (ConTrack*)io.getHandle();
FILE* fp = t->handle; FILE* fp = t->handle;
ssize_t n = 0;
if (ase_fgets (buf, len, fp) == ASE_NULL) while (n < len)
{ {
if (ferror(fp)) return -1; ase_cint_t c = ase_fgetc (fp);
return 0; if (c == ASE_CHAR_EOF) break;
buf[n++] = c;
if (c == ASE_T('\n')) break;
} }
return ase_strlen(buf); return n;
} }
ssize_t writeConsole (Console& io, char_t* buf, size_t len) ssize_t writeConsole (Console& io, char_t* buf, size_t len)
@ -456,39 +333,34 @@ protected:
return 1; return 1;
} }
void* allocMem (size_t n)
// primitive operations
void* allocMem (size_t n) { return ::malloc (n); }
void* reallocMem (void* ptr, size_t n) { return ::realloc (ptr, n); }
void freeMem (void* ptr) { ::free (ptr); }
bool_t isUpper (cint_t c) { return ase_isupper (c); }
bool_t isLower (cint_t c) { return ase_islower (c); }
bool_t isAlpha (cint_t c) { return ase_isalpha (c); }
bool_t isDigit (cint_t c) { return ase_isdigit (c); }
bool_t isXdigit (cint_t c) { return ase_isxdigit (c); }
bool_t isAlnum (cint_t c) { return ase_isalnum (c); }
bool_t isSpace (cint_t c) { return ase_isspace (c); }
bool_t isPrint (cint_t c) { return ase_isprint (c); }
bool_t isGraph (cint_t c) { return ase_isgraph (c); }
bool_t isCntrl (cint_t c) { return ase_iscntrl (c); }
bool_t isPunct (cint_t c) { return ase_ispunct (c); }
cint_t toUpper (cint_t c) { return ase_toupper (c); }
cint_t toLower (cint_t c) { return ase_tolower (c); }
real_t pow (real_t x, real_t y)
{ {
return ::pow (x, y); #ifdef _WIN32
return ::HeapAlloc (heap, 0, n);
#else
return ::malloc (n);
#endif
} }
int vsprintf (char_t* buf, size_t size, const char_t* fmt, va_list arg) void* reallocMem (void* ptr, size_t n)
{ {
return ase_vsprintf (buf, size, fmt, arg); #ifdef _WIN32
if (ptr == NULL)
return ::HeapAlloc (heap, 0, n);
else
return ::HeapReAlloc (heap, 0, ptr, n);
#else
return ::realloc (ptr, n);
#endif
} }
void vdprintf (const char_t* fmt, va_list arg) void freeMem (void* ptr)
{ {
ase_vfprintf (stderr, fmt, arg); #ifdef _WIN32
::HeapFree (heap, 0, ptr);
#else
::free (ptr);
#endif
} }
private: private:
@ -506,6 +378,10 @@ private:
size_t numConOutFiles; size_t numConOutFiles;
const char_t* conOutFile[128]; const char_t* conOutFile[128];
#ifdef _WIN32
void* heap;
#endif
}; };
#ifndef NDEBUG #ifndef NDEBUG
@ -683,15 +559,16 @@ int awk_main (int argc, ase_char_t* argv[])
return 0; return 0;
} }
extern "C" int ase_main (int argc, ase_char_t* argv[]) int ase_main (int argc, ase_achar_t* argv[])
{ {
int n; int n;
#if defined(__linux) && defined(_DEBUG) #if defined(__linux) && defined(_DEBUG)
mtrace (); mtrace ();
#endif #endif
n = awk_main (argc, argv); n = ase_runmain (argc,argv,awk_main);
#if defined(__linux) && defined(_DEBUG) #if defined(__linux) && defined(_DEBUG)
muntrace (); muntrace ();

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c,v 1.6 2007/05/13 14:57:43 bacon Exp $ * $Id: awk.c,v 1.8 2007/05/16 09:15:14 bacon Exp $
*/ */
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
@ -46,13 +46,6 @@ struct mmgr_data_t
}; };
#endif #endif
#if defined(vms) || defined(__vms)
/* it seems that the main function should be placed in the main object file
* in OpenVMS. otherwise, the first function in the main object file seems
* to become the main function resulting in program start-up failure. */
#include <ase/utl/main.c>
#endif
#ifndef NDEBUG #ifndef NDEBUG
void ase_assert_abort (void) void ase_assert_abort (void)
{ {
@ -1096,7 +1089,7 @@ static int awk_main (int argc, ase_char_t* argv[])
return 0; return 0;
} }
int ase_main (int argc, ase_char_t* argv[]) int ase_main (int argc, ase_achar_t* argv[])
{ {
int n; int n;
@ -1109,7 +1102,7 @@ int ase_main (int argc, ase_char_t* argv[])
#endif #endif
*/ */
n = awk_main (argc, argv); n = ase_runmain (argc, argv, awk_main);
#if defined(__linux) && defined(_DEBUG) #if defined(__linux) && defined(_DEBUG)
muntrace (); muntrace ();

View File

@ -1,5 +1,5 @@
/* /*
* $Id: lsp.c,v 1.3 2007/04/30 08:32:50 bacon Exp $ * $Id: lsp.c,v 1.5 2007/05/16 09:15:14 bacon Exp $
*/ */
#include <ase/lsp/lsp.h> #include <ase/lsp/lsp.h>
@ -25,13 +25,6 @@
#include <mcheck.h> #include <mcheck.h>
#endif #endif
#if defined(vms) || defined(__vms)
/* it seems that the main function should be placed in the main object file
* in OpenVMS. otherwise, the first function in the main object file seems
* to become the main function resulting in program start-up failure. */
#include <ase/utl/main.c>
#endif
#ifndef NDEBUG #ifndef NDEBUG
void ase_assert_abort (void) void ase_assert_abort (void)
{ {
@ -379,7 +372,7 @@ int lsp_main (int argc, ase_char_t* argv[])
return 0; return 0;
} }
int ase_main (int argc, ase_char_t* argv[]) int ase_main (int argc, ase_achar_t* argv[])
{ {
int n; int n;
@ -387,7 +380,7 @@ int ase_main (int argc, ase_char_t* argv[])
mtrace (); mtrace ();
#endif #endif
n = lsp_main (argc, argv); n = ase_runmain (argc, argv, lsp_main);
#if defined(__linux) && defined(_DEBUG) #if defined(__linux) && defined(_DEBUG)
muntrace (); muntrace ();

View File

@ -1,5 +1,5 @@
/* /*
* $Id: main.c,v 1.3 2007/04/30 08:32:50 bacon Exp $ * $Id: main.c,v 1.5 2007/05/16 09:28:33 bacon Exp $
* *
* {License} * {License}
*/ */
@ -10,19 +10,18 @@
#include <string.h> #include <string.h>
#include <locale.h> #include <locale.h>
#if !defined(_WIN32) && defined(ASE_CHAR_IS_MCHAR) #if defined(_WIN32)
int main (int argc, char* argv[], char** envp) int ase_runmain (int argc, ase_achar_t* argv[], int(*mf) (int,ase_char_t*[]))
{ {
setlocale (LC_ALL, ""); return mf (argc, argv);
return ase_main (argc, argv, envp);
} }
#elif !defined(_WIN32) && defined(ASE_CHAR_IS_WCHAR) #elif defined(ASE_CHAR_IS_WCHAR)
#include <wchar.h> #include <wchar.h>
int main (int argc, char* argv[]/*, char** envp*/) int ase_runmain (int argc, ase_achar_t* argv[], int(*mf) (int,ase_char_t*[]))
{ {
int i, ret; int i, ret;
ase_char_t** v; ase_char_t** v;
@ -73,7 +72,8 @@ int main (int argc, char* argv[]/*, char** envp*/)
} }
/* TODO: envp... */ /* TODO: envp... */
ret = ase_main (argc, v, NULL); //ret = mf (argc, v, NULL);
ret = mf (argc, v);
exit_main: exit_main:
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
@ -86,4 +86,3 @@ exit_main:
} }
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: main.h,v 1.4 2007/05/06 08:05:36 bacon Exp $ * $Id: main.h,v 1.5 2007/05/16 09:14:10 bacon Exp $
*/ */
#ifndef _ASE_UTL_MAIN_H_ #ifndef _ASE_UTL_MAIN_H_
@ -9,18 +9,23 @@
#include <ase/cmn/macros.h> #include <ase/cmn/macros.h>
#if defined(_WIN32) #if defined(_WIN32)
#include <tchar.h> #include <tchar.h>
#define ase_main _tmain #define ase_main _tmain
typedef ase_char_t ase_achar_t;
#else #else
#define ase_main main
typedef ase_mchar_t ase_achar_t;
#endif
#ifdef __cplusplus
/*extern "C" { int ase_main (...); }*/
#else
extern int ase_main ();
#endif
#ifdef __cplusplus
extern "C" {
#endif
int ase_runmain (int argc, ase_achar_t* argv[], int(*mf) (int,ase_char_t*[]));
#ifdef __cplusplus
}
#endif #endif
#endif #endif