- Timestamp:
- Nov 12, 2006, 10:48:37 AM (16 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/doc/cacaplay.1
r1328 r1352 13 13 .B "raw" 14 14 and storing the program's standard output. 15 .SH EXAMPLE 15 16 If no file argument is provided or '\-' is used, 17 .B cacaplay 18 will read its data from the standard input. 19 .SH EXAMPLES 16 20 cacaplay file.caca 17 .SH BUGS 18 As of now, 19 .B cacaplay 20 can only play single-image canvases, rendering it pretty useless. See 21 .B cacaserver 22 for a more usable alternative. 21 22 CACA_DRIVER=raw CACA_GEOMETRY=80x32 cacademo | cacaplay 23 23 .SH SEE ALSO 24 24 cacaserver(1) -
libcaca/trunk/src/cacaplay.c
r1308 r1352 16 16 17 17 #if !defined(__KERNEL__) 18 #include <stdio.h> 19 #include <stdlib.h> 18 # include <stdio.h> 19 # include <stdlib.h> 20 # include <sys/types.h> 21 # include <sys/stat.h> 22 # include <fcntl.h> 23 # include <string.h> 24 # include <unistd.h> 20 25 #endif 21 26 … … 25 30 int main(int argc, char **argv) 26 31 { 27 caca_event_t ev; 28 cucul_canvas_t *cv; 32 cucul_canvas_t *cv, *app; 29 33 caca_display_t *dp; 34 unsigned char *buf = NULL; 35 long int bytes, total = 0; 36 int fd; 30 37 31 if(argc < 2 )38 if(argc < 2 || !strcmp(argv[1], "-")) 32 39 { 33 fprintf(stderr, "%s: missing argument (filename).\n", argv[0]); 34 return 1; 40 fd = 0; /* use stdin */ 41 } 42 else 43 { 44 fd = open(argv[1], O_RDONLY); 45 if(fd < 0) 46 { 47 fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); 48 return 1; 49 } 35 50 } 36 51 37 52 cv = cucul_create_canvas(0, 0); 38 if(cucul_import_file(cv, argv[1], "caca") < 0) 39 { 40 fprintf(stderr, "%s: could not import file %s.\n", argv[0], argv[1]); 41 return 1; 42 } 53 app = cucul_create_canvas(0, 0); 43 54 44 55 dp = caca_create_display(cv); 45 56 46 caca_refresh_display(dp); 57 for(;;) 58 { 59 caca_event_t ev; 60 int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0); 47 61 48 while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1)) 49 { 50 if(ev.data.key.ch == CACA_KEY_ESCAPE) 62 if(ret && ev.type & CACA_EVENT_KEY_PRESS) 51 63 break; 64 65 bytes = cucul_import_memory(app, buf, total, "caca"); 66 67 if(bytes > 0) 68 { 69 total -= bytes; 70 memmove(buf, buf + bytes, total); 71 72 cucul_blit(cv, 0, 0, app, NULL); 73 caca_refresh_display(dp); 74 } 75 else if(bytes == 0) 76 { 77 ssize_t n; 78 buf = realloc(buf, total + 128); 79 n = read(fd, buf + total, 128); 80 if(n < 0) 81 { 82 fprintf(stderr, "%s: read error\n", argv[0]); 83 return -1; 84 } 85 total += n; 86 } 87 else /* bytes < 0 */ 88 { 89 fprintf(stderr, "%s: corrupted caca file\n", argv[0]); 90 return -1; 91 } 52 92 } 53 93 54 94 /* Clean up */ 95 close(fd); 96 55 97 caca_free_display(dp); 56 98 cucul_free_canvas(cv);
Note: See TracChangeset
for help on using the changeset viewer.