Mercurial > libedl
diff README.md @ 8:0c98b46eaf73 v2.0
*: update API to 2.0, big changes
all APIs now use pointers to an EDL object. it is up to the
user to make sure that the pointer is valid.
additionally, many things have been separated into new files
to make it easier to digest
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 03 Mar 2024 17:56:58 -0500 |
parents | a6ab6d9c0dac |
children | 0cc2555db371 |
line wrap: on
line diff
--- a/README.md Mon Jan 15 06:42:30 2024 -0500 +++ b/README.md Sun Mar 03 17:56:58 2024 -0500 @@ -11,44 +11,65 @@ $ sudo make install ``` -## Usage +## Example ```c #include <stdio.h> #include <stdlib.h> -#include "edl.h" + +#include <edl.h> -int main() { +int file_get_contents(const char* file, char** contents, long* size) { /* open the file */ - FILE* file = fopen("MyProject.TXT", "rb"); + FILE* file = fopen(file, "rb"); if (!file) return 1; /* get filesize */ fseek(file, 0L, SEEK_END); - long fsize = ftell(file); + *size = ftell(file); fseek(file, 0L, SEEK_SET); /* grab the contents */ - char* data = malloc(fsize + 1); - if (!data) + *contents = malloc(*size + 1); + if (!*contents) return 1; - fread(data, fsize, 1, file); + /* hope and pray that `char` is 8-bit */ + fread(*contents, *size, 1, file); - data[fsize] = '\0'; + data[*size] = '\0'; fclose(file); +} - /* pass it to libedl */ - EDL edl = EDL_parse(data, fsize + 1); +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; - /* dump the EDL to a string */ - char* edl_str = EDL_dump(edl); + /* 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, fsize + 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 memory */ - EDL_free(edl); + /* free our used memory; libedl allocates on the heap */ + EDL_free(&edl); free(data); return 0;