Bug#695502: beef: Add support for EsoAPI

2013-01-14 Thread Andrea Bolognani
On Sun, Dec 09, 2012 at 11:16:38PM +1300, Hugh Davenport wrote:

Hi! Sorry for the late reply.

> 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).

Didn't know about it. I like the fact that, unlike most specifications,
this one is so tiny one can actually understand it :)

> 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.

I have taken a quick look at your patch and it seems completely
reasonable.

Unfortunately the standalone version of Beef is now considered legacy,
and no further development is supposed to happen there: all new features
have to be added to Cattle, where the Brainfuck runtime used by Beef is
actually implemented.

> 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"

Hello World aside, can you point out an actual use for this feature? I'm
having a hard time coming up with one myself ;)

Cheers.

-- 
Andrea Bolognani 
Resistance is futile, you will be garbage collected.


signature.asc
Description: Digital signature


Bug#695502: beef: Add support for EsoAPI

2012-12-09 Thread Hugh Davenport

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 9c0ddfd01319544e5861cf9678a554f56f4e
Author: Hugh Davenport 
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 
 #include 
 #include 
+#include 
+#include 

 /* 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);