deleted the isnil operator and added the backquote operator to mean notnil

This commit is contained in:
hyung-hwan 2012-12-19 14:11:07 +00:00
parent 092a8106b2
commit 0dc6c0863e
10 changed files with 113 additions and 92 deletions

View File

@ -50,12 +50,6 @@
#define qse_fputc(x,s) fputwc(x,s)
#endif
#define qse_feof(s) feof(s)
#define qse_ferror(s) ferror(s)
#define qse_clearerr(s) clearerr(s)
#define qse_fflush(s) fflush(s)
#define qse_fclose(s) fclose(s)
#define QSE_FILE FILE
#define QSE_STDIN stdin
#define QSE_STDOUT stdout
@ -71,7 +65,7 @@ QSE_EXPORT int qse_vsprintf (
qse_char_t* buf,
qse_size_t size,
const qse_char_t* fmt,
va_list ap
va_list ap
);
QSE_EXPORT int qse_sprintf (
@ -94,8 +88,12 @@ QSE_EXPORT int qse_dprintf (
const qse_char_t* fmt, ...);
QSE_EXPORT QSE_FILE* qse_fopen (
const qse_char_t* path, const qse_char_t* mode);
QSE_EXPORT QSE_FILE* qse_popen (
const qse_char_t* cmd, const qse_char_t* mode);
QSE_EXPORT void qse_fclose (QSE_FILE* fp);
QSE_EXPORT int qse_fflush (QSE_FILE* fp);
QSE_EXPORT void qse_clearerr (QSE_FILE* fp);
QSE_EXPORT int qse_feof (QSE_FILE* fp);
QSE_EXPORT int qse_ferror (QSE_FILE* fp);
/**
* The qse_getline() function read a line from a file pointer @a fp

View File

@ -509,7 +509,13 @@ typedef int qse_mcint_t;
* The qse_wcint_t type defines a type that can hold a qse_wchar_t value and
* #QSE_WCHAR_EOF.
*/
#if defined(__cplusplus) && !( \
#if defined(__cplusplus) && (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
/* WATCOM C++ before OpenWatcom */
typedef long char qse_wchar_t;
typedef long char qse_wcint_t;
#elif defined(__cplusplus) && !( \
(defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) || \
(defined(__WATCOMC__) && (__WATCOMC__ < 1200)) || \
defined(_SCO_DS) \

View File

@ -69,8 +69,8 @@ enum tok_t
TOK_GT,
TOK_MA, /* match */
TOK_NM, /* not match */
TOK_ND, /* not defined, is-nil */
TOK_LNOT, /* logical negation ! */
TOK_BQUOTE, /* ` */
TOK_PLUS,
TOK_PLUSPLUS,
TOK_MINUS,
@ -3730,7 +3730,7 @@ static qse_awk_nde_t* parse_concat (qse_awk_t* awk, const qse_awk_loc_t* xloc)
/* unary operators */
MATCH(awk,TOK_PLUS) || MATCH(awk,TOK_MINUS) ||
MATCH(awk,TOK_LNOT) || MATCH(awk,TOK_BNOT) ||
MATCH(awk,TOK_ND) ||
MATCH(awk,TOK_COLON) ||
/* increment operators */
MATCH(awk,TOK_PLUSPLUS) || MATCH(awk,TOK_MINUSMINUS) ||
((awk->opt.trait & QSE_AWK_TOLERANT) &&
@ -3801,7 +3801,7 @@ static qse_awk_nde_t* parse_unary (qse_awk_t* awk, const qse_awk_loc_t* xloc)
(MATCH(awk,TOK_MINUS))? QSE_AWK_UNROP_MINUS:
(MATCH(awk,TOK_LNOT))? QSE_AWK_UNROP_LNOT:
(MATCH(awk,TOK_BNOT))? QSE_AWK_UNROP_BNOT:
(MATCH(awk,TOK_ND))? QSE_AWK_UNROP_ND: -1;
(MATCH(awk,TOK_BQUOTE))? QSE_AWK_UNROP_DEF: -1;
/*if (opcode <= -1) return parse_increment (awk);*/
if (opcode <= -1) return parse_exponent (awk, xloc);
@ -3949,7 +3949,7 @@ static qse_awk_nde_t* parse_unary_exp (qse_awk_t* awk, const qse_awk_loc_t* xloc
(MATCH(awk,TOK_MINUS))? QSE_AWK_UNROP_MINUS:
(MATCH(awk,TOK_LNOT))? QSE_AWK_UNROP_LNOT:
(MATCH(awk,TOK_BNOT))? QSE_AWK_UNROP_BNOT:
(MATCH(awk,TOK_ND))? QSE_AWK_UNROP_ND: -1;
(MATCH(awk,TOK_BQUOTE))? QSE_AWK_UNROP_DEF: -1;
if (opcode <= -1) return parse_increment (awk, xloc);
@ -5760,7 +5760,6 @@ static int get_symbols (qse_awk_t* awk, qse_cint_t c, qse_awk_tok_t* tok)
{ QSE_T("!=="), 3, TOK_TNE, 0 },
{ QSE_T("!="), 2, TOK_NE, 0 },
{ QSE_T("!~"), 2, TOK_NM, 0 },
{ QSE_T("!:"), 2, TOK_ND, 0 },
{ QSE_T("!"), 1, TOK_LNOT, 0 },
{ QSE_T(">>="), 3, TOK_RS_ASSN, 0 },
{ QSE_T(">>"), 2, TOK_RS, 0 },
@ -5813,6 +5812,7 @@ static int get_symbols (qse_awk_t* awk, qse_cint_t c, qse_awk_tok_t* tok)
{ QSE_T(":"), 1, TOK_COLON, 0 },
{ QSE_T("?"), 1, TOK_QUEST, 0 },
{ QSE_T("@"), 1, TOK_ATSIGN, 0 },
{ QSE_T("`"), 1, TOK_BQUOTE, 0 },
{ QSE_NULL, 0, 0, 0 }
};

View File

@ -5038,7 +5038,7 @@ static qse_awk_val_t* eval_unary (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
exp->opcode == QSE_AWK_UNROP_MINUS ||
exp->opcode == QSE_AWK_UNROP_LNOT ||
exp->opcode == QSE_AWK_UNROP_BNOT ||
exp->opcode == QSE_AWK_UNROP_ND);
exp->opcode == QSE_AWK_UNROP_DEF);
QSE_ASSERT (exp->left->next == QSE_NULL);
left = eval_expression (run, exp->left);
@ -5087,9 +5087,9 @@ static qse_awk_val_t* eval_unary (qse_awk_rtx_t* run, qse_awk_nde_t* nde)
qse_awk_rtx_makefltval (run, r);
break;
case QSE_AWK_UNROP_ND:
case QSE_AWK_UNROP_DEF:
res = qse_awk_rtx_makeintval (
run, ((left->type == QSE_AWK_VAL_NIL)? 1: 0));
run, ((left->type == QSE_AWK_VAL_NIL)? 0: 1));
break;
}

View File

@ -91,7 +91,7 @@ enum qse_awk_unrop_type_t
QSE_AWK_UNROP_MINUS,
QSE_AWK_UNROP_LNOT,
QSE_AWK_UNROP_BNOT,
QSE_AWK_UNROP_ND
QSE_AWK_UNROP_DEF /* : in the unary operation context */
};
enum qse_awk_incop_type_t

View File

@ -81,7 +81,7 @@ static const qse_char_t* unrop_str[] =
QSE_T("-"),
QSE_T("!"),
QSE_T("~~"),
QSE_T("!:")
QSE_T("`")
};
static const qse_char_t* incop_str[] =

View File

@ -36,7 +36,7 @@ void* Mmgr::realloc_mem (void* ctx, void* ptr, size_t n)
void Mmgr::free_mem (void* ctx, void* ptr)
{
return ((Mmgr*)ctx)->freeMem (ptr);
((Mmgr*)ctx)->freeMem (ptr);
}
/////////////////////////////////

View File

@ -38,7 +38,7 @@ void* StdMmgr::reallocMem (void* ptr, size_t n)
void StdMmgr::freeMem (void* ptr)
{
return ::free (ptr);
::free (ptr);
}
StdMmgr* StdMmgr::getDFL ()

View File

@ -52,17 +52,40 @@ int qse_vfprintf (QSE_FILE *stream, const qse_char_t* fmt, va_list ap)
int qse_vprintf (const qse_char_t* fmt, va_list ap)
{
return qse_vfprintf (stdout, fmt, ap);
int n;
qse_char_t* nf;
nf = __adjust_format (fmt);
if (nf == NULL) return -1;
#if defined(QSE_CHAR_IS_MCHAR)
n = vfprintf (QSE_STDOUT, nf, ap);
#else
n = vfwprintf (QSE_STDOUT, nf, ap);
#endif
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), nf);
return n;
}
int qse_fprintf (QSE_FILE* file, const qse_char_t* fmt, ...)
{
int n;
va_list ap;
qse_char_t* nf;
nf = __adjust_format (fmt);
if (nf == NULL) return -1;
va_start (ap, fmt);
n = qse_vfprintf (file, fmt, ap);
#if defined(QSE_CHAR_IS_MCHAR)
n = vfprintf (file, nf, ap);
#else
n = vfwprintf (file, nf, ap);
#endif
va_end (ap);
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), nf);
return n;
}
@ -70,10 +93,41 @@ int qse_printf (const qse_char_t* fmt, ...)
{
int n;
va_list ap;
qse_char_t* nf;
nf = __adjust_format (fmt);
if (nf == NULL) return -1;
va_start (ap, fmt);
n = qse_vfprintf (QSE_STDOUT, fmt, ap);
#if defined(QSE_CHAR_IS_MCHAR)
n = vfprintf (QSE_STDOUT, nf, ap);
#else
n = vfwprintf (QSE_STDOUT, nf, ap);
#endif
va_end (ap);
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), nf);
return n;
}
int qse_dprintf (const qse_char_t* fmt, ...)
{
int n;
va_list ap;
qse_char_t* nf;
nf = __adjust_format (fmt);
if (nf == NULL) return -1;
va_start (ap, fmt);
#if defined(QSE_CHAR_IS_MCHAR)
n = vfprintf (QSE_STDERR, nf, ap);
#else
n = vfwprintf (QSE_STDOUT, nf, ap);
#endif
va_end (ap);
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), nf);
return n;
}
@ -83,19 +137,19 @@ int qse_vsprintf (qse_char_t* buf, qse_size_t size, const qse_char_t* fmt, va_li
qse_char_t* nf = __adjust_format (fmt);
if (nf == NULL) return -1;
#if defined(QSE_CHAR_IS_MCHAR)
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
n = _vsnprintf (buf, size, nf, ap);
#else
n = vsnprintf (buf, size, nf, ap);
#endif
#if defined(QSE_CHAR_IS_MCHAR)
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
n = _vsnprintf (buf, size, nf, ap);
#else
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
n = _vsnwprintf (buf, size, nf, ap);
#else
n = vswprintf (buf, size, nf, ap);
#endif
n = vsnprintf (buf, size, nf, ap);
#endif
#else
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
n = _vsnwprintf (buf, size, nf, ap);
#else
n = vswprintf (buf, size, nf, ap);
#endif
#endif
if (n < 0 || (size_t)n >= size)
{
@ -368,16 +422,6 @@ done:
return buf.ptr;
}
int qse_dprintf (const qse_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = qse_vfprintf (QSE_STDERR, fmt, ap);
va_end (ap);
return n;
}
QSE_FILE* qse_fopen (const qse_char_t* path, const qse_char_t* mode)
{
@ -407,56 +451,29 @@ QSE_FILE* qse_fopen (const qse_char_t* path, const qse_char_t* mode)
#endif
}
QSE_FILE* qse_popen (const qse_char_t* cmd, const qse_char_t* mode)
void qse_fclose (QSE_FILE* fp)
{
#if defined(QSE_CHAR_IS_MCHAR)
fclose (fp);
}
#if defined(__OS2__)
return _popen (cmd, mode);
#elif defined(__DOS__)
return QSE_NULL;
#else
return popen (cmd, mode);
#endif
int qse_fflush (QSE_FILE* fp)
{
return fflush (fp);
}
#elif defined(_WIN32) || defined(__OS2__)
return _wpopen (cmd, mode);
void qse_clearerr (QSE_FILE* fp)
{
clearerr (fp);
}
#elif defined(__DOS__)
return QSE_NULL;
int qse_feof (QSE_FILE* fp)
{
return feof (fp);
}
#else
QSE_FILE* fp = QSE_NULL;
qse_mchar_t* cmd_mb;
cmd_mb = qse_wcstombsdup (cmd, QSE_NULL, QSE_MMGR_GETDFL());
if (cmd_mb)
{
char mode_mb[3];
int mode_mb_len;
int mode_flag = 0;
fp = popen (cmd_mb, mode_mb);
while (*mode)
{
if (*mode == QSE_T('r')) mode_flag |= 1;
else if (*mode == QSE_T('w')) mode_flag |= 2;
mode++;
}
mode_mb_len = 0;
if (mode_flag & 1) mode_mb[mode_mb_len++] = QSE_MT('r');
if (mode_flag & 2) mode_mb[mode_mb_len++] = QSE_MT('w');
mode_mb[mode_mb_len++] = QSE_MT('\0');
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), cmd_mb);
}
return fp;
#endif
int qse_ferror (QSE_FILE* fp)
{
return ferror (fp);
}
static int isnl (const qse_char_t* ptr, qse_size_t len, void* delim)

View File

@ -67,7 +67,7 @@ int Sed::execute (Stream& iostream)
void Sed::stop ()
{
QSE_ASSERT (sed != QSE_NULL);
return qse_sed_stop (sed);
qse_sed_stop (sed);
}
bool Sed::isStop () const