home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
379a.lha
/
p2c1_13a
/
src
/
src.zoo
/
funcs3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-17
|
23KB
|
982 lines
/* "p2c", a Pascal to C translator.
Copyright (C) 1989 David Gillespie.
Author's address: daveg@csvax.caltech.edu; 256-80 Caltech/Pasadena CA 91125.
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 (any version).
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.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#define PROTO_FUNCS3_C
#include "trans.h"
extern Strlist *enumnames;
extern int enumnamecount;
Stmt *proc_gotoxy(ex)
Expr *ex;
{
return makestmt_call(makeexpr_bicall_2("gotoxy", tp_void,
makeexpr_arglong(ex->args[0], 0),
makeexpr_arglong(ex->args[1], 0)));
}
Expr *handle_vax_hex(ex, fmt, scale)
Expr *ex;
char *fmt;
int scale;
{
Expr *lex, *dex, *vex;
Meaning *tvar;
Type *tp;
long smin, smax;
int bits;
if (!ex) {
if (!skipopenparen())
return NULL;
ex = p_expr(tp_integer);
}
tp = true_type(ex);
if (ord_range(tp, &smin, &smax))
bits = typebits(smin, smax);
else
bits = 32;
if (curtok == TOK_COMMA) {
gettok();
if (curtok != TOK_COMMA)
lex = makeexpr_arglong(p_expr(tp_integer), 0);
else
lex = NULL;
} else
lex = NULL;
if (!lex) {
if (!scale)
lex = makeexpr_long(11);
else
lex = makeexpr_long((bits+scale-1) / scale + 1);
}
if (curtok == TOK_COMMA) {
gettok();
dex = makeexpr_arglong(p_expr(tp_integer), 0);
} else {
if (!scale)
dex = makeexpr_long(10);
else
dex = makeexpr_long((bits+scale-1) / scale);
}
if (lex->kind == EK_CONST && dex->kind == EK_CONST &&
lex->val.i < dex->val.i)
lex = NULL;
skipcloseparen();
tvar = makestmttempvar(tp_str255, name_STRING);
vex = makeexpr_var(tvar);
ex = makeexpr_forcelongness(ex);
if (exprlongness(ex) > 0)
fmt = format_s("l%s", fmt);
if (checkconst(lex, 0) || checkconst(lex, 1))
lex = NULL;
if (checkconst(dex, 0) || checkconst(dex, 1))
dex = NULL;
if (lex) {
if (dex)
ex = makeexpr_bicall_5("sprintf", tp_str255, vex,
makeexpr_string(format_s("%%*.*%s", fmt)),
lex, dex, ex);
else
ex = makeexpr_bicall_4("sprintf", tp_str255, vex,
makeexpr_string(format_s("%%*%s", fmt)),
lex, ex);
} else {
if (dex)
ex = makeexpr_bicall_4("sprintf", tp_str255, vex,
makeexpr_string(format_s("%%.*%s", fmt)),
dex, ex);
else
ex = makeexpr_bicall_3("sprintf", tp_str255, vex,
makeexpr_string(format_s("%%%s", fmt)),
ex);
}
return ex;
}
Expr *func_hex()
{
Expr *ex;
char *cp;
if (!skipopenparen())
return NULL;
ex = makeexpr_stringcast(p_expr(tp_integer));
if ((ex->val.type->kind == TK_STRING ||
ex->val.type == tp_strptr) &&
curtok != TOK_COMMA) {
skipcloseparen();
if (ex->kind == EK_CONST) { /* HP Pascal */
cp = getstring(ex);
ex = makeexpr_long(my_strtol(cp, NULL, 16));
insertarg(&ex, 0, makeexpr_name("%#lx", tp_integer));
return ex;
} else {
return makeexpr_bicall_3("strtol", tp_integer,
ex, makeexpr_nil(), makeexpr_long(16));
}
} else { /* VAX Pascal */
return handle_vax_hex(ex, "x", 4);
}
}
Expr *func_hi()
{
Expr *ex;
ex = force_unsigned(p_parexpr(tp_integer));
return makeexpr_bin(EK_RSH, tp_ubyte,
ex, makeexpr_long(8));
}
Expr *func_high()
{
Expr *ex;
Type *type;
ex = p_parexpr(tp_integer);
type = ex->val.type;
if (type->kind == TK_POINTER)
type = type->basetype;
if (type->kind == TK_ARRAY ||
type->kind == TK_SMALLARRAY) {
ex = makeexpr_minus(copyexpr(type->indextype->smax),
copyexpr(type->indextype->smin));
} else {
warning("HIGH requires an array name parameter [210]");
ex = makeexpr_bicall_1("HIGH", tp_int, ex);
}
return ex;
}
Expr *func_hiword()
{
Expr *ex;
ex = force_unsigned(p_parexpr(tp_unsigned));
return makeexpr_bin(EK_RSH, tp_unsigned,
ex, makeexpr_long(16));
}
Stmt *proc_inc()
{
Expr *vex, *ex;
if (!skipopenparen())
return NULL;
vex = p_expr(NULL);
if (curtok == TOK_COMMA) {
gettok();
ex = p_expr(tp_integer);
} else
ex = makeexpr_long(1);
skipcloseparen();
return makestmt_assign(vex, makeexpr_plus(copyexpr(vex), ex));
}
Stmt *proc_incl()
{
Expr *vex, *ex;
if (!skipopenparen())
return NULL;
vex = p_expr(NULL);
if (!skipcomma())
return NULL;
ex = p_expr(vex->val.type->indextype);
skipcloseparen();
if (vex->val.type->kind == TK_SMALLSET)
return makestmt_assign(vex, makeexpr_bin(EK_BOR, vex->val.type,
copyexpr(vex),
makeexpr_bin(EK_LSH, vex->val.type,
makeexpr_longcast(makeexpr_long(1), 1),
ex)));
else
return makestmt_call(makeexpr_bicall_2(setaddname, tp_void, vex,
makeexpr_arglong(enum_to_int(ex), 0)));
}
Stmt *proc_insert(ex)
Expr *ex;
{
return makestmt_call(makeexpr_bicall_3(strinsertname, tp_void,
ex->args[0],
ex->args[1],
makeexpr_arglong(ex->args[2], 0)));
}
Expr *func_int()
{
Expr *ex;
Meaning *tvar;
ex = p_parexpr(tp_integer);
if (ex->val.type->kind == TK_REAL) { /* Turbo Pascal INT */
tvar = makestmttempvar(tp_longreal, name_TEMP);
return makeexpr_comma(makeexpr_bicall_2("modf", tp_longreal,
grabarg(ex, 0),
makeexpr_addr(makeexpr_var(tvar))),
makeexpr_var(tvar));
} else { /* VAX Pascal INT */
return makeexpr_ord(ex);
}
}
Expr *func_uint()
{
Expr *ex;
ex = p_parexpr(tp_integer);
return makeexpr_cast(ex, tp_unsigned);
}
Stmt *proc_leave()
{
return makestmt(SK_BREAK);
}
Expr *func_lo()
{
Expr *ex;
ex = gentle_cast(p_parexpr(tp_integer), tp_ushort);
return makeexpr_bin(EK_BAND, tp_ubyte,
ex, makeexpr_long(255));
}
Expr *func_loophole()
{
Type *type;
Expr *ex;
if (!skipopenparen())
return NULL;
type = p_type(NULL);
if (!skipcomma())
return NULL;
ex = p_expr(tp_integer);
skipcloseparen();
return pascaltypecast(type, ex);
}
Expr *func_lower()
{
Expr *ex;
Value val;
if (!skipopenparen())
return NULL;
ex = p_expr(tp_integer);
if (curtok == TOK_COMMA) {
gettok();
val = p_constant(tp_integer);
if (!val.type || val.i != 1)
note("LOWER(v,n) not supported for n>1 [190]");
}
skipcloseparen();
return copyexpr(ex->val.type->indextype->smin);
}
Expr *func_loword()
{
Expr *ex;
ex = p_parexpr(tp_integer);
return makeexpr_bin(EK_BAND, tp_ushort,
ex, makeexpr_long(65535));
}
Expr *func_ln(ex)
Expr *ex;
{
return makeexpr_bicall_1("log", tp_longreal, grabarg(ex, 0));
}
Expr *func_log(ex)
Expr *ex;
{
return makeexpr_bicall_1("log10", tp_longreal, grabarg(ex, 0));
}
Expr *func_max()
{
Type *tp;
Expr *ex, *ex2;
if (!skipopenparen())
return NULL;
if (curtok == TOK_IDENT && curtokmeaning &&
curtokmeaning->kind == MK_TYPE) {
tp = curtokmeaning->type;
gettok();
skipcloseparen();
return copyexpr(tp->smax);
}
ex = p_expr(tp_integer);
while (curtok == TOK_COMMA) {
gettok();
ex2 = p_expr(ex->val.type);
if (ex->val.type->kind == TK_REAL) {
tp = ex->val.type;
if (ex2->val.type->kind != TK_REAL)
ex2 = makeexpr_cast(ex2, tp);
} else {
tp = ex2->val.type;
if (ex->val.type->kind != TK_REAL)
ex = makeexpr_cast(ex, tp);
}
ex = makeexpr_bicall_2((tp->kind == TK_REAL) ? "P_rmax" : "P_imax",
tp, ex, ex2);
}
skipcloseparen();
return ex;
}
Expr *func_maxavail(ex)
Expr *ex;
{
freeexpr(ex);
return makeexpr_bicall_0("maxavail", tp_integer);
}
Expr *func_maxpos()
{
return file_iofunc(3, seek_base);
}
Expr *func_memavail(ex)
Expr *ex;
{
freeexpr(ex);
return makeexpr_bicall_0("memavail", tp_integer);
}
Expr *var_mem()
{
Expr *ex, *ex2;
if (!wneedtok(TOK_LBR))
return makeexpr_name("MEM", tp_integer);
ex = p_expr(tp_integer);
if (curtok == TOK_COLON) {
gettok();
ex2 = p_expr(tp_integer);
ex = makeexpr_bicall_2("MEM", tp_ubyte, ex, ex2);
} else {
ex = makeexpr_bicall_1("MEM", tp_ubyte, ex);
}
if (!wneedtok(TOK_RBR))
skippasttotoken(TOK_RBR, TOK_SEMI);
note("Reference to MEM [191]");
return ex;
}
Expr *var_memw()
{
Expr *ex, *ex2;
if (!wneedtok(TOK_LBR))
return makeexpr_name("MEMW", tp_integer);
ex = p_expr(tp_integer);
if (curtok == TOK_COLON) {
gettok();
ex2 = p_expr(tp_integer);
ex = makeexpr_bicall_2("MEMW", tp_ushort, ex, ex2);
} else {
ex = makeexpr_bicall_1("MEMW", tp_ushort, ex);
}
if (!wneedtok(TOK_RBR))
skippasttotoken(TOK_RBR, TOK_SEMI);
note("Reference to MEMW [191]");
return ex;
}
Expr *var_meml()
{
Expr *ex, *ex2;
if (!wneedtok(TOK_LBR))
return makeexpr_name("MEML", tp_integer);
ex = p_expr(tp_integer);
if (curtok == TOK_COLON) {
gettok();
ex2 = p_expr(tp_integer);
ex = makeexpr_bicall_2("MEML", tp_integer, ex, ex2);
} else {
ex = makeexpr_bicall_1("MEML", tp_integer, ex);
}
if (!wneedtok(TOK_RBR))
skippasttotoken(TOK_RBR, TOK_SEMI);
note("Reference to MEML [191]");
return ex;
}
Expr *func_min()
{
Type *tp;
Expr *ex, *ex2;
if (!skipopenparen())
return NULL;
if (curtok == TOK_IDENT && curtokmeaning &&
curtokmeaning->kind == MK_TYPE) {
tp = curtokmeaning->type;
gettok();
skipcloseparen();
return copyexpr(tp->smin);
}
ex = p_expr(tp_integer);
while (curtok == TOK_COMMA) {
gettok();
ex2 = p_expr(ex->val.type);
if (ex->val.type->kind == TK_REAL) {
tp = ex->val.type;
if (ex2->val.type->kind != TK_REAL)
ex2 = makeexpr_cast(ex2, tp);
} else {
tp = ex2->val.type;
if (ex->val.type->kind != TK_REAL)
ex = makeexpr_cast(ex, tp);
}
ex = makeexpr_bicall_2((tp->kind == TK_REAL) ? "P_rmin" : "P_imin",
tp, ex, ex2);
}
skipcloseparen();
return ex;
}
Stmt *proc_move(ex)
Expr *ex;
{
ex->args[0] = gentle_cast(ex->args[0], tp_anyptr); /* source */
ex->args[1] = gentle_cast(ex->args[1], tp_anyptr); /* dest */
ex->args[2] = convert_size(choosetype(argbasetype(ex->args[0]),
argbasetype(ex->args[1])), ex->args[2], "MOVE");
return makestmt_call(makeexpr_bicall_3("memmove", tp_void,
ex->args[1],
ex->args[0],
makeexpr_arglong(ex->args[2], (size_t_long != 0))));
}
Stmt *proc_move_fast()
{
Expr *ex, *ex2, *ex3, *ex4;
if (!skipopenparen())
return NULL;
ex = p_expr(tp_integer);
if (!skipcomma())
return NULL;
ex2 = p_expr(tp_integer);
if (!skipcomma())
return NULL;
ord_range_expr(ex2->val.type->indextype, &ex4, NULL);
ex2 = makeexpr_index(ex2, p_expr(tp_integer), copyexpr(ex4));
if (!skipcomma())
return NULL;
ex3 = p_expr(tp_integer);
if (!skipcomma())
return NULL;
ord_range_expr(ex3->val.type->indextype, &ex4, NULL);
ex3 = makeexpr_index(ex3, p_expr(tp_integer), copyexpr(ex4));
skipcloseparen();
ex = convert_size(choosetype(argbasetype(ex2),
argbasetype(ex3)), ex, "MOVE_FAST");
return makestmt_call(makeexpr_bicall_3("memmove", tp_void,
makeexpr_addr(ex3),
makeexpr_addr(ex2),
makeexpr_arglong(ex, (size_t_long != 0))));
}
Stmt *proc_new()
{
Expr *ex, *ex2;
Stmt *sp, **spp;
Type *type;
char *name, *name2 = NULL, vbuf[1000];
if (!skipopenparen())
return NULL;
ex = p_expr(tp_anyptr);
type = ex->val.type;
if (type->kind == TK_POINTER)
type = type->basetype;
parse_special_variant(type, vbuf);
skipcloseparen();
name = find_special_variant(vbuf, NULL, specialmallocs, 3);
if (!name) {
name2 = find_special_variant(vbuf, NULL, specialsizeofs, 3);
if (!name2) {
name = find_special_variant(vbuf, NULL, specialmallocs, 1);
name2 = find_special_variant(vbuf, NULL, specialsizeofs, 1);
if (name || !name2)
name = find_special_variant(vbuf, "SpecialMalloc", specialmallocs, 1);
else
name2 = find_special_variant(vbuf, "SpecialSizeOf", specialsizeofs, 1);
}
}
if (name) {
ex2 = makeexpr_bicall_0(name, ex->val.type);
} else if (name2) {
ex2 = makeexpr_bicall_1(mallocname, tp_anyptr, pc_expr_str(name2));
} else {
ex2 = makeexpr_bicall_1(mallocname, tp_anyptr,
makeexpr_sizeof(makeexpr_type(type), 1));
}
sp = makestmt_assign(copyexpr(ex), ex2);
if (malloccheck) {
sp = makestmt_seq(sp, makestmt_if(makeexpr_rel(EK_EQ,
copyexpr(ex),
makeexpr_nil()),
makestmt_call(makeexpr_bicall_0(name_OUTMEM, tp_int)),
NULL));
}
spp = &sp->next;
while (*spp)
spp = &(*spp)->next;
if (type->kind == TK_RECORD)
initfilevars(type->fbase, &spp, makeexpr_hat(copyexpr(ex), 0));
else if (isfiletype(type))
sp = makestmt_seq(sp, makestmt_assign(makeexpr_hat(copyexpr(ex), 0),
makeexpr_nil()));
freeexpr(ex);
return sp;
}
Expr *func_oct()
{
return handle_vax_hex(NULL, "o", 3);
}
Expr *func_octal(ex)
Expr *ex;
{
char *cp;
ex = grabarg(ex, 0);
if (ex->kind == EK_CONST) {
cp = getstring(ex);
ex = makeexpr_long(my_strtol(cp, NULL, 8));
insertarg(&ex, 0, makeexpr_name("0%lo", tp_integer));
return ex;
} else {
return makeexpr_bicall_3("strtol", tp_integer,
ex, makeexpr_nil(), makeexpr_long(8));
}
}
Expr *func_odd(ex)
Expr *ex;
{
ex = makeexpr_unlongcast(grabarg(ex, 0));
if (*oddname)
return makeexpr_bicall_1(oddname, tp_boolean, ex);
else
return makeexpr_bin(EK_BAND, tp_boolean, ex, makeexpr_long(1));
}
Stmt *proc_open()
{
return handleopen(2);
}
Expr *func_ord()
{
Expr *ex;
if (wneedtok(TOK_LPAR)) {
ex = p_ord_expr();
skipcloseparen();
} else
ex = p_ord_expr();
return makeexpr_ord(ex);
}
Expr *func_ord4()
{
Expr *ex;
if (wneedtok(TOK_LPAR)) {
ex = p_ord_expr();
skipcloseparen();
} else
ex = p_ord_expr();
return makeexpr_longcast(makeexpr_ord(ex), 1);
}
Expr *func_pad(ex)
Expr *ex;
{
if (checkconst(ex->args[1], 0) || /* "s" is null string */
checkconst(ex->args[2], ' ')) {
return makeexpr_bicall_4("sprintf", tp_strptr, ex->args[0],
makeexpr_string("%*s"),
makeexpr_longcast(ex->args[3], 0),
makeexpr_string(""));
}
return makeexpr_bicall_4(strpadname, tp_strptr,
ex->args[0], ex->args[1], ex->args[2],
makeexpr_arglong(ex->args[3], 0));
}
Stmt *proc_page()
{
Expr *fex, *ex;
if (curtok == TOK_LPAR) {
fex = p_parexpr(tp_text);
ex = makeexpr_bicall_2("fprintf", tp_int,
copyexpr(fex),
makeexpr_string("\f"));
} else {
fex = makeexpr_var(mp_output);
ex = makeexpr_bicall_1("printf", tp_int,
makeexpr_string("\f"));
}
if (FCheck(checkfilewrite)) {
ex = makeexpr_bicall_2("~SETIO", tp_void,
makeexpr_rel(EK_GE, ex, makeexpr_long(0)),
makeexpr_name(filewriteerrorname, tp_int));
}
return wrapopencheck(makestmt_call(ex), fex);
}
Expr *func_paramcount(ex)
Expr *ex;
{
freeexpr(ex);
return makeexpr_minus(makeexpr_name(name_ARGC, tp_int),
makeexpr_long(1));
}
Expr *func_paramstr(ex)
Expr *ex;
{
Expr *ex2;
ex2 = makeexpr_index(makeexpr_name(name_ARGV,
makepointertype(tp_strptr)),
makeexpr_unlongcast(ex->args[1]),
makeexpr_long(0));
ex2->val.type = tp_str255;
return makeexpr_bicall_3("sprintf", tp_strptr,
ex->args[0],
makeexpr_string("%s"),
ex2);
}
Expr *func_pi()
{
return makeexpr_name("M_PI", tp_longreal);
}
Expr *var_port()
{
Expr *ex;
if (!wneedtok(TOK_LBR))
return makeexpr_name("PORT", tp_integer);
ex = p_expr(tp_integer);
if (!wneedtok(TOK_RBR))
skippasttotoken(TOK_RBR, TOK_SEMI);
note("Reference to PORT [191]");
return makeexpr_bicall_1("PORT", tp_ubyte, ex);
}
Expr *var_portw()
{
Expr *ex;
if (!wneedtok(TOK_LBR))
return makeexpr_name("PORTW", tp_integer);
ex = p_expr(tp_integer);
if (!wneedtok(TOK_RBR))
skippasttotoken(TOK_RBR, TOK_SEMI);
note("Reference to PORTW [191]");
return makeexpr_bicall_1("PORTW", tp_ushort, ex);
}
Expr *func_pos(ex)
Expr *ex;
{
char *cp;
cp = strposname;
if (!*cp) {
note("POS function used [192]");
cp = "POS";
}
return makeexpr_bicall_3(cp, tp_int,
ex->args[1],
ex->args[0],
makeexpr_long(1));
}
Expr *func_ptr(ex)
Expr *ex;
{
note("PTR function was used [193]");
return ex;
}
Expr *func_position()
{
return file_iofunc(2, seek_base);
}
Expr *func_pred()
{
Expr *ex;
if (wneedtok(TOK_LPAR)) {
ex = p_ord_expr();
skipcloseparen();
} else
ex = p_ord_expr();
#if 1
ex = makeexpr_inc(ex, makeexpr_long(-1));
#else
ex = makeexpr_cast(makeexpr_plus(ex, makeexpr_long(-1)), ex->val.type);
#endif
return ex;
}
Stmt *proc_put()
{
Expr *ex;
Type *type;
if (curtok == TOK_LPAR)
ex = p_parexpr(tp_text);
else
ex = makeexpr_var(mp_output);
requirefilebuffer(ex);
type = ex->val.type;
if (isfiletype(type) && *charputname &&
type->basetype->basetype->kind == TK_CHAR)
return makestmt_call(makeexpr_bicall_1(charputname, tp_void, ex));
else if (isfiletype(type) && *arrayputname &&
type->basetype->basetype->kind == TK_ARRAY)
return makestmt_call(makeexpr_bicall_2(arrayputname, tp_void, ex,
makeexpr_type(type->basetype->basetype)));
else
return makestmt_call(makeexpr_bicall_2(putname, tp_void, ex,
makeexpr_type(type->basetype->basetype)));
}
Expr *func_pwroften(ex)
Expr *ex;
{
return makeexpr_bicall_2("pow", tp_longreal,
makeexpr_real("10.0"), grabarg(ex, 0));
}
Stmt *proc_reset()
{
return handleopen(0);
}
Stmt *proc_rewrite()
{
return handleopen(1);
}
Stmt *doseek(fex, ex)
Expr *fex, *ex;
{
Expr *ex2;
Type *basetype = fex->val.type->basetype->basetype;
if (ansiC == 1)
ex2 = makeexpr_name("SEEK_SET", tp_int);
else
ex2 = makeexpr_long(0);
ex = makeexpr_bicall_3("fseek", tp_int,
copyexpr(fex),
makeexpr_arglong(
makeexpr_times(makeexpr_minus(ex,
makeexpr_long(seek_base)),
makeexpr_sizeof(makeexpr_type(basetype), 0)),
1),
ex2);
if (FCheck(checkfileseek)) {
ex = makeexpr_bicall_2("~SETIO", tp_void,
makeexpr_rel(EK_EQ, ex, makeexpr_long(0)),
makeexpr_name(endoffilename, tp_int));
}
return makestmt_call(ex);
}
Expr *makegetchar(fex)
Expr *fex;
{
if (isvar(fex, mp_input))
return makeexpr_bicall_0("getchar", tp_char);
else
return makeexpr_bicall_1("getc", tp_char, copyexpr(fex));
}
Stmt *fixscanf(sp, fex)
Stmt *sp;
Expr *fex;
{
int nargs, i, isstrread;
char *cp;
Expr *ex;
Stmt *sp2;
isstrread = (fex->val.type->kind == TK_STRING);
if (sp->kind == SK_ASSIGN && sp->exp1->kind == EK_BICALL &&
!strcmp(sp->exp1->val.s, "scanf")) {
if (sp->exp1->args[0]->kind == EK_CONST &&
!(sp->exp1->args[0]->val.i&1) && !isstrread) {
cp = sp->exp1->args[0]->val.s; /* scanf("%c%c") -> getchar;getchar */
for (i = 0; cp[i] == '%' && cp[i+1] == 'c'; ) {
i += 2;
if (i == sp->exp1->args[0]->val.i) {
sp2 = NULL;
for (i = 1; i < sp->exp1->nargs; i++) {
ex = makeexpr_hat(sp->exp1->args[i], 0);
sp2 = makestmt_seq(sp2,
makestmt_assign(copyexpr(ex),
makegetchar(fex)));
if (checkeof(fex)) {
sp2 = makestmt_seq(sp2,
makestmt_call(makeexpr_bicall_2("~SETIO", tp_void,
makeexpr_rel(EK_NE,
ex,
makeexpr_name("EOF", tp_char)),
makeexpr_name(endoffilename, tp_int))));
} else
freeexpr(ex);
}
return sp2;
}
}
}
nargs = sp->exp1->nargs - 1;
if (isstrread) {
strchange(&sp->exp1->val.s, "sscanf");
insertarg(&sp->exp1, 0, copyexpr(fex));
} else if (!isvar(fex, mp_input)) {
strchange(&sp->exp1->val.s, "fscanf");
insertarg(&sp->exp1, 0, copyexpr(fex));
}
if (FCheck(checkreadformat)) {
if (checkeof(fex) && !isstrread)
ex = makeexpr_cond(makeexpr_rel(EK_NE,
makeexpr_bicall_1("feof", tp_int, copyexpr(fex)),
makeexpr_long(0)),
makeexpr_name(endoffilename, tp_int),
makeexpr_name(badinputformatname, tp_int));
else
ex = makeexpr_name(badinputformatname, tp_int);
sp->exp1 = makeexpr_bicall_2("~SETIO", tp_void,
makeexpr_rel(EK_EQ,
sp->exp1,
makeexpr_long(nargs)),
ex);
} else if (checkeof(fex) && !isstrread) {
sp->exp1 = makeexpr_bicall_2("~SETIO", tp_void,
makeexpr_rel(EK_NE,
sp->exp1,
makeexpr_name("EOF", tp_int)),
makeexpr_name(endoffilename, tp_int));
}
}
return sp;
}