| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/BIF.C,v 1.4 1999/07/11 00:46:29 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include <ctype.h> |
| 26 |
#include <string.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include <math.h> |
| 30 |
#include <time.h> |
| 31 |
#include "os.h" |
| 32 |
#include "std.h" |
| 33 |
#include "bif.h" |
| 34 |
#include "tio.h" |
| 35 |
#include "run.h" |
| 36 |
#include "voc.h" |
| 37 |
#include "fio.h" |
| 38 |
#include "dbg.h" |
| 39 |
#include "prp.h" |
| 40 |
#include "lst.h" |
| 41 |
#include "trd.h" |
| 42 |
#include "regex.h" |
| 43 |
#include "res.h" |
| 44 |
#include "cmap.h" |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
void bifyon(bifcxdef *ctx, int argc) |
| 49 |
{ |
| 50 |
char rsp[128]; |
| 51 |
char *p; |
| 52 |
runsdef val; |
| 53 |
char yesbuf[64]; |
| 54 |
char nobuf[64]; |
| 55 |
re_context rectx; |
| 56 |
int match_yes; |
| 57 |
int match_no; |
| 58 |
|
| 59 |
bifcntargs(ctx, 0, argc); |
| 60 |
|
| 61 |
|
| 62 |
if (os_get_str_rsc(RESID_YORN_YES, yesbuf, sizeof(yesbuf))) |
| 63 |
strcpy(yesbuf, "[Yy].*"); |
| 64 |
if (os_get_str_rsc(RESID_YORN_NO, nobuf, sizeof(nobuf))) |
| 65 |
strcpy(nobuf, "[Nn].*"); |
| 66 |
|
| 67 |
|
| 68 |
if (tio_is_html_mode()) |
| 69 |
tioputs(ctx->bifcxtio, "<font face='TADS-Input'>"); |
| 70 |
|
| 71 |
|
| 72 |
tioflushn(ctx->bifcxtio, 0); |
| 73 |
|
| 74 |
|
| 75 |
tioreset(ctx->bifcxtio); |
| 76 |
|
| 77 |
|
| 78 |
if (tiogets(ctx->bifcxtio, (char *)0, rsp, (int)sizeof(rsp))) |
| 79 |
runsig(ctx->bifcxrun, ERR_RUNQUIT); |
| 80 |
|
| 81 |
|
| 82 |
if (tio_is_html_mode()) |
| 83 |
tioputs(ctx->bifcxtio, "</font>"); |
| 84 |
|
| 85 |
|
| 86 |
for (p = rsp ; t_isspace(*p) ; ++p) ; |
| 87 |
|
| 88 |
|
| 89 |
re_init(&rectx, ctx->bifcxerr); |
| 90 |
|
| 91 |
|
| 92 |
match_yes = re_compile_and_match(&rectx, yesbuf, strlen(yesbuf), |
| 93 |
p, strlen(p)); |
| 94 |
|
| 95 |
|
| 96 |
match_no = re_compile_and_match(&rectx, nobuf, strlen(nobuf), |
| 97 |
p, strlen(p)); |
| 98 |
|
| 99 |
|
| 100 |
if (match_yes == (int)strlen(p)) |
| 101 |
val.runsv.runsvnum = 1; |
| 102 |
else if (match_no == (int)strlen(p)) |
| 103 |
val.runsv.runsvnum = 0; |
| 104 |
else |
| 105 |
val.runsv.runsvnum = -1; |
| 106 |
|
| 107 |
|
| 108 |
re_delete(&rectx); |
| 109 |
|
| 110 |
|
| 111 |
runpush(ctx->bifcxrun, DAT_NUMBER, &val); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
void bifsfs(bifcxdef *ctx, int argc) |
| 116 |
{ |
| 117 |
objnum func; |
| 118 |
uint tm; |
| 119 |
runsdef val; |
| 120 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 121 |
|
| 122 |
bifcntargs(ctx, 3, argc); |
| 123 |
func = runpopfn(ctx->bifcxrun); |
| 124 |
tm = runpopnum(ctx->bifcxrun); |
| 125 |
runpop(ctx->bifcxrun, &val); |
| 126 |
|
| 127 |
|
| 128 |
if (val.runstyp == DAT_LIST || val.runstyp == DAT_SSTRING) |
| 129 |
runsig(ctx->bifcxrun, ERR_FUSEVAL); |
| 130 |
|
| 131 |
vocsetfd(voc, voc->voccxfus, func, (prpnum)0, |
| 132 |
tm, &val, ERR_MANYFUS); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
void bifrfs(bifcxdef *ctx, int argc) |
| 137 |
{ |
| 138 |
objnum func; |
| 139 |
runsdef val; |
| 140 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 141 |
|
| 142 |
bifcntargs(ctx, 2, argc); |
| 143 |
func = runpopfn(ctx->bifcxrun); |
| 144 |
runpop(ctx->bifcxrun, &val); |
| 145 |
vocremfd(voc, voc->voccxfus, func, (prpnum)0, |
| 146 |
&val, ERR_NOFUSE); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
void bifsdm(bifcxdef *ctx, int argc) |
| 151 |
{ |
| 152 |
objnum func; |
| 153 |
runsdef val; |
| 154 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 155 |
|
| 156 |
bifcntargs(ctx, 2, argc); |
| 157 |
func = runpopfn(ctx->bifcxrun); |
| 158 |
runpop(ctx->bifcxrun, &val); |
| 159 |
|
| 160 |
|
| 161 |
if (val.runstyp == DAT_LIST || val.runstyp == DAT_SSTRING) |
| 162 |
runsig(ctx->bifcxrun, ERR_FUSEVAL); |
| 163 |
|
| 164 |
vocsetfd(voc, voc->voccxdmn, func, (prpnum)0, 0, |
| 165 |
&val, ERR_MANYDMN); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
void bifrdm(bifcxdef *ctx, int argc) |
| 170 |
{ |
| 171 |
objnum func; |
| 172 |
runsdef val; |
| 173 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 174 |
|
| 175 |
bifcntargs(ctx, 2, argc); |
| 176 |
func = runpopfn(ctx->bifcxrun); |
| 177 |
runpop(ctx->bifcxrun, &val); |
| 178 |
vocremfd(voc, voc->voccxdmn, func, (prpnum)0, |
| 179 |
&val, ERR_NODMN); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
void bifinc(bifcxdef *ctx, int argc) |
| 184 |
{ |
| 185 |
int turncnt; |
| 186 |
|
| 187 |
if (argc == 1) |
| 188 |
{ |
| 189 |
|
| 190 |
turncnt = runpopnum(ctx->bifcxrun); |
| 191 |
if (turncnt < 1) |
| 192 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "incturn"); |
| 193 |
} |
| 194 |
else |
| 195 |
{ |
| 196 |
|
| 197 |
bifcntargs(ctx, 0, argc); |
| 198 |
turncnt = 1; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
vocturn(ctx->bifcxrun->runcxvoc, turncnt, TRUE); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
void bifskt(bifcxdef *ctx, int argc) |
| 207 |
{ |
| 208 |
int turncnt; |
| 209 |
|
| 210 |
bifcntargs(ctx, 1, argc); |
| 211 |
turncnt = runpopnum(ctx->bifcxrun); |
| 212 |
if (turncnt < 1) |
| 213 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "skipturn"); |
| 214 |
vocturn(ctx->bifcxrun->runcxvoc, turncnt, FALSE); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
void bifqui(bifcxdef *ctx, int argc) |
| 219 |
{ |
| 220 |
|
| 221 |
bifcntargs(ctx, 0, argc); |
| 222 |
|
| 223 |
|
| 224 |
tioflush(ctx->bifcxtio); |
| 225 |
errsig(ctx->bifcxerr, ERR_RUNQUIT); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
static void bifcstr(bifcxdef *ctx, char *buf, size_t bufsiz, uchar *str) |
| 230 |
{ |
| 231 |
size_t srcrem; |
| 232 |
size_t dstrem; |
| 233 |
uchar *src; |
| 234 |
char *dst; |
| 235 |
|
| 236 |
|
| 237 |
srcrem = osrp2(str) - 2; |
| 238 |
str += 2; |
| 239 |
|
| 240 |
|
| 241 |
for (src = str, dst = buf, dstrem = bufsiz ; |
| 242 |
srcrem != 0 && dstrem != 0 ; ++src, --srcrem) |
| 243 |
{ |
| 244 |
|
| 245 |
if (*src == '\\') |
| 246 |
{ |
| 247 |
|
| 248 |
++src; |
| 249 |
--srcrem; |
| 250 |
|
| 251 |
|
| 252 |
if (srcrem == 0) |
| 253 |
{ |
| 254 |
|
| 255 |
*dst++ = '\\'; |
| 256 |
--dstrem; |
| 257 |
|
| 258 |
|
| 259 |
break; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
switch(*src) |
| 264 |
{ |
| 265 |
case 'n': |
| 266 |
|
| 267 |
*dst++ = '\n'; |
| 268 |
--dstrem; |
| 269 |
break; |
| 270 |
|
| 271 |
case 't': |
| 272 |
|
| 273 |
*dst++ = '\t'; |
| 274 |
--dstrem; |
| 275 |
break; |
| 276 |
|
| 277 |
case '(': |
| 278 |
case ')': |
| 279 |
|
| 280 |
break; |
| 281 |
|
| 282 |
default: |
| 283 |
|
| 284 |
*dst++ = *src; |
| 285 |
--dstrem; |
| 286 |
break; |
| 287 |
} |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
|
| 292 |
*dst++ = *src; |
| 293 |
--dstrem; |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
if (dstrem == 0) |
| 299 |
runsig(ctx->bifcxrun, ERR_BIFCSTR); |
| 300 |
|
| 301 |
|
| 302 |
*dst = '\0'; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
void bifsav(bifcxdef *ctx, int argc) |
| 307 |
{ |
| 308 |
uchar *fn; |
| 309 |
char buf[OSFNMAX]; |
| 310 |
int err; |
| 311 |
runsdef val; |
| 312 |
|
| 313 |
bifcntargs(ctx, 1, argc); |
| 314 |
fn = runpopstr(ctx->bifcxrun); |
| 315 |
bifcstr(ctx, buf, (size_t)sizeof(buf), fn); |
| 316 |
os_defext(buf, ctx->bifcxsavext != 0 ? ctx->bifcxsavext : "sav"); |
| 317 |
err = fiosav(ctx->bifcxrun->runcxvoc, buf, ctx->bifcxrun->runcxgamename); |
| 318 |
runpush(ctx->bifcxrun, runclog(err), &val); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
void bifrso(bifcxdef *ctx, int argc) |
| 323 |
{ |
| 324 |
uchar *fn; |
| 325 |
char buf[OSFNMAX]; |
| 326 |
int err; |
| 327 |
voccxdef *vctx = ctx->bifcxrun->runcxvoc; |
| 328 |
|
| 329 |
bifcntargs(ctx, 1, argc); |
| 330 |
|
| 331 |
|
| 332 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 333 |
{ |
| 334 |
|
| 335 |
if (!os_paramfile(buf)) |
| 336 |
{ |
| 337 |
|
| 338 |
runpnum(ctx->bifcxrun, FIORSO_NO_PARAM_FILE); |
| 339 |
return; |
| 340 |
} |
| 341 |
} |
| 342 |
else |
| 343 |
{ |
| 344 |
|
| 345 |
fn = runpopstr(ctx->bifcxrun); |
| 346 |
bifcstr(ctx, buf, (size_t)sizeof(buf), fn); |
| 347 |
os_defext(buf, ctx->bifcxsavext != 0 ? ctx->bifcxsavext : "sav"); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
err = fiorso(vctx, buf); |
| 352 |
|
| 353 |
|
| 354 |
objulose(vctx->voccxundo); |
| 355 |
|
| 356 |
|
| 357 |
runpnum(ctx->bifcxrun, err); |
| 358 |
|
| 359 |
|
| 360 |
vctx->voccxflg |= VOCCXFCLEAR; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
void biflog(bifcxdef *ctx, int argc) |
| 365 |
{ |
| 366 |
char buf[OSFNMAX]; |
| 367 |
uchar *str; |
| 368 |
|
| 369 |
bifcntargs(ctx, 1, argc); |
| 370 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 371 |
{ |
| 372 |
rundisc(ctx->bifcxrun); |
| 373 |
tiologcls(ctx->bifcxtio); |
| 374 |
} |
| 375 |
else |
| 376 |
{ |
| 377 |
str = runpopstr(ctx->bifcxrun); |
| 378 |
bifcstr(ctx, buf, (size_t)sizeof(buf), str); |
| 379 |
tiologopn(ctx->bifcxtio, buf); |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
void bifres(bifcxdef *ctx, int argc) |
| 385 |
{ |
| 386 |
voccxdef *vctx = ctx->bifcxrun->runcxvoc; |
| 387 |
objnum fn; |
| 388 |
|
| 389 |
if (argc == 2) |
| 390 |
fn = runpopfn(ctx->bifcxrun); |
| 391 |
else |
| 392 |
{ |
| 393 |
bifcntargs(ctx, 0, argc); |
| 394 |
fn = MCMONINV; |
| 395 |
} |
| 396 |
|
| 397 |
objulose(vctx->voccxundo); |
| 398 |
vocrevert(vctx); |
| 399 |
vocdmnclr(vctx); |
| 400 |
|
| 401 |
|
| 402 |
vctx->voccxme = vctx->voccxme_init; |
| 403 |
|
| 404 |
|
| 405 |
if (vctx->voccxpreinit != MCMONINV) |
| 406 |
runfn(ctx->bifcxrun, vctx->voccxpreinit, 0); |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
if (fn != MCMONINV) runfn(ctx->bifcxrun, fn, 1); |
| 414 |
|
| 415 |
|
| 416 |
errsig(ctx->bifcxerr, ERR_RUNRESTART); |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
void bifinp(bifcxdef *ctx, int argc) |
| 421 |
{ |
| 422 |
char inbuf[128]; |
| 423 |
|
| 424 |
|
| 425 |
bifcntargs(ctx, 0, argc); |
| 426 |
|
| 427 |
|
| 428 |
tioflushn(ctx->bifcxtio, 0); |
| 429 |
|
| 430 |
|
| 431 |
tioreset(ctx->bifcxtio); |
| 432 |
|
| 433 |
|
| 434 |
if (tiogets(ctx->bifcxtio, (char *)0, inbuf, (int)sizeof(inbuf))) |
| 435 |
runsig(ctx->bifcxrun, ERR_RUNQUIT); |
| 436 |
|
| 437 |
|
| 438 |
runpushcstr(ctx->bifcxrun, inbuf, strlen(inbuf), 0); |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
void bifnfy(bifcxdef *ctx, int argc) |
| 443 |
{ |
| 444 |
objnum objn; |
| 445 |
prpnum prp; |
| 446 |
uint tm; |
| 447 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 448 |
|
| 449 |
bifcntargs(ctx, 3, argc); |
| 450 |
objn = runpopobj(ctx->bifcxrun); |
| 451 |
prp = runpopprp(ctx->bifcxrun); |
| 452 |
tm = runpopnum(ctx->bifcxrun); |
| 453 |
|
| 454 |
|
| 455 |
if (tm == 0) |
| 456 |
tm = VOCDTIM_EACH_TURN; |
| 457 |
|
| 458 |
vocsetfd(voc, voc->voccxalm, objn, prp, tm, |
| 459 |
(runsdef *)0, ERR_MANYNFY); |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
void bifunn(bifcxdef *ctx, int argc) |
| 465 |
{ |
| 466 |
objnum objn; |
| 467 |
prpnum prop; |
| 468 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 469 |
|
| 470 |
bifcntargs(ctx, 2, argc); |
| 471 |
objn = runpopobj(ctx->bifcxrun); |
| 472 |
prop = runpopprp(ctx->bifcxrun); |
| 473 |
vocremfd(voc, voc->voccxalm, objn, prop, |
| 474 |
(runsdef *)0, ERR_NONFY); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
void biftrc(bifcxdef *ctx, int argc) |
| 479 |
{ |
| 480 |
runsdef val; |
| 481 |
int n; |
| 482 |
int flag; |
| 483 |
|
| 484 |
if (argc == 2) |
| 485 |
{ |
| 486 |
|
| 487 |
n = runpopnum(ctx->bifcxrun); |
| 488 |
flag = runpoplog(ctx->bifcxrun); |
| 489 |
|
| 490 |
|
| 491 |
switch(n) |
| 492 |
{ |
| 493 |
case 1: |
| 494 |
|
| 495 |
if (flag) |
| 496 |
ctx->bifcxrun->runcxvoc->voccxflg |= VOCCXFDBG; |
| 497 |
else |
| 498 |
ctx->bifcxrun->runcxvoc->voccxflg &= ~VOCCXFDBG; |
| 499 |
break; |
| 500 |
|
| 501 |
default: |
| 502 |
|
| 503 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "debugTrace"); |
| 504 |
} |
| 505 |
} |
| 506 |
else |
| 507 |
{ |
| 508 |
|
| 509 |
bifcntargs(ctx, 0, argc); |
| 510 |
runpush(ctx->bifcxrun, runclog(dbgstart(ctx->bifcxrun->runcxdbg)), |
| 511 |
&val); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
void bifsay(bifcxdef *ctx, int argc) |
| 517 |
{ |
| 518 |
uchar *str; |
| 519 |
long num; |
| 520 |
char numbuf[30]; |
| 521 |
|
| 522 |
if (argc != 2) bifcntargs(ctx, 1, argc); |
| 523 |
|
| 524 |
switch(runtostyp(ctx->bifcxrun)) |
| 525 |
{ |
| 526 |
case DAT_NUMBER: |
| 527 |
num = runpopnum(ctx->bifcxrun); |
| 528 |
sprintf(numbuf, "%ld", num); |
| 529 |
tioputs(ctx->bifcxtio, numbuf); |
| 530 |
break; |
| 531 |
|
| 532 |
case DAT_SSTRING: |
| 533 |
str = runpopstr(ctx->bifcxrun); |
| 534 |
outfmt(ctx->bifcxtio, str); |
| 535 |
break; |
| 536 |
|
| 537 |
case DAT_NIL: |
| 538 |
(void)runpoplog(ctx->bifcxrun); |
| 539 |
break; |
| 540 |
|
| 541 |
default: |
| 542 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "say"); |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
void bifcar(bifcxdef *ctx, int argc) |
| 548 |
{ |
| 549 |
uchar *lstp; |
| 550 |
uint lstsiz; |
| 551 |
runsdef val; |
| 552 |
|
| 553 |
bifcntargs(ctx, 1, argc); |
| 554 |
bifchkarg(ctx, DAT_LIST); |
| 555 |
|
| 556 |
lstp = runpoplst(ctx->bifcxrun); |
| 557 |
|
| 558 |
|
| 559 |
lstsiz = osrp2(lstp) - 2; |
| 560 |
lstp += 2; |
| 561 |
|
| 562 |
|
| 563 |
if (lstsiz) |
| 564 |
runpbuf(ctx->bifcxrun, *lstp, lstp+1); |
| 565 |
else |
| 566 |
runpush(ctx->bifcxrun, DAT_NIL, &val); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
void bifcdr(bifcxdef *ctx, int argc) |
| 571 |
{ |
| 572 |
uchar *lstp; |
| 573 |
uint siz; |
| 574 |
uint lstsiz; |
| 575 |
runsdef val; |
| 576 |
runsdef stkval; |
| 577 |
|
| 578 |
bifcntargs(ctx, 1, argc); |
| 579 |
bifchkarg(ctx, DAT_LIST); |
| 580 |
|
| 581 |
lstp = runpoplst(ctx->bifcxrun); |
| 582 |
stkval.runstyp = DAT_LIST; |
| 583 |
stkval.runsv.runsvstr = lstp; |
| 584 |
|
| 585 |
|
| 586 |
lstsiz = osrp2(lstp) - 2; |
| 587 |
lstp += 2; |
| 588 |
|
| 589 |
if (lstsiz != 0) |
| 590 |
{ |
| 591 |
|
| 592 |
siz = datsiz(*lstp, lstp+1) + 1; |
| 593 |
lstsiz -= siz; |
| 594 |
|
| 595 |
|
| 596 |
lstsiz += 2; |
| 597 |
|
| 598 |
|
| 599 |
runhres1(ctx->bifcxrun, lstsiz, 1, &stkval); |
| 600 |
lstp = stkval.runsv.runsvstr + siz + 2; |
| 601 |
|
| 602 |
|
| 603 |
oswp2(ctx->bifcxrun->runcxhp, lstsiz); |
| 604 |
memcpy(ctx->bifcxrun->runcxhp+2, lstp, (size_t)(lstsiz-2)); |
| 605 |
|
| 606 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 607 |
val.runstyp = DAT_LIST; |
| 608 |
ctx->bifcxrun->runcxhp += lstsiz; |
| 609 |
runrepush(ctx->bifcxrun, &val); |
| 610 |
} |
| 611 |
else |
| 612 |
runpush(ctx->bifcxrun, DAT_NIL, &val); |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
void bifcap(bifcxdef *ctx, int argc) |
| 617 |
{ |
| 618 |
bifcntargs(ctx, 0, argc); |
| 619 |
tiocaps(ctx->bifxtio); |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
void bifnoc(bifcxdef *ctx, int argc) |
| 624 |
{ |
| 625 |
bifcntargs(ctx, 0, argc); |
| 626 |
tionocaps(ctx->bifxtio); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
void biflen(bifcxdef *ctx, int argc) |
| 631 |
{ |
| 632 |
uchar *p; |
| 633 |
runsdef val; |
| 634 |
long len; |
| 635 |
int l; |
| 636 |
|
| 637 |
bifcntargs(ctx, 1, argc); |
| 638 |
switch(runtostyp(ctx->bifcxrun)) |
| 639 |
{ |
| 640 |
case DAT_SSTRING: |
| 641 |
p = (uchar *)runpopstr(ctx->bifcxrun); |
| 642 |
len = osrp2(p) - 2; |
| 643 |
break; |
| 644 |
|
| 645 |
case DAT_LIST: |
| 646 |
p = runpoplst(ctx->bifcxrun); |
| 647 |
l = osrp2(p) - 2; |
| 648 |
p += 2; |
| 649 |
|
| 650 |
|
| 651 |
for (len = 0 ; l ; ++len) |
| 652 |
{ |
| 653 |
int cursiz; |
| 654 |
|
| 655 |
|
| 656 |
cursiz = datsiz(*p, p+1) + 1; |
| 657 |
l -= cursiz; |
| 658 |
p += cursiz; |
| 659 |
} |
| 660 |
break; |
| 661 |
|
| 662 |
default: |
| 663 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "length"); |
| 664 |
} |
| 665 |
|
| 666 |
val.runsv.runsvnum = len; |
| 667 |
runpush(ctx->bifcxrun, DAT_NUMBER, &val); |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
void biffnd(bifcxdef *ctx, int argc) |
| 672 |
{ |
| 673 |
uchar *p1, *p2; |
| 674 |
int len1, len2; |
| 675 |
int outv; |
| 676 |
runsdef val; |
| 677 |
int typ; |
| 678 |
int siz; |
| 679 |
|
| 680 |
bifcntargs(ctx, 2, argc); |
| 681 |
switch(runtostyp(ctx->bifcxrun)) |
| 682 |
{ |
| 683 |
case DAT_SSTRING: |
| 684 |
p1 = runpopstr(ctx->bifcxrun); |
| 685 |
len1 = osrp2(p1) - 2; |
| 686 |
p1 += 2; |
| 687 |
|
| 688 |
p2 = runpopstr(ctx->bifcxrun); |
| 689 |
len2 = osrp2(p2) - 2; |
| 690 |
p2 += 2; |
| 691 |
|
| 692 |
|
| 693 |
for (typ = DAT_NIL, outv = 1 ; len1 >= len2 ; ++p1, --len1, ++outv) |
| 694 |
{ |
| 695 |
if (!memcmp(p1, p2, (size_t)len2)) |
| 696 |
{ |
| 697 |
typ = DAT_NUMBER; |
| 698 |
break; |
| 699 |
} |
| 700 |
} |
| 701 |
break; |
| 702 |
|
| 703 |
case DAT_LIST: |
| 704 |
p1 = runpoplst(ctx->bifcxrun); |
| 705 |
len1 = osrp2(p1) - 2; |
| 706 |
p1 += 2; |
| 707 |
|
| 708 |
|
| 709 |
runpop(ctx->bifcxrun, &val); |
| 710 |
|
| 711 |
for (typ = DAT_NIL, outv = 1 ; len1 ; ++outv, p1 += siz, len1 -= siz) |
| 712 |
{ |
| 713 |
siz = datsiz(*p1, p1 + 1) + 1; |
| 714 |
if (val.runstyp != *p1) continue; |
| 715 |
|
| 716 |
switch(val.runstyp) |
| 717 |
{ |
| 718 |
case DAT_NUMBER: |
| 719 |
if (val.runsv.runsvnum != osrp4s(p1 + 1)) continue; |
| 720 |
break; |
| 721 |
|
| 722 |
case DAT_SSTRING: |
| 723 |
case DAT_LIST: |
| 724 |
if (osrp2(p1 + 1) != osrp2(val.runsv.runsvstr) || |
| 725 |
memcmp(p1 + 3, val.runsv.runsvstr + 2, |
| 726 |
(size_t)(osrp2(p1 + 1) - 2))) |
| 727 |
continue; |
| 728 |
break; |
| 729 |
|
| 730 |
case DAT_PROPNUM: |
| 731 |
if (osrp2(p1 + 1) != val.runsv.runsvprp) continue; |
| 732 |
break; |
| 733 |
|
| 734 |
case DAT_OBJECT: |
| 735 |
case DAT_FNADDR: |
| 736 |
if (osrp2(p1 + 1) != val.runsv.runsvobj) continue; |
| 737 |
break; |
| 738 |
|
| 739 |
default: |
| 740 |
break; |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
typ = DAT_NUMBER; |
| 745 |
break; |
| 746 |
} |
| 747 |
break; |
| 748 |
|
| 749 |
default: |
| 750 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "find"); |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
val.runsv.runsvnum = outv; |
| 755 |
runpush(ctx->bifcxrun, typ, &val); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
void bifsit(bifcxdef *ctx, int argc) |
| 760 |
{ |
| 761 |
objnum obj; |
| 762 |
int typ; |
| 763 |
voccxdef *vcx = ctx->bifcxrun->runcxvoc; |
| 764 |
|
| 765 |
|
| 766 |
if (argc == 2) |
| 767 |
{ |
| 768 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 769 |
{ |
| 770 |
rundisc(ctx->bifcxrun); |
| 771 |
obj = MCMONINV; |
| 772 |
} |
| 773 |
else |
| 774 |
obj = runpopobj(ctx->bifcxrun); |
| 775 |
|
| 776 |
typ = runpopnum(ctx->bifcxrun); |
| 777 |
vcx->voccxthc = 0; |
| 778 |
|
| 779 |
switch(typ) |
| 780 |
{ |
| 781 |
case 0: |
| 782 |
vcx->voccxit = obj; |
| 783 |
break; |
| 784 |
|
| 785 |
case 1: |
| 786 |
vcx->voccxhim = obj; |
| 787 |
break; |
| 788 |
|
| 789 |
case 2: |
| 790 |
vcx->voccxher = obj; |
| 791 |
break; |
| 792 |
} |
| 793 |
return; |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
bifcntargs(ctx, 1, argc); |
| 798 |
|
| 799 |
|
| 800 |
if (runtostyp(ctx->bifcxrun) == DAT_LIST) |
| 801 |
{ |
| 802 |
uchar *lst; |
| 803 |
uint siz; |
| 804 |
int cnt; |
| 805 |
|
| 806 |
lst = runpoplst(ctx->bifcxrun); |
| 807 |
siz = osrp2(lst); |
| 808 |
lst += 2; |
| 809 |
siz -= 2; |
| 810 |
|
| 811 |
for (cnt = 0 ; siz ; ) |
| 812 |
{ |
| 813 |
|
| 814 |
if (*lst == DAT_OBJECT) |
| 815 |
vcx->voccxthm[cnt++] = osrp2(lst+1); |
| 816 |
|
| 817 |
lstadv(&lst, &siz); |
| 818 |
} |
| 819 |
vcx->voccxthc = cnt; |
| 820 |
vcx->voccxit = MCMONINV; |
| 821 |
} |
| 822 |
else |
| 823 |
{ |
| 824 |
|
| 825 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 826 |
{ |
| 827 |
vcx->voccxit = MCMONINV; |
| 828 |
rundisc(ctx->bifcxrun); |
| 829 |
} |
| 830 |
else |
| 831 |
vcx->voccxit = runpopobj(ctx->bifcxrun); |
| 832 |
vcx->voccxthc = 0; |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
void bifsrn(bifcxdef *ctx, int argc) |
| 838 |
{ |
| 839 |
bifcntargs(ctx, 0, argc); |
| 840 |
os_rand(&ctx->bifcxrnd); |
| 841 |
ctx->bifcxrndset = TRUE; |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
void bifrnd(bifcxdef *ctx, int argc) |
| 846 |
{ |
| 847 |
unsigned long result, max, randseed; |
| 848 |
int tmp; |
| 849 |
runsdef val; |
| 850 |
|
| 851 |
|
| 852 |
bifcntargs(ctx, 1, argc); |
| 853 |
bifchkarg(ctx, DAT_NUMBER); |
| 854 |
max = runpopnum(ctx->bifcxrun); |
| 855 |
|
| 856 |
|
| 857 |
if (max == 0) |
| 858 |
{ |
| 859 |
runpnum(ctx->bifcxrun, 0); |
| 860 |
return; |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
if (!ctx->bifcxrndset) |
| 871 |
{ |
| 872 |
|
| 873 |
randseed = ctx->bifcxrnd; |
| 874 |
randseed *= 1033; |
| 875 |
randseed += 5; |
| 876 |
tmp = randseed / 16384; |
| 877 |
randseed %= 16384; |
| 878 |
result = tmp / 7; |
| 879 |
|
| 880 |
|
| 881 |
result = ( randseed % max ) + 1; |
| 882 |
|
| 883 |
|
| 884 |
ctx->bifcxrnd = randseed; |
| 885 |
val.runsv.runsvnum = result; |
| 886 |
runpush(ctx->bifcxrun, DAT_NUMBER, &val); |
| 887 |
} |
| 888 |
else |
| 889 |
{ |
| 890 |
#define BIF_RAND_M ((ulong)2147483647) |
| 891 |
#define BIF_RAND_Q ((ulong)127773) |
| 892 |
#define BIF_RAND_A ((ulong)16807) |
| 893 |
#define BIF_RAND_R ((ulong)2836) |
| 894 |
|
| 895 |
long lo, hi, test; |
| 896 |
|
| 897 |
lo = ctx->bifcxrnd / BIF_RAND_Q; |
| 898 |
hi = ctx->bifcxrnd % BIF_RAND_Q; |
| 899 |
test = BIF_RAND_A*lo - BIF_RAND_R*hi; |
| 900 |
ctx->bifcxrnd = test; |
| 901 |
if (test > 0) |
| 902 |
ctx->bifcxrnd = test; |
| 903 |
else |
| 904 |
ctx->bifcxrnd = test + BIF_RAND_M; |
| 905 |
runpnum(ctx->bifcxrun, (((ulong)ctx->bifcxrnd) % max) + 1); |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
static char *bif_stristr(const char *s1, const char *s2) |
| 913 |
{ |
| 914 |
size_t s1len; |
| 915 |
size_t s2len; |
| 916 |
|
| 917 |
|
| 918 |
for (s1len = strlen(s1), s2len = strlen(s2) ; s1len >= s2len ; |
| 919 |
++s1, --s1len) |
| 920 |
{ |
| 921 |
|
| 922 |
if (memicmp(s1, s2, s2len) == 0) |
| 923 |
return (char *)s1; |
| 924 |
} |
| 925 |
|
| 926 |
return 0; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
#define BIF_ASKF_EXT_RET 1 |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
void bifask(bifcxdef *ctx, int argc) |
| 938 |
{ |
| 939 |
uchar *prompt; |
| 940 |
char buf[OSFNMAX + 2]; |
| 941 |
char pbuf[128]; |
| 942 |
int err; |
| 943 |
int prompt_type; |
| 944 |
int file_type; |
| 945 |
ulong flags; |
| 946 |
|
| 947 |
|
| 948 |
if (argc != 1 && argc != 3 && argc != 4) |
| 949 |
runsig(ctx->bifcxrun, ERR_BIFARGC); |
| 950 |
|
| 951 |
|
| 952 |
prompt = runpopstr(ctx->bifcxrun); |
| 953 |
bifcstr(ctx, pbuf, (size_t)sizeof(pbuf), prompt); |
| 954 |
|
| 955 |
|
| 956 |
flags = 0; |
| 957 |
|
| 958 |
|
| 959 |
if (argc >= 3) |
| 960 |
{ |
| 961 |
|
| 962 |
prompt_type = (int)runpopnum(ctx->bifcxrun); |
| 963 |
file_type = (int)runpopnum(ctx->bifcxrun); |
| 964 |
|
| 965 |
|
| 966 |
if (argc == 4) |
| 967 |
flags = runpopnum(ctx->bifcxrun); |
| 968 |
} |
| 969 |
else |
| 970 |
{ |
| 971 |
static const char *save_strs[] = |
| 972 |
{ |
| 973 |
"save", |
| 974 |
"write", |
| 975 |
0 |
| 976 |
}; |
| 977 |
const char **sp; |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
prompt_type = OS_AFP_OPEN; |
| 999 |
file_type = OSFTUNK; |
| 1000 |
|
| 1001 |
|
| 1002 |
for (sp = save_strs ; *sp != 0 ; ++sp) |
| 1003 |
{ |
| 1004 |
|
| 1005 |
if (bif_stristr(pbuf, *sp)) |
| 1006 |
{ |
| 1007 |
|
| 1008 |
prompt_type = OS_AFP_SAVE; |
| 1009 |
|
| 1010 |
|
| 1011 |
break; |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
if (bif_stristr(pbuf, "restore") || bif_stristr(pbuf, "save")) |
| 1017 |
{ |
| 1018 |
file_type = OSFTSAVE; |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
if (file_type == OSFTUNK |
| 1023 |
&& prompt_type == OS_AFP_SAVE |
| 1024 |
&& bif_stristr(pbuf, "script") != 0) |
| 1025 |
{ |
| 1026 |
|
| 1027 |
file_type = OSFTLOG; |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
err = tio_askfile(pbuf, buf, (int)sizeof(buf), prompt_type, file_type); |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
if ((flags & BIF_ASKF_EXT_RET) != 0) |
| 1040 |
{ |
| 1041 |
ushort len; |
| 1042 |
runsdef val; |
| 1043 |
uchar *p; |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
len = 2 + (1 + 4); |
| 1052 |
if (err != OS_AFE_SUCCESS) |
| 1053 |
++len; |
| 1054 |
|
| 1055 |
|
| 1056 |
runhres(ctx->bifcxrun, len, 0); |
| 1057 |
|
| 1058 |
|
| 1059 |
val.runstyp = DAT_LIST; |
| 1060 |
val.runsv.runsvstr = p = ctx->bifcxrun->runcxhp; |
| 1061 |
|
| 1062 |
|
| 1063 |
oswp2(p, len); |
| 1064 |
p += 2; |
| 1065 |
|
| 1066 |
|
| 1067 |
*p++ = DAT_NUMBER; |
| 1068 |
oswp4s(p, err); |
| 1069 |
p += 4; |
| 1070 |
|
| 1071 |
|
| 1072 |
if (err != OS_AFE_SUCCESS) |
| 1073 |
*p++ = DAT_NIL; |
| 1074 |
|
| 1075 |
|
| 1076 |
ctx->bifcxrun->runcxhp = p; |
| 1077 |
|
| 1078 |
|
| 1079 |
runrepush(ctx->bifcxrun, &val); |
| 1080 |
|
| 1081 |
|
| 1082 |
if (err == OS_AFE_SUCCESS) |
| 1083 |
{ |
| 1084 |
runsdef val2; |
| 1085 |
|
| 1086 |
|
| 1087 |
runpushcstr(ctx->bifcxrun, buf, strlen(buf), 1); |
| 1088 |
|
| 1089 |
|
| 1090 |
runpop(ctx->bifcxrun, &val2); |
| 1091 |
runpop(ctx->bifcxrun, &val); |
| 1092 |
runadd(ctx->bifcxrun, &val, &val2, 2); |
| 1093 |
|
| 1094 |
|
| 1095 |
runrepush(ctx->bifcxrun, &val); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
else |
| 1099 |
{ |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
if (err) |
| 1105 |
runpnil(ctx->bifcxrun); |
| 1106 |
else |
| 1107 |
runpushcstr(ctx->bifcxrun, buf, strlen(buf), 0); |
| 1108 |
} |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
void bifssc(bifcxdef *ctx, int argc) |
| 1113 |
{ |
| 1114 |
int s1, s2; |
| 1115 |
|
| 1116 |
|
| 1117 |
if (argc == 1 && runtostyp(ctx->bifcxrun) == DAT_SSTRING) |
| 1118 |
{ |
| 1119 |
char buf[80]; |
| 1120 |
uchar *p; |
| 1121 |
|
| 1122 |
p = runpopstr(ctx->bifcxrun); |
| 1123 |
bifcstr(ctx, buf, (size_t)sizeof(buf), p); |
| 1124 |
tiostrsc(ctx->bifcxtio, buf); |
| 1125 |
} |
| 1126 |
else |
| 1127 |
{ |
| 1128 |
|
| 1129 |
bifcntargs(ctx, 2, argc); |
| 1130 |
s1 = runpopnum(ctx->bifcxrun); |
| 1131 |
s2 = runpopnum(ctx->bifcxrun); |
| 1132 |
tioscore(ctx->bifcxtio, s1, s2); |
| 1133 |
} |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
void bifsub(bifcxdef *ctx, int argc) |
| 1138 |
{ |
| 1139 |
uchar *p; |
| 1140 |
int ofs; |
| 1141 |
int asklen; |
| 1142 |
int outlen; |
| 1143 |
int len; |
| 1144 |
|
| 1145 |
bifcntargs(ctx, 3, argc); |
| 1146 |
|
| 1147 |
|
| 1148 |
bifchkarg(ctx, DAT_SSTRING); |
| 1149 |
p = runpopstr(ctx->bifcxrun); |
| 1150 |
len = osrp2(p) - 2; |
| 1151 |
p += 2; |
| 1152 |
|
| 1153 |
|
| 1154 |
bifchkarg(ctx, DAT_NUMBER); |
| 1155 |
ofs = runpopnum(ctx->bifcxrun); |
| 1156 |
if (ofs < 1) runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "substr"); |
| 1157 |
|
| 1158 |
|
| 1159 |
bifchkarg(ctx, DAT_NUMBER); |
| 1160 |
asklen = runpopnum(ctx->bifcxrun); |
| 1161 |
if (asklen < 0) runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "substr"); |
| 1162 |
|
| 1163 |
--ofs; |
| 1164 |
p += ofs; |
| 1165 |
|
| 1166 |
if (ofs >= len) |
| 1167 |
outlen = 0; |
| 1168 |
else if (asklen > len - ofs) |
| 1169 |
outlen = len - ofs; |
| 1170 |
else |
| 1171 |
outlen = asklen; |
| 1172 |
|
| 1173 |
runpstr(ctx->bifcxrun, (char *)p, outlen, 3); |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
void bifcvs(bifcxdef *ctx, int argc) |
| 1178 |
{ |
| 1179 |
char *p; |
| 1180 |
int len; |
| 1181 |
char buf[30]; |
| 1182 |
|
| 1183 |
bifcntargs(ctx, 1, argc); |
| 1184 |
switch(runtostyp(ctx->bifcxrun)) |
| 1185 |
{ |
| 1186 |
case DAT_NIL: |
| 1187 |
p = "nil"; |
| 1188 |
len = 3; |
| 1189 |
(void)runpoplog(ctx->bifcxrun); |
| 1190 |
break; |
| 1191 |
|
| 1192 |
case DAT_TRUE: |
| 1193 |
p = "true"; |
| 1194 |
len = 4; |
| 1195 |
(void)runpoplog(ctx->bifcxrun); |
| 1196 |
break; |
| 1197 |
|
| 1198 |
case DAT_NUMBER: |
| 1199 |
sprintf(buf, "%ld", runpopnum(ctx->bifcxrun)); |
| 1200 |
p = buf; |
| 1201 |
len = strlen(buf); |
| 1202 |
break; |
| 1203 |
|
| 1204 |
case DAT_SSTRING: |
| 1205 |
|
| 1206 |
return; |
| 1207 |
|
| 1208 |
default: |
| 1209 |
|
| 1210 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "cvtstr"); |
| 1211 |
} |
| 1212 |
|
| 1213 |
runpstr(ctx->bifcxrun, p, len, 0); |
| 1214 |
} |
| 1215 |
|
| 1216 |
|
| 1217 |
void bifcvn(bifcxdef *ctx, int argc) |
| 1218 |
{ |
| 1219 |
runsdef val; |
| 1220 |
uchar *p; |
| 1221 |
int len; |
| 1222 |
int typ; |
| 1223 |
long acc; |
| 1224 |
int neg; |
| 1225 |
|
| 1226 |
bifcntargs(ctx, 1, argc); |
| 1227 |
p = runpopstr(ctx->bifcxrun); |
| 1228 |
len = osrp2(p) - 2; |
| 1229 |
p += 2; |
| 1230 |
|
| 1231 |
if (len == 3 && !memcmp(p, "nil", (size_t)3)) |
| 1232 |
typ = DAT_NIL; |
| 1233 |
else if (len == 4 && !memcmp(p, "true", (size_t)4)) |
| 1234 |
typ = DAT_TRUE; |
| 1235 |
else |
| 1236 |
{ |
| 1237 |
typ = DAT_NUMBER; |
| 1238 |
for ( ; len != 0 && t_isspace(*p) ; ++p, --len) ; |
| 1239 |
if (len != 0 && *p == '-') |
| 1240 |
{ |
| 1241 |
neg = TRUE; |
| 1242 |
for (++p, --len ; len != 0 && t_isspace(*p) ; ++p, --len) ; |
| 1243 |
} |
| 1244 |
else neg = FALSE; |
| 1245 |
|
| 1246 |
|
| 1247 |
for (acc = 0 ; len != 0 && isdigit(*p) ; ++p, --len) |
| 1248 |
acc = (acc << 3) + (acc << 1) + ((*p) - '0'); |
| 1249 |
|
| 1250 |
if (neg) acc = -acc; |
| 1251 |
val.runsv.runsvnum = acc; |
| 1252 |
} |
| 1253 |
|
| 1254 |
runpush(ctx->bifcxrun, typ, &val); |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
static void bifcvtstr(bifcxdef *ctx, void (*cvtfn)(uchar *, int), int argc) |
| 1259 |
{ |
| 1260 |
uchar *p; |
| 1261 |
int len; |
| 1262 |
runsdef val; |
| 1263 |
runsdef stkval; |
| 1264 |
|
| 1265 |
bifcntargs(ctx, 1, argc); |
| 1266 |
bifchkarg(ctx, DAT_SSTRING); |
| 1267 |
|
| 1268 |
p = runpopstr(ctx->bifcxrun); |
| 1269 |
stkval.runstyp = DAT_SSTRING; |
| 1270 |
stkval.runsv.runsvstr = p; |
| 1271 |
len = osrp2(p); |
| 1272 |
|
| 1273 |
|
| 1274 |
runhres1(ctx->bifcxrun, len, 1, &stkval); |
| 1275 |
p = stkval.runsv.runsvstr; |
| 1276 |
memcpy(ctx->bifcxrun->runcxhp, p, (size_t)len); |
| 1277 |
(*cvtfn)(ctx->bifcxrun->runcxhp + 2, len - 2); |
| 1278 |
|
| 1279 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 1280 |
val.runstyp = DAT_SSTRING; |
| 1281 |
ctx->bifcxrun->runcxhp += len; |
| 1282 |
runrepush(ctx->bifcxrun, &val); |
| 1283 |
} |
| 1284 |
|
| 1285 |
|
| 1286 |
static void bifstrupr(uchar *str, int len) |
| 1287 |
{ |
| 1288 |
for ( ; len ; --len, ++str) |
| 1289 |
{ |
| 1290 |
if (*str == '\\' && len > 1) |
| 1291 |
--len, ++str; |
| 1292 |
else if (islower(*str)) |
| 1293 |
*str = toupper(*str); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
|
| 1297 |
|
| 1298 |
void bifupr(bifcxdef *ctx, int argc) |
| 1299 |
{ |
| 1300 |
bifcvtstr(ctx, bifstrupr, argc); |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
static void bifstrlwr(uchar *str, int len) |
| 1305 |
{ |
| 1306 |
for ( ; len ; --len, ++str) |
| 1307 |
{ |
| 1308 |
if (*str == '\\' && len > 1) |
| 1309 |
--len, ++str; |
| 1310 |
else if (isupper(*str)) |
| 1311 |
*str = tolower(*str); |
| 1312 |
} |
| 1313 |
} |
| 1314 |
|
| 1315 |
|
| 1316 |
void biflwr(bifcxdef *ctx, int argc) |
| 1317 |
{ |
| 1318 |
bifcvtstr(ctx, bifstrlwr, argc); |
| 1319 |
} |
| 1320 |
|
| 1321 |
|
| 1322 |
int bifinh(voccxdef *voc, vocidef *v, objnum cls) |
| 1323 |
{ |
| 1324 |
int i; |
| 1325 |
objnum *sc; |
| 1326 |
|
| 1327 |
if (!v) return(FALSE); |
| 1328 |
for (i = v->vocinsc, sc = v->vocisc ; i ; ++sc, --i) |
| 1329 |
{ |
| 1330 |
if (*sc == cls |
| 1331 |
|| bifinh(voc, vocinh(voc, *sc), cls)) |
| 1332 |
return(TRUE); |
| 1333 |
} |
| 1334 |
return(FALSE); |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
void bifisc(bifcxdef *ctx, int argc) |
| 1339 |
{ |
| 1340 |
objnum obj; |
| 1341 |
objnum cls; |
| 1342 |
runsdef val; |
| 1343 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 1344 |
|
| 1345 |
bifcntargs(ctx, 2, argc); |
| 1346 |
|
| 1347 |
|
| 1348 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 1349 |
{ |
| 1350 |
rundisc(ctx->bifcxrun); |
| 1351 |
rundisc(ctx->bifcxrun); |
| 1352 |
runpnil(ctx->bifcxrun); |
| 1353 |
return; |
| 1354 |
} |
| 1355 |
|
| 1356 |
|
| 1357 |
obj = runpopobj(ctx->bifcxrun); |
| 1358 |
cls = runpopobj(ctx->bifcxrun); |
| 1359 |
|
| 1360 |
|
| 1361 |
runpush(ctx->bifcxrun, runclog(bifinh(voc, vocinh(voc, obj), cls)), &val); |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
void bif1sc(bifcxdef *ctx, int argc) |
| 1366 |
{ |
| 1367 |
objnum obj; |
| 1368 |
objnum sc; |
| 1369 |
|
| 1370 |
bifcntargs(ctx, 1, argc); |
| 1371 |
obj = runpopobj(ctx->bifcxrun); |
| 1372 |
sc = objget1sc(ctx->bifcxrun->runcxmem, obj); |
| 1373 |
runpobj(ctx->bifcxrun, sc); |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
void biffob(bifcxdef *ctx, int argc) |
| 1378 |
{ |
| 1379 |
vocidef ***vpg; |
| 1380 |
vocidef **v; |
| 1381 |
objnum obj; |
| 1382 |
int i; |
| 1383 |
int j; |
| 1384 |
objnum cls; |
| 1385 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 1386 |
|
| 1387 |
|
| 1388 |
if (argc == 0) |
| 1389 |
cls = MCMONINV; |
| 1390 |
else if (argc == 1) |
| 1391 |
cls = runpopobj(ctx->bifcxrun); |
| 1392 |
else |
| 1393 |
runsig(ctx->bifcxrun, ERR_BIFARGC); |
| 1394 |
|
| 1395 |
for (vpg = voc->voccxinh, i = 0 ; i < VOCINHMAX ; ++vpg, ++i) |
| 1396 |
{ |
| 1397 |
if (!*vpg) continue; |
| 1398 |
for (v = *vpg, obj = (i << 8), j = 0 ; j < 256 ; ++v, ++obj, ++j) |
| 1399 |
{ |
| 1400 |
if (!*v || ((*v)->vociflg & VOCIFCLASS) |
| 1401 |
|| (cls != MCMONINV && !bifinh(voc, *v, cls))) |
| 1402 |
continue; |
| 1403 |
|
| 1404 |
|
| 1405 |
runpobj(ctx->bifcxrun, obj); |
| 1406 |
return; |
| 1407 |
} |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
runpnil(ctx->bifcxrun); |
| 1412 |
} |
| 1413 |
|
| 1414 |
|
| 1415 |
void bifnob(bifcxdef *ctx, int argc) |
| 1416 |
{ |
| 1417 |
objnum prv; |
| 1418 |
vocidef ***vpg; |
| 1419 |
vocidef **v; |
| 1420 |
objnum obj; |
| 1421 |
int i; |
| 1422 |
int j; |
| 1423 |
objnum cls; |
| 1424 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 1425 |
|
| 1426 |
|
| 1427 |
prv = runpopobj(ctx->bifcxrun); |
| 1428 |
|
| 1429 |
|
| 1430 |
if (argc == 1) |
| 1431 |
cls = MCMONINV; |
| 1432 |
else if (argc == 2) |
| 1433 |
cls = runpopobj(ctx->bifcxrun); |
| 1434 |
else |
| 1435 |
runsig(ctx->bifcxrun, ERR_BIFARGC); |
| 1436 |
|
| 1437 |
|
| 1438 |
i = (prv >> 8); |
| 1439 |
vpg = voc->voccxinh + i; |
| 1440 |
j = (prv & 255); |
| 1441 |
obj = prv; |
| 1442 |
v = (*vpg) + j; |
| 1443 |
|
| 1444 |
for (;;) |
| 1445 |
{ |
| 1446 |
++j; |
| 1447 |
++obj; |
| 1448 |
++v; |
| 1449 |
if (j == 256) |
| 1450 |
{ |
| 1451 |
j = 0; |
| 1452 |
++i; |
| 1453 |
++vpg; |
| 1454 |
if (!*vpg) |
| 1455 |
{ |
| 1456 |
obj += 255; |
| 1457 |
j += 255; |
| 1458 |
continue; |
| 1459 |
} |
| 1460 |
v = (*vpg); |
| 1461 |
} |
| 1462 |
if (i >= VOCINHMAX) |
| 1463 |
{ |
| 1464 |
runpnil(ctx->bifcxrun); |
| 1465 |
return; |
| 1466 |
} |
| 1467 |
|
| 1468 |
if (!*v || ((*v)->vociflg & VOCIFCLASS) |
| 1469 |
|| (cls != MCMONINV && !bifinh(voc, *v, cls))) |
| 1470 |
continue; |
| 1471 |
|
| 1472 |
|
| 1473 |
runpobj(ctx->bifcxrun, obj); |
| 1474 |
return; |
| 1475 |
} |
| 1476 |
} |
| 1477 |
|
| 1478 |
|
| 1479 |
void bifsvn(bifcxdef *ctx, int argc) |
| 1480 |
{ |
| 1481 |
bifcntargs(ctx, 1, argc); |
| 1482 |
(void)runpopstr(ctx->bifcxrun); |
| 1483 |
|
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
void bifarg(bifcxdef *ctx, int argc) |
| 1488 |
{ |
| 1489 |
int argnum; |
| 1490 |
|
| 1491 |
bifcntargs(ctx, 1, argc); |
| 1492 |
bifchkarg(ctx, DAT_NUMBER); |
| 1493 |
|
| 1494 |
|
| 1495 |
argnum = runpopnum(ctx->bifcxrun); |
| 1496 |
if (argnum < 1) runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "getarg"); |
| 1497 |
|
| 1498 |
runrepush(ctx->bifcxrun, ctx->bifcxrun->runcxbp - argnum - 1); |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
void biftyp(bifcxdef *ctx, int argc) |
| 1503 |
{ |
| 1504 |
runsdef val; |
| 1505 |
|
| 1506 |
bifcntargs(ctx, 1, argc); |
| 1507 |
|
| 1508 |
|
| 1509 |
runpop(ctx->bifcxrun, &val); |
| 1510 |
val.runsv.runsvnum = val.runstyp; |
| 1511 |
runpush(ctx->bifcxrun, DAT_NUMBER, &val); |
| 1512 |
} |
| 1513 |
|
| 1514 |
|
| 1515 |
void bifund(bifcxdef *ctx, int argc) |
| 1516 |
{ |
| 1517 |
objucxdef *ucx = ctx->bifcxrun->runcxvoc->voccxundo; |
| 1518 |
mcmcxdef *mcx = ctx->bifcxrun->runcxmem; |
| 1519 |
errcxdef *ec = ctx->bifcxerr; |
| 1520 |
int err; |
| 1521 |
int undone; |
| 1522 |
runsdef val; |
| 1523 |
|
| 1524 |
bifcntargs(ctx, 0, argc); |
| 1525 |
|
| 1526 |
ERRBEGIN(ec) |
| 1527 |
if (ucx) |
| 1528 |
{ |
| 1529 |
objundo(mcx, ucx); |
| 1530 |
undone = TRUE; |
| 1531 |
} |
| 1532 |
else |
| 1533 |
undone = FALSE; |
| 1534 |
ERRCATCH(ec, err) |
| 1535 |
if (err == ERR_NOUNDO || err == ERR_ICUNDO) |
| 1536 |
undone = FALSE; |
| 1537 |
else |
| 1538 |
errrse(ec); |
| 1539 |
ERREND(ec) |
| 1540 |
|
| 1541 |
|
| 1542 |
runpush(ctx->bifcxrun, runclog(undone), &val); |
| 1543 |
|
| 1544 |
|
| 1545 |
ctx->bifcxrun->runcxvoc->voccxflg |= VOCCXFCLEAR; |
| 1546 |
} |
| 1547 |
|
| 1548 |
|
| 1549 |
#define BIFDEF_DEFINED_ANY 1 |
| 1550 |
#define BIFDEF_DEFINED_DIRECTLY 2 |
| 1551 |
#define BIFDEF_DEFINED_INHERITS 3 |
| 1552 |
#define BIFDEF_DEFINED_GET_CLASS 4 |
| 1553 |
|
| 1554 |
|
| 1555 |
void bifdef(bifcxdef *ctx, int argc) |
| 1556 |
{ |
| 1557 |
prpnum prpn; |
| 1558 |
objnum objn; |
| 1559 |
uint ofs; |
| 1560 |
runsdef val; |
| 1561 |
objnum def_objn; |
| 1562 |
int flag; |
| 1563 |
|
| 1564 |
|
| 1565 |
objn = runpopobj(ctx->bifcxrun); |
| 1566 |
prpn = runpopprp(ctx->bifcxrun); |
| 1567 |
|
| 1568 |
|
| 1569 |
if (argc == 3) |
| 1570 |
{ |
| 1571 |
|
| 1572 |
flag = (int)runpopnum(ctx->bifcxrun); |
| 1573 |
} |
| 1574 |
else |
| 1575 |
{ |
| 1576 |
|
| 1577 |
bifcntargs(ctx, 2, argc); |
| 1578 |
|
| 1579 |
|
| 1580 |
flag = BIFDEF_DEFINED_ANY; |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
ofs = objgetap(ctx->bifcxrun->runcxmem, objn, prpn, &def_objn, FALSE); |
| 1585 |
|
| 1586 |
|
| 1587 |
switch(flag) |
| 1588 |
{ |
| 1589 |
case BIFDEF_DEFINED_ANY: |
| 1590 |
|
| 1591 |
runpush(ctx->bifcxrun, runclog(ofs != 0), &val); |
| 1592 |
break; |
| 1593 |
|
| 1594 |
case BIFDEF_DEFINED_DIRECTLY: |
| 1595 |
|
| 1596 |
runpush(ctx->bifcxrun, runclog(ofs != 0 && def_objn == objn), &val); |
| 1597 |
break; |
| 1598 |
|
| 1599 |
case BIFDEF_DEFINED_INHERITS: |
| 1600 |
|
| 1601 |
runpush(ctx->bifcxrun, runclog(ofs != 0 && def_objn != objn), &val); |
| 1602 |
break; |
| 1603 |
|
| 1604 |
case BIFDEF_DEFINED_GET_CLASS: |
| 1605 |
|
| 1606 |
if (ofs == 0) |
| 1607 |
runpnil(ctx->bifcxrun); |
| 1608 |
else |
| 1609 |
runpobj(ctx->bifcxrun, def_objn); |
| 1610 |
break; |
| 1611 |
|
| 1612 |
default: |
| 1613 |
|
| 1614 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "defined"); |
| 1615 |
} |
| 1616 |
} |
| 1617 |
|
| 1618 |
|
| 1619 |
void bifpty(bifcxdef *ctx, int argc) |
| 1620 |
{ |
| 1621 |
prpnum prpn; |
| 1622 |
objnum objn; |
| 1623 |
uint ofs; |
| 1624 |
runsdef val; |
| 1625 |
objnum orn; |
| 1626 |
objdef *objptr; |
| 1627 |
prpdef *propptr; |
| 1628 |
|
| 1629 |
bifcntargs(ctx, 2, argc); |
| 1630 |
|
| 1631 |
|
| 1632 |
objn = runpopobj(ctx->bifcxrun); |
| 1633 |
prpn = runpopprp(ctx->bifcxrun); |
| 1634 |
ofs = objgetap(ctx->bifcxrun->runcxmem, objn, prpn, &orn, FALSE); |
| 1635 |
|
| 1636 |
if (ofs) |
| 1637 |
{ |
| 1638 |
|
| 1639 |
objptr = (objdef *)mcmlck(ctx->bifcxrun->runcxmem, (mcmon)orn); |
| 1640 |
propptr = objofsp(objptr, ofs); |
| 1641 |
val.runsv.runsvnum = prptype(propptr); |
| 1642 |
mcmunlck(ctx->bifcxrun->runcxmem, (mcmon)orn); |
| 1643 |
} |
| 1644 |
else |
| 1645 |
{ |
| 1646 |
|
| 1647 |
val.runsv.runsvnum = DAT_NIL; |
| 1648 |
} |
| 1649 |
|
| 1650 |
|
| 1651 |
if (val.runsv.runsvnum == DAT_DEMAND) |
| 1652 |
val.runsv.runsvnum = DAT_LIST; |
| 1653 |
|
| 1654 |
|
| 1655 |
runpush(ctx->bifcxrun, DAT_NUMBER, &val); |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
void bifoph(bifcxdef *ctx, int argc) |
| 1660 |
{ |
| 1661 |
runsdef val; |
| 1662 |
int hidden, output_occurred; |
| 1663 |
|
| 1664 |
bifcntargs(ctx, 1, argc); |
| 1665 |
outstat(&hidden, &output_occurred); |
| 1666 |
if (runtostyp(ctx->bifcxrun) == DAT_TRUE) |
| 1667 |
{ |
| 1668 |
|
| 1669 |
rundisc(ctx->bifcxrun); |
| 1670 |
|
| 1671 |
|
| 1672 |
if (!hidden) |
| 1673 |
val.runsv.runsvnum = 0; |
| 1674 |
else if (!output_occurred) |
| 1675 |
val.runsv.runsvnum = 1; |
| 1676 |
else |
| 1677 |
val.runsv.runsvnum = 2; |
| 1678 |
runpush(ctx->bifcxrun, DAT_NUMBER, &val); |
| 1679 |
|
| 1680 |
|
| 1681 |
outhide(); |
| 1682 |
} |
| 1683 |
else if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 1684 |
{ |
| 1685 |
|
| 1686 |
rundisc(ctx->bifcxrun); |
| 1687 |
|
| 1688 |
|
| 1689 |
runpush(ctx->bifcxrun, runclog(outshow()), &val); |
| 1690 |
} |
| 1691 |
else if (runtostyp(ctx->bifcxrun) == DAT_NUMBER) |
| 1692 |
{ |
| 1693 |
int n = runpopnum(ctx->bifcxrun); |
| 1694 |
|
| 1695 |
if (n == 0) |
| 1696 |
{ |
| 1697 |
|
| 1698 |
runpush(ctx->bifcxrun, runclog(outshow()), &val); |
| 1699 |
} |
| 1700 |
else if (n == 1) |
| 1701 |
{ |
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
runpush(ctx->bifcxrun, runclog(output_occurred), &val); |
| 1708 |
} |
| 1709 |
else if (n == 2) |
| 1710 |
{ |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
runpush(ctx->bifcxrun, runclog(output_occurred), &val); |
| 1718 |
outsethidden(); |
| 1719 |
} |
| 1720 |
else |
| 1721 |
errsig1(ctx->bifcxerr, ERR_INVVBIF, ERRTSTR, "outhide"); |
| 1722 |
} |
| 1723 |
else |
| 1724 |
errsig(ctx->bifcxerr, ERR_REQNUM); |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
static uchar *bifputnum(uchar *lstp, uint val) |
| 1729 |
{ |
| 1730 |
*lstp++ = DAT_NUMBER; |
| 1731 |
oswp4s(lstp, (long)val); |
| 1732 |
return(lstp + 4); |
| 1733 |
} |
| 1734 |
|
| 1735 |
|
| 1736 |
void biftim(bifcxdef *ctx, int argc) |
| 1737 |
{ |
| 1738 |
time_t timer; |
| 1739 |
struct tm *tblock; |
| 1740 |
uchar ret[80]; |
| 1741 |
uchar *p; |
| 1742 |
runsdef val; |
| 1743 |
int typ; |
| 1744 |
|
| 1745 |
if (argc == 1) |
| 1746 |
{ |
| 1747 |
|
| 1748 |
typ = (int)runpopnum(ctx->bifcxrun); |
| 1749 |
} |
| 1750 |
else |
| 1751 |
{ |
| 1752 |
|
| 1753 |
bifcntargs(ctx, 0, argc); |
| 1754 |
|
| 1755 |
|
| 1756 |
typ = 1; |
| 1757 |
} |
| 1758 |
|
| 1759 |
switch(typ) |
| 1760 |
{ |
| 1761 |
case 1: |
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
os_tzset(); |
| 1769 |
|
| 1770 |
|
| 1771 |
timer = time(NULL); |
| 1772 |
tblock = localtime(&timer); |
| 1773 |
|
| 1774 |
|
| 1775 |
tblock->tm_year += 1900; |
| 1776 |
tblock->tm_mon++; |
| 1777 |
tblock->tm_wday++; |
| 1778 |
tblock->tm_yday++; |
| 1779 |
|
| 1780 |
|
| 1781 |
oswp2(ret, 47); |
| 1782 |
p = ret + 2; |
| 1783 |
p = bifputnum(p, tblock->tm_year); |
| 1784 |
p = bifputnum(p, tblock->tm_mon); |
| 1785 |
p = bifputnum(p, tblock->tm_mday); |
| 1786 |
p = bifputnum(p, tblock->tm_wday); |
| 1787 |
p = bifputnum(p, tblock->tm_yday); |
| 1788 |
p = bifputnum(p, tblock->tm_hour); |
| 1789 |
p = bifputnum(p, tblock->tm_min); |
| 1790 |
p = bifputnum(p, tblock->tm_sec); |
| 1791 |
*p++ = DAT_NUMBER; |
| 1792 |
oswp4s(p, (long)timer); |
| 1793 |
|
| 1794 |
val.runstyp = DAT_LIST; |
| 1795 |
val.runsv.runsvstr = ret; |
| 1796 |
runpush(ctx->bifcxrun, DAT_LIST, &val); |
| 1797 |
break; |
| 1798 |
|
| 1799 |
case 2: |
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
runpnum(ctx->bifcxrun, os_get_sys_clock_ms()); |
| 1805 |
break; |
| 1806 |
|
| 1807 |
default: |
| 1808 |
|
| 1809 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "gettime"); |
| 1810 |
break; |
| 1811 |
} |
| 1812 |
} |
| 1813 |
|
| 1814 |
|
| 1815 |
void bifgfu(bifcxdef *ctx, int argc) |
| 1816 |
{ |
| 1817 |
vocddef *daem; |
| 1818 |
objnum func; |
| 1819 |
runsdef val; |
| 1820 |
runcxdef *rcx = ctx->bifcxrun; |
| 1821 |
int slots; |
| 1822 |
prpnum prop; |
| 1823 |
voccxdef *vcx = ctx->bifcxrun->runcxvoc; |
| 1824 |
|
| 1825 |
bifcntargs(ctx, 2, argc); |
| 1826 |
|
| 1827 |
if (runtostyp(rcx) == DAT_FNADDR) |
| 1828 |
{ |
| 1829 |
|
| 1830 |
func = runpopfn(rcx); |
| 1831 |
runpop(rcx, &val); |
| 1832 |
|
| 1833 |
for (slots = vcx->voccxfuc, daem = vcx->voccxfus ; |
| 1834 |
slots ; ++daem, --slots) |
| 1835 |
{ |
| 1836 |
if (daem->vocdfn == func |
| 1837 |
&& daem->vocdarg.runstyp == val.runstyp |
| 1838 |
&& !memcmp(&val.runsv, &daem->vocdarg.runsv, |
| 1839 |
(size_t)datsiz(val.runstyp, &val.runsv))) |
| 1840 |
goto ret_num; |
| 1841 |
} |
| 1842 |
} |
| 1843 |
else |
| 1844 |
{ |
| 1845 |
|
| 1846 |
func = runpopobj(rcx); |
| 1847 |
prop = runpopprp(rcx); |
| 1848 |
|
| 1849 |
for (slots = vcx->voccxalc, daem = vcx->voccxalm ; |
| 1850 |
slots ; ++daem, --slots) |
| 1851 |
{ |
| 1852 |
if (daem->vocdfn == func && daem->vocdprp == prop) |
| 1853 |
goto ret_num; |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
|
| 1858 |
runpush(rcx, DAT_NIL, &val); |
| 1859 |
return; |
| 1860 |
|
| 1861 |
ret_num: |
| 1862 |
|
| 1863 |
runpnum(rcx, (long)daem->vocdtim); |
| 1864 |
return; |
| 1865 |
} |
| 1866 |
|
| 1867 |
|
| 1868 |
void bifruf(bifcxdef *ctx, int argc) |
| 1869 |
{ |
| 1870 |
int ret; |
| 1871 |
runsdef val; |
| 1872 |
|
| 1873 |
bifcntargs(ctx, 0, argc); |
| 1874 |
ret = exefuse(ctx->bifcxrun->runcxvoc, TRUE); |
| 1875 |
runpush(ctx->bifcxrun, runclog(ret), &val); |
| 1876 |
} |
| 1877 |
|
| 1878 |
|
| 1879 |
void bifrud(bifcxdef *ctx, int argc) |
| 1880 |
{ |
| 1881 |
bifcntargs(ctx, 0, argc); |
| 1882 |
exedaem(ctx->bifcxrun->runcxvoc); |
| 1883 |
} |
| 1884 |
|
| 1885 |
|
| 1886 |
void bifsct(bifcxdef *bifctx, int argc) |
| 1887 |
{ |
| 1888 |
runcxdef *ctx = bifctx->bifcxrun; |
| 1889 |
uchar *l1; |
| 1890 |
uchar *l2; |
| 1891 |
uchar *l3; |
| 1892 |
uint siz1; |
| 1893 |
uint siz2; |
| 1894 |
uint siz3; |
| 1895 |
uchar *p; |
| 1896 |
uint l; |
| 1897 |
uint dsz1; |
| 1898 |
uint dsz2; |
| 1899 |
runsdef val; |
| 1900 |
runsdef stk1, stk2; |
| 1901 |
|
| 1902 |
bifcntargs(bifctx, 2, argc); |
| 1903 |
l1 = runpoplst(ctx); |
| 1904 |
siz1 = osrp2(l1); |
| 1905 |
l2 = runpoplst(ctx); |
| 1906 |
siz2 = osrp2(l2); |
| 1907 |
|
| 1908 |
|
| 1909 |
if (siz1 > siz2) |
| 1910 |
l3 = l1, l1 = l2, l2 = l3, siz3 = siz1, siz1 = siz2, siz2 = siz3; |
| 1911 |
|
| 1912 |
|
| 1913 |
stk1.runstyp = stk2.runstyp = DAT_LIST; |
| 1914 |
stk1.runsv.runsvstr = l1; |
| 1915 |
stk2.runsv.runsvstr = l2; |
| 1916 |
runhres2(ctx, siz1, 2, &stk1, &stk2); |
| 1917 |
l1 = stk1.runsv.runsvstr; |
| 1918 |
l2 = stk2.runsv.runsvstr; |
| 1919 |
l3 = ctx->runcxhp + 2; |
| 1920 |
|
| 1921 |
|
| 1922 |
for (l1 += 2, l2 += 2, siz1 -= 2, siz2 -= 2 ; siz1 ; lstadv(&l1, &siz1)) |
| 1923 |
{ |
| 1924 |
dsz1 = datsiz(*l1, l1 + 1) + 1; |
| 1925 |
for (l = siz2, p = l2 ; l ; lstadv(&p, &l)) |
| 1926 |
{ |
| 1927 |
dsz2 = datsiz(*p, p + 1) + 1; |
| 1928 |
#ifndef AMIGA |
| 1929 |
if (dsz1 == dsz2 && !memcmp(l1, p, (size_t)dsz1)) |
| 1930 |
#else |
| 1931 |
if (!memcmp(l1, p, (size_t)dsz1) && (dsz1 == dsz2) ) |
| 1932 |
#endif |
| 1933 |
{ |
| 1934 |
memcpy(l3, p, (size_t)dsz1); |
| 1935 |
l3 += dsz1; |
| 1936 |
break; |
| 1937 |
} |
| 1938 |
} |
| 1939 |
} |
| 1940 |
|
| 1941 |
|
| 1942 |
val.runsv.runsvstr = ctx->runcxhp; |
| 1943 |
val.runstyp = DAT_LIST; |
| 1944 |
oswp2(ctx->runcxhp, (uint)(l3 - ctx->runcxhp)); |
| 1945 |
ctx->runcxhp = l3; |
| 1946 |
runrepush(ctx, &val); |
| 1947 |
} |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
static char *ext_key_names[] = |
| 1954 |
{ |
| 1955 |
"[up]", |
| 1956 |
"[down]", |
| 1957 |
"[right]", |
| 1958 |
"[left]", |
| 1959 |
"[end]", |
| 1960 |
"[home]", |
| 1961 |
"[del-eol]", |
| 1962 |
"[del-line]", |
| 1963 |
"[del]", |
| 1964 |
"[scroll]", |
| 1965 |
"[page up]", |
| 1966 |
"[page down]", |
| 1967 |
"[top]", |
| 1968 |
"[bottom]", |
| 1969 |
"[f1]", |
| 1970 |
"[f2]", |
| 1971 |
"[f3]", |
| 1972 |
"[f4]", |
| 1973 |
"[f5]", |
| 1974 |
"[f6]", |
| 1975 |
"[f7]", |
| 1976 |
"[f8]", |
| 1977 |
"[f9]", |
| 1978 |
"[f10]", |
| 1979 |
"[?]", |
| 1980 |
"[tab]", |
| 1981 |
"[?]", |
| 1982 |
"[?]", |
| 1983 |
"[word-left]", |
| 1984 |
"[word-right]", |
| 1985 |
"[del-word]", |
| 1986 |
"[eof]", |
| 1987 |
"[break]" |
| 1988 |
}; |
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
static int get_ext_key_name(char *namebuf, int c, int extc) |
| 2019 |
{ |
| 2020 |
|
| 2021 |
if (c >= 1 && c <= 27) |
| 2022 |
{ |
| 2023 |
switch(c) |
| 2024 |
{ |
| 2025 |
case 10: |
| 2026 |
case 13: |
| 2027 |
|
| 2028 |
strcpy(namebuf, "\\n"); |
| 2029 |
return TRUE; |
| 2030 |
|
| 2031 |
case 9: |
| 2032 |
|
| 2033 |
strcpy(namebuf, "\\t"); |
| 2034 |
return TRUE; |
| 2035 |
|
| 2036 |
case 8: |
| 2037 |
|
| 2038 |
strcpy(namebuf, "[bksp]"); |
| 2039 |
return TRUE; |
| 2040 |
|
| 2041 |
case 27: |
| 2042 |
|
| 2043 |
strcpy(namebuf, "[esc]"); |
| 2044 |
return TRUE; |
| 2045 |
|
| 2046 |
default: |
| 2047 |
|
| 2048 |
strcpy(namebuf, "[ctrl-X]"); |
| 2049 |
namebuf[6] = (char)(c + 'a' - 1); |
| 2050 |
return TRUE; |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
|
| 2055 |
if (c != 0) |
| 2056 |
{ |
| 2057 |
namebuf[0] = c; |
| 2058 |
namebuf[1] = '\0'; |
| 2059 |
return TRUE; |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
if (extc >= 1 |
| 2064 |
&& extc <= (int)(sizeof(ext_key_names)/sizeof(ext_key_names[0]))) |
| 2065 |
{ |
| 2066 |
|
| 2067 |
strcpy(namebuf, ext_key_names[extc - 1]); |
| 2068 |
return TRUE; |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
if (extc >= CMD_ALT && extc <= CMD_ALT + 25) |
| 2073 |
{ |
| 2074 |
|
| 2075 |
strcpy(namebuf, "[alt-X]"); |
| 2076 |
namebuf[5] = (char)(extc - CMD_ALT + 'a'); |
| 2077 |
return TRUE; |
| 2078 |
} |
| 2079 |
|
| 2080 |
|
| 2081 |
strcpy(namebuf, "[?]"); |
| 2082 |
return FALSE; |
| 2083 |
} |
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
void bifink(bifcxdef *ctx, int argc) |
| 2088 |
{ |
| 2089 |
int c; |
| 2090 |
int extc; |
| 2091 |
char str[20]; |
| 2092 |
size_t len; |
| 2093 |
|
| 2094 |
bifcntargs(ctx, 0, argc); |
| 2095 |
tioflushn(ctx->bifcxtio, 0); |
| 2096 |
|
| 2097 |
|
| 2098 |
c = os_getc_raw(); |
| 2099 |
|
| 2100 |
|
| 2101 |
extc = (c == 0 ? os_getc_raw() : 0); |
| 2102 |
|
| 2103 |
|
| 2104 |
get_ext_key_name(str, c, extc); |
| 2105 |
|
| 2106 |
|
| 2107 |
len = strlen(str); |
| 2108 |
|
| 2109 |
|
| 2110 |
outreset(); |
| 2111 |
|
| 2112 |
|
| 2113 |
runpstr(ctx->bifcxrun, str, len, 0); |
| 2114 |
} |
| 2115 |
|
| 2116 |
|
| 2117 |
void bifwrd(bifcxdef *ctx, int argc) |
| 2118 |
{ |
| 2119 |
int ob; |
| 2120 |
vocoldef *v; |
| 2121 |
uchar buf[128]; |
| 2122 |
uchar *dst; |
| 2123 |
uchar *src; |
| 2124 |
uint len; |
| 2125 |
runsdef val; |
| 2126 |
|
| 2127 |
bifcntargs(ctx, 1, argc); |
| 2128 |
|
| 2129 |
|
| 2130 |
ob = runpopnum(ctx->bifcxrun); |
| 2131 |
switch(ob) |
| 2132 |
{ |
| 2133 |
case 1: |
| 2134 |
v = ctx->bifcxrun->runcxvoc->voccxdobj; |
| 2135 |
break; |
| 2136 |
|
| 2137 |
case 2: |
| 2138 |
v = ctx->bifcxrun->runcxvoc->voccxiobj; |
| 2139 |
break; |
| 2140 |
|
| 2141 |
default: |
| 2142 |
runpnil(ctx->bifcxrun); |
| 2143 |
return; |
| 2144 |
} |
| 2145 |
|
| 2146 |
|
| 2147 |
if (v != 0 && voclistlen(v) != 0 && v->vocolfst != 0 && v->vocollst != 0) |
| 2148 |
{ |
| 2149 |
for (dst = buf + 2, src = (uchar *)v->vocolfst ; |
| 2150 |
src <= (uchar *)v->vocollst ; src += len + 1) |
| 2151 |
{ |
| 2152 |
*dst++ = DAT_SSTRING; |
| 2153 |
len = strlen((char *)src); |
| 2154 |
oswp2(dst, len + 2); |
| 2155 |
strcpy((char *)dst + 2, (char *)src); |
| 2156 |
dst += len + 2; |
| 2157 |
} |
| 2158 |
} |
| 2159 |
else |
| 2160 |
dst = buf + 2; |
| 2161 |
|
| 2162 |
|
| 2163 |
len = dst - buf; |
| 2164 |
oswp2(buf, len); |
| 2165 |
val.runsv.runsvstr = buf; |
| 2166 |
val.runstyp = DAT_LIST; |
| 2167 |
runpush(ctx->bifcxrun, DAT_LIST, &val); |
| 2168 |
} |
| 2169 |
|
| 2170 |
|
| 2171 |
void bifadw(bifcxdef *ctx, int argc) |
| 2172 |
{ |
| 2173 |
uchar *wrd; |
| 2174 |
objnum objn; |
| 2175 |
prpnum prpn; |
| 2176 |
vocidef *voci; |
| 2177 |
int classflg; |
| 2178 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 2179 |
|
| 2180 |
bifcntargs(ctx, 3, argc); |
| 2181 |
|
| 2182 |
|
| 2183 |
objn = runpopobj(ctx->bifcxrun); |
| 2184 |
prpn = runpopprp(ctx->bifcxrun); |
| 2185 |
wrd = runpopstr(ctx->bifcxrun); |
| 2186 |
|
| 2187 |
|
| 2188 |
if (!prpisvoc(prpn)) |
| 2189 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "addword"); |
| 2190 |
|
| 2191 |
|
| 2192 |
voci = vocinh(voc, objn); |
| 2193 |
|
| 2194 |
classflg = VOCFNEW; |
| 2195 |
if (voci->vociflg & VOCIFCLASS) classflg |= VOCFCLASS; |
| 2196 |
|
| 2197 |
|
| 2198 |
vocadd(voc, prpn, objn, classflg, (char *)wrd); |
| 2199 |
|
| 2200 |
|
| 2201 |
vocdusave_addwrd(voc, objn, prpn, classflg, (char *)wrd); |
| 2202 |
} |
| 2203 |
|
| 2204 |
|
| 2205 |
void bifdlw(bifcxdef *ctx, int argc) |
| 2206 |
{ |
| 2207 |
uchar *wrd; |
| 2208 |
objnum objn; |
| 2209 |
prpnum prpn; |
| 2210 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 2211 |
|
| 2212 |
bifcntargs(ctx, 3, argc); |
| 2213 |
|
| 2214 |
|
| 2215 |
objn = runpopobj(ctx->bifcxrun); |
| 2216 |
prpn = runpopprp(ctx->bifcxrun); |
| 2217 |
wrd = runpopstr(ctx->bifcxrun); |
| 2218 |
|
| 2219 |
|
| 2220 |
if (!prpisvoc(prpn)) |
| 2221 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "delword"); |
| 2222 |
|
| 2223 |
|
| 2224 |
vocdel1(voc, objn, (char *)wrd, prpn, FALSE, FALSE, TRUE); |
| 2225 |
} |
| 2226 |
|
| 2227 |
|
| 2228 |
struct bifgtw_cb_ctx |
| 2229 |
{ |
| 2230 |
uchar *p; |
| 2231 |
int typ; |
| 2232 |
}; |
| 2233 |
|
| 2234 |
|
| 2235 |
static void bifgtw_cb(void *ctx0, vocdef *voc, vocwdef *vocw) |
| 2236 |
{ |
| 2237 |
struct bifgtw_cb_ctx *ctx = (struct bifgtw_cb_ctx *)ctx0; |
| 2238 |
|
| 2239 |
|
| 2240 |
if (vocw->vocwflg & VOCFDEL) |
| 2241 |
return; |
| 2242 |
|
| 2243 |
|
| 2244 |
if (vocw->vocwtyp != ctx->typ) |
| 2245 |
return; |
| 2246 |
|
| 2247 |
|
| 2248 |
*ctx->p = DAT_SSTRING; |
| 2249 |
|
| 2250 |
|
| 2251 |
memcpy(ctx->p + 3, voc->voctxt, (size_t)voc->voclen); |
| 2252 |
|
| 2253 |
|
| 2254 |
if (voc->vocln2) |
| 2255 |
{ |
| 2256 |
*(ctx->p + 3 + voc->voclen) = ' '; |
| 2257 |
memcpy(ctx->p + 4 + voc->voclen, voc->voctxt + voc->voclen, |
| 2258 |
(size_t)voc->vocln2); |
| 2259 |
oswp2(ctx->p + 1, voc->voclen + voc->vocln2 + 3); |
| 2260 |
ctx->p += voc->voclen + voc->vocln2 + 4; |
| 2261 |
} |
| 2262 |
else |
| 2263 |
{ |
| 2264 |
oswp2(ctx->p + 1, voc->voclen+2); |
| 2265 |
ctx->p += voc->voclen + 3; |
| 2266 |
} |
| 2267 |
} |
| 2268 |
|
| 2269 |
|
| 2270 |
void bifgtw(bifcxdef *ctx, int argc) |
| 2271 |
{ |
| 2272 |
objnum objn; |
| 2273 |
prpnum prpn; |
| 2274 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 2275 |
int cnt; |
| 2276 |
int siz; |
| 2277 |
runsdef val; |
| 2278 |
struct bifgtw_cb_ctx fnctx; |
| 2279 |
|
| 2280 |
bifcntargs(ctx, 2, argc); |
| 2281 |
|
| 2282 |
|
| 2283 |
objn = runpopobj(ctx->bifcxrun); |
| 2284 |
prpn = runpopprp(ctx->bifcxrun); |
| 2285 |
|
| 2286 |
|
| 2287 |
if (!prpisvoc(prpn)) |
| 2288 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "delword"); |
| 2289 |
|
| 2290 |
|
| 2291 |
voc_count(voc, objn, prpn, &cnt, &siz); |
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
siz += 2 + 4*cnt; |
| 2301 |
|
| 2302 |
|
| 2303 |
runhres(ctx->bifcxrun, siz, 0); |
| 2304 |
|
| 2305 |
|
| 2306 |
fnctx.p = ctx->bifcxrun->runcxhp + 2; |
| 2307 |
fnctx.typ = prpn; |
| 2308 |
voc_iterate(voc, objn, bifgtw_cb, &fnctx); |
| 2309 |
|
| 2310 |
|
| 2311 |
val.runstyp = DAT_LIST; |
| 2312 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 2313 |
|
| 2314 |
|
| 2315 |
oswp2(ctx->bifcxrun->runcxhp, fnctx.p - ctx->bifcxrun->runcxhp); |
| 2316 |
ctx->bifcxrun->runcxhp = fnctx.p; |
| 2317 |
|
| 2318 |
|
| 2319 |
runrepush(ctx->bifcxrun, &val); |
| 2320 |
} |
| 2321 |
|
| 2322 |
|
| 2323 |
static uchar *bifvin_putprpn(uchar *p, prpnum prpn) |
| 2324 |
{ |
| 2325 |
*p++ = DAT_PROPNUM; |
| 2326 |
oswp2(p, prpn); |
| 2327 |
return p + 2; |
| 2328 |
} |
| 2329 |
|
| 2330 |
|
| 2331 |
void bifvin(bifcxdef *ctx, int argc) |
| 2332 |
{ |
| 2333 |
objnum verb; |
| 2334 |
objnum prep; |
| 2335 |
uchar tplbuf[VOCTPL2SIZ]; |
| 2336 |
int newstyle; |
| 2337 |
|
| 2338 |
|
| 2339 |
verb = runpopobj(ctx->bifcxrun); |
| 2340 |
|
| 2341 |
|
| 2342 |
if (argc == 1) |
| 2343 |
{ |
| 2344 |
|
| 2345 |
prep = MCMONINV; |
| 2346 |
} |
| 2347 |
else |
| 2348 |
{ |
| 2349 |
|
| 2350 |
bifcntargs(ctx, 2, argc); |
| 2351 |
prep = runpopobj(ctx->bifcxrun); |
| 2352 |
} |
| 2353 |
|
| 2354 |
|
| 2355 |
if (voctplfnd(ctx->bifcxrun->runcxvoc, verb, prep, tplbuf, &newstyle)) |
| 2356 |
{ |
| 2357 |
prpnum prp_do, prp_verdo, prp_io, prp_verio; |
| 2358 |
int flg_dis_do; |
| 2359 |
ushort siz; |
| 2360 |
uchar *p; |
| 2361 |
runsdef val; |
| 2362 |
|
| 2363 |
|
| 2364 |
prp_do = voctpldo(tplbuf); |
| 2365 |
prp_verdo = voctplvd(tplbuf); |
| 2366 |
prp_io = voctplio(tplbuf); |
| 2367 |
prp_verio = voctplvi(tplbuf); |
| 2368 |
flg_dis_do = (voctplflg(tplbuf) & VOCTPLFLG_DOBJ_FIRST) != 0; |
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
siz = 2 + 2*(2+1); |
| 2376 |
if (prep != MCMONINV) |
| 2377 |
siz += (2+1) + 1; |
| 2378 |
|
| 2379 |
|
| 2380 |
runhres(ctx->bifcxrun, siz, 0); |
| 2381 |
|
| 2382 |
|
| 2383 |
p = ctx->bifcxrun->runcxhp; |
| 2384 |
oswp2(p, siz); |
| 2385 |
p += 2; |
| 2386 |
|
| 2387 |
p = bifvin_putprpn(p, prp_verdo); |
| 2388 |
if (prep == MCMONINV) |
| 2389 |
{ |
| 2390 |
p = bifvin_putprpn(p, prp_do); |
| 2391 |
} |
| 2392 |
else |
| 2393 |
{ |
| 2394 |
p = bifvin_putprpn(p, prp_verio); |
| 2395 |
p = bifvin_putprpn(p, prp_io); |
| 2396 |
*p++ = runclog(flg_dis_do); |
| 2397 |
} |
| 2398 |
|
| 2399 |
|
| 2400 |
val.runstyp = DAT_LIST; |
| 2401 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 2402 |
|
| 2403 |
|
| 2404 |
ctx->bifcxrun->runcxhp += siz; |
| 2405 |
|
| 2406 |
|
| 2407 |
runrepush(ctx->bifcxrun, &val); |
| 2408 |
} |
| 2409 |
else |
| 2410 |
{ |
| 2411 |
|
| 2412 |
runpnil(ctx->bifcxrun); |
| 2413 |
} |
| 2414 |
} |
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
void bifcls(bifcxdef *ctx, int argc) |
| 2419 |
{ |
| 2420 |
|
| 2421 |
bifcntargs(ctx, 0, argc); |
| 2422 |
|
| 2423 |
|
| 2424 |
tioflushn(ctx->bifcxtio, 0); |
| 2425 |
|
| 2426 |
|
| 2427 |
oscls(); |
| 2428 |
} |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
void biffopen(bifcxdef *ctx, int argc) |
| 2455 |
{ |
| 2456 |
char fname[OSFNMAX]; |
| 2457 |
uchar *p; |
| 2458 |
uchar *mode; |
| 2459 |
int modelen; |
| 2460 |
int fnum; |
| 2461 |
osfildef *fp; |
| 2462 |
int bin_mode = TRUE; |
| 2463 |
int rw_mode = FALSE; |
| 2464 |
char main_mode; |
| 2465 |
int in_same_dir; |
| 2466 |
appctxdef *appctx; |
| 2467 |
|
| 2468 |
bifcntargs(ctx, 2, argc); |
| 2469 |
|
| 2470 |
|
| 2471 |
p = runpopstr(ctx->bifcxrun); |
| 2472 |
bifcstr(ctx, fname, (size_t)sizeof(fname), p); |
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
if (!os_is_file_absolute(fname)) |
| 2481 |
{ |
| 2482 |
|
| 2483 |
char newname[OSFNMAX]; |
| 2484 |
os_build_full_path(newname, sizeof(newname), |
| 2485 |
ctx->bifcxrun->runcxgamepath, fname); |
| 2486 |
|
| 2487 |
|
| 2488 |
strcpy(fname, newname); |
| 2489 |
} |
| 2490 |
|
| 2491 |
|
| 2492 |
mode = runpopstr(ctx->bifcxrun); |
| 2493 |
modelen = osrp2(mode) - 2; |
| 2494 |
mode += 2; |
| 2495 |
if (modelen < 1) |
| 2496 |
goto bad_mode; |
| 2497 |
|
| 2498 |
|
| 2499 |
for (fnum = 0 ; fnum < BIFFILMAX ; ++fnum) |
| 2500 |
{ |
| 2501 |
if (ctx->bifcxfile[fnum].fp == 0) |
| 2502 |
break; |
| 2503 |
} |
| 2504 |
if (fnum == BIFFILMAX) |
| 2505 |
{ |
| 2506 |
|
| 2507 |
runpnil(ctx->bifcxrun); |
| 2508 |
return; |
| 2509 |
} |
| 2510 |
|
| 2511 |
|
| 2512 |
switch(*mode) |
| 2513 |
{ |
| 2514 |
case 'w': |
| 2515 |
case 'W': |
| 2516 |
main_mode = 'w'; |
| 2517 |
break; |
| 2518 |
|
| 2519 |
case 'r': |
| 2520 |
case 'R': |
| 2521 |
main_mode = 'r'; |
| 2522 |
break; |
| 2523 |
|
| 2524 |
default: |
| 2525 |
goto bad_mode; |
| 2526 |
} |
| 2527 |
|
| 2528 |
|
| 2529 |
++mode; |
| 2530 |
--modelen; |
| 2531 |
if (modelen > 0 && *mode == '+') |
| 2532 |
{ |
| 2533 |
|
| 2534 |
rw_mode = TRUE; |
| 2535 |
|
| 2536 |
|
| 2537 |
++mode; |
| 2538 |
--modelen; |
| 2539 |
} |
| 2540 |
|
| 2541 |
|
| 2542 |
if (modelen > 0) |
| 2543 |
{ |
| 2544 |
switch(*mode) |
| 2545 |
{ |
| 2546 |
case 'b': |
| 2547 |
case 'B': |
| 2548 |
bin_mode = TRUE; |
| 2549 |
break; |
| 2550 |
|
| 2551 |
case 't': |
| 2552 |
case 'T': |
| 2553 |
bin_mode = FALSE; |
| 2554 |
break; |
| 2555 |
|
| 2556 |
default: |
| 2557 |
goto bad_mode; |
| 2558 |
} |
| 2559 |
|
| 2560 |
|
| 2561 |
++mode; |
| 2562 |
--modelen; |
| 2563 |
} |
| 2564 |
|
| 2565 |
|
| 2566 |
if (modelen > 0) |
| 2567 |
goto bad_mode; |
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
appctx = ctx->bifcxappctx; |
| 2575 |
if (appctx != 0 && appctx->get_io_safety_level != 0) |
| 2576 |
{ |
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
(*appctx->get_io_safety_level)( |
| 2582 |
appctx->io_safety_level_ctx, |
| 2583 |
&ctx->bifcxsafetyr, &ctx->bifcxsafetyw); |
| 2584 |
} |
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
in_same_dir = os_is_file_in_dir( |
| 2592 |
fname, ctx->bifcxrun->runcxgamepath, TRUE, FALSE); |
| 2593 |
|
| 2594 |
|
| 2595 |
switch(main_mode) |
| 2596 |
{ |
| 2597 |
case 'w': |
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
if (ctx->bifcxsafetyw > 2 |
| 2604 |
|| (!in_same_dir && ctx->bifcxsafetyw > 0)) |
| 2605 |
{ |
| 2606 |
|
| 2607 |
runpnil(ctx->bifcxrun); |
| 2608 |
return; |
| 2609 |
} |
| 2610 |
break; |
| 2611 |
|
| 2612 |
case 'r': |
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
if (ctx->bifcxsafetyr > 3 |
| 2620 |
|| (!in_same_dir && ctx->bifcxsafetyr > 1)) |
| 2621 |
{ |
| 2622 |
|
| 2623 |
runpnil(ctx->bifcxrun); |
| 2624 |
return; |
| 2625 |
} |
| 2626 |
break; |
| 2627 |
|
| 2628 |
default: |
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
goto bad_mode; |
| 2636 |
} |
| 2637 |
|
| 2638 |
|
| 2639 |
switch(main_mode) |
| 2640 |
{ |
| 2641 |
case 'w': |
| 2642 |
|
| 2643 |
if (bin_mode) |
| 2644 |
{ |
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
if (rw_mode) |
| 2651 |
fp = osfoprwtb(fname, OSFTDATA); |
| 2652 |
else |
| 2653 |
fp = osfopwb(fname, OSFTDATA); |
| 2654 |
} |
| 2655 |
else |
| 2656 |
{ |
| 2657 |
|
| 2658 |
if (rw_mode) |
| 2659 |
goto bad_mode; |
| 2660 |
|
| 2661 |
|
| 2662 |
fp = osfopwt(fname, OSFTTEXT); |
| 2663 |
} |
| 2664 |
break; |
| 2665 |
|
| 2666 |
case 'r': |
| 2667 |
|
| 2668 |
if (bin_mode) |
| 2669 |
{ |
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
if (rw_mode) |
| 2675 |
{ |
| 2676 |
|
| 2677 |
fp = osfoprwb(fname, OSFTDATA); |
| 2678 |
} |
| 2679 |
else |
| 2680 |
{ |
| 2681 |
|
| 2682 |
fp = osfoprb(fname, OSFTDATA); |
| 2683 |
} |
| 2684 |
} |
| 2685 |
else |
| 2686 |
{ |
| 2687 |
|
| 2688 |
if (rw_mode) |
| 2689 |
goto bad_mode; |
| 2690 |
|
| 2691 |
|
| 2692 |
fp = osfoprt(fname, OSFTTEXT); |
| 2693 |
} |
| 2694 |
break; |
| 2695 |
|
| 2696 |
default: |
| 2697 |
goto bad_mode; |
| 2698 |
} |
| 2699 |
|
| 2700 |
|
| 2701 |
if (fp == 0) |
| 2702 |
{ |
| 2703 |
runpnil(ctx->bifcxrun); |
| 2704 |
return; |
| 2705 |
} |
| 2706 |
|
| 2707 |
|
| 2708 |
ctx->bifcxfile[fnum].flags = 0; |
| 2709 |
if (bin_mode) |
| 2710 |
ctx->bifcxfile[fnum].flags |= BIFFIL_F_BINARY; |
| 2711 |
|
| 2712 |
|
| 2713 |
ctx->bifcxfile[fnum].fp = fp; |
| 2714 |
|
| 2715 |
|
| 2716 |
runpnum(ctx->bifcxrun, (long)fnum); |
| 2717 |
return; |
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
bad_mode: |
| 2722 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "fopen"); |
| 2723 |
} |
| 2724 |
|
| 2725 |
|
| 2726 |
static osfildef *bif_get_file(bifcxdef *ctx, int *fnump, int *bin_modep) |
| 2727 |
{ |
| 2728 |
long fnum; |
| 2729 |
|
| 2730 |
|
| 2731 |
fnum = runpopnum(ctx->bifcxrun); |
| 2732 |
if (fnum < 0 || fnum >= BIFFILMAX || ctx->bifcxfile[fnum].fp == 0) |
| 2733 |
runsig(ctx->bifcxrun, ERR_BADFILE); |
| 2734 |
|
| 2735 |
|
| 2736 |
if (fnump != 0) |
| 2737 |
*fnump = (int)fnum; |
| 2738 |
|
| 2739 |
|
| 2740 |
if (bin_modep != 0) |
| 2741 |
*bin_modep = ((ctx->bifcxfile[fnum].flags & BIFFIL_F_BINARY) != 0); |
| 2742 |
|
| 2743 |
|
| 2744 |
return ctx->bifcxfile[fnum].fp; |
| 2745 |
} |
| 2746 |
|
| 2747 |
void biffclose(bifcxdef *ctx, int argc) |
| 2748 |
{ |
| 2749 |
int fnum; |
| 2750 |
osfildef *fp; |
| 2751 |
|
| 2752 |
|
| 2753 |
bifcntargs(ctx, 1, argc); |
| 2754 |
fp = bif_get_file(ctx, &fnum, 0); |
| 2755 |
|
| 2756 |
|
| 2757 |
osfcls(fp); |
| 2758 |
ctx->bifcxfile[fnum].fp = 0; |
| 2759 |
} |
| 2760 |
|
| 2761 |
void bifftell(bifcxdef *ctx, int argc) |
| 2762 |
{ |
| 2763 |
osfildef *fp; |
| 2764 |
|
| 2765 |
|
| 2766 |
bifcntargs(ctx, 1, argc); |
| 2767 |
fp = bif_get_file(ctx, (int *)0, 0); |
| 2768 |
|
| 2769 |
|
| 2770 |
runpnum(ctx->bifcxrun, osfpos(fp)); |
| 2771 |
} |
| 2772 |
|
| 2773 |
void biffseek(bifcxdef *ctx, int argc) |
| 2774 |
{ |
| 2775 |
osfildef *fp; |
| 2776 |
long pos; |
| 2777 |
|
| 2778 |
|
| 2779 |
bifcntargs(ctx, 2, argc); |
| 2780 |
fp = bif_get_file(ctx, (int *)0, 0); |
| 2781 |
|
| 2782 |
|
| 2783 |
pos = runpopnum(ctx->bifcxrun); |
| 2784 |
osfseek(fp, pos, OSFSK_SET); |
| 2785 |
} |
| 2786 |
|
| 2787 |
void biffseekeof(bifcxdef *ctx, int argc) |
| 2788 |
{ |
| 2789 |
osfildef *fp; |
| 2790 |
|
| 2791 |
|
| 2792 |
bifcntargs(ctx, 1, argc); |
| 2793 |
fp = bif_get_file(ctx, (int *)0, 0); |
| 2794 |
|
| 2795 |
|
| 2796 |
osfseek(fp, 0L, OSFSK_END); |
| 2797 |
} |
| 2798 |
|
| 2799 |
void biffwrite(bifcxdef *ctx, int argc) |
| 2800 |
{ |
| 2801 |
osfildef *fp; |
| 2802 |
char typ; |
| 2803 |
char buf[32]; |
| 2804 |
runsdef val; |
| 2805 |
int bin_mode; |
| 2806 |
|
| 2807 |
|
| 2808 |
bifcntargs(ctx, 2, argc); |
| 2809 |
fp = bif_get_file(ctx, (int *)0, &bin_mode); |
| 2810 |
|
| 2811 |
|
| 2812 |
runpop(ctx->bifcxrun, &val); |
| 2813 |
typ = val.runstyp; |
| 2814 |
|
| 2815 |
if (bin_mode) |
| 2816 |
{ |
| 2817 |
|
| 2818 |
if (osfwb(fp, &typ, 1)) |
| 2819 |
goto ret_error; |
| 2820 |
|
| 2821 |
|
| 2822 |
switch(typ) |
| 2823 |
{ |
| 2824 |
case DAT_NUMBER: |
| 2825 |
oswp4s(buf, val.runsv.runsvnum); |
| 2826 |
if (osfwb(fp, buf, 4)) |
| 2827 |
goto ret_error; |
| 2828 |
break; |
| 2829 |
|
| 2830 |
case DAT_SSTRING: |
| 2831 |
|
| 2832 |
if (osfwb(fp, val.runsv.runsvstr, osrp2(val.runsv.runsvstr))) |
| 2833 |
goto ret_error; |
| 2834 |
break; |
| 2835 |
|
| 2836 |
case DAT_TRUE: |
| 2837 |
|
| 2838 |
break; |
| 2839 |
|
| 2840 |
default: |
| 2841 |
|
| 2842 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "fwrite"); |
| 2843 |
} |
| 2844 |
} |
| 2845 |
else |
| 2846 |
{ |
| 2847 |
uint rem; |
| 2848 |
uchar *p; |
| 2849 |
|
| 2850 |
switch(typ) |
| 2851 |
{ |
| 2852 |
case DAT_SSTRING: |
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
rem = osrp2(val.runsv.runsvstr) - 2; |
| 2859 |
p = val.runsv.runsvstr + 2; |
| 2860 |
while (rem > 0) |
| 2861 |
{ |
| 2862 |
uchar *dst; |
| 2863 |
uchar buf[256]; |
| 2864 |
|
| 2865 |
|
| 2866 |
for (dst = buf ; |
| 2867 |
rem != 0 && (size_t)(dst - buf) < sizeof(buf) - 1 ; |
| 2868 |
++p, --rem) |
| 2869 |
{ |
| 2870 |
|
| 2871 |
if (*p == '\\' && rem > 1) |
| 2872 |
{ |
| 2873 |
|
| 2874 |
++p; |
| 2875 |
--rem; |
| 2876 |
|
| 2877 |
|
| 2878 |
switch(*p) |
| 2879 |
{ |
| 2880 |
case 'n': |
| 2881 |
*dst++ = '\n'; |
| 2882 |
break; |
| 2883 |
|
| 2884 |
case 't': |
| 2885 |
*dst++ = '\t'; |
| 2886 |
break; |
| 2887 |
|
| 2888 |
default: |
| 2889 |
*dst++ = *p; |
| 2890 |
break; |
| 2891 |
} |
| 2892 |
} |
| 2893 |
else |
| 2894 |
{ |
| 2895 |
|
| 2896 |
*dst++ = *p; |
| 2897 |
} |
| 2898 |
} |
| 2899 |
|
| 2900 |
|
| 2901 |
*dst = '\0'; |
| 2902 |
|
| 2903 |
|
| 2904 |
if (osfputs((char *)buf, fp) == EOF) |
| 2905 |
goto ret_error; |
| 2906 |
} |
| 2907 |
|
| 2908 |
|
| 2909 |
break; |
| 2910 |
|
| 2911 |
default: |
| 2912 |
|
| 2913 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "fwrite"); |
| 2914 |
} |
| 2915 |
} |
| 2916 |
|
| 2917 |
|
| 2918 |
runpnil(ctx->bifcxrun); |
| 2919 |
return; |
| 2920 |
|
| 2921 |
ret_error: |
| 2922 |
val.runstyp = DAT_TRUE; |
| 2923 |
runpush(ctx->bifcxrun, DAT_TRUE, &val); |
| 2924 |
} |
| 2925 |
|
| 2926 |
void biffread(bifcxdef *ctx, int argc) |
| 2927 |
{ |
| 2928 |
osfildef *fp; |
| 2929 |
char typ; |
| 2930 |
char buf[32]; |
| 2931 |
runsdef val; |
| 2932 |
ushort len; |
| 2933 |
int bin_mode; |
| 2934 |
|
| 2935 |
|
| 2936 |
bifcntargs(ctx, 1, argc); |
| 2937 |
fp = bif_get_file(ctx, (int *)0, &bin_mode); |
| 2938 |
|
| 2939 |
if (bin_mode) |
| 2940 |
{ |
| 2941 |
|
| 2942 |
if (osfrb(fp, &typ, 1)) |
| 2943 |
goto ret_error; |
| 2944 |
|
| 2945 |
|
| 2946 |
switch(typ) |
| 2947 |
{ |
| 2948 |
case DAT_NUMBER: |
| 2949 |
if (osfrb(fp, buf, 4)) |
| 2950 |
goto ret_error; |
| 2951 |
runpnum(ctx->bifcxrun, osrp4s(buf)); |
| 2952 |
break; |
| 2953 |
|
| 2954 |
case DAT_SSTRING: |
| 2955 |
|
| 2956 |
if (osfrb(fp, buf, 2)) |
| 2957 |
goto ret_error; |
| 2958 |
len = osrp2(buf); |
| 2959 |
|
| 2960 |
|
| 2961 |
runhres(ctx->bifcxrun, len, 0); |
| 2962 |
|
| 2963 |
|
| 2964 |
if (osfrb(fp, ctx->bifcxrun->runcxhp + 2, len - 2)) |
| 2965 |
goto ret_error; |
| 2966 |
|
| 2967 |
|
| 2968 |
oswp2(ctx->bifcxrun->runcxhp, len); |
| 2969 |
val.runstyp = DAT_SSTRING; |
| 2970 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 2971 |
|
| 2972 |
|
| 2973 |
ctx->bifcxrun->runcxhp += len; |
| 2974 |
|
| 2975 |
|
| 2976 |
runrepush(ctx->bifcxrun, &val); |
| 2977 |
break; |
| 2978 |
|
| 2979 |
case DAT_TRUE: |
| 2980 |
val.runstyp = DAT_TRUE; |
| 2981 |
runpush(ctx->bifcxrun, DAT_TRUE, &val); |
| 2982 |
break; |
| 2983 |
|
| 2984 |
default: |
| 2985 |
goto ret_error; |
| 2986 |
} |
| 2987 |
} |
| 2988 |
else |
| 2989 |
{ |
| 2990 |
uchar buf[257]; |
| 2991 |
uchar *dst; |
| 2992 |
uchar *src; |
| 2993 |
uint len; |
| 2994 |
uint res_total; |
| 2995 |
int found_nl; |
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
res_total = sizeof(buf) * 2; |
| 3003 |
runhres(ctx->bifcxrun, res_total, 0); |
| 3004 |
|
| 3005 |
|
| 3006 |
val.runstyp = DAT_SSTRING; |
| 3007 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 3008 |
dst = ctx->bifcxrun->runcxhp + 2; |
| 3009 |
|
| 3010 |
|
| 3011 |
for (found_nl = FALSE ; !found_nl ; ) |
| 3012 |
{ |
| 3013 |
|
| 3014 |
if (!osfgets((char *)buf, sizeof(buf) - 1, fp)) |
| 3015 |
{ |
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
if (found_nl) |
| 3021 |
break; |
| 3022 |
else |
| 3023 |
goto ret_error; |
| 3024 |
} |
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
buf[256] = '\0'; |
| 3031 |
|
| 3032 |
|
| 3033 |
for (src = buf ; *src != '\0' ; ++src, ++dst) |
| 3034 |
{ |
| 3035 |
|
| 3036 |
switch(*src) |
| 3037 |
{ |
| 3038 |
case '\n': |
| 3039 |
case '\r': |
| 3040 |
|
| 3041 |
*dst++ = '\\'; |
| 3042 |
*dst = 'n'; |
| 3043 |
|
| 3044 |
|
| 3045 |
found_nl = TRUE; |
| 3046 |
break; |
| 3047 |
|
| 3048 |
case '\t': |
| 3049 |
|
| 3050 |
*dst++ = '\\'; |
| 3051 |
*dst = 't'; |
| 3052 |
break; |
| 3053 |
|
| 3054 |
case '\\': |
| 3055 |
|
| 3056 |
*dst++ = '\\'; |
| 3057 |
*dst = '\\'; |
| 3058 |
break; |
| 3059 |
|
| 3060 |
default: |
| 3061 |
|
| 3062 |
*dst = *src; |
| 3063 |
break; |
| 3064 |
} |
| 3065 |
} |
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
if (!found_nl) |
| 3076 |
{ |
| 3077 |
|
| 3078 |
res_total += sizeof(buf) * 2; |
| 3079 |
|
| 3080 |
|
| 3081 |
len = dst - val.runsv.runsvstr; |
| 3082 |
oswp2(val.runsv.runsvstr, len); |
| 3083 |
|
| 3084 |
|
| 3085 |
runhres(ctx->bifcxrun, res_total, 0); |
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
if (val.runsv.runsvstr != ctx->bifcxrun->runcxhp) |
| 3094 |
{ |
| 3095 |
|
| 3096 |
memmove(ctx->bifcxrun->runcxhp, val.runsv.runsvstr, len); |
| 3097 |
|
| 3098 |
|
| 3099 |
val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 3100 |
} |
| 3101 |
|
| 3102 |
|
| 3103 |
dst = val.runsv.runsvstr + len; |
| 3104 |
} |
| 3105 |
} |
| 3106 |
|
| 3107 |
|
| 3108 |
len = dst - val.runsv.runsvstr; |
| 3109 |
oswp2(val.runsv.runsvstr, len); |
| 3110 |
|
| 3111 |
|
| 3112 |
ctx->bifcxrun->runcxhp += len; |
| 3113 |
|
| 3114 |
|
| 3115 |
runrepush(ctx->bifcxrun, &val); |
| 3116 |
} |
| 3117 |
|
| 3118 |
|
| 3119 |
return; |
| 3120 |
|
| 3121 |
ret_error: |
| 3122 |
runpnil(ctx->bifcxrun); |
| 3123 |
} |
| 3124 |
|
| 3125 |
void bifcapture(bifcxdef *ctx, int argc) |
| 3126 |
{ |
| 3127 |
mcmcxdef *mcx = ctx->bifcxrun->runcxmem; |
| 3128 |
mcmon obj; |
| 3129 |
uint siz; |
| 3130 |
uint ofs; |
| 3131 |
uchar *p; |
| 3132 |
|
| 3133 |
|
| 3134 |
bifcntargs(ctx, 1, argc); |
| 3135 |
switch(runtostyp(ctx->bifcxrun)) |
| 3136 |
{ |
| 3137 |
case DAT_TRUE: |
| 3138 |
|
| 3139 |
tiocapture(ctx->bifcxtio, mcx, TRUE); |
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
siz = tiocapturesize(ctx->bifcxtio); |
| 3147 |
runpnum(ctx->bifcxrun, (long)siz); |
| 3148 |
break; |
| 3149 |
|
| 3150 |
case DAT_NUMBER: |
| 3151 |
|
| 3152 |
ofs = runpopnum(ctx->bifcxrun); |
| 3153 |
|
| 3154 |
|
| 3155 |
obj = tiogetcapture(ctx->bifcxtio); |
| 3156 |
siz = tiocapturesize(ctx->bifcxtio); |
| 3157 |
if (obj == MCMONINV) |
| 3158 |
{ |
| 3159 |
runpnil(ctx->bifcxrun); |
| 3160 |
return; |
| 3161 |
} |
| 3162 |
|
| 3163 |
|
| 3164 |
if (ofs == 0) |
| 3165 |
{ |
| 3166 |
tiocapture(ctx->bifcxtio, mcx, FALSE); |
| 3167 |
tioclrcapture(ctx->bifcxtio); |
| 3168 |
} |
| 3169 |
|
| 3170 |
|
| 3171 |
p = mcmlck(mcx, obj); |
| 3172 |
|
| 3173 |
|
| 3174 |
p += ofs; |
| 3175 |
siz = (ofs > siz) ? 0 : siz - ofs; |
| 3176 |
|
| 3177 |
ERRBEGIN(ctx->bifcxerr) |
| 3178 |
|
| 3179 |
|
| 3180 |
runpstr(ctx->bifcxrun, (char *)p, siz, 0); |
| 3181 |
|
| 3182 |
ERRCLEAN(ctx->bifcxerr) |
| 3183 |
|
| 3184 |
mcmunlck(mcx, obj); |
| 3185 |
ERRENDCLN(ctx->bifcxerr) |
| 3186 |
|
| 3187 |
|
| 3188 |
mcmunlck(mcx, obj); |
| 3189 |
break; |
| 3190 |
|
| 3191 |
default: |
| 3192 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "outcapture"); |
| 3193 |
} |
| 3194 |
} |
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
|
| 3199 |
void bifsysinfo(bifcxdef *ctx, int argc) |
| 3200 |
{ |
| 3201 |
runsdef val; |
| 3202 |
int id; |
| 3203 |
long result; |
| 3204 |
|
| 3205 |
|
| 3206 |
switch(id = (int)runpopnum(ctx->bifcxrun)) |
| 3207 |
{ |
| 3208 |
case SYSINFO_SYSINFO: |
| 3209 |
|
| 3210 |
bifcntargs(ctx, 1, argc); |
| 3211 |
val.runstyp = DAT_TRUE; |
| 3212 |
runpush(ctx->bifcxrun, DAT_TRUE, &val); |
| 3213 |
break; |
| 3214 |
|
| 3215 |
case SYSINFO_VERSION: |
| 3216 |
|
| 3217 |
bifcntargs(ctx, 1, argc); |
| 3218 |
runpushcstr(ctx->bifcxrun, TADS_RUNTIME_VERSION, |
| 3219 |
strlen(TADS_RUNTIME_VERSION), 0); |
| 3220 |
break; |
| 3221 |
|
| 3222 |
case SYSINFO_OS_NAME: |
| 3223 |
|
| 3224 |
bifcntargs(ctx, 1, argc); |
| 3225 |
runpushcstr(ctx->bifcxrun, OS_SYSTEM_NAME, strlen(OS_SYSTEM_NAME), 0); |
| 3226 |
break; |
| 3227 |
|
| 3228 |
case SYSINFO_HTML: |
| 3229 |
case SYSINFO_JPEG: |
| 3230 |
case SYSINFO_PNG: |
| 3231 |
case SYSINFO_WAV: |
| 3232 |
case SYSINFO_MIDI: |
| 3233 |
case SYSINFO_WAV_MIDI_OVL: |
| 3234 |
case SYSINFO_WAV_OVL: |
| 3235 |
case SYSINFO_PREF_IMAGES: |
| 3236 |
case SYSINFO_PREF_SOUNDS: |
| 3237 |
case SYSINFO_PREF_MUSIC: |
| 3238 |
case SYSINFO_PREF_LINKS: |
| 3239 |
case SYSINFO_MPEG: |
| 3240 |
case SYSINFO_MPEG1: |
| 3241 |
case SYSINFO_MPEG2: |
| 3242 |
case SYSINFO_MPEG3: |
| 3243 |
case SYSINFO_LINKS_HTTP: |
| 3244 |
case SYSINFO_LINKS_FTP: |
| 3245 |
case SYSINFO_LINKS_NEWS: |
| 3246 |
case SYSINFO_LINKS_MAILTO: |
| 3247 |
case SYSINFO_LINKS_TELNET: |
| 3248 |
case SYSINFO_PNG_TRANS: |
| 3249 |
case SYSINFO_PNG_ALPHA: |
| 3250 |
case SYSINFO_OGG: |
| 3251 |
case SYSINFO_MNG: |
| 3252 |
case SYSINFO_MNG_TRANS: |
| 3253 |
case SYSINFO_MNG_ALPHA: |
| 3254 |
case SYSINFO_TEXT_HILITE: |
| 3255 |
case SYSINFO_INTERP_CLASS: |
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
|
| 3260 |
bifcntargs(ctx, 1, argc); |
| 3261 |
if (os_get_sysinfo(id, 0, &result)) |
| 3262 |
{ |
| 3263 |
|
| 3264 |
runpnum(ctx->bifcxrun, result); |
| 3265 |
} |
| 3266 |
else |
| 3267 |
{ |
| 3268 |
|
| 3269 |
runpnil(ctx->bifcxrun); |
| 3270 |
} |
| 3271 |
break; |
| 3272 |
|
| 3273 |
case SYSINFO_HTML_MODE: |
| 3274 |
|
| 3275 |
bifcntargs(ctx, 1, argc); |
| 3276 |
val.runstyp = runclog(tio_is_html_mode()); |
| 3277 |
runpush(ctx->bifcxrun, val.runstyp, &val); |
| 3278 |
break; |
| 3279 |
|
| 3280 |
case SYSINFO_TEXT_COLORS: |
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
bifcntargs(ctx, 1, argc); |
| 3293 |
if (os_get_sysinfo(SYSINFO_HTML, 0, &result) && result != 0) |
| 3294 |
{ |
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
if (os_get_sysinfo(id, 0, &result)) |
| 3300 |
{ |
| 3301 |
|
| 3302 |
runpnum(ctx->bifcxrun, result); |
| 3303 |
} |
| 3304 |
else |
| 3305 |
{ |
| 3306 |
|
| 3307 |
runpnum(ctx->bifcxrun, SYSINFO_TXC_NONE); |
| 3308 |
} |
| 3309 |
} |
| 3310 |
else |
| 3311 |
{ |
| 3312 |
|
| 3313 |
runpnum(ctx->bifcxrun, SYSINFO_TXC_NONE); |
| 3314 |
} |
| 3315 |
break; |
| 3316 |
|
| 3317 |
case SYSINFO_BANNERS: |
| 3318 |
|
| 3319 |
bifcntargs(ctx, 1, argc); |
| 3320 |
runpnum(ctx->bifcxrun, 0); |
| 3321 |
break; |
| 3322 |
|
| 3323 |
default: |
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
for ( ; argc > 1 ; --argc) |
| 3329 |
rundisc(ctx->bifcxrun); |
| 3330 |
runpnil(ctx->bifcxrun); |
| 3331 |
break; |
| 3332 |
} |
| 3333 |
} |
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
void bifmore(bifcxdef *ctx, int argc) |
| 3339 |
{ |
| 3340 |
|
| 3341 |
bifcntargs(ctx, 0, argc); |
| 3342 |
|
| 3343 |
|
| 3344 |
tioflushn(ctx->bifcxtio, 1); |
| 3345 |
out_more_prompt(); |
| 3346 |
} |
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
void bifsetme(bifcxdef *ctx, int argc) |
| 3352 |
{ |
| 3353 |
objnum new_me; |
| 3354 |
|
| 3355 |
|
| 3356 |
bifcntargs(ctx, 1, argc); |
| 3357 |
|
| 3358 |
|
| 3359 |
new_me = runpopobj(ctx->bifcxrun); |
| 3360 |
|
| 3361 |
|
| 3362 |
if (new_me == MCMONINV) |
| 3363 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "parserSetMe"); |
| 3364 |
|
| 3365 |
|
| 3366 |
voc_set_me(ctx->bifcxrun->runcxvoc, new_me); |
| 3367 |
} |
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
void bifgetme(bifcxdef *ctx, int argc) |
| 3373 |
{ |
| 3374 |
|
| 3375 |
bifcntargs(ctx, 0, argc); |
| 3376 |
|
| 3377 |
|
| 3378 |
runpobj(ctx->bifcxrun, ctx->bifcxrun->runcxvoc->voccxme); |
| 3379 |
} |
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
void bifresearch(bifcxdef *ctx, int argc) |
| 3385 |
{ |
| 3386 |
uchar *patstr; |
| 3387 |
size_t patlen; |
| 3388 |
uchar *searchstr; |
| 3389 |
size_t searchlen; |
| 3390 |
int result_len; |
| 3391 |
int match_ofs; |
| 3392 |
|
| 3393 |
|
| 3394 |
bifcntargs(ctx, 2, argc); |
| 3395 |
|
| 3396 |
|
| 3397 |
patstr = runpopstr(ctx->bifcxrun); |
| 3398 |
patlen = osrp2(patstr) - 2; |
| 3399 |
patstr += 2; |
| 3400 |
|
| 3401 |
|
| 3402 |
searchstr = runpopstr(ctx->bifcxrun); |
| 3403 |
searchlen = osrp2(searchstr) - 2; |
| 3404 |
searchstr += 2; |
| 3405 |
|
| 3406 |
|
| 3407 |
match_ofs = re_compile_and_search(&ctx->bifcxregex, |
| 3408 |
(char *)patstr, patlen, |
| 3409 |
(char *)searchstr, searchlen, |
| 3410 |
&result_len); |
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
if (match_ofs < 0) |
| 3417 |
{ |
| 3418 |
|
| 3419 |
runpnil(ctx->bifcxrun); |
| 3420 |
} |
| 3421 |
else |
| 3422 |
{ |
| 3423 |
ushort listsiz; |
| 3424 |
runsdef val; |
| 3425 |
uchar *p; |
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
listsiz = 2 + (1+4)*2 + (1 + 2 + (ushort)(result_len)); |
| 3435 |
|
| 3436 |
|
| 3437 |
runhres(ctx->bifcxrun, listsiz, 0); |
| 3438 |
|
| 3439 |
|
| 3440 |
val.runstyp = DAT_LIST; |
| 3441 |
p = val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 3442 |
|
| 3443 |
|
| 3444 |
oswp2(p, listsiz); |
| 3445 |
p += 2; |
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
*p++ = DAT_NUMBER; |
| 3454 |
oswp4s(p, match_ofs + 1); |
| 3455 |
p += 4; |
| 3456 |
|
| 3457 |
|
| 3458 |
*p++ = DAT_NUMBER; |
| 3459 |
oswp4s(p, result_len); |
| 3460 |
p += 4; |
| 3461 |
|
| 3462 |
|
| 3463 |
*p++ = DAT_SSTRING; |
| 3464 |
oswp2(p, result_len + 2); |
| 3465 |
p += 2; |
| 3466 |
memcpy(p, ctx->bifcxregex.strbuf + match_ofs, result_len); |
| 3467 |
|
| 3468 |
|
| 3469 |
ctx->bifcxrun->runcxhp += listsiz; |
| 3470 |
|
| 3471 |
|
| 3472 |
runrepush(ctx->bifcxrun, &val); |
| 3473 |
} |
| 3474 |
} |
| 3475 |
|
| 3476 |
|
| 3477 |
void bifregroup(bifcxdef *ctx, int argc) |
| 3478 |
{ |
| 3479 |
int grp; |
| 3480 |
size_t len; |
| 3481 |
re_group_register *reg; |
| 3482 |
ushort hplen; |
| 3483 |
runsdef val; |
| 3484 |
uchar *p; |
| 3485 |
long numval; |
| 3486 |
|
| 3487 |
|
| 3488 |
bifcntargs(ctx, 1, argc); |
| 3489 |
|
| 3490 |
|
| 3491 |
grp = (int)runpopnum(ctx->bifcxrun); |
| 3492 |
|
| 3493 |
|
| 3494 |
if (grp < 1 || grp > RE_GROUP_REG_CNT) |
| 3495 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "reGetGroup"); |
| 3496 |
|
| 3497 |
|
| 3498 |
--grp; |
| 3499 |
|
| 3500 |
|
| 3501 |
if (grp >= ctx->bifcxregex.cur_group) |
| 3502 |
{ |
| 3503 |
runpnil(ctx->bifcxrun); |
| 3504 |
return; |
| 3505 |
} |
| 3506 |
|
| 3507 |
|
| 3508 |
reg = &ctx->bifcxregex.regs[grp]; |
| 3509 |
|
| 3510 |
|
| 3511 |
if (reg->start_ofs == 0 || reg->end_ofs == 0) |
| 3512 |
{ |
| 3513 |
runpnil(ctx->bifcxrun); |
| 3514 |
return; |
| 3515 |
} |
| 3516 |
|
| 3517 |
|
| 3518 |
len = reg->end_ofs - reg->start_ofs; |
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
hplen = (ushort)(2 + 2*(1+4) + (1 + 2 + len)); |
| 3528 |
runhres(ctx->bifcxrun, hplen, 0); |
| 3529 |
|
| 3530 |
|
| 3531 |
val.runstyp = DAT_LIST; |
| 3532 |
p = val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 3533 |
|
| 3534 |
|
| 3535 |
oswp2(p, hplen); |
| 3536 |
p += 2; |
| 3537 |
|
| 3538 |
|
| 3539 |
*p++ = DAT_NUMBER; |
| 3540 |
numval = (long)(reg->start_ofs - ctx->bifcxregex.strbuf) + 1; |
| 3541 |
oswp4s(p, numval); |
| 3542 |
p += 4; |
| 3543 |
|
| 3544 |
|
| 3545 |
*p++ = DAT_NUMBER; |
| 3546 |
numval = (long)(reg->end_ofs - reg->start_ofs); |
| 3547 |
oswp4s(p, numval); |
| 3548 |
p += 4; |
| 3549 |
|
| 3550 |
|
| 3551 |
*p++ = DAT_SSTRING; |
| 3552 |
oswp2(p, len+2); |
| 3553 |
p += 2; |
| 3554 |
memcpy(p, reg->start_ofs, len); |
| 3555 |
|
| 3556 |
|
| 3557 |
ctx->bifcxrun->runcxhp += hplen; |
| 3558 |
|
| 3559 |
|
| 3560 |
runrepush(ctx->bifcxrun, &val); |
| 3561 |
} |
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
void bifinpevt(bifcxdef *ctx, int argc) |
| 3568 |
{ |
| 3569 |
unsigned long timeout; |
| 3570 |
int use_timeout; |
| 3571 |
os_event_info_t info; |
| 3572 |
int evt; |
| 3573 |
uchar *p; |
| 3574 |
ushort lstsiz; |
| 3575 |
runsdef val; |
| 3576 |
size_t paramlen; |
| 3577 |
char keyname[20]; |
| 3578 |
|
| 3579 |
|
| 3580 |
if (argc == 0) |
| 3581 |
{ |
| 3582 |
|
| 3583 |
use_timeout = FALSE; |
| 3584 |
timeout = 0; |
| 3585 |
} |
| 3586 |
else if (argc >= 1) |
| 3587 |
{ |
| 3588 |
|
| 3589 |
use_timeout = TRUE; |
| 3590 |
timeout = (unsigned long)runpopnum(ctx->bifcxrun); |
| 3591 |
} |
| 3592 |
|
| 3593 |
|
| 3594 |
if (argc > 1) |
| 3595 |
runsig(ctx->bifcxrun, ERR_BIFARGC); |
| 3596 |
|
| 3597 |
|
| 3598 |
tioflushn(ctx->bifcxtio, 0); |
| 3599 |
|
| 3600 |
|
| 3601 |
tioreset(ctx->bifcxtio); |
| 3602 |
|
| 3603 |
|
| 3604 |
evt = os_get_event(timeout, use_timeout, &info); |
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
|
| 3610 |
|
| 3611 |
lstsiz = 2 + (1 + 4); |
| 3612 |
|
| 3613 |
|
| 3614 |
switch(evt) |
| 3615 |
{ |
| 3616 |
case OS_EVT_KEY: |
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
paramlen = (info.key[0] == 0 ? 2 : 1); |
| 3624 |
|
| 3625 |
|
| 3626 |
get_ext_key_name(keyname, info.key[0], info.key[1]); |
| 3627 |
|
| 3628 |
|
| 3629 |
paramlen = strlen(keyname); |
| 3630 |
|
| 3631 |
|
| 3632 |
lstsiz += 1 + 2 + paramlen; |
| 3633 |
break; |
| 3634 |
|
| 3635 |
case OS_EVT_HREF: |
| 3636 |
|
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
paramlen = strlen(info.href); |
| 3641 |
lstsiz += 1 + 2 + (ushort)paramlen; |
| 3642 |
break; |
| 3643 |
|
| 3644 |
default: |
| 3645 |
|
| 3646 |
break; |
| 3647 |
} |
| 3648 |
|
| 3649 |
|
| 3650 |
runhres(ctx->bifcxrun, lstsiz, 0); |
| 3651 |
|
| 3652 |
|
| 3653 |
val.runstyp = DAT_LIST; |
| 3654 |
p = val.runsv.runsvstr = ctx->bifcxrun->runcxhp; |
| 3655 |
|
| 3656 |
|
| 3657 |
oswp2(p, lstsiz); |
| 3658 |
p += 2; |
| 3659 |
|
| 3660 |
|
| 3661 |
*p++ = DAT_NUMBER; |
| 3662 |
oswp4s(p, evt); |
| 3663 |
p += 4; |
| 3664 |
|
| 3665 |
|
| 3666 |
switch(evt) |
| 3667 |
{ |
| 3668 |
case OS_EVT_KEY: |
| 3669 |
|
| 3670 |
*p++ = DAT_SSTRING; |
| 3671 |
oswp2(p, paramlen + 2); |
| 3672 |
p += 2; |
| 3673 |
|
| 3674 |
|
| 3675 |
memcpy(p, keyname, paramlen); |
| 3676 |
p += paramlen; |
| 3677 |
break; |
| 3678 |
|
| 3679 |
case OS_EVT_HREF: |
| 3680 |
|
| 3681 |
*p++ = DAT_SSTRING; |
| 3682 |
oswp2(p, paramlen + 2); |
| 3683 |
memcpy(p + 2, info.href, paramlen); |
| 3684 |
break; |
| 3685 |
} |
| 3686 |
|
| 3687 |
|
| 3688 |
ctx->bifcxrun->runcxhp += lstsiz; |
| 3689 |
|
| 3690 |
|
| 3691 |
runrepush(ctx->bifcxrun, &val); |
| 3692 |
} |
| 3693 |
|
| 3694 |
|
| 3695 |
void bifdelay(bifcxdef *ctx, int argc) |
| 3696 |
{ |
| 3697 |
long delay; |
| 3698 |
|
| 3699 |
|
| 3700 |
bifcntargs(ctx, 1, argc); |
| 3701 |
|
| 3702 |
|
| 3703 |
tioflushn(ctx->bifcxtio, 0); |
| 3704 |
|
| 3705 |
|
| 3706 |
delay = runpopnum(ctx->bifcxrun); |
| 3707 |
|
| 3708 |
|
| 3709 |
os_sleep_ms(delay); |
| 3710 |
} |
| 3711 |
|
| 3712 |
|
| 3713 |
void bifsetoutfilter(bifcxdef *ctx, int argc) |
| 3714 |
{ |
| 3715 |
|
| 3716 |
bifcntargs(ctx, 1, argc); |
| 3717 |
|
| 3718 |
|
| 3719 |
switch(runtostyp(ctx->bifcxrun)) |
| 3720 |
{ |
| 3721 |
case DAT_NIL: |
| 3722 |
|
| 3723 |
out_set_filter(MCMONINV); |
| 3724 |
|
| 3725 |
|
| 3726 |
rundisc(ctx->bifcxrun); |
| 3727 |
break; |
| 3728 |
|
| 3729 |
case DAT_FNADDR: |
| 3730 |
|
| 3731 |
out_set_filter(runpopfn(ctx->bifcxrun)); |
| 3732 |
break; |
| 3733 |
|
| 3734 |
default: |
| 3735 |
|
| 3736 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "setOutputFilter"); |
| 3737 |
} |
| 3738 |
} |
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
|
| 3746 |
static objnum bif_get_optional_obj_arg(bifcxdef *ctx, int *rem_argc) |
| 3747 |
{ |
| 3748 |
|
| 3749 |
if (*rem_argc == 0) |
| 3750 |
return MCMONINV; |
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
if (runtostyp(ctx->bifcxrun) != DAT_OBJECT |
| 3757 |
&& runtostyp(ctx->bifcxrun) != DAT_NIL) |
| 3758 |
return MCMONINV; |
| 3759 |
|
| 3760 |
|
| 3761 |
--(*rem_argc); |
| 3762 |
|
| 3763 |
|
| 3764 |
return runpopobjnil(ctx->bifcxrun); |
| 3765 |
} |
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
#define EC_HIDE_SUCCESS 0x00000001 |
| 3771 |
#define EC_HIDE_ERROR 0x00000002 |
| 3772 |
#define EC_SKIP_VALIDDO 0x00000004 |
| 3773 |
#define EC_SKIP_VALIDIO 0x00000008 |
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
void bifexec(bifcxdef *ctx, int argc) |
| 3779 |
{ |
| 3780 |
objnum actor; |
| 3781 |
objnum verb; |
| 3782 |
objnum dobj; |
| 3783 |
objnum prep; |
| 3784 |
objnum iobj; |
| 3785 |
int err; |
| 3786 |
uint capture_start; |
| 3787 |
uint capture_end; |
| 3788 |
objnum capture_obj; |
| 3789 |
ulong flags; |
| 3790 |
int hide_any; |
| 3791 |
int rem_argc; |
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
if (argc < 2 || argc > 6) |
| 3798 |
runsig(ctx->bifcxrun, ERR_BIFARGC); |
| 3799 |
|
| 3800 |
|
| 3801 |
actor = runpopobjnil(ctx->bifcxrun); |
| 3802 |
verb = runpopobjnil(ctx->bifcxrun); |
| 3803 |
|
| 3804 |
|
| 3805 |
|
| 3806 |
|
| 3807 |
|
| 3808 |
|
| 3809 |
rem_argc = argc - 2; |
| 3810 |
dobj = bif_get_optional_obj_arg(ctx, &rem_argc); |
| 3811 |
prep = bif_get_optional_obj_arg(ctx, &rem_argc); |
| 3812 |
iobj = bif_get_optional_obj_arg(ctx, &rem_argc); |
| 3813 |
|
| 3814 |
|
| 3815 |
if (rem_argc > 0) |
| 3816 |
{ |
| 3817 |
|
| 3818 |
flags = runpopnum(ctx->bifcxrun); |
| 3819 |
|
| 3820 |
|
| 3821 |
--rem_argc; |
| 3822 |
} |
| 3823 |
else |
| 3824 |
{ |
| 3825 |
|
| 3826 |
flags = 0; |
| 3827 |
} |
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
if (rem_argc != 0) |
| 3836 |
runsig1(ctx->bifcxrun, ERR_INVTBIF, ERRTSTR, "execCommand"); |
| 3837 |
|
| 3838 |
|
| 3839 |
hide_any = ((flags & (EC_HIDE_SUCCESS | EC_HIDE_ERROR)) != 0); |
| 3840 |
if (hide_any) |
| 3841 |
{ |
| 3842 |
|
| 3843 |
tiocapture(ctx->bifcxtio, ctx->bifcxrun->runcxmem, TRUE); |
| 3844 |
|
| 3845 |
|
| 3846 |
capture_start = tiocapturesize(ctx->bifcxtio); |
| 3847 |
} |
| 3848 |
|
| 3849 |
|
| 3850 |
err = execmd_recurs(ctx->bifcxrun->runcxvoc, |
| 3851 |
actor, verb, dobj, prep, iobj, |
| 3852 |
(flags & EC_SKIP_VALIDDO) == 0, |
| 3853 |
(flags & EC_SKIP_VALIDIO) == 0); |
| 3854 |
|
| 3855 |
|
| 3856 |
if (hide_any) |
| 3857 |
{ |
| 3858 |
uchar *p; |
| 3859 |
int hide; |
| 3860 |
|
| 3861 |
|
| 3862 |
capture_end = tiocapturesize(ctx->bifcxtio); |
| 3863 |
|
| 3864 |
|
| 3865 |
if (capture_start == 0) |
| 3866 |
tiocapture(ctx->bifcxtio, ctx->bifcxrun->runcxmem, FALSE); |
| 3867 |
|
| 3868 |
|
| 3869 |
if (err == 0) |
| 3870 |
hide = ((flags & EC_HIDE_SUCCESS) != 0); |
| 3871 |
else |
| 3872 |
hide = ((flags & EC_HIDE_ERROR) != 0); |
| 3873 |
|
| 3874 |
|
| 3875 |
if (hide) |
| 3876 |
{ |
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
|
| 3882 |
if (capture_start != 0) |
| 3883 |
tiopopcapture(ctx->bifcxtio, capture_start); |
| 3884 |
} |
| 3885 |
else |
| 3886 |
{ |
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
if (capture_start == 0) |
| 3893 |
{ |
| 3894 |
|
| 3895 |
capture_obj = tiogetcapture(ctx->bifcxtio); |
| 3896 |
p = mcmlck(ctx->bifcxrun->runcxmem, capture_obj); |
| 3897 |
|
| 3898 |
ERRBEGIN(ctx->bifcxerr) |
| 3899 |
{ |
| 3900 |
|
| 3901 |
outformatlen((char *)p + capture_start, |
| 3902 |
capture_end - capture_start); |
| 3903 |
} |
| 3904 |
ERRCLEAN(ctx->bifcxerr) |
| 3905 |
{ |
| 3906 |
|
| 3907 |
mcmunlck(ctx->bifcxrun->runcxmem, capture_obj); |
| 3908 |
} |
| 3909 |
ERRENDCLN(ctx->bifcxerr); |
| 3910 |
|
| 3911 |
|
| 3912 |
mcmunlck(ctx->bifcxrun->runcxmem, capture_obj); |
| 3913 |
} |
| 3914 |
} |
| 3915 |
|
| 3916 |
|
| 3917 |
if (capture_start == 0) |
| 3918 |
tioclrcapture(ctx->bifcxtio); |
| 3919 |
} |
| 3920 |
|
| 3921 |
|
| 3922 |
runpnum(ctx->bifcxrun, err); |
| 3923 |
} |
| 3924 |
|
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
void bifgetobj(bifcxdef *ctx, int argc) |
| 3929 |
{ |
| 3930 |
int id; |
| 3931 |
objnum obj; |
| 3932 |
voccxdef *voc = ctx->bifcxrun->runcxvoc; |
| 3933 |
|
| 3934 |
|
| 3935 |
bifcntargs(ctx, 1, argc); |
| 3936 |
|
| 3937 |
|
| 3938 |
id = (int)runpopnum(ctx->bifcxrun); |
| 3939 |
|
| 3940 |
|
| 3941 |
switch(id) |
| 3942 |
{ |
| 3943 |
case 1: |
| 3944 |
|
| 3945 |
obj = voc->voccxactor; |
| 3946 |
|
| 3947 |
|
| 3948 |
if (obj == MCMONINV) |
| 3949 |
obj = voc->voccxme; |
| 3950 |
|
| 3951 |
|
| 3952 |
break; |
| 3953 |
|
| 3954 |
case 2: |
| 3955 |
|
| 3956 |
obj = voc->voccxverb; |
| 3957 |
break; |
| 3958 |
|
| 3959 |
case 3: |
| 3960 |
|
| 3961 |
obj = (voc->voccxdobj == 0 ? MCMONINV : voc->voccxdobj->vocolobj); |
| 3962 |
break; |
| 3963 |
|
| 3964 |
case 4: |
| 3965 |
|
| 3966 |
obj = voc->voccxprep; |
| 3967 |
break; |
| 3968 |
|
| 3969 |
case 5: |
| 3970 |
|
| 3971 |
obj = (voc->voccxiobj == 0 ? MCMONINV : voc->voccxiobj->vocolobj); |
| 3972 |
break; |
| 3973 |
|
| 3974 |
case 6: |
| 3975 |
|
| 3976 |
obj = voc->voccxit; |
| 3977 |
break; |
| 3978 |
|
| 3979 |
case 7: |
| 3980 |
|
| 3981 |
obj = voc->voccxhim; |
| 3982 |
break; |
| 3983 |
|
| 3984 |
case 8: |
| 3985 |
|
| 3986 |
obj = voc->voccxher; |
| 3987 |
break; |
| 3988 |
|
| 3989 |
case 9: |
| 3990 |
|
| 3991 |
voc_push_objlist(voc, voc->voccxthm, voc->voccxthc); |
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
return; |
| 3998 |
|
| 3999 |
default: |
| 4000 |
|
| 4001 |
runsig1(ctx->bifcxrun, ERR_INVVBIF, ERRTSTR, "parserGetObj"); |
| 4002 |
break; |
| 4003 |
} |
| 4004 |
|
| 4005 |
|
| 4006 |
runpobj(ctx->bifcxrun, obj); |
| 4007 |
} |
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
void bifparsenl(bifcxdef *ctx, int argc) |
| 4016 |
{ |
| 4017 |
|
| 4018 |
bifcntargs(ctx, 6, argc); |
| 4019 |
|
| 4020 |
|
| 4021 |
voc_parse_np(ctx->bifcxrun->runcxvoc); |
| 4022 |
} |
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
void bifprstok(bifcxdef *ctx, int argc) |
| 4031 |
{ |
| 4032 |
|
| 4033 |
bifcntargs(ctx, 1, argc); |
| 4034 |
|
| 4035 |
|
| 4036 |
voc_parse_tok(ctx->bifcxrun->runcxvoc); |
| 4037 |
} |
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
void bifprstoktyp(bifcxdef *ctx, int argc) |
| 4046 |
{ |
| 4047 |
|
| 4048 |
bifcntargs(ctx, 1, argc); |
| 4049 |
|
| 4050 |
|
| 4051 |
voc_parse_types(ctx->bifcxrun->runcxvoc); |
| 4052 |
} |
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
void bifprsdict(bifcxdef *ctx, int argc) |
| 4061 |
{ |
| 4062 |
|
| 4063 |
bifcntargs(ctx, 2, argc); |
| 4064 |
|
| 4065 |
|
| 4066 |
voc_parse_dict_lookup(ctx->bifcxrun->runcxvoc); |
| 4067 |
} |
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
void bifprsrslv(bifcxdef *ctx, int argc) |
| 4077 |
{ |
| 4078 |
|
| 4079 |
bifcntargs(ctx, 9, argc); |
| 4080 |
|
| 4081 |
|
| 4082 |
voc_parse_disambig(ctx->bifcxrun->runcxvoc); |
| 4083 |
} |
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
void bifprsrplcmd(bifcxdef *ctx, int argc) |
| 4090 |
{ |
| 4091 |
|
| 4092 |
bifcntargs(ctx, 1, argc); |
| 4093 |
|
| 4094 |
|
| 4095 |
voc_parse_replace_cmd(ctx->bifcxrun->runcxvoc); |
| 4096 |
} |
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
void bifexitobj(bifcxdef *ctx, int argc) |
| 4102 |
{ |
| 4103 |
|
| 4104 |
bifcntargs(ctx, 0, argc); |
| 4105 |
|
| 4106 |
|
| 4107 |
errsig(ctx->bifcxerr, ERR_RUNEXITOBJ); |
| 4108 |
} |
| 4109 |
|
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
#define BIFINPDLG_LBL_OK 1 |
| 4114 |
#define BIFINPDLG_LBL_CANCEL 2 |
| 4115 |
#define BIFINPDLG_LBL_YES 3 |
| 4116 |
#define BIFINPDLG_LBL_NO 4 |
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
void bifinpdlg(bifcxdef *ctx, int argc) |
| 4122 |
{ |
| 4123 |
uchar *p; |
| 4124 |
char prompt[256]; |
| 4125 |
char lblbuf[256]; |
| 4126 |
char *labels[10]; |
| 4127 |
char *dst; |
| 4128 |
char *xp; |
| 4129 |
uint len; |
| 4130 |
size_t bcnt; |
| 4131 |
int default_resp, cancel_resp; |
| 4132 |
int resp; |
| 4133 |
int std_btns; |
| 4134 |
int icon_id; |
| 4135 |
|
| 4136 |
|
| 4137 |
bifcntargs(ctx, 5, argc); |
| 4138 |
|
| 4139 |
|
| 4140 |
icon_id = runpopnum(ctx->bifcxrun); |
| 4141 |
|
| 4142 |
|
| 4143 |
p = runpopstr(ctx->bifcxrun); |
| 4144 |
bifcstr(ctx, prompt, (size_t)sizeof(prompt), p); |
| 4145 |
|
| 4146 |
|
| 4147 |
for (xp = prompt ; *xp != '\0' ; xp++) |
| 4148 |
*xp = (char)cmap_i2n(*xp); |
| 4149 |
|
| 4150 |
|
| 4151 |
if (runtostyp(ctx->bifcxrun) == DAT_NUMBER) |
| 4152 |
{ |
| 4153 |
|
| 4154 |
std_btns = runpopnum(ctx->bifcxrun); |
| 4155 |
|
| 4156 |
|
| 4157 |
bcnt = 0; |
| 4158 |
} |
| 4159 |
else |
| 4160 |
{ |
| 4161 |
|
| 4162 |
std_btns = 0; |
| 4163 |
|
| 4164 |
|
| 4165 |
p = runpoplst(ctx->bifcxrun); |
| 4166 |
len = osrp2(p); |
| 4167 |
p += 2; |
| 4168 |
|
| 4169 |
|
| 4170 |
for (bcnt = 0, dst = lblbuf ; len != 0 ; lstadv(&p, &len)) |
| 4171 |
{ |
| 4172 |
|
| 4173 |
if (*p == DAT_SSTRING) |
| 4174 |
{ |
| 4175 |
|
| 4176 |
bifcstr(ctx, dst, sizeof(lblbuf) - (dst - lblbuf), p + 1); |
| 4177 |
|
| 4178 |
|
| 4179 |
for (xp = dst ; *xp != '\0' ; xp++) |
| 4180 |
*xp = (char)cmap_i2n(*xp); |
| 4181 |
|
| 4182 |
|
| 4183 |
labels[bcnt++] = dst; |
| 4184 |
|
| 4185 |
|
| 4186 |
dst += strlen(dst) + 1; |
| 4187 |
} |
| 4188 |
else if (*p == DAT_NUMBER) |
| 4189 |
{ |
| 4190 |
int id; |
| 4191 |
int resid; |
| 4192 |
|
| 4193 |
|
| 4194 |
id = (int)osrp4s(p + 1); |
| 4195 |
|
| 4196 |
|
| 4197 |
switch(id) |
| 4198 |
{ |
| 4199 |
case BIFINPDLG_LBL_OK: |
| 4200 |
resid = RESID_BTN_OK; |
| 4201 |
break; |
| 4202 |
|
| 4203 |
case BIFINPDLG_LBL_CANCEL: |
| 4204 |
resid = RESID_BTN_CANCEL; |
| 4205 |
break; |
| 4206 |
|
| 4207 |
case BIFINPDLG_LBL_YES: |
| 4208 |
resid = RESID_BTN_YES; |
| 4209 |
break; |
| 4210 |
|
| 4211 |
case BIFINPDLG_LBL_NO: |
| 4212 |
resid = RESID_BTN_NO; |
| 4213 |
break; |
| 4214 |
|
| 4215 |
default: |
| 4216 |
resid = 0; |
| 4217 |
break; |
| 4218 |
} |
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
if (resid != 0 |
| 4225 |
&& !os_get_str_rsc(resid, dst, |
| 4226 |
sizeof(lblbuf) - (dst - lblbuf))) |
| 4227 |
{ |
| 4228 |
|
| 4229 |
labels[bcnt++] = dst; |
| 4230 |
|
| 4231 |
|
| 4232 |
dst += strlen(dst) + 1; |
| 4233 |
} |
| 4234 |
} |
| 4235 |
|
| 4236 |
|
| 4237 |
if (bcnt >= sizeof(labels)/sizeof(labels[0]) |
| 4238 |
|| dst >= lblbuf + sizeof(lblbuf)) |
| 4239 |
break; |
| 4240 |
} |
| 4241 |
} |
| 4242 |
|
| 4243 |
|
| 4244 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 4245 |
{ |
| 4246 |
rundisc(ctx->bifcxrun); |
| 4247 |
default_resp = 0; |
| 4248 |
} |
| 4249 |
else |
| 4250 |
default_resp = runpopnum(ctx->bifcxrun); |
| 4251 |
|
| 4252 |
|
| 4253 |
if (runtostyp(ctx->bifcxrun) == DAT_NIL) |
| 4254 |
{ |
| 4255 |
rundisc(ctx->bifcxrun); |
| 4256 |
cancel_resp = 0; |
| 4257 |
} |
| 4258 |
else |
| 4259 |
cancel_resp = runpopnum(ctx->bifcxrun); |
| 4260 |
|
| 4261 |
|
| 4262 |
tioflushn(ctx->bifcxtio, 0); |
| 4263 |
|
| 4264 |
|
| 4265 |
resp = tio_input_dialog(icon_id, prompt, std_btns, |
| 4266 |
(const char **)labels, bcnt, |
| 4267 |
default_resp, cancel_resp); |
| 4268 |
|
| 4269 |
|
| 4270 |
runpnum(ctx->bifcxrun, resp); |
| 4271 |
} |
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
void bifresexists(bifcxdef *ctx, int argc) |
| 4277 |
{ |
| 4278 |
uchar *p; |
| 4279 |
char resname[OSFNMAX]; |
| 4280 |
appctxdef *appctx; |
| 4281 |
int found; |
| 4282 |
runsdef val; |
| 4283 |
|
| 4284 |
|
| 4285 |
bifcntargs(ctx, 1, argc); |
| 4286 |
|
| 4287 |
|
| 4288 |
p = runpopstr(ctx->bifcxrun); |
| 4289 |
bifcstr(ctx, resname, (size_t)sizeof(resname), p); |
| 4290 |
|
| 4291 |
|
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
appctx = ctx->bifcxappctx; |
| 4299 |
found = (appctx != 0 |
| 4300 |
&& appctx->resfile_exists != 0 |
| 4301 |
&& (*appctx->resfile_exists)(appctx->resfile_exists_ctx, |
| 4302 |
resname, strlen(resname))); |
| 4303 |
|
| 4304 |
|
| 4305 |
runpush(ctx->bifcxrun, runclog(found), &val); |
| 4306 |
} |