aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilutin Jovanović <jovanovic.milutin@gmail.com>2012-06-18 13:27:32 -0400
committerMilutin Jovanović <jovanovic.milutin@gmail.com>2012-06-18 15:11:39 -0400
commit42c1b6ba380d9d1ab85f0cc21db07e71667cc682 (patch)
treee5eb7e317ad696d0975e463771c25c8a3c01260c
parentb0ebcfa7bae4a8743698107a82fffc598818ccc5 (diff)
downloadtinycc-42c1b6ba380d9d1ab85f0cc21db07e71667cc682.tar.gz
tinycc-42c1b6ba380d9d1ab85f0cc21db07e71667cc682.tar.bz2
tests: Added numerous tests.
The tests are taken almost verbatim from the open source project PicoC. It can be found at https://code.google.com/p/picoc/. The tests range from very simple/trivial ones to more complicated. My view is that the more tests the better. Without tests like this I was very reluctant to make any changes to tcc for the fear of breaking things. The tests pass on Win32, OSX, Linux x86 and x86_64. One or two tests fail on each platform due to differences in the runtime library.
-rw-r--r--Makefile2
-rw-r--r--tests2/00_assignment.c18
-rw-r--r--tests2/00_assignment.expect3
-rw-r--r--tests2/01_comment.c14
-rw-r--r--tests2/01_comment.expect5
-rw-r--r--tests2/02_printf.c18
-rw-r--r--tests2/02_printf.expect15
-rw-r--r--tests2/03_struct.c31
-rw-r--r--tests2/03_struct.expect6
-rw-r--r--tests2/04_for.c15
-rw-r--r--tests2/04_for.expect10
-rw-r--r--tests2/05_array.c21
-rw-r--r--tests2/05_array.expect10
-rw-r--r--tests2/06_case.c29
-rw-r--r--tests2/06_case.expect8
-rw-r--r--tests2/07_function.c30
-rw-r--r--tests2/07_function.expect4
-rw-r--r--tests2/08_while.c24
-rw-r--r--tests2/08_while.expect11
-rw-r--r--tests2/09_do_while.c24
-rw-r--r--tests2/09_do_while.expect11
-rw-r--r--tests2/10_pointer.c40
-rw-r--r--tests2/10_pointer.expect8
-rw-r--r--tests2/11_precedence.c40
-rw-r--r--tests2/11_precedence.expect15
-rw-r--r--tests2/12_hashdefine.c14
-rw-r--r--tests2/12_hashdefine.expect2
-rw-r--r--tests2/13_integer_literals.c20
-rw-r--r--tests2/13_integer_literals.expect5
-rw-r--r--tests2/14_if.c21
-rw-r--r--tests2/14_if.expect2
-rw-r--r--tests2/15_recursion.c21
-rw-r--r--tests2/15_recursion.expect10
-rw-r--r--tests2/16_nesting.c21
-rw-r--r--tests2/16_nesting.expect18
-rw-r--r--tests2/17_enum.c29
-rw-r--r--tests2/17_enum.expect3
-rw-r--r--tests2/18_include.c12
-rw-r--r--tests2/18_include.expect3
-rw-r--r--tests2/18_include.h1
-rw-r--r--tests2/19_pointer_arithmetic.c28
-rw-r--r--tests2/19_pointer_arithmetic.expect3
-rw-r--r--tests2/20_pointer_comparison.c24
-rw-r--r--tests2/20_pointer_comparison.expect6
-rw-r--r--tests2/21_char_array.c33
-rw-r--r--tests2/21_char_array.expect7
-rw-r--r--tests2/22_floating_point.c50
-rw-r--r--tests2/22_floating_point.expect16
-rw-r--r--tests2/23_type_coercion.c54
-rw-r--r--tests2/23_type_coercion.expect12
-rw-r--r--tests2/24_math_library.c28
-rw-r--r--tests2/24_math_library.expect18
-rw-r--r--tests2/25_quicksort.c83
-rw-r--r--tests2/25_quicksort.expect2
-rw-r--r--tests2/26_character_constants.c17
-rw-r--r--tests2/26_character_constants.expect8
-rw-r--r--tests2/27_sizeof.c16
-rw-r--r--tests2/27_sizeof.expect3
-rw-r--r--tests2/28_strings.c46
-rw-r--r--tests2/28_strings.expect19
-rw-r--r--tests2/29_array_address.c13
-rw-r--r--tests2/29_array_address.expect1
-rw-r--r--tests2/30_hanoi.c122
-rw-r--r--tests2/30_hanoi.expect71
-rw-r--r--tests2/31_args.c14
-rw-r--r--tests2/31_args.expect7
-rw-r--r--tests2/32_led.c266
-rw-r--r--tests2/32_led.expect4
-rw-r--r--tests2/33_ternary_op.c15
-rw-r--r--tests2/33_ternary_op.expect10
-rw-r--r--tests2/34_array_assignment.c23
-rw-r--r--tests2/34_array_assignment.expect2
-rw-r--r--tests2/35_sizeof.c14
-rw-r--r--tests2/35_sizeof.expect2
-rw-r--r--tests2/36_array_initialisers.c21
-rw-r--r--tests2/36_array_initialisers.expect20
-rw-r--r--tests2/37_sprintf.c17
-rw-r--r--tests2/37_sprintf.expect20
-rw-r--r--tests2/38_multiple_array_index.c32
-rw-r--r--tests2/38_multiple_array_index.expect4
-rw-r--r--tests2/39_typedef.c31
-rw-r--r--tests2/39_typedef.expect3
-rw-r--r--tests2/40_stdio.c52
-rw-r--r--tests2/40_stdio.expect27
-rw-r--r--tests2/41_hashif.c85
-rw-r--r--tests2/41_hashif.expect6
-rw-r--r--tests2/42_function_pointer.c18
-rw-r--r--tests2/42_function_pointer.expect2
-rw-r--r--tests2/43_void_param.c15
-rw-r--r--tests2/43_void_param.expect1
-rw-r--r--tests2/44_scoped_declarations.c17
-rw-r--r--tests2/44_scoped_declarations.expect1
-rw-r--r--tests2/45_empty_for.c18
-rw-r--r--tests2/45_empty_for.expect10
-rw-r--r--tests2/46_grep.c564
-rw-r--r--tests2/47_switch_return.c24
-rw-r--r--tests2/47_switch_return.expect4
-rw-r--r--tests2/48_nested_break.c26
-rw-r--r--tests2/48_nested_break.expect1
-rw-r--r--tests2/49_bracket_evaluation.c23
-rw-r--r--tests2/49_bracket_evaluation.expect1
-rw-r--r--tests2/50_logical_second_arg.c29
-rw-r--r--tests2/50_logical_second_arg.expect20
-rw-r--r--tests2/51_static.c30
-rw-r--r--tests2/51_static.expect8
-rw-r--r--tests2/52_unnamed_enum.c27
-rw-r--r--tests2/52_unnamed_enum.expect9
-rw-r--r--tests2/54_goto.c56
-rw-r--r--tests2/54_goto.expect8
-rw-r--r--tests2/LICENSE37
-rw-r--r--tests2/Makefile90
111 files changed, 2988 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index ba94577..cdaad28 100644
--- a/Makefile
+++ b/Makefile
@@ -358,10 +358,12 @@ tar:
export LIBTCC1
%est:
+ $(MAKE) -C tests2 $@
$(MAKE) -C tests $@
clean:
rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
+ $(MAKE) -C tests2 $@
$(MAKE) -C tests $@
ifneq ($(LIBTCC1),)
$(MAKE) -C lib $@
diff --git a/tests2/00_assignment.c b/tests2/00_assignment.c
new file mode 100644
index 0000000..c96109f
--- /dev/null
+++ b/tests2/00_assignment.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ a = 42;
+ printf("%d\n", a);
+
+ int b = 64;
+ printf("%d\n", b);
+
+ int c = 12, d = 34;
+ printf("%d, %d\n", c, d);
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/00_assignment.expect b/tests2/00_assignment.expect
new file mode 100644
index 0000000..d4407f3
--- /dev/null
+++ b/tests2/00_assignment.expect
@@ -0,0 +1,3 @@
+42
+64
+12, 34
diff --git a/tests2/01_comment.c b/tests2/01_comment.c
new file mode 100644
index 0000000..a2e6bc6
--- /dev/null
+++ b/tests2/01_comment.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("Hello\n");
+ printf("Hello\n"); /* this is a comment */ printf("Hello\n");
+ printf("Hello\n");
+ // this is also a comment sayhello();
+ printf("Hello\n");
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/01_comment.expect b/tests2/01_comment.expect
new file mode 100644
index 0000000..b1387ad
--- /dev/null
+++ b/tests2/01_comment.expect
@@ -0,0 +1,5 @@
+Hello
+Hello
+Hello
+Hello
+Hello
diff --git a/tests2/02_printf.c b/tests2/02_printf.c
new file mode 100644
index 0000000..4c34dd8
--- /dev/null
+++ b/tests2/02_printf.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("Hello world\n");
+
+ int Count;
+ for (Count = -5; Count <= 5; Count++)
+ printf("Count = %d\n", Count);
+
+ printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there");
+ printf("Character 'A' is '%c'\n", 65);
+ printf("Character 'a' is '%c'\n", 'a');
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/02_printf.expect b/tests2/02_printf.expect
new file mode 100644
index 0000000..f67a0f6
--- /dev/null
+++ b/tests2/02_printf.expect
@@ -0,0 +1,15 @@
+Hello world
+Count = -5
+Count = -4
+Count = -3
+Count = -2
+Count = -1
+Count = 0
+Count = 1
+Count = 2
+Count = 3
+Count = 4
+Count = 5
+String 'hello', 'there' is 'hello', 'there'
+Character 'A' is 'A'
+Character 'a' is 'a'
diff --git a/tests2/03_struct.c b/tests2/03_struct.c
new file mode 100644
index 0000000..df0d3e7
--- /dev/null
+++ b/tests2/03_struct.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+
+struct fred
+{
+ int boris;
+ int natasha;
+};
+
+void main()
+{
+ struct fred bloggs;
+
+ bloggs.boris = 12;
+ bloggs.natasha = 34;
+
+ printf("%d\n", bloggs.boris);
+ printf("%d\n", bloggs.natasha);
+
+ struct fred jones[2];
+ jones[0].boris = 12;
+ jones[0].natasha = 34;
+ jones[1].boris = 56;
+ jones[1].natasha = 78;
+
+ printf("%d\n", jones[0].boris);
+ printf("%d\n", jones[0].natasha);
+ printf("%d\n", jones[1].boris);
+ printf("%d\n", jones[1].natasha);
+
+ return 0;
+}
diff --git a/tests2/03_struct.expect b/tests2/03_struct.expect
new file mode 100644
index 0000000..ecbf589
--- /dev/null
+++ b/tests2/03_struct.expect
@@ -0,0 +1,6 @@
+12
+34
+12
+34
+56
+78
diff --git a/tests2/04_for.c b/tests2/04_for.c
new file mode 100644
index 0000000..312fed8
--- /dev/null
+++ b/tests2/04_for.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main()
+{
+ int Count;
+
+ for (Count = 1; Count <= 10; Count++)
+ {
+ printf("%d\n", Count);
+ }
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/04_for.expect b/tests2/04_for.expect
new file mode 100644
index 0000000..f00c965
--- /dev/null
+++ b/tests2/04_for.expect
@@ -0,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
diff --git a/tests2/05_array.c b/tests2/05_array.c
new file mode 100644
index 0000000..c218f31
--- /dev/null
+++ b/tests2/05_array.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int main()
+{
+ int Count;
+ int Array[10];
+
+ for (Count = 1; Count <= 10; Count++)
+ {
+ Array[Count-1] = Count * Count;
+ }
+
+ for (Count = 0; Count < 10; Count++)
+ {
+ printf("%d\n", Array[Count]);
+ }
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/05_array.expect b/tests2/05_array.expect
new file mode 100644
index 0000000..bc7257c
--- /dev/null
+++ b/tests2/05_array.expect
@@ -0,0 +1,10 @@
+1
+4
+9
+16
+25
+36
+49
+64
+81
+100
diff --git a/tests2/06_case.c b/tests2/06_case.c
new file mode 100644
index 0000000..c0191e2
--- /dev/null
+++ b/tests2/06_case.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+int main()
+{
+ int Count;
+
+ for (Count = 0; Count < 4; Count++)
+ {
+ printf("%d\n", Count);
+ switch (Count)
+ {
+ case 1:
+ printf("%d\n", 1);
+ break;
+
+ case 2:
+ printf("%d\n", 2);
+ break;
+
+ default:
+ printf("%d\n", 0);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/06_case.expect b/tests2/06_case.expect
new file mode 100644
index 0000000..fab2c20
--- /dev/null
+++ b/tests2/06_case.expect
@@ -0,0 +1,8 @@
+0
+0
+1
+1
+2
+2
+3
+0
diff --git a/tests2/07_function.c b/tests2/07_function.c
new file mode 100644
index 0000000..0477ce1
--- /dev/null
+++ b/tests2/07_function.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+int myfunc(int x)
+{
+ return x * x;
+}
+
+void vfunc(int a)
+{
+ printf("a=%d\n", a);
+}
+
+void qfunc()
+{
+ printf("qfunc()\n");
+}
+
+int main()
+{
+ printf("%d\n", myfunc(3));
+ printf("%d\n", myfunc(4));
+
+ vfunc(1234);
+
+ qfunc();
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/07_function.expect b/tests2/07_function.expect
new file mode 100644
index 0000000..8ffb0a7
--- /dev/null
+++ b/tests2/07_function.expect
@@ -0,0 +1,4 @@
+9
+16
+a=1234
+qfunc()
diff --git a/tests2/08_while.c b/tests2/08_while.c
new file mode 100644
index 0000000..602ffc7
--- /dev/null
+++ b/tests2/08_while.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ int p;
+ int t;
+
+ a = 1;
+ p = 0;
+ t = 0;
+
+ while (a < 100)
+ {
+ printf("%d\n", a);
+ t = a;
+ a = t + p;
+ p = t;
+ }
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/08_while.expect b/tests2/08_while.expect
new file mode 100644
index 0000000..702d4c0
--- /dev/null
+++ b/tests2/08_while.expect
@@ -0,0 +1,11 @@
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
diff --git a/tests2/09_do_while.c b/tests2/09_do_while.c
new file mode 100644
index 0000000..1d3315d
--- /dev/null
+++ b/tests2/09_do_while.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ int p;
+ int t;
+
+ a = 1;
+ p = 0;
+ t = 0;
+
+ do
+ {
+ printf("%d\n", a);
+ t = a;
+ a = t + p;
+ p = t;
+ } while (a < 100);
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/09_do_while.expect b/tests2/09_do_while.expect
new file mode 100644
index 0000000..702d4c0
--- /dev/null
+++ b/tests2/09_do_while.expect
@@ -0,0 +1,11 @@
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
diff --git a/tests2/10_pointer.c b/tests2/10_pointer.c
new file mode 100644
index 0000000..0177f4d
--- /dev/null
+++ b/tests2/10_pointer.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+
+struct ziggy
+{
+ int a;
+ int b;
+ int c;
+} bolshevic;
+
+int main()
+{
+ int a;
+ int *b;
+ int c;
+
+ a = 42;
+ b = &a;
+ printf("a = %d\n", *b);
+
+ bolshevic.a = 12;
+ bolshevic.b = 34;
+ bolshevic.c = 56;
+
+ printf("bolshevic.a = %d\n", bolshevic.a);
+ printf("bolshevic.b = %d\n", bolshevic.b);
+ printf("bolshevic.c = %d\n", bolshevic.c);
+
+ struct ziggy *tsar = &bolshevic;
+
+ printf("tsar->a = %d\n", tsar->a);
+ printf("tsar->b = %d\n", tsar->b);
+ printf("tsar->c = %d\n", tsar->c);
+
+ b = &(bolshevic.b);
+ printf("bolshevic.b = %d\n", *b);
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/10_pointer.expect b/tests2/10_pointer.expect
new file mode 100644
index 0000000..1e3c473
--- /dev/null
+++ b/tests2/10_pointer.expect
@@ -0,0 +1,8 @@
+a = 42
+bolshevic.a = 12
+bolshevic.b = 34
+bolshevic.c = 56
+tsar->a = 12
+tsar->b = 34
+tsar->c = 56
+bolshevic.b = 34
diff --git a/tests2/11_precedence.c b/tests2/11_precedence.c
new file mode 100644
index 0000000..db2049d
--- /dev/null
+++ b/tests2/11_precedence.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ int b;
+ int c;
+ int d;
+ int e;
+ int f;
+ int x;
+ int y;
+
+ a = 12;
+ b = 34;
+ c = 56;
+ d = 78;
+ e = 0;
+ f = 1;
+
+ printf("%d\n", c + d);
+ printf("%d\n", (y = c + d));
+ printf("%d\n", e || e && f);
+ printf("%d\n", e || f && f);
+ printf("%d\n", e && e || f);
+ printf("%d\n", e && f || f);
+ printf("%d\n", a && f | f);
+ printf("%d\n", a | b ^ c & d);
+ printf("%d, %d\n", a == a, a == b);
+ printf("%d, %d\n", a != a, a != b);
+ printf("%d\n", a != b && c != d);
+ printf("%d\n", a + b * c / f);
+ printf("%d\n", a + b * c / f);
+ printf("%d\n", (4 << 4));
+ printf("%d\n", (64 >> 4));
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/11_precedence.expect b/tests2/11_precedence.expect
new file mode 100644
index 0000000..b692396
--- /dev/null
+++ b/tests2/11_precedence.expect
@@ -0,0 +1,15 @@
+134
+134
+0
+1
+1
+1
+1
+46
+1, 0
+0, 1
+1
+1916
+1916
+64
+4
diff --git a/tests2/12_hashdefine.c b/tests2/12_hashdefine.c
new file mode 100644
index 0000000..5c521e0
--- /dev/null
+++ b/tests2/12_hashdefine.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+#define FRED 12
+#define BLOGGS(x) (12*(x))
+
+int main()
+{
+ printf("%d\n", FRED);
+ printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3));
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/12_hashdefine.expect b/tests2/12_hashdefine.expect
new file mode 100644
index 0000000..99f2ed5
--- /dev/null
+++ b/tests2/12_hashdefine.expect
@@ -0,0 +1,2 @@
+12
+12, 24, 36
diff --git a/tests2/13_integer_literals.c b/tests2/13_integer_literals.c
new file mode 100644
index 0000000..7cee98b
--- /dev/null
+++ b/tests2/13_integer_literals.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int main()
+{
+ int a = 24680;
+ int b = 01234567;
+ int c = 0x2468ac;
+ int d = 0x2468AC;
+ int e = 0b010101010101;
+
+ printf("%d\n", a);
+ printf("%d\n", b);
+ printf("%d\n", c);
+ printf("%d\n", d);
+ printf("%d\n", e);
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/13_integer_literals.expect b/tests2/13_integer_literals.expect
new file mode 100644
index 0000000..f5aca06
--- /dev/null
+++ b/tests2/13_integer_literals.expect
@@ -0,0 +1,5 @@
+24680
+342391
+2386092
+2386092
+1365
diff --git a/tests2/14_if.c b/tests2/14_if.c
new file mode 100644
index 0000000..2bd2550
--- /dev/null
+++ b/tests2/14_if.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int main()
+{
+ int a = 1;
+
+ if (a)
+ printf("a is true\n");
+ else
+ printf("a is false\n");
+
+ int b = 0;
+ if (b)
+ printf("b is true\n");
+ else
+ printf("b is false\n");
+
+ return 0;
+}
+
+// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
diff --git a/tests2/14_if.expect b/tests2/14_if.expect
new file mode 100644
index 0000000..c32c415
--- /dev/null
+++ b/tests2/14_if.expect
@@ -0,0 +1,2 @@
+a is true
+b is false
diff --git a/tests2/15_recursion.c b/tests2/15_recursion.c
new file mode 100644
index 0000000..f79a00d
--- /dev/null
+++ b/tests2/15_recursion.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int factorial(int i)
+{
+ if (i < 2)
+ return i;
+ else
+ return i * factorial(i - 1);
+}
+
+int main()
+{
+ int Count;
+
+ for (Count = 1; Count <= 10; Count++)
+ printf("%d\n", factorial(Count));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/15_recursion.expect b/tests2/15_recursion.expect
new file mode 100644
index 0000000..db47b28
--- /dev/null
+++ b/tests2/15_recursion.expect
@@ -0,0 +1,10 @@
+1
+2
+6
+24
+120
+720
+5040
+40320
+362880
+3628800
diff --git a/tests2/16_nesting.c b/tests2/16_nesting.c
new file mode 100644
index 0000000..2b72cc0
--- /dev/null
+++ b/tests2/16_nesting.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int main()
+{
+ int x, y, z;
+
+ for (x = 0; x < 2; x++)
+ {
+ for (y = 0; y < 3; y++)
+ {
+ for (z = 0; z < 3; z++)
+ {
+ printf("%d %d %d\n", x, y, z);
+ }
+ }
+ }
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/16_nesting.expect b/tests2/16_nesting.expect
new file mode 100644
index 0000000..625ee13
--- /dev/null
+++ b/tests2/16_nesting.expect
@@ -0,0 +1,18 @@
+0 0 0
+0 0 1
+0 0 2
+0 1 0
+0 1 1
+0 1 2
+0 2 0
+0 2 1
+0 2 2
+1 0 0
+1 0 1
+1 0 2
+1 1 0
+1 1 1
+1 1 2
+1 2 0
+1 2 1
+1 2 2
diff --git a/tests2/17_enum.c b/tests2/17_enum.c
new file mode 100644
index 0000000..0853c42
--- /dev/null
+++ b/tests2/17_enum.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+enum fred
+{
+ a,
+ b,
+ c,
+ d,
+ e = 54,
+ f = 73,
+ g,
+ h
+};
+
+int main()
+{
+ enum fred frod;
+
+ printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h);
+ /* printf("%d\n", frod); */
+ frod = 12;
+ printf("%d\n", frod);
+ frod = e;
+ printf("%d\n", frod);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/17_enum.expect b/tests2/17_enum.expect
new file mode 100644
index 0000000..bef4be6
--- /dev/null
+++ b/tests2/17_enum.expect
@@ -0,0 +1,3 @@
+0 1 2 3 54 73 74 75
+12
+54
diff --git a/tests2/18_include.c b/tests2/18_include.c
new file mode 100644
index 0000000..dbae3aa
--- /dev/null
+++ b/tests2/18_include.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("including\n");
+#include "18_include.h"
+ printf("done\n");
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/18_include.expect b/tests2/18_include.expect
new file mode 100644
index 0000000..87729df
--- /dev/null
+++ b/tests2/18_include.expect
@@ -0,0 +1,3 @@
+including
+included
+done
diff --git a/tests2/18_include.h b/tests2/18_include.h
new file mode 100644
index 0000000..01f894d
--- /dev/null
+++ b/tests2/18_include.h
@@ -0,0 +1 @@
+printf("included\n");
diff --git a/tests2/19_pointer_arithmetic.c b/tests2/19_pointer_arithmetic.c
new file mode 100644
index 0000000..aff65e5
--- /dev/null
+++ b/tests2/19_pointer_arithmetic.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ int *b;
+ int *c;
+
+ a = 42;
+ b = &a;
+ c = NULL;
+
+ printf("%d\n", *b);
+
+ if (b == NULL)
+ printf("b is NULL\n");
+ else
+ printf("b is not NULL\n");
+
+ if (c == NULL)
+ printf("c is NULL\n");
+ else
+ printf("c is not NULL\n");
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/19_pointer_arithmetic.expect b/tests2/19_pointer_arithmetic.expect
new file mode 100644
index 0000000..0cf781b
--- /dev/null
+++ b/tests2/19_pointer_arithmetic.expect
@@ -0,0 +1,3 @@
+42
+b is not NULL
+c is NULL
diff --git a/tests2/20_pointer_comparison.c b/tests2/20_pointer_comparison.c
new file mode 100644
index 0000000..825f778
--- /dev/null
+++ b/tests2/20_pointer_comparison.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ int b;
+ int *d;
+ int *e;
+ d = &a;
+ e = &b;
+ a = 12;
+ b = 34;
+ printf("%d\n", *d);
+ printf("%d\n", *e);
+ printf("%d\n", d == e);
+ printf("%d\n", d != e);
+ d = e;
+ printf("%d\n", d == e);
+ printf("%d\n", d != e);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/20_pointer_comparison.expect b/tests2/20_pointer_comparison.expect
new file mode 100644
index 0000000..5d1e5f5
--- /dev/null
+++ b/tests2/20_pointer_comparison.expect
@@ -0,0 +1,6 @@
+12
+34
+0
+1
+1
+0
diff --git a/tests2/21_char_array.c b/tests2/21_char_array.c
new file mode 100644
index 0000000..f22f527
--- /dev/null
+++ b/tests2/21_char_array.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+
+int main()
+{
+ int x = 'a';
+ char y = x;
+
+ char *a = "hello";
+
+ printf("%s\n", a);
+
+ int c;
+ c = *a;
+
+ char *b;
+ for (b = a; *b != 0; b++)
+ printf("%c: %d\n", *b, *b);
+
+ char destarray[10];
+ char *dest = &destarray[0];
+ char *src = a;
+
+ while (*src != 0)
+ *dest++ = *src++;
+
+ *dest = 0;
+
+ printf("copied string is %s\n", destarray);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/21_char_array.expect b/tests2/21_char_array.expect
new file mode 100644
index 0000000..dbc6068
--- /dev/null
+++ b/tests2/21_char_array.expect
@@ -0,0 +1,7 @@
+hello
+h: 104
+e: 101
+l: 108
+l: 108
+o: 111
+copied string is hello
diff --git a/tests2/22_floating_point.c b/tests2/22_floating_point.c
new file mode 100644
index 0000000..e3491f5
--- /dev/null
+++ b/tests2/22_floating_point.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <math.h>
+
+int main()
+{
+ // variables
+ float a = 12.34 + 56.78;
+ printf("%f\n", a);
+
+ // infix operators
+ printf("%f\n", 12.34 + 56.78);
+ printf("%f\n", 12.34 - 56.78);
+ printf("%f\n", 12.34 * 56.78);
+ printf("%f\n", 12.34 / 56.78);
+
+ // comparison operators
+ printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78);
+ printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34);
+ printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34);
+
+ // assignment operators
+ a = 12.34;
+ a += 56.78;
+ printf("%f\n", a);
+
+ a = 12.34;
+ a -= 56.78;
+ printf("%f\n", a);
+
+ a = 12.34;
+ a *= 56.78;
+ printf("%f\n", a);
+
+ a = 12.34;
+ a /= 56.78;
+ printf("%f\n", a);
+
+ // prefix operators
+ printf("%f\n", +12.34);
+ printf("%f\n", -12.34);
+
+ // type coercion
+ a = 2;
+ printf("%f\n", a);
+ printf("%f\n", sin(2));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/22_floating_point.expect b/tests2/22_floating_point.expect
new file mode 100644
index 0000000..75ea3a7
--- /dev/null
+++ b/tests2/22_floating_point.expect
@@ -0,0 +1,16 @@
+69.120003
+69.120000
+-44.440000
+700.665200
+0.217330
+1 1 0 0 0 1
+0 1 1 1 0 0
+0 0 0 1 1 1
+69.120003
+-44.439999
+700.665222
+0.217330
+12.340000
+-12.340000
+2.000000
+0.909297
diff --git a/tests2/23_type_coercion.c b/tests2/23_type_coercion.c
new file mode 100644
index 0000000..1fcc335
--- /dev/null
+++ b/tests2/23_type_coercion.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+
+void charfunc(char a)
+{
+ printf("char: %c\n", a);
+}
+
+void intfunc(int a)
+{
+ printf("int: %d\n", a);
+}
+
+void floatfunc(float a)
+{
+ printf("float: %f\n", a);
+}
+
+int main()
+{
+ charfunc('a');
+ charfunc(98);
+ charfunc(99.0);
+
+ intfunc('a');
+ intfunc(98);
+ intfunc(99.0);
+
+ floatfunc('a');
+ floatfunc(98);
+ floatfunc(99.0);
+
+ /* printf("%c %d %f\n", 'a', 'b', 'c'); */
+ /* printf("%c %d %f\n", 97, 98, 99); */
+ /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */
+
+ char b = 97;
+ char c = 97.0;
+
+ printf("%d %d\n", b, c);
+
+ int d = 'a';
+ int e = 97.0;
+
+ printf("%d %d\n", d, e);
+
+ float f = 'a';
+ float g = 97;
+
+ printf("%f %f\n", f, g);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/23_type_coercion.expect b/tests2/23_type_coercion.expect
new file mode 100644
index 0000000..d9076f0
--- /dev/null
+++ b/tests2/23_type_coercion.expect
@@ -0,0 +1,12 @@
+char: a
+char: b
+char: c
+int: 97
+int: 98
+int: 99
+float: 97.000000
+float: 98.000000
+float: 99.000000
+97 97
+97 97
+97.000000 97.000000
diff --git a/tests2/24_math_library.c b/tests2/24_math_library.c
new file mode 100644
index 0000000..4cc3d9e
--- /dev/null
+++ b/tests2/24_math_library.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <math.h>
+
+int main()
+{
+ printf("%f\n", sin(0.12));
+ printf("%f\n", cos(0.12));
+ printf("%f\n", tan(0.12));
+ printf("%f\n", asin(0.12));
+ printf("%f\n", acos(0.12));
+ printf("%f\n", atan(0.12));
+ printf("%f\n", sinh(0.12));
+ printf("%f\n", cosh(0.12));
+ printf("%f\n", tanh(0.12));
+ printf("%f\n", exp(0.12));
+ printf("%f\n", fabs(-0.12));
+ printf("%f\n", log(0.12));
+ printf("%f\n", log10(0.12));
+ printf("%f\n", pow(0.12, 0.12));
+ printf("%f\n", sqrt(0.12));
+ printf("%f\n", round(12.34));
+ printf("%f\n", ceil(12.34));
+ printf("%f\n", floor(12.34));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/24_math_library.expect b/tests2/24_math_library.expect
new file mode 100644
index 0000000..99f7299
--- /dev/null
+++ b/tests2/24_math_library.expect
@@ -0,0 +1,18 @@
+0.119712
+0.992809
+0.120579
+0.120290
+1.450506
+0.119429
+0.120288
+1.007209
+0.119427
+1.127497
+0.120000
+-2.120264
+-0.920819
+0.775357
+0.346410
+12.000000
+13.000000
+12.000000
diff --git a/tests2/25_quicksort.c b/tests2/25_quicksort.c
new file mode 100644
index 0000000..5cc08bd
--- /dev/null
+++ b/tests2/25_quicksort.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+
+int array[16];
+
+//Swap integer values by array indexes
+void swap(int a, int b)
+{
+ int tmp = array[a];
+ array[a] = array[b];
+ array[b] = tmp;
+}
+
+//Partition the array into two halves and return the
+//index about which the array is partitioned
+int partition(int left, int right)
+{
+ int pivotIndex = left;
+ int pivotValue = array[pivotIndex];
+ int index = left;
+ int i;
+
+ swap(pivotIndex, right);
+ for(i = left; i < right; i++)
+ {
+ if(array[i] < pivotValue)
+ {
+ swap(i, index);
+ index += 1;
+ }
+ }
+ swap(right, index);
+
+ return index;
+}
+
+//Quicksort the array
+void quicksort(int left, int right)
+{
+ if(left >= right)
+ return;
+
+ int index = partition(left, right);
+ quicksort(left, index - 1);
+ quicksort(index + 1, right);
+}
+
+int main()
+{
+ int i;
+
+ array[0] = 62;
+ array[1] = 83;
+ array[2] = 4;
+ array[3] = 89;
+ array[4] = 36;
+ array[5] = 21;
+ array[6] = 74;
+ array[7] = 37;
+ array[8] = 65;
+ array[9] = 33;
+ array[10] = 96;
+ array[11] = 38;
+ array[12] = 53;
+ array[13] = 16;
+ array[14] = 74;
+ array[15] = 55;
+
+ for (i = 0; i < 16; i++)
+ printf("%d ", array[i]);
+
+ printf("\n");
+
+ quicksort(0, 15);
+
+ for (i = 0; i < 16; i++)
+ printf("%d ", array[i]);
+
+ printf("\n");
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/25_quicksort.expect b/tests2/25_quicksort.expect
new file mode 100644
index 0000000..2d39cd3
--- /dev/null
+++ b/tests2/25_quicksort.expect
@@ -0,0 +1,2 @@
+62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55
+4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96
diff --git a/tests2/26_character_constants.c b/tests2/26_character_constants.c
new file mode 100644
index 0000000..95c4423
--- /dev/null
+++ b/tests2/26_character_constants.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("%d\n", '\1');
+ printf("%d\n", '\10');
+ printf("%d\n", '\100');
+ printf("%d\n", '\x01');
+ printf("%d\n", '\x0e');
+ printf("%d\n", '\x10');
+ printf("%d\n", '\x40');
+ printf("test \x40\n");
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/26_character_constants.expect b/tests2/26_character_constants.expect
new file mode 100644
index 0000000..8f8bfa4
--- /dev/null
+++ b/tests2/26_character_constants.expect
@@ -0,0 +1,8 @@
+1
+8
+64
+1
+14
+16
+64
+test @
diff --git a/tests2/27_sizeof.c b/tests2/27_sizeof.c
new file mode 100644
index 0000000..d1694b6
--- /dev/null
+++ b/tests2/27_sizeof.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int main()
+{
+ char a;
+ int b;
+ double c;
+
+ printf("%d\n", sizeof(a));
+ printf("%d\n", sizeof(b));
+ printf("%d\n", sizeof(c));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/27_sizeof.expect b/tests2/27_sizeof.expect
new file mode 100644
index 0000000..7329e00
--- /dev/null
+++ b/tests2/27_sizeof.expect
@@ -0,0 +1,3 @@
+1
+4
+8
diff --git a/tests2/28_strings.c b/tests2/28_strings.c
new file mode 100644
index 0000000..115fe09
--- /dev/null
+++ b/tests2/28_strings.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+int main()
+{
+ char a[10];
+
+ strcpy(a, "hello");
+ printf("%s\n", a);
+
+ strncpy(a, "gosh", 2);
+ printf("%s\n", a);
+
+ printf("%d\n", strcmp(a, "apple") > 0);
+ printf("%d\n", strcmp(a, "goere") > 0);
+ printf("%d\n", strcmp(a, "zebra") < 0);
+
+ printf("%d\n", strlen(a));
+
+ strcat(a, "!");
+ printf("%s\n", a);
+
+ printf("%d\n", strncmp(a, "apple", 2) > 0);
+ printf("%d\n", strncmp(a, "goere", 2) == 0);
+ printf("%d\n", strncmp(a, "goerg", 2) == 0);
+ printf("%d\n", strncmp(a, "zebra", 2) < 0);
+
+ printf("%s\n", index(a, 'o'));
+ printf("%s\n", rindex(a, 'l'));
+ printf("%d\n", rindex(a, 'x') == NULL);
+
+ memset(&a[1], 'r', 4);
+ printf("%s\n", a);
+
+ memcpy(&a[2], a, 2);
+ printf("%s\n", a);
+
+ printf("%d\n", memcmp(a, "apple", 4) > 0);
+ printf("%d\n", memcmp(a, "grgr", 4) == 0);
+ printf("%d\n", memcmp(a, "zebra", 4) < 0);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/28_strings.expect b/tests2/28_strings.expect
new file mode 100644
index 0000000..fd9217a
--- /dev/null
+++ b/tests2/28_strings.expect
@@ -0,0 +1,19 @@
+hello
+gollo
+1
+1
+1
+5
+gollo!
+1
+1
+1
+1
+ollo!
+lo!
+1
+grrrr!
+grgrr!
+1
+1
+1
diff --git a/tests2/29_array_address.c b/tests2/29_array_address.c
new file mode 100644
index 0000000..bda5ddd
--- /dev/null
+++ b/tests2/29_array_address.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#include <string.h>
+
+int main()
+{
+ char a[10];
+ strcpy(a, "abcdef");
+ printf("%s\n", &a[1]);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/29_array_address.expect b/tests2/29_array_address.expect
new file mode 100644
index 0000000..9bc8683
--- /dev/null
+++ b/tests2/29_array_address.expect
@@ -0,0 +1 @@
+bcdef
diff --git a/tests2/30_hanoi.c b/tests2/30_hanoi.c
new file mode 100644
index 0000000..b1a1181
--- /dev/null
+++ b/tests2/30_hanoi.c
@@ -0,0 +1,122 @@
+/* example from http://barnyard.syr.edu/quickies/hanoi.c */
+
+/* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */
+/* By Terry R. McConnell (12/2/97) */
+/* Compile: cc -o hanoi hanoi.c */
+
+/* This program does no error checking. But then, if it's right,
+ it's right ... right ? */
+
+
+/* The original towers of hanoi problem seems to have been originally posed
+ by one M. Claus in 1883. There is a popular legend that goes along with
+ it that has been often repeated and paraphrased. It goes something like this:
+ In the great temple at Benares there are 3 golden spikes. On one of them,
+ God placed 64 disks increasing in size from bottom to top, at the beginning
+ of time. Since then, and to this day, the priest on duty constantly transfers
+ disks, one at a time, in such a way that no larger disk is ever put on top
+ of a smaller one. When the disks have been transferred entirely to another
+ spike the Universe will come to an end in a large thunderclap.
+
+ This paraphrases the original legend due to DeParville, La Nature, Paris 1884,
+ Part I, 285-286. For this and further information see: Mathematical
+ Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
+ 303-305.
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TRUE 1
+#define FALSE 0
+
+/* This is the number of "disks" on tower A initially. Taken to be 64 in the
+ * legend. The number of moves required, in general, is 2^N - 1. For N = 64,
+ * this is 18,446,744,073,709,551,615 */
+#define N 4
+
+/* These are the three towers. For example if the state of A is 0,1,3,4, that
+ * means that there are three discs on A of sizes 1, 3, and 4. (Think of right
+ * as being the "down" direction.) */
+int A[N], B[N], C[N];
+
+void Hanoi(int,int*,int*,int*);
+
+/* Print the current configuration of A, B, and C to the screen */
+void PrintAll()
+{
+ int i;
+
+ printf("A: ");
+ for(i=0;i<N;i++)printf(" %d ",A[i]);
+ printf("\n");
+
+ printf("B: ");
+ for(i=0;i<N;i++)printf(" %d ",B[i]);
+ printf("\n");
+
+ printf("C: ");
+ for(i=0;i<N;i++)printf(" %d ",C[i]);
+ printf("\n");
+ printf("------------------------------------------\n");
+ return;
+}
+
+/* Move the leftmost nonzero element of source to dest, leave behind 0. */
+/* Returns the value moved (not used.) */
+int Move(int *source, int *dest)
+{
+ int i,j;
+
+ while (i<N && (source[i])==0) i++;
+ while (j<N && (dest[j])==0) j++;
+
+ dest[j-1] = source[i];
+ source[i] = 0;
+ PrintAll(); /* Print configuration after each move. */
+ return dest[j-1];
+}
+
+
+/* Moves first n nonzero numbers from source to dest using the rules of Hanoi.
+ Calls itself recursively.
+ */
+void Hanoi(int n,int *source, int *dest, int *spare)
+{
+ int i;
+ if(n==1){
+ Move(source,dest);
+ return;
+ }
+
+ Hanoi(n-1,source,spare,dest);
+ Move(source,dest);
+ Hanoi(n-1,spare,dest,source);
+ return;
+}
+
+int main()
+{
+ int i;
+
+ /* initialize the towers */
+ for(i=0;i<N;i++)A[i]=i+1;
+ for(i=0;i<N;i++)B[i]=0;
+ for(i=0;i<N;i++)C[i]=0;
+
+ printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N);
+
+ /* Print the starting state */
+ printf("Starting state:\n");
+ PrintAll();
+ printf("\n\nSubsequent states:\n\n");
+
+ /* Do it! Use A = Source, B = Destination, C = Spare */
+ Hanoi(N,A,B,C);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/30_hanoi.expect b/tests2/30_hanoi.expect
new file mode 100644
index 0000000..7798ee0
--- /dev/null
+++ b/tests2/30_hanoi.expect
@@ -0,0 +1,71 @@
+Solution of Tower of Hanoi Problem with 4 Disks
+
+Starting state:
+A: 1 2 3 4
+B: 0 0 0 0
+C: 0 0 0 0
+------------------------------------------
+
+
+Subsequent states:
+
+A: 0 2 3 4
+B: 0 0 0 0
+C: 0 0 0 1
+------------------------------------------
+A: 0 0 3 4
+B: 0 0 0 2
+C: 0 0 0 1
+------------------------------------------
+A: 0 0 3 4
+B: 0 0 1 2
+C: 0 0 0 0
+------------------------------------------
+A: 0 0 0 4
+B: 0 0 1 2
+C: 0 0 0 3
+------------------------------------------
+A: 0 0 1 4
+B: 0 0 0 2
+C: 0 0 0 3
+------------------------------------------
+A: 0 0 1 4
+B: 0 0 0 0
+C: 0 0 2 3
+------------------------------------------
+A: 0 0 0 4
+B: 0 0 0 0
+C: 0 1 2 3
+------------------------------------------
+A: 0 0 0 0
+B: 0 0 0 4
+C: 0 1 2 3
+------------------------------------------
+A: 0 0 0 0
+B: 0 0 1 4
+C: 0 0 2 3
+------------------------------------------
+A: 0 0 0 2
+B: 0 0 1 4
+C: 0 0 0 3
+------------------------------------------
+A: 0 0 1 2
+B: 0 0 0 4
+C: 0 0 0 3
+------------------------------------------
+A: 0 0 1 2
+B: 0 0 3 4
+C: 0 0 0 0
+------------------------------------------
+A: 0 0 0 2
+B: 0 0 3 4
+C: 0 0 0 1
+------------------------------------------
+A: 0 0 0 0
+B: 0 2 3 4
+C: 0 0 0 1
+------------------------------------------
+A: 0 0 0 0
+B: 1 2 3 4
+C: 0 0 0 0
+------------------------------------------
diff --git a/tests2/31_args.c b/tests2/31_args.c
new file mode 100644
index 0000000..275f8cf
--- /dev/null
+++ b/tests2/31_args.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ int Count;
+
+ printf("hello world %d\n", argc);
+ for (Count = 0; Count < argc; Count++)
+ printf("arg %d: %s\n", Count, argv[Count]);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/31_args.expect b/tests2/31_args.expect
new file mode 100644
index 0000000..c392b67
--- /dev/null
+++ b/tests2/31_args.expect
@@ -0,0 +1,7 @@
+hello world 6
+arg 0: 31_args.c
+arg 1: -
+arg 2: arg1
+arg 3: arg2
+arg 4: arg3
+arg 5: arg4
diff --git a/tests2/32_led.c b/tests2/32_led.c
new file mode 100644
index 0000000..5596cbf
--- /dev/null
+++ b/tests2/32_led.c
@@ -0,0 +1,266 @@
+/* example from http://barnyard.syr.edu/quickies/led.c */
+
+/* led.c: print out number as if on 7 line led display. I.e., write integer
+ given on command line like this:
+ _ _ _
+ | _| _| |_| |_
+ | |_ _| | _| etc.
+
+ We assume the terminal behaves like a classical teletype. So the top
+ lines of all digits have to be printed first, then the middle lines of
+ all digits, etc.
+
+ By Terry R. McConnell
+
+compile: cc -o led led.c
+
+If you just want to link in the subroutine print_led that does all the
+work, compile with -DNO_MAIN, and declare the following in any source file
+that uses the call:
+
+extern void print_led(unsigned long x, char *buf);
+
+Bug: you cannot call repeatedly to print more than one number to a line.
+That would require curses or some other terminal API that allows moving the
+cursor to a previous line.
+
+*/
+
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#define MAX_DIGITS 32
+#define NO_MAIN
+
+
+/* Print the top line of the digit d into buffer.
+ Does not null terminate buffer. */
+
+void topline(int d, char *p){
+
+ *p++ = ' ';
+ switch(d){
+
+ /* all these have _ on top line */
+
+ case 0:
+ case 2:
+ case 3:
+ case 5:
+ case 7:
+ case 8:
+ case 9:
+ *p++ = '_';
+ break;
+ default:
+ *p++=' ';
+
+ }
+ *p++=' ';
+}
+
+/* Print the middle line of the digit d into the buffer.
+ Does not null terminate. */
+
+void midline(int d, char *p){
+
+ switch(d){
+
+ /* those that have leading | on middle line */
+
+ case 0:
+ case 4:
+ case 5:
+ case 6:
+ case 8:
+ case 9:
+ *p++='|';
+ break;
+ default:
+ *p++=' ';
+ }
+ switch(d){
+
+ /* those that have _ on middle line */
+
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 8:
+ case 9:
+ *p++='_';
+ break;
+ default:
+ *p++=' ';
+
+ }
+ switch(d){
+
+ /* those that have closing | on middle line */
+
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 7:
+ case 8:
+ case 9:
+ *p++='|';
+ break;
+ default:
+ *p++=' ';
+
+ }
+}
+
+/* Print the bottom line of the digit d. Does not null terminate. */
+
+void botline(int d, char *p){
+
+
+ switch(d){
+
+ /* those that have leading | on bottom line */
+
+ case 0:
+ case 2:
+ case 6:
+ case 8:
+ *p++='|';
+ break;
+ default:
+ *p++=' ';
+ }
+ switch(d){
+
+ /* those that have _ on bottom line */
+
+ case 0:
+ case 2:
+ case 3:
+ case 5:
+ case 6:
+ case 8:
+ *p++='_';
+ break;
+ default:
+ *p++=' ';
+
+ }
+ switch(d){
+
+ /* those that have closing | on bottom line */
+
+ case 0:
+ case 1:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ *p++='|';
+ break;
+ default:
+ *p++=' ';
+
+ }
+}
+
+/* Write the led representation of integer to string buffer. */
+
+void print_led(unsigned long x, char *buf)
+{
+
+ int i=0,n;
+ static int d[MAX_DIGITS];
+
+
+ /* extract digits from x */
+
+ n = ( x == 0L ? 1 : 0 ); /* 0 is a digit, hence a special case */
+
+ while(x){
+ d[n++] = (int)(x%10L);
+ if(n >= MAX_DIGITS)break;
+ x = x/10L;
+ }
+
+ /* print top lines of all digits */
+
+ for(i=n-1;i>=0;i--){
+ topline(d[i],buf);
+ buf += 3;
+ *buf++=' ';
+ }
+ *buf++='\n'; /* move teletype to next line */
+
+ /* print middle lines of all digits */
+
+ for(i=n-1;i>=0;i--){
+ midline(d[i],buf);
+ buf += 3;
+ *buf++=' ';
+ }
+ *buf++='\n';
+
+ /* print bottom lines of all digits */
+
+ for(i=n-1;i>=0;i--){
+ botline(d[i],buf);
+ buf += 3;
+ *buf++=' ';
+ }
+ *buf++='\n';
+ *buf='\0';
+}
+
+int main()
+{
+ char buf[5*MAX_DIGITS];
+ print_led(1234567, buf);
+ printf("%s\n",buf);
+
+ return 0;
+}
+
+#ifndef NO_MAIN
+int main(int argc, char **argv)
+{
+
+ int i=0,n;
+ long x;
+ static int d[MAX_DIGITS];
+ char buf[5*MAX_DIGITS];
+
+ if(argc != 2){
+ fprintf(stderr,"led: usage: led integer\n");
+ return 1;
+ }
+
+ /* fetch argument from command line */
+
+ x = atol(argv[1]);
+
+ /* sanity check */
+
+ if(x<0){
+ fprintf(stderr,"led: %d must be non-negative\n",x);
+ return 1;
+ }
+
+ print_led(x,buf);
+ printf("%s\n",buf);
+
+ return 0;
+
+}
+#endif
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/32_led.expect b/tests2/32_led.expect
new file mode 100644
index 0000000..c53b58a
--- /dev/null
+++ b/tests2/32_led.expect
@@ -0,0 +1,4 @@
+ _ _ _ _
+ | _| _| |_| |_ |_ |
+ | |_ _| | _| |_| |
+
diff --git a/tests2/33_ternary_op.c b/tests2/33_ternary_op.c
new file mode 100644
index 0000000..8579b50
--- /dev/null
+++ b/tests2/33_ternary_op.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main()
+{
+ int Count;
+
+ for (Count = 0; Count < 10; Count++)
+ {
+ printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3));
+ }
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/33_ternary_op.expect b/tests2/33_ternary_op.expect
new file mode 100644
index 0000000..45ea507
--- /dev/null
+++ b/tests2/33_ternary_op.expect
@@ -0,0 +1,10 @@
+0
+1
+4
+9
+16
+15
+18
+21
+24
+27
diff --git a/tests2/34_array_assignment.c b/tests2/34_array_assignment.c
new file mode 100644
index 0000000..5885c97
--- /dev/null
+++ b/tests2/34_array_assignment.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main()
+{
+ int a[4];
+
+ a[0] = 12;
+ a[1] = 23;
+ a[2] = 34;
+ a[3] = 45;
+
+ printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);
+
+ int b[4];
+
+ b = a;
+
+ printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/34_array_assignment.expect b/tests2/34_array_assignment.expect
new file mode 100644
index 0000000..9736bf5
--- /dev/null
+++ b/tests2/34_array_assignment.expect
@@ -0,0 +1,2 @@
+12 23 34 45
+12 23 34 45
diff --git a/tests2/35_sizeof.c b/tests2/35_sizeof.c
new file mode 100644
index 0000000..672e87e
--- /dev/null
+++ b/tests2/35_sizeof.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main()
+{
+ char a;
+ short b;
+
+ printf("%d %d\n", sizeof(char), sizeof(a));
+ printf("%d %d\n", sizeof(short), sizeof(b));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/35_sizeof.expect b/tests2/35_sizeof.expect
new file mode 100644
index 0000000..534fb83
--- /dev/null
+++ b/tests2/35_sizeof.expect
@@ -0,0 +1,2 @@
+1 1
+2 2
diff --git a/tests2/36_array_initialisers.c b/tests2/36_array_initialisers.c
new file mode 100644
index 0000000..1bc8ee0
--- /dev/null
+++ b/tests2/36_array_initialisers.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int main()
+{
+ int Count;
+
+ int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 };
+
+ for (Count = 0; Count < 10; Count++)
+ printf("%d: %d\n", Count, Array[Count]);
+
+ int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, };
+
+ for (Count = 0; Count < 10; Count++)
+ printf("%d: %d\n", Count, Array2[Count]);
+
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/36_array_initialisers.expect b/tests2/36_array_initialisers.expect
new file mode 100644
index 0000000..3ac6c77
--- /dev/null
+++ b/tests2/36_array_initialisers.expect
@@ -0,0 +1,20 @@
+0: 12
+1: 34
+2: 56
+3: 78
+4: 90
+5: 123
+6: 456
+7: 789
+8: 8642
+9: 9753
+0: 12
+1: 34
+2: 56
+3: 78
+4: 90
+5: 123
+6: 456
+7: 789
+8: 8642
+9: 9753
diff --git a/tests2/37_sprintf.c b/tests2/37_sprintf.c
new file mode 100644
index 0000000..1dd1dce
--- /dev/null
+++ b/tests2/37_sprintf.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main()
+{
+ char Buf[100];
+ int Count;
+
+ for (Count = 1; Count <= 20; Count++)
+ {
+ sprintf(Buf, "->%02d<-\n", Count);
+ printf("%s", Buf);
+ }
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/37_sprintf.expect b/tests2/37_sprintf.expect
new file mode 100644
index 0000000..a643da8
--- /dev/null
+++ b/tests2/37_sprintf.expect
@@ -0,0 +1,20 @@
+->01<-
+->02<-
+->03<-
+->04<-
+->05<-
+->06<-
+->07<-
+->08<-
+->09<-
+->10<-
+->11<-
+->12<-
+->13<-
+->14<-
+->15<-
+->16<-
+->17<-
+->18<-
+->19<-
+->20<-
diff --git a/tests2/38_multiple_array_index.c b/tests2/38_multiple_array_index.c
new file mode 100644
index 0000000..4e1868e
--- /dev/null
+++ b/tests2/38_multiple_array_index.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+int main()
+{
+ int a[4][4];
+ int b = 0;
+ int x;
+ int y;
+
+ for (x = 0; x < 4; x++)
+ {
+ for (y = 0; y < 4; y++)
+ {
+ b++;
+ a[x][y] = b;
+ }
+ }
+
+ for (x = 0; x < 4; x++)
+ {
+ printf("x=%d: ", x);
+ for (y = 0; y < 4; y++)
+ {
+ printf("%d ", a[x][y]);
+ }
+ printf("\n");
+ }
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/38_multiple_array_index.expect b/tests2/38_multiple_array_index.expect
new file mode 100644
index 0000000..747ad75
--- /dev/null
+++ b/tests2/38_multiple_array_index.expect
@@ -0,0 +1,4 @@
+x=0: 1 2 3 4
+x=1: 5 6 7 8
+x=2: 9 10 11 12
+x=3: 13 14 15 16
diff --git a/tests2/39_typedef.c b/tests2/39_typedef.c
new file mode 100644
index 0000000..79ab58b
--- /dev/null
+++ b/tests2/39_typedef.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+
+typedef int MyInt;
+
+struct FunStruct
+{
+ int i;
+ int j;
+};
+
+typedef struct FunStruct MyFunStruct;
+
+typedef MyFunStruct *MoreFunThanEver;
+
+int main()
+{
+ MyInt a = 1;
+ printf("%d\n", a);
+
+ MyFunStruct b;
+ b.i = 12;
+ b.j = 34;
+ printf("%d,%d\n", b.i, b.j);
+
+ MoreFunThanEver c = &b;
+ printf("%d,%d\n", c->i, c->j);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/39_typedef.expect b/tests2/39_typedef.expect
new file mode 100644
index 0000000..b9050a9
--- /dev/null
+++ b/tests2/39_typedef.expect
@@ -0,0 +1,3 @@
+1
+12,34
+12,34
diff --git a/tests2/40_stdio.c b/tests2/40_stdio.c
new file mode 100644
index 0000000..575127a
--- /dev/null
+++ b/tests2/40_stdio.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+
+int main()
+{
+ FILE *f = fopen("fred.txt", "w");
+ fwrite("hello\nhello\n", 1, 12, f);
+ fclose(f);
+
+ char freddy[7];
+ f = fopen("fred.txt", "r");
+ if (fread(freddy, 1, 6, f) != 6)
+ printf("couldn't read fred.txt\n");
+
+ freddy[6] = '\0';
+ fclose(f);
+
+ printf("%s", freddy);
+
+ char InChar;
+ char ShowChar;
+ f = fopen("fred.txt", "r");
+ while ( (InChar = fgetc(f)) != EOF)
+ {
+ ShowChar = InChar;
+ if (ShowChar < ' ')
+ ShowChar = '.';
+
+ printf("ch: %d '%c'\n", InChar, ShowChar);
+ }
+ fclose(f);
+
+ f = fopen("fred.txt", "r");
+ while ( (InChar = getc(f)) != EOF)
+ {
+ ShowChar = InChar;
+ if (ShowChar < ' ')
+ ShowChar = '.';
+
+ printf("ch: %d '%c'\n", InChar, ShowChar);
+ }
+ fclose(f);
+
+ f = fopen("fred.txt", "r");
+ while (fgets(freddy, sizeof(freddy), f) != NULL)
+ printf("x: %s", freddy);
+
+ fclose(f);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/40_stdio.expect b/tests2/40_stdio.expect
new file mode 100644
index 0000000..e08167a
--- /dev/null
+++ b/tests2/40_stdio.expect
@@ -0,0 +1,27 @@
+hello
+ch: 104 'h'
+ch: 101 'e'
+ch: 108 'l'
+ch: 108 'l'
+ch: 111 'o'
+ch: 10 '.'
+ch: 104 'h'
+ch: 101 'e'
+ch: 108 'l'
+ch: 108 'l'
+ch: 111 'o'
+ch: 10 '.'
+ch: 104 'h'
+ch: 101 'e'
+ch: 108 'l'
+ch: 108 'l'
+ch: 111 'o'
+ch: 10 '.'
+ch: 104 'h'
+ch: 101 'e'
+ch: 108 'l'
+ch: 108 'l'
+ch: 111 'o'
+ch: 10 '.'
+x: hello
+x: hello
diff --git a/tests2/41_hashif.c b/tests2/41_hashif.c
new file mode 100644
index 0000000..cb37b9e
--- /dev/null
+++ b/tests2/41_hashif.c
@@ -0,0 +1,85 @@
+#include <stdio.h>
+
+int main()
+{
+ printf("#include test\n");
+
+#if 1
+#if 0
+ printf("a\n");
+#else
+ printf("b\n");
+#endif
+#else
+#if 0
+ printf("c\n");
+#else
+ printf("d\n");
+#endif
+#endif
+
+#if 0
+#if 1
+ printf("e\n");
+#else
+ printf("f\n");
+#endif
+#else
+#if 1
+ printf("g\n");
+#else
+ printf("h\n");
+#endif
+#endif
+
+#define DEF
+
+#ifdef DEF
+#ifdef DEF
+ printf("i\n");
+#else
+ printf("j\n");
+#endif
+#else
+#ifdef DEF
+ printf("k\n");
+#else
+ printf("l\n");
+#endif
+#endif
+
+#ifndef DEF
+#ifndef DEF
+ printf("m\n");
+#else
+ printf("n\n");
+#endif
+#else
+#ifndef DEF
+ printf("o\n");
+#else
+ printf("p\n");
+#endif
+#endif
+
+#define ONE 1
+#define ZERO 0
+
+#if ONE
+#if ZERO
+ printf("q\n");
+#else
+ printf("r\n");
+#endif
+#else
+#if ZERO
+ printf("s\n");
+#else
+ printf("t\n");
+#endif
+#endif
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/41_hashif.expect b/tests2/41_hashif.expect
new file mode 100644
index 0000000..5fd414b
--- /dev/null
+++ b/tests2/41_hashif.expect
@@ -0,0 +1,6 @@
+#include test
+b
+g
+i
+p
+r
diff --git a/tests2/42_function_pointer.c b/tests2/42_function_pointer.c
new file mode 100644
index 0000000..49c331b
--- /dev/null
+++ b/tests2/42_function_pointer.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int fred(int p)
+{
+ printf("yo %d\n", p);
+ return 42;
+}
+
+int (*f)(int) = &fred;
+
+int main()
+{
+ printf("%d\n", (*f)(24));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/42_function_pointer.expect b/tests2/42_function_pointer.expect
new file mode 100644
index 0000000..6c8b6ce
--- /dev/null
+++ b/tests2/42_function_pointer.expect
@@ -0,0 +1,2 @@
+yo 24
+42
diff --git a/tests2/43_void_param.c b/tests2/43_void_param.c
new file mode 100644
index 0000000..de17098
--- /dev/null
+++ b/tests2/43_void_param.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+void fred(void)
+{
+ printf("yo\n");
+}
+
+int main()
+{
+ fred();
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/43_void_param.expect b/tests2/43_void_param.expect
new file mode 100644
index 0000000..092bfb9
--- /dev/null
+++ b/tests2/43_void_param.expect
@@ -0,0 +1 @@
+yo
diff --git a/tests2/44_scoped_declarations.c b/tests2/44_scoped_declarations.c
new file mode 100644
index 0000000..2febf98
--- /dev/null
+++ b/tests2/44_scoped_declarations.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+
+ for (a = 0; a < 2; a++)
+ {
+ int b = a;
+ }
+
+ printf("it's all good\n");
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/44_scoped_declarations.expect b/tests2/44_scoped_declarations.expect
new file mode 100644
index 0000000..231ccc0
--- /dev/null
+++ b/tests2/44_scoped_declarations.expect
@@ -0,0 +1 @@
+it's all good
diff --git a/tests2/45_empty_for.c b/tests2/45_empty_for.c
new file mode 100644
index 0000000..b14e9d4
--- /dev/null
+++ b/tests2/45_empty_for.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+int main()
+{
+ int Count = 0;
+
+ for (;;)
+ {
+ Count++;
+ printf("%d\n", Count);
+ if (Count >= 10)
+ break;
+ }
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/45_empty_for.expect b/tests2/45_empty_for.expect
new file mode 100644
index 0000000..f00c965
--- /dev/null
+++ b/tests2/45_empty_for.expect
@@ -0,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
diff --git a/tests2/46_grep.c b/tests2/46_grep.c
new file mode 100644
index 0000000..5f52220
--- /dev/null
+++ b/tests2/46_grep.c
@@ -0,0 +1,564 @@
+/*
+ * The information in this document is subject to change
+ * without notice and should not be construed as a commitment
+ * by Digital Equipment Corporation or by DECUS.
+ *
+ * Neither Digital Equipment Corporation, DECUS, nor the authors
+ * assume any responsibility for the use or reliability of this
+ * document or the described software.
+ *
+ * Copyright (C) 1980, DECUS
+ *
+ * General permission to copy or modify, but not for profit, is
+ * hereby granted, provided that the above copyright notice is
+ * included and reference made to the fact that reproduction
+ * privileges were granted by DECUS.
+ */
+#include <stdio.h>
+
+/*
+ * grep
+ *
+ * Runs on the Decus compiler or on vms, On vms, define as:
+ * grep :== "$disk:[account]grep" (native)
+ * grep :== "$disk:[account]grep grep" (Decus)
+ * See below for more information.
+ */
+
+#if 0
+char *documentation[] = {
+ "grep searches a file for a given pattern. Execute by",
+ " grep [flags] regular_expression file_list\n",
+ "Flags are single characters preceeded by '-':",
+ " -c Only a count of matching lines is printed",
+ " -f Print file name for matching lines switch, see below",
+ " -n Each line is preceeded by its line number",
+ " -v Only print non-matching lines\n",
+ "The file_list is a list of files (wildcards are acceptable on RSX modes).",
+ "\nThe file name is normally printed if there is a file given.",
+ "The -f flag reverses this action (print name no file, not if more).\n",
+ 0 };
+
+char *patdoc[] = {
+ "The regular_expression defines the pattern to search for. Upper- and",
+ "lower-case are always ignored. Blank lines never match. The expression",
+ "should be quoted to prevent file-name translation.",
+ "x An ordinary character (not mentioned below) matches that character.",
+ "'\\' The backslash quotes any character. \"\\$\" matches a dollar-sign.",
+ "'^' A circumflex at the beginning of an expression matches the",
+ " beginning of a line.",
+ "'$' A dollar-sign at the end of an expression matches the end of a line.",
+ "'.' A period matches any character except \"new-line\".",
+ "':a' A colon matches a class of characters described by the following",
+ "':d' character. \":a\" matches any alphabetic, \":d\" matches digits,",
+ "':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and",
+ "': ' other control characters, such as new-line.",
+ "'*' An expression followed by an asterisk matches zero or more",
+ " occurrances of that expression: \"fo*\" matches \"f\", \"fo\"",
+ " \"foo\", etc.",
+ "'+' An expression followed by a plus sign matches one or more",
+ " occurrances of that expression: \"fo+\" matches \"fo\", etc.",
+ "'-' An expression followed by a minus sign optionally matches",
+ " the expression.",
+ "'[]' A string enclosed in square brackets matches any character in",
+ " that string, but no others. If the first character in the",
+ " string is a circumflex, the expression matches any character",
+ " except \"new-line\" and the characters in the string. For",
+ " example, \"[xyz]\" matches \"xx\" and \"zyx\", while \"[^xyz]\"",
+ " matches \"abc\" but not \"axb\". A range of characters may be",
+ " specified by two characters separated by \"-\". Note that,",
+ " [a-z] matches alphabetics, while [z-a] never matches.",
+ "The concatenation of regular expressions is a regular expression.",
+ 0};
+#endif
+
+#define LMAX 512
+#define PMAX 256
+
+#define CHAR 1
+#define BOL 2
+#define EOL 3
+#define ANY 4
+#define CLASS 5
+#define NCLASS 6
+#define STAR 7
+#define PLUS 8
+#define MINUS 9
+#define ALPHA 10
+#define DIGIT 11
+#define NALPHA 12
+#define PUNCT 13
+#define RANGE 14
+#define ENDPAT 15
+
+int cflag=0, fflag=0, nflag=0, vflag=0, nfile=0, debug=0;
+
+char *pp, lbuf[LMAX], pbuf[PMAX];
+
+char *cclass();
+char *pmatch();
+
+
+/*** Display a file name *******************************/
+void file(char *s)
+{
+ printf("File %s:\n", s);
+}
+
+/*** Report unopenable file ****************************/
+void cant(char *s)
+{
+ fprintf(stderr, "%s: cannot open\n", s);
+}
+
+/*** Give good help ************************************/
+void help(char **hp)
+{
+ char **dp;
+
+ for (dp = hp; *dp; ++dp)
+ printf("%s\n", *dp);
+}
+
+/*** Display usage summary *****************************/
+void usage(char *s)
+{
+ fprintf(stderr, "?GREP-E-%s\n", s);
+ fprintf(stderr,
+ "Usage: grep [-cfnv] pattern [file ...]. grep ? for help\n");
+ exit(1);
+}
+
+/*** Compile the pattern into global pbuf[] ************/
+void compile(char *source)
+{
+ char *s; /* Source string pointer */
+ char *lp; /* Last pattern pointer */
+ int c; /* Current character */
+ int o; /* Temp */
+ char *spp; /* Save beginning of pattern */
+
+ s = source;
+ if (debug)
+ printf("Pattern = \"%s\"\n", s);
+ pp = pbuf;
+ while (c = *s++) {
+ /*
+ * STAR, PLUS and MINUS are special.
+ */
+ if (c == '*' || c == '+' || c == '-') {
+ if (pp == pbuf ||
+ (o=pp[-1]) == BOL ||
+ o == EOL ||
+ o == STAR ||
+ o == PLUS ||
+ o == MINUS)
+ badpat("Illegal occurrance op.", source, s);
+ store(ENDPAT);
+ store(ENDPAT);
+ spp = pp; /* Save pattern end */
+ while (--pp > lp) /* Move pattern down */
+ *pp = pp[-1]; /* one byte */
+ *pp = (c == '*') ? STAR :
+ (c == '-') ? MINUS : PLUS;
+ pp = spp; /* Restore pattern end */
+ continue;
+ }
+ /*
+ * All the rest.
+ */
+ lp = pp; /* Remember start */
+ switch(c) {
+
+ case '^':
+ store(BOL);
+ break;
+
+ case '$':
+ store(EOL);
+ break;
+
+ case '.':
+ store(ANY);
+ break;
+
+ case '[':
+ s = cclass(source, s);
+ break;
+
+ case ':':
+ if (*s) {
+ switch(tolower(c = *s++)) {
+
+ case 'a':
+ case 'A':
+ store(ALPHA);
+ break;
+
+ case 'd':
+ case 'D':
+ store(DIGIT);
+ break;
+
+ case 'n':
+ case 'N':
+ store(NALPHA);
+ break;
+
+ case ' ':
+ store(PUNCT);
+ break;
+
+ default:
+ badpat("Unknown : type", source, s);
+
+ }
+ break;
+ }
+ else badpat("No : type", source, s);
+
+ case '\\':
+ if (*s)
+ c = *s++;
+
+ default:
+ store(CHAR);
+ store(tolower(c));
+ }
+ }
+ store(ENDPAT);
+ store(0); /* Terminate string */
+ if (debug) {
+ for (lp = pbuf; lp < pp;) {
+ if ((c = (*lp++ & 0377)) < ' ')
+ printf("\\%o ", c);
+ else printf("%c ", c);
+ }
+ printf("\n");
+ }
+}
+
+/*** Compile a class (within []) ***********************/
+char *cclass(char *source, char *src)
+ /* char *source; // Pattern start -- for error msg. */
+ /* char *src; // Class start */
+{
+ char *s; /* Source pointer */
+ char *cp; /* Pattern start */
+ int c; /* Current character */
+ int o; /* Temp */
+
+ s = src;
+ o = CLASS;
+ if (*s == '^') {
+ ++s;
+ o = NCLASS;
+ }
+ store(o);
+ cp = pp;
+ store(0); /* Byte count */
+ while ((c = *s++) && c!=']') {
+ if (c == '\\') { /* Store quoted char */
+ if ((c = *s++) == '\0') /* Gotta get something */
+ badpat("Class terminates badly", source, s);
+ else store(tolower(c));
+ }
+ else if (c == '-' &&
+ (pp - cp) > 1 && *s != ']' && *s != '\0') {
+ c = pp[-1]; /* Range start */
+ pp[-1] = RANGE; /* Range signal */
+ store(c); /* Re-store start */
+ c = *s++; /* Get end char and*/
+ store(tolower(c)); /* Store it */
+ }
+ else {
+ store(tolower(c)); /* Store normal char */
+ }
+ }
+ if (c != ']')
+ badpat("Unterminated class", source, s);
+ if ((c = (pp - cp)) >= 256)
+ badpat("Class too large", source, s);
+ if (c == 0)
+ badpat("Empty class", source, s);
+ *cp = c;
+ return(s);
+}
+
+/*** Store an entry in the pattern buffer **************/
+void store(int op)
+{
+ if (pp >= &pbuf[PMAX])
+ error("Pattern too complex\n");
+ *pp++ = op;
+}
+
+/*** Report a bad pattern specification ****************/
+void badpat(char *message, char *source, char *stop)
+ /* char *message; // Error message */
+ /* char *source; // Pattern start */
+ /* char *stop; // Pattern end */
+{
+ fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source);
+ fprintf(stderr, "-GREP-E-Stopped at byte %d, '%c'\n",
+ stop-source, stop[-1]);
+ error("?GREP-E-Bad pattern\n");
+}
+
+/*** Scan the file for the pattern in pbuf[] ***********/
+void grep(FILE *fp, char *fn)
+ /* FILE *fp; // File to process */
+ /* char *fn; // File name (for -f option) */
+{
+ int lno, count, m;
+
+ lno = 0;
+ count = 0;
+ while (fgets(lbuf, LMAX, fp)) {
+ ++lno;
+ m = match();
+ if ((m && !vflag) || (!m && vflag)) {
+ ++count;
+ if (!cflag) {
+ if (fflag && fn) {
+ file(fn);
+ fn = 0;
+ }
+ if (nflag)
+ printf("%d\t", lno);
+ printf("%s\n", lbuf);
+ }
+ }
+ }
+ if (cflag) {
+ if (fflag && fn)
+ file(fn);
+ printf("%d\n", count);
+ }
+}
+
+/*** Match line (lbuf) with pattern (pbuf) return 1 if match ***/
+void match()
+{
+ char *l; /* Line pointer */
+
+ for (l = lbuf; *l; ++l) {
+ if (pmatch(l, pbuf))
+ return(1);
+ }
+ return(0);
+}
+
+/*** Match partial line with pattern *******************/
+char *pmatch(char *line, char *pattern)
+ /* char *line; // (partial) line to match */
+ /* char *pattern; // (partial) pattern to match */
+{
+ char *l; /* Current line pointer */
+ char *p; /* Current pattern pointer */
+ char c; /* Current character */
+ char *e; /* End for STAR and PLUS match */
+ int op; /* Pattern operation */
+ int n; /* Class counter */
+ char *are; /* Start of STAR match */
+
+ l = line;
+ if (debug > 1)
+ printf("pmatch(\"%s\")\n", line);
+ p = pattern;
+ while ((op = *p++) != ENDPAT) {
+ if (debug > 1)
+ printf("byte[%d] = 0%o, '%c', op = 0%o\n",
+ l-line, *l, *l, op);
+ switch(op) {
+
+ case CHAR:
+ if (tolower(*l++) != *p++)
+ return(0);
+ break;
+
+ case BOL:
+ if (l != lbuf)
+ return(0);
+ break;
+
+ case EOL:
+ if (*l != '\0')
+ return(0);
+ break;
+
+ case ANY:
+ if (*l++ == '\0')
+ return(0);
+ break;
+
+ case DIGIT:
+ if ((c = *l++) < '0' || (c > '9'))
+ return(0);
+ break;
+
+ case ALPHA:
+ c = tolower(*l++);
+ if (c < 'a' || c > 'z')
+ return(0);
+ break;
+
+ case NALPHA:
+ c = tolower(*l++);
+ if (c >= 'a' && c <= 'z')
+ break;
+ else if (c < '0' || c > '9')
+ return(0);
+ break;
+
+ case PUNCT:
+ c = *l++;
+ if (c == 0 || c > ' ')
+ return(0);
+ break;
+
+ case CLASS:
+ case NCLASS:
+ c = tolower(*l++);
+ n = *p++ & 0377;
+ do {
+ if (*p == RANGE) {
+ p += 3;
+ n -= 2;
+ if (c >= p[-2] && c <= p[-1])
+ break;
+ }
+ else if (c == *p++)
+ break;
+ } while (--n > 1);
+ if ((op == CLASS) == (n <= 1))
+ return(0);
+ if (op == CLASS)
+ p += n - 2;
+ break;
+
+ case MINUS:
+ e = pmatch(l, p); /* Look for a match */
+ while (*p++ != ENDPAT); /* Skip over pattern */
+ if (e) /* Got a match? */
+ l = e; /* Yes, update string */
+ break; /* Always succeeds */
+
+ case PLUS: /* One or more ... */
+ if ((l = pmatch(l, p)) == 0)
+ return(0); /* Gotta have a match */
+ case STAR: /* Zero or more ... */
+ are = l; /* Remember line start */
+ while (*l && (e = pmatch(l, p)))
+ l = e; /* Get longest match */
+ while (*p++ != ENDPAT); /* Skip over pattern */
+ while (l >= are) { /* Try to match rest */
+ if (e = pmatch(l, p))
+ return(e);
+ --l; /* Nope, try earlier */
+ }
+ return(0); /* Nothing else worked */
+
+ default:
+ printf("Bad op code %d\n", op);
+ error("Cannot happen -- match\n");
+ }
+ }
+ return(l);
+}
+
+/*** Report an error ***********************************/
+void error(char *s)
+{
+ fprintf(stderr, "%s", s);
+ exit(1);
+}
+
+/*** Main program - parse arguments & grep *************/
+int main(int argc, char **argv)
+{
+ char *p;
+ int c, i;
+ int gotpattern;
+
+ FILE *f;
+
+ if (argc <= 1)
+ usage("No arguments");
+ if (argc == 2 && argv[1][0] == '?' && argv[1][1] == 0) {
+ help(documentation);
+ help(patdoc);
+ return 0;
+ }
+ nfile = argc-1;
+ gotpattern = 0;
+ for (i=1; i < argc; ++i) {
+ p = argv[i];
+ if (*p == '-') {
+ ++p;
+ while (c = *p++) {
+ switch(tolower(c)) {
+
+ case '?':
+ help(documentation);
+ break;
+
+ case 'C':
+ case 'c':
+ ++cflag;
+ break;
+
+ case 'D':
+ case 'd':
+ ++debug;
+ break;
+
+ case 'F':
+ case 'f':
+ ++fflag;
+ break;
+
+ case 'n':
+ case 'N':
+ ++nflag;
+ break;
+
+ case 'v':
+ case 'V':
+ ++vflag;
+ break;
+
+ default:
+ usage("Unknown flag");
+ }
+ }
+ argv[i] = 0;
+ --nfile;
+ } else if (!gotpattern) {
+ compile(p);
+ argv[i] = 0;
+ ++gotpattern;
+ --nfile;
+ }
+ }
+ if (!gotpattern)
+ usage("No pattern");
+ if (nfile == 0)
+ grep(stdin, 0);
+ else {
+ fflag = fflag ^ (nfile > 0);
+ for (i=1; i < argc; ++i) {
+ if (p = argv[i]) {
+ if ((f=fopen(p, "r")) == NULL)
+ cant(p);
+ else {
+ grep(f, p);
+ fclose(f);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/47_switch_return.c b/tests2/47_switch_return.c
new file mode 100644
index 0000000..1ec7924
--- /dev/null
+++ b/tests2/47_switch_return.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+void fred(int x)
+{
+ switch (x)
+ {
+ case 1: printf("1\n"); return;
+ case 2: printf("2\n"); break;
+ case 3: printf("3\n"); return;
+ }
+
+ printf("out\n");
+}
+
+int main()
+{
+ fred(1);
+ fred(2);
+ fred(3);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/47_switch_return.expect b/tests2/47_switch_return.expect
new file mode 100644
index 0000000..b6deb7e
--- /dev/null
+++ b/tests2/47_switch_return.expect
@@ -0,0 +1,4 @@
+1
+2
+out
+3
diff --git a/tests2/48_nested_break.c b/tests2/48_nested_break.c
new file mode 100644
index 0000000..5bc5ba4
--- /dev/null
+++ b/tests2/48_nested_break.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+int main()
+{
+ int a;
+ char b;
+
+ a = 0;
+ while (a < 2)
+ {
+ printf("%d", a++);
+ break;
+
+ b = 'A';
+ while (b < 'C')
+ {
+ printf("%c", b++);
+ }
+ printf("e");
+ }
+ printf("\n");
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/48_nested_break.expect b/tests2/48_nested_break.expect
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/tests2/48_nested_break.expect
@@ -0,0 +1 @@
+0
diff --git a/tests2/49_bracket_evaluation.c b/tests2/49_bracket_evaluation.c
new file mode 100644
index 0000000..0cbe57d
--- /dev/null
+++ b/tests2/49_bracket_evaluation.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+struct point
+{
+ double x;
+ double y;
+};
+
+struct point point_array[100];
+
+int main()
+{
+ int my_point = 10;
+
+ point_array[my_point].x = 12.34;
+ point_array[my_point].y = 56.78;
+
+ printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/49_bracket_evaluation.expect b/tests2/49_bracket_evaluation.expect
new file mode 100644
index 0000000..1da66db
--- /dev/null
+++ b/tests2/49_bracket_evaluation.expect
@@ -0,0 +1 @@
+12.340000, 56.780000
diff --git a/tests2/50_logical_second_arg.c b/tests2/50_logical_second_arg.c
new file mode 100644
index 0000000..5fa0bb9
--- /dev/null
+++ b/tests2/50_logical_second_arg.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+int fred()
+{
+ printf("fred\n");
+ return 0;
+}
+
+int joe()
+{
+ printf("joe\n");
+ return 1;
+}
+
+int main()
+{
+ printf("%d\n", fred() && joe());
+ printf("%d\n", fred() || joe());
+ printf("%d\n", joe() && fred());
+ printf("%d\n", joe() || fred());
+ printf("%d\n", fred() && (1 + joe()));
+ printf("%d\n", fred() || (0 + joe()));
+ printf("%d\n", joe() && (0 + fred()));
+ printf("%d\n", joe() || (1 + fred()));
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/50_logical_second_arg.expect b/tests2/50_logical_second_arg.expect
new file mode 100644
index 0000000..d6174ae
--- /dev/null
+++ b/tests2/50_logical_second_arg.expect
@@ -0,0 +1,20 @@
+fred
+0
+fred
+joe
+1
+joe
+fred
+0
+joe
+1
+fred
+0
+fred
+joe
+1
+joe
+fred
+0
+joe
+1
diff --git a/tests2/51_static.c b/tests2/51_static.c
new file mode 100644
index 0000000..d6c0917
--- /dev/null
+++ b/tests2/51_static.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+static int fred = 1234;
+static int joe;
+
+void henry()
+{
+ static int fred = 4567;
+
+ printf("%d\n", fred);
+ fred++;
+}
+
+int main()
+{
+ printf("%d\n", fred);
+ henry();
+ henry();
+ henry();
+ henry();
+ printf("%d\n", fred);
+ fred = 8901;
+ joe = 2345;
+ printf("%d\n", fred);
+ printf("%d\n", joe);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/51_static.expect b/tests2/51_static.expect
new file mode 100644
index 0000000..18224fa
--- /dev/null
+++ b/tests2/51_static.expect
@@ -0,0 +1,8 @@
+1234
+4567
+4568
+4569
+4570
+1234
+8901
+2345
diff --git a/tests2/52_unnamed_enum.c b/tests2/52_unnamed_enum.c
new file mode 100644
index 0000000..d0395b2
--- /dev/null
+++ b/tests2/52_unnamed_enum.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+enum fred { a, b, c };
+
+int main()
+{
+ printf("a=%d\n", a);
+ printf("b=%d\n", b);
+ printf("c=%d\n", c);
+
+ enum fred d;
+
+ typedef enum { e, f, g } h;
+ typedef enum { i, j, k } m;
+
+ printf("e=%d\n", e);
+ printf("f=%d\n", f);
+ printf("g=%d\n", g);
+
+ printf("i=%d\n", i);
+ printf("j=%d\n", j);
+ printf("k=%d\n", k);
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/52_unnamed_enum.expect b/tests2/52_unnamed_enum.expect
new file mode 100644
index 0000000..84f2ac8
--- /dev/null
+++ b/tests2/52_unnamed_enum.expect
@@ -0,0 +1,9 @@
+a=0
+b=1
+c=2
+e=0
+f=1
+g=2
+i=0
+j=1
+k=2
diff --git a/tests2/54_goto.c b/tests2/54_goto.c
new file mode 100644
index 0000000..9509e83
--- /dev/null
+++ b/tests2/54_goto.c
@@ -0,0 +1,56 @@
+#include <stdio.h>
+
+void fred()
+{
+ printf("In fred()\n");
+ goto done;
+ printf("In middle\n");
+done:
+ printf("At end\n");
+}
+
+void joe()
+{
+ int b = 5678;
+
+ printf("In joe()\n");
+
+ {
+ int c = 1234;
+ printf("c = %d\n", c);
+ goto outer;
+ printf("uh-oh\n");
+ }
+
+outer:
+
+ printf("done\n");
+}
+
+void henry()
+{
+ int a;
+
+ printf("In henry()\n");
+ goto inner;
+
+ {
+ int b;
+inner:
+ b = 1234;
+ printf("b = %d\n", b);
+ }
+
+ printf("done\n");
+}
+
+int main()
+{
+ fred();
+ joe();
+ henry();
+
+ return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
diff --git a/tests2/54_goto.expect b/tests2/54_goto.expect
new file mode 100644
index 0000000..8e553fa
--- /dev/null
+++ b/tests2/54_goto.expect
@@ -0,0 +1,8 @@
+In fred()
+At end
+In joe()
+c = 1234
+done
+In henry()
+b = 1234
+done
diff --git a/tests2/LICENSE b/tests2/LICENSE
new file mode 100644
index 0000000..b08a652
--- /dev/null
+++ b/tests2/LICENSE
@@ -0,0 +1,37 @@
+The tests in this directory are either directly copied from the picoc project or
+are subsequently modified and added to for the purpose of TinyCC project. All
+these modifications are licensed under the same terms as TinyCC as specified in
+the file COPYING.
+
+=== picoc license ===
+
+Copyright (c) 2009-2011, Zik Saleeba
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the Zik Saleeba nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests2/Makefile b/tests2/Makefile
new file mode 100644
index 0000000..cc13cde
--- /dev/null
+++ b/tests2/Makefile
@@ -0,0 +1,90 @@
+TOP = ..
+include $(TOP)/Makefile
+
+ifeq ($(TARGETOS),Darwin)
+ CFLAGS+=-Wl,-flat_namespace,-undefined,warning
+ TCCFLAGS=-D_ANSI_SOURCE
+ export MACOSX_DEPLOYMENT_TARGET:=10.2
+endif
+
+ifdef CONFIG_WIN32
+ TCCFLAGS=-I $(TOP)/win32/include -L$(TOP)
+endif
+
+TESTS= 00_assignment.test \
+ 01_comment.test \
+ 02_printf.test \
+ 03_struct.test \
+ 04_for.test \
+ 05_array.test \
+ 06_case.test \
+ 07_function.test \
+ 08_while.test \
+ 09_do_while.test \
+ 10_pointer.test \
+ 11_precedence.test \
+ 12_hashdefine.test \
+ 13_integer_literals.test \
+ 14_if.test \
+ 15_recursion.test \
+ 16_nesting.test \
+ 17_enum.test \
+ 18_include.test \
+ 19_pointer_arithmetic.test \
+ 20_pointer_comparison.test \
+ 21_char_array.test \
+ 22_floating_point.test \
+ 23_type_coercion.test \
+ 24_math_library.test \
+ 25_quicksort.test \
+ 26_character_constants.test \
+ 27_sizeof.test \
+ 28_strings.test \
+ 29_array_address.test \
+ 31_args.test \
+ 32_led.test \
+ 33_ternary_op.test \
+ 35_sizeof.test \
+ 36_array_initialisers.test \
+ 37_sprintf.test \
+ 38_multiple_array_index.test \
+ 39_typedef.test \
+ 40_stdio.test \
+ 41_hashif.test \
+ 42_function_pointer.test \
+ 43_void_param.test \
+ 44_scoped_declarations.test \
+ 45_empty_for.test \
+ 47_switch_return.test \
+ 48_nested_break.test \
+ 49_bracket_evaluation.test \
+ 50_logical_second_arg.test \
+ 51_static.test \
+ 52_unnamed_enum.test \
+ 54_goto.test
+
+ # 30_hanoi.test \ # seg fault in the code, gcc as well
+ # 34_array_assignment.test \ # array assignment is not in C standard
+ # 46_grep.test \ # does not compile even with gcc
+
+%.test: %.expect %.c
+ @echo Test: $*...
+ -@if [ "x`echo $* | grep args`" != "x" ]; \
+ then \
+ ../tcc -B.. $(TCCFLAGS) -run $*.c - arg1 arg2 arg3 arg4 2>&1 >$*.output; \
+ else \
+ ../tcc -B.. $(TCCFLAGS) -run $*.c 2>&1 >$*.output; \
+ fi
+ @if diff -bu $*.expect $*.output ; \
+ then \
+ rm -f $*.output \
+ : \
+ else \
+ echo "ERROR: test $*"; \
+ fi
+
+all: test
+
+test: $(TESTS)
+
+# vim: set expandtab ts=4 sw=4 sts=4 tw=80 :