Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 06 Oct 2001 12:32:14 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        current@freebsd.org
Subject:   FORTH PATCH FOR KRIS TO COMMIT
Message-ID:  <3BBF5C3E.3F88B4CD@mindspring.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------D1FD7E74232804756F25371E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Here is a patch to add the verbs "fwrite" and "flseek" to the
FORTH interpreter.

This is a necessary part of reimplementing the "nextboot" code,
which was murdered when the new boot loader came in.

Commit, K PLZ THX.

-- Terry
--------------D1FD7E74232804756F25371E
Content-Type: text/plain; charset=us-ascii;
 name="forth.pat.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="forth.pat.txt"

Index: boot/ficl/words.c
===================================================================
RCS file: /home/cvs/clickarray/FreeBSD/sys.releng4/boot/ficl/words.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 words.c
*** boot/ficl/words.c   2001/03/21 00:50:28     1.1.1.1
--- boot/ficl/words.c   2001/06/08 04:15:33
***************
*** 4256,4262 ****
  #endif
      (void)stackPopINT(pVM->pStack); /* don't need count value */
      p = stackPopPtr(pVM->pStack);
!     fd = open(p, O_RDONLY);
      stackPushINT(pVM->pStack, fd);
      return;
  }
--- 4256,4262 ----
  #endif
      (void)stackPopINT(pVM->pStack); /* don't need count value */
      p = stackPopPtr(pVM->pStack);
!     fd = open(p, O_RDWR);
      stackPushINT(pVM->pStack, fd);
      return;
  }
***************
*** 4300,4305 ****
--- 4300,4348 ----
      return;
  }

+ /*          fwrite - write file contents
+  *
+  * fwrite  ( fd buf nbytes  -- nwritten )
+  */
+ static void pfwrite(FICL_VM *pVM)
+ {
+     int     fd, len;
+     char *buf;
+
+ #if FICL_ROBUST > 1
+     vmCheckStack(pVM, 3, 1);
+ #endif
+     len = stackPopINT(pVM->pStack); /* get number of bytes to write */
+     buf = stackPopPtr(pVM->pStack); /* get buffer */
+     fd = stackPopINT(pVM->pStack); /* get fd */
+     if (len > 0 && buf && fd != -1)
+       stackPushINT(pVM->pStack, write(fd, buf, len));
+     else
+       stackPushINT(pVM->pStack, -1);
+     return;
+ }
+
+ /*          flseek - seek to file offset
+  *
+  * flseek  ( fd offset whence  -- whence )
+  */
+ static void pflseek(FICL_VM *pVM)
+ {
+     int     fd, whence, offset;
+
+ #if FICL_ROBUST > 1
+     vmCheckStack(pVM, 3, 1);
+ #endif
+     whence = stackPopINT(pVM->pStack); /* get whence */
+     offset = stackPopINT(pVM->pStack); /* get offset */
+     fd = stackPopINT(pVM->pStack); /* get fd */
+     if (whence >= 0 && whence <= 2 && offset >= 0 && fd != -1)
+       stackPushINT(pVM->pStack, lseek(fd, offset, whence));
+     else
+       stackPushINT(pVM->pStack, -1);
+     return;
+ }
+
  /*          fload - interpret file contents
   *
   * fload  ( fd -- )
***************
*** 4808,4813 ****
--- 4851,4858 ----
      dictAppendWord(dp, "fopen",           pfopen,         FW_DEFAULT);
      dictAppendWord(dp, "fclose",    pfclose,      FW_DEFAULT);
      dictAppendWord(dp, "fread",           pfread,         FW_DEFAULT);
+     dictAppendWord(dp, "fwrite",    pfwrite,      FW_DEFAULT);
+     dictAppendWord(dp, "flseek",    pflseek,      FW_DEFAULT);
      dictAppendWord(dp, "fload",           pfload,         FW_DEFAULT);
      dictAppendWord(dp, "fkey",            fkey,           FW_DEFAULT);
      dictAppendWord(dp, "key",     key,            FW_DEFAULT);

--------------D1FD7E74232804756F25371E--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3BBF5C3E.3F88B4CD>