2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
2012-03-24 14:06:46 -04:00
|
|
|
* Copyright 2001, 2011 Fidelity Information Services, Inc *
|
2012-02-05 11:35:58 -05:00
|
|
|
* *
|
|
|
|
* This source code contains the intellectual property *
|
|
|
|
* of its copyright holder(s), and is made available *
|
|
|
|
* under a license. If you do not know the terms of *
|
|
|
|
* the license, please stop and do not read further. *
|
|
|
|
* *
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "mdef.h"
|
|
|
|
|
|
|
|
#include "gtm_string.h"
|
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "stringpool.h"
|
|
|
|
#include "opcode.h"
|
|
|
|
#include "indir_enum.h"
|
|
|
|
#include "toktyp.h"
|
|
|
|
#include "advancewindow.h"
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "rwformat.h"
|
|
|
|
|
|
|
|
GBLREF spdesc stringpool;
|
|
|
|
GBLREF bool devctlexp;
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
error_def(ERR_STRINGOFLOW);
|
|
|
|
|
2012-02-05 11:35:58 -05:00
|
|
|
#define STO_LLPTR(X) (llptr ? *++llptr = (X) : 0)
|
|
|
|
#define LITLST_TOP (&litlst[(SIZEOF(litlst) / SIZEOF(triple *)) - 2])
|
2012-03-24 14:06:46 -04:00
|
|
|
|
2012-02-05 11:35:58 -05:00
|
|
|
int m_write(void)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
char *cp;
|
|
|
|
int lnx;
|
|
|
|
mval lit;
|
|
|
|
mstr *msp;
|
|
|
|
oprtype *oprptr, x;
|
|
|
|
triple *litlst[128], **llptr, **ltop, **ptx, *ref, *t1;
|
|
|
|
DCL_THREADGBL_ACCESS;
|
2012-02-05 11:35:58 -05:00
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
SETUP_THREADGBL_ACCESS;
|
2012-02-05 11:35:58 -05:00
|
|
|
llptr = litlst;
|
|
|
|
ltop = 0;
|
|
|
|
*llptr = 0;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
devctlexp = FALSE;
|
2012-03-24 14:06:46 -04:00
|
|
|
switch (TREF(window_token))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
case TK_ASTERISK:
|
|
|
|
advancewindow();
|
2012-03-24 14:06:46 -04:00
|
|
|
if (EXPR_FAIL == expr(&x, MUMPS_INT))
|
2012-02-05 11:35:58 -05:00
|
|
|
return FALSE;
|
2012-03-24 14:06:46 -04:00
|
|
|
assert(TRIP_REF == x.oprclass);
|
2012-02-05 11:35:58 -05:00
|
|
|
ref = newtriple(OC_WTONE);
|
|
|
|
ref->operand[0] = x;
|
2012-03-24 14:06:46 -04:00
|
|
|
STO_LLPTR((OC_ILIT == x.oprval.tref->opcode) ? ref : 0);
|
2012-02-05 11:35:58 -05:00
|
|
|
break;
|
|
|
|
case TK_QUESTION:
|
|
|
|
case TK_EXCLAIMATION:
|
|
|
|
case TK_HASH:
|
|
|
|
case TK_SLASH:
|
|
|
|
if (!rwformat())
|
|
|
|
return FALSE;
|
|
|
|
STO_LLPTR(0);
|
|
|
|
break;
|
|
|
|
default:
|
2012-03-24 14:06:46 -04:00
|
|
|
switch (expr(&x, MUMPS_STR))
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
case EXPR_FAIL:
|
|
|
|
return FALSE;
|
|
|
|
case EXPR_GOOD:
|
2012-03-24 14:06:46 -04:00
|
|
|
assert(TRIP_REF == x.oprclass);
|
2012-02-05 11:35:58 -05:00
|
|
|
if (devctlexp)
|
|
|
|
{
|
|
|
|
ref = newtriple(OC_WRITE);
|
|
|
|
ref->operand[0] = x;
|
|
|
|
STO_LLPTR(0);
|
|
|
|
} else if (x.oprval.tref->opcode == OC_CAT)
|
2012-03-24 14:06:46 -04:00
|
|
|
wrtcatopt(x.oprval.tref, &llptr, LITLST_TOP);
|
|
|
|
else
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
ref = newtriple(OC_WRITE);
|
|
|
|
ref->operand[0] = x;
|
2012-03-24 14:06:46 -04:00
|
|
|
STO_LLPTR((OC_LIT == x.oprval.tref->opcode) ? ref : 0);
|
2012-02-05 11:35:58 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_INDR:
|
2012-03-24 14:06:46 -04:00
|
|
|
make_commarg(&x, indir_write);
|
2012-02-05 11:35:58 -05:00
|
|
|
STO_LLPTR(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-24 14:06:46 -04:00
|
|
|
if (TK_COMMA != TREF(window_token))
|
2012-02-05 11:35:58 -05:00
|
|
|
break;
|
|
|
|
advancewindow();
|
2012-03-24 14:06:46 -04:00
|
|
|
if (LITLST_TOP <= llptr)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
*++llptr = 0;
|
|
|
|
ltop = llptr;
|
|
|
|
llptr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
STO_LLPTR(0);
|
|
|
|
if (ltop)
|
|
|
|
llptr = ltop;
|
|
|
|
for (ptx = litlst ; ptx < llptr ; ptx++)
|
|
|
|
{
|
|
|
|
if (*ptx && *(ptx + 1))
|
|
|
|
{
|
|
|
|
lit.mvtype = MV_STR;
|
2012-03-24 14:06:46 -04:00
|
|
|
lit.str.addr = cp = (char *)stringpool.free;
|
2012-02-05 11:35:58 -05:00
|
|
|
for (t1 = ref = *ptx++ ; ref ; ref = *ptx++)
|
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
if (OC_WRITE == ref->opcode)
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
|
|
|
msp = &(ref->operand[0].oprval.tref->operand[0].oprval.mlit->v.str);
|
|
|
|
lnx = msp->len;
|
2012-03-24 14:06:46 -04:00
|
|
|
ENSURE_STP_FREE_SPACE(lnx);
|
2012-02-05 11:35:58 -05:00
|
|
|
memcpy(cp, msp->addr, lnx);
|
|
|
|
cp += lnx;
|
2012-03-24 14:06:46 -04:00
|
|
|
} else
|
2012-02-05 11:35:58 -05:00
|
|
|
{
|
2012-03-24 14:06:46 -04:00
|
|
|
assert(OC_WTONE == ref->opcode);
|
|
|
|
ENSURE_STP_FREE_SPACE(1);
|
2012-02-05 11:35:58 -05:00
|
|
|
*cp++ = ref->operand[0].oprval.tref->operand[0].oprval.ilit;
|
|
|
|
}
|
|
|
|
ref->operand[0].oprval.tref->opcode = OC_NOOP;
|
|
|
|
ref->opcode = OC_NOOP;
|
|
|
|
ref->operand[0].oprval.tref->operand[0].oprclass = OC_NOOP;
|
|
|
|
ref->operand[0].oprclass = 0;
|
|
|
|
}
|
|
|
|
ptx--;
|
|
|
|
stringpool.free = (unsigned char *) cp;
|
|
|
|
lit.str.len = INTCAST(cp - lit.str.addr);
|
|
|
|
s2n(&lit);
|
|
|
|
t1->opcode = OC_WRITE;
|
|
|
|
t1->operand[0] = put_lit(&lit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|