*** empty log message ***

This commit is contained in:
hyung-hwan 2006-10-24 04:48:52 +00:00
parent ef845392e4
commit 6c99da0073
7 changed files with 196 additions and 209 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h,v 1.133 2006-10-24 04:10:12 bacon Exp $ * $Id: awk.h,v 1.134 2006-10-24 04:48:52 bacon Exp $
*/ */
#ifndef _ASE_AWK_AWK_H_ #ifndef _ASE_AWK_AWK_H_
@ -316,6 +316,14 @@ enum
ASE_AWK_EXTIO_NUM ASE_AWK_EXTIO_NUM
}; };
/* assertion statement */
#ifdef NDEBUG
#define ase_awk_assert(awk,expr) ((void)0)
#else
#define ase_awk_assert(awk,expr) (void)((expr) || \
(ase_awk_assertfail (awk, ASE_T(#expr), ASE_T(__FILE__), __LINE__), 0))
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -411,6 +419,10 @@ ase_char_t* ase_awk_strxnstr (
const ase_char_t* str, ase_size_t strsz, const ase_char_t* str, ase_size_t strsz,
const ase_char_t* sub, ase_size_t subsz); const ase_char_t* sub, ase_size_t subsz);
/* abort function for assertion. use ase_awk_assert instead */
int ase_awk_assertfail (ase_awk_t* awk,
const ase_char_t* expr, const ase_char_t* file, int line);
/* utility functions to convert an error number ot a string */ /* utility functions to convert an error number ot a string */
const ase_char_t* ase_awk_geterrstr (int errnum); const ase_char_t* ase_awk_geterrstr (int errnum);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_i.h,v 1.72 2006-10-24 04:10:12 bacon Exp $ * $Id: awk_i.h,v 1.73 2006-10-24 04:48:52 bacon Exp $
*/ */
#ifndef _ASE_AWK_AWKI_H_ #ifndef _ASE_AWK_AWKI_H_
@ -21,13 +21,6 @@ typedef struct ase_awk_tree_t ase_awk_tree_t;
#include <ase/awk/extio.h> #include <ase/awk/extio.h>
#include <ase/awk/misc.h> #include <ase/awk/misc.h>
#ifdef NDEBUG
#define ase_awk_assert(awk,expr) ((void)0)
#else
#define ase_awk_assert(awk,expr) (void)((expr) || \
(ase_awk_abort(awk, ASE_T(#expr), ASE_T(__FILE__), __LINE__), 0))
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (disable: 4996) #pragma warning (disable: 4996)
#endif #endif

View File

@ -1,17 +1,9 @@
/* /*
* $Id: func.c,v 1.68 2006-10-24 04:10:12 bacon Exp $ * $Id: func.c,v 1.69 2006-10-24 04:48:52 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
#ifdef _WIN32
#include <tchar.h>
#include <math.h>
#else
#include <stdlib.h>
#include <math.h>
#endif
static int __bfn_close (ase_awk_run_t* run); static int __bfn_close (ase_awk_run_t* run);
static int __bfn_fflush (ase_awk_run_t* run); static int __bfn_fflush (ase_awk_run_t* run);
static int __bfn_index (ase_awk_run_t* run); static int __bfn_index (ase_awk_run_t* run);
@ -23,8 +15,6 @@ static int __bfn_toupper (ase_awk_run_t* run);
static int __bfn_gsub (ase_awk_run_t* run); static int __bfn_gsub (ase_awk_run_t* run);
static int __bfn_sub (ase_awk_run_t* run); static int __bfn_sub (ase_awk_run_t* run);
static int __bfn_match (ase_awk_run_t* run); static int __bfn_match (ase_awk_run_t* run);
static int __bfn_system (ase_awk_run_t* run);
/*static int __bfn_sin (ase_awk_run_t* run);*/
/* TODO: move it under the awk structure... */ /* TODO: move it under the awk structure... */
static ase_awk_bfn_t __sys_bfn[] = static ase_awk_bfn_t __sys_bfn[] =
@ -44,10 +34,6 @@ static ase_awk_bfn_t __sys_bfn[] =
{ASE_T("sub"), 3, 0, 2, 3, ASE_T("xvr"), __bfn_sub}, {ASE_T("sub"), 3, 0, 2, 3, ASE_T("xvr"), __bfn_sub},
{ASE_T("match"), 5, 0, 2, 2, ASE_T("vx"), __bfn_match}, {ASE_T("match"), 5, 0, 2, 2, ASE_T("vx"), __bfn_match},
/* TODO: remove these two functions */
{ASE_T("system"), 6, 0, 1, 1, ASE_NULL, __bfn_system},
/*{ ASE_T("sin"), 3, 0, 1, 1, ASE_NULL, __bfn_sin},*/
{ASE_NULL, 0, 0, 0, 0, ASE_NULL, ASE_NULL} {ASE_NULL, 0, 0, 0, 0, ASE_NULL, ASE_NULL}
}; };
@ -1253,6 +1239,7 @@ static int __bfn_match (ase_awk_run_t* run)
return 0; return 0;
} }
#if 0
static int __bfn_system (ase_awk_run_t* run) static int __bfn_system (ase_awk_run_t* run)
{ {
ase_size_t nargs; ase_size_t nargs;
@ -1289,7 +1276,6 @@ static int __bfn_system (ase_awk_run_t* run)
} }
/* math functions */ /* math functions */
#if 0
static int __bfn_sin (ase_awk_run_t* run) static int __bfn_sin (ase_awk_run_t* run)
{ {
ase_size_t nargs; ase_size_t nargs;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: misc.c,v 1.31 2006-10-24 04:10:12 bacon Exp $ * $Id: misc.c,v 1.32 2006-10-24 04:48:52 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
@ -1060,7 +1060,7 @@ exit_loop:
} }
} }
int ase_awk_abort (ase_awk_t* awk, int ase_awk_assertfail (ase_awk_t* awk,
const ase_char_t* expr, const ase_char_t* file, int line) const ase_char_t* expr, const ase_char_t* file, int line)
{ {
awk->syscas.dprintf ( awk->syscas.dprintf (

View File

@ -1,5 +1,5 @@
/* /*
* $Id: misc.h,v 1.7 2006-10-24 04:10:12 bacon Exp $ * $Id: misc.h,v 1.8 2006-10-24 04:48:52 bacon Exp $
*/ */
#ifndef _ASE_AWK_MISC_H_ #ifndef _ASE_AWK_MISC_H_
@ -38,9 +38,6 @@ ase_char_t* ase_awk_strxntokbyrex (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum); void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum);
int ase_awk_abort (ase_awk_t* awk,
const ase_char_t* expr, const ase_char_t* file, int line);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,14 +1,14 @@
/* /*
* $Id: awk.c,v 1.101 2006-10-22 12:39:30 bacon Exp $ * $Id: awk.c,v 1.102 2006-10-24 04:48:52 bacon Exp $
*/ */
#include <sse/awk/awk.h> #include <ase/awk/awk.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef SSE_CHAR_IS_WCHAR #ifdef ASE_CHAR_IS_WCHAR
#include <wchar.h> #include <wchar.h>
#include <wctype.h> #include <wctype.h>
#endif #endif
@ -25,9 +25,9 @@
#include <xp/bas/stdio.h> #include <xp/bas/stdio.h>
#include <limits.h> #include <limits.h>
#ifndef PATH_MAX #ifndef PATH_MAX
#define SSE_PATH_MAX 4096 #define ASE_PATH_MAX 4096
#else #else
#define SSE_PATH_MAX PATH_MAX #define ASE_PATH_MAX PATH_MAX
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
@ -66,7 +66,7 @@ static FILE* fopen_t (const xp_char_t* path, const xp_char_t* mode)
#ifdef _WIN32 #ifdef _WIN32
return _tfopen (path, mode); return _tfopen (path, mode);
#else #else
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
const xp_mchar_t* path_mb; const xp_mchar_t* path_mb;
const xp_mchar_t* mode_mb; const xp_mchar_t* mode_mb;
#else #else
@ -74,14 +74,14 @@ static FILE* fopen_t (const xp_char_t* path, const xp_char_t* mode)
xp_mchar_t mode_mb[32]; xp_mchar_t mode_mb[32];
#endif #endif
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
path_mb = path; path_mb = path;
mode_mb = mode; mode_mb = mode;
#else #else
if (xp_wcstomcs_strict ( if (xp_wcstomcs_strict (
path, path_mb, xp_countof(path_mb)) == -1) return SSE_NULL; path, path_mb, xp_countof(path_mb)) == -1) return ASE_NULL;
if (xp_wcstomcs_strict ( if (xp_wcstomcs_strict (
mode, mode_mb, xp_countof(mode_mb)) == -1) return SSE_NULL; mode, mode_mb, xp_countof(mode_mb)) == -1) return ASE_NULL;
#endif #endif
return fopen (path_mb, mode_mb); return fopen (path_mb, mode_mb);
@ -100,9 +100,9 @@ static int __dprintf (const xp_char_t* fmt, ...)
#ifdef _WIN32 #ifdef _WIN32
n = xp_vsprintf (buf, xp_countof(buf), fmt, ap); n = xp_vsprintf (buf, xp_countof(buf), fmt, ap);
#if defined(_MSC_VER) && (_MSC_VER>=1400) #if defined(_MSC_VER) && (_MSC_VER>=1400)
MessageBox (NULL, buf, SSE_T("\uD655\uC778\uC2E4\uD328 Assertion Failure"), MB_OK | MB_ICONERROR); MessageBox (NULL, buf, ASE_T("\uD655\uC778\uC2E4\uD328 Assertion Failure"), MB_OK | MB_ICONERROR);
#else #else
MessageBox (NULL, buf, SSE_T("Assertion Failure"), MB_OK | MB_ICONERROR); MessageBox (NULL, buf, ASE_T("Assertion Failure"), MB_OK | MB_ICONERROR);
#endif #endif
#else #else
@ -117,7 +117,7 @@ static FILE* popen_t (const xp_char_t* cmd, const xp_char_t* mode)
#ifdef _WIN32 #ifdef _WIN32
return _tpopen (cmd, mode); return _tpopen (cmd, mode);
#else #else
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
const xp_mchar_t* cmd_mb; const xp_mchar_t* cmd_mb;
const xp_mchar_t* mode_mb; const xp_mchar_t* mode_mb;
#else #else
@ -125,14 +125,14 @@ static FILE* popen_t (const xp_char_t* cmd, const xp_char_t* mode)
xp_mchar_t mode_mb[32]; xp_mchar_t mode_mb[32];
#endif #endif
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
cmd_mb = cmd; cmd_mb = cmd;
mode_mb = mode; mode_mb = mode;
#else #else
if (xp_wcstomcs_strict ( if (xp_wcstomcs_strict (
cmd, cmd_mb, xp_countof(cmd_mb)) == -1) return SSE_NULL; cmd, cmd_mb, xp_countof(cmd_mb)) == -1) return ASE_NULL;
if (xp_wcstomcs_strict ( if (xp_wcstomcs_strict (
mode, mode_mb, xp_countof(mode_mb)) == -1) return SSE_NULL; mode, mode_mb, xp_countof(mode_mb)) == -1) return ASE_NULL;
#endif #endif
return popen (cmd_mb, mode_mb); return popen (cmd_mb, mode_mb);
@ -143,7 +143,7 @@ static FILE* popen_t (const xp_char_t* cmd, const xp_char_t* mode)
#define fgets_t _fgetts #define fgets_t _fgetts
#define fputs_t _fputts #define fputs_t _fputts
#else #else
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
#define fgets_t fgets #define fgets_t fgets
#define fputs_t fputs #define fputs_t fputs
#else #else
@ -158,28 +158,28 @@ static xp_ssize_t process_source (
struct src_io* src_io = (struct src_io*)arg; struct src_io* src_io = (struct src_io*)arg;
xp_char_t c; xp_char_t c;
if (cmd == SSE_AWK_IO_OPEN) if (cmd == ASE_AWK_IO_OPEN)
{ {
if (src_io->input_file == SSE_NULL) return 0; if (src_io->input_file == ASE_NULL) return 0;
src_io->input_handle = fopen_t (src_io->input_file, SSE_T("r")); src_io->input_handle = fopen_t (src_io->input_file, ASE_T("r"));
if (src_io->input_handle == NULL) return -1; if (src_io->input_handle == NULL) return -1;
return 1; return 1;
} }
else if (cmd == SSE_AWK_IO_CLOSE) else if (cmd == ASE_AWK_IO_CLOSE)
{ {
if (src_io->input_file == SSE_NULL) return 0; if (src_io->input_file == ASE_NULL) return 0;
fclose ((FILE*)src_io->input_handle); fclose ((FILE*)src_io->input_handle);
return 0; return 0;
} }
else if (cmd == SSE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
if (size <= 0) return -1; if (size <= 0) return -1;
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
c = fgetc ((FILE*)src_io->input_handle); c = fgetc ((FILE*)src_io->input_handle);
#else #else
c = fgetwc ((FILE*)src_io->input_handle); c = fgetwc ((FILE*)src_io->input_handle);
#endif #endif
if (c == SSE_CHAR_EOF) return 0; if (c == ASE_CHAR_EOF) return 0;
*data = c; *data = c;
return 1; return 1;
} }
@ -192,14 +192,14 @@ static xp_ssize_t dump_source (
{ {
/*struct src_io* src_io = (struct src_io*)arg;*/ /*struct src_io* src_io = (struct src_io*)arg;*/
if (cmd == SSE_AWK_IO_OPEN) return 1; if (cmd == ASE_AWK_IO_OPEN) return 1;
else if (cmd == SSE_AWK_IO_CLOSE) return 0; else if (cmd == ASE_AWK_IO_CLOSE) return 0;
else if (cmd == SSE_AWK_IO_WRITE) else if (cmd == ASE_AWK_IO_WRITE)
{ {
xp_size_t i; xp_size_t i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
fputc (data[i], stdout); fputc (data[i], stdout);
#else #else
fputwc (data[i], stdout); fputwc (data[i], stdout);
@ -214,56 +214,56 @@ static xp_ssize_t dump_source (
static xp_ssize_t process_extio_pipe ( static xp_ssize_t process_extio_pipe (
int cmd, void* arg, xp_char_t* data, xp_size_t size) int cmd, void* arg, xp_char_t* data, xp_size_t size)
{ {
sse_awk_extio_t* epa = (sse_awk_extio_t*)arg; ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
switch (cmd) switch (cmd)
{ {
case SSE_AWK_IO_OPEN: case ASE_AWK_IO_OPEN:
{ {
FILE* handle; FILE* handle;
const xp_char_t* mode; const xp_char_t* mode;
if (epa->mode == SSE_AWK_IO_PIPE_READ) if (epa->mode == ASE_AWK_IO_PIPE_READ)
mode = SSE_T("r"); mode = ASE_T("r");
else if (epa->mode == SSE_AWK_IO_PIPE_WRITE) else if (epa->mode == ASE_AWK_IO_PIPE_WRITE)
mode = SSE_T("w"); mode = ASE_T("w");
else return -1; /* TODO: any way to set the error number? */ else return -1; /* TODO: any way to set the error number? */
xp_printf (SSE_TEXT("opending %s of type %d (pipe)\n"), epa->name, epa->type); xp_printf (ASE_TEXT("opending %s of type %d (pipe)\n"), epa->name, epa->type);
handle = popen_t (epa->name, mode); handle = popen_t (epa->name, mode);
if (handle == NULL) return -1; if (handle == NULL) return -1;
epa->handle = (void*)handle; epa->handle = (void*)handle;
return 1; return 1;
} }
case SSE_AWK_IO_CLOSE: case ASE_AWK_IO_CLOSE:
{ {
xp_printf (SSE_TEXT("closing %s of type (pipe) %d\n"), epa->name, epa->type); xp_printf (ASE_TEXT("closing %s of type (pipe) %d\n"), epa->name, epa->type);
fclose ((FILE*)epa->handle); fclose ((FILE*)epa->handle);
epa->handle = NULL; epa->handle = NULL;
return 0; return 0;
} }
case SSE_AWK_IO_READ: case ASE_AWK_IO_READ:
{ {
if (fgets_t (data, size, (FILE*)epa->handle) == SSE_NULL) if (fgets_t (data, size, (FILE*)epa->handle) == ASE_NULL)
return 0; return 0;
return sse_awk_strlen(data); return ase_awk_strlen(data);
} }
case SSE_AWK_IO_WRITE: case ASE_AWK_IO_WRITE:
{ {
/* TODO: size... */ /* TODO: size... */
fputs_t (data, (FILE*)epa->handle); fputs_t (data, (FILE*)epa->handle);
return size; return size;
} }
case SSE_AWK_IO_FLUSH: case ASE_AWK_IO_FLUSH:
{ {
if (epa->mode == SSE_AWK_IO_PIPE_READ) return -1; if (epa->mode == ASE_AWK_IO_PIPE_READ) return -1;
else return 0; else return 0;
} }
case SSE_AWK_IO_NEXT: case ASE_AWK_IO_NEXT:
{ {
return -1; return -1;
} }
@ -275,24 +275,24 @@ xp_printf (SSE_TEXT("closing %s of type (pipe) %d\n"), epa->name, epa->type);
static xp_ssize_t process_extio_file ( static xp_ssize_t process_extio_file (
int cmd, void* arg, xp_char_t* data, xp_size_t size) int cmd, void* arg, xp_char_t* data, xp_size_t size)
{ {
sse_awk_extio_t* epa = (sse_awk_extio_t*)arg; ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
switch (cmd) switch (cmd)
{ {
case SSE_AWK_IO_OPEN: case ASE_AWK_IO_OPEN:
{ {
FILE* handle; FILE* handle;
const xp_char_t* mode; const xp_char_t* mode;
if (epa->mode == SSE_AWK_IO_FILE_READ) if (epa->mode == ASE_AWK_IO_FILE_READ)
mode = SSE_T("r"); mode = ASE_T("r");
else if (epa->mode == SSE_AWK_IO_FILE_WRITE) else if (epa->mode == ASE_AWK_IO_FILE_WRITE)
mode = SSE_T("w"); mode = ASE_T("w");
else if (epa->mode == SSE_AWK_IO_FILE_APPEND) else if (epa->mode == ASE_AWK_IO_FILE_APPEND)
mode = SSE_T("a"); mode = ASE_T("a");
else return -1; /* TODO: any way to set the error number? */ else return -1; /* TODO: any way to set the error number? */
xp_printf (SSE_TEXT("opending %s of type %d (file)\n"), epa->name, epa->type); xp_printf (ASE_TEXT("opending %s of type %d (file)\n"), epa->name, epa->type);
handle = fopen_t (epa->name, mode); handle = fopen_t (epa->name, mode);
if (handle == NULL) return -1; if (handle == NULL) return -1;
@ -300,35 +300,35 @@ xp_printf (SSE_TEXT("opending %s of type %d (file)\n"), epa->name, epa->type);
return 1; return 1;
} }
case SSE_AWK_IO_CLOSE: case ASE_AWK_IO_CLOSE:
{ {
xp_printf (SSE_TEXT("closing %s of type %d (file)\n"), epa->name, epa->type); xp_printf (ASE_TEXT("closing %s of type %d (file)\n"), epa->name, epa->type);
fclose ((FILE*)epa->handle); fclose ((FILE*)epa->handle);
epa->handle = NULL; epa->handle = NULL;
return 0; return 0;
} }
case SSE_AWK_IO_READ: case ASE_AWK_IO_READ:
{ {
if (fgets_t (data, size, (FILE*)epa->handle) == SSE_NULL) if (fgets_t (data, size, (FILE*)epa->handle) == ASE_NULL)
return 0; return 0;
return sse_awk_strlen(data); return ase_awk_strlen(data);
} }
case SSE_AWK_IO_WRITE: case ASE_AWK_IO_WRITE:
{ {
/* TODO: how to return error or 0 */ /* TODO: how to return error or 0 */
fputs_t (data, /*size,*/ (FILE*)epa->handle); fputs_t (data, /*size,*/ (FILE*)epa->handle);
return size; return size;
} }
case SSE_AWK_IO_FLUSH: case ASE_AWK_IO_FLUSH:
{ {
if (fflush ((FILE*)epa->handle) == EOF) return -1; if (fflush ((FILE*)epa->handle) == EOF) return -1;
return 0; return 0;
} }
case SSE_AWK_IO_NEXT: case ASE_AWK_IO_NEXT:
{ {
return -1; return -1;
} }
@ -338,56 +338,56 @@ xp_printf (SSE_TEXT("closing %s of type %d (file)\n"), epa->name, epa->type);
return -1; return -1;
} }
static int open_extio_console (sse_awk_extio_t* epa); static int open_extio_console (ase_awk_extio_t* epa);
static int close_extio_console (sse_awk_extio_t* epa); static int close_extio_console (ase_awk_extio_t* epa);
static int next_extio_console (sse_awk_extio_t* epa); static int next_extio_console (ase_awk_extio_t* epa);
static xp_size_t infile_no = 0; static xp_size_t infile_no = 0;
static const xp_char_t* infiles[10000] = static const xp_char_t* infiles[10000] =
{ {
SSE_T(""), ASE_T(""),
SSE_NULL ASE_NULL
}; };
static xp_ssize_t process_extio_console ( static xp_ssize_t process_extio_console (
int cmd, void* arg, xp_char_t* data, xp_size_t size) int cmd, void* arg, xp_char_t* data, xp_size_t size)
{ {
sse_awk_extio_t* epa = (sse_awk_extio_t*)arg; ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
if (cmd == SSE_AWK_IO_OPEN) if (cmd == ASE_AWK_IO_OPEN)
{ {
return open_extio_console (epa); return open_extio_console (epa);
} }
else if (cmd == SSE_AWK_IO_CLOSE) else if (cmd == ASE_AWK_IO_CLOSE)
{ {
return close_extio_console (epa); return close_extio_console (epa);
} }
else if (cmd == SSE_AWK_IO_READ) else if (cmd == ASE_AWK_IO_READ)
{ {
while (fgets_t (data, size, epa->handle) == SSE_NULL) while (fgets_t (data, size, epa->handle) == ASE_NULL)
{ {
/* it has reached the end of the current file. /* it has reached the end of the current file.
* open the next file if available */ * open the next file if available */
if (infiles[infile_no] == SSE_NULL) if (infiles[infile_no] == ASE_NULL)
{ {
/* no more input console */ /* no more input console */
/* is this correct??? */ /* is this correct??? */
/* /*
if (epa->handle != SSE_NULL && if (epa->handle != ASE_NULL &&
epa->handle != stdin && epa->handle != stdin &&
epa->handle != stdout && epa->handle != stdout &&
epa->handle != stderr) fclose (epa->handle); epa->handle != stderr) fclose (epa->handle);
epa->handle = SSE_NULL; epa->handle = ASE_NULL;
*/ */
return 0; return 0;
} }
if (infiles[infile_no][0] == SSE_T('\0')) if (infiles[infile_no][0] == ASE_T('\0'))
{ {
if (epa->handle != SSE_NULL && if (epa->handle != ASE_NULL &&
epa->handle != stdin && epa->handle != stdin &&
epa->handle != stdout && epa->handle != stdout &&
epa->handle != stderr) fclose (epa->handle); epa->handle != stderr) fclose (epa->handle);
@ -395,40 +395,40 @@ static xp_ssize_t process_extio_console (
} }
else else
{ {
FILE* fp = fopen_t (infiles[infile_no], SSE_T("r")); FILE* fp = fopen_t (infiles[infile_no], ASE_T("r"));
if (fp == SSE_NULL) if (fp == ASE_NULL)
{ {
xp_printf (SSE_TEXT("failed to open the next console of type %x - fopen failure\n"), epa->type); xp_printf (ASE_TEXT("failed to open the next console of type %x - fopen failure\n"), epa->type);
return -1; return -1;
} }
if (epa->handle != SSE_NULL && if (epa->handle != ASE_NULL &&
epa->handle != stdin && epa->handle != stdin &&
epa->handle != stdout && epa->handle != stdout &&
epa->handle != stderr) fclose (epa->handle); epa->handle != stderr) fclose (epa->handle);
xp_printf (SSE_TEXT("open the next console [%s]\n"), infiles[infile_no]); xp_printf (ASE_TEXT("open the next console [%s]\n"), infiles[infile_no]);
epa->handle = fp; epa->handle = fp;
} }
infile_no++; infile_no++;
} }
return sse_awk_strlen(data); return ase_awk_strlen(data);
} }
else if (cmd == SSE_AWK_IO_WRITE) else if (cmd == ASE_AWK_IO_WRITE)
{ {
/* TODO: how to return error or 0 */ /* TODO: how to return error or 0 */
fputs_t (data, /*size,*/ (FILE*)epa->handle); fputs_t (data, /*size,*/ (FILE*)epa->handle);
/*MessageBox (NULL, data, data, MB_OK);*/ /*MessageBox (NULL, data, data, MB_OK);*/
return size; return size;
} }
else if (cmd == SSE_AWK_IO_FLUSH) else if (cmd == ASE_AWK_IO_FLUSH)
{ {
if (fflush ((FILE*)epa->handle) == EOF) return -1; if (fflush ((FILE*)epa->handle) == EOF) return -1;
return 0; return 0;
} }
else if (cmd == SSE_AWK_IO_NEXT) else if (cmd == ASE_AWK_IO_NEXT)
{ {
return next_extio_console (epa); return next_extio_console (epa);
} }
@ -436,44 +436,44 @@ xp_printf (SSE_TEXT("open the next console [%s]\n"), infiles[infile_no]);
return -1; return -1;
} }
static int open_extio_console (sse_awk_extio_t* epa) static int open_extio_console (ase_awk_extio_t* epa)
{ {
/* TODO: OpenConsole in GUI APPLICATION */ /* TODO: OpenConsole in GUI APPLICATION */
/* epa->name is always empty for console */ /* epa->name is always empty for console */
xp_assert (epa->name[0] == SSE_T('\0')); xp_assert (epa->name[0] == ASE_T('\0'));
xp_printf (SSE_TEXT("opening console[%s] of type %x\n"), epa->name, epa->type); xp_printf (ASE_TEXT("opening console[%s] of type %x\n"), epa->name, epa->type);
if (epa->mode == SSE_AWK_IO_CONSOLE_READ) if (epa->mode == ASE_AWK_IO_CONSOLE_READ)
{ {
if (infiles[infile_no] == SSE_NULL) if (infiles[infile_no] == ASE_NULL)
{ {
/* no more input file */ /* no more input file */
xp_printf (SSE_TEXT("console - no more file\n"));; xp_printf (ASE_TEXT("console - no more file\n"));;
return 0; return 0;
} }
if (infiles[infile_no][0] == SSE_T('\0')) if (infiles[infile_no][0] == ASE_T('\0'))
{ {
xp_printf (SSE_T(" console(r) - <standard input>\n")); xp_printf (ASE_T(" console(r) - <standard input>\n"));
epa->handle = stdin; epa->handle = stdin;
} }
else else
{ {
/* a temporary variable fp is used here not to change /* a temporary variable fp is used here not to change
* any fields of epa when the open operation fails */ * any fields of epa when the open operation fails */
FILE* fp = fopen_t (infiles[infile_no], SSE_T("r")); FILE* fp = fopen_t (infiles[infile_no], ASE_T("r"));
if (fp == SSE_NULL) if (fp == ASE_NULL)
{ {
xp_printf (SSE_TEXT("failed to open console of type %x - fopen failure\n"), epa->type); xp_printf (ASE_TEXT("failed to open console of type %x - fopen failure\n"), epa->type);
return -1; return -1;
} }
xp_printf (SSE_T(" console(r) - %s\n"), infiles[infile_no]); xp_printf (ASE_T(" console(r) - %s\n"), infiles[infile_no]);
if (sse_awk_setconsolename ( if (ase_awk_setconsolename (
epa->run, infiles[infile_no], epa->run, infiles[infile_no],
sse_awk_strlen(infiles[infile_no])) == -1) ase_awk_strlen(infiles[infile_no])) == -1)
{ {
fclose (fp); fclose (fp);
return -1; return -1;
@ -485,11 +485,11 @@ xp_printf (SSE_T(" console(r) - %s\n"), infiles[infile_no]);
infile_no++; infile_no++;
return 1; return 1;
} }
else if (epa->mode == SSE_AWK_IO_CONSOLE_WRITE) else if (epa->mode == ASE_AWK_IO_CONSOLE_WRITE)
{ {
xp_printf (SSE_T(" console(w) - <standard output>\n")); xp_printf (ASE_T(" console(w) - <standard output>\n"));
/* TODO: does output console has a name??? */ /* TODO: does output console has a name??? */
/*sse_awk_setconsolename (SSE_T(""));*/ /*ase_awk_setconsolename (ASE_T(""));*/
epa->handle = stdout; epa->handle = stdout;
return 1; return 1;
} }
@ -497,11 +497,11 @@ xp_printf (SSE_T(" console(w) - <standard output>\n"));
return -1; return -1;
} }
static int close_extio_console (sse_awk_extio_t* epa) static int close_extio_console (ase_awk_extio_t* epa)
{ {
xp_printf (SSE_TEXT("closing console of type %x\n"), epa->type); xp_printf (ASE_TEXT("closing console of type %x\n"), epa->type);
if (epa->handle != SSE_NULL && if (epa->handle != ASE_NULL &&
epa->handle != stdin && epa->handle != stdin &&
epa->handle != stdout && epa->handle != stdout &&
epa->handle != stderr) epa->handle != stderr)
@ -513,11 +513,11 @@ xp_printf (SSE_TEXT("closing console of type %x\n"), epa->type);
return 0; return 0;
} }
static int next_extio_console (sse_awk_extio_t* epa) static int next_extio_console (ase_awk_extio_t* epa)
{ {
int n; int n;
FILE* fp = epa->handle; FILE* fp = epa->handle;
xp_printf (SSE_TEXT("switching console[%s] of type %x\n"), epa->name, epa->type); xp_printf (ASE_TEXT("switching console[%s] of type %x\n"), epa->name, epa->type);
n = open_extio_console(epa); n = open_extio_console(epa);
if (n == -1) return -1; if (n == -1) return -1;
@ -528,14 +528,14 @@ xp_printf (SSE_TEXT("switching console[%s] of type %x\n"), epa->name, epa->type)
return 0; return 0;
} }
if (fp != SSE_NULL && fp != stdin && if (fp != ASE_NULL && fp != stdin &&
fp != stdout && fp != stderr) fclose (fp); fp != stdout && fp != stderr) fclose (fp);
return n; return n;
} }
sse_awk_t* app_awk = NULL; ase_awk_t* app_awk = NULL;
void* app_run = NULL; void* app_run = NULL;
#ifdef _WIN32 #ifdef _WIN32
@ -544,7 +544,7 @@ static BOOL WINAPI __stop_run (DWORD ctrl_type)
if (ctrl_type == CTRL_C_EVENT || if (ctrl_type == CTRL_C_EVENT ||
ctrl_type == CTRL_CLOSE_EVENT) ctrl_type == CTRL_CLOSE_EVENT)
{ {
sse_awk_stop (app_awk, app_run); ase_awk_stop (app_awk, app_run);
return TRUE; return TRUE;
} }
@ -554,27 +554,27 @@ static BOOL WINAPI __stop_run (DWORD ctrl_type)
static void __stop_run (int sig) static void __stop_run (int sig)
{ {
signal (SIGINT, SIG_IGN); signal (SIGINT, SIG_IGN);
sse_awk_stop (app_awk, app_run); ase_awk_stop (app_awk, app_run);
//sse_awk_stoprun (awk, handle); //ase_awk_stoprun (awk, handle);
/*sse_awk_stopallruns (awk); */ /*ase_awk_stopallruns (awk); */
signal (SIGINT, __stop_run); signal (SIGINT, __stop_run);
} }
#endif #endif
static void __on_run_start (sse_awk_t* awk, void* handle, void* arg) static void __on_run_start (ase_awk_t* awk, void* handle, void* arg)
{ {
app_awk = awk; app_awk = awk;
app_run = handle; app_run = handle;
xp_printf (SSE_T("AWK PRORAM ABOUT TO START...\n")); xp_printf (ASE_T("AWK PRORAM ABOUT TO START...\n"));
} }
static void __on_run_end (sse_awk_t* awk, void* handle, int errnum, void* arg) static void __on_run_end (ase_awk_t* awk, void* handle, int errnum, void* arg)
{ {
if (errnum != SSE_AWK_ENOERR) if (errnum != ASE_AWK_ENOERR)
{ {
xp_printf (SSE_T("AWK PRORAM ABOUT TO END WITH AN ERROR - %d - %s\n"), errnum, sse_awk_geterrstr (errnum)); xp_printf (ASE_T("AWK PRORAM ABOUT TO END WITH AN ERROR - %d - %s\n"), errnum, ase_awk_geterrstr (errnum));
} }
else xp_printf (SSE_T("AWK PRORAM ENDED SUCCESSFULLY\n")); else xp_printf (ASE_T("AWK PRORAM ENDED SUCCESSFULLY\n"));
app_awk = NULL; app_awk = NULL;
app_run = NULL; app_run = NULL;
@ -625,27 +625,27 @@ static int __main (int argc, char* argv[])
static int __main (int argc, xp_char_t* argv[]) static int __main (int argc, xp_char_t* argv[])
#endif #endif
{ {
sse_awk_t* awk; ase_awk_t* awk;
sse_awk_srcios_t srcios; ase_awk_srcios_t srcios;
sse_awk_runcbs_t runcbs; ase_awk_runcbs_t runcbs;
sse_awk_runios_t runios; ase_awk_runios_t runios;
sse_awk_runarg_t runarg[10]; ase_awk_runarg_t runarg[10];
sse_awk_syscas_t syscas; ase_awk_syscas_t syscas;
struct src_io src_io = { NULL, NULL }; struct src_io src_io = { NULL, NULL };
int opt, i, file_count = 0; int opt, i, file_count = 0;
#ifdef _WIN32 #ifdef _WIN32
syscas_data_t syscas_data; syscas_data_t syscas_data;
#endif #endif
opt = SSE_AWK_EXPLICIT | SSE_AWK_UNIQUE | SSE_AWK_HASHSIGN | opt = ASE_AWK_EXPLICIT | ASE_AWK_UNIQUE | ASE_AWK_HASHSIGN |
/*SSE_AWK_DBLSLASHES |*/ /*ASE_AWK_DBLSLASHES |*/
SSE_AWK_SHADING | SSE_AWK_IMPLICIT | SSE_AWK_SHIFT | ASE_AWK_SHADING | ASE_AWK_IMPLICIT | ASE_AWK_SHIFT |
SSE_AWK_EXTIO | SSE_AWK_BLOCKLESS | SSE_AWK_STRINDEXONE | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_STRINDEXONE |
SSE_AWK_STRIPSPACES | SSE_AWK_NEWLINE; ASE_AWK_STRIPSPACES | ASE_AWK_NEWLINE;
if (argc <= 1) if (argc <= 1)
{ {
xp_printf (SSE_T("Usage: %s [-m] source_file [data_file ...]\n"), argv[0]); xp_printf (ASE_T("Usage: %s [-m] source_file [data_file ...]\n"), argv[0]);
return -1; return -1;
} }
@ -654,10 +654,10 @@ static int __main (int argc, xp_char_t* argv[])
#if defined(__STAND_ALONE) && !defined(_WIN32) #if defined(__STAND_ALONE) && !defined(_WIN32)
if (strcmp(argv[i], "-m") == 0) if (strcmp(argv[i], "-m") == 0)
#else #else
if (sse_awk_strcmp(argv[i], SSE_T("-m")) == 0) if (ase_awk_strcmp(argv[i], ASE_T("-m")) == 0)
#endif #endif
{ {
opt |= SSE_AWK_RUNMAIN; opt |= ASE_AWK_RUNMAIN;
} }
else if (file_count == 0) else if (file_count == 0)
{ {
@ -667,12 +667,12 @@ static int __main (int argc, xp_char_t* argv[])
else if (file_count >= 1 && file_count < xp_countof(infiles)-1) else if (file_count >= 1 && file_count < xp_countof(infiles)-1)
{ {
infiles[file_count-1] = argv[i]; infiles[file_count-1] = argv[i];
infiles[file_count] = SSE_NULL; infiles[file_count] = ASE_NULL;
file_count++; file_count++;
} }
else else
{ {
xp_printf (SSE_T("Usage: %s [-m] [-f source_file] [data_file ...]\n"), argv[0]); xp_printf (ASE_T("Usage: %s [-m] [-f source_file] [data_file ...]\n"), argv[0]);
return -1; return -1;
} }
} }
@ -685,7 +685,7 @@ static int __main (int argc, xp_char_t* argv[])
syscas.lock = NULL; syscas.lock = NULL;
syscas.unlock = NULL; syscas.unlock = NULL;
#ifdef SSE_CHAR_IS_MCHAR #ifdef ASE_CHAR_IS_MCHAR
syscas.is_upper = isupper; syscas.is_upper = isupper;
syscas.is_lower = islower; syscas.is_lower = islower;
syscas.is_alpha = isalpha; syscas.is_alpha = isalpha;
@ -724,43 +724,43 @@ static int __main (int argc, xp_char_t* argv[])
syscas_data.heap = HeapCreate (0, 1000000, 1000000); syscas_data.heap = HeapCreate (0, 1000000, 1000000);
if (syscas_data.heap == NULL) if (syscas_data.heap == NULL)
{ {
xp_printf (SSE_T("Error: cannot create an awk heap\n")); xp_printf (ASE_T("Error: cannot create an awk heap\n"));
return -1; return -1;
} }
syscas.custom_data = &syscas_data; syscas.custom_data = &syscas_data;
#endif #endif
if ((awk = sse_awk_open(&syscas)) == SSE_NULL) if ((awk = ase_awk_open(&syscas)) == ASE_NULL)
{ {
#ifdef _WIN32 #ifdef _WIN32
HeapDestroy (syscas_data.heap); HeapDestroy (syscas_data.heap);
#endif #endif
xp_printf (SSE_T("Error: cannot open awk\n")); xp_printf (ASE_T("Error: cannot open awk\n"));
return -1; return -1;
} }
sse_awk_setopt (awk, opt); ase_awk_setopt (awk, opt);
srcios.in = process_source; srcios.in = process_source;
srcios.out = dump_source; srcios.out = dump_source;
srcios.custom_data = &src_io; srcios.custom_data = &src_io;
if (sse_awk_parse (awk, &srcios) == -1) if (ase_awk_parse (awk, &srcios) == -1)
{ {
int errnum = sse_awk_geterrnum(awk); int errnum = ase_awk_geterrnum(awk);
#if defined(__STAND_ALONE) && !defined(_WIN32) && defined(SSE_CHAR_IS_WCHAR) #if defined(__STAND_ALONE) && !defined(_WIN32) && defined(ASE_CHAR_IS_WCHAR)
xp_printf ( xp_printf (
SSE_T("ERROR: cannot parse program - line %u [%d] %ls\n"), ASE_T("ERROR: cannot parse program - line %u [%d] %ls\n"),
(unsigned int)sse_awk_getsrcline(awk), (unsigned int)ase_awk_getsrcline(awk),
errnum, sse_awk_geterrstr(errnum)); errnum, ase_awk_geterrstr(errnum));
#else #else
xp_printf ( xp_printf (
SSE_T("ERROR: cannot parse program - line %u [%d] %s\n"), ASE_T("ERROR: cannot parse program - line %u [%d] %s\n"),
(unsigned int)sse_awk_getsrcline(awk), (unsigned int)ase_awk_getsrcline(awk),
errnum, sse_awk_geterrstr(errnum)); errnum, ase_awk_geterrstr(errnum));
#endif #endif
sse_awk_close (awk); ase_awk_close (awk);
return -1; return -1;
} }
@ -771,41 +771,41 @@ static int __main (int argc, xp_char_t* argv[])
#endif #endif
runios.pipe = process_extio_pipe; runios.pipe = process_extio_pipe;
runios.coproc = SSE_NULL; runios.coproc = ASE_NULL;
runios.file = process_extio_file; runios.file = process_extio_file;
runios.console = process_extio_console; runios.console = process_extio_console;
runcbs.on_start = __on_run_start; runcbs.on_start = __on_run_start;
runcbs.on_end = __on_run_end; runcbs.on_end = __on_run_end;
runcbs.custom_data = SSE_NULL; runcbs.custom_data = ASE_NULL;
runarg[0].ptr = SSE_T("argument 0"); runarg[0].ptr = ASE_T("argument 0");
runarg[0].len = sse_awk_strlen(runarg[0].ptr); runarg[0].len = ase_awk_strlen(runarg[0].ptr);
runarg[1].ptr = SSE_T("argumetn 1"); runarg[1].ptr = ASE_T("argumetn 1");
runarg[1].len = sse_awk_strlen(runarg[1].ptr); runarg[1].len = ase_awk_strlen(runarg[1].ptr);
runarg[2].ptr = SSE_T("argumetn 2"); runarg[2].ptr = ASE_T("argumetn 2");
runarg[2].len = sse_awk_strlen(runarg[2].ptr); runarg[2].len = ase_awk_strlen(runarg[2].ptr);
runarg[3].ptr = SSE_NULL; runarg[3].ptr = ASE_NULL;
runarg[3].len = 0; runarg[3].len = 0;
if (sse_awk_run (awk, &runios, &runcbs, runarg) == -1) if (ase_awk_run (awk, &runios, &runcbs, runarg) == -1)
{ {
int errnum = sse_awk_geterrnum(awk); int errnum = ase_awk_geterrnum(awk);
#if defined(__STAND_ALONE) && !defined(_WIN32) && defined(SSE_CHAR_IS_WCHAR) #if defined(__STAND_ALONE) && !defined(_WIN32) && defined(ASE_CHAR_IS_WCHAR)
xp_printf ( xp_printf (
SSE_T("error: cannot run program - [%d] %ls\n"), ASE_T("error: cannot run program - [%d] %ls\n"),
errnum, sse_awk_geterrstr(errnum)); errnum, ase_awk_geterrstr(errnum));
#else #else
xp_printf ( xp_printf (
SSE_T("error: cannot run program - [%d] %s\n"), ASE_T("error: cannot run program - [%d] %s\n"),
errnum, sse_awk_geterrstr(errnum)); errnum, ase_awk_geterrstr(errnum));
#endif #endif
sse_awk_close (awk); ase_awk_close (awk);
return -1; return -1;
} }
sse_awk_close (awk); ase_awk_close (awk);
#ifdef _WIN32 #ifdef _WIN32
HeapDestroy (syscas_data.heap); HeapDestroy (syscas_data.heap);
#endif #endif
@ -994,25 +994,25 @@ int xp_main (int argc, xp_char_t* argv[])
{ {
xp_char_t buf[xp_sizeof(xp_long_t)*8+2+2]; xp_char_t buf[xp_sizeof(xp_long_t)*8+2+2];
xp_size_t n; xp_size_t n;
n = sse_awk_longtostr (-0x7FFFFFFFFFFFFFFFi64, 16, SSE_T("0x"), buf, xp_countof(buf)); n = ase_awk_longtostr (-0x7FFFFFFFFFFFFFFFi64, 16, ASE_T("0x"), buf, xp_countof(buf));
if (n == (xp_size_t)-1) if (n == (xp_size_t)-1)
{ {
xp_printf (SSE_T("cannot convert...\n")); xp_printf (ASE_T("cannot convert...\n"));
} }
else xp_printf (SSE_T("%d, %s\n"), n, buf); else xp_printf (ASE_T("%d, %s\n"), n, buf);
} }
if (IsDebuggerPresent ()) if (IsDebuggerPresent ())
{ {
xp_printf (SSE_T("Running application in a debugger....\n")); xp_printf (ASE_T("Running application in a debugger....\n"));
} }
if (is_debugger_present ()) if (is_debugger_present ())
{ {
xp_printf (SSE_T("Running application in a debugger by is_debugger_present...\n")); xp_printf (ASE_T("Running application in a debugger by is_debugger_present...\n"));
} }
if (is_debugger_present2 ()) if (is_debugger_present2 ())
{ {
xp_printf (SSE_T("Running application in a debugger by is_debugger_present2...\n")); xp_printf (ASE_T("Running application in a debugger by is_debugger_present2...\n"));
} }
#endif #endif

View File

@ -1,8 +1,7 @@
CC = cl CC = cl
#CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. CFLAGS = /nologo /MT /W3 /GR- -I..\..\.. -I$(XPKIT) -D_WIN32_WINNT=0x0400 -D__STAND_ALONE
CFLAGS = /nologo /MT /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. -D__STAND_ALONE LDFLAGS = /libpath:..\..\awk /libpath:$(XPKIT)\xp\bas
LDFLAGS = /libpath:..\..\bas /libpath:..\..\awk LIBS = aseawk.lib xpbas.lib kernel32.lib user32.lib
LIBS = xpbas.lib xpawk.lib user32.lib
all: awk #rex2 rex3 all: awk #rex2 rex3