Anonymous avatar Anonymous committed 1925b6e

Import of RUBE version 1.3 revision 2010.0204 sources.

Comments (0)

Files changed (2)

-<html><head>
-    <meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
-    <meta name="Description" content="Cat's Eye Technologies: The RUBE Language">
-    <title>Cat's Eye Technologies: The RUBE Language</title>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+  <title>The RUBE Automaton</title>
 </head>
 <body>
-<center>
-<A HREF="/esoteric/index.html">Esoteric Topics in Computer Programming</A> presents...
-<br><table border=0><tr>
-    <td nowrap align=center valign=center
-    bgcolor="#000000" background="/img/sineblack.gif">&nbsp;<a href="http://www.catseye.mb.ca/index.html"><img
-    align=absmiddle src="/img/3qtrsize.gif"
-    alt="Cat's Eye Technologies" border=0></a>&nbsp;</td>
-    <td nowrap align=center><font size=+3
-    face="century gothic,arial,times new roman" color="#800000">&nbsp;&nbsp;</font><FONT face="arial,monaco" color=#00007f SIZE=+4><B>R</B></FONT>
-<FONT face="arial,monaco" color=#007f00 SIZE=+4><B>U</B></FONT>
-<FONT face="arial,monaco" color=#007f7f SIZE=+4><B>B</B></FONT>
-<FONT face="arial,monaco" color=#7f0000 SIZE=+4><B>E</B></FONT><font></td>
-    </tr></table>
 
-<TABLE WIDTH="100%"><TR><TD WIDTH="50%" ALIGN=LEFT VALIGN=TOP>
+<h1>RUBE</h1>
 
-<p><font face="arial,monaco" size=+2><b>Language</b></font>
+<p><dfn>RUBE</dfn> is a tribute to Rube Goldberg, creator of all those unique
+cartoon contrivances, who showed the world that anything
+can be done in a more complicated fashion than necessary.</p>
 
-<P>RUBE is a tribute to Rube Goldberg, creator of all those unique
-cartoon contrivances, showed the world that anything
-can be done in a more complicated fashion than necessary.
-
-<p>The language itself is a cellular "bully" automaton: certain state
+<p>The RUBE language is a "bully" cellular automaton: certain state
 transitions force other, non-adjacent cells to assume certain state
 transitions.  Although this may sound like an interesting notion, the
 number of interactions climbs quickly as more objects are added, and
 things get much messier than they normally would in a regular
-cellular automaton, like John Conway's Game of Life.
+cellular automaton, like John Conway's Game of Life.</p>
 
 <p>Also unlike a real cellular automaton, RUBE supports rudimentary
-output functionality; input was planned, but has never been implemented.
+output functionality; input was planned, but has not yet been implemented.</p>
 
-<p><a HREF="/esoteric/alpaca/redgreen/index.html">REDGREEN</A> is an
-updated version of the RUBE universe, one which is expressible as
-a proper cellular automaton.
+<p>Because implementing an algorithm in RUBE is a clumsy job
+of co-ordinating concurrently operating sections of the playfield, few
+non-trivial RUBE programs exist.  In particular, it has never to the
+author's knowledge been shown that RUBE is Turing-complete.
+On the other hand, it has never been shown that it's not.</p>
 
-<p><img src="/img/new.gif" alt="[NEW]" width=26 height=16 border=0> John Colagioia has created a more consistent version of
-the RUBE language, <a href="klik.txt">RUBE II:  Das Klickenklacker</a>.
-
-</TD><TD WIDTH="50%" ALIGN=RIGHT VALIGN=BOTTOM>
-
-<p><font face="arial,monaco" size=+2><b>Implementation</b></font>
-
-<p>You can download the <a href="/esoteric/rube/rubev102.zip"><img src="/img/fileicon.gif" border=0 ALT="[D/L]" width=12 height=12>RUBE</a> distribution from
-this web server.
-It contains C source code, documentation, and a precompiled binary for MS-DOS.
-
-<p>You can also download John's <a href="/esoteric/rube/rube_ii.zip"><img src="/img/fileicon.gif" border=0 ALT="[D/L]" width=12 height=12>RUBE II</a>
- distribution from this web server.
-Strangely enough it <i>also</i> contains C source code, documentation, and a precompiled binary for MS-DOS.
-
-<p><font face="arial,monaco" size=+2><b>Documentation</b></font>
-
-<p>See <a href="/esoteric/rube/rube.txt">rube.txt</a> for the original
-description of the interpreter, <a href="/esoteric/rube/klik.txt">klik.txt</a>
-for RUBE II.
-
-<p><font face="arial,monaco" size=+2><b>Programs</b></font>
-
-<p>Attempting to write anything even approaching a single
-"Turing-power" in this language is an utter nightmare.  Partly this
-is because the playfield in the available implementation is
-restricted to 80 columns by 25 rows.  But mostly it's just because
-programming anything non-trivial in RUBE is a clumsy job of
-co-oridnating concurrently operating sections of the playfield.
-
-</TD></TR></TABLE>
+<p>See <a href="rube.txt">rube.txt</a> for the original
+description of the RUBE interpreter.  The only point that perhaps
+needs clarification is that the limitation of the playfield to 80x25
+is a limitation of the implementation, not of the language.
+The language imposes no bounds on the size of a RUBE playfield.</p>
 
 </body></html>
 /*
-
-   rube.c - RUBE language
-   Interpreter/Debugger Implementation
-     v1.02, Jul 1997, Chris Pressey
-
-   (c)1997, 2000 Cat's Eye Technologies.
-   http://www.catseye.mb.ca/
-
-   Usage :
-
-   rube [-d] [-q] [-r input-file] [-w output-file]
-	[-y delay] [-f frame-skip] [-o offset] <rube-source>
-
-      -d: disable debugging output
-      -q: produce no output but program output
-      -r: redirect input from a specified file instead of stdin
-      -w: redirect output to a specified file instead of stdout
-      -y: specify debugging delay in milliseconds (default 0)
-      -f: specify debugging frame skip in frames (default 1)
-
-   Compilation :
-
-   MS-DOS: used Borland C++ v3.1 to compile RUBE.EXE
-
-   Notes for the DOS version:
-     Load ANSI.SYS or compatible ANSI driver before using.
-
-   v1.00: May/Jun 97 original, minimal implementation
-   v1.01: Jun 97 added K gate, AV swinches, + packer, - unpacker
-   v1.02: Jul 97 fixed bug in WM winches, - unpacker, added . and C
-	  doubled height of playfield and improved debugger.
-	  added Ben Olmstead's cursor-turner-offer-thingy.
-	  added -q option.
-
+ * rube.c v1.3, Feb 2010, Chris Pressey
+ * Interpreter/Debugger for the RUBE programming language
+ *
+ * (c)1997-2010 Cat's Eye Technologies.  All rights reserved.
+ *
+ * Freely redistributable unmodified for non-commmercial purposes.
+ * THIS "AS-IS" SOFTWARE COMES WITH NO WARRANTY, EXPRESS OR IMPLIED.
+ *
+ * Usage :
+ *
+ * rube [-d] [-q] [-r input-file] [-w output-file]
+ *      [-y delay] [-f frame-skip] [-o offset] <rube-source>
+ *
+ *  -d: disable debugging output
+ *  -q: produce no output but program output
+ *  -r: redirect input from a specified file instead of stdin
+ *  -w: redirect output to a specified file instead of stdout
+ *  -y: specify debugging delay in milliseconds (default 0)
+ *  -f: specify debugging frame skip in frames (default 1)
+ *
+ * Compilation :
+ *
+ * MS-DOS: tested with Borland C++ v3.1.
+ *         Load ANSI.SYS or compatible ANSI driver before using.
+ * Windows: tested with GCC 3.4.4 under Cygwin.
+ * Linux: tested with GCC 4.2.4 under Ubuntu 8.04.3 LTS.
+ *
+ * History :
+ *
+ * v1.00: May/Jun 97 original, minimal implementation
+ * v1.01: Jun 97 added K gate, AV swinches, + packer, - unpacker
+ * v1.02: Jul 97 fixed bug in WM winches, - unpacker, added . and C
+ *	  doubled height of playfield and improved debugger.
+ *	  added Ben Olmstead's cursor-turner-offer-thingy.
+ *	  added -q option.
+ * v1.3: Feb 110 made compilable in POSIX and strict ANSI C89.
+ *        screen is cleared before drawing initial playfield.
  */
 
 /********************************************************* #INCLUDE'S */
 #include <time.h>
 #if __BORLANDC__
   #include <dos.h>
+#else
+  #define stricmp strcasecmp
+#endif
+#ifdef _POSIX_C_SOURCE
+  #include <sys/time.h>
 #endif
 
 /********************************************************** #DEFINE'S */
 
 /******************************************************* MAIN PROGRAM */
 
-void main (argc, argv)
-     int argc;
-     char **argv;
+int main (int argc, char **argv)
 {
   FILE *f;
   FILE *fi;
     if (!stricmp(argv[i], "-y")) { deldur = atoi(argv[i + 1]); }
     if (!stricmp(argv[i], "-f")) { debskip = atoi(argv[i + 1]); }
   }
-  if (!quiet) printf ("Cat's Eye Technologies RUBE Interpreter v1.02\n");
+  if (!quiet) printf ("Cat's Eye Technologies RUBE Interpreter v1.3\n");
   if ((f = fopen (argv[argc - 1], "r")) != NULL)             /*** Input Phase */
   {
     int x = 0, y = 0;
   setcbrk(1);
 #endif
 
+  if (debug)
+  {
+    printf ("%c[2J", 27);
+  }
   while (!done)          /*** Intepreting Phase */
   {
     if ((debug) && (!(frame++ % debskip) || (!frame)))
       }
     } else
     {
-      // putc('.', stdout);
+      /* putc('.', stdout); */
     }
     fflush (stdout);
     fflush (stdin);
 	  case 20: case 21: case 22: case 23: case 24:
 	  case 25: case 26: case 27: case 28: case 29:
 	  case 30: case 31: case 32:
-	    if (iscrate(curd(0,-1))) nex = curd(0,-1);    // falling in from above
+	    if (iscrate(curd(0,-1))) nex = curd(0,-1);    /* falling in from above */
 	    if (curd(0,-1) == '(') nex = '(';
 	    if (curd(0,-1) == ')') nex = ')';
 
 	    if (curd(0,-1) == ':') nex = curd(0,-2);
 	    if ((curd(0,-1) == ';') && (iscrate(curd(0,-2)))) nex = curd(0,-2);
 	    if ((curd(0,1) == '.') && (iscrate(curd(0,2)))) nex = curd(0,2);
-	    if ((curd(-1,0) == '(') && (curd(1,0) == ')')) // collision
+	    if ((curd(-1,0) == '(') && (curd(1,0) == ')')) /* collision */
 	    {
 	      nex = ' ';
 	    } else
 	      }
 	    }
 	    if (iscrate(curd(-1,0)))
-	    { // shift crates
+	    { /* shift crates */
 	      int bx=-1;
 	      while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1))))
 	      {
 		    printf ("%c[%d;%dH%c[K", 27, 25, 1, 27);
 		    debopos += strlen(s);
 		  }
-		  printf(s);
+		  printf("%s", s);
 		} else
 		{
 		  printf("%d ", (int)d);
 	}
       }
     }
-    // fix nex array
+    /* fix nex array */
     for (x=0; x<=(maxx); x++)
     {
       for (y=0; y<=(maxy); y++)
 	    (curd(0,1)=='F')) nex = ' ';
       }
     }
-#if __BORLANDC__
-    delay (deldur);
-#endif
+    if (deldur > 0)
+      rube_delay (deldur);
     memcpy(pg, pg2, LINEWIDTH * PAGEHEIGHT * sizeof(cell));
   }
   if (fi) fclose (fi);
   exit (0);
 }
 
-int isramp(c)
-  char c;
+int isramp(char c)
 {
   return ((c=='/')||(c=='\\'));
 }
 
-int isblock(c)
-  char c;
+int isblock(char c)
 {
   return ((c=='='));
 }
 
-int issupport(c)
-  char c;
+int issupport(char c)
 {
   return ((c=='=')||iscrate(c)||(c=='(')||(c==')')||(c==';')||
 	  (c=='/')||(c=='\\')||(c==':')||(c=='*')||(c==',')||
 	  (c=='A')||(c=='V')||(c=='~')||(c=='.'));
 }
 
-int iscrate(c)
-  char c;
+int iscrate(char c)
 {
   return ((c=='0')||(c=='1')||(c=='2')||(c=='3')||
 	  (c=='4')||(c=='5')||(c=='6')||(c=='7')||
 	  (c=='c')||(c=='d')||(c=='e')||(c=='f'));
 }
 
-int ctoh(c)
-  char c;
+int ctoh(char c)
 {
   if((c>='0') && (c<='9')) return (c-'0'); else return ((c-'a')+10);
 }
 
-char htoc(i)
-  int i;
+char htoc(int i)
 {
   if((i>=0) && (i<=9)) return ((char)(i+'0')); else return ((char)(i+'a')-10);
 }
+
+int rube_delay(int msec)
+{
+#if __BORLANDC__
+  delay (msec);
+#elsif _POSIX_C_SOURCE
+  struct timespec d;
+
+  d.tv_sec = msec / 1000;
+  msec %= 1000;
+  d.tv_nsec = msec * 1000000;
+  nanosleep(&d, NULL);
+#else
+  sleep(msec / 1000);
+#endif
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.