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.
 
 
 
 
 
 

110 lignes
2.7 KiB

  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[4];
  28. long int bytes[4], total[4];
  29. FILE *f[4];
  30. int w, h, i;
  31. if(argc < 5)
  32. {
  33. fprintf(stderr, "usage: %s <cmd1> <cmd2> <cmd3> <cmd4>\n", argv[0]);
  34. return 1;
  35. }
  36. cv = cucul_create_canvas(0, 0);
  37. app = cucul_create_canvas(0, 0);
  38. w = 38;
  39. h = 13;
  40. dp = caca_create_display(cv);
  41. if(!dp)
  42. return 1;
  43. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  44. cucul_draw_line(cv, 0, 0, 80, 0, ' ');
  45. cucul_printf(cv, 30, 0, "libcaca multiplexer");
  46. for(i = 0; i < 4; i++)
  47. {
  48. buf[i] = NULL;
  49. total[i] = bytes[i] = 0;
  50. sprintf(cmd, "CACA_DRIVER=raw CACA_GEOMETRY=%ix%i %s",
  51. w, h, argv[i + 1]);
  52. f[i] = popen(cmd, "r");
  53. if(!f[i])
  54. return 1;
  55. cucul_printf(cv, 40 * (i / 2) + 1,
  56. (h + 2) * (i % 2) + h + 2, "%s", argv[i + 1]);
  57. }
  58. for(;;)
  59. {
  60. caca_event_t ev;
  61. int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0);
  62. if(ret && ev.type & CACA_EVENT_KEY_PRESS)
  63. break;
  64. for(i = 0; i < 4; i++)
  65. {
  66. bytes[i] = cucul_import_memory(app, buf[i], total[i], "caca");
  67. if(bytes[i] > 0)
  68. {
  69. total[i] -= bytes[i];
  70. memmove(buf[i], buf[i] + bytes[i], total[i]);
  71. cucul_blit(cv, 1 + (i / 2) * (w + 2),
  72. (h + 2) * (i % 2) + 2, app, NULL);
  73. caca_refresh_display(dp);
  74. }
  75. else if(bytes[i] == 0)
  76. {
  77. buf[i] = realloc(buf[i], total[i] + 128);
  78. fread(buf[i] + total[i], 128, 1, f[i]);
  79. total[i] += 128;
  80. }
  81. else
  82. {
  83. fprintf(stderr, "%s: corrupted input %i\n", argv[0], i);
  84. return -1;
  85. }
  86. }
  87. }
  88. /* Clean up */
  89. caca_free_display(dp);
  90. cucul_free_canvas(cv);
  91. cucul_free_canvas(app);
  92. return 0;
  93. }