Ignore:
Timestamp:
Apr 26, 2006, 1:54:26 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Implemented cucul_load_file() and cucul_load_memory() to load respectively a file and a memory area into a libcucul buffer.
  • Changed the cucul_import_canvas() prototype so that it uses libcucul buffers instead of simple memory areas.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/cacaplay.c

    r859 r896  
    1616
    1717#include <stdio.h>
    18 #include <sys/types.h>
    19 #include <sys/stat.h>
    20 #include <fcntl.h>
    21 #include <unistd.h>
    2218#include <stdlib.h>
    2319
     
    2723int main(int argc, char **argv)
    2824{
    29     struct stat statbuf;
    3025    caca_event_t ev;
     26    cucul_buffer_t *b;
    3127    cucul_canvas_t *cv;
    3228    caca_display_t *dp;
    33     void *buffer;
    34     int fd;
    3529
    3630    if(argc < 2)
     
    4034    }
    4135
    42     fd = open(argv[1], O_RDONLY);
    43     if(!fd)
     36    b = cucul_load_file(argv[1]);
     37    if(!b)
    4438    {
    4539        fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]);
     
    4741    }
    4842
    49     if(fstat(fd, &statbuf))
     43    cv = cucul_import_canvas(b, "caca");
     44    if(!cv)
    5045    {
    51         fprintf(stderr, "%s: could not stat %s.\n", argv[0], argv[1]);
     46        fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
     47        cucul_free_buffer(b);
    5248        return 1;
    5349    }
    5450
    55     buffer = malloc(statbuf.st_size);
    56     read(fd, buffer, statbuf.st_size);
    57     cv = cucul_import_canvas(buffer, statbuf.st_size, "caca");
    58     free(buffer);
    59 
    60     if(!cv)
    61     {
    62         fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
    63         return 1;
    64     }
     51    cucul_free_buffer(b);
    6552
    6653    dp = caca_create_display(cv);
Note: See TracChangeset for help on using the changeset viewer.