2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbc_trans_subr.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-08-03 17:38:01 +02:00
|
|
|
(c) 2000-2013 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define _TRANS_SUBR_C
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbc_compile.h"
|
|
|
|
#include "gbc_trans.h"
|
|
|
|
#include "gb_code.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
|
|
|
|
/*#define DEBUG*/
|
|
|
|
|
|
|
|
|
|
|
|
typedef
|
2010-12-29 10:12:56 +01:00
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
SUBR_INFO *info;
|
|
|
|
}
|
|
|
|
TRANS_SUBR_INFO;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void trans_subr(int subr, int nparam)
|
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
static TRANS_SUBR_INFO subr_info[] =
|
|
|
|
{
|
|
|
|
{ ".Print" }, { ".Input" }, { ".Write" }, { ".WriteBytes" }, { ".Read" },
|
2009-09-20 19:32:12 +02:00
|
|
|
{ ".ReadBytes" }, { ".Open" }, { ".Close" }, { "Seek" }, { ".LineInput" },
|
|
|
|
{ ".Flush" }, { ".Exec" }, { ".Shell" }, { ".Wait" }, { ".Kill" },
|
|
|
|
{ ".Move" }, { ".Mkdir" }, { ".Rmdir" }, { ".Array" }, {".Collection" },
|
|
|
|
{ ".Copy" }, { ".Link" }, { ".Error" }, { ".Lock" }, { ".Unlock" },
|
2014-03-09 18:51:52 +01:00
|
|
|
{ ".LockWait" }, { ".InputFrom" }, { ".OutputTo" }, { ".Debug" }, { ".Sleep" },
|
|
|
|
{ ".Randomize" }, { ".ErrorTo" }, { "Left" }, { "Mid" }, { ".OpenMemory" },
|
2014-11-28 00:31:51 +01:00
|
|
|
{ ".Chmod" }, { ".Chown" }, { ".Chgrp" }, { ".Use" }, { ".CheckExec" }
|
2010-12-29 10:12:56 +01:00
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_SUBR_INFO *tsi = &subr_info[subr];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (tsi->info == NULL)
|
|
|
|
{
|
|
|
|
tsi->info = SUBR_get(tsi->name);
|
|
|
|
if (!tsi->info)
|
|
|
|
ERROR_panic("Unknown intern subroutine: %s", tsi->name);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2014-01-28 17:17:40 +01:00
|
|
|
if (subr == TS_SUBR_ARRAY && nparam > MAX_PARAM_OP)
|
|
|
|
CODE_subr(tsi->info->opcode, MAX_PARAM_OP + 1, CODE_CALL_VARIANT + MAX_PARAM_OP, FALSE);
|
|
|
|
else if (subr == TS_SUBR_COLLECTION && nparam > MAX_PARAM_OP)
|
|
|
|
CODE_subr(tsi->info->opcode, MAX_PARAM_OP, CODE_CALL_VARIANT + MAX_PARAM_OP - 1, FALSE);
|
2014-01-28 00:46:37 +01:00
|
|
|
else
|
|
|
|
CODE_subr(tsi->info->opcode, nparam, tsi->info->optype, tsi->info->min_param == tsi->info->max_param);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
static bool trans_stream_check(int default_stream, bool check)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2014-03-22 13:25:48 +01:00
|
|
|
if (TRANS_is(RS_SHARP) || default_stream == TS_NONE)
|
2010-12-29 10:12:56 +01:00
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
if (check)
|
2009-07-20 17:53:19 +02:00
|
|
|
{
|
2009-09-20 19:32:12 +02:00
|
|
|
if (PATTERN_is(*JOB->current, RS_COMMA))
|
|
|
|
{
|
|
|
|
JOB->current++;
|
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!PATTERN_is_newline(*JOB->current))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
}
|
2009-07-20 17:53:19 +02:00
|
|
|
}
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2010-12-29 10:12:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-22 13:25:48 +01:00
|
|
|
//if (default_stream == TS_NONE)
|
|
|
|
// THROW("Syntax error. &1 expected", "'#'");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
CODE_push_number(default_stream);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
#define trans_stream(_default_stream) trans_stream_check(_default_stream, TRUE)
|
|
|
|
#define trans_stream_no_check(_default_stream) trans_stream_check(_default_stream, FALSE)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-20 17:53:19 +02:00
|
|
|
static void trans_print_debug()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int nparam = 1;
|
|
|
|
bool semicolon_or_comma = FALSE;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
break;
|
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
semicolon_or_comma = FALSE;
|
|
|
|
|
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_SCOLON))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_SCOLON))
|
|
|
|
{
|
|
|
|
CODE_push_char(' ');
|
|
|
|
nparam++;
|
|
|
|
}
|
|
|
|
semicolon_or_comma = TRUE;
|
|
|
|
}
|
|
|
|
else if (TRANS_is(RS_COMMA))
|
|
|
|
{
|
|
|
|
CODE_push_char('\t');
|
|
|
|
nparam++;
|
|
|
|
semicolon_or_comma = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!semicolon_or_comma)
|
|
|
|
{
|
|
|
|
CODE_push_char('\n');
|
|
|
|
nparam++;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans_subr(TS_SUBR_PRINT, nparam);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_print(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-07-20 17:53:19 +02:00
|
|
|
trans_stream(TS_STDOUT);
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_print_debug();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_debug(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (!JOB->debug)
|
|
|
|
{
|
|
|
|
while (!PATTERN_is_newline(*JOB->current))
|
|
|
|
JOB->current++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans_subr(TS_SUBR_DEBUG, 0);
|
|
|
|
CODE_drop();
|
|
|
|
CODE_push_number(2); // stderr
|
|
|
|
trans_print_debug();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_error(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (TRANS_is(RS_TO))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_DEFAULT))
|
|
|
|
CODE_push_null();
|
|
|
|
else
|
|
|
|
trans_stream(TS_NONE);
|
|
|
|
|
|
|
|
trans_subr(TS_SUBR_ERROR_TO, 1);
|
|
|
|
|
|
|
|
if (TRANS_in_affectation == 0)
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CODE_push_number(2); // stderr
|
|
|
|
trans_print_debug();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
static int trans_binary_type(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int index;
|
2009-09-20 19:32:12 +02:00
|
|
|
int nparam = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (PATTERN_is_class(*JOB->current))
|
|
|
|
{
|
|
|
|
index = CLASS_add_class(JOB->class, PATTERN_index(*JOB->current));
|
|
|
|
if (PATTERN_is(JOB->current[1], RS_LSQR))
|
|
|
|
index = CLASS_get_array_class(JOB->class, T_OBJECT, index);
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
CODE_push_class(index);
|
2010-12-29 10:12:56 +01:00
|
|
|
}
|
|
|
|
else if (PATTERN_is_type(*JOB->current))
|
|
|
|
{
|
|
|
|
if (PATTERN_is(JOB->current[1], RS_LSQR))
|
2009-09-20 19:32:12 +02:00
|
|
|
{
|
|
|
|
index = CLASS_get_array_class(JOB->class, RES_get_type(PATTERN_index(*JOB->current)), -1);
|
|
|
|
CODE_push_class(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = RES_get_type(PATTERN_index(*JOB->current));
|
|
|
|
CODE_push_number(index);
|
|
|
|
}
|
2010-12-29 10:12:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
THROW(E_SYNTAX);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current++;
|
2009-09-20 19:32:12 +02:00
|
|
|
nparam++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
#if 0
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_LSQR))
|
|
|
|
{
|
2009-09-20 19:32:12 +02:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
TRANS_want(RS_RSQR, NULL);
|
|
|
|
}
|
|
|
|
else if (TRANS_is(RS_STAR))
|
|
|
|
{
|
|
|
|
if (!string)
|
|
|
|
THROW("Syntax error");
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return nparam;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
void TRANS_write(void)
|
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_stream(TS_STDOUT);
|
2009-09-20 19:32:12 +02:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
if (TRANS_is(RS_AS))
|
|
|
|
{
|
|
|
|
trans_binary_type();
|
|
|
|
trans_subr(TS_SUBR_WRITE, 3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_COMMA))
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
else
|
2009-09-20 20:04:04 +02:00
|
|
|
{
|
|
|
|
if (JOB->no_old_read_syntax)
|
2009-09-21 18:57:21 +02:00
|
|
|
THROW("Syntax error. &1 expected", "AS");
|
2009-09-20 19:32:12 +02:00
|
|
|
CODE_push_number(-1);
|
2009-09-20 20:04:04 +02:00
|
|
|
}
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
trans_subr(TS_SUBR_WRITE_BYTES, 3);
|
|
|
|
}
|
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_output_to()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_want(RS_TO, NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_DEFAULT))
|
|
|
|
CODE_push_null();
|
|
|
|
else
|
|
|
|
trans_stream(TS_NONE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_OUTPUT_TO, 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_in_affectation == 0)
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_input_from()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_DEFAULT))
|
|
|
|
CODE_push_null();
|
|
|
|
else
|
|
|
|
trans_stream(TS_NONE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_INPUT_FROM, 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_in_affectation == 0)
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_input(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
bool stream = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_FROM))
|
|
|
|
{
|
|
|
|
TRANS_input_from();
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_stream(TS_STDIN);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
trans_subr(TS_SUBR_INPUT, (stream ? 1 : 0));
|
|
|
|
stream = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_reference();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (!PATTERN_is(*JOB->current, RS_COMMA)
|
|
|
|
&& !PATTERN_is(*JOB->current, RS_SCOLON))
|
|
|
|
THROW(E_SYNTAX);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current++;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
void TRANS_read_old(void)
|
|
|
|
{
|
|
|
|
PATTERN *save_var;
|
|
|
|
PATTERN *save_current;
|
|
|
|
TYPE type;
|
|
|
|
|
|
|
|
if (JOB->no_old_read_syntax)
|
2009-09-21 18:57:21 +02:00
|
|
|
THROW(E_UNEXPECTED, "READ");
|
2009-09-20 19:32:12 +02:00
|
|
|
|
|
|
|
trans_stream(TS_STDIN);
|
|
|
|
|
|
|
|
save_var = JOB->current;
|
|
|
|
type = TRANS_variable_get_type();
|
|
|
|
|
|
|
|
if (TRANS_is(RS_COMMA))
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_READ_BYTES, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int id = TYPE_get_id(type);
|
|
|
|
|
|
|
|
CODE_push_number(id);
|
|
|
|
trans_subr(TS_SUBR_READ, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
save_current = JOB->current;
|
|
|
|
JOB->current = save_var;
|
|
|
|
TRANS_reference();
|
|
|
|
JOB->current = save_current;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_read(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-09-20 19:32:12 +02:00
|
|
|
bool def = trans_stream_no_check(TS_STDIN);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-09-20 19:32:12 +02:00
|
|
|
if (TRANS_is(RS_AS))
|
|
|
|
{
|
|
|
|
trans_binary_type();
|
|
|
|
trans_subr(TS_SUBR_READ, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!def)
|
|
|
|
TRANS_want(RS_COMMA, NULL);
|
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_READ_BYTES, 2);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_open(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int mode = TS_MODE_READ;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-11-04 16:17:01 +01:00
|
|
|
if (TRANS_is(RS_PIPE))
|
|
|
|
{
|
|
|
|
TRANS_pipe();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (TRANS_is(RS_MEMORY))
|
|
|
|
{
|
|
|
|
TRANS_memory();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (TRANS_is(RS_STRING))
|
|
|
|
{
|
|
|
|
TRANS_open_string();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/* Nom du fichier */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/* mode d'ouverture */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_FOR))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_READ))
|
|
|
|
mode |= TS_MODE_READ | TS_MODE_DIRECT;
|
|
|
|
else if (TRANS_is(RS_INPUT))
|
|
|
|
mode |= TS_MODE_READ;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_WRITE))
|
|
|
|
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
|
|
|
|
else if (TRANS_is(RS_OUTPUT))
|
|
|
|
mode |= TS_MODE_WRITE;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_CREATE))
|
|
|
|
mode |= TS_MODE_CREATE;
|
|
|
|
else if (TRANS_is(RS_APPEND))
|
|
|
|
mode |= TS_MODE_APPEND;
|
|
|
|
|
|
|
|
//if (TRANS_is(RS_DIRECT))
|
|
|
|
// mode |= TS_MODE_DIRECT;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_WATCH))
|
|
|
|
mode |= TS_MODE_WATCH;
|
|
|
|
|
|
|
|
/*if (TRANS_is(RS_BIG))
|
|
|
|
mode |= TS_MODE_BIG;
|
|
|
|
else if (TRANS_is(RS_LITTLE))
|
|
|
|
mode |= TS_MODE_LITTLE;*/
|
|
|
|
|
|
|
|
/*JOB->current--;
|
|
|
|
if (PATTERN_is(*JOB->current, RS_FOR))
|
|
|
|
THROW("Syntax error in file open mode");
|
|
|
|
JOB->current++;*/
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
CODE_push_number(mode);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_OPEN, 2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/*if (TRANS_in_affectation == 0)
|
|
|
|
{
|
|
|
|
//CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_want(RS_AS, NULL);
|
|
|
|
TRANS_ignore(RS_SHARP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_reference();
|
|
|
|
}*/
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_pipe(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int mode = TS_MODE_READ;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/* Nom du fichier */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/* mode d'ouverture */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_FOR))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_READ))
|
|
|
|
mode |= TS_MODE_READ | TS_MODE_DIRECT;
|
|
|
|
//else if (TRANS_is(RS_INPUT))
|
|
|
|
// mode |= TS_MODE_READ;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_WRITE))
|
|
|
|
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
|
|
|
|
//else if (TRANS_is(RS_OUTPUT))
|
|
|
|
// mode |= TS_MODE_WRITE;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_WATCH))
|
|
|
|
mode |= TS_MODE_WATCH;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
CODE_push_number(mode | TS_MODE_PIPE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_OPEN, 2);
|
2009-09-17 22:58:27 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2009-09-17 22:58:27 +02:00
|
|
|
void TRANS_memory(void)
|
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int mode = TS_MODE_READ;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/* Memory address */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2009-09-17 22:58:27 +02:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/* Open mode */
|
2009-09-17 22:58:27 +02:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_FOR))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_READ))
|
|
|
|
mode |= TS_MODE_READ | TS_MODE_DIRECT;
|
2009-09-17 22:58:27 +02:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_WRITE))
|
|
|
|
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
|
|
|
|
}
|
2009-09-17 22:58:27 +02:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
CODE_push_number(mode);
|
2009-09-17 22:58:27 +02:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_OPEN_MEMORY, 2);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-04 16:17:01 +01:00
|
|
|
void TRANS_open_string(void)
|
|
|
|
{
|
|
|
|
int mode = TS_MODE_READ;
|
|
|
|
|
|
|
|
/* Nom du fichier */
|
|
|
|
|
2013-11-04 21:12:24 +01:00
|
|
|
if (!PATTERN_is(*JOB->current, RS_FOR))
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
else
|
|
|
|
CODE_push_null();
|
2013-11-04 16:17:01 +01:00
|
|
|
|
|
|
|
/* mode d'ouverture */
|
|
|
|
|
|
|
|
if (TRANS_is(RS_FOR))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_READ))
|
|
|
|
mode |= TS_MODE_READ | TS_MODE_DIRECT;
|
|
|
|
|
|
|
|
if (TRANS_is(RS_WRITE))
|
|
|
|
mode |= TS_MODE_WRITE | TS_MODE_DIRECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
CODE_push_number(mode | TS_MODE_STRING);
|
|
|
|
|
|
|
|
trans_subr(TS_SUBR_OPEN, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_close(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
THROW(E_SYNTAX);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_ignore(RS_SHARP);
|
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_CLOSE, 1);
|
2013-11-04 16:17:01 +01:00
|
|
|
|
|
|
|
if (TRANS_in_affectation == 0)
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_lock(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
THROW(E_SYNTAX);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
if (!TRANS_in_affectation)
|
|
|
|
THROW("Useless LOCK");
|
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2014-03-09 18:51:52 +01:00
|
|
|
|
|
|
|
if (TRANS_is(RS_WAIT))
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_LOCK_WAIT, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trans_subr(TS_SUBR_LOCK, 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_unlock(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
THROW(E_SYNTAX);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_ignore(RS_SHARP);
|
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_UNLOCK, 1);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_seek(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_stream(TS_NONE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam = 2;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
/*
|
|
|
|
if (TRANS_is(RS_COMMA))
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam++;
|
|
|
|
}
|
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_SEEK, nparam);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_line_input(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
if (TRANS_is(RS_INPUT))
|
|
|
|
{
|
|
|
|
trans_stream(TS_STDIN);
|
|
|
|
trans_subr(TS_SUBR_LINE_INPUT, 1);
|
|
|
|
TRANS_reference();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
THROW(E_SYNTAX);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_flush(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_stream(TS_STDOUT);
|
|
|
|
trans_subr(TS_SUBR_FLUSH, 1);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_quit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-10-19 23:00:35 +02:00
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
{
|
|
|
|
CODE_quit(FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
CODE_quit(TRUE);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_randomize(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (PATTERN_is_newline(*JOB->current))
|
|
|
|
{
|
|
|
|
trans_subr(TS_SUBR_RANDOMIZE, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_RANDOMIZE, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void trans_exec_shell(bool shell)
|
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int mode = TS_EXEC_NONE;
|
|
|
|
bool wait;
|
|
|
|
bool as = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-22 16:52:36 +02:00
|
|
|
if (TRANS_is(RS_WITH))
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
else
|
|
|
|
CODE_push_null();
|
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
wait = TRANS_is(RS_WAIT);
|
|
|
|
|
|
|
|
if (TRANS_is(RS_FOR))
|
|
|
|
{
|
|
|
|
if (TRANS_is(RS_READ))
|
|
|
|
mode |= TS_EXEC_READ;
|
|
|
|
if (TRANS_is(RS_WRITE))
|
|
|
|
mode |= TS_EXEC_WRITE;
|
|
|
|
|
|
|
|
if (mode == 0)
|
|
|
|
{
|
|
|
|
mode |= TS_EXEC_TERM;
|
|
|
|
if (TRANS_is(RS_INPUT))
|
|
|
|
mode |= TS_EXEC_READ;
|
|
|
|
if (TRANS_is(RS_OUTPUT))
|
|
|
|
mode |= TS_EXEC_WRITE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (TRANS_is(RS_TO))
|
|
|
|
{
|
|
|
|
if (TRANS_in_affectation)
|
|
|
|
THROW("Syntax error. Cannot use this syntax in assignment");
|
|
|
|
|
|
|
|
mode = TS_EXEC_STRING;
|
|
|
|
wait = TRUE;
|
|
|
|
as = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wait) mode |= TS_EXEC_WAIT;
|
|
|
|
CODE_push_number(mode);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (as && TRANS_is(RS_AS))
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
else
|
|
|
|
CODE_push_null();
|
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(shell ? TS_SUBR_SHELL : TS_SUBR_EXEC, 4);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (mode & TS_EXEC_STRING)
|
|
|
|
TRANS_reference();
|
|
|
|
else if (TRANS_in_affectation == 0)
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_exec(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_exec_shell(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_shell(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_exec_shell(TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_wait(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
int nparam = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
if (!PATTERN_is_newline(*JOB->current))
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
nparam = 1;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(TS_SUBR_WAIT, nparam);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_sleep(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_SLEEP, 1);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_kill(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_KILL, 1);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_move(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_MOVE, 2);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_copy(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_COPY, 2);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_link(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_LINK, 2);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-01-15 09:54:57 +01:00
|
|
|
void TRANS_chmod(void)
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_CHMOD, 2);
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRANS_chown(void)
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_CHOWN, 2);
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRANS_chgrp(void)
|
|
|
|
{
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_CHGRP, 2);
|
|
|
|
CODE_drop();
|
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_inc(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
PATTERN *save = JOB->current;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
CODE_push_number(1);
|
|
|
|
CODE_op(C_ADD, 0, 2, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current = save;
|
|
|
|
TRANS_reference();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_dec(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
PATTERN *save = JOB->current;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
CODE_push_number(1);
|
|
|
|
CODE_op(C_SUB, 0, 2, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current = save;
|
|
|
|
TRANS_reference();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_swap(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
PATTERN *sa;
|
|
|
|
PATTERN *sb;
|
|
|
|
PATTERN *current;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
sa = JOB->current;
|
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_want(RS_COMMA, "Comma");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
sb = JOB->current;
|
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
current = JOB->current;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current = sa;
|
|
|
|
TRANS_reference();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current = sb;
|
|
|
|
TRANS_reference();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current = current;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_mkdir(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_MKDIR, 1);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_rmdir(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
|
|
|
trans_subr(TS_SUBR_RMDIR, 1);
|
|
|
|
CODE_drop();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-03-17 15:54:17 +01:00
|
|
|
void TRANS_mid()
|
|
|
|
{
|
|
|
|
PATTERN *str;
|
|
|
|
PATTERN *pos;
|
|
|
|
PATTERN *len;
|
|
|
|
PATTERN *save;
|
|
|
|
|
2009-08-21 21:43:40 +02:00
|
|
|
TRANS_want(RS_LBRA, "Left bracket");
|
2008-03-17 15:54:17 +01:00
|
|
|
|
|
|
|
str = JOB->current;
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
|
|
|
|
TRANS_want(RS_COMMA, "Comma");
|
|
|
|
|
|
|
|
pos = JOB->current;
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
CODE_push_number(1);
|
2009-09-27 11:28:52 +02:00
|
|
|
CODE_op(C_SUB, 0, 2, TRUE);
|
2008-03-17 15:54:17 +01:00
|
|
|
TRANS_subr(TS_SUBR_LEFT, 2);
|
|
|
|
|
|
|
|
if (TRANS_is(RS_COMMA))
|
|
|
|
{
|
|
|
|
len = JOB->current;
|
|
|
|
TRANS_ignore_expression();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = NULL;
|
|
|
|
}
|
|
|
|
|
2009-08-21 21:43:40 +02:00
|
|
|
TRANS_want(RS_RBRA, "Right bracket");
|
2008-03-17 15:54:17 +01:00
|
|
|
TRANS_want(RS_EQUAL, "Equal");
|
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
|
|
|
|
save = JOB->current;
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
JOB->current = str;
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
JOB->current = pos;
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
JOB->current = len;
|
|
|
|
TRANS_expression(FALSE);
|
2009-09-27 11:28:52 +02:00
|
|
|
CODE_op(C_ADD, 0, 2, TRUE);
|
2008-03-17 15:54:17 +01:00
|
|
|
TRANS_subr(TS_SUBR_MID, 2);
|
|
|
|
}
|
|
|
|
|
2009-09-27 11:28:52 +02:00
|
|
|
CODE_op(C_CAT, 0, len ? 3 : 2, FALSE);
|
2008-03-17 15:54:17 +01:00
|
|
|
|
|
|
|
JOB->current = str;
|
|
|
|
TRANS_reference();
|
|
|
|
|
|
|
|
JOB->current = save;
|
|
|
|
}
|
|
|
|
|
2014-11-12 23:25:37 +01:00
|
|
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#if 0
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_scan(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
PATTERN *save;
|
|
|
|
int noutput = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
TRANS_want(RS_WITH, NULL);
|
|
|
|
TRANS_expression(FALSE);
|
|
|
|
|
|
|
|
TRANS_want(RS_TO, NULL);
|
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
save = JOB->current;
|
2007-12-30 17:41:49 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_expression(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
noutput++;
|
|
|
|
if (!TRANS_is(RS_COMMA))
|
|
|
|
break;
|
|
|
|
}
|
2010-12-29 10:12:56 +01:00
|
|
|
JOB->current = save;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr_output(TSO_SUBR_SCAN, 2 + noutput, noutput);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
TRANS_reference();
|
2007-12-30 17:41:49 +01:00
|
|
|
if (!TRANS_is(RS_COMMA))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-06 19:49:23 +01:00
|
|
|
void TRANS_subr(int subr, int nparam)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-29 10:12:56 +01:00
|
|
|
trans_subr(subr, nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|