sshcr.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Coroutine mechanics used in PuTTY's SSH code.
  3. */
  4. #ifndef PUTTY_SSHCR_H
  5. #define PUTTY_SSHCR_H
  6. /*
  7. * If these macros look impenetrable to you, you might find it helpful
  8. * to read
  9. *
  10. * https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
  11. *
  12. * which explains the theory behind these macros.
  13. *
  14. * In particular, if you are getting `case expression not constant'
  15. * errors when building with MS Visual Studio, this is because MS's
  16. * Edit and Continue debugging feature causes their compiler to
  17. * violate ANSI C. To disable Edit and Continue debugging:
  18. *
  19. * - right-click ssh.c in the FileView
  20. * - click Settings
  21. * - select the C/C++ tab and the General category
  22. * - under `Debug info:', select anything _other_ than `Program
  23. * Database for Edit and Continue'.
  24. */
  25. #define crBegin(v) { int *crLine = &v; switch(v) { case 0:;
  26. #define crBeginState crBegin(s->crLine)
  27. #define crStateP(t, v) \
  28. struct t *s; \
  29. if (!(v)) { s = (v) = snew(struct t); s->crLine = 0; } \
  30. s = (v);
  31. #define crState(t) crStateP(t, ssh->t)
  32. #define crFinish(z) } *crLine = 0; return (z); }
  33. #define crFinishV } *crLine = 0; return; }
  34. #define crFinishFree(z) } sfree(s); return (z); }
  35. #define crFinishFreeV } sfree(s); return; }
  36. #define crReturn(z) \
  37. do {\
  38. *crLine =__LINE__; return (z); case __LINE__:;\
  39. } while (0)
  40. #define crReturnV \
  41. do {\
  42. *crLine=__LINE__; return; case __LINE__:;\
  43. } while (0)
  44. #define crStop(z) do{ *crLine = 0; return (z); }while(0)
  45. #define crStopV do{ *crLine = 0; return; }while(0)
  46. #define crWaitUntil(c) do { crReturn(0); } while (!(c))
  47. #define crWaitUntilV(c) do { crReturnV; } while (!(c))
  48. #define crMaybeWaitUntil(c) do { while (!(c)) crReturn(0); } while (0)
  49. #define crMaybeWaitUntilV(c) do { while (!(c)) crReturnV; } while (0)
  50. #endif /* PUTTY_SSHCR_H */