/vendor/gc/include/ec.h

http://github.com/feyeleanor/RubyGoLightly · C++ Header · 70 lines · 25 code · 11 blank · 34 comment · 2 complexity · b1d9c432f2e6709f4eed702f26126ac1 MD5 · raw file

  1. # ifndef EC_H
  2. # define EC_H
  3. # ifndef CORD_H
  4. # include "cord.h"
  5. # endif
  6. /* Extensible cords are strings that may be destructively appended to. */
  7. /* They allow fast construction of cords from characters that are */
  8. /* being read from a stream. */
  9. /*
  10. * A client might look like:
  11. *
  12. * {
  13. * CORD_ec x;
  14. * CORD result;
  15. * char c;
  16. * FILE *f;
  17. *
  18. * ...
  19. * CORD_ec_init(x);
  20. * while(...) {
  21. * c = getc(f);
  22. * ...
  23. * CORD_ec_append(x, c);
  24. * }
  25. * result = CORD_balance(CORD_ec_to_cord(x));
  26. *
  27. * If a C string is desired as the final result, the call to CORD_balance
  28. * may be replaced by a call to CORD_to_char_star.
  29. */
  30. # ifndef CORD_BUFSZ
  31. # define CORD_BUFSZ 128
  32. # endif
  33. typedef struct CORD_ec_struct {
  34. CORD ec_cord;
  35. char * ec_bufptr;
  36. char ec_buf[CORD_BUFSZ+1];
  37. } CORD_ec[1];
  38. /* This structure represents the concatenation of ec_cord with */
  39. /* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */
  40. /* Flush the buffer part of the extended chord into ec_cord. */
  41. /* Note that this is almost the only real function, and it is */
  42. /* implemented in 6 lines in cordxtra.c */
  43. void CORD_ec_flush_buf(CORD_ec x);
  44. /* Convert an extensible cord to a cord. */
  45. # define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord)
  46. /* Initialize an extensible cord. */
  47. # define CORD_ec_init(x) ((x)[0].ec_cord = 0, (x)[0].ec_bufptr = (x)[0].ec_buf)
  48. /* Append a character to an extensible cord. */
  49. # define CORD_ec_append(x, c) \
  50. { \
  51. if ((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ) { \
  52. CORD_ec_flush_buf(x); \
  53. } \
  54. *((x)[0].ec_bufptr)++ = (c); \
  55. }
  56. /* Append a cord to an extensible cord. Structure remains shared with */
  57. /* original. */
  58. void CORD_ec_append_cord(CORD_ec x, CORD s);
  59. # endif /* EC_H */