44-switch.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,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. #include <mes/lib-mini.h>
  21. enum type_t
  22. { TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING,
  23. TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART };
  24. int
  25. swits (int c)
  26. {
  27. int x = -1;
  28. switch (c)
  29. {
  30. case TCHAR:
  31. {
  32. oputs ("TCHAR\n");
  33. goto next;
  34. }
  35. case 1:
  36. {
  37. oputs ("1\n");
  38. goto next;
  39. }
  40. case 2:
  41. {
  42. oputs ("2\n");
  43. goto next;
  44. }
  45. default:
  46. {
  47. oputs ("default\n");
  48. goto next;
  49. }
  50. }
  51. return 1;
  52. next:
  53. switch (c)
  54. {
  55. case 0:
  56. {
  57. oputs ("0\n");
  58. x = 0;
  59. c = 34;
  60. break;
  61. }
  62. case 5:
  63. case 4:
  64. case 3:
  65. case 2:
  66. case -1:
  67. case 1:
  68. oputs ("5..1, -1\n");
  69. x = 1;
  70. break;
  71. default:
  72. oputs ("default\n");
  73. x = 2;
  74. x = 2;
  75. break;
  76. }
  77. return x;
  78. }
  79. int
  80. default_first (int c)
  81. {
  82. int a;
  83. switch (c)
  84. {
  85. here:
  86. default:
  87. a = 1;
  88. {
  89. }
  90. a = 2;
  91. return a;
  92. there:
  93. case 0:
  94. ;
  95. {
  96. }
  97. return 0;
  98. }
  99. return -1;
  100. }
  101. int
  102. main ()
  103. {
  104. oputs ("\n");
  105. oputs ("t: switch 0\n");
  106. int i = swits (0);
  107. if (i != 0)
  108. return i;
  109. oputs ("t: switch 1\n");
  110. if (swits (1) != 1)
  111. return 10;
  112. oputs ("t: switch -1\n");
  113. if (swits (-1) != 1)
  114. return 11;
  115. oputs ("t: switch -1\n");
  116. if (swits (-2) != 2)
  117. return 12;
  118. if (default_first (1) != 2)
  119. return 13;
  120. if (default_first (0) != 0)
  121. return 14;
  122. i = 15;
  123. switch (i)
  124. {
  125. case 0:
  126. case 1:
  127. case 2:
  128. case 3:
  129. case 4:
  130. i = 15;
  131. break;
  132. }
  133. if (i != 15)
  134. return 15;
  135. i = 16;
  136. switch (i)
  137. {
  138. case 1:
  139. default:
  140. case 0:
  141. i = 0;
  142. break;
  143. }
  144. if (i != 0)
  145. return 16;
  146. i = 2;
  147. switch (i)
  148. {
  149. default:
  150. case 0:
  151. i = 17;
  152. break;
  153. case 2:
  154. i = 0;
  155. }
  156. return i;
  157. }