You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

67 lines
1.7 KiB

  1. /*
  2. * neercs console-based window manager
  3. * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
  4. * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * 2008-2010 Pascal Terjan <pterjan@linuxfr.org>
  6. * All Rights Reserved
  7. *
  8. * This program is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://www.wtfpl.net/ for more details.
  13. */
  14. #if defined HAVE_CONFIG_H
  15. # include "config.h"
  16. #endif
  17. #include <caca.h>
  18. #include <errno.h>
  19. #include <string.h>
  20. #include <sys/stat.h>
  21. #include "neercs.h"
  22. void dump_to_file(struct screen_list *screen_list)
  23. {
  24. char filename[14] = "hardcopy.0";
  25. int n = 0;
  26. struct stat bufstat;
  27. void * export;
  28. size_t len, wrote;
  29. FILE * out;
  30. /* FIXME maybe use glob and get next one directly */
  31. while (n<9999 && !stat(filename, &bufstat))
  32. {
  33. n++;
  34. sprintf(&filename[9], "%d", n);
  35. }
  36. if (n>=9999)
  37. {
  38. debug("Too many hardcopy files in current directory\n");
  39. return;
  40. }
  41. export = caca_export_canvas_to_memory(screen_list->cv, "ansi", &len);
  42. if (!export)
  43. {
  44. debug("Failed to export to ansi\n");
  45. return;
  46. }
  47. out = fopen(filename, "w");
  48. if (!out)
  49. {
  50. debug("Failed to open output file %s: %s\n", filename, strerror(errno));
  51. return;
  52. }
  53. wrote = fwrite(export, len, 1, out);
  54. if (!wrote)
  55. {
  56. debug("Failed to write to output file: %s\n", strerror(errno));
  57. return;
  58. }
  59. free(export);
  60. }