t.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. int puts (char const *);
  21. #include <string.h>
  22. char global_arena[10];
  23. int global_i = 1;
  24. int global_unitialized;
  25. char *global_string = "foo";
  26. char global_array[8] = "XXX";
  27. char *global_chars = global_array;
  28. typedef int SCM;
  29. enum type_t
  30. { TCHAR };
  31. char *env[] = { "foo", "bar", "baz", 0 };
  32. char *list[2] = { "foo\n", "bar\n" };
  33. struct foo
  34. {
  35. int length;
  36. char *string;
  37. };
  38. struct foo g_f = { 3, "foo" };
  39. struct foo *g_g = &g_f;
  40. struct foo g_foes[2];
  41. int g_foe;
  42. struct anon
  43. {
  44. struct
  45. {
  46. int bar;
  47. int baz;
  48. };
  49. };
  50. struct anion
  51. {
  52. union
  53. {
  54. int foo;
  55. int bar;
  56. };
  57. union
  58. {
  59. int baz;
  60. int bla;
  61. };
  62. };
  63. struct here
  64. {
  65. int and;
  66. } there;
  67. typedef int int_array_t[1];
  68. int_array_t bar;
  69. typedef struct foo *foo_pointer_t;
  70. foo_pointer_t foep;
  71. struct nest
  72. {
  73. struct bar
  74. {
  75. int baz;
  76. } bar;
  77. int i;
  78. enum baz
  79. {
  80. bla
  81. } baz;
  82. enum
  83. {
  84. blub = 33,
  85. } blub;
  86. };
  87. int
  88. test (struct foo *p)
  89. {
  90. struct foo *g = &g_f;
  91. g[0].length = 0;
  92. p[0].length = 0;
  93. }
  94. int
  95. next_main (int argc, char *argv[])
  96. {
  97. return 0;
  98. }
  99. int
  100. main (int argc, char *argv[])
  101. {
  102. int i;
  103. int j = 1;
  104. int k, l = 1;
  105. if (j != 1)
  106. return 1;
  107. if (l != 1)
  108. return 2;
  109. if (global_i != 1)
  110. return 3;
  111. global_arena[1] = 0;
  112. if (global_i != 1)
  113. return 4;
  114. if (global_unitialized != 0)
  115. return 5;
  116. if (strcmp (global_string, "foo"))
  117. return 6;
  118. char *s = "bar";
  119. if (strcmp (s, "bar"))
  120. return 7;
  121. if (*global_array != 'X')
  122. return 8;
  123. if (*global_chars != 'X')
  124. return 9;
  125. SCM x = 0;
  126. if (x != 0)
  127. return 9;
  128. if (TCHAR != 0)
  129. return 11;
  130. if (strncmp (argv[0], "lib/test/scaffold", 5))
  131. return 12;
  132. if (strcmp (env[0], "foo"))
  133. return 13;
  134. if (strcmp (env[2], "baz"))
  135. return 14;
  136. if (env[3])
  137. return 15;
  138. if (g_f.length != 3)
  139. return 16;
  140. if (strcmp (g_f.string, "foo"))
  141. return 17;
  142. struct foo g = { 4, "baar" };
  143. if (g.length != 4)
  144. return 18;
  145. if (strcmp (g.string, "baar"))
  146. return 19;
  147. struct foo f = { 3, "foo" };
  148. g_foes[0] = f;
  149. g_foes[1] = f;
  150. if (g_foe)
  151. return 20;
  152. char *strings[] = { "one\n", "two\n", "three\n", 0 };
  153. char **p = strings;
  154. while (*p)
  155. eputs (*p++);
  156. if (strcmp (strings[1], "two\n"))
  157. return 21;
  158. p = list;
  159. struct anon a = { 3, 4 };
  160. eputs ("bar:");
  161. eputs (itoa (a.bar));
  162. eputs ("\n");
  163. eputs ("baz:");
  164. eputs (itoa (a.baz));
  165. eputs ("\n");
  166. if (a.bar != 3)
  167. return 22;
  168. if (a.baz != 4)
  169. return 23;
  170. struct anion u = { 3, 4 };
  171. eputs ("u.foo:");
  172. eputs (itoa (u.foo));
  173. eputs ("\n");
  174. eputs ("u.bla:");
  175. eputs (itoa (u.bla));
  176. eputs ("\n");
  177. if (u.foo != 3)
  178. return 24;
  179. if (u.bla != 4)
  180. return 25;
  181. struct nest n = { 0 };
  182. if (n.bar.baz)
  183. return 26;
  184. if (bla != 0)
  185. return 27;
  186. if (blub != 33)
  187. return 28;
  188. char buf[sizeof (g_f.string)];
  189. char buf1[sizeof (g_g->string)];
  190. int (*fun) (int, char **);
  191. fun = &next_main;
  192. //i = (*fun)(argc, argv);
  193. int (*fun2) (int, char *[]);
  194. fun2 = &next_main;
  195. //i = (*fun2)(argc, argv);
  196. i = 1;
  197. int lst[6] = { -1, 1 - 1, i, 2, 3 };
  198. for (int i = 0; i < 4; i++)
  199. {
  200. eputs ("i: ");
  201. eputs (itoa (lst[i]));
  202. eputs ("\n");
  203. if (lst[i + 1] != i)
  204. return 30 + i;
  205. }
  206. eputs ("foo" "bar");
  207. return 0;
  208. }