Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

swallow.c 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * swallow swallow another libcaca application
  3. * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include "common.h"
  15. #if !defined(__KERNEL__)
  16. # include <stdio.h>
  17. # include <string.h>
  18. # include <stdlib.h>
  19. #endif
  20. #include "cucul.h"
  21. #include "caca.h"
  22. int main(int argc, char **argv)
  23. {
  24. char cmd[BUFSIZ];
  25. static cucul_canvas_t *cv, *app;
  26. static caca_display_t *dp;
  27. unsigned char *buf[2];
  28. long int bytes[2], total[2];
  29. FILE *f[2];
  30. int w, h, i;
  31. buf[0] = buf[1] = NULL;
  32. total[0] = total[1] = 0;
  33. if(argc < 3)
  34. return 1;
  35. cv = cucul_create_canvas(0, 0);
  36. app = cucul_create_canvas(0, 0);
  37. w = 38;
  38. h = 26;
  39. dp = caca_create_display(cv);
  40. if(!dp)
  41. return 1;
  42. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  43. cucul_printf(cv, 1, h + 4, "libcaca multiplexer");
  44. for(i = 0; i < 2; i++)
  45. {
  46. sprintf(cmd, "CACA_DRIVER=raw CACA_GEOMETRY=%ix%i %s",
  47. w, h, argv[i + 1]);
  48. f[i] = popen(cmd, "r");
  49. if(!f[i])
  50. return 1;
  51. cucul_printf(cv, 40 * i + 1, 1, "%s", argv[i + 1]);
  52. }
  53. for(;;)
  54. {
  55. caca_event_t ev;
  56. int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0);
  57. if(ret && ev.type & CACA_EVENT_KEY_PRESS)
  58. break;
  59. for(i = 0; i < 2; i++)
  60. {
  61. bytes[i] = cucul_import_memory(app, buf[i], total[i], "caca");
  62. if(bytes[i] > 0)
  63. {
  64. total[i] -= bytes[i];
  65. memmove(buf[i], buf[i] + bytes[i], total[i]);
  66. cucul_blit(cv, 1 + i * (w + 2), 3, app, NULL);
  67. caca_refresh_display(dp);
  68. }
  69. else if(bytes[i] == 0)
  70. {
  71. buf[i] = realloc(buf[i], total[i] + 128);
  72. fread(buf[i] + total[i], 128, 1, f[i]);
  73. total[i] += 128;
  74. }
  75. else
  76. {
  77. fprintf(stderr, "%s: corrupted input\n", argv[0]);
  78. return -1;
  79. }
  80. }
  81. }
  82. /* Clean up */
  83. caca_free_display(dp);
  84. cucul_free_canvas(cv);
  85. cucul_free_canvas(app);
  86. return 0;
  87. }