comparison 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
comparison
equal deleted inserted replaced
7:fee08fa622e1 8:0c98b46eaf73
9 $ ../configure 9 $ ../configure
10 $ make 10 $ make
11 $ sudo make install 11 $ sudo make install
12 ``` 12 ```
13 13
14 ## Usage 14 ## Example
15 ```c 15 ```c
16 #include <stdio.h> 16 #include <stdio.h>
17 #include <stdlib.h> 17 #include <stdlib.h>
18 #include "edl.h"
19 18
20 int main() { 19 #include <edl.h>
20
21 int file_get_contents(const char* file, char** contents, long* size) {
21 /* open the file */ 22 /* open the file */
22 FILE* file = fopen("MyProject.TXT", "rb"); 23 FILE* file = fopen(file, "rb");
23 if (!file) 24 if (!file)
24 return 1; 25 return 1;
25 26
26 /* get filesize */ 27 /* get filesize */
27 fseek(file, 0L, SEEK_END); 28 fseek(file, 0L, SEEK_END);
28 long fsize = ftell(file); 29 *size = ftell(file);
29 fseek(file, 0L, SEEK_SET); 30 fseek(file, 0L, SEEK_SET);
30 31
31 /* grab the contents */ 32 /* grab the contents */
32 char* data = malloc(fsize + 1); 33 *contents = malloc(*size + 1);
33 if (!data) 34 if (!*contents)
34 return 1; 35 return 1;
35 36
36 fread(data, fsize, 1, file); 37 /* hope and pray that `char` is 8-bit */
38 fread(*contents, *size, 1, file);
37 39
38 data[fsize] = '\0'; 40 data[*size] = '\0';
39 41
40 fclose(file); 42 fclose(file);
43 }
41 44
42 /* pass it to libedl */ 45 int main(int argc, char** argv) {
43 EDL edl = EDL_parse(data, fsize + 1); 46 char* data = NULL;
47 long size = 0;
48 EDL edl = {0};
44 49
45 /* dump the EDL to a string */ 50 if (argc != 2)
46 char* edl_str = EDL_dump(edl); 51 return 1;
52
53 if (file_get_contents(argv[1], &data, &size))
54 return 1;
55
56 /* if you know the amount of lines beforehand,
57 * you can preallocate the memory for libedl to use */
58 EDL_reallocate(&edl, 1024);
59
60 /* pass the file data to libedl
61 *
62 * it is also perfectly valid to use mmap() or
63 * variations of it (ex MapViewOfFile()) here... */
64 EDL_parse(&edl, data, fsize + 1);
65
66 /* dump the data to a valid EDL string */
67 char* edl_str = EDL_dump(&edl);
47 printf("%s\n", edl_str); 68 printf("%s\n", edl_str);
48 free(edl_str); 69 free(edl_str);
49 70
50 /* free our memory */ 71 /* free our used memory; libedl allocates on the heap */
51 EDL_free(edl); 72 EDL_free(&edl);
52 free(data); 73 free(data);
53 74
54 return 0; 75 return 0;
55 } 76 }
56 ``` 77 ```