Package: beef
Version: 0.0.6-2
Severity: wishlist
Tags: patch

There is an extension to Brainfuck (as well as other esoterical
languages)
called EsoAPI (mentioned http://esolangs.org/wiki/EsoAPI, defined
http://kidsquid. 99k .org/programs/esoapi/esoapi.html, example
implemention http://esolangs.org/wiki/User:JayCampbell/weave.rb).

I've attached a patch to add support for this API to the beef source.
I haven't yet done it for the version in experimental (1.0.0) yet.

You can test via the attache esoapi-hello.bf. Before the patch it will
print "EsoAPI required\n", and after the patch will print "Hello
World!\n"

Cheers,

Hugh

-- System Information:
Debian Release: 6.0.6
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_NZ.UTF-8, LC_CTYPE=en_NZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages beef depends on:
ii libc6 2.11.3-4 Embedded GNU C Library: Shared lib

beef recommends no packages.

beef suggests no packages.

-- no debconf information

*** beef-esoapi.patch
commit 9c0ddfd01eeee319544e5861cf9678a554f56f4e
Author: Hugh Davenport <h...@fir.torus.co.nz>
Date:   Sun Dec 9 22:55:39 2012 +1300

    Add EsoAPI

diff --git a/src/beef.h b/src/beef.h
index b3937f1..5bb7309 100644
--- a/src/beef.h
+++ b/src/beef.h
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <unistd.h>
+#include <fcntl.h>

 /* Program name and version */
 #define PROGRAM_NAME "beef"
@@ -42,6 +44,8 @@
 #define ON '1'
 #define OFF '0'

+#define SECTOR_SIZE 512
+
 /* This struct defines an istruction */
 struct instruction {
   char type;
@@ -66,7 +70,7 @@ struct instruction *code;
 /* Various functions */
 struct tape_cell *new_cell ();
 struct instruction *load (FILE *fp, char debug);
-void eval (struct instruction *code, char on_eof);
+void eval (struct instruction *code, char on_eof, int esoapidsk, char lastprinted);
 void tape_dump ();
 void code_dump (struct instruction *code, long indent);

diff --git a/src/eval.c b/src/eval.c
index 38c9038..7aedafa 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -20,9 +20,12 @@

 #include "beef.h"

-void eval (struct instruction *current, char on_eof)
+void eval (struct instruction *current, char on_eof, int esoapidsk, char lastprinted)
 {
-  long i;
+  long i, j;
+  ssize_t size;
+  struct tape_cell *temp;
+  char buffer[SECTOR_SIZE];

   /* Continue as long as the istruction is not the last */
   while (current->type != ']') {
@@ -73,8 +76,53 @@ void eval (struct instruction *current, char on_eof)
       case '.':
         /* Repeat current->quantity times */
         for (i = 0; i < (current->quantity); i++) {
-          /* Print the char which is in the current cell */
-          fputc (tape->content, stdout);
+          if (esoapidsk != -1 && lastprinted == 0) {
+            switch (tape->content) {
+              case 1:
+                lseek (esoapidsk, SECTOR_SIZE, SEEK_CUR);
+                break;
+              case 2:
+                lseek (esoapidsk, -SECTOR_SIZE, SEEK_CUR);
+                break;
+              case 3:
+                size = read (esoapidsk, buffer, SECTOR_SIZE);
+                /* temp points to the current cell */
+                temp = tape;
+                for (j = 0; j < size; j++) {
+                  if (temp->next == NULL) {
+                    /* Create new cell if necessary */
+                    temp->next = new_cell ();
+                    (temp->next)->previous = temp;
+                  }
+                  /* Move forward one cell */
+                  temp = temp->next;
+                  temp->content = buffer[j];
+                }
+                break;
+              case 4:
+                /* temp points to the current cell */
+                temp = tape;
+ for (size = 0; temp->next != NULL && size < SECTOR_SIZE; size++) {
+                  temp = temp->next;
+                  buffer[size] = temp->content;
+                }
+                write (esoapidsk, buffer, size);
+                break;
+              case 5:
+                lseek (esoapidsk, 0, SEEK_SET);
+                break;
+              case 8:
+                tape->content = 0;
+                break;
+              default:
+                /* Print the char which is in the current cell */
+                fputc (tape->content, stdout);
+            }
+          } else {
+            /* Print the char which is in the current cell */
+            fputc (tape->content, stdout);
+          }
+          lastprinted = tape->content;
         }
         break;
       case ',':
@@ -107,7 +155,7 @@ void eval (struct instruction *current, char on_eof)
         /* Repeat as long as the current cell is not empty */
         while (tape->content != '\0') {
           /* Run the loop */
-          eval (current->loop, on_eof);
+          eval (current->loop, on_eof, esoapidsk, lastprinted);
         }
         break;

diff --git a/src/main.c b/src/main.c
index 89d0dcc..f406fa2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,6 +30,9 @@ int main (int argc, char **argv)
   char on_eof = STORE_ZERO;
   /* Debug on/off (default is off)  */
   char debug = OFF;
+  /* EsoAPI on/off (default is off)  */
+  char esoapi = OFF;
+  int esoapidsk = -1;
   int count;
   int num;

@@ -51,6 +54,7 @@ Options:\n\
-e Store an EOF in the current cell when read an EOF from input\n\
   -n          Do nothing when read an EOF from input\n\
-d Enable the debugging command `#' (which dumps the tape)\n\
+  -a          Enable EsoAPI support, reading from file esoapi.dsk\n\
   --version   Show version number and exit successfully\n\
   --help      Show this help and exit succesfully\n", PROGRAM_NAME);
       return 0;
@@ -71,6 +75,19 @@ Copyright (C) 2005-2007 KiyuKo\n", PROGRAM_NAME, VERSION);
         on_eof = DO_NOTHING;
       if (!strcmp (argv[num], "-d"))
         debug = ON;
+      if (!strcmp (argv[num], "-a"))
+        esoapi = ON;
+    }
+
+    /* Try to open esoapi.dsk */
+    if (esoapi == ON) {
+      esoapidsk = open ("esoapi.dsk", O_RDWR|O_CREAT, 0666);
+      if (esoapidsk == -1) {
+        /* Print an error message and disable EsoAPI */
+ fprintf (stderr, "%s: Could not open esoapi.dsk, turning off EsoAPI support\n",
+                         PROGRAM_NAME);
+        esoapi = OFF;
+      }
     }

     /* Try to open the input file */
@@ -93,7 +110,11 @@ Copyright (C) 2005-2007 KiyuKo\n", PROGRAM_NAME, VERSION);
       /* code_dump (code, 0); */

       /* Start executing the code */
-      eval (code, on_eof);
+      eval (code, on_eof, esoapidsk, -1);
+
+      if (esoapidsk != -1) {
+        close (esoapidsk);
+      }
     }
   }
   /* Exit with success */

*** esoapi-hello.bf
+>.++++++++.[
++++++[>++>+++++>++++++++>+++++++>+<<<<<-]>>-.>+++.----.<----.+++++++++++++++.-------.<++++.>>+++.>+++.<-.++++.>++++.<---.>----.-.>-.---.>>]
<[
EsoAPI comapatible
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.<<<<<
-]


--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to