append.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "prescheme.h"
  2. #include "ps-init.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. static void string_copyB(char *, long, char *, long, long);
  7. char *string_append(char *, char *);
  8. long main(long, char **);
  9. static void string_copyB(char *target_0X, long offset_1X, char *source_2X,
  10. long start_3X, long end_4X) {
  11. long arg0K1;
  12. long arg0K0;
  13. long src_6X;
  14. long tgt_5X;
  15. {
  16. arg0K0 = offset_1X;
  17. arg0K1 = start_3X;
  18. goto L18;
  19. }
  20. L18 : {
  21. tgt_5X = arg0K0;
  22. src_6X = arg0K1;
  23. if ((src_6X == end_4X)) {
  24. return;
  25. } else {
  26. *(target_0X + tgt_5X) = (*(source_2X + src_6X));
  27. arg0K0 = (1 + tgt_5X);
  28. arg0K1 = (1 + src_6X);
  29. goto L18;
  30. }
  31. }
  32. }
  33. char *string_append(char *a_7X, char *b_8X) {
  34. char *target_11X;
  35. long len_b_10X;
  36. long len_a_9X;
  37. {
  38. len_a_9X = strlen((char *)a_7X);
  39. len_b_10X = strlen((char *)b_8X);
  40. target_11X = (char *)calloc(1, 1 + (len_a_9X + len_b_10X));
  41. string_copyB(target_11X, 0, a_7X, 0, len_a_9X);
  42. string_copyB(target_11X, len_a_9X, b_8X, 0, len_b_10X);
  43. return target_11X;
  44. }
  45. }
  46. long main(long argc_12X, char **argv_13X) {
  47. FILE *merged_arg2K2;
  48. char *merged_arg1K1;
  49. char *merged_arg1K0;
  50. #ifdef USE_DIRECT_THREADING
  51. void *demo_string_append_return_address;
  52. #else
  53. int demo_string_append_return_tag;
  54. #endif
  55. char demo_string_append0_return_value;
  56. char *a_14X;
  57. char *b_15X;
  58. FILE *out_16X;
  59. char *target_23X;
  60. long len_b_22X;
  61. long len_a_21X;
  62. FILE *out_20X;
  63. char *b_19X;
  64. char *a_18X;
  65. FILE *out_17X;
  66. {
  67. if ((3 == argc_12X)) {
  68. out_17X = stdout;
  69. a_18X = *(argv_13X + 1);
  70. b_19X = *(argv_13X + 2);
  71. merged_arg1K0 = a_18X;
  72. merged_arg1K1 = a_18X;
  73. merged_arg2K2 = out_17X;
  74. #ifdef USE_DIRECT_THREADING
  75. demo_string_append_return_address = &&demo_string_append_return_0;
  76. #else
  77. demo_string_append_return_tag = 0;
  78. #endif
  79. goto demo_string_append;
  80. demo_string_append_return_0:
  81. merged_arg1K0 = a_18X;
  82. merged_arg1K1 = b_19X;
  83. merged_arg2K2 = out_17X;
  84. #ifdef USE_DIRECT_THREADING
  85. demo_string_append_return_address = &&demo_string_append_return_1;
  86. #else
  87. demo_string_append_return_tag = 1;
  88. #endif
  89. goto demo_string_append;
  90. demo_string_append_return_1:
  91. merged_arg1K0 = b_19X;
  92. merged_arg1K1 = b_19X;
  93. merged_arg2K2 = out_17X;
  94. #ifdef USE_DIRECT_THREADING
  95. demo_string_append_return_address = &&demo_string_append_return_2;
  96. #else
  97. demo_string_append_return_tag = 2;
  98. #endif
  99. goto demo_string_append;
  100. demo_string_append_return_2:
  101. return 0;
  102. } else {
  103. out_20X = stderr;
  104. ps_write_string("Usage: ", out_20X);
  105. ps_write_string((*(argv_13X + 0)), out_20X);
  106. ps_write_string(" <string-a> <string-b>", out_20X);
  107. {
  108. long ignoreXX;
  109. PS_WRITE_CHAR(10, out_20X, ignoreXX)
  110. }
  111. ps_write_string(" Prints permutations of <string-a> and <string-b>.",
  112. out_20X);
  113. {
  114. long ignoreXX;
  115. PS_WRITE_CHAR(10, out_20X, ignoreXX)
  116. }
  117. return 1;
  118. }
  119. }
  120. demo_string_append : {
  121. a_14X = merged_arg1K0;
  122. b_15X = merged_arg1K1;
  123. out_16X = merged_arg2K2;
  124. {
  125. len_a_21X = strlen((char *)a_14X);
  126. len_b_22X = strlen((char *)b_15X);
  127. target_23X = (char *)calloc(1, 1 + (len_a_21X + len_b_22X));
  128. string_copyB(target_23X, 0, a_14X, 0, len_a_21X);
  129. string_copyB(target_23X, len_a_21X, b_15X, 0, len_b_22X);
  130. ps_write_string(target_23X, out_16X);
  131. {
  132. long ignoreXX;
  133. PS_WRITE_CHAR(10, out_16X, ignoreXX)
  134. }
  135. free(target_23X);
  136. demo_string_append0_return_value = 1;
  137. #ifdef USE_DIRECT_THREADING
  138. goto *demo_string_append_return_address;
  139. #else
  140. goto demo_string_append_return;
  141. #endif
  142. }
  143. #ifndef USE_DIRECT_THREADING
  144. demo_string_append_return:
  145. switch (demo_string_append_return_tag) {
  146. case 0:
  147. goto demo_string_append_return_0;
  148. case 1:
  149. goto demo_string_append_return_1;
  150. default:
  151. goto demo_string_append_return_2;
  152. }
  153. #endif
  154. }
  155. }