seat_dialog_text.c 991 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Helper routines for dealing with SeatDialogText structures.
  3. */
  4. #include <stdarg.h>
  5. #include "putty.h"
  6. SeatDialogText *seat_dialog_text_new(void)
  7. {
  8. SeatDialogText *sdt = snew(SeatDialogText);
  9. sdt->nitems = sdt->itemsize = 0;
  10. sdt->items = NULL;
  11. return sdt;
  12. }
  13. void seat_dialog_text_free(SeatDialogText *sdt)
  14. {
  15. for (size_t i = 0; i < sdt->nitems; i++)
  16. sfree(sdt->items[i].text);
  17. sfree(sdt->items);
  18. sfree(sdt);
  19. }
  20. static void seat_dialog_text_append_v(
  21. SeatDialogText *sdt, SeatDialogTextType type, const char *fmt, va_list ap)
  22. {
  23. sgrowarray(sdt->items, sdt->itemsize, sdt->nitems);
  24. SeatDialogTextItem *item = &sdt->items[sdt->nitems++];
  25. item->type = type;
  26. item->text = dupvprintf(fmt, ap);
  27. }
  28. void seat_dialog_text_append(SeatDialogText *sdt, SeatDialogTextType type,
  29. const char *fmt, ...)
  30. {
  31. va_list ap;
  32. va_start(ap, fmt);
  33. seat_dialog_text_append_v(sdt, type, fmt, ap);
  34. va_end(ap);
  35. }