Deleted Added
full compact
loader.c (82941) loader.c (87636)
1/*-
2 * Copyright (c) 2000 Daniel Capo Sobral
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000 Daniel Capo Sobral
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/boot/ficl/loader.c 82941 2001-09-04 08:51:15Z dfr $
26 * $FreeBSD: head/sys/boot/ficl/loader.c 87636 2001-12-11 00:49:34Z jhb $
27 */
28
29/*******************************************************************
30** l o a d e r . c
31** Additional FICL words designed for FreeBSD's loader
32**
33*******************************************************************/
34

--- 331 unchanged lines hidden (view full) ---

366 c = stackPop(pVM->pStack);
367 ltoa((c).i, pVM->pad, pVM->base);
368 vmTextOut(pVM, pVM->pad, 0);
369 return;
370}
371
372/* fopen - open a file and return new fd on stack.
373 *
27 */
28
29/*******************************************************************
30** l o a d e r . c
31** Additional FICL words designed for FreeBSD's loader
32**
33*******************************************************************/
34

--- 331 unchanged lines hidden (view full) ---

366 c = stackPop(pVM->pStack);
367 ltoa((c).i, pVM->pad, pVM->base);
368 vmTextOut(pVM, pVM->pad, 0);
369 return;
370}
371
372/* fopen - open a file and return new fd on stack.
373 *
374 * fopen ( count ptr -- fd )
374 * fopen ( ptr count mode -- fd )
375 */
376static void pfopen(FICL_VM *pVM)
377{
375 */
376static void pfopen(FICL_VM *pVM)
377{
378 int fd;
379 char *p;
378 int mode, fd, count;
379 char *ptr, *name;
380
381#if FICL_ROBUST > 1
380
381#if FICL_ROBUST > 1
382 vmCheckStack(pVM, 2, 1);
382 vmCheckStack(pVM, 3, 1);
383#endif
383#endif
384 (void)stackPopINT(pVM->pStack); /* don't need count value */
385 p = stackPopPtr(pVM->pStack);
386 fd = open(p, O_RDONLY);
384
385 mode = stackPopINT(pVM->pStack); /* get mode */
386 count = stackPopINT(pVM->pStack); /* get count */
387 ptr = stackPopPtr(pVM->pStack); /* get ptr */
388
389 if ((count < 0) || (ptr == NULL)) {
390 stackPushINT(pVM->pStack, -1);
391 return;
392 }
393
394 /* ensure that the string is null terminated */
395 name = (char *)malloc(count+1);
396 bcopy(ptr,name,count);
397 name[count] = 0;
398
399 /* open the file */
400 fd = open(name, mode);
401 free(name);
387 stackPushINT(pVM->pStack, fd);
388 return;
402 stackPushINT(pVM->pStack, fd);
403 return;
389 }
404}
390
391/* fclose - close a file who's fd is on stack.
392 *
393 * fclose ( fd -- )
394 */
395static void pfclose(FICL_VM *pVM)
396{
397 int fd;

--- 41 unchanged lines hidden (view full) ---

439 vmCheckStack(pVM, 1, 0);
440#endif
441 fd = stackPopINT(pVM->pStack); /* get fd */
442 if (fd != -1)
443 ficlExecFD(pVM, fd);
444 return;
445}
446
405
406/* fclose - close a file who's fd is on stack.
407 *
408 * fclose ( fd -- )
409 */
410static void pfclose(FICL_VM *pVM)
411{
412 int fd;

--- 41 unchanged lines hidden (view full) ---

454 vmCheckStack(pVM, 1, 0);
455#endif
456 fd = stackPopINT(pVM->pStack); /* get fd */
457 if (fd != -1)
458 ficlExecFD(pVM, fd);
459 return;
460}
461
462/* fwrite - write file contents
463 *
464 * fwrite ( fd buf nbytes -- nwritten )
465 */
466static void pfwrite(FICL_VM *pVM)
467{
468 int fd, len;
469 char *buf;
470
471#if FICL_ROBUST > 1
472 vmCheckStack(pVM, 3, 1);
473#endif
474 len = stackPopINT(pVM->pStack); /* get number of bytes to read */
475 buf = stackPopPtr(pVM->pStack); /* get buffer */
476 fd = stackPopINT(pVM->pStack); /* get fd */
477 if (len > 0 && buf && fd != -1)
478 stackPushINT(pVM->pStack, write(fd, buf, len));
479 else
480 stackPushINT(pVM->pStack, -1);
481 return;
482}
483
484/* fseek - seek to a new position in a file
485 *
486 * fseek ( fd ofs whence -- pos )
487 */
488static void pfseek(FICL_VM *pVM)
489{
490 int fd, pos, whence;
491
492#if FICL_ROBUST > 1
493 vmCheckStack(pVM, 3, 1);
494#endif
495 whence = stackPopINT(pVM->pStack);
496 pos = stackPopINT(pVM->pStack);
497 fd = stackPopINT(pVM->pStack);
498 stackPushINT(pVM->pStack, lseek(fd, pos, whence));
499 return;
500}
501
447/* key - get a character from stdin
448 *
449 * key ( -- char )
450 */
451static void key(FICL_VM *pVM)
452{
453#if FICL_ROBUST > 1
454 vmCheckStack(pVM, 0, 1);

--- 108 unchanged lines hidden (view full) ---

563 assert (dp);
564
565 dictAppendWord(dp, ".#", displayCellNoPad, FW_DEFAULT);
566 dictAppendWord(dp, "fopen", pfopen, FW_DEFAULT);
567 dictAppendWord(dp, "fclose", pfclose, FW_DEFAULT);
568 dictAppendWord(dp, "fread", pfread, FW_DEFAULT);
569 dictAppendWord(dp, "fload", pfload, FW_DEFAULT);
570 dictAppendWord(dp, "fkey", fkey, FW_DEFAULT);
502/* key - get a character from stdin
503 *
504 * key ( -- char )
505 */
506static void key(FICL_VM *pVM)
507{
508#if FICL_ROBUST > 1
509 vmCheckStack(pVM, 0, 1);

--- 108 unchanged lines hidden (view full) ---

618 assert (dp);
619
620 dictAppendWord(dp, ".#", displayCellNoPad, FW_DEFAULT);
621 dictAppendWord(dp, "fopen", pfopen, FW_DEFAULT);
622 dictAppendWord(dp, "fclose", pfclose, FW_DEFAULT);
623 dictAppendWord(dp, "fread", pfread, FW_DEFAULT);
624 dictAppendWord(dp, "fload", pfload, FW_DEFAULT);
625 dictAppendWord(dp, "fkey", fkey, FW_DEFAULT);
626 dictAppendWord(dp, "fseek", pfseek, FW_DEFAULT);
627 dictAppendWord(dp, "fwrite", pfwrite, FW_DEFAULT);
571 dictAppendWord(dp, "key", key, FW_DEFAULT);
572 dictAppendWord(dp, "key?", keyQuestion, FW_DEFAULT);
573 dictAppendWord(dp, "ms", ms, FW_DEFAULT);
574 dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT);
575 dictAppendWord(dp, "heap?", freeHeap, FW_DEFAULT);
576 dictAppendWord(dp, "dictthreshold", ficlDictThreshold, FW_DEFAULT);
577 dictAppendWord(dp, "dictincrease", ficlDictIncrease, FW_DEFAULT);
578

--- 36 unchanged lines hidden ---
628 dictAppendWord(dp, "key", key, FW_DEFAULT);
629 dictAppendWord(dp, "key?", keyQuestion, FW_DEFAULT);
630 dictAppendWord(dp, "ms", ms, FW_DEFAULT);
631 dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT);
632 dictAppendWord(dp, "heap?", freeHeap, FW_DEFAULT);
633 dictAppendWord(dp, "dictthreshold", ficlDictThreshold, FW_DEFAULT);
634 dictAppendWord(dp, "dictincrease", ficlDictIncrease, FW_DEFAULT);
635

--- 36 unchanged lines hidden ---