PikaRunExternContral.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Author: lyon
  3. Tencent QQ: 645275593
  4. */
  5. #include "PikaObj.h"
  6. #include <stdarg.h>
  7. #include "BaseObj.h"
  8. #include "PikaBlock.h"
  9. #include "PikaIf.h"
  10. #include "PikaWhile.h"
  11. #include "dataArgs.h"
  12. #include "dataMemory.h"
  13. #include "dataString.h"
  14. #include "dataStrs.h"
  15. int __runExtern_contral(PikaObj* self, char* cmd) {
  16. int isExit = 0;
  17. /* in block */
  18. if (NULL != obj_getArg(self, "_isInBlock")) {
  19. PikaObj* block = obj_getObj(self, "_block", 0);
  20. if (strIsStartWith(cmd, " ")) {
  21. if (strEqu(block_getMode(block), "if")) {
  22. if_pushLine(block, cmd);
  23. isExit = 1;
  24. goto exit;
  25. }
  26. if (strEqu(block_getMode(block), "while")) {
  27. while_pushLine(block, cmd);
  28. isExit = 1;
  29. goto exit;
  30. }
  31. isExit = 1;
  32. goto exit;
  33. }
  34. /* the block is end */
  35. else {
  36. obj_removeArg(self, "_isInBlock");
  37. if (strEqu(block_getMode(block), "if")) {
  38. if_run(block);
  39. }
  40. if (strEqu(block_getMode(block), "while")) {
  41. while_run(block);
  42. }
  43. obj_removeArg(self, "_block");
  44. /* not finished */
  45. }
  46. }
  47. /* if block */
  48. if (strIsStartWith(cmd, "if ")) {
  49. obj_setInt(self, "_isInBlock", 1);
  50. obj_setObjWithoutClass(self, "_block", block_init);
  51. PikaObj* block = obj_getObj(self, "_block", 0);
  52. if_setAssert(block, cmd);
  53. /* this line processed ok */
  54. isExit = 1;
  55. goto exit;
  56. }
  57. /* while block */
  58. if (strIsStartWith(cmd, "while ")) {
  59. obj_setInt(self, "_isInBlock", 1);
  60. obj_setObjWithoutClass(self, "_block", block_init);
  61. PikaObj* block = obj_getObj(self, "_block", 0);
  62. while_setAssert(block, cmd);
  63. /* this line processed ok */
  64. isExit = 1;
  65. goto exit;
  66. }
  67. exit:
  68. return isExit;
  69. }