procframe.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*+-------------------------------------------------------------------------
  2. procframe.c - execute frame of procedure statements
  3. wht@wht.net
  4. Defined functions:
  5. execute_frame(truth)
  6. pcmd_break()
  7. pcmd_continue()
  8. --------------------------------------------------------------------------*/
  9. /*+:EDITS:*/
  10. /*:04-26-2000-11:16-wht@bob-RELEASE 4.42 */
  11. /*:01-24-1997-02:38-wht@yuriatin-SOURCE RELEASE 4.00 */
  12. /*:09-11-1996-20:01-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  13. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  14. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  15. /*:05-04-1994-04:40-wht@n4hgf-ECU release 3.30 */
  16. /*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  17. /*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  18. /*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  19. /*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  20. #include <ctype.h>
  21. #include "ecu.h"
  22. #include "ecukey.h"
  23. #include "ecuerror.h"
  24. #include "esd.h"
  25. #include "var.h"
  26. #include "procedure.h"
  27. extern PCB *pcb_stack[PROC_STACK_MAX];
  28. /*+-------------------------------------------------------------------------
  29. pcmd_break()
  30. --------------------------------------------------------------------------*/
  31. int
  32. pcmd_break()
  33. {
  34. return (eBreakCommand);
  35. } /* end of pcmd_break */
  36. /*+-------------------------------------------------------------------------
  37. pcmd_continue()
  38. --------------------------------------------------------------------------*/
  39. int
  40. pcmd_continue()
  41. {
  42. return (eContinueCommand);
  43. } /* end of pcmd_continue */
  44. /*+-------------------------------------------------------------------------
  45. execute_frame(truth)
  46. pcb_stack[proc_level - 1]->current points to lcb behind frame: one
  47. statement or { statements }
  48. if truth true, execute frame, else skip it
  49. --------------------------------------------------------------------------*/
  50. int
  51. execute_frame(truth)
  52. int truth;
  53. {
  54. int itmp;
  55. int erc = 0;
  56. PCB *pcb = pcb_stack[proc_level - 1];
  57. LCB *original_lcb = pcb->current;
  58. LCB *begin_lcb;
  59. ESD *text;
  60. int nest_level = 0;
  61. int remember_break = 0;
  62. extern int proc_interrupt;
  63. if (!(pcb->current = pcb->current->next))
  64. {
  65. pcb->current = original_lcb;
  66. return (eNoFrame);
  67. }
  68. text = pcb->current->text;
  69. text->old_index = text->index = 0;
  70. if (*text->pb != SPACE) /* tabs were converted to spaces at read time */
  71. return (eLabelInvalidHere);
  72. skip_cmd_break(text);
  73. /* handle single statement frame */
  74. if (*(text->pb + text->index) != '{')
  75. {
  76. itmp = text->cb - text->index;
  77. if (((itmp > 2) && !strncmp(text->pb + text->index, "if", 2)))
  78. {
  79. pputs("command must appear inside {} or on same line as else\n");
  80. erc = eFATAL_ALREADY;
  81. }
  82. else if (((itmp > 5) && !strncmp(text->pb + text->index, "while", 5)))
  83. {
  84. pputs("command must appear inside {} within this context\n");
  85. erc = eFATAL_ALREADY;
  86. }
  87. else if (truth)
  88. {
  89. trace_proc_cmd(pcb);
  90. erc = execute_esd(text);
  91. }
  92. return (erc);
  93. }
  94. /* we've got a {} frame */
  95. begin_lcb = pcb->current;
  96. pcb->current = pcb->current->next;
  97. while (pcb->current)
  98. {
  99. if (proc_interrupt)
  100. return (eCONINT);
  101. text = pcb->current->text;
  102. text->old_index = text->index = 0;
  103. if (*text->pb != SPACE) /* tabs were converted to spaces at read
  104. * time */
  105. return (eLabelInvalidHere);
  106. skip_cmd_break(text);
  107. if (*(text->pb + text->index) == '}')
  108. {
  109. if (!nest_level)
  110. {
  111. text->index = text->cb;
  112. if (remember_break)
  113. return (eBreakCommand);
  114. return (0);
  115. }
  116. nest_level--;
  117. }
  118. else if (truth)
  119. {
  120. trace_proc_cmd(pcb);
  121. if (erc = execute_esd(text))
  122. {
  123. if (erc != eBreakCommand)
  124. return (erc);
  125. remember_break = 1;
  126. truth = 0;
  127. }
  128. }
  129. else if (*(text->pb + text->index) == '{')
  130. nest_level++;
  131. pcb->current = pcb->current->next;
  132. }
  133. pcb->current = begin_lcb;
  134. return (eNoCloseFrame);
  135. } /* end of execute_frame */
  136. /* vi: set tabstop=4 shiftwidth=4: */
  137. /* end of procframe.c */