hmmlib2 2.0.10: Rename annotation to timestamp

This commit is contained in:
Matt Mascarenhas 2021-05-30 18:42:02 +01:00
parent b20192e445
commit 65fe93fb57
1 changed files with 32 additions and 32 deletions

View File

@ -86,7 +86,7 @@ typedef struct {
size_t marker_count; size_t marker_count;
HMML_Quote quote; HMML_Quote quote;
} HMML_Annotation; } HMML_Timestamp;
typedef struct { typedef struct {
int line; int line;
@ -97,8 +97,8 @@ typedef struct {
typedef struct { typedef struct {
_Bool well_formed; _Bool well_formed;
HMML_VideoMetaData metadata; HMML_VideoMetaData metadata;
HMML_Annotation* annotations; HMML_Timestamp* timestamps;
size_t annotation_count; size_t timestamp_count;
HMML_Error error; HMML_Error error;
void* free_list; // implementation detail void* free_list; // implementation detail
} HMML_Output; } HMML_Output;
@ -467,7 +467,7 @@ next_attr:
return ref; return ref;
} }
static void _hmml_parse_timecode(struct _hmml_parser* p, HMML_Annotation* anno) static void _hmml_parse_timecode(struct _hmml_parser* p, HMML_Timestamp* ts)
{ {
unsigned int h = 0, m = 0, s = 0; unsigned int h = 0, m = 0, s = 0;
int offset = 0; int offset = 0;
@ -507,16 +507,16 @@ static void _hmml_parse_timecode(struct _hmml_parser* p, HMML_Annotation* anno)
_hmml_err(p, "Minutes cannot exceed 59"); _hmml_err(p, "Minutes cannot exceed 59");
} }
anno->h = h; ts->h = h;
anno->m = m; ts->m = m;
anno->s = s; ts->s = s;
} }
static void _hmml_store_marker(struct _hmml_parser* p, HMML_Annotation* anno, char** out, char* text_mem, size_t text_mem_size) static void _hmml_store_marker(struct _hmml_parser* p, HMML_Timestamp* ts, char** out, char* text_mem, size_t text_mem_size)
{ {
HMML_Marker m = _hmml_parse_marker(p); HMML_Marker m = _hmml_parse_marker(p);
m.offset = (*out) - text_mem; m.offset = (*out) - text_mem;
_hmml_persist_array(p, &anno->markers, &anno->marker_count, m); _hmml_persist_array(p, &ts->markers, &ts->marker_count, m);
const char* marker_text = m.parameter const char* marker_text = m.parameter
? m.parameter ? m.parameter
@ -531,7 +531,7 @@ static void _hmml_store_marker(struct _hmml_parser* p, HMML_Annotation* anno, ch
*out += text_len; *out += text_len;
} }
static size_t _hmml_parse_text(struct _hmml_parser* p, HMML_Annotation* anno) static size_t _hmml_parse_text(struct _hmml_parser* p, HMML_Timestamp* ts)
{ {
static char text_mem[4096]; static char text_mem[4096];
char* out = text_mem; char* out = text_mem;
@ -579,9 +579,9 @@ static size_t _hmml_parse_text(struct _hmml_parser* p, HMML_Annotation* anno)
p->cursor += 4; p->cursor += 4;
HMML_Reference ref = _hmml_parse_ref(p); HMML_Reference ref = _hmml_parse_ref(p);
ref.offset = out - text_mem; ref.offset = out - text_mem;
_hmml_persist_array(p, &anno->references, &anno->reference_count, ref); _hmml_persist_array(p, &ts->references, &ts->reference_count, ref);
} else { } else {
_hmml_store_marker(p, anno, &out, text_mem, sizeof(text_mem)); _hmml_store_marker(p, ts, &out, text_mem, sizeof(text_mem));
} }
} }
@ -593,7 +593,7 @@ static size_t _hmml_parse_text(struct _hmml_parser* p, HMML_Annotation* anno)
*out++ = c; *out++ = c;
++p->cursor; ++p->cursor;
} else { } else {
_hmml_store_marker(p, anno, &out, text_mem, sizeof(text_mem)); _hmml_store_marker(p, ts, &out, text_mem, sizeof(text_mem));
} }
} }
@ -609,24 +609,24 @@ static size_t _hmml_parse_text(struct _hmml_parser* p, HMML_Annotation* anno)
} }
size_t text_size = out - text_mem; size_t text_size = out - text_mem;
anno->text = _hmml_persist_str(p, (struct _hmml_str){ text_mem, text_size }); ts->text = _hmml_persist_str(p, (struct _hmml_str){ text_mem, text_size });
return text_size; return text_size;
} }
static void _hmml_parse_quote(struct _hmml_parser* p, HMML_Annotation* anno) static void _hmml_parse_quote(struct _hmml_parser* p, HMML_Timestamp* ts)
{ {
char member[256]; char member[256];
int id; int id;
int off = 0; int off = 0;
if(sscanf(p->cursor, "[quote %255s %d]%n", member, &id, &off) == 2 && off) { if(sscanf(p->cursor, "[quote %255s %d]%n", member, &id, &off) == 2 && off) {
anno->quote.present = 1; ts->quote.present = 1;
anno->quote.id = id; ts->quote.id = id;
anno->quote.author = _hmml_persist_str(p, (struct _hmml_str){ member, strlen(member) }); ts->quote.author = _hmml_persist_str(p, (struct _hmml_str){ member, strlen(member) });
} else if(sscanf(p->cursor, "[quote %d]%n", &id, &off) == 1 && off) { } else if(sscanf(p->cursor, "[quote %d]%n", &id, &off) == 1 && off) {
anno->quote.present = 1; ts->quote.present = 1;
anno->quote.id = id; ts->quote.id = id;
} else { } else {
_hmml_err(p, "Unable to parse quote"); _hmml_err(p, "Unable to parse quote");
} }
@ -634,7 +634,7 @@ static void _hmml_parse_quote(struct _hmml_parser* p, HMML_Annotation* anno)
p->cursor += off; p->cursor += off;
} }
static void _hmml_parse_annotations(struct _hmml_parser* p) static void _hmml_parse_timestamps(struct _hmml_parser* p)
{ {
for(;;) { for(;;) {
_hmml_skip_ws(p); _hmml_skip_ws(p);
@ -647,11 +647,11 @@ static void _hmml_parse_annotations(struct _hmml_parser* p)
break; break;
} }
HMML_Annotation anno = { HMML_Timestamp ts = {
.line = p->line .line = p->line
}; };
_hmml_parse_timecode(p, &anno); _hmml_parse_timecode(p, &ts);
if(*p->cursor != '[') { if(*p->cursor != '[') {
_hmml_err(p, "Expected '['"); _hmml_err(p, "Expected '['");
@ -659,18 +659,18 @@ static void _hmml_parse_annotations(struct _hmml_parser* p)
if(p->cursor[1] == '@') { if(p->cursor[1] == '@') {
HMML_Marker m = _hmml_parse_marker(p); HMML_Marker m = _hmml_parse_marker(p);
anno.author = m.marker; ts.author = m.marker;
} }
++p->cursor; ++p->cursor;
int text_len = _hmml_parse_text(p, &anno); int text_len = _hmml_parse_text(p, &ts);
if(p->cursor[0] == '[' && p->cursor[1] == ':') { if(p->cursor[0] == '[' && p->cursor[1] == ':') {
++p->cursor; ++p->cursor;
do { do {
HMML_Marker m = _hmml_parse_marker(p); HMML_Marker m = _hmml_parse_marker(p);
_hmml_persist_array(p, &anno.markers, &anno.marker_count, m); _hmml_persist_array(p, &ts.markers, &ts.marker_count, m);
_hmml_skip_ws(p); _hmml_skip_ws(p);
if(*p->cursor != ':' && *p->cursor != ']') { if(*p->cursor != ':' && *p->cursor != ']') {
_hmml_err(p, "Unterminated post-text category node"); _hmml_err(p, "Unterminated post-text category node");
@ -680,12 +680,12 @@ static void _hmml_parse_annotations(struct _hmml_parser* p)
} }
if(p->cursor[0] == '[' && p->cursor[1] == 'q') { if(p->cursor[0] == '[' && p->cursor[1] == 'q') {
_hmml_parse_quote(p, &anno); _hmml_parse_quote(p, &ts);
} }
// convert all markers to lowercase, fix any out of range offsets // convert all markers to lowercase, fix any out of range offsets
for(size_t i = 0; i < anno.marker_count; ++i) { for(size_t i = 0; i < ts.marker_count; ++i) {
HMML_Marker* m = anno.markers + i; HMML_Marker* m = ts.markers + i;
for(char* c = m->marker; *c; ++c) { for(char* c = m->marker; *c; ++c) {
if(*c >= 'A' && *c <= 'Z') { if(*c >= 'A' && *c <= 'Z') {
*c = (*c - ('A' - 'a')); *c = (*c - ('A' - 'a'));
@ -696,7 +696,7 @@ static void _hmml_parse_annotations(struct _hmml_parser* p)
} }
} }
_hmml_persist_array(p, &p->out.annotations, &p->out.annotation_count, anno); _hmml_persist_array(p, &p->out.timestamps, &p->out.timestamp_count, ts);
} }
} }
@ -736,7 +736,7 @@ next_attr:
if(*p->cursor == ']') { if(*p->cursor == ']') {
++p->cursor; ++p->cursor;
_hmml_parse_annotations(p); _hmml_parse_timestamps(p);
return; return;
} }
@ -813,7 +813,7 @@ void hmml_free(HMML_Output* out)
} }
const struct HMML_Version hmml_version = { const struct HMML_Version hmml_version = {
2, 0, 9 2, 0, 10
}; };
#undef HSTX #undef HSTX