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.
 
 
 
 
 
 

82 line
1.6 KiB

  1. /*
  2. * cacaplay caca file player
  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 <stdio.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <fcntl.h>
  18. #include <unistd.h>
  19. #include <stdlib.h>
  20. #include "cucul.h"
  21. #include "caca.h"
  22. int main(int argc, char **argv)
  23. {
  24. struct stat statbuf;
  25. caca_event_t ev;
  26. cucul_t *qq;
  27. caca_t *kk;
  28. void *buffer;
  29. int fd;
  30. if(argc < 2)
  31. {
  32. fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
  33. return 1;
  34. }
  35. fd = open(argv[1], O_RDONLY);
  36. if(!fd)
  37. {
  38. fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]);
  39. return 1;
  40. }
  41. if(fstat(fd, &statbuf))
  42. {
  43. fprintf(stderr, "%s: could not stat %s.\n", argv[0], argv[1]);
  44. return 1;
  45. }
  46. buffer = malloc(statbuf.st_size);
  47. read(fd, buffer, statbuf.st_size);
  48. qq = cucul_load(buffer, statbuf.st_size);
  49. free(buffer);
  50. if(!qq)
  51. {
  52. fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
  53. return 1;
  54. }
  55. kk = caca_attach(qq);
  56. caca_display(kk);
  57. while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1))
  58. {
  59. if(ev.data.key.c == CACA_KEY_ESCAPE)
  60. break;
  61. }
  62. /* Clean up */
  63. caca_detach(kk);
  64. cucul_free(qq);
  65. return 0;
  66. }