]> thyrsus.com Git - ctopy.git/commitdiff
We translate do/while now.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 19 Oct 2006 03:13:06 +0000 (03:13 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 19 Oct 2006 03:13:06 +0000 (03:13 +0000)
ctopy
testload.c

diff --git a/ctopy b/ctopy
index 463eb77503dc1a339fab85915b3d7bad32b4d889..7305170451d32ac5d0dabf5faa361e32a94408f1 100755 (executable)
--- a/ctopy
+++ b/ctopy
@@ -678,6 +678,8 @@ post_transformations = (
     (r"else if", r"elif"),
     (r"(?:} )?else\s*{", r"else"),
     (r"(?<!#)else", r"else:"),
+    (r"\bdo\s*{", r"while True:"),
+    (r"}\s*while\s*(\(.*\));", r"if not \1: break      # DO-WHILE TERMINATOR -- INDENTATION IS PROBABLY WRONG"), 
     (r"switch *\((.*)\)(\s*{)?", r"switch \1:"),# Not Python, but less ugly
     # constants
     (r"\btrue\b", r"True"),    # C99
index fbbfc80c2b6f1f5152abfb382d7ac2c3113e3dae..c3cb6144120c539cdb35e74d6002c38584cc6301 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This is a test load for ctopy, the C to Python translator.
  * It is syntactically valid C, parts taken from the source for 
- * Super Star Trek.
+ * Super Star Trek and Galaxis.
  *
  * This boxed comment at the beginning should turn into a series of
  * Python comments with # at the left margin.  Both comment delimiters
@@ -111,16 +111,56 @@ static int randdevice(void)
        10,     /* DDRAY: death ray                      1.0% */
        30,     /* DDSP: deep-space probes               3.0% */
     };
-    // ctopy strips the type away, but isn't yet smart enough 
-    // to remove the following variables that don't have initializers.
-    int sum, i, idx = Rand() * 1000.0; /* weights must sum to 1000 */
+    // $ctopy class coord
+    // Scalar type , one initializer just before semi, trailing comment
+    int sum = 0, i, idx = Rand() * 1000.0;     /* weights must sum to 1000 */
+    // All scalars -- this line should vanish
+    int i, i2, j, ideltax, ideltay, ifindit, iwhichb;
+    // Class instances variables require initialization
+    coord iq, sc, ibq;
+    // Arrays don't get initializers.  This could be handled better.
+    int basetbl[BASEMAX+1];
+    // Scalar, just one, should vanish
+    bool avoid;
 
     // simple C for loops are translated
     for (i = 0; i < NDEVICES; i++) {
        sum += weights[i];
-       if (idx < sum)
+       if (idx < sum) {
+           fprintf(stdout, "Found device %i\n", i); 
            return i;
     }
     return -1; /* we should never get here, but this quiets GCC */
 }
 
+// Test the ability to declare a type is mapped into a class and pass
+// back a reference to it.  Also test the hint parser.
+// $ctopy class event
+
+event *unschedule(int evtype)
+/* remove an event from the schedule */
+{
+    // Test our ability to handle gettexted format strings
+    printf(_("Unscheduling event %d\n"), evtype)
+    game.future[evtype].date = FOREVER;
+    // The & should be stripped
+    return &game.future[evtype];
+}
+
+main(int argc, char *argv)
+{
+    intro();
+    do {
+       initgame();
+       redisplay(TRUE);
+
+       while (boatsfound < LIFEBOATS && !allmarked() && domove())
+           continue;
+
+       redisplay(FALSE);       /* force found count to be updated */
+       prompt("Want to play again [yn]? ");
+    } while
+       (confirm());
+    outro();
+    /*NOTREACHED*/
+}