pcmdwhile.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*+-------------------------------------------------------------------------
  2. pcmdwhile.c - ecu while procedure commands
  3. wht@wht.net
  4. Defined functions:
  5. _pcmd_while_z_nz(param,nz)
  6. pcmd_whilei(param)
  7. pcmd_whilenz(param)
  8. pcmd_whiles(param)
  9. pcmd_whilez(param)
  10. --------------------------------------------------------------------------*/
  11. /*+:EDITS:*/
  12. /*:04-26-2000-11:16-wht@bob-RELEASE 4.42 */
  13. /*:01-24-1997-02:38-wht@yuriatin-SOURCE RELEASE 4.00 */
  14. /*:10-09-1996-21:00-wht@yuriatin-add whilez/whilenz */
  15. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  16. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  17. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  18. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  19. /*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  20. /*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  21. /*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  22. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  23. #include <ctype.h>
  24. #include "ecu.h"
  25. #include "ecuerror.h"
  26. #include "esd.h"
  27. #include "var.h"
  28. #include "procedure.h"
  29. #include "relop.h"
  30. extern PCB *pcb_stack[];
  31. /*+-------------------------------------------------------------------------
  32. _pcmd_while_z_nz(param,nz)
  33. --------------------------------------------------------------------------*/
  34. int
  35. _pcmd_while_z_nz(param,nz)
  36. ESD *param;
  37. int nz; /* if nz==1 whilenz, ==0 whilez */
  38. {
  39. int erc;
  40. long truth;
  41. PCB *pcb;
  42. LCB *condition_lcb;
  43. int condition_index = param->index;
  44. if (!proc_level)
  45. return (eNotExecutingProc);
  46. pcb = pcb_stack[proc_level - 1];
  47. condition_lcb = pcb->current;
  48. REPEAT_WHILE:
  49. if (erc = gint(param, &truth))
  50. return (erc);
  51. truth = !!truth;
  52. if(!nz)
  53. truth = !truth;
  54. /* if end of command, execute frame */
  55. if (end_of_cmd(param))
  56. {
  57. if (erc = execute_frame(truth))
  58. {
  59. if (erc == eContinueCommand)
  60. goto CONTINUE;
  61. if (erc == eBreakCommand)
  62. erc = 0;
  63. return (erc);
  64. }
  65. }
  66. else if (truth)
  67. {
  68. if (erc = execute_esd(param))
  69. return (erc);
  70. }
  71. /* repeat if indicated */
  72. CONTINUE:
  73. if (truth)
  74. {
  75. pcb->current = condition_lcb;
  76. param->index = param->old_index = condition_index;
  77. goto REPEAT_WHILE;
  78. }
  79. return (0);
  80. } /* end of _pcmd_while_z_nz */
  81. /*+-------------------------------------------------------------------------
  82. pcmd_whilenz(param)
  83. --------------------------------------------------------------------------*/
  84. int
  85. pcmd_whilenz(param)
  86. ESD *param;
  87. {
  88. return(_pcmd_while_z_nz(param,1));
  89. } /* end of pcmd_whilenz */
  90. /*+-------------------------------------------------------------------------
  91. pcmd_whilez(param)
  92. --------------------------------------------------------------------------*/
  93. int
  94. pcmd_whilez(param)
  95. ESD *param;
  96. {
  97. return(_pcmd_while_z_nz(param,0));
  98. } /* end of pcmd_whilez */
  99. /*+-------------------------------------------------------------------------
  100. pcmd_whilei(param)
  101. --------------------------------------------------------------------------*/
  102. int
  103. pcmd_whilei(param)
  104. ESD *param;
  105. {
  106. int erc;
  107. int truth;
  108. PCB *pcb;
  109. LCB *condition_lcb;
  110. int condition_index = param->index;
  111. if (!proc_level)
  112. return (eNotExecutingProc);
  113. pcb = pcb_stack[proc_level - 1];
  114. condition_lcb = pcb->current;
  115. REPEAT_WHILE:
  116. if (erc = get_truth_int(param, &truth))
  117. return (erc);
  118. /* if end of command, execute frame */
  119. if (end_of_cmd(param))
  120. {
  121. if (erc = execute_frame(truth))
  122. {
  123. if (erc == eContinueCommand)
  124. goto CONTINUE;
  125. if (erc == eBreakCommand)
  126. erc = 0;
  127. return (erc);
  128. }
  129. }
  130. else if (truth)
  131. {
  132. if (erc = execute_esd(param))
  133. return (erc);
  134. }
  135. /* repeat if indicated */
  136. CONTINUE:
  137. if (truth)
  138. {
  139. pcb->current = condition_lcb;
  140. param->index = param->old_index = condition_index;
  141. goto REPEAT_WHILE;
  142. }
  143. return (0);
  144. } /* end of pcmd_whilei */
  145. /*+-------------------------------------------------------------------------
  146. pcmd_whiles(param)
  147. --------------------------------------------------------------------------*/
  148. int
  149. pcmd_whiles(param)
  150. ESD *param;
  151. {
  152. int erc;
  153. int truth;
  154. PCB *pcb;
  155. LCB *condition_lcb;
  156. int condition_index = param->index;
  157. if (!proc_level)
  158. return (eNotExecutingProc);
  159. pcb = pcb_stack[proc_level - 1];
  160. condition_lcb = pcb->current;
  161. REPEAT_WHILE:
  162. if (erc = get_truth_str(param, &truth))
  163. return (erc);
  164. /* if end of command, execute frame */
  165. if (end_of_cmd(param))
  166. {
  167. if (erc = execute_frame(truth))
  168. {
  169. if (erc == eContinueCommand)
  170. goto CONTINUE;
  171. if (erc == eBreakCommand)
  172. erc = 0;
  173. return (erc);
  174. }
  175. }
  176. else if (truth)
  177. {
  178. if (erc = execute_esd(param))
  179. return (erc);
  180. }
  181. /* repeat if indicated */
  182. CONTINUE:
  183. if (truth)
  184. {
  185. pcb->current = condition_lcb;
  186. param->index = param->old_index = condition_index;
  187. goto REPEAT_WHILE;
  188. }
  189. return (0);
  190. } /* end of pcmd_whiles */
  191. /* vi: set tabstop=4 shiftwidth=4: */
  192. /* end of pcmdwhile.c */