view README.md @ 12:0cc2555db371

*: make our string functions not stupid strncat() made everything slow! new addition internally: an EDL_header structure to make things not stupid. if we were using C++ it wouldn't really be necessary, but alas :)
author Paper <paper@paper.us.eu.org>
date Wed, 27 Mar 2024 13:38:30 -0400
parents 0c98b46eaf73
children
line wrap: on
line source

# libedl
libedl is a library for parsing Vegas Pro EDL files and translating them into usable C structures.

## Build
```console
$ autoreconf -i
$ mkdir build
$ cd build
$ ../configure
$ make
$ sudo make install
```

## Example
```c
#include <stdio.h>
#include <stdlib.h>

#include <edl.h>

int file_get_contents(const char* f, char** contents, long* size) {
    /* open the file */
    FILE* file = fopen(f, "rb");
    if (!file)
        return 1;

    /* get filesize */
    fseek(file, 0L, SEEK_END);
    *size = ftell(file);
    fseek(file, 0L, SEEK_SET);

    /* grab the contents */
    *contents = malloc(*size + 1);
    if (!*contents)
        return 1;

    /* hope and pray that `char` is 8-bit */
    fread(*contents, *size, 1, file);

    (*contents)[*size] = '\0';

    fclose(file);
}

int main(int argc, char** argv) {
    char* data = NULL;
    long size = 0;
    EDL edl = {0};

    if (argc != 2)
        return 1;

    if (file_get_contents(argv[1], &data, &size))
        return 1;

    /* if you know the amount of lines beforehand,
     * you can preallocate the memory for libedl to use */
    EDL_reallocate(&edl, 1024);

    /* pass the file data to libedl
     *
     * it is also perfectly valid to use mmap() or
     * variations of it (ex MapViewOfFile()) here... */
    EDL_parse(&edl, data, size + 1);

    /* dump the data to a valid EDL string */
    char* edl_str = EDL_dump(&edl);
    printf("%s\n", edl_str);
    free(edl_str);

    /* free our used memory; libedl allocates on the heap */
    EDL_free(&edl);
    free(data);

    return 0;
}
```